Changeset 107731 in webkit


Ignore:
Timestamp:
Feb 14, 2012 1:17:27 PM (12 years ago)
Author:
leviw@chromium.org
Message:

Update usage of LayoutUnits in RenderLayer
https://bugs.webkit.org/show_bug.cgi?id=78511

Reviewed by Simon Fraser.

Updating RenderLayer to properly use LayoutUnits. See descriptions below for the rationale behind all
the changes. Also adding a roundedIntSize method that takes a LayoutSize.

No new tests. No change in behavior.

  • rendering/LayoutTypes.h:

(WebCore::roundedIntSize): Inline method that currently does nothing, but will round a LayoutSize
to an IntSize.

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::updateLayerPositions): Switching repaint and outline boxes to LayoutRects, as
it's important to keep the precision of these rects until handing off to the embedder (in FrameView).
(WebCore::RenderLayer::computeRepaintRects): Repaint rects should be preserved in subpixel units until
being passed to the embedding layer. This prevents needless repaints.
(WebCore::RenderLayer::convertToPixelSnappedLayerCoords): Convenience function to return pixel snapped rects
(WebCore):
(WebCore::RenderLayer::convertToLayerCoords): Fixing a style flaw.
(WebCore::RenderLayer::scrollRectToVisible): Pixel snapping the rect when handing off to the embedder.
(WebCore::RenderLayer::maximumScrollPosition): Scroll offsets are rounded.
(WebCore::RenderLayer::scrollCornerRect): Scrollbars are drawn natively and should be positioned on pixel
boundaries.
(WebCore::RenderLayer::scrollCornerAndResizerRect): Resize corner doesn't influence the size/position of
render objects. It is only painted and hit tested. Therefor it should use integers.
(WebCore::RenderLayer::offsetFromResizeCorner): Ditto.
(WebCore::RenderLayer::positionOverflowControls): Overflow controls are drawn natively and should be
positioned on integer boundaries.
(WebCore::RenderLayer::paintOverflowControls): Ditto.
(WebCore::RenderLayer::paintScrollCorner): Ditto.
(WebCore::RenderLayer::drawPlatformResizerImage): Ditto.
(WebCore::RenderLayer::paintResizer): Ditto.
(WebCore::RenderLayer::hitTestOverflowControls): Hit testing & overflow controls both use integers.
(WebCore::RenderLayer::clipToRect): Clipping to actual painted (pixel snapped) layer bounds in the
graphics context.
(WebCore::RenderLayer::paintLayerContents): Calling paintOverflowControls at pixel bounds.
(WebCore::RenderLayer::hitTest): Intersecting the hit test area with pixel snapped boundaries.
(WebCore::RenderLayer::setBackingNeedsRepaintInRect): Sending pixelSnapped rects to the backing
store, which only cares about pixels, and hence integers.

  • rendering/RenderLayer.h:

