Changeset 274464 in webkit


Ignore:
Timestamp:
Mar 15, 2021 9:33:30 PM (16 months ago)
Author:
Patrick Angle
Message:

Web Inspector: Grid overlay does not adjust for element inside iframes
https://bugs.webkit.org/show_bug.cgi?id=222920

Reviewed by Simon Fraser.

Resolves an issue when overlays are applied to grids within iframes, which need to account for the
position/transform of their containing frame, and any other parent frames, to appear correctly in relation to
the root frame. This patch also has the side effect of changing how drawing the grid overlay while the page is
scrolled by allowing localPointToRootPoint to account for the scroll translation instead of explicitly
offsetting drawing by the scroll offset.

Widget, ScrollView, and FrameView are updated to retain floating-point precision where necessary.

  • inspector/InspectorOverlay.cpp:

(WebCore::localPointToRootPoint):

  • Use floating-point precision instead of integer precision.

(WebCore::InspectorOverlay::drawGridOverlay):

  • Use localPointToRootPoint to calculate absolute points relative to a renderGrid's parent hierarchy.
  • Remove graphics context translation, as localPointToRootPoint will account for this translation.
  • page/FrameView.cpp:

(WebCore::FrameView::convertFromRendererToContainingView const):
(WebCore::FrameView::convertToContainingView const):

  • page/FrameView.h:
  • platform/ScrollView.cpp:

(WebCore::ScrollView::contentsToView const):

  • platform/ScrollView.h:

(WebCore::ScrollView::convertChildToSelf const):

  • platform/Widget.cpp:

