Title: [280928] trunk
Revision
280928
Author
[email protected]
Date
2021-08-11 13:32:32 -0700 (Wed, 11 Aug 2021)

Log Message

Start smooth keyboard scrolling animation when pageUp or pageDown key is pressed.
https://bugs.webkit.org/show_bug.cgi?id=228156

Patch by Dana Estra <[email protected]> on 2021-08-11
Reviewed by Tim Horton.

Source/WebCore:

UIProcess now no longer handles scrollPageUp and scrollPageDown events. They return to eventHandler as
unhandled and the keyboard scroll animation is started.

Tests: fast/scrolling/keyboard-scrolling-distance-downArrow.html
       fast/scrolling/keyboard-scrolling-distance-pageDown.html

* page/EventHandler.cpp:
(WebCore::EventHandler::defaultKeyboardEventHandler):
* platform/KeyboardScrollingAnimator.cpp:
(WebCore::KeyboardScrollingAnimator::keyboardScrollForKeyboardEvent const):

Source/WebKit:

UIProcess now no longer handles scrollPageUp and scrollPageDown events. They return
to eventHandler as unhandled and the keyboard scroll animation is started.

* UIProcess/API/mac/WKWebViewMac.mm:
(-[WKWebView scrollPageDown:]):
(-[WKWebView scrollPageUp:]):

LayoutTests:

Tests check that at least 2 scroll events occur when the downArrow key or pageDown key is pressed, and
that with each event, the page's offset from its original position increases.

* fast/scrolling/keyboard-scrolling-distance-downArrow-expected.txt: Added.
* fast/scrolling/keyboard-scrolling-distance-downArrow.html: Added.
* fast/scrolling/keyboard-scrolling-distance-pageDown-expected.txt: Added.
* fast/scrolling/keyboard-scrolling-distance-pageDown.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (280927 => 280928)


--- trunk/LayoutTests/ChangeLog	2021-08-11 20:19:33 UTC (rev 280927)
+++ trunk/LayoutTests/ChangeLog	2021-08-11 20:32:32 UTC (rev 280928)
@@ -1,3 +1,18 @@
+2021-08-11  Dana Estra  <[email protected]>
+
+        Start smooth keyboard scrolling animation when pageUp or pageDown key is pressed.
+        https://bugs.webkit.org/show_bug.cgi?id=228156
+
+        Reviewed by Tim Horton.
+        
+        Tests check that at least 2 scroll events occur when the downArrow key or pageDown key is pressed, and
+        that with each event, the page's offset from its original position increases.
+
+        * fast/scrolling/keyboard-scrolling-distance-downArrow-expected.txt: Added.
+        * fast/scrolling/keyboard-scrolling-distance-downArrow.html: Added.
+        * fast/scrolling/keyboard-scrolling-distance-pageDown-expected.txt: Added.
+        * fast/scrolling/keyboard-scrolling-distance-pageDown.html: Added.
+
 2021-08-11  Aditya Keerthi  <[email protected]>
 
         REGRESSION (r273072): Caps lock indicator in password field is too large

Modified: trunk/LayoutTests/TestExpectations (280927 => 280928)


--- trunk/LayoutTests/TestExpectations	2021-08-11 20:19:33 UTC (rev 280927)
+++ trunk/LayoutTests/TestExpectations	2021-08-11 20:32:32 UTC (rev 280928)
@@ -92,6 +92,8 @@
 # WebKit2 only.
 printing/printing-events.html [ Skip ]
 fast/forms/enterkeyhint-attribute-values.html [ Skip ]
+fast/scrolling/keyboard-scrolling-distance-downArrow.html [ Skip ]
+fast/scrolling/keyboard-scrolling-distance-pageDown.html [ Skip ]
 
 # Highlighting marked text ranges from layout tests is only supported in WebKit2.
 editing/input/composition-highlights.html [ Skip ]

Added: trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-downArrow-expected.txt (0 => 280928)


--- trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-downArrow-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-downArrow-expected.txt	2021-08-11 20:32:32 UTC (rev 280928)
@@ -0,0 +1,2 @@
+Successful Scroll
+

