Changeset 183510 in webkit


Ignore:
Timestamp:
Apr 28, 2015, 2:51:04 PM (10 years ago)
Author:
Simon Fraser
Message:

Provide contentsToView() and viewToContents() functions on ScrollView, and use them
https://bugs.webkit.org/show_bug.cgi?id=144357

Reviewed by Tim Horton.

Too much code was consulting topContentInset() and headerHeight() directly. Replace
with calls to new contentsToView() and viewToContents() functions, which wrap the
exisiting documentScrollOffsetRelativeToViewOrigin().

Use the new functions in FrameView and ScrollView coordinate mapping functions.

No behavior change.

  • page/FrameView.cpp:

(WebCore::FrameView::convertFromRendererToContainingView):
(WebCore::FrameView::convertFromContainingViewToRenderer):

  • platform/ScrollView.cpp:

(WebCore::ScrollView::viewToContents):
(WebCore::ScrollView::contentsToView):
(WebCore::ScrollView::rootViewToContents):
(WebCore::ScrollView::contentsToRootView):
(WebCore::ScrollView::rootViewToTotalContents):
(WebCore::ScrollView::windowToContents):
(WebCore::ScrollView::contentsToWindow):

  • platform/ScrollView.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r183509 r183510  
     12015-04-28  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Provide contentsToView() and viewToContents() functions on ScrollView, and use them
     4        https://bugs.webkit.org/show_bug.cgi?id=144357
     5
     6        Reviewed by Tim Horton.
     7
     8        Too much code was consulting topContentInset() and headerHeight() directly. Replace
     9        with calls to new contentsToView() and viewToContents() functions, which wrap the
     10        exisiting documentScrollOffsetRelativeToViewOrigin().
     11       
     12        Use the new functions in FrameView and ScrollView coordinate mapping functions.
     13       
     14        No behavior change.
     15
     16        * page/FrameView.cpp:
     17        (WebCore::FrameView::convertFromRendererToContainingView):
     18        (WebCore::FrameView::convertFromContainingViewToRenderer):
     19        * platform/ScrollView.cpp:
     20        (WebCore::ScrollView::viewToContents):
     21        (WebCore::ScrollView::contentsToView):
     22        (WebCore::ScrollView::rootViewToContents):
     23        (WebCore::ScrollView::contentsToRootView):
     24        (WebCore::ScrollView::rootViewToTotalContents):
     25        (WebCore::ScrollView::windowToContents):
     26        (WebCore::ScrollView::contentsToWindow):
     27        * platform/ScrollView.h:
     28
    1292015-04-28  Eric Carlson  <eric.carlson@apple.com>
    230
  • trunk/Source/WebCore/page/FrameView.cpp

    r183173 r183510  
    42004200    IntRect rect = snappedIntRect(enclosingLayoutRect(renderer->localToAbsoluteQuad(FloatRect(rendererRect)).boundingBox()));
    42014201
    4202     // Convert from page ("absolute") to FrameView coordinates.
    42034202    if (!delegatesScrolling())
    4204         rect.moveBy(-scrollPosition() + IntPoint(0, headerHeight() + topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset)));
     4203        rect = contentsToView(rect);
    42054204
    42064205    return rect;
     
    42134212    // Convert from FrameView coords into page ("absolute") coordinates.
    42144213    if (!delegatesScrolling())
    4215         rect.moveBy(documentScrollPositionRelativeToViewOrigin());
     4214        rect = viewToContents(rect);
    42164215
    42174216    // FIXME: we don't have a way to map an absolute rect down to a local quad, so just
     
    42274226    // Convert from page ("absolute") to FrameView coordinates.
    42284227    if (!delegatesScrolling())
    4229         point.moveBy(-scrollPosition() + IntPoint(0, headerHeight() + topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset)));
     4228        point = contentsToView(point);
     4229
    42304230    return point;
    42314231}
     
    42374237    // Convert from FrameView coords into page ("absolute") coordinates.
    42384238    if (!delegatesScrolling())
    4239         point = point + documentScrollPositionRelativeToViewOrigin();
     4239        point = viewToContents(point);
    42404240
    42414241    return roundedIntPoint(renderer->absoluteToLocal(point, UseTransforms));
  • trunk/Source/WebCore/platform/ScrollView.cpp

    r182364 r183510  
    865865}
    866866
     867IntPoint ScrollView::viewToContents(const IntPoint& point) const
     868{
     869    return point + documentScrollOffsetRelativeToViewOrigin();
     870}
     871
     872IntPoint ScrollView::contentsToView(const IntPoint& point) const
     873{
     874    return point - documentScrollOffsetRelativeToViewOrigin();
     875}
     876
     877IntRect ScrollView::viewToContents(IntRect rect) const
     878{
     879    rect.move(documentScrollOffsetRelativeToViewOrigin());
     880    return rect;
     881}
     882
     883IntRect ScrollView::contentsToView(IntRect rect) const
     884{
     885    rect.move(-documentScrollOffsetRelativeToViewOrigin());
     886    return rect;
     887}
     888
    867889IntPoint ScrollView::rootViewToContents(const IntPoint& rootViewPoint) const
    868890{
     
    870892        return convertFromRootView(rootViewPoint);
    871893
    872     IntPoint viewPoint = convertFromRootView(rootViewPoint);
    873     return viewPoint + documentScrollOffsetRelativeToViewOrigin();
     894    return viewToContents(convertFromRootView(rootViewPoint));
    874895}
    875896
     
    879900        return convertToRootView(contentsPoint);
    880901
    881     IntPoint viewPoint = contentsPoint + IntSize(0, headerHeight() + topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset)) - scrollOffset();
    882     return convertToRootView(viewPoint); 
     902    return convertToRootView(contentsToView(contentsPoint));
    883903}
    884904
     
    888908        return convertFromRootView(rootViewRect);
    889909
    890     IntRect viewRect = convertFromRootView(rootViewRect);
    891     viewRect.move(documentScrollOffsetRelativeToViewOrigin());
    892     return viewRect;
     910    return viewToContents(convertFromRootView(rootViewRect));
     911}
     912
     913IntPoint ScrollView::rootViewToTotalContents(const IntPoint& rootViewPoint) const
     914{
     915    if (delegatesScrolling())
     916        return convertFromRootView(rootViewPoint);
     917
     918    IntPoint viewPoint = convertFromRootView(rootViewPoint);
     919    // Like rootViewToContents(), but ignores headerHeight.
     920    return viewPoint + scrollOffset() - IntSize(0, topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset));
    893921}
    894922
     
    898926        return convertToRootView(contentsRect);
    899927
    900     IntRect viewRect = contentsRect;
    901     viewRect.move(-scrollOffset() + IntSize(0, headerHeight() + topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset)));
    902     return convertToRootView(viewRect);
    903 }
    904 
    905 IntPoint ScrollView::rootViewToTotalContents(const IntPoint& rootViewPoint) const
    906 {
    907     if (delegatesScrolling())
    908         return convertFromRootView(rootViewPoint);
    909 
    910     IntPoint viewPoint = convertFromRootView(rootViewPoint);
    911     return viewPoint + scrollOffset() - IntSize(0, topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset));
     928    return convertToRootView(contentsToView(contentsRect));
    912929}
    913930
     
    917934        return convertFromContainingWindow(windowPoint);
    918935
    919     IntPoint viewPoint = convertFromContainingWindow(windowPoint);
    920     return viewPoint + documentScrollOffsetRelativeToViewOrigin();
     936    return viewToContents(convertFromContainingWindow(windowPoint));
    921937}
    922938
     
    926942        return convertToContainingWindow(contentsPoint);
    927943
    928     IntPoint viewPoint = contentsPoint + IntSize(0, headerHeight() + topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset)) - scrollOffset();
    929     return convertToContainingWindow(viewPoint); 
     944    return convertToContainingWindow(contentsToView(contentsPoint));
    930945}
    931946
     
    935950        return convertFromContainingWindow(windowRect);
    936951
    937     IntRect viewRect = convertFromContainingWindow(windowRect);
    938     viewRect.move(documentScrollOffsetRelativeToViewOrigin());
    939     return viewRect;
     952    return viewToContents(convertFromContainingWindow(windowRect));
    940953}
    941954
     
    945958        return convertToContainingWindow(contentsRect);
    946959
    947     IntRect viewRect = contentsRect;
    948     viewRect.move(-scrollOffset() + IntSize(0, headerHeight() + topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset)));
    949     return convertToContainingWindow(viewRect);
     960    return convertToContainingWindow(contentsToView(contentsRect));
    950961}
    951962
  • trunk/Source/WebCore/platform/ScrollView.h

    r180615 r183510  
    293293    WEBCORE_EXPORT IntRect contentsToRootView(const IntRect&) const;
    294294
     295    IntPoint viewToContents(const IntPoint&) const;
     296    IntPoint contentsToView(const IntPoint&) const;
     297
     298    IntRect viewToContents(IntRect) const;
     299    IntRect contentsToView(IntRect) const;
     300
    295301    WEBCORE_EXPORT IntPoint rootViewToTotalContents(const IntPoint&) const;
    296302
Note: See TracChangeset for help on using the changeset viewer.