Chromium Code Reviews| Index: content/browser/renderer_host/input/synthetic_mouse_driver.cc |
| diff --git a/content/browser/renderer_host/input/synthetic_mouse_driver.cc b/content/browser/renderer_host/input/synthetic_mouse_driver.cc |
| index 4db6f2deaf3639571e59d6217f89616b6047b38f..aa42701059d08718df0ae38b579eec3596b18949 100644 |
| --- a/content/browser/renderer_host/input/synthetic_mouse_driver.cc |
| +++ b/content/browser/renderer_host/input/synthetic_mouse_driver.cc |
| @@ -8,7 +8,40 @@ |
| namespace content { |
| -SyntheticMouseDriver::SyntheticMouseDriver() {} |
| +namespace { |
| + |
| +unsigned GetWebMouseEventModifier(int button) { |
| + switch (button) { |
| + case 0: |
|
Navid Zolghadr
2017/01/12 18:23:46
Do we ever hit this case? Should we ever have a ca
lanwei
2017/01/13 17:29:30
No, I just list all the case. Now, I will just lis
|
| + return 0; |
| + case 1: |
|
Navid Zolghadr
2017/01/12 18:23:46
Can we just use the same numbers as already existi
lanwei
2017/01/13 17:29:30
Done.
|
| + return blink::WebMouseEvent::LeftButtonDown; |
| + case 2: |
| + return blink::WebMouseEvent::MiddleButtonDown; |
| + case 3: |
| + return blink::WebMouseEvent::RightButtonDown; |
| + } |
| + NOTREACHED(); |
| + return 0; |
| +} |
| + |
| +blink::WebMouseEvent::Button GetWebMouseEventButton(int button) { |
| + switch (button) { |
| + case 0: |
| + return blink::WebMouseEvent::Button::NoButton; |
| + case 1: |
| + return blink::WebMouseEvent::Button::Left; |
| + case 2: |
| + return blink::WebMouseEvent::Button::Middle; |
| + case 3: |
| + return blink::WebMouseEvent::Button::Right; |
| + } |
| + NOTREACHED(); |
| + return blink::WebMouseEvent::Button::NoButton; |
| +} |
| +} |
| + |
| +SyntheticMouseDriver::SyntheticMouseDriver() : last_modifiers_(0) {} |
| SyntheticMouseDriver::~SyntheticMouseDriver() {} |
| @@ -18,11 +51,14 @@ void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target, |
| target->DispatchInputEventToPlatform(mouse_event_); |
| } |
| -void SyntheticMouseDriver::Press(float x, float y, int index) { |
| +void SyntheticMouseDriver::Press(float x, float y, int index, int button) { |
| DCHECK_EQ(index, 0); |
| + int modifiers = GetWebMouseEventModifier(button); |
| mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| - blink::WebInputEvent::MouseDown, x, y, 0); |
| + blink::WebInputEvent::MouseDown, x, y, modifiers | last_modifiers_); |
| mouse_event_.clickCount = 1; |
| + mouse_event_.button = GetWebMouseEventButton(button); |
| + last_modifiers_ = modifiers | last_modifiers_; |
| } |
| void SyntheticMouseDriver::Move(float x, float y, int index) { |
| @@ -30,16 +66,19 @@ void SyntheticMouseDriver::Move(float x, float y, int index) { |
| blink::WebMouseEvent::Button button = mouse_event_.button; |
| int click_count = mouse_event_.clickCount; |
| mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| - blink::WebInputEvent::MouseMove, x, y, 0); |
| + blink::WebInputEvent::MouseMove, x, y, last_modifiers_); |
| mouse_event_.button = button; |
| mouse_event_.clickCount = click_count; |
| } |
| -void SyntheticMouseDriver::Release(int index) { |
| +void SyntheticMouseDriver::Release(int index, int button) { |
| DCHECK_EQ(index, 0); |
| mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| - blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, 0); |
| + blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, |
| + last_modifiers_); |
| mouse_event_.clickCount = 1; |
| + mouse_event_.button = GetWebMouseEventButton(button); |
| + last_modifiers_ = last_modifiers_ & (~GetWebMouseEventModifier(button)); |
| } |
| bool SyntheticMouseDriver::UserInputCheck( |
| @@ -53,9 +92,10 @@ bool SyntheticMouseDriver::UserInputCheck( |
| } |
| if (params.pointer_action_type() == |
| - SyntheticPointerActionParams::PointerActionType::PRESS && |
| - mouse_event_.clickCount > 0) { |
| - return false; |
| + SyntheticPointerActionParams::PointerActionType::PRESS) { |
| + int modifiers = GetWebMouseEventModifier(params.button()); |
| + if (last_modifiers_ & modifiers) |
| + return false; |
| } |
| if (params.pointer_action_type() == |