| 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 SyntheticMouseDriver::SyntheticMouseDriver() : last_modifiers_(0) {} |
| 12 | 12 |
| 13 SyntheticMouseDriver::~SyntheticMouseDriver() {} | 13 SyntheticMouseDriver::~SyntheticMouseDriver() {} |
| 14 | 14 |
| 15 void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target, | 15 void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target, |
| 16 const base::TimeTicks& timestamp) { | 16 const base::TimeTicks& timestamp) { |
| 17 mouse_event_.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); | 17 mouse_event_.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); |
| 18 target->DispatchInputEventToPlatform(mouse_event_); | 18 target->DispatchInputEventToPlatform(mouse_event_); |
| 19 } | 19 } |
| 20 | 20 |
| 21 void SyntheticMouseDriver::Press(float x, float y, int index) { | 21 void SyntheticMouseDriver::Press(float x, float y, int index, int button) { |
| 22 DCHECK_EQ(index, 0); | 22 DCHECK_EQ(index, 0); |
| 23 int modifiers = GetWebMouseEventModifier(button); |
| 23 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 24 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 24 blink::WebInputEvent::MouseDown, x, y, 0); | 25 blink::WebInputEvent::MouseDown, x, y, modifiers | last_modifiers_); |
| 25 mouse_event_.clickCount = 1; | 26 mouse_event_.clickCount = 1; |
| 27 mouse_event_.button = GetWebMouseEventButton(button); |
| 28 last_modifiers_ = modifiers | last_modifiers_; |
| 26 } | 29 } |
| 27 | 30 |
| 28 void SyntheticMouseDriver::Move(float x, float y, int index) { | 31 void SyntheticMouseDriver::Move(float x, float y, int index) { |
| 29 DCHECK_EQ(index, 0); | 32 DCHECK_EQ(index, 0); |
| 30 blink::WebMouseEvent::Button button = mouse_event_.button; | 33 blink::WebMouseEvent::Button button = mouse_event_.button; |
| 31 int click_count = mouse_event_.clickCount; | 34 int click_count = mouse_event_.clickCount; |
| 32 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 35 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 33 blink::WebInputEvent::MouseMove, x, y, 0); | 36 blink::WebInputEvent::MouseMove, x, y, last_modifiers_); |
| 34 mouse_event_.button = button; | 37 mouse_event_.button = button; |
| 35 mouse_event_.clickCount = click_count; | 38 mouse_event_.clickCount = click_count; |
| 36 } | 39 } |
| 37 | 40 |
| 38 void SyntheticMouseDriver::Release(int index) { | 41 void SyntheticMouseDriver::Release(int index, int button) { |
| 39 DCHECK_EQ(index, 0); | 42 DCHECK_EQ(index, 0); |
| 40 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 43 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 41 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, 0); | 44 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, |
| 45 last_modifiers_); |
| 42 mouse_event_.clickCount = 1; | 46 mouse_event_.clickCount = 1; |
| 47 mouse_event_.button = GetWebMouseEventButton(button); |
| 48 last_modifiers_ = last_modifiers_ & (~GetWebMouseEventModifier(button)); |
| 43 } | 49 } |
| 44 | 50 |
| 45 bool SyntheticMouseDriver::UserInputCheck( | 51 bool SyntheticMouseDriver::UserInputCheck( |
| 46 const SyntheticPointerActionParams& params) const { | 52 const SyntheticPointerActionParams& params) const { |
| 47 if (params.index() != 0) | 53 if (params.index() != 0) |
| 48 return false; | 54 return false; |
| 49 | 55 |
| 50 if (params.pointer_action_type() == | 56 if (params.pointer_action_type() == |
| 51 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { | 57 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { |
| 52 return false; | 58 return false; |
| 53 } | 59 } |
| 54 | 60 |
| 55 if (params.pointer_action_type() == | 61 if (params.pointer_action_type() == |
| 56 SyntheticPointerActionParams::PointerActionType::PRESS && | 62 SyntheticPointerActionParams::PointerActionType::PRESS) { |
| 57 mouse_event_.clickCount > 0) { | 63 int modifiers = GetWebMouseEventModifier(params.button()); |
| 58 return false; | 64 if (last_modifiers_ & modifiers) |
| 65 return false; |
| 59 } | 66 } |
| 60 | 67 |
| 61 if (params.pointer_action_type() == | 68 if (params.pointer_action_type() == |
| 62 SyntheticPointerActionParams::PointerActionType::RELEASE && | 69 SyntheticPointerActionParams::PointerActionType::RELEASE && |
| 63 mouse_event_.clickCount <= 0) { | 70 mouse_event_.clickCount <= 0) { |
| 64 return false; | 71 return false; |
| 65 } | 72 } |
| 66 | 73 |
| 67 return true; | 74 return true; |
| 68 } | 75 } |
| 69 | 76 |
| 77 // static |
| 78 unsigned SyntheticMouseDriver::GetWebMouseEventModifier(int button) { |
| 79 switch (button) { |
| 80 case 0: |
| 81 return blink::WebMouseEvent::LeftButtonDown; |
| 82 case 1: |
| 83 return blink::WebMouseEvent::MiddleButtonDown; |
| 84 case 2: |
| 85 return blink::WebMouseEvent::RightButtonDown; |
| 86 } |
| 87 NOTREACHED(); |
| 88 return blink::WebMouseEvent::NoModifiers; |
| 89 } |
| 90 |
| 91 // static |
| 92 blink::WebMouseEvent::Button SyntheticMouseDriver::GetWebMouseEventButton( |
| 93 int button) { |
| 94 switch (button) { |
| 95 case 0: |
| 96 return blink::WebMouseEvent::Button::Left; |
| 97 case 1: |
| 98 return blink::WebMouseEvent::Button::Middle; |
| 99 case 2: |
| 100 return blink::WebMouseEvent::Button::Right; |
| 101 } |
| 102 NOTREACHED(); |
| 103 return blink::WebMouseEvent::Button::NoButton; |
| 104 } |
| 105 |
| 70 } // namespace content | 106 } // namespace content |
| OLD | NEW |