Title: [125167] trunk
Revision
125167
Author
[email protected]
Date
2012-08-09 05:20:30 -0700 (Thu, 09 Aug 2012)

Log Message

Floored and truncated rounded confused.
https://bugs.webkit.org/show_bug.cgi?id=93475

Reviewed by Levi Weintraub.

Source/WebCore:

Fix the common mistake of confusing truncating (round towards zero) and
flooring (round down). They are only identical for positive numbers,
not for negative numbers.

This patch fixes instances of misimplemented or misused floor in the
layout and geometric code. And also uses the new correct implementations
to clean up the code for enclosingRect.

* platform/FractionalLayoutUnit.h:
(WebCore::FractionalLayoutUnit::fromFloatFloor):
(FractionalLayoutUnit):
(WebCore::FractionalLayoutUnit::ceil):
(WebCore::FractionalLayoutUnit::floor):
* platform/graphics/FloatPoint.h:
(WebCore::FloatPoint::FloatPoint):
(WebCore::roundedIntPoint):
(WebCore::flooredIntPoint):
(WebCore::ceiledIntPoint):
(WebCore::flooredIntSize):
* platform/graphics/FloatRect.cpp:
(WebCore::enclosingIntRect):
(WebCore::enclosedIntRect):
* platform/graphics/FloatSize.h:
(WebCore::roundedIntSize):
(WebCore::flooredIntSize):
(WebCore::flooredIntPoint):
* platform/graphics/FractionalLayoutPoint.h:
(WebCore::flooredIntPoint):
(WebCore::flooredFractionalLayoutPoint):
(WebCore::ceiledFractionalLayoutPoint):
* platform/graphics/FractionalLayoutRect.cpp:
(WebCore::enclosingIntRect):
(WebCore::enclosingFractionalLayoutRect):
* platform/graphics/FractionalLayoutSize.h:
(WebCore::flooredIntSize):
* platform/graphics/IntRect.cpp:
(WebCore::IntRect::IntRect):
* rendering/LayoutTypes.h:
(WebCore::flooredLayoutPoint):
(WebCore::floorToInt):
(WebCore::isIntegerValue):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::convertToLayerCoords):

LayoutTests:

* platform/chromium/TestExpectations:
* platform/mac/TestExpectations:
* platform/qt/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (125166 => 125167)


--- trunk/LayoutTests/ChangeLog	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/LayoutTests/ChangeLog	2012-08-09 12:20:30 UTC (rev 125167)
@@ -1,3 +1,14 @@
+2012-08-09  Allan Sandfeld Jensen  <[email protected]>
+
+        Floored and truncated rounded confused.
+        https://bugs.webkit.org/show_bug.cgi?id=93475
+
+        Reviewed by Levi Weintraub.
+
+        * platform/chromium/TestExpectations:
+        * platform/mac/TestExpectations:
+        * platform/qt/TestExpectations:
+
 2012-08-09  Pavel Feldman  <[email protected]>
 
         Web Inspector: improve large array logging experience

Modified: trunk/LayoutTests/platform/chromium/TestExpectations (125166 => 125167)


--- trunk/LayoutTests/platform/chromium/TestExpectations	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/LayoutTests/platform/chromium/TestExpectations	2012-08-09 12:20:30 UTC (rev 125167)
@@ -3489,3 +3489,6 @@
 
 BUGWK93586 : fast/forms/autocomplete-off-with-default-value-does-not-clear.html = TIMEOUT
 
+// Tests requiring rebaseling afer bug 93475
+BUGWK93475 : fast/block/float/overhanging-tall-block.html = TEXT
+BUGWK93475 : fast/html/details-writing-mode.html = IMAGE

Modified: trunk/LayoutTests/platform/mac/TestExpectations (125166 => 125167)


--- trunk/LayoutTests/platform/mac/TestExpectations	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2012-08-09 12:20:30 UTC (rev 125167)
@@ -335,3 +335,6 @@
 
 // (r124484) inspector/device-orientation-success.html failing on Mac ports
 BUGWK93552 : inspector/device-orientation-success.html = TEXT
+
+// Tests requiring rebaseling afer bug 93475
+BUGWK93475 : fast/block/float/overhanging-tall-block.html = TEXT