(WebCore::Widget::convertToContainingView const):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r274461 r274464  
     12021-03-15  Patrick Angle  <pangle@apple.com>
     2
     3        Web Inspector: Grid overlay does not adjust for element inside iframes
     4        https://bugs.webkit.org/show_bug.cgi?id=222920
     5
     6        Reviewed by Simon Fraser.
     7
     8        Resolves an issue when overlays are applied to grids within iframes, which need to account for the
     9        position/transform of their containing frame, and any other parent frames, to appear correctly in relation to
     10        the root frame. This patch also has the side effect of changing how drawing the grid overlay while the page is
     11        scrolled by allowing `localPointToRootPoint` to account for the scroll translation instead of explicitly
     12        offsetting drawing by the scroll offset.
     13
     14        `Widget`, `ScrollView`, and `FrameView` are updated to retain floating-point precision where necessary.
     15
     16        * inspector/InspectorOverlay.cpp:
     17        (WebCore::localPointToRootPoint):
     18        - Use floating-point precision instead of integer precision.
     19        (WebCore::InspectorOverlay::drawGridOverlay):
     20        - Use `localPointToRootPoint` to calculate absolute points relative to a `renderGrid`'s parent hierarchy.
     21        - Remove graphics context translation, as `localPointToRootPoint` will account for this translation.
     22        * page/FrameView.cpp:
     23        (WebCore::FrameView::convertFromRendererToContainingView const):
     24        (WebCore::FrameView::convertToContainingView const):
     25        * page/FrameView.h:
     26        * platform/ScrollView.cpp:
     27        (WebCore::ScrollView::contentsToView const):
     28        * platform/ScrollView.h:
     29        (WebCore::ScrollView::convertChildToSelf const):
     30        * platform/Widget.cpp:
     31        (WebCore::Widget::convertToContainingView const):
     32
    1332021-03-15  Simon Fraser  <simon.fraser@apple.com>
    234
  • trunk/Source/WebCore/inspector/InspectorOverlay.cpp

    r274096 r274464  
    100100static FloatPoint localPointToRootPoint(const FrameView* view, const FloatPoint& point)
    101101{
    102     return view->contentsToRootView(roundedIntPoint(point));
     102    return view->contentsToRootView(point);
    103103}
    104104
     
    14011401    constexpr auto translucentLabelBackgroundColor = Color::white.colorWithAlphaByte(153);
    14021402   
    1403     IntPoint scrollOffset;
    14041403    FrameView* pageView = m_page.mainFrame().view();
    1405     if (!pageView->delegatesScrolling())
    1406         scrollOffset = pageView->visibleContentRect().location();
    1407    
    1408     FloatSize contentInset(0, pageView->topContentInset(ScrollView::TopContentInsetType::WebCoreOrPlatformContentInset));
    1409     float pageScaleFactor = m_page.pageScaleFactor();
    1410 
    1411     float scrollX = scrollOffset.x() * pageScaleFactor;
    1412     float scrollY = scrollOffset.y() * pageScaleFactor;
    1413    
    1414     FloatRect viewportBounds = { FloatPoint(scrollX, scrollY), pageView->sizeForVisibleContent() };
     1404    if (!pageView)
     1405        return;
     1406    FloatRect viewportBounds = { { 0, 0 }, pageView->sizeForVisibleContent() };
    14151407   
    14161408    auto& renderGrid = *downcast<RenderGrid>(renderer);
     
    14241416    float gridStartY = rowPositions[0];
    14251417    float gridEndY = rowPositions[rowPositions.size() - 1];
    1426    
    1427     // FIXME: <webkit.org/b/222920> Grid overlay does not adjust for element inside iframes.
     1418
     1419    Frame* containingFrame = node->document().frame();
     1420    if (!containingFrame)
     1421        return;
     1422    FrameView* containingView = containingFrame->view();
     1423
    14281424    auto columnLineAt = [&](int x) -> FloatLine {
    14291425        return {
    1430             renderGrid.localToContainerPoint(FloatPoint(x, gridStartY), nullptr),
    1431             renderGrid.localToContainerPoint(FloatPoint(x, gridEndY), nullptr),
     1426            localPointToRootPoint(containingView, renderGrid.localToContainerPoint(FloatPoint(x, gridStartY), nullptr)),
     1427            localPointToRootPoint(containingView, renderGrid.localToContainerPoint(FloatPoint(x, gridEndY), nullptr)),
    14321428        };
    14331429    };
    14341430    auto rowLineAt = [&](int y) -> FloatLine {
    14351431        return {
    1436             renderGrid.localToContainerPoint(FloatPoint(gridStartX, y), nullptr),
    1437             renderGrid.localToContainerPoint(FloatPoint(gridEndX, y), nullptr),
     1432            localPointToRootPoint(containingView, renderGrid.localToContainerPoint(FloatPoint(gridStartX, y), nullptr)),
     1433            localPointToRootPoint(containingView, renderGrid.localToContainerPoint(FloatPoint(gridEndX, y), nullptr)),
    14381434        };
    14391435    };
    14401436   
    14411437    GraphicsContextStateSaver saver(context);
    1442 
    1443     // Drawing code is relative to the visible viewport area.
    1444     context.translate(0 - scrollX, contentInset.height() - scrollY);
    14451438    context.setStrokeThickness(1);
    14461439    context.setStrokeColor(gridOverlay.config.gridColor);
  • trunk/Source/WebCore/page/FrameView.cpp

    r273812 r274464  
    47864786}
    47874787
     4788FloatPoint FrameView::convertFromRendererToContainingView(const RenderElement* renderer, const FloatPoint& rendererPoint) const
     4789{
     4790    return contentsToView(renderer->localToAbsolute(rendererPoint, UseTransforms));
     4791}
     4792
    47884793IntPoint FrameView::convertFromContainingViewToRenderer(const RenderElement* renderer, const IntPoint& viewPoint) const
    47894794{
     
    48844889}
    48854890
     4891FloatPoint FrameView::convertToContainingView(const FloatPoint& localPoint) const
     4892{
     4893    if (const ScrollView* parentScrollView = parent()) {
     4894        if (is<FrameView>(*parentScrollView)) {
     4895            const FrameView& parentView = downcast<FrameView>(*parentScrollView);
     4896
     4897            // Get our renderer in the parent view
     4898            RenderWidget* renderer = frame().ownerRenderer();
     4899            if (!renderer)
     4900                return localPoint;
     4901
     4902            auto point = localPoint;
     4903            point.moveBy(renderer->contentBoxLocation());
     4904            return parentView.convertFromRendererToContainingView(renderer, point);
     4905        }
     4906
     4907        return Widget::convertToContainingView(localPoint);
     4908    }
     4909
     4910    return localPoint;
     4911}
     4912
    48864913IntPoint FrameView::convertFromContainingView(const IntPoint& parentPoint) const
    48874914{
  • trunk/Source/WebCore/page/FrameView.h

    r273275 r274464  
    482482    WEBCORE_EXPORT FloatRect convertFromContainingViewToRenderer(const RenderElement*, const FloatRect&) const;
    483483    WEBCORE_EXPORT IntPoint convertFromRendererToContainingView(const RenderElement*, const IntPoint&) const;
     484    WEBCORE_EXPORT FloatPoint convertFromRendererToContainingView(const RenderElement*, const FloatPoint&) const;
    484485    WEBCORE_EXPORT IntPoint convertFromContainingViewToRenderer(const RenderElement*, const IntPoint&) const;
    485486
     
    489490    FloatRect convertFromContainingView(const FloatRect&) const final;
    490491    IntPoint convertToContainingView(const IntPoint&) const final;
     492    FloatPoint convertToContainingView(const FloatPoint&) const final;
    491493    IntPoint convertFromContainingView(const IntPoint&) const final;
    492494
  • trunk/Source/WebCore/platform/ScrollView.cpp

    r273275 r274464  
    891891    if (delegatesScrolling())
    892892        return point;
    893 
    894     return contentsToView(IntPoint(point));
     893    return point - toFloatSize(documentScrollPositionRelativeToViewOrigin());
    895894}
    896895
  • trunk/Source/WebCore/platform/ScrollView.h

    r271788 r274464  
    355355    }
    356356
     357    FloatPoint convertChildToSelf(const Widget* child, const FloatPoint& point) const
     358    {
     359        FloatPoint newPoint = point;
     360        if (!isScrollViewScrollbar(child))
     361            newPoint -= toFloatSize(scrollPosition());
     362        newPoint.moveBy(child->location());
     363        return newPoint;
     364    }
     365
    357366    IntPoint convertSelfToChild(const Widget* child, const IntPoint& point) const
    358367    {
  • trunk/Source/WebCore/platform/Widget.cpp

    r271360 r274464  
    264264FloatPoint Widget::convertToContainingView(const FloatPoint& localPoint) const
    265265{
    266     return convertToContainingView(IntPoint(localPoint));
     266    if (const ScrollView* parentScrollView = parent())
     267        return parentScrollView->convertChildToSelf(this, localPoint);
     268
     269    return localPoint;
    267270}
    268271
Note: See TracChangeset for help on using the changeset viewer.