| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_tap_gesture.h" | 5 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/common/input/input_event.h" | |
| 9 #include "third_party/WebKit/public/web/WebInputEvent.h" | 8 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 10 #include "ui/events/latency_info.h" | 9 #include "ui/events/latency_info.h" |
| 11 | 10 |
| 12 namespace content { | 11 namespace content { |
| 13 namespace { | |
| 14 | |
| 15 void DispatchEventToPlatform(SyntheticGestureTarget* target, | |
| 16 const blink::WebInputEvent& event) { | |
| 17 target->DispatchInputEventToPlatform( | |
| 18 InputEvent(event, ui::LatencyInfo(), false)); | |
| 19 } | |
| 20 | |
| 21 } // namespace | |
| 22 | 12 |
| 23 SyntheticTapGesture::SyntheticTapGesture( | 13 SyntheticTapGesture::SyntheticTapGesture( |
| 24 const SyntheticTapGestureParams& params) | 14 const SyntheticTapGestureParams& params) |
| 25 : params_(params), | 15 : params_(params), |
| 26 gesture_source_type_(SyntheticGestureParams::DEFAULT_INPUT), | 16 gesture_source_type_(SyntheticGestureParams::DEFAULT_INPUT), |
| 27 state_(SETUP) { | 17 state_(SETUP) { |
| 28 DCHECK_GE(params_.duration_ms, 0); | 18 DCHECK_GE(params_.duration_ms, 0); |
| 29 } | 19 } |
| 30 | 20 |
| 31 SyntheticTapGesture::~SyntheticTapGesture() {} | 21 SyntheticTapGesture::~SyntheticTapGesture() {} |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 case DONE: | 69 case DONE: |
| 80 NOTREACHED() << "State DONE invalid for synthetic tap gesture."; | 70 NOTREACHED() << "State DONE invalid for synthetic tap gesture."; |
| 81 } | 71 } |
| 82 } | 72 } |
| 83 | 73 |
| 84 void SyntheticTapGesture::Press(SyntheticGestureTarget* target, | 74 void SyntheticTapGesture::Press(SyntheticGestureTarget* target, |
| 85 const base::TimeTicks& timestamp) { | 75 const base::TimeTicks& timestamp) { |
| 86 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) { | 76 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) { |
| 87 touch_event_.PressPoint(params_.position.x(), params_.position.y()); | 77 touch_event_.PressPoint(params_.position.x(), params_.position.y()); |
| 88 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 78 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 89 DispatchEventToPlatform(target, touch_event_); | 79 target->DispatchInputEventToPlatform(touch_event_); |
| 90 } else if (gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) { | 80 } else if (gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) { |
| 91 blink::WebMouseEvent mouse_event = | 81 blink::WebMouseEvent mouse_event = |
| 92 SyntheticWebMouseEventBuilder::Build(blink::WebInputEvent::MouseDown, | 82 SyntheticWebMouseEventBuilder::Build(blink::WebInputEvent::MouseDown, |
| 93 params_.position.x(), | 83 params_.position.x(), |
| 94 params_.position.y(), | 84 params_.position.y(), |
| 95 0); | 85 0); |
| 96 mouse_event.clickCount = 1; | 86 mouse_event.clickCount = 1; |
| 97 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 87 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 98 DispatchEventToPlatform(target, mouse_event); | 88 target->DispatchInputEventToPlatform(mouse_event); |
| 99 } else { | 89 } else { |
| 100 NOTREACHED() << "Invalid gesture source type for synthetic tap gesture."; | 90 NOTREACHED() << "Invalid gesture source type for synthetic tap gesture."; |
| 101 } | 91 } |
| 102 } | 92 } |
| 103 | 93 |
| 104 void SyntheticTapGesture::Release(SyntheticGestureTarget* target, | 94 void SyntheticTapGesture::Release(SyntheticGestureTarget* target, |
| 105 const base::TimeTicks& timestamp) { | 95 const base::TimeTicks& timestamp) { |
| 106 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) { | 96 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) { |
| 107 touch_event_.ReleasePoint(0); | 97 touch_event_.ReleasePoint(0); |
| 108 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 98 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 109 DispatchEventToPlatform(target, touch_event_); | 99 target->DispatchInputEventToPlatform(touch_event_); |
| 110 } else if (gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) { | 100 } else if (gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) { |
| 111 blink::WebMouseEvent mouse_event = | 101 blink::WebMouseEvent mouse_event = |
| 112 SyntheticWebMouseEventBuilder::Build(blink::WebInputEvent::MouseUp, | 102 SyntheticWebMouseEventBuilder::Build(blink::WebInputEvent::MouseUp, |
| 113 params_.position.x(), | 103 params_.position.x(), |
| 114 params_.position.y(), | 104 params_.position.y(), |
| 115 0); | 105 0); |
| 116 mouse_event.clickCount = 1; | 106 mouse_event.clickCount = 1; |
| 117 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 107 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 118 DispatchEventToPlatform(target, mouse_event); | 108 target->DispatchInputEventToPlatform(mouse_event); |
| 119 } else { | 109 } else { |
| 120 NOTREACHED() << "Invalid gesture source type for synthetic tap gesture."; | 110 NOTREACHED() << "Invalid gesture source type for synthetic tap gesture."; |
| 121 } | 111 } |
| 122 } | 112 } |
| 123 | 113 |
| 124 base::TimeDelta SyntheticTapGesture::GetDuration() const { | 114 base::TimeDelta SyntheticTapGesture::GetDuration() const { |
| 125 return base::TimeDelta::FromMilliseconds(params_.duration_ms); | 115 return base::TimeDelta::FromMilliseconds(params_.duration_ms); |
| 126 } | 116 } |
| 127 | 117 |
| 128 } // namespace content | 118 } // namespace content |
| OLD | NEW |