Title: [109835] trunk/Source/WebCore
Revision
109835
Author
[email protected]
Date
2012-03-05 18:42:55 -0800 (Mon, 05 Mar 2012)

Log Message

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

Reviewed by Julien Chaffraix.

Updating the usage of integers versus LayoutUnits in RenderBox to mirror the
subpixellayout branch. This reverts absoluteRects, intrinsicSize, and focusRingRects
methods to use integers, and flipForWritingMode functions to LayoutUnits.

No new tests. No change in behavior.

* platform/graphics/FractionalLayoutRect.h:
(WebCore::FractionalLayoutRect::pixelSnappedX): Convenience methods that only calculate
the needed values. This requires less computation than pixelSnappedIntRect(r).x().
(WebCore::FractionalLayoutRect::pixelSnappedY): Ditto.
(WebCore::FractionalLayoutRect::pixelSnappedWidth): Ditto.
(WebCore::FractionalLayoutRect::pixelSnappedHeight): Ditto.
(WebCore::FractionalLayoutRect::pixelSnappedMaxX): Ditto.
(WebCore::FractionalLayoutRect::pixelSnappedMaxY): Ditto.
(FractionalLayoutRect):
* platform/graphics/IntRect.h:
(IntRect):
(WebCore::IntRect::pixelSnappedX): Stub methods to allow us to use IntRects like we do
FractionalLayoutRects.
(WebCore::IntRect::pixelSnappedY): Ditto.
(WebCore::IntRect::pixelSnappedMaxX): Ditto.
(WebCore::IntRect::pixelSnappedMaxY): Ditto.
(WebCore::IntRect::pixelSnappedWidth): Ditto.
(WebCore::IntRect::pixelSnappedHeight): Ditto.
* rendering/LayoutTypes.h:
(WebCore::pixelSnappedIntRect): Convenience method for building a pixelSnappedIntRect from
a LayoutPoint and LayoutSize without constructing an intermediate LayoutRect.
(WebCore):
(WebCore::snapSizeToPixel): Stub method for snapping a LayoutUnit representing a size to
its pixel value using its location.
* rendering/RenderBox.cpp:
(WebCore::RenderBox::pixelSnappedClientWidth): Changing to actually call snapSizeToPixel.
(WebCore::RenderBox::pixelSnappedClientHeight): Ditto.
(WebCore::RenderBox::absoluteRects): Switching to return IntRects that represent the actual
rendered location on screen.
(WebCore::RenderBox::addFocusRingRects): Ditto.
(WebCore::RenderBox::paintFillLayer): One-liner switching an IntSize() to LayoutSize() to
avoid unnecessary conversion.
(WebCore::RenderBox::shrinkLogicalWidthToAvoidFloats): Preparing for the conversion by
replacing 0 with zeroLayoutUnit.
(WebCore::RenderBox::positionLineBox): Preparing for conversion by replacing lroundf
with roundedLayoutUnit.
(WebCore::RenderBox::flipForWritingMode): Switching to use LayoutUnits.
* rendering/RenderBox.h:
(RenderBox):
(WebCore::RenderBox::pixelSnappedBorderBoxRect): Convenience method.
(WebCore::RenderBox::borderBoundingBox): Converting to a pixelSnappedIntRect.
(WebCore::RenderBox::intrinsicSize): Intrinsic sizes should always be integers.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (109834 => 109835)


