Changeset 108719 in webkit


Ignore:
Timestamp:
Feb 23, 2012 7:55:53 PM (12 years ago)
Author:
leviw@chromium.org
Message:

Switch drawLineForBoxSide to use integers
https://bugs.webkit.org/show_bug.cgi?id=78647

Reviewed by Eric Seidel.

drawLineForBoxSide handles painting lines for boxes which must be done on pixel boundaries.
Its interface doesn't make it possible to pixel snap properly within the function itself --
it draws one side of the box at a time, and the logical right and bottom lines can only be
properly determined using the logical top and left positions -- so it needs to be treated
like a graphics context function, whereby the caller handles the proper pixel snapping before
passing the values in.

No new tests. No change in behavior.

  • rendering/LayoutTypes.h:

(WebCore::pixelSnappedIntRectFromEdges): convenience function for returning a pixel snapped
int rect from four LayoutUnits that are its edges (as opposed to position and size).

  • rendering/RenderBlock.cpp:

(WebCore::RenderBlock::paintColumnRules): Pixel snapping the column rule rect.

  • rendering/RenderBoxModelObject.cpp:

(WebCore::RenderBoxModelObject::paintOneBorderSide): Side rects are now IntRects by the time
they get to paintOneBorderSide.
(WebCore::calculateSideRect): Properly use RoundedRect as IntRects instead of LayoutRects.
(WebCore::RenderBoxModelObject::paintBorderSides): Ditto.
(WebCore::RenderBoxModelObject::paintBorder): Ditto.
(WebCore::calculateSideRectIncludingInner): Ditto.

  • rendering/RenderBoxModelObject.h:

(RenderBoxModelObject):

  • rendering/RenderInline.cpp:

(WebCore::RenderInline::paintOutlineForLine): Outline widths are related to borders and stored
as ints. Removing an unnecessary conversion to LayoutUnits. Pixel snapping the edges of the box.

  • rendering/RenderObject.cpp:

(WebCore::RenderObject::drawLineForBoxSide): Moving back to integers and removing an
unnecessary pixelSnappedIntRect call.
(WebCore::RenderObject::paintOutline): Pixel snapping the column rule rect and using an integer
for outlineOffset.

  • rendering/RenderObject.h:

