| 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, |
| 22 float y, |
| 23 int index, |
| 24 SyntheticPointerActionParams::Button button) { |
| 22 DCHECK_EQ(index, 0); | 25 DCHECK_EQ(index, 0); |
| 26 int modifiers = |
| 27 SyntheticPointerActionParams::GetWebMouseEventModifier(button); |
| 23 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 28 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 24 blink::WebInputEvent::MouseDown, x, y, 0); | 29 blink::WebInputEvent::MouseDown, x, y, modifiers | last_modifiers_); |
| 25 mouse_event_.clickCount = 1; | 30 mouse_event_.clickCount = 1; |
| 31 mouse_event_.button = |
| 32 SyntheticPointerActionParams::GetWebMouseEventButton(button); |
| 33 last_modifiers_ = modifiers | last_modifiers_; |
| 26 } | 34 } |
| 27 | 35 |
| 28 void SyntheticMouseDriver::Move(float x, float y, int index) { | 36 void SyntheticMouseDriver::Move(float x, float y, int index) { |
| 29 DCHECK_EQ(index, 0); | 37 DCHECK_EQ(index, 0); |
| 30 blink::WebMouseEvent::Button button = mouse_event_.button; | 38 blink::WebMouseEvent::Button button = mouse_event_.button; |
| 31 int click_count = mouse_event_.clickCount; | 39 int click_count = mouse_event_.clickCount; |
| 32 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 40 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 33 blink::WebInputEvent::MouseMove, x, y, 0); | 41 blink::WebInputEvent::MouseMove, x, y, last_modifiers_); |
| 34 mouse_event_.button = button; | 42 mouse_event_.button = button; |
| 35 mouse_event_.clickCount = click_count; | 43 mouse_event_.clickCount = click_count; |
| 36 } | 44 } |
| 37 | 45 |
| 38 void SyntheticMouseDriver::Release(int index) { | 46 void SyntheticMouseDriver::Release( |
| 47 int index, |
| 48 SyntheticPointerActionParams::Button button) { |
| 39 DCHECK_EQ(index, 0); | 49 DCHECK_EQ(index, 0); |
| 40 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 50 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 41 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, 0); | 51 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, |
| 52 last_modifiers_); |
| 42 mouse_event_.clickCount = 1; | 53 mouse_event_.clickCount = 1; |
| 54 mouse_event_.button = |
| 55 SyntheticPointerActionParams::GetWebMouseEventButton(button); |
| 56 last_modifiers_ = |
| 57 last_modifiers_ & |
| 58 (~SyntheticPointerActionParams::GetWebMouseEventModifier(button)); |
| 43 } | 59 } |
| 44 | 60 |
| 45 bool SyntheticMouseDriver::UserInputCheck( | 61 bool SyntheticMouseDriver::UserInputCheck( |
| 46 const SyntheticPointerActionParams& params) const { | 62 const SyntheticPointerActionParams& params) const { |
| 47 if (params.index() != 0) | 63 if (params.index() != 0) |
| 48 return false; | 64 return false; |
| 49 | 65 |
| 50 if (params.pointer_action_type() == | 66 if (params.pointer_action_type() == |
| 51 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { | 67 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { |
| 52 return false; | 68 return false; |
| 53 } | 69 } |
| 54 | 70 |
| 55 if (params.pointer_action_type() == | 71 if (params.pointer_action_type() == |
| 56 SyntheticPointerActionParams::PointerActionType::PRESS && | 72 SyntheticPointerActionParams::PointerActionType::PRESS) { |
| 57 mouse_event_.clickCount > 0) { | 73 int modifiers = |
| 58 return false; | 74 SyntheticPointerActionParams::GetWebMouseEventModifier(params.button()); |
| 75 if (last_modifiers_ & modifiers) |
| 76 return false; |
| 59 } | 77 } |
| 60 | 78 |
| 61 if (params.pointer_action_type() == | 79 if (params.pointer_action_type() == |
| 62 SyntheticPointerActionParams::PointerActionType::RELEASE && | 80 SyntheticPointerActionParams::PointerActionType::RELEASE && |
| 63 mouse_event_.clickCount <= 0) { | 81 mouse_event_.clickCount <= 0) { |
| 64 return false; | 82 return false; |
| 65 } | 83 } |
| 66 | 84 |
| 67 return true; | 85 return true; |
| 68 } | 86 } |
| 69 | 87 |
| 70 } // namespace content | 88 } // namespace content |
| OLD | NEW |