--- trunk/Source/WebCore/ChangeLog	2012-03-06 02:40:05 UTC (rev 109834)
+++ trunk/Source/WebCore/ChangeLog	2012-03-06 02:42:55 UTC (rev 109835)
@@ -1,3 +1,59 @@
+2012-03-05  Levi Weintraub  <[email protected]>
+
+        Update usage of LayoutUnits in RenderBox
+        https://bugs.webkit.org/show_bug.cgi?id=80039
+
+        Reviewed by Julien Chaffraix.
+
+        Updating the usage of integers versus LayoutUnits in RenderBox to mirror the
+        subpixellayout branch. This reverts absoluteRects, intrinsicSize, and focusRingRects
+        methods to use integers, and flipForWritingMode functions to LayoutUnits.
+
+        No new tests. No change in behavior.
+
+        * platform/graphics/FractionalLayoutRect.h:
+        (WebCore::FractionalLayoutRect::pixelSnappedX): Convenience methods that only calculate
+        the needed values. This requires less computation than pixelSnappedIntRect(r).x().
+        (WebCore::FractionalLayoutRect::pixelSnappedY): Ditto.
+        (WebCore::FractionalLayoutRect::pixelSnappedWidth): Ditto.
+        (WebCore::FractionalLayoutRect::pixelSnappedHeight): Ditto.
+        (WebCore::FractionalLayoutRect::pixelSnappedMaxX): Ditto.
+        (WebCore::FractionalLayoutRect::pixelSnappedMaxY): Ditto.
+        (FractionalLayoutRect):
+        * platform/graphics/IntRect.h:
+        (IntRect):
+        (WebCore::IntRect::pixelSnappedX): Stub methods to allow us to use IntRects like we do
+        FractionalLayoutRects.
+        (WebCore::IntRect::pixelSnappedY): Ditto.
+        (WebCore::IntRect::pixelSnappedMaxX): Ditto.
+        (WebCore::IntRect::pixelSnappedMaxY): Ditto.
+        (WebCore::IntRect::pixelSnappedWidth): Ditto.
+        (WebCore::IntRect::pixelSnappedHeight): Ditto.
+        * rendering/LayoutTypes.h:
+        (WebCore::pixelSnappedIntRect): Convenience method for building a pixelSnappedIntRect from
+        a LayoutPoint and LayoutSize without constructing an intermediate LayoutRect.
+        (WebCore):
+        (WebCore::snapSizeToPixel): Stub method for snapping a LayoutUnit representing a size to
+        its pixel value using its location.
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::pixelSnappedClientWidth): Changing to actually call snapSizeToPixel.
+        (WebCore::RenderBox::pixelSnappedClientHeight): Ditto.
+        (WebCore::RenderBox::absoluteRects): Switching to return IntRects that represent the actual
+        rendered location on screen.
+        (WebCore::RenderBox::addFocusRingRects): Ditto.
+        (WebCore::RenderBox::paintFillLayer): One-liner switching an IntSize() to LayoutSize() to
+        avoid unnecessary conversion.
+        (WebCore::RenderBox::shrinkLogicalWidthToAvoidFloats): Preparing for the conversion by
+        replacing 0 with zeroLayoutUnit.
+        (WebCore::RenderBox::positionLineBox): Preparing for conversion by replacing lroundf
+        with roundedLayoutUnit.
+        (WebCore::RenderBox::flipForWritingMode): Switching to use LayoutUnits.
+        * rendering/RenderBox.h:
+        (RenderBox):
+        (WebCore::RenderBox::pixelSnappedBorderBoxRect): Convenience method.
+        (WebCore::RenderBox::borderBoundingBox): Converting to a pixelSnappedIntRect.
+        (WebCore::RenderBox::intrinsicSize): Intrinsic sizes should always be integers.
+
 2012-03-05  Adam Barth  <[email protected]>
 
         WorkerContext shouldn't need to know about SQLDatabase

Modified: trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.h (109834 => 109835)


--- trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.h	2012-03-06 02:40:05 UTC (rev 109834)
+++ trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.h	2012-03-06 02:42:55 UTC (rev 109835)
@@ -65,6 +65,13 @@
     FractionalLayoutUnit width() const { return m_size.width(); }
     FractionalLayoutUnit height() const { return m_size.height(); }
 
