Title: [284575] trunk
Revision
284575
Author
[email protected]
Date
2021-10-20 14:50:18 -0700 (Wed, 20 Oct 2021)

Log Message

macOS key-driven smooth scrolling does not stop when focus changes
https://bugs.webkit.org/show_bug.cgi?id=228302

Patch by Beth Dakin  <[email protected]> and Dana Estra <[email protected]> on 2021-10-20
Reviewed by Simon Fraser.

Source/WebCore:

Call stopKeyboardScrollAnimation() on the old FrameView after changing Frame focus.
* page/FocusController.cpp:
(WebCore::FocusController::setFocusedFrame):

Call stopKeyboardScrollAnimation() when the window visibility / active state changes.
* page/Page.cpp:
(WebCore::Page::setActivityState):
(WebCore::Page::stopKeyboardScrollAnimation):
* page/Page.h:

Plumbing to get to ScrollingEffectsController, which can invoke keyUp.
* platform/ScrollAnimator.cpp:
(WebCore::ScrollAnimator::stopKeyboardScrollAnimation):
* platform/ScrollAnimator.h:
* platform/ScrollableArea.cpp:
(WebCore::ScrollableArea::stopKeyboardScrollAnimation):
* platform/ScrollableArea.h:

Tools:

This patch adds support for rawKeyUp and rawKeyDown to the macOS versions of WKTR and DRT.