Added: trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-downArrow.html (0 => 280928)


--- trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-downArrow.html	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-downArrow.html	2021-08-11 20:32:32 UTC (rev 280928)
@@ -0,0 +1,62 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true EventHandlerDrivenSmoothKeyboardScrollingEnabled=true ] -->
+
+<html>
+
+<head>
+    <script src=""
+    <script src=""
+    <meta name="viewport" content="initial-scale=1.5, user-scalable=no">
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+        
+        function checkSuccessfulScroll(scrollObj)
+        {
+            if (window.scrollY <= scrollObj.offset) {
+                debug("Unsuccessful Scroll - offset does not increase with each scroll event.");
+                testRunner.notifyDone();
+            }
+            
+            scrollObj.offset = window.scrollY;
+            scrollObj.count++;
+            
+            if (scrollObj.count == 2) {
+                debug("Successful Scroll");
+                testRunner.notifyDone();
+            }
+        }
+        
+        async function runTest()
+        {
+            if (!window.testRunner || !testRunner.runUIScript)
+                return;
+                
+            let scrollObj = {
+                count: 0,
+                offset: 0
+            }
+            
+            document.addEventListener("scroll", function () {
+                checkSuccessfulScroll(scrollObj);
+            });
+            
+            await UIHelper.keyDown("downArrow");
+        }
+    </script>
+    <style>
+    #placeholder {
+        width: 100px;
+        height: 5000px;
+    }
+    </style>
+</head>
+
+<body style="margin: 0;" _onload_="runTest()">
+    <div id="placeholder">
+    <div id="console"></div>
+    <script src=""
+</body>
+
+</html>

Added: trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-pageDown-expected.txt (0 => 280928)


--- trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-pageDown-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-pageDown-expected.txt	2021-08-11 20:32:32 UTC (rev 280928)
@@ -0,0 +1,2 @@
+Successful Scroll
+

Added: trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-pageDown.html (0 => 280928)


--- trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-pageDown.html	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/keyboard-scrolling-distance-pageDown.html	2021-08-11 20:32:32 UTC (rev 280928)
@@ -0,0 +1,62 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true EventHandlerDrivenSmoothKeyboardScrollingEnabled=true ] -->
+
+<html>
+
+<head>
+    <script src=""
+    <script src=""
+    <meta name="viewport" content="initial-scale=1.5, user-scalable=no">
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+        
+        function checkSuccessfulScroll(scrollObj)
+        {
+            if (window.scrollY <= scrollObj.offset) {
+                debug("Unsuccessful Scroll - offset does not increase with each scroll event.");
+                testRunner.notifyDone();
+            }
+            
+            scrollObj.offset = window.scrollY;
+            scrollObj.count++;
+            
+            if (scrollObj.count == 2) {
+                debug("Successful Scroll");
+                testRunner.notifyDone();
+            }
+        }
+        
+        async function runTest()
+        {
+            if (!window.testRunner || !testRunner.runUIScript)
+                return;
+                
+            let scrollObj = {
+                count: 0,
+                offset: 0
+            }
+            
+            document.addEventListener("scroll", function () {
+                checkSuccessfulScroll(scrollObj);
+            });
+            
+            await UIHelper.keyDown("pageDown");
+        }
+    </script>
+    <style>
+    #placeholder {
+        width: 100px;
+        height: 5000px;
+    }
+    </style>
+</head>
+
+<body style="margin: 0;" _onload_="runTest()">
+    <div id="placeholder">
+    <div id="console"></div>
+    <script src=""
+</body>
+
+</html>

Modified: trunk/LayoutTests/platform/wk2/TestExpectations (280927 => 280928)


--- trunk/LayoutTests/platform/wk2/TestExpectations	2021-08-11 20:19:33 UTC (rev 280927)
+++ trunk/LayoutTests/platform/wk2/TestExpectations	2021-08-11 20:32:32 UTC (rev 280928)
@@ -860,6 +860,8 @@
 
 # WebKit2 only.
 js/throw-large-string-oom.html [ Pass ]