+    int pixelSnappedX() const { return x().round(); }
+    int pixelSnappedY() const { return y().round(); }
+    int pixelSnappedWidth() const { return snapSizeToPixel(width(), x()); }
+    int pixelSnappedHeight() const { return snapSizeToPixel(height(), y()); }
+    int pixelSnappedMaxX() const { return pixelSnappedX() + pixelSnappedWidth(); }
+    int pixelSnappedMaxY() const { return pixelSnappedY() + pixelSnappedHeight(); }
+
     void setX(FractionalLayoutUnit x) { m_location.setX(x); }
     void setY(FractionalLayoutUnit y) { m_location.setY(y); }
     void setWidth(FractionalLayoutUnit width) { m_size.setWidth(width); }

Modified: trunk/Source/WebCore/platform/graphics/IntRect.h (109834 => 109835)


--- trunk/Source/WebCore/platform/graphics/IntRect.h	2012-03-06 02:40:05 UTC (rev 109834)
+++ trunk/Source/WebCore/platform/graphics/IntRect.h	2012-03-06 02:42:55 UTC (rev 109835)
@@ -103,6 +103,15 @@
     int width() const { return m_size.width(); }
     int height() const { return m_size.height(); }
 
+    // FIXME: These methods are here only to ease the transition to sub-pixel layout. They should
+    // be removed when we close http://webkit.org/b/60318
+    int pixelSnappedX() const { return m_location.x(); }
+    int pixelSnappedY() const { return m_location.y(); }
+    int pixelSnappedMaxX() const { return x() + width(); }
+    int pixelSnappedMaxY() const { return y() + height(); }
+    int pixelSnappedWidth() const { return m_size.width(); }
+    int pixelSnappedHeight() const { return m_size.height(); }
+
     void setX(int x) { m_location.setX(x); }
     void setY(int y) { m_location.setY(y); }
     void setWidth(int width) { m_size.setWidth(width); }

Modified: trunk/Source/WebCore/rendering/LayoutTypes.h (109834 => 109835)


--- trunk/Source/WebCore/rendering/LayoutTypes.h	2012-03-06 02:40:05 UTC (rev 109834)
+++ trunk/Source/WebCore/rendering/LayoutTypes.h	2012-03-06 02:42:55 UTC (rev 109835)
@@ -38,6 +38,7 @@
 
 #include "FloatRect.h"
 #include "IntRect.h"
+#include <wtf/UnusedParam.h>
 
 namespace WebCore {
 
@@ -63,11 +64,22 @@
     return IntRect(left, top, width, height);
 }
 
+inline IntRect pixelSnappedIntRect(const LayoutPoint& location, const LayoutSize& size)
+{
+    return IntRect(location, size);
+}
+
 inline IntRect pixelSnappedIntRectFromEdges(LayoutUnit left, LayoutUnit top, LayoutUnit right, LayoutUnit bottom)
 {
     return IntRect(left, top, right - left, bottom - top);
 }
 
+inline int snapSizeToPixel(LayoutUnit size, LayoutUnit location) 
+{
+    UNUSED_PARAM(location);
+    return size;
+}
+
 inline IntSize roundedIntSize(const LayoutSize& s)
 {
     return s;

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (109834 => 109835)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2012-03-06 02:40:05 UTC (rev 109834)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2012-03-06 02:42:55 UTC (rev 109835)
@@ -480,12 +480,12 @@
 
 int RenderBox::pixelSnappedClientWidth() const
 {
-    return clientWidth();
+    return snapSizeToPixel(clientWidth(), clientLeft());
 }
 
 int RenderBox::pixelSnappedClientHeight() const
 {
-    return clientHeight();
+    return snapSizeToPixel(clientHeight(), clientTop());
 }
 
 int RenderBox::scrollWidth() const
@@ -532,7 +532,7 @@
 
 void RenderBox::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumulatedOffset) const
 {
-    rects.append(LayoutRect(accumulatedOffset, size()));
+    rects.append(pixelSnappedIntRect(accumulatedOffset, size()));
 }
 
 void RenderBox::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
@@ -581,10 +581,10 @@
     return box;
 }
 
-void RenderBox::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPoint& additionalOffset)
+void RenderBox::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint& additionalOffset)
 {
     if (!size().isEmpty())
-        rects.append(LayoutRect(additionalOffset, size()));
+        rects.append(pixelSnappedIntRect(additionalOffset, size()));
 }
 
 LayoutRect RenderBox::reflectionBox() const
@@ -1078,7 +1078,7 @@
 void RenderBox::paintFillLayer(const PaintInfo& paintInfo, const Color& c, const FillLayer* fillLayer, const LayoutRect& rect,
     BackgroundBleedAvoidance bleedAvoidance, CompositeOperator op, RenderObject* backgroundObject)
 {
-    paintFillLayerExtended(paintInfo, c, fillLayer, rect, bleedAvoidance, 0, IntSize(), op, backgroundObject);
+    paintFillLayerExtended(paintInfo, c, fillLayer, rect, bleedAvoidance, 0, LayoutSize(), op, backgroundObject);
 }
 
 #if USE(ACCELERATED_COMPOSITING)
@@ -1276,7 +1276,7 @@
     LayoutUnit logicalTopPosition = logicalTop();
     LayoutUnit adjustedPageOffsetForContainingBlock = offsetFromLogicalTopOfFirstPage - logicalTop();
     if (region) {
-        LayoutUnit offsetFromLogicalTopOfRegion = region ? region->offsetFromLogicalTopOfFirstPage() - offsetFromLogicalTopOfFirstPage : 0;
+        LayoutUnit offsetFromLogicalTopOfRegion = region ? region->offsetFromLogicalTopOfFirstPage() - offsetFromLogicalTopOfFirstPage : zeroLayoutUnit;
         logicalTopPosition = max(logicalTopPosition, logicalTopPosition + offsetFromLogicalTopOfRegion);
         containingBlockRegion = cb->clampToStartAndEndRegions(region);
     }
@@ -1484,7 +1484,7 @@
             // our object was inline originally, since otherwise it would have ended up underneath
             // the inlines.
             RootInlineBox* root = box->root();
-            root->block()->setStaticInlinePositionForChild(this, root->lineTopWithLeading(), lroundf(box->logicalLeft()));
+            root->block()->setStaticInlinePositionForChild(this, root->lineTopWithLeading(), roundedLayoutUnit(box->logicalLeft()));
             if (style()->hasStaticInlinePosition(box->isHorizontal()))
                 setChildNeedsLayout(true, false); // Just go ahead and mark the positioned object as needing layout, so it will update its position properly.
         } else {
@@ -3895,7 +3895,7 @@
     return LayoutPoint(point.x() + width() - child->width() - (2 * child->x()), point.y());
 }
 
-void RenderBox::flipForWritingMode(IntRect& rect) const
+void RenderBox::flipForWritingMode(LayoutRect& rect) const
 {
     if (!style()->isFlippedBlocksWritingMode())
         return;
@@ -3906,18 +3906,18 @@
         rect.setX(width() - rect.maxX());
 }
 
-int RenderBox::flipForWritingMode(int position) const
+LayoutUnit RenderBox::flipForWritingMode(LayoutUnit position) const
 {
     if (!style()->isFlippedBlocksWritingMode())
         return position;
     return logicalHeight() - position;
 }
 
-IntPoint RenderBox::flipForWritingMode(const IntPoint& position) const
+LayoutPoint RenderBox::flipForWritingMode(const LayoutPoint& position) const
 {
     if (!style()->isFlippedBlocksWritingMode())
         return position;
-    return isHorizontalWritingMode() ? IntPoint(position.x(), height() - position.y()) : IntPoint(width() - position.x(), position.y());
+    return isHorizontalWritingMode() ? LayoutPoint(position.x(), height() - position.y()) : LayoutPoint(width() - position.x(), position.y());
 }
 
 LayoutPoint RenderBox::flipForWritingModeIncludingColumns(const LayoutPoint& point) const
