| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/input/synthetic_mouse_driver.h" | 5 #include "content/browser/renderer_host/input/synthetic_mouse_driver.h" |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 7 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 SyntheticMouseDriver::SyntheticMouseDriver() {} | 11 namespace { |
| 12 |
| 13 unsigned GetWebMouseEventModifier(int button) { |
| 14 switch (button) { |
| 15 case 0: |
| 16 return blink::WebMouseEvent::LeftButtonDown; |
| 17 case 1: |
| 18 return blink::WebMouseEvent::MiddleButtonDown; |
| 19 case 2: |
| 20 return blink::WebMouseEvent::RightButtonDown; |
| 21 } |
| 22 NOTREACHED(); |
| 23 return blink::WebMouseEvent::NoModifiers; |
| 24 } |
| 25 |
| 26 blink::WebMouseEvent::Button GetWebMouseEventButton(int button) { |
| 27 switch (button) { |
| 28 case 0: |
| 29 return blink::WebMouseEvent::Button::Left; |
| 30 case 1: |
| 31 return blink::WebMouseEvent::Button::Middle; |
| 32 case 2: |
| 33 return blink::WebMouseEvent::Button::Right; |
| 34 } |
| 35 NOTREACHED(); |
| 36 return blink::WebMouseEvent::Button::NoButton; |
| 37 } |
| 38 } |
| 39 |
| 40 SyntheticMouseDriver::SyntheticMouseDriver() : last_modifiers_(0) {} |
| 12 | 41 |
| 13 SyntheticMouseDriver::~SyntheticMouseDriver() {} | 42 SyntheticMouseDriver::~SyntheticMouseDriver() {} |
| 14 | 43 |
| 15 void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target, | 44 void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target, |
| 16 const base::TimeTicks& timestamp) { | 45 const base::TimeTicks& timestamp) { |
| 17 mouse_event_.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); | 46 mouse_event_.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); |
| 18 target->DispatchInputEventToPlatform(mouse_event_); | 47 target->DispatchInputEventToPlatform(mouse_event_); |
| 19 } | 48 } |
| 20 | 49 |
| 21 void SyntheticMouseDriver::Press(float x, float y, int index) { | 50 void SyntheticMouseDriver::Press(float x, float y, int index, int button) { |
| 22 DCHECK_EQ(index, 0); | 51 DCHECK_EQ(index, 0); |
| 52 int modifiers = GetWebMouseEventModifier(button); |
| 23 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 53 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 24 blink::WebInputEvent::MouseDown, x, y, 0); | 54 blink::WebInputEvent::MouseDown, x, y, modifiers | last_modifiers_); |
| 25 mouse_event_.clickCount = 1; | 55 mouse_event_.clickCount = 1; |
| 56 mouse_event_.button = GetWebMouseEventButton(button); |
| 57 last_modifiers_ = modifiers | last_modifiers_; |
| 26 } | 58 } |
| 27 | 59 |
| 28 void SyntheticMouseDriver::Move(float x, float y, int index) { | 60 void SyntheticMouseDriver::Move(float x, float y, int index) { |
| 29 DCHECK_EQ(index, 0); | 61 DCHECK_EQ(index, 0); |
| 30 blink::WebMouseEvent::Button button = mouse_event_.button; | 62 blink::WebMouseEvent::Button button = mouse_event_.button; |
| 31 int click_count = mouse_event_.clickCount; | 63 int click_count = mouse_event_.clickCount; |
| 32 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 64 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 33 blink::WebInputEvent::MouseMove, x, y, 0); | 65 blink::WebInputEvent::MouseMove, x, y, last_modifiers_); |
| 34 mouse_event_.button = button; | 66 mouse_event_.button = button; |
| 35 mouse_event_.clickCount = click_count; | 67 mouse_event_.clickCount = click_count; |
| 36 } | 68 } |
| 37 | 69 |
| 38 void SyntheticMouseDriver::Release(int index) { | 70 void SyntheticMouseDriver::Release(int index, int button) { |
| 39 DCHECK_EQ(index, 0); | 71 DCHECK_EQ(index, 0); |
| 40 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 72 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 41 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, 0); | 73 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, |
| 74 last_modifiers_); |
| 42 mouse_event_.clickCount = 1; | 75 mouse_event_.clickCount = 1; |
| 76 mouse_event_.button = GetWebMouseEventButton(button); |
| 77 last_modifiers_ = last_modifiers_ & (~GetWebMouseEventModifier(button)); |
| 43 } | 78 } |
| 44 | 79 |
| 45 bool SyntheticMouseDriver::UserInputCheck( | 80 bool SyntheticMouseDriver::UserInputCheck( |
| 46 const SyntheticPointerActionParams& params) const { | 81 const SyntheticPointerActionParams& params) const { |
| 47 if (params.index() != 0) | 82 if (params.index() != 0) |
| 48 return false; | 83 return false; |
| 49 | 84 |
| 50 if (params.pointer_action_type() == | 85 if (params.pointer_action_type() == |
| 51 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { | 86 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { |
| 52 return false; | 87 return false; |
| 53 } | 88 } |
| 54 | 89 |
| 55 if (params.pointer_action_type() == | 90 if (params.pointer_action_type() == |
| 56 SyntheticPointerActionParams::PointerActionType::PRESS && | 91 SyntheticPointerActionParams::PointerActionType::PRESS) { |
| 57 mouse_event_.clickCount > 0) { | 92 int modifiers = GetWebMouseEventModifier(params.button()); |
| 58 return false; | 93 if (last_modifiers_ & modifiers) |
| 94 return false; |
| 59 } | 95 } |
| 60 | 96 |
| 61 if (params.pointer_action_type() == | 97 if (params.pointer_action_type() == |
| 62 SyntheticPointerActionParams::PointerActionType::RELEASE && | 98 SyntheticPointerActionParams::PointerActionType::RELEASE && |
| 63 mouse_event_.clickCount <= 0) { | 99 mouse_event_.clickCount <= 0) { |
| 64 return false; | 100 return false; |
| 65 } | 101 } |
| 66 | 102 |
| 67 return true; | 103 return true; |
| 68 } | 104 } |
| 69 | 105 |
| 70 } // namespace content | 106 } // namespace content |
| OLD | NEW |