Title: [208409] trunk
Revision
208409
Author
[email protected]
Date
2016-11-04 17:41:50 -0700 (Fri, 04 Nov 2016)

Log Message

Layout viewport wrong with RTL documents
https://bugs.webkit.org/show_bug.cgi?id=164434

Reviewed by Tim Horton.

Source/WebCore:

The layoutViewportRect was computed incorrectly in RTL documents, because
FrameView::unscaledMaximumScrollPosition() was wrong; it erroneously mapped
what it thought was a scrollOffset to a scrollPosition.

Unscaled scroll positions are in the same coordinate space as unscaledDocumentRect,
so we should not call scrollPositionFromOffset() in FrameView::unscaledMaximumScrollPosition().

Changed FrameView::unscaledMinimumScrollPosition() to also just grab the location of
unscaledDocumentRect, for symmetry.

Finally fixed the tiled scrolling indicator's viewport rect for zoomed RTL documents
by using the unscaled scroll origin.

Tests: fast/visual-viewport/rtl-nonzoomed-rects.html
       fast/visual-viewport/rtl-zoomed-rects.html

* page/FrameView.cpp:
(WebCore::FrameView::setLayoutViewportOrigin):
(WebCore::FrameView::unscaledScrollOrigin):
(WebCore::FrameView::unscaledMinimumScrollPosition):
(WebCore::FrameView::unscaledMaximumScrollPosition):
* page/FrameView.h:

LayoutTests:

* fast/visual-viewport/rtl-nonzoomed-rects-expected.txt: Added.
* fast/visual-viewport/rtl-nonzoomed-rects.html: Added.
* fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added.
* fast/visual-viewport/rtl-zoomed-rects.html: Added.
* platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt: Added.
* platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added.
* platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added. WK1 and RTL are weird.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (208408 => 208409)


--- trunk/LayoutTests/ChangeLog	2016-11-05 00:03:32 UTC (rev 208408)
+++ trunk/LayoutTests/ChangeLog	2016-11-05 00:41:50 UTC (rev 208409)
@@ -1,3 +1,18 @@
+2016-11-04  Simon Fraser  <[email protected]>
+
+        Layout viewport wrong with RTL documents
+        https://bugs.webkit.org/show_bug.cgi?id=164434
+
+        Reviewed by Tim Horton.
+
+        * fast/visual-viewport/rtl-nonzoomed-rects-expected.txt: Added.
+        * fast/visual-viewport/rtl-nonzoomed-rects.html: Added.
+        * fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added.
+        * fast/visual-viewport/rtl-zoomed-rects.html: Added.
+        * platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt: Added.
+        * platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added.
+        * platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added. WK1 and RTL are weird.
+
 2016-11-04  Wenson Hsieh  <[email protected]>
 
         Safari does not emit composition end if blurred for dead key / Japanese IME

Added: trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt (0 => 208409)


--- trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt	2016-11-05 00:41:50 UTC (rev 208409)
@@ -0,0 +1,23 @@
+This test scrolls the page and checks that the layout and visual viewports respond as expected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+JSON.stringify(internals.layoutViewportRect()) is {"top":0,"right":785,"bottom":585,"left":0,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":0,"right":785,"bottom":585,"left":0,"width":785,"height":585}
+
+Scrolled to -475, 525
+JSON.stringify(internals.layoutViewportRect()) is {"top":525,"right":310,"bottom":1110,"left":-475,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":525,"right":310,"bottom":1110,"left":-475,"width":785,"height":585}
+
+Scrolled to -100, 776
+JSON.stringify(internals.layoutViewportRect()) is {"top":776,"right":685,"bottom":1361,"left":-100,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":776,"right":685,"bottom":1361,"left":-100,"width":785,"height":585}
+
+Scrolled to -50, 300
+JSON.stringify(internals.layoutViewportRect()) is {"top":300,"right":735,"bottom":885,"left":-50,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":300,"right":735,"bottom":885,"left":-50,"width":785,"height":585}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects.html (0 => 208409)


--- trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects.html	                        (rev 0)
+++ trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects.html	2016-11-05 00:41:50 UTC (rev 208409)
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+
+<html dir="rtl">
+<head>
+    <script src=""
+    <style>
+        body {
+            height: 2000px;
+            width: 2000px;
+        }
+    </style>
+    <script>
+        description("This test scrolls the page and checks that the layout and visual viewports respond as expected.");
+
+        if (window.internals)
+            internals.settings.setVisualViewportEnabled(true);
+
+        window.jsTestIsAsync = true;
+
+        function doTest()
+        {
+            // Zooming may scroll the view away from the origin.
+            window.scrollTo(0, 0);
+
+            // Don't use shouldBeEqualToString() to avoid showing failures when correct output differs between platforms. 
+            evalAndLogResult("JSON.stringify(internals.layoutViewportRect())");
+            evalAndLogResult("JSON.stringify(internals.visualViewportRect())");
+
+            debug('');
+            window.scrollTo(-475, 525);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult("JSON.stringify(internals.layoutViewportRect())");
+            evalAndLogResult("JSON.stringify(internals.visualViewportRect())");
+
+            debug('');
+            window.scrollTo(-100, 776);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult("JSON.stringify(internals.layoutViewportRect())");
+            evalAndLogResult("JSON.stringify(internals.visualViewportRect())");
+
+            debug('');
+            window.scrollTo(-50, 300);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult("JSON.stringify(internals.layoutViewportRect())");
+            evalAndLogResult("JSON.stringify(internals.visualViewportRect())");
+
+            window.scrollTo(0, 0);
+
+            finishJSTest();
+        }
+        
+        window.addEventListener('load', doTest, false);
+    </script>
+</head>
+<body>
+    <script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects-expected.txt (0 => 208409)


--- trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects-expected.txt	2016-11-05 00:41:50 UTC (rev 208409)
@@ -0,0 +1,23 @@
+This test zooms and scrolls the page and checks that the layout and visual viewports respond as expected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+JSON.stringify(internals.layoutViewportRect()) is {"top":0,"right":785,"bottom":585,"left":0,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":0,"right":392.5,"bottom":292.5,"left":0,"width":392.5,"height":292.5}
+
+Scrolled to -475, 525
+JSON.stringify(internals.layoutViewportRect()) is {"top":232.5,"right":310,"bottom":817.5,"left":-475,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":525,"right":-82.5,"bottom":817.5,"left":-475,"width":392.5,"height":292.5}
+
+Scrolled to -100, 776
+JSON.stringify(internals.layoutViewportRect()) is {"top":483.5,"right":310,"bottom":1068.5,"left":-475,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":776,"right":292.5,"bottom":1068.5,"left":-100,"width":392.5,"height":292.5}
+
+Scrolled to -50, 300
+JSON.stringify(internals.layoutViewportRect()) is {"top":300,"right":342.5,"bottom":885,"left":-442.5,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":300,"right":342.5,"bottom":592.5,"left":-50,"width":392.5,"height":292.5}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects.html (0 => 208409)


--- trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects.html	                        (rev 0)
+++ trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects.html	2016-11-05 00:41:50 UTC (rev 208409)
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+
+<html dir="rtl">
+<head>
+    <style>
+        body {
+            height: 2000px;
+            width: 2000px;
+        }
+    </style>
+    <script src=""
+    <script>
+        description("This test zooms and scrolls the page and checks that the layout and visual viewports respond as expected.");
+
+        if (window.internals)
+            internals.settings.setVisualViewportEnabled(true);
+
+        window.jsTestIsAsync = true;
+
+        function doAfterZooming()
+        {
+            window.scrollTo(0, 0);
+
+            evalAndLogResult("JSON.stringify(internals.layoutViewportRect())");
+            evalAndLogResult("JSON.stringify(internals.visualViewportRect())");
+
+            debug('');
+            window.scrollTo(-475, 525);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult("JSON.stringify(internals.layoutViewportRect())");
+            evalAndLogResult("JSON.stringify(internals.visualViewportRect())");
+
+            debug('');
+            window.scrollTo(-100, 776);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult("JSON.stringify(internals.layoutViewportRect())");
+            evalAndLogResult("JSON.stringify(internals.visualViewportRect())");
+
+            debug('');
+            window.scrollTo(-50, 300);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult("JSON.stringify(internals.layoutViewportRect())");
+            evalAndLogResult("JSON.stringify(internals.visualViewportRect())");
+
+            window.scrollTo(0, 0);
+
+            finishJSTest();
+        }
+        
+        function getUIScript()
+        {
+            return `(function() {
+                uiController.zoomToScale(2, function() {
+                    uiController.uiScriptComplete(uiController.zoomScale);
+                });
+            })();`;
+        }
+
+        function doTest()
+        {
+            if (!window.testRunner)
+                return;
+
+            testRunner.runUIScript(getUIScript(), function(zoomScale) {
+                doAfterZooming();
+            });
+        }
+        
+        window.addEventListener('load', doTest, false);
+    </script>
+</head>
+<body>
+    <script src=""
+</body>
+</html>

Added: trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt (0 => 208409)


--- trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt	2016-11-05 00:41:50 UTC (rev 208409)
@@ -0,0 +1,23 @@
+This test scrolls the page and checks that the layout and visual viewports respond as expected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+JSON.stringify(internals.layoutViewportRect()) is {"top":0,"right":800,"bottom":600,"left":0,"width":800,"height":600}
+JSON.stringify(internals.visualViewportRect()) is {"top":0,"right":800,"bottom":600,"left":0,"width":800,"height":600}
+
+Scrolled to -475, 525
+JSON.stringify(internals.layoutViewportRect()) is {"top":525,"right":325,"bottom":1125,"left":-475,"width":800,"height":600}
+JSON.stringify(internals.visualViewportRect()) is {"top":525,"right":325,"bottom":1125,"left":-475,"width":800,"height":600}
+
+Scrolled to -100, 776
+JSON.stringify(internals.layoutViewportRect()) is {"top":776,"right":700,"bottom":1376,"left":-100,"width":800,"height":600}
+JSON.stringify(internals.visualViewportRect()) is {"top":776,"right":700,"bottom":1376,"left":-100,"width":800,"height":600}
+
+Scrolled to -50, 300
+JSON.stringify(internals.layoutViewportRect()) is {"top":300,"right":750,"bottom":900,"left":-50,"width":800,"height":600}
+JSON.stringify(internals.visualViewportRect()) is {"top":300,"right":750,"bottom":900,"left":-50,"width":800,"height":600}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt (0 => 208409)


--- trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt	2016-11-05 00:41:50 UTC (rev 208409)
@@ -0,0 +1,23 @@
+This test zooms and scrolls the page and checks that the layout and visual viewports respond as expected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+JSON.stringify(internals.layoutViewportRect()) is {"top":0,"right":800,"bottom":600,"left":0,"width":800,"height":600}
+JSON.stringify(internals.visualViewportRect()) is {"top":0,"right":400,"bottom":300,"left":0,"width":400,"height":300}
+
+Scrolled to -475, 525
+JSON.stringify(internals.layoutViewportRect()) is {"top":225,"right":325,"bottom":825,"left":-475,"width":800,"height":600}
+JSON.stringify(internals.visualViewportRect()) is {"top":525,"right":-75,"bottom":825,"left":-475,"width":400,"height":300}
+
+Scrolled to -100, 776
+JSON.stringify(internals.layoutViewportRect()) is {"top":476,"right":325,"bottom":1076,"left":-475,"width":800,"height":600}
+JSON.stringify(internals.visualViewportRect()) is {"top":776,"right":300,"bottom":1076,"left":-100,"width":400,"height":300}
+
+Scrolled to -50, 300
+JSON.stringify(internals.layoutViewportRect()) is {"top":300,"right":350,"bottom":900,"left":-450,"width":800,"height":600}
+JSON.stringify(internals.visualViewportRect()) is {"top":300,"right":350,"bottom":600,"left":-50,"width":400,"height":300}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt (0 => 208409)


--- trunk/LayoutTests/platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt	2016-11-05 00:41:50 UTC (rev 208409)
@@ -0,0 +1,23 @@
+This test zooms and scrolls the page and checks that the layout and visual viewports respond as expected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+JSON.stringify(internals.layoutViewportRect()) is {"top":0,"right":392.5,"bottom":585,"left":-392.5,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":0,"right":392.5,"bottom":292.5,"left":0,"width":392.5,"height":292.5}
+
+Scrolled to -475, 525
+JSON.stringify(internals.layoutViewportRect()) is {"top":232.5,"right":310,"bottom":817.5,"left":-475,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":525,"right":-82.5,"bottom":817.5,"left":-475,"width":392.5,"height":292.5}
+
+Scrolled to -100, 776
+JSON.stringify(internals.layoutViewportRect()) is {"top":483.5,"right":310,"bottom":1068.5,"left":-475,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":776,"right":292.5,"bottom":1068.5,"left":-100,"width":392.5,"height":292.5}
+
+Scrolled to -50, 300
+JSON.stringify(internals.layoutViewportRect()) is {"top":300,"right":342.5,"bottom":885,"left":-442.5,"width":785,"height":585}
+JSON.stringify(internals.visualViewportRect()) is {"top":300,"right":342.5,"bottom":592.5,"left":-50,"width":392.5,"height":292.5}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Modified: trunk/Source/WebCore/ChangeLog (208408 => 208409)


--- trunk/Source/WebCore/ChangeLog	2016-11-05 00:03:32 UTC (rev 208408)
+++ trunk/Source/WebCore/ChangeLog	2016-11-05 00:41:50 UTC (rev 208409)
@@ -1,3 +1,33 @@
+2016-11-04  Simon Fraser  <[email protected]>
+
+        Layout viewport wrong with RTL documents
+        https://bugs.webkit.org/show_bug.cgi?id=164434
+
+        Reviewed by Tim Horton.
+
+        The layoutViewportRect was computed incorrectly in RTL documents, because 
+        FrameView::unscaledMaximumScrollPosition() was wrong; it erroneously mapped
+        what it thought was a scrollOffset to a scrollPosition.
+
+        Unscaled scroll positions are in the same coordinate space as unscaledDocumentRect,
+        so we should not call scrollPositionFromOffset() in FrameView::unscaledMaximumScrollPosition().
+
+        Changed FrameView::unscaledMinimumScrollPosition() to also just grab the location of
+        unscaledDocumentRect, for symmetry.
+
+        Finally fixed the tiled scrolling indicator's viewport rect for zoomed RTL documents
+        by using the unscaled scroll origin.
+
+        Tests: fast/visual-viewport/rtl-nonzoomed-rects.html
+               fast/visual-viewport/rtl-zoomed-rects.html
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::setLayoutViewportOrigin):
+        (WebCore::FrameView::unscaledScrollOrigin):
+        (WebCore::FrameView::unscaledMinimumScrollPosition):
+        (WebCore::FrameView::unscaledMaximumScrollPosition):
+        * page/FrameView.h:
+
 2016-11-04  Sam Weinig  <[email protected]>
 
         [WebIDL] Add support for modern callback syntax

Modified: trunk/Source/WebCore/page/FrameView.cpp (208408 => 208409)


--- trunk/Source/WebCore/page/FrameView.cpp	2016-11-05 00:03:32 UTC (rev 208408)
+++ trunk/Source/WebCore/page/FrameView.cpp	2016-11-05 00:41:50 UTC (rev 208409)
@@ -1821,8 +1821,11 @@
     m_layoutViewportOrigin = origin;
     setViewportConstrainedObjectsNeedLayout();
     
-    if (TiledBacking* tiledBacking = this->tiledBacking())
-        tiledBacking->setLayoutViewportRect(FloatRect(layoutViewportRect()));
+    if (TiledBacking* tiledBacking = this->tiledBacking()) {
+        FloatRect layoutViewport = layoutViewportRect();
+        layoutViewport.moveBy(unscaledScrollOrigin()); // tiledBacking deals in top-left relative coordinates.
+        tiledBacking->setLayoutViewportRect(layoutViewport);
+    }
 }
 
 void FrameView::updateLayoutViewport()
@@ -1854,6 +1857,14 @@
     return unscaledMaximumScrollPosition();
 }
 
+IntPoint FrameView::unscaledScrollOrigin() const
+{
+    if (RenderView* renderView = this->renderView())
+        return -renderView->unscaledDocumentRect().location(); // Akin to code in adjustViewSize().
+
+    return { };
+}
+
 // Size of initial containing block, anchored at scroll position, in document coordinates (unchanged by scale factor).
 LayoutRect FrameView::layoutViewportRect() const
 {
@@ -2038,16 +2049,14 @@
 {
     if (RenderView* renderView = this->renderView()) {
         IntRect unscaledDocumentRect = renderView->unscaledDocumentRect();
+        ScrollPosition minimumPosition = unscaledDocumentRect.location() - visibleSize();
 
-        IntPoint unscaledScrollOrigin = -unscaledDocumentRect.location();
-        ScrollPosition minimumPosition = scrollPositionFromOffset(ScrollOffset(), toIntSize(unscaledScrollOrigin));
-
         if (frame().isMainFrame() && m_scrollPinningBehavior == PinToBottom)
             minimumPosition.setY(unscaledMaximumScrollPosition().y());
 
         return minimumPosition;
     }
-    
+
     return minimumScrollPosition();
 }
 
@@ -2056,11 +2065,7 @@
     if (RenderView* renderView = this->renderView()) {
         IntRect unscaledDocumentRect = renderView->unscaledDocumentRect();
         unscaledDocumentRect.expand(0, headerHeight() + footerHeight());
-        
-        // Max scroll position is size - visible - scrollOrigin, which is max - visible.
-        ScrollOffset maximumOffset = unscaledDocumentRect.maxXMaxYCorner() - visibleSize();
-        IntPoint unscaledScrollOrigin = -unscaledDocumentRect.location();
-        ScrollPosition maximumPosition = scrollPositionFromOffset(maximumOffset, toIntSize(unscaledScrollOrigin));
+        ScrollPosition maximumPosition = unscaledDocumentRect.maxXMaxYCorner() - visibleSize();
 
         if (frame().isMainFrame() && m_scrollPinningBehavior == PinToTop)
             maximumPosition.setY(unscaledMinimumScrollPosition().y());

Modified: trunk/Source/WebCore/page/FrameView.h (208408 => 208409)


--- trunk/Source/WebCore/page/FrameView.h	2016-11-05 00:03:32 UTC (rev 208408)
+++ trunk/Source/WebCore/page/FrameView.h	2016-11-05 00:41:50 UTC (rev 208409)
@@ -250,6 +250,8 @@
     ScrollPosition unscaledMinimumScrollPosition() const;
     ScrollPosition unscaledMaximumScrollPosition() const;
 
+    IntPoint unscaledScrollOrigin() const;
+
     void setLayoutViewportOrigin(LayoutPoint);
     LayoutPoint layoutViewportOrigin() const { return m_layoutViewportOrigin; }
     
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to