Commit 8234cb57 authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Add a enum MouseButton to devtools_protocol input domain

Mouse button type are used for both dispatchMouseEvent and
emulateTouchFromMouseEvent. They are using separate enum, but same logic
converting to WebMouseEvent type. This is not very clean and not good
for maintenance.

This CL makes both method use a MouseButton type, and the comment
for emulateTouchFromMouseEvent (it fires contextmenu for right button,
ignores events with middle/forward/back button)
Also adds back/forward button to the tests.

This change is not going to change the usage for these two function.

Change-Id: Ib6d151c7472008cee04aef8792b67a68eb2d44bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1948827Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarMathias Bynens <mathias@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Ella Ge <eirage@chromium.org>
Cr-Commit-Position: refs/heads/master@{#724566}
parent 0f39e79c
......@@ -421,7 +421,7 @@ void WebController::TapOrClickOnCoordinates(
.SetX(x)
.SetY(y)
.SetClickCount(1)
.SetButton(input::DispatchMouseEventButton::LEFT)
.SetButton(input::MouseButton::LEFT)
.SetType(input::DispatchMouseEventType::MOUSE_PRESSED)
.Build(),
node_frame_id,
......@@ -466,7 +466,7 @@ void WebController::OnDispatchPressMouseEvent(
.SetX(x)
.SetY(y)
.SetClickCount(1)
.SetButton(input::DispatchMouseEventButton::LEFT)
.SetButton(input::MouseButton::LEFT)
.SetType(input::DispatchMouseEventType::MOUSE_RELEASED)
.Build(),
node_frame_id,
......
......@@ -135,21 +135,21 @@ bool GetMouseEventButton(const std::string& button,
if (button.empty())
return true;
if (button == Input::DispatchMouseEvent::ButtonEnum::None) {
if (button == Input::MouseButtonEnum::None) {
*event_button = blink::WebMouseEvent::Button::kNoButton;
} else if (button == Input::DispatchMouseEvent::ButtonEnum::Left) {
} else if (button == Input::MouseButtonEnum::Left) {
*event_button = blink::WebMouseEvent::Button::kLeft;
*event_modifiers = blink::WebInputEvent::kLeftButtonDown;
} else if (button == Input::DispatchMouseEvent::ButtonEnum::Middle) {
} else if (button == Input::MouseButtonEnum::Middle) {
*event_button = blink::WebMouseEvent::Button::kMiddle;
*event_modifiers = blink::WebInputEvent::kMiddleButtonDown;
} else if (button == Input::DispatchMouseEvent::ButtonEnum::Right) {
} else if (button == Input::MouseButtonEnum::Right) {
*event_button = blink::WebMouseEvent::Button::kRight;
*event_modifiers = blink::WebInputEvent::kRightButtonDown;
} else if (button == Input::DispatchMouseEvent::ButtonEnum::Back) {
} else if (button == Input::MouseButtonEnum::Back) {
*event_button = blink::WebMouseEvent::Button::kBack;
*event_modifiers = blink::WebInputEvent::kBackButtonDown;
} else if (button == Input::DispatchMouseEvent::ButtonEnum::Forward) {
} else if (button == Input::MouseButtonEnum::Forward) {
*event_button = blink::WebMouseEvent::Button::kForward;
*event_modifiers = blink::WebInputEvent::kForwardButtonDown;
} else {
......
......@@ -3206,6 +3206,15 @@ domain Input
touch
mouse
type MouseButton extends string
enum
none
left
middle
right
back
forward
# UTC time in seconds, counted from January 1, 1970.
type TimeSinceEpoch extends number
......@@ -3277,13 +3286,7 @@ domain Input
# Time at which the event occurred.
optional TimeSinceEpoch timestamp
# Mouse button (default: "none").
optional enum button
none
left
middle
right
back
forward
optional MouseButton button
# A number indicating which buttons are pressed on the mouse when a mouse event is triggered.
# Left=1, Right=2, Middle=4, Back=8, Forward=16, None=0.
optional integer buttons
......@@ -3331,12 +3334,8 @@ domain Input
integer x
# Y coordinate of the mouse pointer in DIP.
integer y
# Mouse button.
enum button
none
left
middle
right
# Mouse button. Only "none", "left", "right" are supported.
MouseButton button
# Time at which the event occurred (default: current time).
optional TimeSinceEpoch timestamp
# X delta in DIP for mouse wheel event (default: 0).
......
......@@ -49,6 +49,18 @@ buttons: 0
x: 100
y: 200
-----Event-----
type: mousedown
button: 3
buttons: 8
x: 100
y: 200
-----Event-----
type: mousedown
button: 4
buttons: 24
x: 100
y: 200
-----Event-----
type: mousewheel
button: 0
buttons: 0
......
......@@ -90,6 +90,22 @@
x: 100,
y: 200
}));
dumpError(await dp.Input.dispatchMouseEvent({
type: 'mousePressed',
button: 'back',
buttons: 0,
clickCount: 1,
x: 100,
y: 200
}));
dumpError(await dp.Input.dispatchMouseEvent({
type: 'mousePressed',
button: 'forward',
buttons: 8,
clickCount: 2,
x: 100,
y: 200
}));
dumpError(await dp.Input.dispatchMouseEvent({
type: 'mouseWheel',
x: 100,
......
......@@ -19,15 +19,17 @@
if (event.shiftKey)
log('shiftKey');
log('----Touches----');
for (var i = 0; i < event.touches.length; i++) {
var touch = event.touches[i];
log('id: ' + i);
log('pageX: ' + touch.pageX);
log('pageY: ' + touch.pageY);
log('radiusX: ' + touch.radiusX);
log('radiusY: ' + touch.radiusY);
log('rotationAngle: ' + touch.rotationAngle);
log('force: ' + touch.force);
if (event.touches) {
for (var i = 0; i < event.touches.length; i++) {
var touch = event.touches[i];
log('id: ' + i);
log('pageX: ' + touch.pageX);
log('pageY: ' + touch.pageY);
log('radiusX: ' + touch.radiusX);
log('radiusY: ' + touch.radiusY);
log('rotationAngle: ' + touch.rotationAngle);
log('force: ' + touch.force);
}
}
eventCount++;
if (eventCount === expectedEventCount)
......@@ -85,14 +87,29 @@
'clickCount': 1,
'x': 100,
'y': 200
},
{
'type': 'mousePressed',
'button': 'forward',
'clickCount': 1,
'x': 100,
'y': 200
},
{
'type': 'mousePressed',
'button': 'back',
'clickCount': 1,
'x': 100,
'y': 200
}
];
await dp.Emulation.setTouchEmulationEnabled({enabled: true});
await dp.Emulation.setEmitTouchEventsForMouse({enabled: true});
// Moving mouse while not pressed does not generate touch events.
await session.evaluate(`expectedEventCount = ${events.length - 2}`);
// Moving mouse while not pressed and press with button with forward/back
// button does not generate touch events.
await session.evaluate(`expectedEventCount = ${events.length - 4}`);
var time = Number(new Date()) / 1000;
for (var index = 0; index < events.length; index++) {
......
......@@ -49,6 +49,18 @@ buttons: 0
x: 100
y: 200
-----Event-----
type: mousedown
button: 3
buttons: 8
x: 100
y: 200
-----Event-----
type: mousedown
button: 4
buttons: 24
x: 100
y: 200
-----Event-----
type: mousewheel
button: 0
buttons: 0
......
......@@ -49,6 +49,18 @@ buttons: 0
x: 100
y: 200
-----Event-----
type: mousedown
button: 3
buttons: 8
x: 100
y: 200
-----Event-----
type: mousedown
button: 4
buttons: 24
x: 100
y: 200
-----Event-----
type: mousewheel
button: 0
buttons: 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment