Title: [118569] trunk
Revision
118569
Author
[email protected]
Date
2012-05-25 14:48:51 -0700 (Fri, 25 May 2012)

Log Message

Body scrollWidth() and scrollHeight() should be page scale-invariant
https://bugs.webkit.org/show_bug.cgi?id=87494

RenderView::documentRect() is calculating the "scaled" document rect by applying
the current transformation matrix to the unscaledDocumentRect() and then
returning the rounded-out IntRect result.

This rounding out is incorrect because it allows the scaled rectangle to
represent an area that is not actually covered by the document.

We fix this by applying the current transform to the document rect
as a FloatRect and then explicitly converting to IntRect, which
takes the floor of the resulting rectangle coordinates instead of
rounding them out.

This is evidenced by the document.body.scrollWidth() and
document.body.scrollHeight() changing under page scale factor when
they are expected to remain invariant.

Reviewed by James Robinson.

Source/WebCore:

Test: fast/dom/window-scroll-scaling.html

* rendering/RenderView.cpp:
(WebCore::RenderView::documentRect):

LayoutTests:

* fast/dom/window-scroll-scaling-expected.txt: Added.
* fast/dom/window-scroll-scaling.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (118568 => 118569)


--- trunk/LayoutTests/ChangeLog	2012-05-25 21:46:57 UTC (rev 118568)
+++ trunk/LayoutTests/ChangeLog	2012-05-25 21:48:51 UTC (rev 118569)
@@ -1,3 +1,29 @@
+2012-05-25  John Knottenbelt  <[email protected]>
+
+        Body scrollWidth() and scrollHeight() should be page scale-invariant
+        https://bugs.webkit.org/show_bug.cgi?id=87494
+
+        RenderView::documentRect() is calculating the "scaled" document rect by applying
+        the current transformation matrix to the unscaledDocumentRect() and then
+        returning the rounded-out IntRect result.
+
+        This rounding out is incorrect because it allows the scaled rectangle to
+        represent an area that is not actually covered by the document.
+
+        We fix this by applying the current transform to the document rect
+        as a FloatRect and then explicitly converting to IntRect, which
+        takes the floor of the resulting rectangle coordinates instead of
+        rounding them out.
+
+        This is evidenced by the document.body.scrollWidth() and
+        document.body.scrollHeight() changing under page scale factor when
+        they are expected to remain invariant.
+
+        Reviewed by James Robinson.
+
+        * fast/dom/window-scroll-scaling-expected.txt: Added.
+        * fast/dom/window-scroll-scaling.html: Added.
+
 2012-05-25  Simon Fraser  <[email protected]>
 
         Terrible performance on http://alliances.commandandconquer.com/ and http://www.lordofultima.com/

Added: trunk/LayoutTests/fast/dom/window-scroll-scaling-expected.txt (0 => 118569)


--- trunk/LayoutTests/fast/dom/window-scroll-scaling-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/window-scroll-scaling-expected.txt	2012-05-25 21:48:51 UTC (rev 118569)
@@ -0,0 +1,11 @@
+This test ensures that document content width (height) as reported by scrollWidth (scrollHeight) is invariant to changes in page scale factor.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS body.scrollWidth is originalScrollWidth
+PASS body.scrollHeight is originalScrollHeight
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/window-scroll-scaling.html (0 => 118569)


--- trunk/LayoutTests/fast/dom/window-scroll-scaling.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/window-scroll-scaling.html	2012-05-25 21:48:51 UTC (rev 118569)
@@ -0,0 +1,39 @@
+<html>
+<body>
+    <script src=""
+    <script>
+        description("This test ensures that document content width (height) as reported by scrollWidth (scrollHeight) is invariant to changes in page scale factor.");
+
+        if (window.internals)
+            window.internals.settings.setMockScrollbarsEnabled(true);
+
+        var body = document.body;
+
+        // According to CSSOM (http://dev.w3.org/csswg/cssom-view/#dom-element-scrollwidth)
+        // the scrollWidth of the body element (in Quirks mode) is defined as
+        //    max(document content width, value of innerWidth).
+        // In this test, we want to measure the document content width (height),
+        // rather than innerWidth (innerHeight), so we make the body element
+        // larger than the innerWidth (innerHeight).
+
+        body.style["width"] = window.innerWidth + 100 + "px";
+        body.style["height"] = window.innerHeight + 100 + "px";
+
+        var originalScrollWidth = body.scrollWidth;
+        var originalScrollHeight = body.scrollHeight;
+
+        var scale = 1.1;
+        if (window.internals)
+            window.internals.settings.setPageScaleFactor(scale, 0, 0);
+
+        // As we have increased the scale factor, the innerWidth will be less
+        // as fewer CSS pixels will be rendered in the same viewport, so
+        // body.scrollWidth (scrollHeight) will still be measuring the document
+        // content width (height).
+
+        shouldBe("body.scrollWidth", "originalScrollWidth");
+        shouldBe("body.scrollHeight", "originalScrollHeight");
+    </script>
+    <script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (118568 => 118569)


--- trunk/Source/WebCore/ChangeLog	2012-05-25 21:46:57 UTC (rev 118568)
+++ trunk/Source/WebCore/ChangeLog	2012-05-25 21:48:51 UTC (rev 118569)
@@ -1,3 +1,31 @@
+2012-05-25  John Knottenbelt  <[email protected]>
+
+        Body scrollWidth() and scrollHeight() should be page scale-invariant
+        https://bugs.webkit.org/show_bug.cgi?id=87494
+
+        RenderView::documentRect() is calculating the "scaled" document rect by applying
+        the current transformation matrix to the unscaledDocumentRect() and then
+        returning the rounded-out IntRect result.
+
+        This rounding out is incorrect because it allows the scaled rectangle to
+        represent an area that is not actually covered by the document.
+
+        We fix this by applying the current transform to the document rect
+        as a FloatRect and then explicitly converting to IntRect, which
+        takes the floor of the resulting rectangle coordinates instead of
+        rounding them out.
+
+        This is evidenced by the document.body.scrollWidth() and
+        document.body.scrollHeight() changing under page scale factor when
+        they are expected to remain invariant.
+
+        Reviewed by James Robinson.
+
+        Test: fast/dom/window-scroll-scaling.html
+
+        * rendering/RenderView.cpp:
+        (WebCore::RenderView::documentRect):
+
 2012-05-25  Dan Bernstein  <[email protected]>
 
         characterBreakIterator() is not safe to use reentrantly or from multiple threads

Modified: trunk/Source/WebCore/rendering/RenderView.cpp (118568 => 118569)


--- trunk/Source/WebCore/rendering/RenderView.cpp	2012-05-25 21:46:57 UTC (rev 118568)
+++ trunk/Source/WebCore/rendering/RenderView.cpp	2012-05-25 21:48:51 UTC (rev 118569)
@@ -755,10 +755,10 @@
 
 IntRect RenderView::documentRect() const
 {
-    IntRect overflowRect(unscaledDocumentRect());
+    FloatRect overflowRect(unscaledDocumentRect());
     if (hasTransform())
         overflowRect = layer()->currentTransform().mapRect(overflowRect);
-    return overflowRect;
+    return IntRect(overflowRect);
 }
 
 int RenderView::viewHeight() const
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to