Changeset 111066 in webkit


Ignore:
Timestamp:
Mar 16, 2012 2:30:11 PM (12 years ago)
Author:
eae@chromium.org
Message:

Fix rounding and usage of LayoutUnits in RenderBoxModelObject
https://bugs.webkit.org/show_bug.cgi?id=81057

Reviewed by Julien Chaffraix.

No new tests.

(WebCore):

  • rendering/RenderBoxModelObject.cpp:

(WebCore::RenderBoxModelObject::pixelSnappedOffsetWidth):
(WebCore::RenderBoxModelObject::pixelSnappedOffsetHeight):
Fix implementation of pixelSnappedOffsetWidth/Height. The location
parameter will be ignored until we enable subpixel support.

(WebCore::RenderBoxModelObject::paintFillLayerExtended):
Use ints for border widths.

(WebCore::resolveWidthForRatio):
(WebCore::resolveHeightForRatio):
(WebCore::resolveAgainstIntrinsicWidthOrHeightAndRatio):
(WebCore::resolveAgainstIntrinsicRatio):
Change resolve*Ratio methods to operate on IntSizes as none of the
callers need subpixel precision.

(WebCore::RenderBoxModelObject::calculateBackgroundImageGeometry):
(WebCore::RenderBoxModelObject::paintNinePieceImage):
Pixel snap paintRect when computing image geometry.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r111064 r111066  
     12012-03-16  Emil A Eklund  <eae@chromium.org>
     2
     3        Fix rounding and usage of LayoutUnits in RenderBoxModelObject
     4        https://bugs.webkit.org/show_bug.cgi?id=81057
     5
     6        Reviewed by Julien Chaffraix.
     7
     8        No new tests.
     9
     10        (WebCore):
     11        * rendering/RenderBoxModelObject.cpp:
     12        (WebCore::RenderBoxModelObject::pixelSnappedOffsetWidth):
     13        (WebCore::RenderBoxModelObject::pixelSnappedOffsetHeight):
     14        Fix implementation of pixelSnappedOffsetWidth/Height. The location
     15        parameter will be ignored until we enable subpixel support.
     16
     17        (WebCore::RenderBoxModelObject::paintFillLayerExtended):
     18        Use ints for border widths.
     19       
     20        (WebCore::resolveWidthForRatio):
     21        (WebCore::resolveHeightForRatio):
     22        (WebCore::resolveAgainstIntrinsicWidthOrHeightAndRatio):
     23        (WebCore::resolveAgainstIntrinsicRatio):
     24        Change resolve*Ratio methods to operate on IntSizes as none of the
     25        callers need subpixel precision.
     26
     27        (WebCore::RenderBoxModelObject::calculateBackgroundImageGeometry):
     28        (WebCore::RenderBoxModelObject::paintNinePieceImage):
     29        Pixel snap paintRect when computing image geometry.
     30
    1312012-03-16  Terry Anderson  <tdanderson@chromium.org>
    232
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp

    r110769 r111066  
    543543int RenderBoxModelObject::pixelSnappedOffsetWidth() const
    544544{
    545     return offsetWidth();
     545    return snapSizeToPixel(offsetWidth(), offsetLeft());
    546546}
    547547
    548548int RenderBoxModelObject::pixelSnappedOffsetHeight() const
    549549{
    550     return offsetHeight();
     550    return snapSizeToPixel(offsetHeight(), offsetTop());
    551551}
    552552
     
    732732    }
    733733   
    734     LayoutUnit bLeft = includeLeftEdge ? borderLeft() : zeroLayoutUnit;
    735     LayoutUnit bRight = includeRightEdge ? borderRight() : zeroLayoutUnit;
     734    int bLeft = includeLeftEdge ? borderLeft() : 0;
     735    int bRight = includeRightEdge ? borderRight() : 0;
    736736    LayoutUnit pLeft = includeLeftEdge ? paddingLeft() : zeroLayoutUnit;
    737737    LayoutUnit pRight = includeRightEdge ? paddingRight() : zeroLayoutUnit;
     
    880880}
    881881
    882 static inline LayoutUnit resolveWidthForRatio(LayoutUnit height, const FloatSize& intrinsicRatio)
    883 {
    884     // FIXME: Remove unnecessary rounding when layout is off ints: webkit.org/b/63656
    885     return static_cast<LayoutUnit>(ceilf(height * intrinsicRatio.width() / intrinsicRatio.height()));
    886 }
    887 
    888 static inline LayoutUnit resolveHeightForRatio(LayoutUnit width, const FloatSize& intrinsicRatio)
    889 {
    890     // FIXME: Remove unnecessary rounding when layout is off ints: webkit.org/b/63656
    891     return static_cast<LayoutUnit>(ceilf(width * intrinsicRatio.height() / intrinsicRatio.width()));
    892 }
    893 
    894 static inline LayoutSize resolveAgainstIntrinsicWidthOrHeightAndRatio(const LayoutSize& size, const FloatSize& intrinsicRatio, LayoutUnit useWidth, LayoutUnit useHeight)
     882static inline int resolveWidthForRatio(int height, const FloatSize& intrinsicRatio)
     883{
     884    return ceilf(height * intrinsicRatio.width() / intrinsicRatio.height());
     885}
     886
     887static inline int resolveHeightForRatio(int width, const FloatSize& intrinsicRatio)
     888{
     889    return ceilf(width * intrinsicRatio.height() / intrinsicRatio.width());
     890}
     891
     892static inline IntSize resolveAgainstIntrinsicWidthOrHeightAndRatio(const IntSize& size, const FloatSize& intrinsicRatio, int useWidth, int useHeight)
    895893{
    896894    if (intrinsicRatio.isEmpty()) {
    897895        if (useWidth)
    898             return LayoutSize(useWidth, size.height());
    899         return LayoutSize(size.width(), useHeight);
     896            return IntSize(useWidth, size.height());
     897        return IntSize(size.width(), useHeight);
    900898    }
    901899
    902900    if (useWidth)
    903         return LayoutSize(useWidth, resolveHeightForRatio(useWidth, intrinsicRatio));
    904     return LayoutSize(resolveWidthForRatio(useHeight, intrinsicRatio), useHeight);
    905 }
    906 
    907 static inline LayoutSize resolveAgainstIntrinsicRatio(const LayoutSize& size, const FloatSize& intrinsicRatio)
     901        return IntSize(useWidth, resolveHeightForRatio(useWidth, intrinsicRatio));
     902    return IntSize(resolveWidthForRatio(useHeight, intrinsicRatio), useHeight);
     903}
     904
     905static inline IntSize resolveAgainstIntrinsicRatio(const IntSize& size, const FloatSize& intrinsicRatio)
    908906{
    909907    // Two possible solutions: (size.width(), solutionHeight) or (solutionWidth, size.height())
    910908    // "... must be assumed to be the largest dimensions..." = easiest answer: the rect with the largest surface area.
    911909
    912     LayoutUnit solutionWidth = resolveWidthForRatio(size.height(), intrinsicRatio);
    913     LayoutUnit solutionHeight = resolveHeightForRatio(size.width(), intrinsicRatio);
     910    int solutionWidth = resolveWidthForRatio(size.height(), intrinsicRatio);
     911    int solutionHeight = resolveHeightForRatio(size.width(), intrinsicRatio);
    914912    if (solutionWidth <= size.width()) {
    915913        if (solutionHeight <= size.height()) {
    916914            // If both solutions fit, choose the one covering the larger area.
    917             LayoutUnit areaOne = solutionWidth * size.height();
    918             LayoutUnit areaTwo = size.width() * solutionHeight;
     915            int areaOne = solutionWidth * size.height();
     916            int areaTwo = size.width() * solutionHeight;
    919917            if (areaOne < areaTwo)
    920                 return LayoutSize(size.width(), solutionHeight);
    921             return LayoutSize(solutionWidth, size.height());
     918                return IntSize(size.width(), solutionHeight);
     919            return IntSize(solutionWidth, size.height());
    922920        }
    923921
    924922        // Only the first solution fits.
    925         return LayoutSize(solutionWidth, size.height());
     923        return IntSize(solutionWidth, size.height());
    926924    }
    927925
    928926    // Only the second solution fits, assert that.
    929927    ASSERT(solutionHeight <= size.height());
    930     return LayoutSize(size.width(), solutionHeight);
     928    return IntSize(size.width(), solutionHeight);
    931929}
    932930
     
    10841082    LayoutUnit top = 0;
    10851083    IntSize positioningAreaSize;
     1084    IntRect snappedPaintRect = pixelSnappedIntRect(paintRect);
    10861085
    10871086    // Determine the background positioning area and set destRect to the background painting area.
     
    11001099
    11011100    if (!fixedAttachment) {
    1102         geometry.setDestRect(paintRect);
     1101        geometry.setDestRect(snappedPaintRect);
    11031102
    11041103        LayoutUnit right = 0;
     
    11221121        // the background positioning area.
    11231122        if (isRoot()) {
    1124             positioningAreaSize = LayoutSize(toRenderBox(this)->width() - left - right, toRenderBox(this)->height() - top - bottom);
     1123            positioningAreaSize = IntSize(snapSizeToPixel(toRenderBox(this)->width() - left - right, toRenderBox(this)->x()),
     1124                                          snapSizeToPixel(toRenderBox(this)->height() - top - bottom, toRenderBox(this)->y()));
    11251125            left += marginLeft();
    11261126            top += marginTop();
    11271127        } else
    1128             positioningAreaSize = LayoutSize(paintRect.width() - left - right, paintRect.height() - top - bottom);
     1128            positioningAreaSize = IntSize(snapSizeToPixel(paintRect.width() - left - right, paintRect.x()),
     1129                                          snapSizeToPixel(paintRect.height() - top - bottom, paintRect.y()));
    11291130    } else {
    11301131        geometry.setDestRect(pixelSnappedIntRect(viewRect()));
     
    11411142    LayoutUnit xPosition = fillLayer->xPosition().calcMinValue(positioningAreaSize.width() - geometry.tileSize().width(), true);
    11421143    if (backgroundRepeatX == RepeatFill)
    1143         geometry.setPhaseX(geometry.tileSize().width() ? layoutMod(geometry.tileSize().width() - (xPosition + left), geometry.tileSize().width()) : LayoutUnit(0));
     1144        geometry.setPhaseX(geometry.tileSize().width() ? geometry.tileSize().width() - (xPosition + left) % geometry.tileSize().width() : 0);
    11441145    else
    11451146        geometry.setNoRepeatX(xPosition + left);
     
    11471148    LayoutUnit yPosition = fillLayer->yPosition().calcMinValue(positioningAreaSize.height() - geometry.tileSize().height(), true);
    11481149    if (backgroundRepeatY == RepeatFill)
    1149         geometry.setPhaseY(geometry.tileSize().height() ? layoutMod(geometry.tileSize().height() - (yPosition + top), geometry.tileSize().height()) : LayoutUnit(0));
     1150        geometry.setPhaseY(geometry.tileSize().height() ? geometry.tileSize().height() - (yPosition + top) % geometry.tileSize().height() : 0);
    11501151    else
    11511152        geometry.setNoRepeatY(yPosition + top);
    11521153
    11531154    if (fixedAttachment)
    1154         geometry.useFixedAttachment(paintRect.location());
    1155 
    1156     geometry.clip(paintRect);
     1155        geometry.useFixedAttachment(snappedPaintRect.location());
     1156
     1157    geometry.clip(snappedPaintRect);
    11571158    geometry.setDestOrigin(geometry.destRect().location());
    11581159}
     
    11921193    LayoutUnit leftWithOutset = rect.x() - leftOutset;
    11931194    LayoutUnit rightWithOutset = rect.maxX() + rightOutset;
    1194     LayoutRect borderImageRect = LayoutRect(leftWithOutset, topWithOutset, rightWithOutset - leftWithOutset, bottomWithOutset - topWithOutset);
     1195    IntRect borderImageRect = pixelSnappedIntRect(leftWithOutset, topWithOutset, rightWithOutset - leftWithOutset, bottomWithOutset - topWithOutset);
    11951196
    11961197    IntSize imageSize = calculateImageIntrinsicDimensions(styleImage, borderImageRect.size());
Note: See TracChangeset for help on using the changeset viewer.