Title: [105512] trunk
Revision
105512
Author
[email protected]
Date
2012-01-20 07:03:23 -0800 (Fri, 20 Jan 2012)

Log Message

window.innerWidth/Height should not include page scale
https://bugs.webkit.org/show_bug.cgi?id=76555

Source/WebCore:

The DOM attributes window.innerWidth and window.innerHeight should be in
CSS pixels instead of device pixels. Currently the text zoom factor is
cancelled out when calculating these values, but the same also needs to
be done for the page scale.

There is an additional subtlety concerning frames/iframes since their
visible content rectangle is already in (unscaled) CSS pixels. By using
Frame::frameScaleFactor() we avoid unnecessarily cancelling out the page
scale factor in this case.

Patch by Sami Kyostila <[email protected]> on 2012-01-20
Reviewed by Kenneth Rohde Christiansen.

Tests: fast/dom/iframe-inner-size-scaling.html
       fast/dom/window-inner-size-scaling.html

* page/DOMWindow.cpp:
(WebCore::DOMWindow::innerHeight):
(WebCore::DOMWindow::innerWidth):

LayoutTests:

Add two tests for window.innerWidth and window.innerHeight interaction
with page scaling.

Patch by Sami Kyostila <[email protected]> on 2012-01-20
Reviewed by Kenneth Rohde Christiansen.

* fast/dom/iframe-inner-size-scaling-expected.txt: Added.
* fast/dom/iframe-inner-size-scaling.html: Added.
* fast/dom/window-inner-size-scaling-expected.txt: Added.
* fast/dom/window-inner-size-scaling.html: Added.
* fast/frames/frame-set-rotation-hit.html: Calculate the panel height before changing the page scale, because the visual viewport changes with the page scale.
* fast/frames/frame-set-scaling-hit.html: Ditto.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (105511 => 105512)


--- trunk/LayoutTests/ChangeLog	2012-01-20 14:53:33 UTC (rev 105511)
+++ trunk/LayoutTests/ChangeLog	2012-01-20 15:03:23 UTC (rev 105512)
@@ -1,3 +1,20 @@
+2012-01-20  Sami Kyostila  <[email protected]>
+
+        window.innerWidth/Height should not include page scale
+        https://bugs.webkit.org/show_bug.cgi?id=76555
+
+        Add two tests for window.innerWidth and window.innerHeight interaction
+        with page scaling.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * fast/dom/iframe-inner-size-scaling-expected.txt: Added.
+        * fast/dom/iframe-inner-size-scaling.html: Added.
+        * fast/dom/window-inner-size-scaling-expected.txt: Added.
+        * fast/dom/window-inner-size-scaling.html: Added.
+        * fast/frames/frame-set-rotation-hit.html: Calculate the panel height before changing the page scale, because the visual viewport changes with the page scale.
+        * fast/frames/frame-set-scaling-hit.html: Ditto.
+
 2012-01-20  Alexis Menard  <[email protected]>
 
         [Qt] animations tests fails which uses suspend/resume

Added: trunk/LayoutTests/fast/dom/iframe-inner-size-scaling-expected.txt (0 => 105512)


--- trunk/LayoutTests/fast/dom/iframe-inner-size-scaling-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/iframe-inner-size-scaling-expected.txt	2012-01-20 15:03:23 UTC (rev 105512)
@@ -0,0 +1,13 @@
+This tests that innerWidth/innerHeight on an frame window returns the size of the frame itself in CSS pixels, regardless of page scale.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS frame.contentWindow.innerWidth is non-zero.
+PASS frame.contentWindow.innerHeight is non-zero.
+PASS frame.contentWindow.innerWidth is originalWidth
+PASS frame.contentWindow.innerHeight is originalHeight
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/iframe-inner-size-scaling.html (0 => 105512)


--- trunk/LayoutTests/fast/dom/iframe-inner-size-scaling.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/iframe-inner-size-scaling.html	2012-01-20 15:03:23 UTC (rev 105512)
@@ -0,0 +1,29 @@
+<html>
+    <script src=""
+    <script>
+        description("This tests that innerWidth/innerHeight on an frame window returns the size of the frame itself in CSS pixels, regardless of page scale.");
+        window.jsTestIsAsync = true;
+
+        function runTest() {
+            frame = document.getElementById('iframe');
+            originalWidth = frame.contentWindow.innerWidth;
+            originalHeight = frame.contentWindow.innerHeight;
+
+            if (window.internals)
+                window.internals.setPageScaleFactor(document, 2, 0, 0);
+
+            shouldBeNonZero("frame.contentWindow.innerWidth");
+            shouldBeNonZero("frame.contentWindow.innerHeight");
+            shouldBe("frame.contentWindow.innerWidth", "originalWidth");
+            shouldBe("frame.contentWindow.innerHeight", "originalHeight");
+            finishJSTest();
+        }
+
+        window._onload_ = function() {
+          // We must use setTimeout since the innerWidth/innerHeight are not yet valid for the iframe.
+          window.setTimeout(runTest, 0);
+        }
+    </script>
+    <iframe id="iframe" style="width: 100%; height: 100%;"></iframe>
+    <script src=""
+</html>

Added: trunk/LayoutTests/fast/dom/window-inner-size-scaling-expected.txt (0 => 105512)


--- trunk/LayoutTests/fast/dom/window-inner-size-scaling-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/window-inner-size-scaling-expected.txt	2012-01-20 15:03:23 UTC (rev 105512)
@@ -0,0 +1,11 @@
+This test ensures window.innerWidth/innerHeight return the size of the visual viewport in CSS pixels.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS window.innerWidth is Math.floor(originalWidth / scale)
+PASS window.innerHeight is Math.floor(originalHeight / scale)
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/window-inner-size-scaling.html (0 => 105512)


