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
Don't fire a mousemove event when a modifier key is pressed
https://bugs.webkit.org/show_bug.cgi?id=16271 rdar://81287778 Reviewed by Wenson Hsieh. Previously, we dispatched mousemove events whenever a modifier key was pressed. This was used to call the UIClient delegate callback mouseDidMoveOverElement, which downstream clients could use to modify various behaviors based on whether or not modifier keys were pressed. Unfortunately, the act of dispatching a mousemove event meant that pressing modifier keys could cause unexpected mouse behavior. One notable example is Slack. When using Slack through Minibrowser, it is possible to experience spontaneous mouse selection when a cursor was originally placed behind a completion list, since our hover state gets constantly re-evaluated. In this patch, we introduce a mechanism to avoid the need to fire a mousemove event when modifier keys are pressed. This is achieved by adding a new message from the UI process to the web process where we request that a given mouse event's hit test be performed. With the hit test result and user data associated with said mouse event, we can simply call into the UIClient delegate callback mouseDidMoveOverElement, avoiding the regular mouse event dispatch dance altogether. * LayoutTests/fast/events/no-mousemove-on-modifier-key-press-expected.txt: Added. * LayoutTests/fast/events/no-mousemove-on-modifier-key-press.html: Added. Layout test that verifies pressing the modifier keys does not fire a MouseMove event. * Source/WebCore/page/Chrome.h: Export (and make public) Chrome::getToolTip to access from the web process. * Source/WebCore/page/EventHandler.cpp: (WebCore::EventHandler::getHitTypeForMouseMoveEvent): (WebCore::EventHandler::getHitTestResultForMouseEvent): (WebCore::EventHandler::handleMouseMoveEvent): Introduce two functions getHitTypeForMouseMoveEvent and getHitTestResultForMouseEvent. The latter strips out some common code from handleMouseMoveEvent so that it can be called independently to identify a hitType, whereas the former is a handy way to produce a hitTestResult without bringing the MouseEventWithHitTestResults type into web process land. * Source/WebCore/page/EventHandler.h: * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::dispatchMouseDidMoveOverElementAsynchronously): Introduce a method that communicates the need for user data and a hit test on a mouse event without actually dispatching said mouse event to the web process. Once we round trip from the web process, it feeds the returned data to the client delegate callback mouseDidMoveOverElement. * Source/WebKit/UIProcess/WebPageProxy.h: * Source/WebKit/UIProcess/mac/WebViewImpl.h: * Source/WebKit/UIProcess/mac/WebViewImpl.mm: (WebKit::WebViewImpl::viewDidMoveToWindow): (WebKit::WebViewImpl::fireMouseDidMoveOverElement): (WebKit::WebViewImpl::postFakeMouseMovedEventForFlagsChangedEvent): Deleted. Rename postFakeMouseMovedEventForFlagsChangedEvent to fireMouseDidMoveOverElement to better represent our signaling intent. fireMouseDidMoveOverElement then communicates with the web page to receive user data and hit test results before passing that over to the client delegate callback. * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::performHitTestAndGetUserData): * Source/WebKit/WebProcess/WebPage/WebPage.h: * Source/WebKit/WebProcess/WebPage/WebPage.messages.in: Introduce a new message that receives a mouse event from the UI process and calls into the page's event handler and chrome clients to perform a hit test on the received mouse event. This allows us to circumvent the usual dance with a dispatched mouse event while returning the user data and hit test result associated with a mouse event. Canonical link: https://commits.webkit.org/264455@main
- Loading branch information
1 parent
da000fd
commit f84b233
Showing
13 changed files
with
139 additions
and
34 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
LayoutTests/fast/events/no-mousemove-on-modifier-key-press-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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
This test verifies that MouseMove events are not fired when modifier keys are pressed. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
To run this test by hand, press a modifier key. | ||
|
||
Dispatched KeyDown event with modifier metaKey | ||
Dispatched KeyDown event with modifier altKey | ||
Dispatched KeyDown event with modifier shiftKey | ||
Dispatched KeyDown event with modifier ctrlKey | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
43 changes: 43 additions & 0 deletions
43
LayoutTests/fast/events/no-mousemove-on-modifier-key-press.html
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,43 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../../resources/js-test.js"></script> | ||
<script src="../../resources/ui-helper.js"></script> | ||
<style> | ||
.hidden { | ||
display: none; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<p id="description"></p> | ||
<p id="manual-instructions" class="hide">To run this test by hand, press a modifier key.</p> | ||
<div id="console"></div> | ||
<script> | ||
window.jsTestIsAsync = true; | ||
|
||
async function fireKeyDownEventsWithModifiers() { | ||
for (const modifierKey of ['metaKey', 'altKey', 'shiftKey', 'ctrlKey']) { | ||
await UIHelper.keyDown("k", [modifierKey]); | ||
debug('Dispatched KeyDown event with modifier ' + modifierKey); | ||
} | ||
} | ||
|
||
async function runTest() | ||
{ | ||
if (!window.testRunner) | ||
document.getElementById("manual-instructions").classList.remove("hidden"); | ||
|
||
window.addEventListener('mousemove', () => testFailed("MouseMove event detected")); | ||
|
||
if (window.testRunner) | ||
await fireKeyDownEventsWithModifiers(); | ||
finishJSTest(); | ||
} | ||
|
||
description("This test verifies that MouseMove events are not fired when modifier keys are pressed."); | ||
runTest(); | ||
</script> | ||
</body> | ||
</html> |
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
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
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