@@ -3927,11 +3927,11 @@
     return toRenderBlock(this)->flipForWritingModeIncludingColumns(point);
 }
 
-IntSize RenderBox::flipForWritingMode(const IntSize& offset) const
+LayoutSize RenderBox::flipForWritingMode(const LayoutSize& offset) const
 {
     if (!style()->isFlippedBlocksWritingMode())
         return offset;
-    return isHorizontalWritingMode() ? IntSize(offset.width(), height() - offset.height()) : IntSize(width() - offset.width(), offset.height());
+    return isHorizontalWritingMode() ? LayoutSize(offset.width(), height() - offset.height()) : LayoutSize(width() - offset.width(), offset.height());
 }
 
 FloatPoint RenderBox::flipForWritingMode(const FloatPoint& position) const

Modified: trunk/Source/WebCore/rendering/RenderBox.h (109834 => 109835)


--- trunk/Source/WebCore/rendering/RenderBox.h	2012-03-06 02:40:05 UTC (rev 109834)
+++ trunk/Source/WebCore/rendering/RenderBox.h	2012-03-06 02:42:55 UTC (rev 109835)
@@ -127,8 +127,10 @@
     LayoutRect frameRect() const { return m_frameRect; }
     void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
 
+    // FIXME: We shouldn't be returning this as a LayoutRect, since it loses its position and won't properly pixel snap.
     LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
-    virtual LayoutRect borderBoundingBox() const { return borderBoxRect(); } 
+    IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), IntSize(m_frameRect.pixelSnappedWidth(), m_frameRect.pixelSnappedHeight())); }
+    virtual IntRect borderBoundingBox() const { return pixelSnappedBorderBoxRect(); }
 
     // The content area of the box (excludes padding and border).
     LayoutRect contentBoxRect(PaddingOptions paddingOption = ExcludeIntrinsicPadding) const { return LayoutRect(borderLeft() + paddingLeft(paddingOption), borderTop() + paddingTop(paddingOption), contentWidth(paddingOption), contentHeight(paddingOption)); }
@@ -139,7 +141,7 @@
 
     // Bounds of the outline box in absolute coords. Respects transforms
     virtual LayoutRect outlineBoundsForRepaint(RenderBoxModelObject* /*repaintContainer*/, LayoutPoint* cachedOffsetToRepaintContainer) const;
-    virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint&);
+    virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint&);
 
     // Use this with caution! No type checking is done!
     RenderBox* previousSiblingBox() const;
@@ -246,7 +248,7 @@
     virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
     virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
 
-    virtual void absoluteRects(Vector<LayoutRect>&, const LayoutPoint& accumulatedOffset) const;
+    virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
     
     LayoutRect reflectionBox() const;
@@ -321,7 +323,7 @@
         return document()->inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrPositioned() && (isRoot() || isBody());
     }
 
-    virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
+    virtual IntSize intrinsicSize() const { return IntSize(); }
     LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
     LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
 
@@ -424,11 +426,11 @@
     virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
 
     LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
-    int flipForWritingMode(int position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
-    IntPoint flipForWritingMode(const IntPoint&) const;
+    LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
+    LayoutPoint flipForWritingMode(const LayoutPoint&) const;
     LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
-    IntSize flipForWritingMode(const IntSize&) const;
-    void flipForWritingMode(IntRect&) const;
+    LayoutSize flipForWritingMode(const LayoutSize&) const;
+    void flipForWritingMode(LayoutRect&) const;
     FloatPoint flipForWritingMode(const FloatPoint&) const;
     void flipForWritingMode(FloatRect&) const;
     // These represent your location relative to your container as a physical offset.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to