--- trunk/LayoutTests/fast/dom/window-inner-size-scaling.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/window-inner-size-scaling.html	2012-01-20 15:03:23 UTC (rev 105512)
@@ -0,0 +1,17 @@
+<html>
+    <script src=""
+    <script>
+        description("This test ensures window.innerWidth/innerHeight return the size of the visual viewport in CSS pixels.");
+
+        var originalWidth = window.innerWidth;
+        var originalHeight = window.innerHeight;
+        var scale = 2;
+
+        if (window.internals)
+            window.internals.setPageScaleFactor(document, scale, 0, 0);
+
+        shouldBe("window.innerWidth", "Math.floor(originalWidth / scale)");
+        shouldBe("window.innerHeight", "Math.floor(originalHeight / scale)");
+    </script>
+    <script src=""
+</html>

Modified: trunk/LayoutTests/fast/frames/frame-set-rotation-hit.html (105511 => 105512)


--- trunk/LayoutTests/fast/frames/frame-set-rotation-hit.html	2012-01-20 14:53:33 UTC (rev 105511)
+++ trunk/LayoutTests/fast/frames/frame-set-rotation-hit.html	2012-01-20 15:03:23 UTC (rev 105512)
@@ -7,11 +7,12 @@
             if (!window.eventSender || !window.internals)
                 return;
             // Scale the page and resize the frames to verify hit testing on the frameset
+            var leftPanelWidth = window.innerWidth / 8;
+            var panelHeight = window.innerHeight / 2;
             window.internals.setPageScaleFactor(document, 0.5, 0, 0);
-            var leftPanelWidth = window.innerWidth / 8;
-            eventSender.mouseMoveTo(window.innerWidth / 4, leftPanelWidth);
+            eventSender.mouseMoveTo(panelHeight / 2, leftPanelWidth);
             eventSender.mouseDown();
-            eventSender.mouseMoveTo(window.innerWidth / 4, 2 * leftPanelWidth);
+            eventSender.mouseMoveTo(panelHeight / 2, 2 * leftPanelWidth);
             eventSender.mouseUp();
         }
         window._onload_ = init;

Modified: trunk/LayoutTests/fast/frames/frame-set-scaling-hit.html (105511 => 105512)


--- trunk/LayoutTests/fast/frames/frame-set-scaling-hit.html	2012-01-20 14:53:33 UTC (rev 105511)
+++ trunk/LayoutTests/fast/frames/frame-set-scaling-hit.html	2012-01-20 15:03:23 UTC (rev 105512)
@@ -8,10 +8,11 @@
                 return;
             // Scale the page and resize the frames to verify hit testing on the frameset
             var leftPanelWidth = window.innerWidth / 8;
+            var panelHeight = window.innerHeight / 2;
             window.internals.setPageScaleFactor(document, 0.5, 0, 0);
-            eventSender.mouseMoveTo(leftPanelWidth, window.innerHeight / 4);
+            eventSender.mouseMoveTo(leftPanelWidth, panelHeight / 2);
             eventSender.mouseDown();
-            eventSender.mouseMoveTo(2 * leftPanelWidth, window.innerHeight / 4);
+            eventSender.mouseMoveTo(2 * leftPanelWidth, panelHeight / 2);
             eventSender.mouseUp();
         }
         window._onload_ = init;

Modified: trunk/Source/WebCore/ChangeLog (105511 => 105512)


--- trunk/Source/WebCore/ChangeLog	2012-01-20 14:53:33 UTC (rev 105511)
+++ trunk/Source/WebCore/ChangeLog	2012-01-20 15:03:23 UTC (rev 105512)
@@ -1,3 +1,27 @@
+2012-01-20  Sami Kyostila  <[email protected]>
+
+        window.innerWidth/Height should not include page scale
+        https://bugs.webkit.org/show_bug.cgi?id=76555
+
+        The DOM attributes window.innerWidth and window.innerHeight should be in
+        CSS pixels instead of device pixels. Currently the text zoom factor is
+        cancelled out when calculating these values, but the same also needs to
+        be done for the page scale.
+
+        There is an additional subtlety concerning frames/iframes since their
+        visible content rectangle is already in (unscaled) CSS pixels. By using
+        Frame::frameScaleFactor() we avoid unnecessarily cancelling out the page
+        scale factor in this case.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Tests: fast/dom/iframe-inner-size-scaling.html
+               fast/dom/window-inner-size-scaling.html
+
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::innerHeight):
+        (WebCore::DOMWindow::innerWidth):
+
 2012-01-20  Kinuko Yasuda  <[email protected]>
 
         Add DataTransferItems support for drag-and-drop'ed files and texts

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (105511 => 105512)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2012-01-20 14:53:33 UTC (rev 105511)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2012-01-20 15:03:23 UTC (rev 105512)
@@ -1136,7 +1136,7 @@
     
     long height = view->visibleContentRect(/* includeScrollbars */ true).height();
     InspectorInstrumentation::applyScreenHeightOverride(m_frame, &height);
-    return static_cast<int>(height / m_frame->pageZoomFactor());
+    return static_cast<int>(height / (m_frame->pageZoomFactor() * m_frame->frameScaleFactor()));
 }
 
 int DOMWindow::innerWidth() const
@@ -1150,7 +1150,7 @@
 
     long width = view->visibleContentRect(/* includeScrollbars */ true).width();
     InspectorInstrumentation::applyScreenWidthOverride(m_frame, &width);
-    return static_cast<int>(width / m_frame->pageZoomFactor());
+    return static_cast<int>(width / (m_frame->pageZoomFactor() * m_frame->frameScaleFactor()));
 }
 
 int DOMWindow::screenX() const
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to