+fast/scrolling/keyboard-scrolling-distance-downArrow.html [ Pass ]
+fast/scrolling/keyboard-scrolling-distance-pageDown.html [ Pass ]
 fast/speechrecognition/permission-error.html [ Pass ]
 fast/speechrecognition/start-recognition-then-stop.html [ Pass ]
 fast/speechrecognition/start-second-recognition.html [ Pass ]

Modified: trunk/Source/WebCore/ChangeLog (280927 => 280928)


--- trunk/Source/WebCore/ChangeLog	2021-08-11 20:19:33 UTC (rev 280927)
+++ trunk/Source/WebCore/ChangeLog	2021-08-11 20:32:32 UTC (rev 280928)
@@ -1,3 +1,21 @@
+2021-08-11  Dana Estra  <[email protected]>
+
+        Start smooth keyboard scrolling animation when pageUp or pageDown key is pressed.
+        https://bugs.webkit.org/show_bug.cgi?id=228156
+
+        Reviewed by Tim Horton.
+        
+        UIProcess now no longer handles scrollPageUp and scrollPageDown events. They return to eventHandler as
+        unhandled and the keyboard scroll animation is started.
+
+        Tests: fast/scrolling/keyboard-scrolling-distance-downArrow.html
+               fast/scrolling/keyboard-scrolling-distance-pageDown.html
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::defaultKeyboardEventHandler):
+        * platform/KeyboardScrollingAnimator.cpp:
+        (WebCore::KeyboardScrollingAnimator::keyboardScrollForKeyboardEvent const):
+
 2021-08-11  Aditya Keerthi  <[email protected]>
 
         REGRESSION (r273072): Caps lock indicator in password field is too large

Modified: trunk/Source/WebCore/page/EventHandler.cpp (280927 => 280928)


--- trunk/Source/WebCore/page/EventHandler.cpp	2021-08-11 20:19:33 UTC (rev 280927)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2021-08-11 20:32:32 UTC (rev 280928)
@@ -3819,6 +3819,8 @@
             defaultTabEventHandler(event);
         else if (event.keyIdentifier() == "U+0008")
             defaultBackspaceEventHandler(event);
+        else if (event.keyIdentifier() == "PageUp" || event.keyIdentifier() == "PageDown")
+            startKeyboardScrolling(event);
         else {
             FocusDirection direction = focusDirectionForKey(event.keyIdentifier());
             if (direction != FocusDirection::None)

Modified: trunk/Source/WebCore/platform/KeyboardScrollingAnimator.cpp (280927 => 280928)


--- trunk/Source/WebCore/platform/KeyboardScrollingAnimator.cpp	2021-08-11 20:19:33 UTC (rev 280927)
+++ trunk/Source/WebCore/platform/KeyboardScrollingAnimator.cpp	2021-08-11 20:32:32 UTC (rev 280928)
@@ -142,15 +142,17 @@
         return m_scrollAnimator.scrollableArea().horizontalScrollbar();
     }();
 
