Chromium Code Reviews| 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() : last_modifiers_(0) {} | 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); | |
|
tdresser
2017/01/25 15:22:46
This DCHECK is redundant with the NOTREACHED at th
lanwei
2017/01/26 02:55:40
Done.
| |
| 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 SyntheticMouseDriver::SyntheticMouseDriver() | |
| 27 : last_modifiers_(0), | |
| 28 pointer_type_(blink::WebPointerProperties::PointerType::Mouse) {} | |
| 29 | |
| 30 SyntheticMouseDriver::SyntheticMouseDriver( | |
| 31 SyntheticGestureParams::GestureSourceType gesture_source_type) | |
| 32 : last_modifiers_(0), | |
| 33 pointer_type_(GetWebPointerType(gesture_source_type)) {} | |
| 12 | 34 |
| 13 SyntheticMouseDriver::~SyntheticMouseDriver() {} | 35 SyntheticMouseDriver::~SyntheticMouseDriver() {} |
| 14 | 36 |
| 15 void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target, | 37 void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target, |
| 16 const base::TimeTicks& timestamp) { | 38 const base::TimeTicks& timestamp) { |
| 17 mouse_event_.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); | 39 mouse_event_.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); |
| 18 target->DispatchInputEventToPlatform(mouse_event_); | 40 target->DispatchInputEventToPlatform(mouse_event_); |
| 19 } | 41 } |
| 20 | 42 |
| 21 void SyntheticMouseDriver::Press(float x, | 43 void SyntheticMouseDriver::Press(float x, |
| 22 float y, | 44 float y, |
| 23 int index, | 45 int index, |
| 24 SyntheticPointerActionParams::Button button) { | 46 SyntheticPointerActionParams::Button button) { |
| 25 DCHECK_EQ(index, 0); | 47 DCHECK_EQ(index, 0); |
| 26 int modifiers = | 48 int modifiers = |
| 27 SyntheticPointerActionParams::GetWebMouseEventModifier(button); | 49 SyntheticPointerActionParams::GetWebMouseEventModifier(button); |
| 28 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 50 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 29 blink::WebInputEvent::MouseDown, x, y, modifiers | last_modifiers_); | 51 blink::WebInputEvent::MouseDown, x, y, modifiers | last_modifiers_, |
| 52 pointer_type_); | |
| 30 mouse_event_.clickCount = 1; | 53 mouse_event_.clickCount = 1; |
| 31 mouse_event_.button = | 54 mouse_event_.button = |
| 32 SyntheticPointerActionParams::GetWebMouseEventButton(button); | 55 SyntheticPointerActionParams::GetWebMouseEventButton(button); |
| 33 last_modifiers_ = modifiers | last_modifiers_; | 56 last_modifiers_ = modifiers | last_modifiers_; |
| 34 } | 57 } |
| 35 | 58 |
| 36 void SyntheticMouseDriver::Move(float x, float y, int index) { | 59 void SyntheticMouseDriver::Move(float x, float y, int index) { |
| 37 DCHECK_EQ(index, 0); | 60 DCHECK_EQ(index, 0); |
| 38 blink::WebMouseEvent::Button button = mouse_event_.button; | 61 blink::WebMouseEvent::Button button = mouse_event_.button; |
| 39 int click_count = mouse_event_.clickCount; | 62 int click_count = mouse_event_.clickCount; |
| 40 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 63 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 41 blink::WebInputEvent::MouseMove, x, y, last_modifiers_); | 64 blink::WebInputEvent::MouseMove, x, y, last_modifiers_, pointer_type_); |
| 42 mouse_event_.button = button; | 65 mouse_event_.button = button; |
| 43 mouse_event_.clickCount = click_count; | 66 mouse_event_.clickCount = click_count; |
| 44 } | 67 } |
| 45 | 68 |
| 46 void SyntheticMouseDriver::Release( | 69 void SyntheticMouseDriver::Release( |
| 47 int index, | 70 int index, |
| 48 SyntheticPointerActionParams::Button button) { | 71 SyntheticPointerActionParams::Button button) { |
| 49 DCHECK_EQ(index, 0); | 72 DCHECK_EQ(index, 0); |
| 50 mouse_event_ = SyntheticWebMouseEventBuilder::Build( | 73 mouse_event_ = SyntheticWebMouseEventBuilder::Build( |
| 51 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, | 74 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, |
| 52 last_modifiers_); | 75 last_modifiers_, pointer_type_); |
| 53 mouse_event_.clickCount = 1; | 76 mouse_event_.clickCount = 1; |
| 54 mouse_event_.button = | 77 mouse_event_.button = |
| 55 SyntheticPointerActionParams::GetWebMouseEventButton(button); | 78 SyntheticPointerActionParams::GetWebMouseEventButton(button); |
| 56 last_modifiers_ = | 79 last_modifiers_ = |
| 57 last_modifiers_ & | 80 last_modifiers_ & |
| 58 (~SyntheticPointerActionParams::GetWebMouseEventModifier(button)); | 81 (~SyntheticPointerActionParams::GetWebMouseEventModifier(button)); |
| 59 } | 82 } |
| 60 | 83 |
| 61 bool SyntheticMouseDriver::UserInputCheck( | 84 bool SyntheticMouseDriver::UserInputCheck( |
| 62 const SyntheticPointerActionParams& params) const { | 85 const SyntheticPointerActionParams& params) const { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 79 if (params.pointer_action_type() == | 102 if (params.pointer_action_type() == |
| 80 SyntheticPointerActionParams::PointerActionType::RELEASE && | 103 SyntheticPointerActionParams::PointerActionType::RELEASE && |
| 81 mouse_event_.clickCount <= 0) { | 104 mouse_event_.clickCount <= 0) { |
| 82 return false; | 105 return false; |
| 83 } | 106 } |
| 84 | 107 |
| 85 return true; | 108 return true; |
| 86 } | 109 } |
| 87 | 110 |
| 88 } // namespace content | 111 } // namespace content |
| OLD | NEW |