Title: [244851] trunk
Revision
244851
Author
[email protected]
Date
2019-05-01 14:38:01 -0700 (Wed, 01 May 2019)

Log Message

[iOS] Element::focus and Element::scrollIntoView do not clamp scroll positions
https://bugs.webkit.org/show_bug.cgi?id=197211

Reviewed by Simon Fraser.

Source/WebCore:

Fixed the bug that Element::focus and Element::scrollIntoView were not clamping scroll offsets,
which causes scrollTop etc... to return a bogus negative scrolling offset.

Unfortunately, we can't just use FrameView's ScrollableArea::constrainScrollPosition since
scrollRectToVisible relies on the visible rect being expanded by the content insets in order to scroll to
a position within the content insets of UIScrollView; e.g. revealing the top of the page as the center.
We manually expand minimumScrollPosition() and maximumScrollPosition() by the content insets instead.

Tests: fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html
       fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html
       fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html

* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::scrollRectToVisible):

LayoutTests:

Added tests for scrolling via Element.prototype.focus and Element.prototype.scrollIntoView.

* fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt: Added.
* fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html: Added.
* fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt: Added.
* fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html: Added.
* fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt: Added.
* fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html: Added.
* platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt: Rebaselined the output now that the scroll position
is properly clamped.
* platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt: Rebaselined as one
more test case is passing.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (244850 => 244851)


--- trunk/LayoutTests/ChangeLog	2019-05-01 21:19:24 UTC (rev 244850)
+++ trunk/LayoutTests/ChangeLog	2019-05-01 21:38:01 UTC (rev 244851)
@@ -1,3 +1,23 @@
+2019-05-01  Ryosuke Niwa  <[email protected]>
+
+        [iOS] Element::focus and Element::scrollIntoView do not clamp scroll positions
+        https://bugs.webkit.org/show_bug.cgi?id=197211
+
+        Reviewed by Simon Fraser.
+
+        Added tests for scrolling via Element.prototype.focus and Element.prototype.scrollIntoView.
+
+        * fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt: Added.
+        * fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html: Added.
+        * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt: Added.
+        * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html: Added.
+        * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt: Added.
+        * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html: Added.
+        * platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt: Rebaselined the output now that the scroll position
+        is properly clamped.
+        * platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt: Rebaselined as one
+        more test case is passing.
+
 2019-05-01  Wenson Hsieh  <[email protected]>
 
         [iOS] Add a version of viewport shrink-to-fit heuristics that preserves page layout

Added: trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt (0 => 244851)


--- trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt	2019-05-01 21:38:01 UTC (rev 244851)
@@ -0,0 +1,13 @@
+This tests programming scrolling via element.focus to an element position well above the viewport top
+WebKit should clamp the scroll top to 0px.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.documentElement.scrollTop is 0
+PASS visualViewport.pageTop is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+hi
+

Added: trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html (0 => 244851)


--- trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html	2019-05-01 21:38:01 UTC (rev 244851)
@@ -0,0 +1,20 @@
+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+<div style="position: absolute; top:-1000px;" id="hiddenEditor" contenteditable>hi<br></div>
+<script src=""
+<script>
+
+description(`This tests programming scrolling via element.focus to an element position well above the viewport top<br>
+WebKit should clamp the scroll top to 0px.`);
+
+hiddenEditor.focus();
+shouldBe('document.documentElement.scrollTop', '0');
+shouldBe('visualViewport.pageTop', '0');
+
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt (0 => 244851)


--- trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt	2019-05-01 21:38:01 UTC (rev 244851)
@@ -0,0 +1,15 @@
+This tests programming scrolling via element.scrollIntoView to an element inside an iframe position well above the viewport top
+WebKit should clamp the scroll top to 0px.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.documentElement.scrollTop is 0
+PASS visualViewport.pageTop is 0
+PASS iframe.contentDocument.documentElement.scrollTop is 0
+PASS iframe.contentWindow.visualViewport.pageTop > 900 is true
+PASS iframe.contentWindow.visualViewport.pageTop is target.offsetTop + target.offsetHeight - iframe.clientHeight
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html (0 => 244851)


--- trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html	2019-05-01 21:38:01 UTC (rev 244851)
@@ -0,0 +1,33 @@
+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true internal:AsyncFrameScrollingEnabled=true ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+<script src=""
+<script>
+
+if (window.internals)
+    internals.settings.setAsyncFrameScrollingEnabled(true);
+
+description(`This tests programming scrolling via element.scrollIntoView to an element inside an iframe position well above the viewport top<br>
+WebKit should clamp the scroll top to 0px.`);
+
+const iframe = document.createElement('iframe');
+document.body.append(iframe);
+iframe.style.position = 'absolute';
+iframe.style.top = '-1000px';
+iframe.style.height = '1050px';
+iframe.contentDocument.body.innerHTML = '<div id="target" style="position: absolute; top:2000px; height: 20px;">some content</div>';
+const target = iframe.contentWindow.target;
+
+target.scrollIntoView({block: 'end'});
+shouldBe('document.documentElement.scrollTop', '0');
+shouldBe('visualViewport.pageTop', '0');
+shouldBe('iframe.contentDocument.documentElement.scrollTop', '0');
+shouldBeTrue('iframe.contentWindow.visualViewport.pageTop > 900');
+shouldBe('iframe.contentWindow.visualViewport.pageTop', 'target.offsetTop + target.offsetHeight - iframe.clientHeight');
+
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt (0 => 244851)


--- trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt	2019-05-01 21:38:01 UTC (rev 244851)
@@ -0,0 +1,12 @@
+This tests programming scrolling via element.scrollIntoView to an element position well above the viewport top
+WebKit should clamp the scroll top to 0px.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.documentElement.scrollTop is 0
+PASS visualViewport.pageTop is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+some content

Added: trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html (0 => 244851)


--- trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html	2019-05-01 21:38:01 UTC (rev 244851)
@@ -0,0 +1,20 @@
+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+<div id="target" style="position: absolute; top:-1000px;">some content</div>
+<script src=""
+<script>
+
+description(`This tests programming scrolling via element.scrollIntoView to an element position well above the viewport top<br>
+WebKit should clamp the scroll top to 0px.`);
+
+target.scrollIntoView();
+shouldBe('document.documentElement.scrollTop', '0');
+shouldBe('visualViewport.pageTop', '0');
+
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt (244850 => 244851)


--- trunk/LayoutTests/platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt	2019-05-01 21:19:24 UTC (rev 244850)
+++ trunk/LayoutTests/platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt	2019-05-01 21:38:01 UTC (rev 244851)
@@ -18,4 +18,4 @@
           text run at (0,0) width 78: "Test Passed."
       RenderBlock {DIV} at (0,886) size 784x0
 caret: position 0 of child 0 {#text} of child 5 {DIV} of body
-scrolled to 0,561
+scrolled to 0,282

Modified: trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt (244850 => 244851)


--- trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt	2019-05-01 21:19:24 UTC (rev 244850)
+++ trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt	2019-05-01 21:38:01 UTC (rev 244851)
@@ -17,5 +17,5 @@
 PASS No viewport available 
 FAIL Image Maps assert_equals: Should have returned the area element expected Element node <area id="rectG" shape="rect" coords="0,0,90,100" href="" but got Element node <html><head><title>cssom-view - elementFromPoint</title>
 ...
-FAIL Fieldsets assert_equals: The fieldset should not cover up the div it doesn't even overlap expected Element node <div id="fieldset-div" class="size" style="position: abso... but got null
+PASS Fieldsets 
 

Modified: trunk/Source/WebCore/ChangeLog (244850 => 244851)


--- trunk/Source/WebCore/ChangeLog	2019-05-01 21:19:24 UTC (rev 244850)
+++ trunk/Source/WebCore/ChangeLog	2019-05-01 21:38:01 UTC (rev 244851)
@@ -1,3 +1,25 @@
+2019-05-01  Ryosuke Niwa  <[email protected]>
+
+        [iOS] Element::focus and Element::scrollIntoView do not clamp scroll positions
+        https://bugs.webkit.org/show_bug.cgi?id=197211
+
+        Reviewed by Simon Fraser.
+
+        Fixed the bug that Element::focus and Element::scrollIntoView were not clamping scroll offsets,
+        which causes scrollTop etc... to return a bogus negative scrolling offset.
+
+        Unfortunately, we can't just use FrameView's ScrollableArea::constrainScrollPosition since
+        scrollRectToVisible relies on the visible rect being expanded by the content insets in order to scroll to
+        a position within the content insets of UIScrollView; e.g. revealing the top of the page as the center.
+        We manually expand minimumScrollPosition() and maximumScrollPosition() by the content insets instead.
+
+        Tests: fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html
+               fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html
+               fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html
+
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::scrollRectToVisible):
+
 2019-05-01  Wenson Hsieh  <[email protected]>
 
         [iOS] Add a version of viewport shrink-to-fit heuristics that preserves page layout

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (244850 => 244851)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2019-05-01 21:19:24 UTC (rev 244850)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2019-05-01 21:38:01 UTC (rev 244851)
@@ -2586,10 +2586,19 @@
             if (options.revealMode == SelectionRevealMode::RevealUpToMainFrame && frameView.frame().isMainFrame())
                 return;
 
+            auto minScrollPosition = frameView.minimumScrollPosition();
+            auto maxScrollPosition = frameView.maximumScrollPosition();
+
 #if !PLATFORM(IOS_FAMILY)
             LayoutRect viewRect = frameView.visibleContentRect();
 #else
+            // FIXME: ContentInsets should be taken care of in UI process side.
+            // To do that, getRectToExpose needs to return the additional scrolling to do beyond content rect.
             LayoutRect viewRect = frameView.visualViewportRectExpandedByContentInsets();
+
+            auto contentInsets = page().contentInsets();
+            minScrollPosition.move(-contentInsets.left(), -contentInsets.top());
+            maxScrollPosition.move(contentInsets.right(), contentInsets.bottom());
 #endif
             // Move the target rect into "scrollView contents" coordinates.
             LayoutRect targetRect = absoluteRect;
@@ -2596,8 +2605,8 @@
             targetRect.move(0, frameView.headerHeight());
 
             LayoutRect revealRect = getRectToExpose(viewRect, targetRect, insideFixed, options.alignX, options.alignY);
-            
-            frameView.setScrollPosition(roundedIntPoint(revealRect.location()));
+            ScrollOffset clampedScrollPosition = roundedIntPoint(revealRect.location()).constrainedBetween(minScrollPosition, maxScrollPosition);
+            frameView.setScrollPosition(clampedScrollPosition);
 
             // This is the outermost view of a web page, so after scrolling this view we
             // scroll its container by calling Page::scrollRectIntoView.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to