Modified: trunk/LayoutTests/platform/qt/TestExpectations (125166 => 125167)


--- trunk/LayoutTests/platform/qt/TestExpectations	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/LayoutTests/platform/qt/TestExpectations	2012-08-09 12:20:30 UTC (rev 125167)
@@ -137,3 +137,6 @@
 BUGWK93148 : fast/css/nested-layers-with-hover.html = TEXT
 
 BUGWK93247 DEBUG : fast/lists/list-marker-remove-crash.html = CRASH
+
+// Test requiring rebaseling afer bug 93475
+BUGWK93475 : fast/block/float/overhanging-tall-block.html = TEXT

Modified: trunk/Source/WebCore/ChangeLog (125166 => 125167)


--- trunk/Source/WebCore/ChangeLog	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/ChangeLog	2012-08-09 12:20:30 UTC (rev 125167)
@@ -1,3 +1,54 @@
+2012-08-09  Allan Sandfeld Jensen  <[email protected]>
+
+        Floored and truncated rounded confused.
+        https://bugs.webkit.org/show_bug.cgi?id=93475
+
+        Reviewed by Levi Weintraub.
+
+        Fix the common mistake of confusing truncating (round towards zero) and
+        flooring (round down). They are only identical for positive numbers,
+        not for negative numbers.
+
+        This patch fixes instances of misimplemented or misused floor in the
+        layout and geometric code. And also uses the new correct implementations
+        to clean up the code for enclosingRect.
+
+        * platform/FractionalLayoutUnit.h:
+        (WebCore::FractionalLayoutUnit::fromFloatFloor):
+        (FractionalLayoutUnit):
+        (WebCore::FractionalLayoutUnit::ceil):
+        (WebCore::FractionalLayoutUnit::floor):
+        * platform/graphics/FloatPoint.h:
+        (WebCore::FloatPoint::FloatPoint):
+        (WebCore::roundedIntPoint):
+        (WebCore::flooredIntPoint):
+        (WebCore::ceiledIntPoint):
+        (WebCore::flooredIntSize):
+        * platform/graphics/FloatRect.cpp:
+        (WebCore::enclosingIntRect):
+        (WebCore::enclosedIntRect):
+        * platform/graphics/FloatSize.h:
+        (WebCore::roundedIntSize):
+        (WebCore::flooredIntSize):
+        (WebCore::flooredIntPoint):
+        * platform/graphics/FractionalLayoutPoint.h:
+        (WebCore::flooredIntPoint):
+        (WebCore::flooredFractionalLayoutPoint):
+        (WebCore::ceiledFractionalLayoutPoint):
+        * platform/graphics/FractionalLayoutRect.cpp:
+        (WebCore::enclosingIntRect):
+        (WebCore::enclosingFractionalLayoutRect):
+        * platform/graphics/FractionalLayoutSize.h:
+        (WebCore::flooredIntSize):
+        * platform/graphics/IntRect.cpp:
+        (WebCore::IntRect::IntRect):
+        * rendering/LayoutTypes.h:
+        (WebCore::flooredLayoutPoint):
+        (WebCore::floorToInt):
+        (WebCore::isIntegerValue):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::convertToLayerCoords):
+
 2012-08-07  Andrey Kosyakov  <[email protected]>
 
         Web Inspector: use WebInspector.ProgressIndicator in AdvancedSearchController

Modified: trunk/Source/WebCore/platform/FractionalLayoutUnit.h (125166 => 125167)


--- trunk/Source/WebCore/platform/FractionalLayoutUnit.h	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/platform/FractionalLayoutUnit.h	2012-08-09 12:20:30 UTC (rev 125167)
@@ -95,6 +95,14 @@
         return v;
     }
 