* DumpRenderTree/mac/EventSendingController.mm:
(+[EventSendingController initialize]):
(+[EventSendingController isSelectorExcludedFromWebScript:]):
(+[EventSendingController webScriptNameForSelector:]):
(-[EventSendingController rawKeyDown:withModifiers:withLocation:]):
(-[EventSendingController rawKeyDownWrapper:withModifiers:withLocation:]):
(-[EventSendingController rawKeyUp:withModifiers:withLocation:]):
(-[EventSendingController rawKeyUpWrapper:withModifiers:withLocation:]):
* WebKitTestRunner/EventSenderProxy.h:
* WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl:
* WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
(WTR::createRawKeyDownMessageBody):
(WTR::createRawKeyUpMessageBody):
(WTR::EventSendingController::rawKeyDown):
(WTR::EventSendingController::rawKeyUp):
* WebKitTestRunner/InjectedBundle/EventSendingController.h:
* WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm:
(WTR::EventSenderProxy::rawKeyDown):
(WTR::EventSenderProxy::rawKeyUp):
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::didReceiveRawKeyDownMessageFromInjectedBundle):
(WTR::TestController::didReceiveRawKeyUpMessageFromInjectedBundle):
(WTR::TestController::didReceiveMessageFromInjectedBundle):
(WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/gtk/EventSenderProxyGtk.cpp:
(WTR::EventSenderProxy::rawKeyDown):
(WTR::EventSenderProxy::rawKeyUp):
* WebKitTestRunner/mac/EventSenderProxy.mm:
(WTR::EventSenderProxy::rawKeyDown):
(WTR::EventSenderProxy::rawKeyUp):
* WebKitTestRunner/win/EventSenderProxyWin.cpp:
(WTR::EventSenderProxy::rawKeyDown):
(WTR::EventSenderProxy::rawKeyUp):
* WebKitTestRunner/wpe/EventSenderProxyWPE.cpp:
(WTR::EventSenderProxy::rawKeyDown):
(WTR::EventSenderProxy::rawKeyUp):

LayoutTests:

EventHandlerDrivenSmoothKeyboardScrollingEnabled keys are WK2 only right now, so skip the new
test in general.
* TestExpectations:

New test that verifies this bug is resolved.
* fast/scrolling/unfocusing-page-while-keyboard-scrolling-expected.txt: Added.
* fast/scrolling/unfocusing-page-while-keyboard-scrolling.html: Added.

Do run the test for mac-wk2. rawKeyDown / rawKeyUp are currently not implemented
elsewhere.
* platform/mac-wk2/TestExpectations:

New support for rawKeyDown in order to simulate holding the key down.
* resources/ui-helper.js:
(window.UIHelper.rawKeyDown):
(window.UIHelper.rawKeyUp):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (284574 => 284575)


--- trunk/LayoutTests/ChangeLog	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/LayoutTests/ChangeLog	2021-10-20 21:50:18 UTC (rev 284575)
@@ -1,3 +1,27 @@
+2021-10-20  Beth Dakin  <[email protected]> and Dana Estra <[email protected]>
+
+        macOS key-driven smooth scrolling does not stop when focus changes
+        https://bugs.webkit.org/show_bug.cgi?id=228302
+
+        Reviewed by Simon Fraser.
+
+        EventHandlerDrivenSmoothKeyboardScrollingEnabled keys are WK2 only right now, so skip the new 
+        test in general.
+        * TestExpectations:
+
+        New test that verifies this bug is resolved.
+        * fast/scrolling/unfocusing-page-while-keyboard-scrolling-expected.txt: Added.
+        * fast/scrolling/unfocusing-page-while-keyboard-scrolling.html: Added.
+
+        Do run the test for mac-wk2. rawKeyDown / rawKeyUp are currently not implemented 
+        elsewhere.
+        * platform/mac-wk2/TestExpectations:
+
+        New support for rawKeyDown in order to simulate holding the key down.
+        * resources/ui-helper.js:
+        (window.UIHelper.rawKeyDown):
+        (window.UIHelper.rawKeyUp):
+
 2021-10-20  Eric Hutchison  <[email protected]>
 
         [ iOS15 EWS ] http/tests/privateClickMeasurement/attribution-conversion-through-image-redirect-in-new-window.html is crashing.

Modified: trunk/LayoutTests/TestExpectations (284574 => 284575)


--- trunk/LayoutTests/TestExpectations	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/LayoutTests/TestExpectations	2021-10-20 21:50:18 UTC (rev 284575)
@@ -97,6 +97,7 @@
 fast/scrolling/keyboard-scrolling-distance-downArrow.html [ Skip ]
 fast/scrolling/keyboard-scrolling-distance-pageDown.html [ Skip ]
 fast/scrolling/keyboard-scrolling-last-timestamp.html [ Skip ]
+fast/scrolling/unfocusing-page-while-keyboard-scrolling.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/unfocusing-page-while-keyboard-scrolling-expected.txt (0 => 284575)


--- trunk/LayoutTests/fast/scrolling/unfocusing-page-while-keyboard-scrolling-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/unfocusing-page-while-keyboard-scrolling-expected.txt	2021-10-20 21:50:18 UTC (rev 284575)
@@ -0,0 +1,6 @@
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+SUCCESS: Blue frame stopped scolling before red frame
+

Added: trunk/LayoutTests/fast/scrolling/unfocusing-page-while-keyboard-scrolling.html (0 => 284575)


--- trunk/LayoutTests/fast/scrolling/unfocusing-page-while-keyboard-scrolling.html	                        (rev 0)
+++ trunk/LayoutTests/fast/scrolling/unfocusing-page-while-keyboard-scrolling.html	2021-10-20 21:50:18 UTC (rev 284575)
@@ -0,0 +1,62 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ 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 scrollRed()
+        {
+            let redOffset = document.getElementById('red-frame').contentDocument.defaultView.scrollY;
+            let blueOffset = document.getElementById('blue-frame').contentDocument.defaultView.scrollY;
+            if (redOffset > 1900) {
+                if (blueOffset > 1900)
+                    debug("FAIL: Blue frame scrolled as far as the red frame.");
+                else
+                    debug("SUCCESS: Blue frame stopped scolling before red frame");
+                testRunner.notifyDone();
+            }
+        }
+
+        async function runTest()
+        {
+            if (!window.testRunner || !testRunner.runUIScript)
+                return;
+
+            let blueFrame = document.getElementById('blue-frame');
+            let redFrame = document.getElementById('red-frame');
+            let redDocument = redFrame.contentDocument;
+
+            redDocument.addEventListener("scroll", function () {
+                scrollRed();
+            });
+
+            blueFrame.focus();
+            await UIHelper.rawKeyDown("downArrow");
+            redFrame.focus();
+            await UIHelper.rawKeyDown("downArrow");
+        }
+    </script>
+    <style>
+    #placeholder {
+        width: 100px;
+        height: 5000px;
+    }
+    iframe {
+        width: 100px;
+        height: 100px;
+    }
+    </style>
+</head>
+<body style="margin: 0;" _onload_="runTest()">
+    <iframe id="blue-frame" srcdoc="<div style='width: 100px; height: 2000px; background-color: blue;'></div>"></iframe>
+    <iframe id="red-frame" srcdoc="<div style='width: 100px; height: 2000px; background-color: red;'></div>"></iframe>
+    <div id="placeholder">
+    <div id="console"></div>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (284574 => 284575)


--- trunk/LayoutTests/platform/mac-wk2/TestExpectations	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations	2021-10-20 21:50:18 UTC (rev 284575)
@@ -42,6 +42,8 @@
 fast/media/mq-prefers-contrast-live-update.html [ Pass ]
 fast/media/mq-prefers-contrast.html [ Pass ]
 
+fast/scrolling/unfocusing-page-while-keyboard-scrolling.html [ Pass ]
+
 http/tests/ssl/applepay [ Pass ]
 
 # APPLE_PAY_INSTALLMENTS was first available in Catalina.

Modified: trunk/LayoutTests/resources/ui-helper.js (284574 => 284575)


--- trunk/LayoutTests/resources/ui-helper.js	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/LayoutTests/resources/ui-helper.js	2021-10-20 21:50:18 UTC (rev 284575)
@@ -344,6 +344,30 @@
         }
     }
 
+    static rawKeyDown(key, modifiers=[])
+    {
+        if (!this.isWebKit2() || !this.isIOSFamily()) {
+            eventSender.rawKeyDown(key, modifiers);
+            return Promise.resolve();
+        }
+
+        return new Promise((resolve) => {
+            testRunner.runUIScript(`uiController.rawKeyDown("${key}", ${JSON.stringify(modifiers)});`, resolve);
+        });
+    }
+
+    static rawKeyUp(key, modifiers=[])
+    {
+        if (!this.isWebKit2() || !this.isIOSFamily()) {
+            eventSender.rawKeyUp(key, modifiers);
+            return Promise.resolve();
+        }
+
+        return new Promise((resolve) => {
+            testRunner.runUIScript(`uiController.rawKeyUp("${key}", ${JSON.stringify(modifiers)});`, resolve);
+        });
+    }
+
     static keyDown(key, modifiers=[])
     {
         if (!this.isWebKit2() || !this.isIOSFamily()) {

Modified: trunk/Source/WebCore/ChangeLog (284574 => 284575)


--- trunk/Source/WebCore/ChangeLog	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Source/WebCore/ChangeLog	2021-10-20 21:50:18 UTC (rev 284575)
@@ -1,3 +1,28 @@
+2021-10-20  Beth Dakin  <[email protected]> and Dana Estra <[email protected]>
+
+        macOS key-driven smooth scrolling does not stop when focus changes
+        https://bugs.webkit.org/show_bug.cgi?id=228302
+
+        Reviewed by Simon Fraser.
+
+        Call stopKeyboardScrollAnimation() on the old FrameView after changing Frame focus.
+        * page/FocusController.cpp:
+        (WebCore::FocusController::setFocusedFrame):
+
+        Call stopKeyboardScrollAnimation() when the window visibility / active state changes.
+        * page/Page.cpp:
+        (WebCore::Page::setActivityState):
+        (WebCore::Page::stopKeyboardScrollAnimation):
+        * page/Page.h:
+
+        Plumbing to get to ScrollingEffectsController, which can invoke keyUp.
+        * platform/ScrollAnimator.cpp:
+        (WebCore::ScrollAnimator::stopKeyboardScrollAnimation):
+        * platform/ScrollAnimator.h:
+        * platform/ScrollableArea.cpp:
+        (WebCore::ScrollableArea::stopKeyboardScrollAnimation):
+        * platform/ScrollableArea.h:
+
 2021-10-20  Fujii Hironori  <[email protected]>
 
         The code decoding std::optional<ImagePaintingOptions> can't be compiled by PlayStation due to the ImagePaintingOptions template constructor

Modified: trunk/Source/WebCore/page/FocusController.cpp (284574 => 284575)


--- trunk/Source/WebCore/page/FocusController.cpp	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Source/WebCore/page/FocusController.cpp	2021-10-20 21:50:18 UTC (rev 284575)
@@ -359,7 +359,8 @@
     m_focusedFrame = newFrame;
 
     // Now that the frame is updated, fire events and update the selection focused states of both frames.
-    if (oldFrame && oldFrame->view()) {
+    if (auto* oldFrameView = oldFrame ? oldFrame->view() : nullptr) {
+        oldFrameView->stopKeyboardScrollAnimation();
         oldFrame->selection().setFocused(false);
         oldFrame->document()->dispatchWindowEvent(Event::create(eventNames().blurEvent, Event::CanBubble::No, Event::IsCancelable::No));
     }

Modified: trunk/Source/WebCore/page/Page.cpp (284574 => 284575)


--- trunk/Source/WebCore/page/Page.cpp	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Source/WebCore/page/Page.cpp	2021-10-20 21:50:18 UTC (rev 284575)
@@ -2366,13 +2366,36 @@
     for (auto& observer : m_activityStateChangeObservers)
         observer.activityStateDidChange(oldActivityState, m_activityState);
 
-    if (wasVisibleAndActive != isVisibleAndActive())
+    if (wasVisibleAndActive != isVisibleAndActive()) {
         PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary();
+        stopKeyboardScrollAnimation();
+    }
 
     if (m_performanceMonitor)
         m_performanceMonitor->activityStateChanged(oldActivityState, activityState);
 }
 
+void Page::stopKeyboardScrollAnimation()
+{
+    for (auto* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
+        auto* frameView = frame->view();
+        if (!frameView)
+            continue;
+
+        frameView->stopKeyboardScrollAnimation();
+
+        auto scrollableAreas = frameView->scrollableAreas();
+        if (!scrollableAreas)
+            continue;
+
+        for (auto& scrollableArea : *scrollableAreas) {
+            // First call stopAsyncAnimatedScroll() to prepare for the keyboard scroller running on the scrolling thread.
+            scrollableArea->stopAsyncAnimatedScroll();
+            scrollableArea->stopKeyboardScrollAnimation();
+        }
+    }
+}
+
 bool Page::isVisibleAndActive() const
 {
     return m_activityState.contains(ActivityState::IsVisible) && m_activityState.contains(ActivityState::WindowIsActive);

Modified: trunk/Source/WebCore/page/Page.h (284574 => 284575)


--- trunk/Source/WebCore/page/Page.h	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Source/WebCore/page/Page.h	2021-10-20 21:50:18 UTC (rev 284575)
@@ -906,6 +906,8 @@
     void setIsVisibleInternal(bool);
     void setIsVisuallyIdleInternal(bool);
 
+    void stopKeyboardScrollAnimation();
+
     enum ShouldHighlightMatches { DoNotHighlightMatches, HighlightMatches };
     enum ShouldMarkMatches { DoNotMarkMatches, MarkMatches };
 

Modified: trunk/Source/WebCore/platform/ScrollAnimator.cpp (284574 => 284575)


--- trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Source/WebCore/platform/ScrollAnimator.cpp	2021-10-20 21:50:18 UTC (rev 284575)
@@ -234,6 +234,11 @@
 #endif
 }
 
+void ScrollAnimator::stopKeyboardScrollAnimation()
+{
+    m_scrollController.stopKeyboardScrolling();
+}
+
 #if ENABLE(TOUCH_EVENTS)
 bool ScrollAnimator::handleTouchEvent(const PlatformTouchEvent&)
 {

Modified: trunk/Source/WebCore/platform/ScrollAnimator.h (284574 => 284575)


--- trunk/Source/WebCore/platform/ScrollAnimator.h	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Source/WebCore/platform/ScrollAnimator.h	2021-10-20 21:50:18 UTC (rev 284575)
@@ -85,6 +85,8 @@
 
     virtual bool processWheelEventForScrollSnap(const PlatformWheelEvent&) { return false; }
 
+    void stopKeyboardScrollAnimation();
+    
 #if PLATFORM(COCOA)
     virtual void handleWheelEventPhase(PlatformWheelEventPhase) { }
 #endif

Modified: trunk/Source/WebCore/platform/ScrollableArea.cpp (284574 => 284575)


--- trunk/Source/WebCore/platform/ScrollableArea.cpp	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Source/WebCore/platform/ScrollableArea.cpp	2021-10-20 21:50:18 UTC (rev 284575)
@@ -219,6 +219,11 @@
     return handledEvent;
 }
 
+void ScrollableArea::stopKeyboardScrollAnimation()
+{
+    scrollAnimator().stopKeyboardScrollAnimation();
+}
+
 #if ENABLE(TOUCH_EVENTS)
 bool ScrollableArea::handleTouchEvent(const PlatformTouchEvent& touchEvent)
 {

Modified: trunk/Source/WebCore/platform/ScrollableArea.h (284574 => 284575)


--- trunk/Source/WebCore/platform/ScrollableArea.h	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Source/WebCore/platform/ScrollableArea.h	2021-10-20 21:50:18 UTC (rev 284575)
@@ -100,6 +100,8 @@
     void resnapAfterLayout();
     void doPostThumbMoveSnapping(ScrollbarOrientation);
 
+    void stopKeyboardScrollAnimation();
+
 #if ENABLE(TOUCH_EVENTS)
     virtual bool handleTouchEvent(const PlatformTouchEvent&);
 #endif

Modified: trunk/Tools/ChangeLog (284574 => 284575)


--- trunk/Tools/ChangeLog	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/ChangeLog	2021-10-20 21:50:18 UTC (rev 284575)
@@ -1,3 +1,50 @@
+2021-10-20  Beth Dakin  <[email protected]> and Dana Estra <[email protected]>
+
+        macOS key-driven smooth scrolling does not stop when focus changes
+        https://bugs.webkit.org/show_bug.cgi?id=228302
+
+        Reviewed by Simon Fraser.
+
+        This patch adds support for rawKeyUp and rawKeyDown to the macOS versions of WKTR and DRT.
+
+        * DumpRenderTree/mac/EventSendingController.mm:
+        (+[EventSendingController initialize]):
+        (+[EventSendingController isSelectorExcludedFromWebScript:]):
+        (+[EventSendingController webScriptNameForSelector:]):
+        (-[EventSendingController rawKeyDown:withModifiers:withLocation:]):
+        (-[EventSendingController rawKeyDownWrapper:withModifiers:withLocation:]):
+        (-[EventSendingController rawKeyUp:withModifiers:withLocation:]):
+        (-[EventSendingController rawKeyUpWrapper:withModifiers:withLocation:]):
+        * WebKitTestRunner/EventSenderProxy.h:
+        * WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl:
+        * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
+        (WTR::createRawKeyDownMessageBody):
+        (WTR::createRawKeyUpMessageBody):
+        (WTR::EventSendingController::rawKeyDown):
+        (WTR::EventSendingController::rawKeyUp):
+        * WebKitTestRunner/InjectedBundle/EventSendingController.h:
+        * WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm:
+        (WTR::EventSenderProxy::rawKeyDown):
+        (WTR::EventSenderProxy::rawKeyUp):
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::didReceiveRawKeyDownMessageFromInjectedBundle):
+        (WTR::TestController::didReceiveRawKeyUpMessageFromInjectedBundle):
+        (WTR::TestController::didReceiveMessageFromInjectedBundle):
+        (WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/gtk/EventSenderProxyGtk.cpp:
+        (WTR::EventSenderProxy::rawKeyDown):
+        (WTR::EventSenderProxy::rawKeyUp):
+        * WebKitTestRunner/mac/EventSenderProxy.mm:
+        (WTR::EventSenderProxy::rawKeyDown):
+        (WTR::EventSenderProxy::rawKeyUp):
+        * WebKitTestRunner/win/EventSenderProxyWin.cpp:
+        (WTR::EventSenderProxy::rawKeyDown):
+        (WTR::EventSenderProxy::rawKeyUp):
+        * WebKitTestRunner/wpe/EventSenderProxyWPE.cpp:
+        (WTR::EventSenderProxy::rawKeyDown):
+        (WTR::EventSenderProxy::rawKeyUp):
+
 2021-10-20  Alex Christensen  <[email protected]>
 
         REGRESSION (r284418): [iOS] TestWebKitAPI.HSTS.Basic, TestWebKitAPI.HSTS.CrossOriginRedirect, TestWebKitAPI.HSTS.ThirdParty, and TestWebKitAPI.WebKit.RedirectToPlaintextHTTPSUpgrade timing out

Modified: trunk/Tools/DumpRenderTree/mac/EventSendingController.mm (284574 => 284575)


--- trunk/Tools/DumpRenderTree/mac/EventSendingController.mm	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/DumpRenderTree/mac/EventSendingController.mm	2021-10-20 21:50:18 UTC (rev 284575)
@@ -196,6 +196,8 @@
         @"focus",
         @"input",
         @"keydown",
+        @"rawkeydown",
+        @"rawkeyup",
         @"keypress",
         @"keyup",
         @"load",
@@ -239,6 +241,8 @@
             || aSelector == @selector(enableDOMUIEventLogging:)
             || aSelector == @selector(fireKeyboardEventsToElement:)
             || aSelector == @selector(keyDown:withModifiers:withLocation:)
+            || aSelector == @selector(rawKeyDown:withModifiers:withLocation:)
+            || aSelector == @selector(rawKeyUp:withModifiers:withLocation:)
             || aSelector == @selector(leapForward:)
             || aSelector == @selector(mouseDown:withModifiers:)
             || aSelector == @selector(mouseMoveToX:Y:)
@@ -300,6 +304,10 @@
         return @"fireKeyboardEventsToElement";
     if (aSelector == @selector(keyDown:withModifiers:withLocation:))
         return @"keyDown";
+    if (aSelector == @selector(rawKeyDown:withModifiers:withLocation:))
+        return @"rawKeyDown";
+    if (aSelector == @selector(rawKeyUp:withModifiers:withLocation:))
+        return @"rawKeyUp";
     if (aSelector == @selector(scheduleAsynchronousKeyDown:withModifiers:withLocation:))
         return @"scheduleAsynchronousKeyDown";
     if (aSelector == @selector(leapForward:))
@@ -1022,6 +1030,76 @@
     [self keyDown:character withModifiers:modifiers withLocation:location];
 }
 
+- (void)rawKeyDown:(NSString *)character withModifiers:(WebScriptObject *)modifiers withLocation:(unsigned long)location
+{
+    RetainPtr<ModifierKeys> modifierKeys = [ModifierKeys modifierKeysWithKey:character modifiers:buildModifierFlags(modifiers) keyLocation:location];
+
+    [[[mainFrame frameView] documentView] layout];
+
+#if !PLATFORM(IOS_FAMILY)
+    auto event = retainPtr([NSEvent keyEventWithType:NSEventTypeKeyDown
+        location:NSMakePoint(5, 5)
+        modifierFlags:modifierKeys->modifierFlags
+        timestamp:[self currentEventTime]
+        windowNumber:[[[mainFrame webView] window] windowNumber]
+        context:[NSGraphicsContext currentContext]
+        characters:modifierKeys->eventCharacter.get()
+        charactersIgnoringModifiers:modifierKeys->charactersIgnoringModifiers.get()
+        isARepeat:NO
+        keyCode:modifierKeys->keyCode]);
+#else
+    auto event = adoptNS([[WebEvent alloc] initWithKeyEventType:WebEventKeyDown timeStamp:[self currentEventTime] characters:modifierKeys->eventCharacter.get() charactersIgnoringModifiers:modifierKeys->charactersIgnoringModifiers.get() modifiers:(WebEventFlags)modifierKeys->modifierFlags isRepeating:NO withFlags:0 withInputManagerHint:nil keyCode:[character characterAtIndex:0] isTabKey:([character characterAtIndex:0] == '\t')]);
+#endif
+
+#if !PLATFORM(IOS_FAMILY)
+    [NSApp _setCurrentEvent:event.get()];
+#endif
+    [[[[mainFrame webView] window] firstResponder] keyDown:event.get()];
+#if !PLATFORM(IOS_FAMILY)
+    [NSApp _setCurrentEvent:nil];
+#endif
+}
+
+- (void)rawKeyDownWrapper:(NSString *)character withModifiers:(WebScriptObject *)modifiers withLocation:(unsigned long)location
+{
+    [self rawKeyDown:character withModifiers:modifiers withLocation:location];
+}
+
+- (void)rawKeyUp:(NSString *)character withModifiers:(WebScriptObject *)modifiers withLocation:(unsigned long)location
+{
+    RetainPtr<ModifierKeys> modifierKeys = [ModifierKeys modifierKeysWithKey:character modifiers:buildModifierFlags(modifiers) keyLocation:location];
+
+    [[[mainFrame frameView] documentView] layout];
+
+#if !PLATFORM(IOS_FAMILY)
+    auto event = retainPtr([NSEvent keyEventWithType:NSEventTypeKeyUp
+        location:NSMakePoint(5, 5)
+        modifierFlags:modifierKeys->modifierFlags
+        timestamp:[self currentEventTime]
+        windowNumber:[[[mainFrame webView] window] windowNumber]
+        context:[NSGraphicsContext currentContext]
+        characters:modifierKeys->eventCharacter.get()
+        charactersIgnoringModifiers:modifierKeys->charactersIgnoringModifiers.get()
+        isARepeat:NO
+        keyCode:modifierKeys->keyCode]);
+#else
+    auto event = adoptNS([[WebEvent alloc] initWithKeyEventType:WebEventKeyUp timeStamp:[self currentEventTime] characters:modifierKeys->eventCharacter.get() charactersIgnoringModifiers:modifierKeys->charactersIgnoringModifiers.get() modifiers:(WebEventFlags)modifierKeys->modifierFlags isRepeating:NO withFlags:0 withInputManagerHint:nil keyCode:[character characterAtIndex:0] isTabKey:([character characterAtIndex:0] == '\t')]);
+#endif
+
+#if !PLATFORM(IOS_FAMILY)
+    [NSApp _setCurrentEvent:event.get()];
+#endif
+    [[[[mainFrame webView] window] firstResponder] keyUp:event.get()];
+#if !PLATFORM(IOS_FAMILY)
+    [NSApp _setCurrentEvent:nil];
+#endif
+}
+
+- (void)rawKeyUpWrapper:(NSString *)character withModifiers:(WebScriptObject *)modifiers withLocation:(unsigned long)location
+{
+    [self rawKeyUp:character withModifiers:modifiers withLocation:location];
+}
+
 - (void)scheduleAsynchronousKeyDown:(NSString *)character withModifiers:(WebScriptObject *)modifiers withLocation:(unsigned long)location
 {
     NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[EventSendingController instanceMethodSignatureForSelector:@selector(keyDownWrapper:withModifiers:withLocation:)]];

Modified: trunk/Tools/WebKitTestRunner/EventSenderProxy.h (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/EventSenderProxy.h	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/EventSenderProxy.h	2021-10-20 21:50:18 UTC (rev 284575)
@@ -70,6 +70,8 @@
     void leapForward(int milliseconds);
 
     void keyDown(WKStringRef key, WKEventModifiers, unsigned location);
+    void rawKeyDown(WKStringRef key, WKEventModifiers, unsigned location);
+    void rawKeyUp(WKStringRef key, WKEventModifiers, unsigned location);
 
 #if PLATFORM(COCOA)
     unsigned mouseButtonsCurrentlyDown() const { return m_mouseButtonsCurrentlyDown; }

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl	2021-10-20 21:50:18 UTC (rev 284575)
@@ -45,7 +45,11 @@
 
     undefined leapForward(long milliseconds);
 
+    // keyDown is really keyUpAndDown, and perhaps should be renamed to reflect that.
+    // rawKeyDown is just the keyDown, and rawKeyUp is just the keyUp
     undefined keyDown(DOMString key, object modifierArray, long location);
+    undefined rawKeyDown(DOMString key, object modifierArray, long location);
+    undefined rawKeyUp(DOMString key, object modifierArray, long location);
     undefined scheduleAsynchronousKeyDown(DOMString key);
 
     // Zoom functions.

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp	2021-10-20 21:50:18 UTC (rev 284575)
@@ -301,11 +301,41 @@
     return body;
 }
 
+static WKRetainPtr<WKMutableDictionaryRef> createRawKeyDownMessageBody(JSStringRef key, WKEventModifiers modifiers, int location)
+{
+    auto body = adoptWK(WKMutableDictionaryCreate());
+    setValue(body, "SubMessage", "RawKeyDown");
+    setValue(body, "Key", key);
+    setValue(body, "Modifiers", adoptWK(WKUInt64Create(modifiers)));
+    setValue(body, "Location", adoptWK(WKUInt64Create(location)));
+    return body;
+}
+
+static WKRetainPtr<WKMutableDictionaryRef> createRawKeyUpMessageBody(JSStringRef key, WKEventModifiers modifiers, int location)
+{
+    auto body = adoptWK(WKMutableDictionaryCreate());
+    setValue(body, "SubMessage", "RawKeyUp");
+    setValue(body, "Key", key);
+    setValue(body, "Modifiers", adoptWK(WKUInt64Create(modifiers)));
+    setValue(body, "Location", adoptWK(WKUInt64Create(location)));
+    return body;
+}
+
 void EventSendingController::keyDown(JSStringRef key, JSValueRef modifierArray, int location)
 {
     postSynchronousPageMessage("EventSender", createKeyDownMessageBody(key, parseModifierArray(modifierArray), location));
 }
 
+void EventSendingController::rawKeyDown(JSStringRef key, JSValueRef modifierArray, int location)
+{
+    postSynchronousPageMessage("EventSender", createRawKeyDownMessageBody(key, parseModifierArray(modifierArray), location));
+}
+
+void EventSendingController::rawKeyUp(JSStringRef key, JSValueRef modifierArray, int location)
+{
+    postSynchronousPageMessage("EventSender", createRawKeyUpMessageBody(key, parseModifierArray(modifierArray), location));
+}
+
 void EventSendingController::scheduleAsynchronousKeyDown(JSStringRef key)
 {
     postPageMessage("EventSender", createKeyDownMessageBody(key, 0, 0));

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.h (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.h	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.h	2021-10-20 21:50:18 UTC (rev 284575)
@@ -68,6 +68,8 @@
     void callAfterScrollingCompletes(JSValueRef functionCallback);
 
     void keyDown(JSStringRef key, JSValueRef modifierArray, int location);
+    void rawKeyDown(JSStringRef key, JSValueRef modifierArray, int location);
+    void rawKeyUp(JSStringRef key, JSValueRef modifierArray, int location);
     void scheduleAsynchronousKeyDown(JSStringRef key);
 
     void textZoomIn();

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm	2021-10-20 21:50:18 UTC (rev 284575)
@@ -79,6 +79,14 @@
 {
 }
 
+void EventSenderProxy::rawKeyDown(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
+{
+}
+
+void EventSenderProxy::rawKeyUp(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
+{
+}
+
 void EventSenderProxy::mouseScrollBy(int x, int y)
 {
 }

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2021-10-20 21:50:18 UTC (rev 284575)
@@ -1600,6 +1600,16 @@
     m_eventSenderProxy->keyDown(stringValue(dictionary, "Key"), uint64Value(dictionary, "Modifiers"), uint64Value(dictionary, "Location"));
 }
 
+void TestController::didReceiveRawKeyDownMessageFromInjectedBundle(WKDictionaryRef dictionary, bool synchronous)
+{
+    m_eventSenderProxy->rawKeyDown(stringValue(dictionary, "Key"), uint64Value(dictionary, "Modifiers"), uint64Value(dictionary, "Location"));
+}
+
+void TestController::didReceiveRawKeyUpMessageFromInjectedBundle(WKDictionaryRef dictionary, bool synchronous)
+{
+    m_eventSenderProxy->rawKeyUp(stringValue(dictionary, "Key"), uint64Value(dictionary, "Modifiers"), uint64Value(dictionary, "Location"));
+}
+
 void TestController::didReceiveLiveDocumentsList(WKArrayRef liveDocumentList)
 {
     auto numDocuments = WKArrayGetSize(liveDocumentList);
@@ -1657,6 +1667,16 @@
             return;
         }
 
+        if (WKStringIsEqualToUTF8CString(subMessageName, "RawKeyDown")) {
+            didReceiveRawKeyDownMessageFromInjectedBundle(dictionary, false);
+            return;
+        }
+
+        if (WKStringIsEqualToUTF8CString(subMessageName, "RawKeyUp")) {
+            didReceiveRawKeyUpMessageFromInjectedBundle(dictionary, false);
+            return;
+        }
+        
         if (WKStringIsEqualToUTF8CString(subMessageName, "MouseScrollBy")) {
             m_eventSenderProxy->mouseScrollBy(doubleValue(dictionary, "X"), doubleValue(dictionary, "Y"));
             return;
@@ -1716,6 +1736,16 @@
             return completionHandler(nullptr);
         }
 
+        if (WKStringIsEqualToUTF8CString(subMessageName, "RawKeyDown")) {
+            didReceiveRawKeyDownMessageFromInjectedBundle(dictionary, true);
+            return completionHandler(nullptr);
+        }
+
+        if (WKStringIsEqualToUTF8CString(subMessageName, "RawKeyUp")) {
+            didReceiveRawKeyUpMessageFromInjectedBundle(dictionary, true);
+            return completionHandler(nullptr);
+        }
+
         if (WKStringIsEqualToUTF8CString(subMessageName, "MouseMoveTo")) {
             m_eventSenderProxy->mouseMoveTo(doubleValue(dictionary, "X"), doubleValue(dictionary, "Y"), stringValue(dictionary, "PointerType"));
             return completionHandler(nullptr);

Modified: trunk/Tools/WebKitTestRunner/TestController.h (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/TestController.h	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2021-10-20 21:50:18 UTC (rev 284575)
@@ -441,6 +441,8 @@
     WKRetainPtr<WKTypeRef> getInjectedBundleInitializationUserData();
 
     void didReceiveKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
+    void didReceiveRawKeyDownMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
+    void didReceiveRawKeyUpMessageFromInjectedBundle(WKDictionaryRef messageBodyDictionary, bool synchronous);
 
     // WKContextClient
     static void networkProcessDidCrash(WKContextRef, const void*);

Modified: trunk/Tools/WebKitTestRunner/gtk/EventSenderProxyGtk.cpp (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/gtk/EventSenderProxyGtk.cpp	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/gtk/EventSenderProxyGtk.cpp	2021-10-20 21:50:18 UTC (rev 284575)
@@ -245,6 +245,14 @@
     webkitWebViewBaseSynthesizeKeyEvent(toWebKitGLibAPI(m_testController->mainWebView()->platformView()), KeyEventType::Insert, gdkKeySym, modifiers, ShouldTranslateKeyboardState::No);
 }
 
+void EventSenderProxy::rawKeyDown(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
+{
+}
+
+void EventSenderProxy::rawKeyUp(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
+{
+}
+
 void EventSenderProxy::mouseDown(unsigned button, WKEventModifiers wkModifiers, WKStringRef pointerType)
 {
     unsigned gdkButton = eventSenderButtonToGDKButton(button);

Modified: trunk/Tools/WebKitTestRunner/mac/EventSenderProxy.mm (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/mac/EventSenderProxy.mm	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/mac/EventSenderProxy.mm	2021-10-20 21:50:18 UTC (rev 284575)
@@ -659,6 +659,46 @@
     [NSApp _setCurrentEvent:nil];
 }
 
+void EventSenderProxy::rawKeyDown(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
+{
+    RetainPtr<ModifierKeys> modifierKeys = [ModifierKeys modifierKeysWithKey:toWTFString(key) modifiers:buildModifierFlags(modifiers) keyLocation:keyLocation];
+
+    NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyDown
+        location:NSMakePoint(5, 5)
+        modifierFlags:modifierKeys->modifierFlags
+        timestamp:absoluteTimeForEventTime(currentEventTime())
+        windowNumber:[m_testController->mainWebView()->platformWindow() windowNumber]
+        context:[NSGraphicsContext currentContext]
+        characters:modifierKeys->eventCharacter.get()
+        charactersIgnoringModifiers:modifierKeys->charactersIgnoringModifiers.get()
+        isARepeat:NO
+        keyCode:modifierKeys->keyCode];
+
+    [NSApp _setCurrentEvent:event];
+    [[m_testController->mainWebView()->platformWindow() firstResponder] keyDown:event];
+    [NSApp _setCurrentEvent:nil];
+}
+
+void EventSenderProxy::rawKeyUp(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
+{
+    RetainPtr<ModifierKeys> modifierKeys = [ModifierKeys modifierKeysWithKey:toWTFString(key) modifiers:buildModifierFlags(modifiers) keyLocation:keyLocation];
+
+    NSEvent *event = [NSEvent keyEventWithType:NSEventTypeKeyUp
+        location:NSMakePoint(5, 5)
+        modifierFlags:modifierKeys->modifierFlags
+        timestamp:absoluteTimeForEventTime(currentEventTime())
+        windowNumber:[m_testController->mainWebView()->platformWindow() windowNumber]
+        context:[NSGraphicsContext currentContext]
+        characters:modifierKeys->eventCharacter.get()
+        charactersIgnoringModifiers:modifierKeys->charactersIgnoringModifiers.get()
+        isARepeat:NO
+        keyCode:modifierKeys->keyCode];
+
+    [NSApp _setCurrentEvent:event];
+    [[m_testController->mainWebView()->platformWindow() firstResponder] keyUp:event];
+    [NSApp _setCurrentEvent:nil];
+}
+
 void EventSenderProxy::mouseScrollBy(int x, int y)
 {
     auto cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(0, kCGScrollEventUnitLine, 2, y, x, 0));

Modified: trunk/Tools/WebKitTestRunner/win/EventSenderProxyWin.cpp (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/win/EventSenderProxyWin.cpp	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/win/EventSenderProxyWin.cpp	2021-10-20 21:50:18 UTC (rev 284575)
@@ -314,6 +314,14 @@
         SetKeyboardState(keyState);
 }
 
+void EventSenderProxy::rawKeyDown(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
+{
+}
+
+void EventSenderProxy::rawKeyUp(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
+{
+}
+
 #if ENABLE(TOUCH_EVENTS)
 void EventSenderProxy::addTouchPoint(int, int)
 {

Modified: trunk/Tools/WebKitTestRunner/wpe/EventSenderProxyWPE.cpp (284574 => 284575)


--- trunk/Tools/WebKitTestRunner/wpe/EventSenderProxyWPE.cpp	2021-10-20 21:49:11 UTC (rev 284574)
+++ trunk/Tools/WebKitTestRunner/wpe/EventSenderProxyWPE.cpp	2021-10-20 21:50:18 UTC (rev 284575)
@@ -327,6 +327,14 @@
     free(entries);
 }
 
+void EventSenderProxy::rawKeyDown(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
+{
+}
+
+void EventSenderProxy::rawKeyUp(WKStringRef key, WKEventModifiers modifiers, unsigned keyLocation)
+{
+}
+
 void EventSenderProxy::addTouchPoint(int x, int y)
 {
     struct wpe_input_touch_event_raw rawEvent { wpe_input_touch_event_type_down, secToMsTimestamp(m_time), static_cast<int>(m_touchEvents.size()), static_cast<int32_t>(x), static_cast<int32_t>(y) };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to