(WebCore::RenderLayer::scrolledContentOffset): RenderLayer's scroll offsets are used in platform
code, so we need to return them as integers. Rounding the scroll overflow before adding it to the
scroll offset, which was already stored in integers.
(RenderLayer):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r107729 r107731  
     12012-02-14  Levi Weintraub  <leviw@chromium.org>
     2
     3        Update usage of LayoutUnits in RenderLayer
     4        https://bugs.webkit.org/show_bug.cgi?id=78511
     5
     6        Reviewed by Simon Fraser.
     7
     8        Updating RenderLayer to properly use LayoutUnits. See descriptions below for the rationale behind all
     9        the changes. Also adding a roundedIntSize method that takes a LayoutSize.
     10
     11        No new tests. No change in behavior.
     12
     13        * rendering/LayoutTypes.h:
     14        (WebCore::roundedIntSize): Inline method that currently does nothing, but will round a LayoutSize
     15        to an IntSize.
     16        * rendering/RenderLayer.cpp:
     17        (WebCore::RenderLayer::updateLayerPositions): Switching repaint and outline boxes to LayoutRects, as
     18        it's important to keep the precision of these rects until handing off to the embedder (in FrameView).
     19        (WebCore::RenderLayer::computeRepaintRects): Repaint rects should be preserved in subpixel units until
     20        being passed to the embedding layer. This prevents needless repaints.
     21        (WebCore::RenderLayer::convertToPixelSnappedLayerCoords): Convenience function to return pixel snapped rects
     22        (WebCore):
     23        (WebCore::RenderLayer::convertToLayerCoords): Fixing a style flaw.
     24        (WebCore::RenderLayer::scrollRectToVisible): Pixel snapping the rect when handing off to the embedder.
     25        (WebCore::RenderLayer::maximumScrollPosition): Scroll offsets are rounded.
     26        (WebCore::RenderLayer::scrollCornerRect): Scrollbars are drawn natively and should be positioned on pixel
     27        boundaries.
     28        (WebCore::RenderLayer::scrollCornerAndResizerRect): Resize corner doesn't influence the size/position of
     29        render objects. It is only painted and hit tested. Therefor it should use integers.
     30        (WebCore::RenderLayer::offsetFromResizeCorner): Ditto.
     31        (WebCore::RenderLayer::positionOverflowControls): Overflow controls are drawn natively and should be
     32        positioned on integer boundaries.
     33        (WebCore::RenderLayer::paintOverflowControls): Ditto.
     34        (WebCore::RenderLayer::paintScrollCorner): Ditto.
     35        (WebCore::RenderLayer::drawPlatformResizerImage): Ditto.
     36        (WebCore::RenderLayer::paintResizer): Ditto.
     37        (WebCore::RenderLayer::hitTestOverflowControls): Hit testing & overflow controls both use integers.
     38        (WebCore::RenderLayer::clipToRect): Clipping to actual painted (pixel snapped) layer bounds in the
     39        graphics context.
     40        (WebCore::RenderLayer::paintLayerContents): Calling paintOverflowControls at pixel bounds.
     41        (WebCore::RenderLayer::hitTest): Intersecting the hit test area with pixel snapped boundaries.
     42        (WebCore::RenderLayer::setBackingNeedsRepaintInRect): Sending pixelSnapped rects to the backing
     43        store, which only cares about pixels, and hence integers.
     44        * rendering/RenderLayer.h:
     45        (WebCore::RenderLayer::scrolledContentOffset): RenderLayer's scroll offsets are used in platform
     46        code, so we need to return them as integers. Rounding the scroll overflow before adding it to the
     47        scroll offset, which was already stored in integers.
     48        (RenderLayer):
     49
    1502012-02-14  Abhishek Arya  <inferno@chromium.org>
    251
  • trunk/Source/WebCore/rendering/LayoutTypes.h

    r107465 r107731  
    5555{
    5656    return rect;
     57}
     58
     59inline IntSize roundedIntSize(const LayoutSize& s)
     60{
     61    return s;
    5762}
    5863
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r107605 r107731  
    359359        convertToLayerCoords(root(), offset);
    360360    }
    361     positionOverflowControls(toSize(offset));
     361    positionOverflowControls(toSize(roundedIntPoint(offset)));
    362362
    363363    updateVisibilityStatus();
     
    377377
    378378        RenderBoxModelObject* repaintContainer = renderer()->containerForRepaint();
    379         IntRect oldRepaintRect = m_repaintRect;
    380         IntRect oldOutlineBox = m_outlineBox;
     379        LayoutRect oldRepaintRect = m_repaintRect;
     380        LayoutRect oldOutlineBox = m_outlineBox;
    381381        computeRepaintRects(offsetFromRoot);
    382382        // FIXME: Should ASSERT that value calculated for m_outlineBox using the cached offset is the same
     
    435435}
    436436
    437 void RenderLayer::computeRepaintRects(IntPoint* offsetFromRoot)
     437void RenderLayer::computeRepaintRects(LayoutPoint* offsetFromRoot)
    438438{
    439439    ASSERT(!m_visibleContentStatusDirty);
     
    12391239}
    12401240
    1241 void
    1242 RenderLayer::convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint& location) const
     1241void RenderLayer::convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntPoint& roundedLocation) const
     1242{
     1243    LayoutPoint location = roundedLocation;
     1244    convertToLayerCoords(ancestorLayer, location);
     1245    roundedLocation = roundedIntPoint(location);
     1246}
     1247
     1248void RenderLayer::convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntRect& roundedRect) const
     1249{
     1250    LayoutRect rect = roundedRect;
     1251    convertToLayerCoords(ancestorLayer, rect);
     1252    roundedRect = pixelSnappedIntRect(rect);
     1253}
     1254
     1255void RenderLayer::convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint& location) const
    12431256{
    12441257    if (ancestorLayer == this)
     
    13271340}
    13281341
    1329 void
    1330 RenderLayer::convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutRect& rect) const
     1342void RenderLayer::convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutRect& rect) const
    13311343{
    13321344    LayoutPoint delta;
     
    17901802{
    17911803    // FIXME: m_scrollSize may not be up-to-date if m_scrollDimensionsDirty is true.
    1792     return scrollOrigin() + m_scrollSize - visibleContentRect(true).size();
     1804    return scrollOrigin() + roundedIntSize(m_scrollSize) - visibleContentRect(true).size();
    17931805}
    17941806
     
    18521864    bool hasResizer = renderer()->style()->resize() != RESIZE_NONE;
    18531865    if ((hasHorizontalBar && hasVerticalBar) || (hasResizer && (hasHorizontalBar || hasVerticalBar)))
    1854         return cornerRect(this, renderBox()->borderBoxRect());
     1866        return cornerRect(this, pixelSnappedIntRect(renderBox()->borderBoxRect()));
    18551867    return IntRect();
    18561868}
     
    18711883    IntRect scrollCornerAndResizer = scrollCornerRect();
    18721884    if (scrollCornerAndResizer.isEmpty())
    1873         scrollCornerAndResizer = resizerCornerRect(this, box->borderBoxRect());
     1885        scrollCornerAndResizer = resizerCornerRect(this, pixelSnappedIntRect(box->borderBoxRect()));
    18741886    return scrollCornerAndResizer;
    18751887}
     
    21332145}
    21342146
    2135 LayoutSize RenderLayer::offsetFromResizeCorner(const LayoutPoint& absolutePoint) const
     2147IntSize RenderLayer::offsetFromResizeCorner(const IntPoint& absolutePoint) const
    21362148{
    21372149    // Currently the resize corner is always the bottom right corner
     
    21472159}
    21482160
    2149 void RenderLayer::positionOverflowControls(const LayoutSize& offsetFromLayer)
     2161void RenderLayer::positionOverflowControls(const IntSize& offsetFromLayer)
    21502162{
    21512163    if (!m_hBar && !m_vBar && (!renderer()->hasOverflowClip() || renderer()->style()->resize() == RESIZE_NONE))
     
    23992411}
    24002412
    2401 void RenderLayer::paintOverflowControls(GraphicsContext* context, const LayoutPoint& paintOffset, const LayoutRect& damageRect, bool paintingOverlayControls)
     2413void RenderLayer::paintOverflowControls(GraphicsContext* context, const IntPoint& paintOffset, const IntRect& damageRect, bool paintingOverlayControls)
    24022414{
    24032415    // Don't do anything if we have no overflow.
     
    24232435        return;
    24242436
    2425     LayoutPoint adjustedPaintOffset = paintOffset;
     2437    IntPoint adjustedPaintOffset = paintOffset;
    24262438    if (paintingOverlayControls)
    24272439        adjustedPaintOffset = m_cachedOverlayScrollbarOffset;
     
    24592471}
    24602472
    2461 void RenderLayer::paintScrollCorner(GraphicsContext* context, const LayoutPoint& paintOffset, const LayoutRect& damageRect)
     2473void RenderLayer::paintScrollCorner(GraphicsContext* context, const IntPoint& paintOffset, const IntRect& damageRect)
    24622474{
    24632475    RenderBox* box = renderBox();
    24642476    ASSERT(box);
    24652477
    2466     LayoutRect absRect = scrollCornerRect();
     2478    IntRect absRect = scrollCornerRect();
    24672479    absRect.moveBy(paintOffset);
    24682480    if (!absRect.intersects(damageRect))
     
    24852497}
    24862498
    2487 void RenderLayer::drawPlatformResizerImage(GraphicsContext* context, LayoutRect resizerCornerRect)
     2499void RenderLayer::drawPlatformResizerImage(GraphicsContext* context, IntRect resizerCornerRect)
    24882500{
    24892501    float deviceScaleFactor = WebCore::deviceScaleFactor(renderer()->frame());
     
    25062518}
    25072519
    2508 void RenderLayer::paintResizer(GraphicsContext* context, const LayoutPoint& paintOffset, const LayoutRect& damageRect)
     2520void RenderLayer::paintResizer(GraphicsContext* context, const IntPoint& paintOffset, const IntRect& damageRect)
    25092521{
    25102522    if (renderer()->style()->resize() == RESIZE_NONE)
     
    25142526    ASSERT(box);
    25152527
    2516     LayoutRect absRect = resizerCornerRect(this, box->borderBoxRect());
     2528    IntRect absRect = resizerCornerRect(this, pixelSnappedIntRect(box->borderBoxRect()));
    25172529    absRect.moveBy(paintOffset);
    25182530    if (!absRect.intersects(damageRect))
     
    25362548        GraphicsContextStateSaver stateSaver(*context);
    25372549        context->clip(absRect);
    2538         LayoutRect largerCorner = absRect;
    2539         largerCorner.setSize(LayoutSize(largerCorner.width() + 1, largerCorner.height() + 1));
     2550        IntRect largerCorner = absRect;
     2551        largerCorner.setSize(IntSize(largerCorner.width() + 1, largerCorner.height() + 1));
    25402552        context->setStrokeColor(Color(makeRGB(217, 217, 217)), ColorSpaceDeviceRGB);
    25412553        context->setStrokeThickness(1.0f);
     
    25592571}
    25602572   
    2561 bool RenderLayer::hitTestOverflowControls(HitTestResult& result, const LayoutPoint& localPoint)
     2573bool RenderLayer::hitTestOverflowControls(HitTestResult& result, const IntPoint& localPoint)
    25622574{
    25632575    if (!m_hBar && !m_vBar && (!renderer()->hasOverflowClip() || renderer()->style()->resize() == RESIZE_NONE))
     
    25692581    IntRect resizeControlRect;
    25702582    if (renderer()->style()->resize() != RESIZE_NONE) {
    2571         resizeControlRect = resizerCornerRect(this, box->borderBoxRect());
     2583        resizeControlRect = resizerCornerRect(this, pixelSnappedIntRect(box->borderBoxRect()));
    25722584        if (resizeControlRect.contains(localPoint))
    25732585            return true;
     
    26472659        return;
    26482660    context->save();
    2649     context->clip(clipRect.rect());
     2661    context->clip(pixelSnappedIntRect(clipRect.rect()));
    26502662   
    26512663    if (!clipRect.hasRadius())
     
    29482960    if (isPaintingOverlayScrollbars) {
    29492961        clipToRect(rootLayer, context, paintDirtyRect, damageRect);
    2950         paintOverflowControls(context, roundedIntPoint(paintOffset), damageRect.rect(), true);
     2962        paintOverflowControls(context, roundedIntPoint(paintOffset), pixelSnappedIntRect(damageRect.rect()), true);
    29512963        restoreClip(context, paintDirtyRect, damageRect);
    29522964    }
     
    31123124    renderer()->document()->updateLayout();
    31133125   
    3114     LayoutRect hitTestArea = renderer()->isRenderFlowThread() ? toRenderFlowThread(renderer())->borderBoxRect() : renderer()->view()->documentRect();
     3126    IntRect hitTestArea = renderer()->isRenderFlowThread() ? toRenderFlowThread(renderer())->borderBoxRect() : renderer()->view()->documentRect();
    31153127    if (!request.ignoreClipping())
    3116         hitTestArea.intersect(frameVisibleRect(renderer()));
     3128        hitTestArea.intersect(pixelSnappedIntRect(frameVisibleRect(renderer())));
    31173129
    31183130    RenderLayer* insideLayer = hitTestLayer(this, 0, request, result, hitTestArea, result.point(), false);
     
    42714283            view->repaintViewRectangle(absRect);
    42724284    } else
    4273         backing()->setContentsNeedDisplayInRect(r);
     4285        backing()->setContentsNeedDisplayInRect(pixelSnappedIntRect(r));
    42744286}
    42754287
  • trunk/Source/WebCore/rendering/RenderLayer.h

    r107422 r107731  
    296296    void scrollByRecursively(LayoutUnit xDelta, LayoutUnit yDelta, ScrollOffsetClamping = ScrollOffsetUnclamped);
    297297
    298     LayoutSize scrolledContentOffset() const { return scrollOffset() + m_scrollOverflow; }
     298    IntSize scrolledContentOffset() const { return scrollOffset() + roundedIntSize(m_scrollOverflow); }
    299299
    300300    int scrollXOffset() const { return m_scrollOffset.width() + scrollOrigin().x(); }
     
    328328
    329329    bool hasOverflowControls() const;
    330     bool isPointInResizeControl(const LayoutPoint& absolutePoint) const;
    331     bool hitTestOverflowControls(HitTestResult&, const LayoutPoint& localPoint);
    332     LayoutSize offsetFromResizeCorner(const LayoutPoint& absolutePoint) const;
    333 
    334     void paintOverflowControls(GraphicsContext*, const LayoutPoint&, const LayoutRect& damageRect, bool paintingOverlayControls = false);
    335     void paintScrollCorner(GraphicsContext*, const LayoutPoint&, const LayoutRect& damageRect);
    336     void paintResizer(GraphicsContext*, const LayoutPoint&, const LayoutRect& damageRect);
     330    bool isPointInResizeControl(const IntPoint& absolutePoint) const;
     331    bool hitTestOverflowControls(HitTestResult&, const IntPoint& localPoint);
     332    IntSize offsetFromResizeCorner(const IntPoint& absolutePoint) const;
     333
     334    void paintOverflowControls(GraphicsContext*, const IntPoint&, const IntRect& damageRect, bool paintingOverlayControls = false);
     335    void paintScrollCorner(GraphicsContext*, const IntPoint&, const IntRect& damageRect);
     336    void paintResizer(GraphicsContext*, const IntPoint&, const IntRect& damageRect);
    337337
    338338    void updateScrollInfoAfterLayout();
     
    426426#endif
    427427
     428    void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntPoint& location) const;
     429    void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntRect&) const;
    428430    void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint& location) const;
    429431    void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutRect&) const;
     
    569571    void updateZOrderListsSlowCase();
    570572
    571     void computeRepaintRects(IntPoint* offsetFromRoot = 0);
     573    void computeRepaintRects(LayoutPoint* offsetFromRoot = 0);
    572574    void clearRepaintRects();
    573575
     
    714716    LayoutPoint absoluteToContents(const LayoutPoint&) const;
    715717
    716     void positionOverflowControls(const LayoutSize&);
     718    void positionOverflowControls(const IntSize&);
    717719    void updateScrollCornerStyle();
    718720    void updateResizerStyle();
    719721
    720     void drawPlatformResizerImage(GraphicsContext*, LayoutRect resizerCornerRect);
     722    void drawPlatformResizerImage(GraphicsContext*, IntRect resizerCornerRect);
    721723
    722724    void updatePagination();
     
    822824   
    823825    // The width/height of our scrolled area.
    824     IntSize m_scrollSize;
     826    LayoutSize m_scrollSize;
    825827
    826828    // For layers with overflow, we have a pair of scrollbars.
     
    844846#endif
    845847
    846     LayoutPoint m_cachedOverlayScrollbarOffset;
     848    IntPoint m_cachedOverlayScrollbarOffset;
    847849
    848850    RenderMarquee* m_marquee; // Used by layers with overflow:marquee
Note: See TracChangeset for help on using the changeset viewer.