+    static FractionalLayoutUnit fromFloatFloor(float value)
+    {
+        REPORT_OVERFLOW(isInBounds(value));
+        FractionalLayoutUnit v;
+        v.m_value = floorf(value * kFixedPointDenominator);
+        return v;
+    }
+
     static FractionalLayoutUnit fromFloatRound(float value)
     {
         if (value >= 0)
@@ -146,9 +154,9 @@
 #endif
     {
 #if ENABLE(SUBPIXEL_LAYOUT)
-        if (m_value > 0)
+        if (m_value >= 0)
             return (m_value + kFixedPointDenominator - 1) / kFixedPointDenominator;
-        return (m_value - kFixedPointDenominator + 1) / kFixedPointDenominator;
+        return toInt();
 #else
         return m_value;
 #endif
@@ -166,7 +174,13 @@
 
     int floor() const
     {
-        return toInt();
+#if ENABLE(SUBPIXEL_LAYOUT)
+        if (m_value >= 0)
+            return toInt();
+        return (m_value - kFixedPointDenominator + 1) / kFixedPointDenominator;
+#else
+        return m_value;
+#endif
     }
 
     static float epsilon() { return 1.0f / kFixedPointDenominator; }

Modified: trunk/Source/WebCore/platform/graphics/FloatPoint.h (125166 => 125167)


--- trunk/Source/WebCore/platform/graphics/FloatPoint.h	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/platform/graphics/FloatPoint.h	2012-08-09 12:20:30 UTC (rev 125167)
@@ -77,6 +77,7 @@
     FloatPoint(float x, float y) : m_x(x), m_y(y) { }
     FloatPoint(const IntPoint&);
     FloatPoint(const FractionalLayoutPoint&);
+    explicit FloatPoint(const FloatSize& size) : m_x(size.width()), m_y(size.height()) { }
 
     static FloatPoint zero() { return FloatPoint(); }
 
@@ -243,17 +244,22 @@
 
 inline IntPoint roundedIntPoint(const FloatPoint& p)
 {
-    return IntPoint(static_cast<int>(roundf(p.x())), static_cast<int>(roundf(p.y())));
+    return IntPoint(clampToInteger(roundf(p.x())), clampToInteger(roundf(p.y())));
 }
 
 inline IntPoint flooredIntPoint(const FloatPoint& p)
 {
-    return IntPoint(static_cast<int>(p.x()), static_cast<int>(p.y()));
+    return IntPoint(clampToInteger(floorf(p.x())), clampToInteger(floorf(p.y())));
 }
 
+inline IntPoint ceiledIntPoint(const FloatPoint& p)
+{
+    return IntPoint(clampToInteger(ceilf(p.x())), clampToInteger(ceilf(p.y())));
+}
+
 inline IntSize flooredIntSize(const FloatPoint& p)
 {
-    return IntSize(static_cast<int>(p.x()), static_cast<int>(p.y()));
+    return IntSize(clampToInteger(floorf(p.x())), clampToInteger(floorf(p.y())));
 }
 
 float findSlope(const FloatPoint& p1, const FloatPoint& p2, float& c);

Modified: trunk/Source/WebCore/platform/graphics/FloatRect.cpp (125166 => 125167)


--- trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2012-08-09 12:20:30 UTC (rev 125167)
@@ -214,26 +214,20 @@
 
 IntRect enclosingIntRect(const FloatRect& rect)
 {
-    float left = floorf(rect.x());
-    float top = floorf(rect.y());
-    float width = ceilf(rect.maxX()) - left;
-    float height = ceilf(rect.maxY()) - top;
-    
-    return IntRect(clampToInteger(left), clampToInteger(top), 
-                   clampToInteger(width), clampToInteger(height));
+    IntPoint location = flooredIntPoint(rect.minXMinYCorner());
+    IntPoint maxPoint = ceiledIntPoint(rect.maxXMaxYCorner());
+
+    return IntRect(location, maxPoint - location);
 }
 
 IntRect enclosedIntRect(const FloatRect& rect)
 {
-    int x = clampToInteger(ceilf(rect.x()));
-    int y = clampToInteger(ceilf(rect.y()));
-    float maxX = clampToInteger(floorf(rect.maxX()));
-    float maxY = clampToInteger(floorf(rect.maxY()));
-    // A rect of width 0 should not become a rect of width -1 due to ceil/floor.
-    int width = max(clampToInteger(maxX - x), 0);
-    int height = max(clampToInteger(maxY - y), 0);
+    IntPoint location = ceiledIntPoint(rect.minXMinYCorner());
+    IntPoint maxPoint = flooredIntPoint(rect.maxXMaxYCorner());
+    IntSize size = maxPoint - location;
+    size.clampNegativeToZero();
 
-    return IntRect(x, y, width, height);
+    return IntRect(location, size);
 }
 
 IntRect roundedIntRect(const FloatRect& rect)

Modified: trunk/Source/WebCore/platform/graphics/FloatSize.h (125166 => 125167)


--- trunk/Source/WebCore/platform/graphics/FloatSize.h	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/platform/graphics/FloatSize.h	2012-08-09 12:20:30 UTC (rev 125167)
@@ -186,12 +186,12 @@
 
 inline IntSize roundedIntSize(const FloatSize& p)
 {
-    return IntSize(static_cast<int>(roundf(p.width())), static_cast<int>(roundf(p.height())));
+    return IntSize(clampToInteger(roundf(p.width())), clampToInteger(roundf(p.height())));
 }
 
 inline IntSize flooredIntSize(const FloatSize& p)
 {
-    return IntSize(static_cast<int>(p.width()), static_cast<int>(p.height()));
+    return IntSize(clampToInteger(floorf(p.width())), clampToInteger(floorf(p.height())));
 }
 
 inline IntSize expandedIntSize(const FloatSize& p)
@@ -201,7 +201,7 @@
 
 inline IntPoint flooredIntPoint(const FloatSize& p)
 {
-    return IntPoint(static_cast<int>(p.width()), static_cast<int>(p.height()));
+    return IntPoint(clampToInteger(floorf(p.width())), clampToInteger(floorf(p.height())));
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/FractionalLayoutPoint.h (125166 => 125167)


--- trunk/Source/WebCore/platform/graphics/FractionalLayoutPoint.h	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/platform/graphics/FractionalLayoutPoint.h	2012-08-09 12:20:30 UTC (rev 125167)
@@ -159,7 +159,7 @@
 
 inline IntPoint flooredIntPoint(const FractionalLayoutPoint& point)
 {
-    return IntPoint(point.x().toInt(), point.y().toInt());
+    return IntPoint(point.x().floor(), point.y().floor());
 }
 
 inline IntPoint roundedIntPoint(const FractionalLayoutPoint& point)
@@ -177,6 +177,16 @@
     return IntPoint(point.x().ceil(), point.y().ceil());
 }
 
+inline FractionalLayoutPoint flooredFractionalLayoutPoint(const FloatPoint& p)
+{
+    return FractionalLayoutPoint(FractionalLayoutUnit::fromFloatFloor(p.x()), FractionalLayoutUnit::fromFloatFloor(p.y()));
+}
+
+inline FractionalLayoutPoint ceiledFractionalLayoutPoint(const FloatPoint& p)
+{
+    return FractionalLayoutPoint(FractionalLayoutUnit::fromFloatCeil(p.x()), FractionalLayoutUnit::fromFloatCeil(p.y()));
+}
+
 } // namespace WebCore
 
 #endif // FractionalLayoutPoint_h

Modified: trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.cpp (125166 => 125167)


--- trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.cpp	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.cpp	2012-08-09 12:20:30 UTC (rev 125167)
@@ -128,21 +128,19 @@
 
 IntRect enclosingIntRect(const FractionalLayoutRect& rect)
 {
-    float x = floorf(rect.x().toFloat());
-    float y = floorf(rect.y().toFloat());
-    float width = ceilf(rect.maxX().toFloat()) - x;
-    float height = ceilf(rect.maxY().toFloat()) - y;
+    IntPoint location = flooredIntPoint(rect.minXMinYCorner());
+    IntPoint maxPoint = ceiledIntPoint(rect.maxXMaxYCorner());
 
-    return IntRect(clampToInteger(x), clampToInteger(y), 
-                   clampToInteger(width), clampToInteger(height));
+    return IntRect(location, maxPoint - location);
 }
 
 FractionalLayoutRect enclosingFractionalLayoutRect(const FloatRect& rect)
 {
 #if ENABLE(SUBPIXEL_LAYOUT)
-    return FractionalLayoutRect(rect.x(), rect.y(),
-                     rect.maxX() - rect.x() + FractionalLayoutUnit::epsilon(),
-                     rect.maxY() - rect.y() + FractionalLayoutUnit::epsilon());
+    FractionalLayoutPoint location = flooredFractionalLayoutPoint(rect.minXMinYCorner());
+    FractionalLayoutPoint maxPoint = ceiledFractionalLayoutPoint(rect.maxXMaxYCorner());
+
+    return FractionalLayoutRect(location, maxPoint - location);
 #else
     return enclosingIntRect(rect);
 #endif

Modified: trunk/Source/WebCore/platform/graphics/FractionalLayoutSize.h (125166 => 125167)


--- trunk/Source/WebCore/platform/graphics/FractionalLayoutSize.h	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/platform/graphics/FractionalLayoutSize.h	2012-08-09 12:20:30 UTC (rev 125167)
@@ -151,7 +151,7 @@
 
 inline IntSize flooredIntSize(const FractionalLayoutSize& s)
 {
-    return IntSize(s.width().toInt(), s.height().toInt());
+    return IntSize(s.width().floor(), s.height().floor());
 }
 
 inline IntSize roundedIntSize(const FractionalLayoutSize& s)

Modified: trunk/Source/WebCore/platform/graphics/IntRect.cpp (125166 => 125167)


--- trunk/Source/WebCore/platform/graphics/IntRect.cpp	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/platform/graphics/IntRect.cpp	2012-08-09 12:20:30 UTC (rev 125167)
@@ -36,14 +36,14 @@
 namespace WebCore {
 
 IntRect::IntRect(const FloatRect& r)
-    : m_location(IntPoint(static_cast<int>(r.x()), static_cast<int>(r.y())))
-    , m_size(IntSize(static_cast<int>(r.width()), static_cast<int>(r.height())))
+    : m_location(clampToInteger(r.x()), clampToInteger(r.y()))
+    , m_size(clampToInteger(r.width()), clampToInteger(r.height()))
 {
 }
 
 IntRect::IntRect(const FractionalLayoutRect& r)
-    : m_location(flooredIntPoint(r.location()))
-    , m_size(flooredIntSize(r.size()))
+    : m_location(r.x(), r.y())
+    , m_size(r.width(), r.height())
 {
 }
 

Modified: trunk/Source/WebCore/rendering/LayoutTypes.h (125166 => 125167)


--- trunk/Source/WebCore/rendering/LayoutTypes.h	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/rendering/LayoutTypes.h	2012-08-09 12:20:30 UTC (rev 125167)
@@ -91,19 +91,14 @@
 
 inline LayoutPoint flooredLayoutPoint(const FloatPoint& p)
 {
-    return LayoutPoint(p.x(), p.y());
+    return flooredFractionalLayoutPoint(p);
 }
 
 inline LayoutPoint flooredLayoutPoint(const FloatSize& s)
 {
-    return LayoutPoint(s.width(), s.height());
+    return flooredLayoutPoint(FloatPoint(s));
 }
 
-inline LayoutSize flooredLayoutSize(const FloatPoint& p)
-{
-    return LayoutSize(p.x(), p.y());
-}
-
 inline int roundToInt(LayoutUnit value)
 {
     return value.round();
@@ -111,7 +106,7 @@
 
 inline int floorToInt(LayoutUnit value)
 {
-    return value.toInt();
+    return value.floor();
 }
 
 inline LayoutUnit roundedLayoutUnit(float value)
@@ -164,7 +159,7 @@
 
 inline bool isIntegerValue(const LayoutUnit value)
 {
-    return value.floor() == value;
+    return value.toInt() == value;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (125166 => 125167)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2012-08-09 12:18:18 UTC (rev 125166)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2012-08-09 12:20:30 UTC (rev 125167)
@@ -1457,7 +1457,7 @@
         // If the fixed layer's container is the root, just add in the offset of the view. We can obtain this by calling
         // localToAbsolute() on the RenderView.
         FloatPoint absPos = renderer()->localToAbsolute(FloatPoint(), true);
-        location += flooredLayoutSize(absPos);
+        location += LayoutSize(absPos.x(), absPos.y());
         return;
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to