forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix noisy event modifiers when UI events are converted to Blink events
Certain mouse-input devices are known to send mouse events whose modifiers don't always match the state implied by the changed (pressed/released) buttons. While the bad modifiers are not exposed to JS event's button/buttons fields, internal Blink plumbing may behave erratically with this state. This CL: - adds a fix where Blink WebInputEvents are first created from UI events (for events seen in production), and - completes an existing fix "in the middle" of Blink event path (for events injected in testing). Fixed: 378451943 Bug: 40851596 Change-Id: I0d7a496d0ab76089d68b653daaebd41dfae11fc9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6049401 Reviewed-by: Robert Flack <[email protected]> Commit-Queue: Dave Tapuska <[email protected]> Auto-Submit: Mustaq Ahmed <[email protected]> Reviewed-by: Dave Tapuska <[email protected]> Cr-Commit-Position: refs/heads/main@{#1391250}
- Loading branch information
1 parent
ade1cef
commit 1213893
Showing
6 changed files
with
194 additions
and
40 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -32,6 +32,8 @@ | |
|
||
#include <array> | ||
|
||
#include "third_party/blink/public/common/features.h" | ||
#include "third_party/blink/public/common/input/web_pointer_properties.h" | ||
#include "third_party/blink/public/platform/platform.h" | ||
#include "third_party/blink/renderer/core/events/gesture_event.h" | ||
#include "third_party/blink/renderer/core/events/keyboard_event.h" | ||
|
@@ -89,18 +91,6 @@ void UpdateWebMouseEventFromCoreMouseEvent(const MouseEvent& event, | |
web_event.SetPositionInWidget(local_point); | ||
} | ||
|
||
unsigned ToWebInputEventModifierFrom(WebMouseEvent::Button button) { | ||
if (button == WebMouseEvent::Button::kNoButton) | ||
return 0; | ||
|
||
constexpr auto web_mouse_button_to_platform_modifier = std::to_array<unsigned>( | ||
{WebInputEvent::kLeftButtonDown, WebInputEvent::kMiddleButtonDown, | ||
WebInputEvent::kRightButtonDown, WebInputEvent::kBackButtonDown, | ||
WebInputEvent::kForwardButtonDown}); | ||
|
||
return web_mouse_button_to_platform_modifier[static_cast<int>(button)]; | ||
} | ||
|
||
WebPointerEvent TransformWebPointerEvent(float frame_scale, | ||
gfx::Vector2dF frame_translate, | ||
const WebPointerEvent& event) { | ||
|
@@ -120,12 +110,17 @@ WebMouseEvent TransformWebMouseEvent(LocalFrameView* frame_view, | |
const WebMouseEvent& event) { | ||
WebMouseEvent result = event; | ||
|
||
// TODO(dtapuska): Perhaps the event should be constructed correctly? | ||
// crbug.com/686200 | ||
if (event.GetType() == WebInputEvent::Type::kMouseUp) { | ||
result.SetModifiers(event.GetModifiers() & | ||
~ToWebInputEventModifierFrom(event.button)); | ||
// The code in production fixes the modifiers field further upstream at | ||
// `MakeWebMouseEventFromUiEvent`. But thousands of our tests (both WPTs and | ||
// binary tests) bypasses the upstream fix while injecting mouse clicks | ||
// without proper event modifiers! And then mouse events on DevTools overlay | ||
// bypasses the fix below!! | ||
if (event.GetType() == WebInputEvent::Type::kMouseUp || | ||
(RuntimeEnabledFeatures::ClickToCapturedPointerEnabled() && | ||
event.GetType() == WebInputEvent::Type::kMouseDown)) { | ||
result.UpdateEventModifiersToMatchButton(); | ||
} | ||
|
||
result.SetFrameScale(FrameScale(frame_view)); | ||
result.SetFrameTranslate(FrameTranslation(frame_view)); | ||
return result; | ||
|
@@ -181,19 +176,19 @@ WebMouseEventBuilder::WebMouseEventBuilder(const LayoutObject* layout_object, | |
|
||
switch (event.button()) { | ||
case int16_t(WebPointerProperties::Button::kLeft): | ||
button = WebMouseEvent::Button::kLeft; | ||
button = WebPointerProperties::Button::kLeft; | ||
break; | ||
case int16_t(WebPointerProperties::Button::kMiddle): | ||
button = WebMouseEvent::Button::kMiddle; | ||
button = WebPointerProperties::Button::kMiddle; | ||
break; | ||
case int16_t(WebPointerProperties::Button::kRight): | ||
button = WebMouseEvent::Button::kRight; | ||
button = WebPointerProperties::Button::kRight; | ||
break; | ||
case int16_t(WebPointerProperties::Button::kBack): | ||
button = WebMouseEvent::Button::kBack; | ||
button = WebPointerProperties::Button::kBack; | ||
break; | ||
case int16_t(WebPointerProperties::Button::kForward): | ||
button = WebMouseEvent::Button::kForward; | ||
button = WebPointerProperties::Button::kForward; | ||
break; | ||
} | ||
if (event.ButtonDown()) { | ||
|
@@ -215,7 +210,7 @@ WebMouseEventBuilder::WebMouseEventBuilder(const LayoutObject* layout_object, | |
break; | ||
} | ||
} else { | ||
button = WebMouseEvent::Button::kNoButton; | ||
button = WebPointerProperties::Button::kNoButton; | ||
} | ||
movement_x = event.movementX(); | ||
movement_y = event.movementY(); | ||
|
@@ -262,7 +257,8 @@ WebMouseEventBuilder::WebMouseEventBuilder(const LayoutObject* layout_object, | |
gfx::PointF screen_point = touch->ScreenLocation(); | ||
SetPositionInScreen(screen_point.x(), screen_point.y()); | ||
|
||
button = WebMouseEvent::Button::kLeft; | ||
button = WebPointerProperties::Button::kLeft; | ||
// TODO([email protected]): Shouldn't we reset the bit for kMouseUp? | ||
modifiers_ |= WebInputEvent::kLeftButtonDown; | ||
click_count = (type_ == WebInputEvent::Type::kMouseDown || | ||
type_ == WebInputEvent::Type::kMouseUp); | ||
|
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