Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Throttle
mousemove
events to one per rendering update
https://bugs.webkit.org/show_bug.cgi?id=259408 rdar://110921187 Reviewed by Tim Horton and Simon Fraser. Throttle the mousemove event dispatch rate to a maximum of 1 per rendering update, if the user isn't clicking or dragging. See below for more details. Test: MouseEventTests.CoalesceMouseMoveEvents MouseEventTests.ProcessSwapWithDeferredMouseMoveEventCompletion * LayoutTests/fast/selectors/style-invalidation-hover-change-descendants-expected.txt: * LayoutTests/fast/selectors/style-invalidation-hover-change-descendants.html: * LayoutTests/fast/selectors/style-invalidation-hover-change-siblings-expected.txt: * LayoutTests/fast/selectors/style-invalidation-hover-change-siblings.html: Adjust a couple of layout tests that need to run checks for style invalidation state immediately after handling the mousemove event, without waiting for any further IPC messages to be dispatched. Ensure this by moving the test logic into one-shot `mousemove` event listeners; we also take the opportunity to modernize the test a bit by using `js-test.js` and `testPassed` / `testFailed`. * Source/WebKit/Shared/WebEvent.h: * Source/WebKit/Shared/WebEventType.h: Copied from Source/WebKit/Shared/WebEvent.h. * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::handleMouseEvent): See comments under `WebPage::mouseEvent`. * Source/WebKit/WebKit.xcodeproj/project.pbxproj: * Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp: (WKBundlePageFlushDeferredDidReceiveMouseEventForTesting): Add a testing-only SPI hook to flush the `DidReceiveEvent` message corresponding to any `mousemove` events that have already been handled in the web process. WebKitTestRunner uses this to ensure that `window.eventSender` API to simulate mouse events behaves the same way as it currently does. * Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h: * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::close): (WebKit::WebPage::suspendForProcessSwap): Flush any deferred `mousemove` IPC responses here when suspending right before a process swap, so that we won't end up trying to send a `DidReceiveEvent` message back to the UI process when the `WebPageProxy`'s `mouseEventQueue` has already been emptied, due to process swapping. (WebKit::WebPage::mouseEvent): When handling a `mousemove` event, rather than invoke the IPC completion handler immediately, we instead defer the call to `WebPageProxy::DidReceiveEvent` until the end of the current rendering update. This means that existing UI-side logic for coalescing `mousemove` events when the web process is still handling mouse events will coalesce mousemove events until the end of the rendering update, after which the web process will be done with current mousemove. If a non-`mousemove` event enters the mouse event queue), we'll also tell the web process to dispatch the deferred mousemove completion handler early so that we can process the incoming click right away. (WebKit::WebPage::flushDeferredDidReceiveMouseEvent): (WebKit::WebPage::finalizeRenderingUpdate): Clear out `m_deferredDidReceiveMouseEvent` if it was set, and dispatch the `DidReceiveEvent` message back to the UI process for this deferred event. (WebKit::WebPage::didCommitLoad): Similarly, flush any deferred `DidReceiveEvent` response when committing a load. * Source/WebKit/WebProcess/WebPage/WebPage.h: * Source/WebKit/WebProcess/WebPage/WebPage.messages.in: * Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * Tools/TestWebKitAPI/Tests/mac/MouseEventTests.mm: Added. Add an API test to exercise `mousemove` event coalescing (both this new completion deferral, as well as the preexisting mechanism for coalescing events in the UI process). This test simulates moving a mouse cursor over (300, 300) in the window, clicking, and then verifies that: 1. There are at least 4 mouse events observed: a `mousemove` for the starting location, another `mousemove` for the final destination, and `mousedown` and `mouseup` events for the click. 2. There are no more than 200 events in total (in other words, some `mousemove` events were coalesced). Also, add an API test to verify that we don't hit a `MESSAGE_CHECK` due to sending a deferred `mousemove` event completion message during a process swap. * Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp: (WTR::EventSendingController::mouseMoveTo): Use the above testing hook. We also wait for one extra web <-> UI process round trip here in order to ensure that the UI process has received the message from the web process indicating that we've handled the `mousemove` event. * Tools/WebKitTestRunner/TestController.cpp: (WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle): Canonical link: https://commits.webkit.org/266341@main
- Loading branch information
Showing
17 changed files
with
359 additions
and
81 deletions.
There are no files selected for viewing
15 changes: 9 additions & 6 deletions
15
LayoutTests/fast/selectors/style-invalidation-hover-change-descendants-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
PASS | ||
PASS | ||
PASS | ||
PASS | ||
PASS | ||
PASS | ||
PASS .target styleChangeType was InlineStyleChange | ||
PASS .container styleChangeType was NoStyleChange | ||
PASS .inert styleChangeType was NoStyleChange | ||
PASS .target styleChangeType was InlineStyleChange | ||
PASS .container styleChangeType was NoStyleChange | ||
PASS .inert styleChangeType was NoStyleChange | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
LayoutTests/fast/selectors/style-invalidation-hover-change-siblings-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
PASS | ||
PASS | ||
PASS | ||
PASS | ||
PASS | ||
PASS | ||
PASS .target styleChangeType was InlineStyleChange | ||
PASS .container styleChangeType was NoStyleChange | ||
PASS .inert styleChangeType was NoStyleChange | ||
PASS .target styleChangeType was InlineStyleChange | ||
PASS .container styleChangeType was NoStyleChange | ||
PASS .inert styleChangeType was NoStyleChange | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2023 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace WebKit { | ||
|
||
enum class WebEventType : int8_t { | ||
NoType = -1, | ||
|
||
// WebMouseEvent | ||
MouseDown, | ||
MouseUp, | ||
MouseMove, | ||
MouseForceChanged, | ||
MouseForceDown, | ||
MouseForceUp, | ||
|
||
// WebWheelEvent | ||
Wheel, | ||
|
||
// WebKeyboardEvent | ||
KeyDown, | ||
KeyUp, | ||
RawKeyDown, | ||
Char, | ||
|
||
#if ENABLE(TOUCH_EVENTS) | ||
// WebTouchEvent | ||
TouchStart, | ||
TouchMove, | ||
TouchEnd, | ||
TouchCancel, | ||
#endif | ||
|
||
#if ENABLE(MAC_GESTURE_EVENTS) | ||
GestureStart, | ||
GestureChange, | ||
GestureEnd, | ||
#endif | ||
}; | ||
|
||
} // namespace WebKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.