| 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 blink::WebPointerProperties::PointerType GetWebPointerType( |
| 14 SyntheticGestureParams::GestureSourceType gesture_source_type) { |
| 15 DCHECK(gesture_source_type == SyntheticGestureParams::MOUSE_INPUT || |
| 16 gesture_source_type == SyntheticGestureParams::PEN_INPUT); |
| 17 if (gesture_source_type == SyntheticGestureParams::MOUSE_INPUT) |
| 18 return blink::WebPointerProperties::PointerType::Mouse; |
| 19 if (gesture_source_type == SyntheticGestureParams::PEN_INPUT) |
| 20 return blink::WebPointerProperties::PointerType::Pen; |
| 21 NOTREACHED(); |
| 22 return blink::WebPointerProperties::PointerType::Unknown; |
| 23 } |
| 24 |
| 25 } |
| 26 |
| 27 SyntheticMouseDriver::SyntheticMouseDriver() |
| 28 : pointer_type_(blink::WebPointerProperties::PointerType::Mouse) {} |
| 29 |
| 30 SyntheticMouseDriver::SyntheticMouseDriver( |
| 31 SyntheticGestureParams::GestureSourceType gesture_source_type) |
| 32 : pointer_type_(GetWebPointerType(gesture_source_type)) {} |
| 12 | 33 |
| 13 SyntheticMouseDriver::~SyntheticMouseDriver() {} | 34 SyntheticMouseDriver::~SyntheticMouseDriver() {} |
| 14 | 35 |
| 15 void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target, | 36 void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target, |
| 16 const base::TimeTicks& timestamp) { | 37 const base::TimeTicks& timestamp) { |
| 17 mouse_event_.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); | 38 mouse_event_.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); |
| 18 target->DispatchInputEventToPlatform(mouse_event_); | 39 target->DispatchInputEventToPlatform(mouse_event_); |
| 19 } | 40 } |
| 20 | 41 |
| 21 void SyntheticMouseDriver::Press(float x, float y, int index) { | 42 void SyntheticMouseDriver::Press(float x, float y, int index) { |
| 22 DCHECK_EQ(index, 0); | 43 DCHECK_EQ(index, 0); |
| 23 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 44 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 24 blink::WebInputEvent::MouseDown, x, y, 0); | 45 blink::WebInputEvent::MouseDown, x, y, 0, pointer_type_); |
| 25 mouse_event_.clickCount = 1; | 46 mouse_event_.clickCount = 1; |
| 26 } | 47 } |
| 27 | 48 |
| 28 void SyntheticMouseDriver::Move(float x, float y, int index) { | 49 void SyntheticMouseDriver::Move(float x, float y, int index) { |
| 29 DCHECK_EQ(index, 0); | 50 DCHECK_EQ(index, 0); |
| 30 blink::WebMouseEvent::Button button = mouse_event_.button; | 51 blink::WebMouseEvent::Button button = mouse_event_.button; |
| 31 int click_count = mouse_event_.clickCount; | 52 int click_count = mouse_event_.clickCount; |
| 32 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 53 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 33 blink::WebInputEvent::MouseMove, x, y, 0); | 54 blink::WebInputEvent::MouseMove, x, y, 0, pointer_type_); |
| 34 mouse_event_.button = button; | 55 mouse_event_.button = button; |
| 35 mouse_event_.clickCount = click_count; | 56 mouse_event_.clickCount = click_count; |
| 36 } | 57 } |
| 37 | 58 |
| 38 void SyntheticMouseDriver::Release(int index) { | 59 void SyntheticMouseDriver::Release(int index) { |
| 39 DCHECK_EQ(index, 0); | 60 DCHECK_EQ(index, 0); |
| 40 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 61 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 41 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, 0); | 62 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, 0, |
| 63 pointer_type_); |
| 42 mouse_event_.clickCount = 1; | 64 mouse_event_.clickCount = 1; |
| 43 } | 65 } |
| 44 | 66 |
| 45 bool SyntheticMouseDriver::UserInputCheck( | 67 bool SyntheticMouseDriver::UserInputCheck( |
| 46 const SyntheticPointerActionParams& params) const { | 68 const SyntheticPointerActionParams& params) const { |
| 47 if (params.index() != 0) | 69 if (params.index() != 0) |
| 48 return false; | 70 return false; |
| 49 | 71 |
| 50 if (params.pointer_action_type() == | 72 if (params.pointer_action_type() == |
| 51 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { | 73 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { |
| 52 return false; | 74 return false; |
| 53 } | 75 } |
| 54 | 76 |
| 55 if (params.pointer_action_type() == | 77 if (params.pointer_action_type() == |
| 56 SyntheticPointerActionParams::PointerActionType::PRESS && | 78 SyntheticPointerActionParams::PointerActionType::PRESS && |
| 57 mouse_event_.clickCount > 0) { | 79 mouse_event_.clickCount > 0) { |
| 58 return false; | 80 return false; |
| 59 } | 81 } |
| 60 | 82 |
| 61 if (params.pointer_action_type() == | 83 if (params.pointer_action_type() == |
| 62 SyntheticPointerActionParams::PointerActionType::RELEASE && | 84 SyntheticPointerActionParams::PointerActionType::RELEASE && |
| 63 mouse_event_.clickCount <= 0) { | 85 mouse_event_.clickCount <= 0) { |
| 64 return false; | 86 return false; |
| 65 } | 87 } |
| 66 | 88 |
| 67 return true; | 89 return true; |
| 68 } | 90 } |
| 69 | 91 |
| 70 } // namespace content | 92 } // namespace content |
| OLD | NEW |