Title: [295394] trunk
- Revision
- 295394
- Author
- commit-qu...@webkit.org
- Date
- 2022-06-08 14:23:35 -0700 (Wed, 08 Jun 2022)
Log Message
Allow keyboard smooth scrolling to take place in overflow:scroll regions
https://bugs.webkit.org/show_bug.cgi?id=228158
rdar://80911829
Patch by destra <des...@apple.com> on 2022-06-08
Reviewed by Tim Horton.
Test: LayoutTests/fast/scrolling/mac/keyboard-scrolling-overflow-scroll.html
Right now, keyboard smooth scrolling can only scroll the entire page and
cannot scroll overflow:scroll regions. To fix this, rather than always
obtaining ScrollingAnimator from m_frame->view(), which will only ever
scroll the whole page, the code should get ScrollingAnimator from
m_frame.document()->focusedElement() or m_mousePressNode if either one
of them is non-null, which indicates that a sub-scrollable region is
focused.
* LayoutTests/fast/scrolling/mac/keyboard-scrolling-overflow-scroll-expected.txt: Added.
* LayoutTests/fast/scrolling/mac/keyboard-scrolling-overflow-scroll.html: Added.
* Source/WebCore/page/EventHandler.cpp:
(Webcore::EventHandler::keyboardScrollingAnimatorForFocusedNode):
(WebCore::EventHandler::stopKeyboardScrolling):
(WebCore::EventHandler::startKeyboardScrolling):
* Source/WebCore/page/EventHandler.h:
Canonical link: https://commits.webkit.org/251400@main
Modified Paths
Added Paths
Diff
Added: trunk/LayoutTests/fast/scrolling/mac/keyboard-scrolling-overflow-scroll-expected.txt (0 => 295394)
--- trunk/LayoutTests/fast/scrolling/mac/keyboard-scrolling-overflow-scroll-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/keyboard-scrolling-overflow-scroll-expected.txt 2022-06-08 21:23:35 UTC (rev 295394)
@@ -0,0 +1,2 @@
+Successful.
+
Added: trunk/LayoutTests/fast/scrolling/mac/keyboard-scrolling-overflow-scroll.html (0 => 295394)
--- trunk/LayoutTests/fast/scrolling/mac/keyboard-scrolling-overflow-scroll.html (rev 0)
+++ trunk/LayoutTests/fast/scrolling/mac/keyboard-scrolling-overflow-scroll.html 2022-06-08 21:23:35 UTC (rev 295394)
@@ -0,0 +1,65 @@
+<!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">
+ <style>
+ body {
+ height: 2000px;
+ }
+ #scroller {
+ width: 20%;
+ height: 20%;
+ overflow: scroll;
+ border: 1px solid black;
+ padding: 10px;
+ }
+ #innerDiv {
+ height: 1000px;
+ }
+ </style>
+ <script>
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+ function scrollerScrolled()
+ {
+ debug("Successful.")
+ testRunner.notifyDone();
+ }
+
+ function documentScrolled()
+ {
+ debug("Unsuccessful.");
+ testRunner.notifyDone();
+ }
+
+ async function runTest()
+ {
+ if (!window.testRunner || !testRunner.runUIScript)
+ return;
+
+ let scroller = document.getElementById("scroller");
+
+ scroller.addEventListener("scroll", scrollerScrolled);
+ document.addEventListener("scroll", documentScrolled);
+
+ await UIHelper.activateAt(10, 10);
+ await UIHelper.keyDown("downArrow");
+ }
+ </script>
+</head>
+
+<body _onload_="runTest()">
+ <div id="scroller">
+ <div id="innerDiv"></div>
+ </div>
+ <script src=""
+</body>
+
+</html>
Modified: trunk/Source/WebCore/page/EventHandler.cpp (295393 => 295394)
--- trunk/Source/WebCore/page/EventHandler.cpp 2022-06-08 21:02:15 UTC (rev 295393)
+++ trunk/Source/WebCore/page/EventHandler.cpp 2022-06-08 21:23:35 UTC (rev 295394)
@@ -4337,14 +4337,23 @@
event.setDefaultHandled();
}
+KeyboardScrollingAnimator* EventHandler::keyboardScrollingAnimatorForFocusedNode()
+{
+ Node* node = m_frame.document()->focusedElement();
+
+ if (!node)
+ node = m_mousePressNode.get();
+
+ auto* scrollableArea = enclosingScrollableArea(node);
+ if (!scrollableArea)
+ return nullptr;
+
+ return scrollableArea->scrollAnimator().keyboardScrollingAnimator();
+}
+
void EventHandler::stopKeyboardScrolling()
{
- Ref protectedFrame = m_frame;
- auto* view = m_frame.view();
- if (!view)
- return;
-
- auto* animator = view->scrollAnimator().keyboardScrollingAnimator();
+ auto* animator = keyboardScrollingAnimatorForFocusedNode();
if (animator)
animator->handleKeyUpEvent();
}
@@ -4351,16 +4360,14 @@
bool EventHandler::startKeyboardScrolling(KeyboardEvent& event)
{
+ Ref protectedFrame = m_frame;
+
if (!m_frame.settings().eventHandlerDrivenSmoothKeyboardScrollingEnabled())
return false;
- Ref protectedFrame = m_frame;
- auto* view = m_frame.view();
- if (!view)
- return false;
+ auto* animator = keyboardScrollingAnimatorForFocusedNode();
+ auto* platformEvent = event.underlyingPlatformEvent();
- auto* animator = view->scrollAnimator().keyboardScrollingAnimator();
- auto* platformEvent = event.underlyingPlatformEvent();
if (animator && platformEvent)
return animator->beginKeyboardScrollGesture(*platformEvent);
Modified: trunk/Source/WebCore/page/EventHandler.h (295393 => 295394)
--- trunk/Source/WebCore/page/EventHandler.h 2022-06-08 21:02:15 UTC (rev 295393)
+++ trunk/Source/WebCore/page/EventHandler.h 2022-06-08 21:23:35 UTC (rev 295394)
@@ -74,6 +74,7 @@
class HTMLFrameSetElement;
class HitTestResult;
class KeyboardEvent;
+class KeyboardScrollingAnimator;
class MouseEventWithHitTestResults;
class Node;
class Pasteboard;
@@ -382,6 +383,7 @@
bool handleMousePressEventDoubleClick(const MouseEventWithHitTestResults&);
bool handleMousePressEventTripleClick(const MouseEventWithHitTestResults&);
+ KeyboardScrollingAnimator* keyboardScrollingAnimatorForFocusedNode();
bool startKeyboardScrolling(KeyboardEvent&);
void stopKeyboardScrolling();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes