snapToSize rounds the incorrectly for negative locations
authoreae@chromium.org <eae@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Sep 2012 15:35:12 +0000 (15:35 +0000)
committereae@chromium.org <eae@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Sep 2012 15:35:12 +0000 (15:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=97265

Reviewed by Eric Seidel.

Source/WebCore:

Change snapSizeToPixel to preserve sign for location which
affects rounding.

Test: fast/sub-pixel/snap-negative-location.html

* platform/FractionalLayoutUnit.h:
(WebCore::snapSizeToPixel):

LayoutTests:

Add test for snapSizeToPixel handling of negative locations.
Skipped on platforms that do not enable subpixel layout.

* fast/sub-pixel/snap-negative-location-expected.html: Added.
* fast/sub-pixel/snap-negative-location.html: Added.
* platform/mac-lion/Skipped:
* platform/mac-snowleopard/Skipped:
* platform/mac-wk2/Skipped:
* platform/mac/Skipped:
* platform/qt-4.8/Skipped:
* platform/qt/Skipped:
* platform/win-wk2/Skipped:
* platform/win-xp/Skipped:
* platform/win/Skipped:
* platform/wincairo/Skipped:
* platform/wk2/Skipped:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@129370 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/sub-pixel/snap-negative-location-expected.html [new file with mode: 0644]
LayoutTests/fast/sub-pixel/snap-negative-location.html [new file with mode: 0644]
LayoutTests/platform/mac-lion/Skipped
LayoutTests/platform/mac-snowleopard/Skipped
LayoutTests/platform/mac-wk2/Skipped
LayoutTests/platform/mac/Skipped
LayoutTests/platform/qt-4.8/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win-wk2/Skipped
LayoutTests/platform/win-xp/Skipped
LayoutTests/platform/win/Skipped
LayoutTests/platform/wincairo/Skipped
LayoutTests/platform/wk2/Skipped
Source/WebCore/ChangeLog
Source/WebCore/platform/FractionalLayoutUnit.h

index 6634492..19fd7af 100644 (file)
@@ -1,3 +1,27 @@
+2012-09-20  Emil A Eklund  <eae@chromium.org>
+
+        snapToSize rounds the incorrectly for negative locations
+        https://bugs.webkit.org/show_bug.cgi?id=97265
+
+        Reviewed by Eric Seidel.
+
+        Add test for snapSizeToPixel handling of negative locations.
+        Skipped on platforms that do not enable subpixel layout.
+
+        * fast/sub-pixel/snap-negative-location-expected.html: Added.
+        * fast/sub-pixel/snap-negative-location.html: Added.
+        * platform/mac-lion/Skipped:
+        * platform/mac-snowleopard/Skipped:
+        * platform/mac-wk2/Skipped:
+        * platform/mac/Skipped:
+        * platform/qt-4.8/Skipped:
+        * platform/qt/Skipped:
+        * platform/win-wk2/Skipped:
+        * platform/win-xp/Skipped:
+        * platform/win/Skipped:
+        * platform/wincairo/Skipped:
+        * platform/wk2/Skipped:
+
 2012-09-24  Zan Dobersek  <zandobersek@gmail.com>
 
         REGRESSION (r129211-r129218): http/tests/loading/redirect-with-no-location-crash.html failing on GTK Linux 64-bit Release WK2 (Tests)
diff --git a/LayoutTests/fast/sub-pixel/snap-negative-location-expected.html b/LayoutTests/fast/sub-pixel/snap-negative-location-expected.html
new file mode 100644 (file)
index 0000000..861619a
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<body>
+    <div style="position: absolute; top: -4.5px; left: -4.5px; width: 50px; height: 50px; background: navy;">&nbsp;</div>
+    <p style="position: absolute; top: 50px;">
+        Figure above should appear as a solid dark blue square.
+    </p>
+</body>
+</html>
diff --git a/LayoutTests/fast/sub-pixel/snap-negative-location.html b/LayoutTests/fast/sub-pixel/snap-negative-location.html
new file mode 100644 (file)
index 0000000..9f7635f
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<body>
+    <div style="position: absolute; top: -4.5px; left: -4.5px; width: 25px; height: 25px; background: navy;">&nbsp;</div>
+    <div style="position: absolute; top: -4.5px; left: 20.5px; width: 25px; height: 25px; background: navy;">&nbsp;</div>
+    <div style="position: absolute; top: 20.5px; left: -4.5px; width: 25px; height: 25px; background: navy;">&nbsp;</div>
+    <div style="position: absolute; top: 20.5px; left: 20.5px; width: 25px; height: 25px; background: navy;">&nbsp;</div>
+    <p style="position: absolute; top: 50px;">
+        Figure above should appear as a solid dark blue square.
+    </p>
+</body>
+</html>
index d7f2937..1b31a97 100644 (file)
@@ -119,6 +119,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # This media test always failed on Lion
 # https://bugs.webkit.org/show_bug.cgi?id=86527 and <rdar://problem/11458493>
@@ -136,4 +137,4 @@ inspector/profiler/heap-snapshot-containment-show-all.html
 inspector/debugger/debugger-expand-scope.html
 
 # Lion does not support web notifications
-http/tests/notifications
\ No newline at end of file
+http/tests/notifications
index 971a848..289889d 100644 (file)
@@ -213,6 +213,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # Frame::findString does nothing on pages that prevent selection
 # https://bugs.webkit.org/show_bug.cgi?id=40361
index 01bc6fa..2ff0033 100644 (file)
@@ -216,6 +216,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # fast/events/pagehide-timeout.html, pageshow-pagehide-on-back-cached-with-frames.html, and
 # pageshow-pagehide-on-back-cached.html flakey on Lion Intel Debug WebKit testers.
index 8fbbb63..0ff7e43 100644 (file)
@@ -726,6 +726,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # No CORS support for media elements is implemented yet.
 http/tests/security/video-cross-origin-readback.html
index 4437b99..4351695 100644 (file)
@@ -106,6 +106,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # SVG Fonts are only supported when using QRawFont, which is not
 # supported with Qt 4.
index f62baef..05b7405 100644 (file)
@@ -312,6 +312,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # USE(V8)
 
index 2e0fbfd..cbcc80c 100644 (file)
@@ -950,6 +950,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # HiDPI tests require test infrastructure enhancements
 fast/hidpi
index 0b38b66..5f0735d 100644 (file)
@@ -49,6 +49,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # REGRESSION (r83928 or before): Some tests failing assertions in MarkStack::internalAppend / MarkStack::drain
 # https://bugs.webkit.org/show_bug.cgi?id=58657
index b195bf2..a46b9bf 100644 (file)
@@ -1752,6 +1752,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # No CORS support for media elements is implemented yet.
 http/tests/security/video-cross-origin-readback.html
index 831f3f8..ce82673 100644 (file)
@@ -2283,6 +2283,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # No CORS support for media elements is implemented yet.
 http/tests/security/video-cross-origin-readback.html
index 34f0072..bc4201f 100644 (file)
@@ -98,6 +98,7 @@ fast/sub-pixel/size-of-box-with-zoom.html
 fast/sub-pixel/table-rows-no-gaps.html
 fast/sub-pixel/sub-pixel-accumulates-to-layers.html
 fast/sub-pixel/selection/selection-rect-in-sub-pixel-table.html
+fast/sub-pixel/snap-negative-location.html
 
 # [WK2][WTR] svg/animations/animate-text-nested-transforms.html fails
 # https://bugs.webkit.org/show_bug.cgi?id=95191
index 996dce4..a47986a 100644 (file)
@@ -1,3 +1,18 @@
+2012-09-20  Emil A Eklund  <eae@chromium.org>
+
+        snapToSize rounds the incorrectly for negative locations
+        https://bugs.webkit.org/show_bug.cgi?id=97265
+
+        Reviewed by Eric Seidel.
+
+        Change snapSizeToPixel to preserve sign for location which
+        affects rounding.
+
+        Test: fast/sub-pixel/snap-negative-location.html
+
+        * platform/FractionalLayoutUnit.h:
+        (WebCore::snapSizeToPixel):
+
 2012-09-24  Jonathan Liu  <net147@gmail.com>
 
         Use unsigned char for bitfield instead of unsigned.
index 0f3a86a..06be897 100644 (file)
@@ -227,6 +227,15 @@ public:
 #endif
     }
 
+    FractionalLayoutUnit fraction() const
+    {   
+        // Add the fraction to the size (as opposed to the full location) to avoid overflows.
+        // Compute fraction using the mod operator to preserve the sign of the value as it may affect rounding.
+        FractionalLayoutUnit fraction;
+        fraction.setRawValue(rawValue() % kFixedPointDenominator);
+        return fraction;
+    }
+
 #if ENABLE(SUBPIXEL_LAYOUT)
     static float epsilon() { return 1.0f / kFixedPointDenominator; }
 #else
@@ -807,7 +816,7 @@ inline float& operator/=(float& a, const FractionalLayoutUnit& b)
 
 inline int snapSizeToPixel(FractionalLayoutUnit size, FractionalLayoutUnit location) 
 {
-    FractionalLayoutUnit fraction = location - location.floor();
+    FractionalLayoutUnit fraction = location.fraction();
     return (fraction + size).round() - fraction.round();
 }