(RenderObject):

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r108715 r108719  
     12012-02-23  Levi Weintraub  <leviw@chromium.org>
     2
     3        Switch drawLineForBoxSide to use integers
     4        https://bugs.webkit.org/show_bug.cgi?id=78647
     5
     6        Reviewed by Eric Seidel.
     7
     8        drawLineForBoxSide handles painting lines for boxes which must be done on pixel boundaries.
     9        Its interface doesn't make it possible to pixel snap properly within the function itself --
     10        it draws one side of the box at a time, and the logical right and bottom lines can only be
     11        properly determined using the logical top and left positions -- so it needs to be treated
     12        like a graphics context function, whereby the caller handles the proper pixel snapping before
     13        passing the values in.
     14
     15        No new tests. No change in behavior.
     16
     17        * rendering/LayoutTypes.h:
     18        (WebCore::pixelSnappedIntRectFromEdges): convenience function for returning a pixel snapped
     19        int rect from four LayoutUnits that are its edges (as opposed to position and size).
     20        * rendering/RenderBlock.cpp:
     21        (WebCore::RenderBlock::paintColumnRules): Pixel snapping the column rule rect.
     22        * rendering/RenderBoxModelObject.cpp:
     23        (WebCore::RenderBoxModelObject::paintOneBorderSide): Side rects are now IntRects by the time
     24        they get to paintOneBorderSide.
     25        (WebCore::calculateSideRect): Properly use RoundedRect as IntRects instead of LayoutRects.
     26        (WebCore::RenderBoxModelObject::paintBorderSides): Ditto.
     27        (WebCore::RenderBoxModelObject::paintBorder): Ditto.
     28        (WebCore::calculateSideRectIncludingInner): Ditto.
     29        * rendering/RenderBoxModelObject.h:
     30        (RenderBoxModelObject):
     31        * rendering/RenderInline.cpp:
     32        (WebCore::RenderInline::paintOutlineForLine): Outline widths are related to borders and stored
     33        as ints. Removing an unnecessary conversion to LayoutUnits. Pixel snapping the edges of the box.
     34        * rendering/RenderObject.cpp:
     35        (WebCore::RenderObject::drawLineForBoxSide): Moving back to integers and removing an
     36        unnecessary pixelSnappedIntRect call.
     37        (WebCore::RenderObject::paintOutline): Pixel snapping the column rule rect and using an integer
     38        for outlineOffset.
     39        * rendering/RenderObject.h:
     40        (RenderObject):
     41
    1422012-02-23  Leo Yang  <leo.yang@torchmobile.com.cn>
    243
  • trunk/Source/WebCore/rendering/LayoutTypes.h

    r107880 r108719  
    5757{
    5858    return rect;
     59}
     60
     61inline IntRect pixelSnappedIntRectFromEdges(LayoutUnit left, LayoutUnit top, LayoutUnit right, LayoutUnit bottom)
     62{
     63    return IntRect(left, top, right - left, bottom - top);
    5964}
    6065
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r108645 r108719  
    25942594                LayoutUnit ruleTop = isHorizontalWritingMode() ? paintOffset.y() + borderTop() + paddingTop() : paintOffset.y() + ruleLogicalLeft - ruleThickness / 2 + ruleAdd;
    25952595                LayoutUnit ruleBottom = isHorizontalWritingMode() ? ruleTop + contentHeight() : ruleTop + ruleThickness;
    2596                 drawLineForBoxSide(paintInfo.context, ruleLeft, ruleTop, ruleRight, ruleBottom, boxSide, ruleColor, ruleStyle, 0, 0, antialias);
     2596                IntRect pixelSnappedRuleRect = pixelSnappedIntRectFromEdges(ruleLeft, ruleTop, ruleRight, ruleBottom);
     2597                drawLineForBoxSide(paintInfo.context, pixelSnappedRuleRect.x(), pixelSnappedRuleRect.y(), pixelSnappedRuleRect.maxX(), pixelSnappedRuleRect.maxY(), boxSide, ruleColor, ruleStyle, 0, 0, antialias);
    25972598            }
    25982599           
     
    26192620        for (unsigned i = 1; i < colCount; i++) {
    26202621            ruleRect.move(step);
    2621             drawLineForBoxSide(paintInfo.context, ruleRect.x(), ruleRect.y(), ruleRect.maxX(), ruleRect.maxY(), boxSide, ruleColor, ruleStyle, 0, 0, antialias);
     2622            IntRect pixelSnappedRuleRect = pixelSnappedIntRect(ruleRect);
     2623            drawLineForBoxSide(paintInfo.context, pixelSnappedRuleRect.x(), pixelSnappedRuleRect.y(), pixelSnappedRuleRect.maxX(), pixelSnappedRuleRect.maxY(), boxSide, ruleColor, ruleStyle, 0, 0, antialias);
    26222624        }
    26232625    }
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp

    r108494 r108719  
    15861586
    15871587void RenderBoxModelObject::paintOneBorderSide(GraphicsContext* graphicsContext, const RenderStyle* style, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
    1588     const LayoutRect& sideRect, BoxSide side, BoxSide adjacentSide1, BoxSide adjacentSide2, const BorderEdge edges[], const Path* path,
     1588    const IntRect& sideRect, BoxSide side, BoxSide adjacentSide1, BoxSide adjacentSide2, const BorderEdge edges[], const Path* path,
    15891589    BackgroundBleedAvoidance bleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor)
    15901590{
     
    16311631}
    16321632
    1633 static LayoutRect calculateSideRect(const RoundedRect& outerBorder, const BorderEdge edges[], int side)
    1634 {
    1635     LayoutRect sideRect = outerBorder.rect();
     1633static IntRect calculateSideRect(const RoundedRect& outerBorder, const BorderEdge edges[], int side)
     1634{
     1635    IntRect sideRect = outerBorder.rect();
    16361636    int width = edges[side].width;
    16371637
     
    16591659   
    16601660    if (edges[BSTop].shouldRender() && includesEdge(edgeSet, BSTop)) {
    1661         LayoutRect sideRect = outerBorder.rect();
     1661        IntRect sideRect = outerBorder.rect();
    16621662        sideRect.setHeight(edges[BSTop].width);
    16631663
     
    16671667
    16681668    if (edges[BSBottom].shouldRender() && includesEdge(edgeSet, BSBottom)) {
    1669         LayoutRect sideRect = outerBorder.rect();
     1669        IntRect sideRect = outerBorder.rect();
    16701670        sideRect.shiftYEdgeTo(sideRect.maxY() - edges[BSBottom].width);
    16711671
     
    16751675
    16761676    if (edges[BSLeft].shouldRender() && includesEdge(edgeSet, BSLeft)) {
    1677         LayoutRect sideRect = outerBorder.rect();
     1677        IntRect sideRect = outerBorder.rect();
    16781678        sideRect.setWidth(edges[BSLeft].width);
    16791679
     
    16831683
    16841684    if (edges[BSRight].shouldRender() && includesEdge(edgeSet, BSRight)) {
    1685         LayoutRect sideRect = outerBorder.rect();
     1685        IntRect sideRect = outerBorder.rect();
    16861686        sideRect.shiftXEdgeTo(sideRect.maxX() - edges[BSRight].width);
    16871687
     
    18121812                const BorderEdge& currEdge = edges[i];
    18131813                if (currEdge.shouldRender()) {
    1814                     LayoutRect sideRect = calculateSideRect(outerBorder, edges, i);
     1814                    IntRect sideRect = calculateSideRect(outerBorder, edges, i);
    18151815                    path.addRect(sideRect);
    18161816                }
     
    24342434}
    24352435
    2436 static LayoutRect calculateSideRectIncludingInner(const RoundedRect& outerBorder, const BorderEdge edges[], BoxSide side)
    2437 {
    2438     LayoutRect sideRect = outerBorder.rect();
     2436static IntRect calculateSideRectIncludingInner(const RoundedRect& outerBorder, const BorderEdge edges[], BoxSide side)
     2437{
     2438    IntRect sideRect = outerBorder.rect();
    24392439    int width;
    24402440
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.h

    r107874 r108719  
    221221    void clipBorderSideForComplexInnerPath(GraphicsContext*, const RoundedRect&, const RoundedRect&, BoxSide, const class BorderEdge[]);
    222222    void paintOneBorderSide(GraphicsContext*, const RenderStyle*, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
    223                                 const LayoutRect& sideRect, BoxSide, BoxSide adjacentSide1, BoxSide adjacentSide2, const class BorderEdge[],
     223                                const IntRect& sideRect, BoxSide, BoxSide adjacentSide1, BoxSide adjacentSide2, const class BorderEdge[],
    224224                                const Path*, BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor = 0);
    225225    void paintTranslucentBorderSides(GraphicsContext*, const RenderStyle*, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
  • trunk/Source/WebCore/rendering/RenderInline.cpp

    r108382 r108719  
    14471447{
    14481448    RenderStyle* styleToUse = style();
    1449     LayoutUnit outlineWidth = styleToUse->outlineWidth();
     1449    int outlineWidth = styleToUse->outlineWidth();
    14501450    EBorderStyle outlineStyle = styleToUse->outlineStyle();
    14511451
    14521452    bool antialias = shouldAntialiasLines(graphicsContext);
    14531453
    1454     LayoutUnit offset = style()->outlineOffset();
    1455 
    1456     LayoutUnit top = paintOffset.y() + thisline.y() - offset;
    1457     LayoutUnit left = paintOffset.x() + thisline.x() - offset;
    1458     LayoutUnit bottom = paintOffset.y() + thisline.maxY() + offset;
    1459     LayoutUnit right = paintOffset.x() + thisline.maxX() + offset;
     1454    int offset = style()->outlineOffset();
     1455
     1456    LayoutRect box(LayoutPoint(paintOffset.x() + thisline.x() - offset, paintOffset.y() + thisline.y() - offset),
     1457        LayoutSize(thisline.width() + offset, thisline.height() + offset));
     1458
     1459    IntRect pixelSnappedBox = pixelSnappedIntRect(box);
    14601460   
    14611461    // left edge
    14621462    drawLineForBoxSide(graphicsContext,
    1463         left - outlineWidth,
    1464         top - (lastline.isEmpty() || thisline.x() < lastline.x() || (lastline.maxX() - 1) <= thisline.x() ? outlineWidth : zeroLayoutUnit),
    1465         left,
    1466         bottom + (nextline.isEmpty() || thisline.x() <= nextline.x() || (nextline.maxX() - 1) <= thisline.x() ? outlineWidth : zeroLayoutUnit),
     1463        pixelSnappedBox.x() - outlineWidth,
     1464        pixelSnappedBox.y() - (lastline.isEmpty() || thisline.x() < lastline.x() || (lastline.maxX() - 1) <= thisline.x() ? outlineWidth : 0),
     1465        pixelSnappedBox.x(),
     1466        pixelSnappedBox.maxY() + (nextline.isEmpty() || thisline.x() <= nextline.x() || (nextline.maxX() - 1) <= thisline.x() ? outlineWidth : 0),
    14671467        BSLeft,
    14681468        outlineColor, outlineStyle,
     
    14731473    // right edge
    14741474    drawLineForBoxSide(graphicsContext,
    1475         right,
    1476         top - (lastline.isEmpty() || lastline.maxX() < thisline.maxX() || (thisline.maxX() - 1) <= lastline.x() ? outlineWidth : zeroLayoutUnit),
    1477         right + outlineWidth,
    1478         bottom + (nextline.isEmpty() || nextline.maxX() <= thisline.maxX() || (thisline.maxX() - 1) <= nextline.x() ? outlineWidth : zeroLayoutUnit),
     1475        pixelSnappedBox.maxX(),
     1476        pixelSnappedBox.y() - (lastline.isEmpty() || lastline.maxX() < thisline.maxX() || (thisline.maxX() - 1) <= lastline.x() ? outlineWidth : 0),
     1477        pixelSnappedBox.maxX() + outlineWidth,
     1478        pixelSnappedBox.maxY() + (nextline.isEmpty() || nextline.maxX() <= thisline.maxX() || (thisline.maxX() - 1) <= nextline.x() ? outlineWidth : 0),
    14791479        BSRight,
    14801480        outlineColor, outlineStyle,
     
    14851485    if (thisline.x() < lastline.x())
    14861486        drawLineForBoxSide(graphicsContext,
    1487             left - outlineWidth,
    1488             top - outlineWidth,
    1489             min(right + outlineWidth, (lastline.isEmpty() ? 1000000 : paintOffset.x() + lastline.x())),
    1490             top,
     1487            pixelSnappedBox.x() - outlineWidth,
     1488            pixelSnappedBox.y() - outlineWidth,
     1489            min(pixelSnappedBox.maxX() + outlineWidth, (lastline.isEmpty() ? 1000000 : paintOffset.x() + lastline.x())),
     1490            pixelSnappedBox.y(),
    14911491            BSTop, outlineColor, outlineStyle,
    14921492            outlineWidth,
    1493             (!lastline.isEmpty() && paintOffset.x() + lastline.x() + 1 < right + outlineWidth) ? -outlineWidth : outlineWidth,
     1493            (!lastline.isEmpty() && paintOffset.x() + lastline.x() + 1 < pixelSnappedBox.maxX() + outlineWidth) ? -outlineWidth : outlineWidth,
    14941494            antialias);
    14951495   
    14961496    if (lastline.maxX() < thisline.maxX())
    14971497        drawLineForBoxSide(graphicsContext,
    1498             max(lastline.isEmpty() ? -1000000 : paintOffset.x() + lastline.maxX(), left - outlineWidth),
    1499             top - outlineWidth,
    1500             right + outlineWidth,
    1501             top,
     1498            max(lastline.isEmpty() ? -1000000 : paintOffset.x() + lastline.maxX(), pixelSnappedBox.x() - outlineWidth),
     1499            pixelSnappedBox.y() - outlineWidth,
     1500            pixelSnappedBox.maxX() + outlineWidth,
     1501            pixelSnappedBox.y(),
    15021502            BSTop, outlineColor, outlineStyle,
    1503             (!lastline.isEmpty() && left - outlineWidth < paintOffset.x() + lastline.maxX()) ? -outlineWidth : outlineWidth,
     1503            (!lastline.isEmpty() && pixelSnappedBox.x() - outlineWidth < paintOffset.x() + lastline.maxX()) ? -outlineWidth : outlineWidth,
    15041504            outlineWidth, antialias);
    15051505
    15061506    if (thisline.x() == thisline.maxX())
    15071507          drawLineForBoxSide(graphicsContext,
    1508             left - outlineWidth,
    1509             top - outlineWidth,
    1510             right + outlineWidth,
    1511             top,
     1508            pixelSnappedBox.x() - outlineWidth,
     1509            pixelSnappedBox.y() - outlineWidth,
     1510            pixelSnappedBox.maxX() + outlineWidth,
     1511            pixelSnappedBox.y(),
    15121512            BSTop, outlineColor, outlineStyle,
    15131513            outlineWidth,
     
    15181518    if (thisline.x() < nextline.x())
    15191519        drawLineForBoxSide(graphicsContext,
    1520             left - outlineWidth,
    1521             bottom,
    1522             min(right + outlineWidth, !nextline.isEmpty() ? paintOffset.x() + nextline.x() + 1 : 1000000),
    1523             bottom + outlineWidth,
     1520            pixelSnappedBox.x() - outlineWidth,
     1521            pixelSnappedBox.maxY(),
     1522            min(pixelSnappedBox.maxX() + outlineWidth, !nextline.isEmpty() ? paintOffset.x() + nextline.x() + 1 : 1000000),
     1523            pixelSnappedBox.maxY() + outlineWidth,
    15241524            BSBottom, outlineColor, outlineStyle,
    15251525            outlineWidth,
    1526             (!nextline.isEmpty() && paintOffset.x() + nextline.x() + 1 < right + outlineWidth) ? -outlineWidth : outlineWidth,
     1526            (!nextline.isEmpty() && paintOffset.x() + nextline.x() + 1 < pixelSnappedBox.maxX() + outlineWidth) ? -outlineWidth : outlineWidth,
    15271527            antialias);
    15281528   
    15291529    if (nextline.maxX() < thisline.maxX())
    15301530        drawLineForBoxSide(graphicsContext,
    1531             max(!nextline.isEmpty() ? paintOffset.x() + nextline.maxX() : -1000000, left - outlineWidth),
    1532             bottom,
    1533             right + outlineWidth,
    1534             bottom + outlineWidth,
     1531            max(!nextline.isEmpty() ? paintOffset.x() + nextline.maxX() : -1000000, pixelSnappedBox.x() - outlineWidth),
     1532            pixelSnappedBox.maxY(),
     1533            pixelSnappedBox.maxX() + outlineWidth,
     1534            pixelSnappedBox.maxY() + outlineWidth,
    15351535            BSBottom, outlineColor, outlineStyle,
    1536             (!nextline.isEmpty() && left - outlineWidth < paintOffset.x() + nextline.maxX()) ? -outlineWidth : outlineWidth,
     1536            (!nextline.isEmpty() && pixelSnappedBox.x() - outlineWidth < paintOffset.x() + nextline.maxX()) ? -outlineWidth : outlineWidth,
    15371537            outlineWidth, antialias);
    15381538
    15391539    if (thisline.x() == thisline.maxX())
    15401540          drawLineForBoxSide(graphicsContext,
    1541             left - outlineWidth,
    1542             bottom,
    1543             right + outlineWidth,
    1544             bottom + outlineWidth,
     1541            pixelSnappedBox.x() - outlineWidth,
     1542            pixelSnappedBox.maxY(),
     1543            pixelSnappedBox.maxX() + outlineWidth,
     1544            pixelSnappedBox.maxY() + outlineWidth,
    15451545            BSBottom, outlineColor, outlineStyle,
    15461546            outlineWidth,
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r108690 r108719  
    808808}
    809809
    810 void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, LayoutUnit x1, LayoutUnit y1, LayoutUnit x2, LayoutUnit y2,
     810void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
    811811                                      BoxSide side, Color color, EBorderStyle style,
    812812                                      int adjacentWidth1, int adjacentWidth2, bool antialias)
     
    983983                bool wasAntialiased = graphicsContext->shouldAntialias();
    984984                graphicsContext->setShouldAntialias(antialias);
    985                 graphicsContext->drawRect(pixelSnappedIntRect(LayoutRect(x1, y1, x2 - x1, y2 - y1)));
     985                graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1));
    986986                graphicsContext->setShouldAntialias(wasAntialiased);
    987987                graphicsContext->setStrokeStyle(oldStrokeStyle);
     
    11421142    Color outlineColor = styleToUse->visitedDependentColor(CSSPropertyOutlineColor);
    11431143
    1144     LayoutUnit outlineOffset = styleToUse->outlineOffset();
     1144    int outlineOffset = styleToUse->outlineOffset();
    11451145
    11461146    if (styleToUse->outlineStyleIsAuto() || hasOutlineAnnotation()) {
     
    11541154        return;
    11551155
    1156     LayoutRect inner = paintRect;
     1156    IntRect inner = pixelSnappedIntRect(paintRect);
    11571157    inner.inflate(outlineOffset);
    11581158
    1159     LayoutRect outer = inner;
     1159    IntRect outer = pixelSnappedIntRect(inner);
    11601160    outer.inflate(outlineWidth);
    11611161
     
    11791179    }
    11801180
    1181     LayoutUnit leftOuter = outer.x();
    1182     LayoutUnit leftInner = inner.x();
    1183     LayoutUnit rightOuter = outer.maxX();
    1184     LayoutUnit rightInner = inner.maxX();
    1185     LayoutUnit topOuter = outer.y();
    1186     LayoutUnit topInner = inner.y();
    1187     LayoutUnit bottomOuter = outer.maxY();
    1188     LayoutUnit bottomInner = inner.maxY();
     1181    int leftOuter = outer.x();
     1182    int leftInner = inner.x();
     1183    int rightOuter = outer.maxX();
     1184    int rightInner = inner.maxX();
     1185    int topOuter = outer.y();
     1186    int topInner = inner.y();
     1187    int bottomOuter = outer.maxY();
     1188    int bottomInner = inner.maxY();
    11891189   
    11901190    drawLineForBoxSide(graphicsContext, leftOuter, topOuter, leftInner, bottomOuter, BSLeft, outlineColor, outlineStyle, outlineWidth, outlineWidth);
  • trunk/Source/WebCore/rendering/RenderObject.h

    r108699 r108719  
    862862    void propagateStyleToAnonymousChildren(bool blockChildrenOnly = false);
    863863
    864     void drawLineForBoxSide(GraphicsContext*, LayoutUnit x1, LayoutUnit y1, LayoutUnit x2, LayoutUnit y2, BoxSide,
     864    void drawLineForBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2, BoxSide,
    865865                            Color, EBorderStyle, int adjbw1, int adjbw2, bool antialias = false);
    866866
Note: See TracChangeset for help on using the changeset viewer.