-    switch (granularity) {
-    case ScrollGranularity::ScrollByLine:
-        return scrollbar->lineStep();
-    case ScrollGranularity::ScrollByPage:
-        return scrollbar->pageStep();
-    case ScrollGranularity::ScrollByDocument:
-        return scrollbar->totalSize();
-    case ScrollGranularity::ScrollByPixel:
-        return scrollbar->pixelStep();
+    if (scrollbar) {
+        switch (granularity) {
+        case ScrollGranularity::ScrollByLine:
+            return scrollbar->lineStep();
+        case ScrollGranularity::ScrollByPage:
+            return scrollbar->pageStep();
+        case ScrollGranularity::ScrollByDocument:
+            return scrollbar->totalSize();
+        case ScrollGranularity::ScrollByPixel:
+            return scrollbar->pixelStep();
+        }
     }
 
     return 0;
@@ -160,7 +162,7 @@
 {
     // FIXME (bug 227459): This logic does not account for writing-mode.
 
-    enum class Key : uint8_t { LeftArrow, RightArrow, UpArrow, DownArrow, Space };
+    enum class Key : uint8_t { LeftArrow, RightArrow, UpArrow, DownArrow, Space, PageUp, PageDown };
 
     Key key;
     if (event.keyIdentifier() == "Left")
@@ -173,6 +175,10 @@
         key = Key::DownArrow;
     else if (event.charCode() == ' ')
         key = Key::Space;
+    else if (event.keyIdentifier() == "PageUp")
+        key = Key::PageUp;
+    else if (event.keyIdentifier() == "PageDown")
+        key = Key::PageDown;
     else
         return std::nullopt;
 
@@ -189,6 +195,8 @@
                 return ScrollGranularity::ScrollByPage;
             return ScrollGranularity::ScrollByLine;
         case Key::Space:
+        case Key::PageUp:
+        case Key::PageDown:
             return ScrollGranularity::ScrollByPage;
         };
         RELEASE_ASSERT_NOT_REACHED();
@@ -201,8 +209,10 @@
         case Key::RightArrow:
             return ScrollDirection::ScrollRight;
         case Key::UpArrow:
+        case Key::PageUp:
             return ScrollDirection::ScrollUp;
         case Key::DownArrow:
+        case Key::PageDown:
             return ScrollDirection::ScrollDown;
         case Key::Space:
             return event.shiftKey() ? ScrollDirection::ScrollUp : ScrollDirection::ScrollDown;
@@ -212,6 +222,9 @@
 
     float distance = scrollDistance(direction, granularity);
 
+    if (!distance)
+        return std::nullopt;
+
     KeyboardScroll scroll;
 
     scroll.offset = unitVectorForScrollDirection(direction).scaled(distance);

Modified: trunk/Source/WebKit/ChangeLog (280927 => 280928)


--- trunk/Source/WebKit/ChangeLog	2021-08-11 20:19:33 UTC (rev 280927)
+++ trunk/Source/WebKit/ChangeLog	2021-08-11 20:32:32 UTC (rev 280928)
@@ -1,3 +1,17 @@
+2021-08-11  Dana Estra  <[email protected]>
+
+        Start smooth keyboard scrolling animation when pageUp or pageDown key is pressed.
+        https://bugs.webkit.org/show_bug.cgi?id=228156
+
+        Reviewed by Tim Horton.
+        
+        UIProcess now no longer handles scrollPageUp and scrollPageDown events. They return
+        to eventHandler as unhandled and the keyboard scroll animation is started.
+
+        * UIProcess/API/mac/WKWebViewMac.mm:
+        (-[WKWebView scrollPageDown:]):
+        (-[WKWebView scrollPageUp:]):
+
 2021-08-11  Alex Christensen  <[email protected]>
 
         Fix iOS debug build after r280875

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm (280927 => 280928)


--- trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm	2021-08-11 20:19:33 UTC (rev 280927)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm	2021-08-11 20:32:32 UTC (rev 280928)
@@ -240,8 +240,6 @@
 WEBCORE_COMMAND(pageUpAndModifySelection)
 WEBCORE_COMMAND(paste)
 WEBCORE_COMMAND(pasteAsPlainText)
-WEBCORE_COMMAND(scrollPageDown)
-WEBCORE_COMMAND(scrollPageUp)
 WEBCORE_COMMAND(scrollLineDown)
 WEBCORE_COMMAND(scrollLineUp)
 WEBCORE_COMMAND(scrollToBeginningOfDocument)
@@ -265,6 +263,26 @@
 
 #undef WEBCORE_COMMAND
 
+- (void)scrollPageDown:(id)sender
+{
+    if (_impl->page().preferences().eventHandlerDrivenSmoothKeyboardScrollingEnabled()) {
+        [self.nextResponder tryToPerform:_cmd with:sender];
+        return;
+    }
+
+    _impl->executeEditCommandForSelector(_cmd);
+}
+
+- (void)scrollPageUp:(id)sender
+{
+    if (_impl->page().preferences().eventHandlerDrivenSmoothKeyboardScrollingEnabled()) {
+        [self.nextResponder tryToPerform:_cmd with:sender];
+        return;
+    }
+
+    _impl->executeEditCommandForSelector(_cmd);
+}
+
 - (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pasteboard types:(NSArray *)types
 {
     return _impl->writeSelectionToPasteboard(pasteboard, types);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to