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" | 8 #include "content/common/input/input_event.h" |
9 #include "third_party/WebKit/public/web/WebInputEvent.h" | 9 #include "third_party/WebKit/public/web/WebInputEvent.h" |
10 #include "ui/events/latency_info.h" | 10 #include "ui/events/latency_info.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 const SyntheticTapGestureParams& params) | 24 const SyntheticTapGestureParams& params) |
25 : params_(params), | 25 : params_(params), |
26 gesture_source_type_(SyntheticGestureParams::DEFAULT_INPUT), | 26 gesture_source_type_(SyntheticGestureParams::DEFAULT_INPUT), |
27 state_(SETUP) { | 27 state_(SETUP) { |
28 DCHECK_GE(params_.duration_ms, 0); | 28 DCHECK_GE(params_.duration_ms, 0); |
29 } | 29 } |
30 | 30 |
31 SyntheticTapGesture::~SyntheticTapGesture() {} | 31 SyntheticTapGesture::~SyntheticTapGesture() {} |
32 | 32 |
33 SyntheticGesture::Result SyntheticTapGesture::ForwardInputEvents( | 33 SyntheticGesture::Result SyntheticTapGesture::ForwardInputEvents( |
34 const base::TimeDelta& interval, SyntheticGestureTarget* target) { | 34 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { |
35 if (state_ == SETUP) { | 35 if (state_ == SETUP) { |
36 gesture_source_type_ = params_.gesture_source_type; | 36 gesture_source_type_ = params_.gesture_source_type; |
37 if (gesture_source_type_ == SyntheticGestureParams::DEFAULT_INPUT) | 37 if (gesture_source_type_ == SyntheticGestureParams::DEFAULT_INPUT) |
38 gesture_source_type_ = target->GetDefaultSyntheticGestureSourceType(); | 38 gesture_source_type_ = target->GetDefaultSyntheticGestureSourceType(); |
39 | 39 |
40 if (!target->SupportsSyntheticGestureSourceType(gesture_source_type_)) | 40 if (!target->SupportsSyntheticGestureSourceType(gesture_source_type_)) |
41 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_SUPPORTED_BY_PLATFORM; | 41 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_SUPPORTED_BY_PLATFORM; |
42 | 42 |
43 state_ = PRESS; | 43 state_ = PRESS; |
44 } | 44 } |
45 | 45 |
46 DCHECK_NE(gesture_source_type_, SyntheticGestureParams::DEFAULT_INPUT); | 46 DCHECK_NE(gesture_source_type_, SyntheticGestureParams::DEFAULT_INPUT); |
47 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT || | 47 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT || |
48 gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) | 48 gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) |
49 ForwardTouchOrMouseInputEvents(interval, target); | 49 ForwardTouchOrMouseInputEvents(timestamp, target); |
50 else | 50 else |
51 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; | 51 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; |
52 | 52 |
53 return (state_ == DONE) ? SyntheticGesture::GESTURE_FINISHED | 53 return (state_ == DONE) ? SyntheticGesture::GESTURE_FINISHED |
54 : SyntheticGesture::GESTURE_RUNNING; | 54 : SyntheticGesture::GESTURE_RUNNING; |
55 } | 55 } |
56 | 56 |
57 void SyntheticTapGesture::ForwardTouchOrMouseInputEvents( | 57 void SyntheticTapGesture::ForwardTouchOrMouseInputEvents( |
58 const base::TimeDelta& interval, SyntheticGestureTarget* target) { | 58 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { |
59 switch (state_) { | 59 switch (state_) { |
60 case PRESS: | 60 case PRESS: |
61 Press(target); | 61 Press(target, timestamp); |
62 // Release immediately if duration is 0. | 62 // Release immediately if duration is 0. |
63 if (params_.duration_ms == 0) { | 63 if (params_.duration_ms == 0) { |
64 Release(target); | 64 Release(target, timestamp); |
65 state_ = DONE; | 65 state_ = DONE; |
66 } else { | 66 } else { |
| 67 start_time_ = timestamp; |
67 state_ = WAITING_TO_RELEASE; | 68 state_ = WAITING_TO_RELEASE; |
68 } | 69 } |
69 break; | 70 break; |
70 case WAITING_TO_RELEASE: | 71 case WAITING_TO_RELEASE: |
71 total_waiting_time_ += interval; | 72 if (timestamp - start_time_ >= GetDuration()) { |
72 if (total_waiting_time_ >= | 73 Release(target, start_time_ + GetDuration()); |
73 base::TimeDelta::FromMilliseconds(params_.duration_ms)) { | |
74 Release(target); | |
75 state_ = DONE; | 74 state_ = DONE; |
76 } | 75 } |
77 break; | 76 break; |
78 case SETUP: | 77 case SETUP: |
79 NOTREACHED() << "State SETUP invalid for synthetic tap gesture."; | 78 NOTREACHED() << "State SETUP invalid for synthetic tap gesture."; |
80 case DONE: | 79 case DONE: |
81 NOTREACHED() << "State DONE invalid for synthetic tap gesture."; | 80 NOTREACHED() << "State DONE invalid for synthetic tap gesture."; |
82 } | 81 } |
83 } | 82 } |
84 | 83 |
85 void SyntheticTapGesture::Press(SyntheticGestureTarget* target) { | 84 void SyntheticTapGesture::Press(SyntheticGestureTarget* target, |
| 85 const base::TimeTicks& timestamp) { |
86 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) { | 86 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) { |
87 touch_event_.PressPoint(params_.position.x(), params_.position.y()); | 87 touch_event_.PressPoint(params_.position.x(), params_.position.y()); |
| 88 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
88 DispatchEventToPlatform(target, touch_event_); | 89 DispatchEventToPlatform(target, touch_event_); |
89 } else if (gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) { | 90 } else if (gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) { |
90 blink::WebMouseEvent mouse_event = | 91 blink::WebMouseEvent mouse_event = |
91 SyntheticWebMouseEventBuilder::Build(blink::WebInputEvent::MouseDown, | 92 SyntheticWebMouseEventBuilder::Build(blink::WebInputEvent::MouseDown, |
92 params_.position.x(), | 93 params_.position.x(), |
93 params_.position.y(), | 94 params_.position.y(), |
94 0); | 95 0); |
95 mouse_event.clickCount = 1; | 96 mouse_event.clickCount = 1; |
| 97 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
96 DispatchEventToPlatform(target, mouse_event); | 98 DispatchEventToPlatform(target, mouse_event); |
97 } else { | 99 } else { |
98 NOTREACHED() << "Invalid gesture source type for synthetic tap gesture."; | 100 NOTREACHED() << "Invalid gesture source type for synthetic tap gesture."; |
99 } | 101 } |
100 } | 102 } |
101 | 103 |
102 void SyntheticTapGesture::Release(SyntheticGestureTarget* target) { | 104 void SyntheticTapGesture::Release(SyntheticGestureTarget* target, |
| 105 const base::TimeTicks& timestamp) { |
103 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) { | 106 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) { |
104 touch_event_.ReleasePoint(0); | 107 touch_event_.ReleasePoint(0); |
| 108 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
105 DispatchEventToPlatform(target, touch_event_); | 109 DispatchEventToPlatform(target, touch_event_); |
106 } else if (gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) { | 110 } else if (gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) { |
107 blink::WebMouseEvent mouse_event = | 111 blink::WebMouseEvent mouse_event = |
108 SyntheticWebMouseEventBuilder::Build(blink::WebInputEvent::MouseUp, | 112 SyntheticWebMouseEventBuilder::Build(blink::WebInputEvent::MouseUp, |
109 params_.position.x(), | 113 params_.position.x(), |
110 params_.position.y(), | 114 params_.position.y(), |
111 0); | 115 0); |
112 mouse_event.clickCount = 1; | 116 mouse_event.clickCount = 1; |
| 117 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
113 DispatchEventToPlatform(target, mouse_event); | 118 DispatchEventToPlatform(target, mouse_event); |
114 } else { | 119 } else { |
115 NOTREACHED() << "Invalid gesture source type for synthetic tap gesture."; | 120 NOTREACHED() << "Invalid gesture source type for synthetic tap gesture."; |
116 } | 121 } |
117 } | 122 } |
118 | 123 |
| 124 base::TimeDelta SyntheticTapGesture::GetDuration() const { |
| 125 return base::TimeDelta::FromMilliseconds(params_.duration_ms); |
| 126 } |
| 127 |
119 } // namespace content | 128 } // namespace content |
OLD | NEW |