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_smooth_scroll_gesture.h" | 5 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/gfx/geometry/point_f.h" | 8 #include "ui/gfx/geometry/point_f.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 namespace { | 11 namespace { |
12 | 12 |
13 gfx::Vector2d FloorTowardZero(const gfx::Vector2dF& vector) { | 13 gfx::Vector2d FloorTowardZero(const gfx::Vector2dF& vector) { |
14 int x = vector.x() > 0 ? floor(vector.x()) : ceil(vector.x()); | 14 int x = vector.x() > 0 ? floor(vector.x()) : ceil(vector.x()); |
15 int y = vector.y() > 0 ? floor(vector.y()) : ceil(vector.y()); | 15 int y = vector.y() > 0 ? floor(vector.y()) : ceil(vector.y()); |
16 return gfx::Vector2d(x, y); | 16 return gfx::Vector2d(x, y); |
17 } | 17 } |
18 | 18 |
19 gfx::Vector2d CeilFromZero(const gfx::Vector2dF& vector) { | 19 gfx::Vector2d CeilFromZero(const gfx::Vector2dF& vector) { |
20 int x = vector.x() > 0 ? ceil(vector.x()) : floor(vector.x()); | 20 int x = vector.x() > 0 ? ceil(vector.x()) : floor(vector.x()); |
21 int y = vector.y() > 0 ? ceil(vector.y()) : floor(vector.y()); | 21 int y = vector.y() > 0 ? ceil(vector.y()) : floor(vector.y()); |
22 return gfx::Vector2d(x, y); | 22 return gfx::Vector2d(x, y); |
23 } | 23 } |
24 | 24 |
25 gfx::Vector2dF ProjectScalarOntoVector( | 25 gfx::Vector2dF ProjectScalarOntoVector(float scalar, |
26 float scalar, const gfx::Vector2d& vector) { | 26 const gfx::Vector2dF& vector) { |
27 return gfx::ScaleVector2d(vector, scalar / vector.Length()); | 27 return gfx::ScaleVector2d(vector, scalar / vector.Length()); |
28 } | 28 } |
29 | 29 |
| 30 const int kDefaultSpeedInPixelsPerSec = 800; |
| 31 |
30 } // namespace | 32 } // namespace |
31 | 33 |
32 SyntheticSmoothScrollGesture::SyntheticSmoothScrollGesture( | 34 SyntheticSmoothMoveGestureParams::SyntheticSmoothMoveGestureParams() |
33 const SyntheticSmoothScrollGestureParams& params) | 35 : speed_in_pixels_s(kDefaultSpeedInPixelsPerSec), |
| 36 prevent_fling(true), |
| 37 add_slop(true) {} |
| 38 |
| 39 SyntheticSmoothMoveGestureParams::~SyntheticSmoothMoveGestureParams() {} |
| 40 |
| 41 SyntheticSmoothMoveGesture::SyntheticSmoothMoveGesture( |
| 42 SyntheticSmoothMoveGestureParams params) |
34 : params_(params), | 43 : params_(params), |
35 gesture_source_type_(SyntheticGestureParams::DEFAULT_INPUT), | 44 current_move_segment_start_position_(params.start_point), |
36 state_(SETUP) {} | 45 state_(SETUP) { |
| 46 } |
37 | 47 |
38 SyntheticSmoothScrollGesture::~SyntheticSmoothScrollGesture() {} | 48 SyntheticSmoothMoveGesture::~SyntheticSmoothMoveGesture() {} |
39 | 49 |
40 SyntheticGesture::Result SyntheticSmoothScrollGesture::ForwardInputEvents( | 50 SyntheticGesture::Result SyntheticSmoothMoveGesture::ForwardInputEvents( |
41 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { | 51 const base::TimeTicks& timestamp, |
| 52 SyntheticGestureTarget* target) { |
42 if (state_ == SETUP) { | 53 if (state_ == SETUP) { |
43 gesture_source_type_ = params_.gesture_source_type; | |
44 if (gesture_source_type_ == SyntheticGestureParams::DEFAULT_INPUT) | |
45 gesture_source_type_ = target->GetDefaultSyntheticGestureSourceType(); | |
46 | |
47 state_ = STARTED; | 54 state_ = STARTED; |
48 current_scroll_segment_ = -1; | 55 current_move_segment_ = -1; |
49 current_scroll_segment_stop_time_ = timestamp; | 56 current_move_segment_stop_time_ = timestamp; |
50 } | 57 } |
51 | 58 |
52 DCHECK_NE(gesture_source_type_, SyntheticGestureParams::DEFAULT_INPUT); | 59 switch (params_.input_type) { |
53 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) | 60 case SyntheticSmoothMoveGestureParams::TOUCH_INPUT: |
54 ForwardTouchInputEvents(timestamp, target); | 61 ForwardTouchInputEvents(timestamp, target); |
55 else if (gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) | 62 break; |
56 ForwardMouseInputEvents(timestamp, target); | 63 case SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT: |
57 else | 64 ForwardMouseClickInputEvents(timestamp, target); |
58 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; | 65 break; |
59 | 66 case SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT: |
| 67 ForwardMouseWheelInputEvents(timestamp, target); |
| 68 break; |
| 69 default: |
| 70 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; |
| 71 } |
60 return (state_ == DONE) ? SyntheticGesture::GESTURE_FINISHED | 72 return (state_ == DONE) ? SyntheticGesture::GESTURE_FINISHED |
61 : SyntheticGesture::GESTURE_RUNNING; | 73 : SyntheticGesture::GESTURE_RUNNING; |
62 } | 74 } |
63 | 75 |
64 void SyntheticSmoothScrollGesture::ForwardTouchInputEvents( | 76 // TODO(ssid): Clean up the switch statements by adding functions instead of |
65 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { | 77 // large code, in the Forward*Events functions. Move the actions for all input |
| 78 // types to different class (SyntheticInputDevice) which generates input events |
| 79 // for all input types. The gesture class can use instance of device actions. |
| 80 // Refer: crbug.com/461825 |
| 81 |
| 82 void SyntheticSmoothMoveGesture::ForwardTouchInputEvents( |
| 83 const base::TimeTicks& timestamp, |
| 84 SyntheticGestureTarget* target) { |
66 base::TimeTicks event_timestamp = timestamp; | 85 base::TimeTicks event_timestamp = timestamp; |
67 switch (state_) { | 86 switch (state_) { |
68 case STARTED: | 87 case STARTED: |
69 if (ScrollIsNoOp()) { | 88 if (MoveIsNoOp()) { |
70 state_ = DONE; | 89 state_ = DONE; |
71 break; | 90 break; |
72 } | 91 } |
73 AddTouchSlopToFirstDistance(target); | 92 if (params_.add_slop) |
74 ComputeNextScrollSegment(); | 93 AddTouchSlopToFirstDistance(target); |
75 current_scroll_segment_start_position_ = params_.anchor; | 94 ComputeNextMoveSegment(); |
76 PressTouchPoint(target, event_timestamp); | 95 PressTouchPoint(target, event_timestamp); |
77 state_ = MOVING; | 96 state_ = MOVING; |
78 break; | 97 break; |
79 case MOVING: { | 98 case MOVING: { |
80 event_timestamp = ClampTimestamp(timestamp); | 99 event_timestamp = ClampTimestamp(timestamp); |
81 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp); | 100 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp); |
82 MoveTouchPoint(target, delta, event_timestamp); | 101 MoveTouchPoint(target, delta, event_timestamp); |
83 | 102 |
84 if (FinishedCurrentScrollSegment(event_timestamp)) { | 103 if (FinishedCurrentMoveSegment(event_timestamp)) { |
85 if (!IsLastScrollSegment()) { | 104 if (!IsLastMoveSegment()) { |
86 current_scroll_segment_start_position_ += | 105 current_move_segment_start_position_ += |
87 params_.distances[current_scroll_segment_]; | 106 params_.distances[current_move_segment_]; |
88 ComputeNextScrollSegment(); | 107 ComputeNextMoveSegment(); |
89 } else if (params_.prevent_fling) { | 108 } else if (params_.prevent_fling) { |
90 state_ = STOPPING; | 109 state_ = STOPPING; |
91 } else { | 110 } else { |
92 ReleaseTouchPoint(target, event_timestamp); | 111 ReleaseTouchPoint(target, event_timestamp); |
93 state_ = DONE; | 112 state_ = DONE; |
94 } | 113 } |
95 } | 114 } |
96 } break; | 115 } break; |
97 case STOPPING: | 116 case STOPPING: |
98 if (timestamp - current_scroll_segment_stop_time_ >= | 117 if (timestamp - current_move_segment_stop_time_ >= |
99 target->PointerAssumedStoppedTime()) { | 118 target->PointerAssumedStoppedTime()) { |
100 event_timestamp = current_scroll_segment_stop_time_ + | 119 event_timestamp = current_move_segment_stop_time_ + |
101 target->PointerAssumedStoppedTime(); | 120 target->PointerAssumedStoppedTime(); |
102 ReleaseTouchPoint(target, event_timestamp); | 121 ReleaseTouchPoint(target, event_timestamp); |
103 state_ = DONE; | 122 state_ = DONE; |
104 } | 123 } |
105 break; | 124 break; |
106 case SETUP: | 125 case SETUP: |
107 NOTREACHED() | 126 NOTREACHED() |
108 << "State STARTED invalid for synthetic scroll using touch input."; | 127 << "State SETUP invalid for synthetic scroll using touch input."; |
109 case DONE: | 128 case DONE: |
110 NOTREACHED() | 129 NOTREACHED() |
111 << "State DONE invalid for synthetic scroll using touch input."; | 130 << "State DONE invalid for synthetic scroll using touch input."; |
112 } | 131 } |
113 } | 132 } |
114 | 133 |
115 void SyntheticSmoothScrollGesture::ForwardMouseInputEvents( | 134 void SyntheticSmoothMoveGesture::ForwardMouseWheelInputEvents( |
116 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { | 135 const base::TimeTicks& timestamp, |
| 136 SyntheticGestureTarget* target) { |
117 switch (state_) { | 137 switch (state_) { |
118 case STARTED: | 138 case STARTED: |
119 if (ScrollIsNoOp()) { | 139 if (MoveIsNoOp()) { |
120 state_ = DONE; | 140 state_ = DONE; |
121 break; | 141 break; |
122 } | 142 } |
123 ComputeNextScrollSegment(); | 143 ComputeNextMoveSegment(); |
124 state_ = MOVING; | 144 state_ = MOVING; |
125 // Fall through to forward the first event. | 145 // Fall through to forward the first event. |
126 case MOVING: { | 146 case MOVING: { |
127 // Even though WebMouseWheelEvents take floating point deltas, | 147 // Even though WebMouseWheelEvents take floating point deltas, |
128 // internally the scroll position is stored as an integer. We therefore | 148 // internally the scroll position is stored as an integer. We therefore |
129 // keep track of the discrete delta which is consistent with the | 149 // keep track of the discrete delta which is consistent with the |
130 // internal scrolling state. This ensures that when the gesture has | 150 // internal scrolling state. This ensures that when the gesture has |
131 // finished we've scrolled exactly the specified distance. | 151 // finished we've scrolled exactly the specified distance. |
132 base::TimeTicks event_timestamp = ClampTimestamp(timestamp); | 152 base::TimeTicks event_timestamp = ClampTimestamp(timestamp); |
133 gfx::Vector2dF current_scroll_segment_total_delta = | 153 gfx::Vector2dF current_move_segment_total_delta = |
134 GetPositionDeltaAtTime(event_timestamp); | 154 GetPositionDeltaAtTime(event_timestamp); |
135 gfx::Vector2d delta_discrete = | 155 gfx::Vector2d delta_discrete = |
136 FloorTowardZero(current_scroll_segment_total_delta - | 156 FloorTowardZero(current_move_segment_total_delta - |
137 current_scroll_segment_total_delta_discrete_); | 157 current_move_segment_total_delta_discrete_); |
138 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp); | 158 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp); |
139 current_scroll_segment_total_delta_discrete_ += delta_discrete; | 159 current_move_segment_total_delta_discrete_ += delta_discrete; |
140 | 160 |
141 if (FinishedCurrentScrollSegment(event_timestamp)) { | 161 if (FinishedCurrentMoveSegment(event_timestamp)) { |
142 if (!IsLastScrollSegment()) { | 162 if (!IsLastMoveSegment()) { |
143 current_scroll_segment_total_delta_discrete_ = gfx::Vector2d(); | 163 current_move_segment_total_delta_discrete_ = gfx::Vector2d(); |
144 ComputeNextScrollSegment(); | 164 ComputeNextMoveSegment(); |
145 ForwardMouseInputEvents(timestamp, target); | 165 ForwardMouseWheelInputEvents(timestamp, target); |
146 } else { | 166 } else { |
147 state_ = DONE; | 167 state_ = DONE; |
148 } | 168 } |
149 } | 169 } |
150 } break; | 170 } break; |
151 case SETUP: | 171 case SETUP: |
152 NOTREACHED() | 172 NOTREACHED() << "State SETUP invalid for synthetic scroll using mouse " |
153 << "State STARTED invalid for synthetic scroll using touch input."; | 173 "wheel input."; |
154 case STOPPING: | 174 case STOPPING: |
155 NOTREACHED() | 175 NOTREACHED() << "State STOPPING invalid for synthetic scroll using mouse " |
156 << "State STOPPING invalid for synthetic scroll using touch input."; | 176 "wheel input."; |
157 case DONE: | 177 case DONE: |
158 NOTREACHED() | 178 NOTREACHED() |
159 << "State DONE invalid for synthetic scroll using touch input."; | 179 << "State DONE invalid for synthetic scroll using mouse wheel input."; |
160 } | 180 } |
161 } | 181 } |
162 | 182 |
163 void SyntheticSmoothScrollGesture::ForwardTouchEvent( | 183 void SyntheticSmoothMoveGesture::ForwardMouseClickInputEvents( |
164 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { | 184 const base::TimeTicks& timestamp, |
| 185 SyntheticGestureTarget* target) { |
| 186 base::TimeTicks event_timestamp = timestamp; |
| 187 switch (state_) { |
| 188 case STARTED: |
| 189 if (MoveIsNoOp()) { |
| 190 state_ = DONE; |
| 191 break; |
| 192 } |
| 193 ComputeNextMoveSegment(); |
| 194 PressMousePoint(target, event_timestamp); |
| 195 state_ = MOVING; |
| 196 break; |
| 197 case MOVING: { |
| 198 base::TimeTicks event_timestamp = ClampTimestamp(timestamp); |
| 199 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp); |
| 200 MoveMousePoint(target, delta, event_timestamp); |
| 201 |
| 202 if (FinishedCurrentMoveSegment(event_timestamp)) { |
| 203 if (!IsLastMoveSegment()) { |
| 204 current_move_segment_start_position_ += |
| 205 params_.distances[current_move_segment_]; |
| 206 ComputeNextMoveSegment(); |
| 207 } else { |
| 208 ReleaseMousePoint(target, event_timestamp); |
| 209 state_ = DONE; |
| 210 } |
| 211 } |
| 212 } break; |
| 213 case STOPPING: |
| 214 NOTREACHED() |
| 215 << "State STOPPING invalid for synthetic drag using mouse input."; |
| 216 case SETUP: |
| 217 NOTREACHED() |
| 218 << "State SETUP invalid for synthetic drag using mouse input."; |
| 219 case DONE: |
| 220 NOTREACHED() |
| 221 << "State DONE invalid for synthetic drag using mouse input."; |
| 222 } |
| 223 } |
| 224 |
| 225 void SyntheticSmoothMoveGesture::ForwardTouchEvent( |
| 226 SyntheticGestureTarget* target, |
| 227 const base::TimeTicks& timestamp) { |
165 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 228 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
166 | 229 |
167 target->DispatchInputEventToPlatform(touch_event_); | 230 target->DispatchInputEventToPlatform(touch_event_); |
168 } | 231 } |
169 | 232 |
170 void SyntheticSmoothScrollGesture::ForwardMouseWheelEvent( | 233 void SyntheticSmoothMoveGesture::ForwardMouseWheelEvent( |
171 SyntheticGestureTarget* target, | 234 SyntheticGestureTarget* target, |
172 const gfx::Vector2dF& delta, | 235 const gfx::Vector2dF& delta, |
173 const base::TimeTicks& timestamp) const { | 236 const base::TimeTicks& timestamp) const { |
174 blink::WebMouseWheelEvent mouse_wheel_event = | 237 blink::WebMouseWheelEvent mouse_wheel_event = |
175 SyntheticWebMouseWheelEventBuilder::Build(delta.x(), delta.y(), 0, false); | 238 SyntheticWebMouseWheelEventBuilder::Build(delta.x(), delta.y(), 0, false); |
176 | 239 |
177 mouse_wheel_event.x = params_.anchor.x(); | 240 mouse_wheel_event.x = current_move_segment_start_position_.x(); |
178 mouse_wheel_event.y = params_.anchor.y(); | 241 mouse_wheel_event.y = current_move_segment_start_position_.y(); |
179 | 242 |
180 mouse_wheel_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 243 mouse_wheel_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
181 | 244 |
182 target->DispatchInputEventToPlatform(mouse_wheel_event); | 245 target->DispatchInputEventToPlatform(mouse_wheel_event); |
183 } | 246 } |
184 | 247 |
185 void SyntheticSmoothScrollGesture::PressTouchPoint( | 248 void SyntheticSmoothMoveGesture::PressTouchPoint( |
186 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { | 249 SyntheticGestureTarget* target, |
187 DCHECK_EQ(current_scroll_segment_, 0); | 250 const base::TimeTicks& timestamp) { |
188 touch_event_.PressPoint(params_.anchor.x(), params_.anchor.y()); | 251 DCHECK_EQ(current_move_segment_, 0); |
| 252 touch_event_.PressPoint(current_move_segment_start_position_.x(), |
| 253 current_move_segment_start_position_.y()); |
189 ForwardTouchEvent(target, timestamp); | 254 ForwardTouchEvent(target, timestamp); |
190 } | 255 } |
191 | 256 |
192 void SyntheticSmoothScrollGesture::MoveTouchPoint( | 257 void SyntheticSmoothMoveGesture::MoveTouchPoint( |
193 SyntheticGestureTarget* target, | 258 SyntheticGestureTarget* target, |
194 const gfx::Vector2dF& delta, | 259 const gfx::Vector2dF& delta, |
195 const base::TimeTicks& timestamp) { | 260 const base::TimeTicks& timestamp) { |
196 DCHECK_GE(current_scroll_segment_, 0); | 261 DCHECK_GE(current_move_segment_, 0); |
197 DCHECK_LT(current_scroll_segment_, | 262 DCHECK_LT(current_move_segment_, static_cast<int>(params_.distances.size())); |
198 static_cast<int>(params_.distances.size())); | 263 gfx::PointF touch_position = current_move_segment_start_position_ + delta; |
199 gfx::PointF touch_position = current_scroll_segment_start_position_ + delta; | |
200 touch_event_.MovePoint(0, touch_position.x(), touch_position.y()); | 264 touch_event_.MovePoint(0, touch_position.x(), touch_position.y()); |
201 ForwardTouchEvent(target, timestamp); | 265 ForwardTouchEvent(target, timestamp); |
202 } | 266 } |
203 | 267 |
204 void SyntheticSmoothScrollGesture::ReleaseTouchPoint( | 268 void SyntheticSmoothMoveGesture::ReleaseTouchPoint( |
205 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { | 269 SyntheticGestureTarget* target, |
206 DCHECK_EQ(current_scroll_segment_, | 270 const base::TimeTicks& timestamp) { |
| 271 DCHECK_EQ(current_move_segment_, |
207 static_cast<int>(params_.distances.size()) - 1); | 272 static_cast<int>(params_.distances.size()) - 1); |
208 touch_event_.ReleasePoint(0); | 273 touch_event_.ReleasePoint(0); |
209 ForwardTouchEvent(target, timestamp); | 274 ForwardTouchEvent(target, timestamp); |
210 } | 275 } |
211 | 276 |
212 void SyntheticSmoothScrollGesture::AddTouchSlopToFirstDistance( | 277 void SyntheticSmoothMoveGesture::PressMousePoint( |
| 278 SyntheticGestureTarget* target, |
| 279 const base::TimeTicks& timestamp) { |
| 280 DCHECK_EQ(params_.input_type, |
| 281 SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT); |
| 282 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build( |
| 283 blink::WebInputEvent::MouseDown, current_move_segment_start_position_.x(), |
| 284 current_move_segment_start_position_.y(), 0); |
| 285 mouse_event.clickCount = 1; |
| 286 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 287 target->DispatchInputEventToPlatform(mouse_event); |
| 288 } |
| 289 |
| 290 void SyntheticSmoothMoveGesture::ReleaseMousePoint( |
| 291 SyntheticGestureTarget* target, |
| 292 const base::TimeTicks& timestamp) { |
| 293 DCHECK_EQ(params_.input_type, |
| 294 SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT); |
| 295 gfx::PointF mouse_position = |
| 296 current_move_segment_start_position_ + GetPositionDeltaAtTime(timestamp); |
| 297 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build( |
| 298 blink::WebInputEvent::MouseUp, mouse_position.x(), mouse_position.y(), 0); |
| 299 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 300 target->DispatchInputEventToPlatform(mouse_event); |
| 301 } |
| 302 |
| 303 void SyntheticSmoothMoveGesture::MoveMousePoint( |
| 304 SyntheticGestureTarget* target, |
| 305 const gfx::Vector2dF& delta, |
| 306 const base::TimeTicks& timestamp) { |
| 307 gfx::PointF mouse_position = current_move_segment_start_position_ + delta; |
| 308 DCHECK_EQ(params_.input_type, |
| 309 SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT); |
| 310 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build( |
| 311 blink::WebInputEvent::MouseMove, mouse_position.x(), mouse_position.y(), |
| 312 0); |
| 313 mouse_event.button = blink::WebMouseEvent::ButtonLeft; |
| 314 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 315 target->DispatchInputEventToPlatform(mouse_event); |
| 316 } |
| 317 |
| 318 void SyntheticSmoothMoveGesture::AddTouchSlopToFirstDistance( |
213 SyntheticGestureTarget* target) { | 319 SyntheticGestureTarget* target) { |
214 DCHECK_GE(params_.distances.size(), 1ul); | 320 DCHECK_GE(params_.distances.size(), 1ul); |
215 gfx::Vector2d& first_scroll_distance = params_.distances[0]; | 321 gfx::Vector2dF& first_move_distance = params_.distances[0]; |
216 DCHECK_GT(first_scroll_distance.Length(), 0); | 322 DCHECK_GT(first_move_distance.Length(), 0); |
217 first_scroll_distance += CeilFromZero(ProjectScalarOntoVector( | 323 first_move_distance += CeilFromZero(ProjectScalarOntoVector( |
218 target->GetTouchSlopInDips(), first_scroll_distance)); | 324 target->GetTouchSlopInDips(), first_move_distance)); |
219 } | 325 } |
220 | 326 |
221 gfx::Vector2dF SyntheticSmoothScrollGesture::GetPositionDeltaAtTime( | 327 gfx::Vector2dF SyntheticSmoothMoveGesture::GetPositionDeltaAtTime( |
222 const base::TimeTicks& timestamp) const { | 328 const base::TimeTicks& timestamp) const { |
223 // Make sure the final delta is correct. Using the computation below can lead | 329 // Make sure the final delta is correct. Using the computation below can lead |
224 // to issues with floating point precision. | 330 // to issues with floating point precision. |
225 if (FinishedCurrentScrollSegment(timestamp)) | 331 if (FinishedCurrentMoveSegment(timestamp)) |
226 return params_.distances[current_scroll_segment_]; | 332 return params_.distances[current_move_segment_]; |
227 | 333 |
228 float delta_length = | 334 float delta_length = |
229 params_.speed_in_pixels_s * | 335 params_.speed_in_pixels_s * |
230 (timestamp - current_scroll_segment_start_time_).InSecondsF(); | 336 (timestamp - current_move_segment_start_time_).InSecondsF(); |
231 return ProjectScalarOntoVector(delta_length, | 337 return ProjectScalarOntoVector(delta_length, |
232 params_.distances[current_scroll_segment_]); | 338 params_.distances[current_move_segment_]); |
233 } | 339 } |
234 | 340 |
235 void SyntheticSmoothScrollGesture::ComputeNextScrollSegment() { | 341 void SyntheticSmoothMoveGesture::ComputeNextMoveSegment() { |
236 current_scroll_segment_++; | 342 current_move_segment_++; |
237 DCHECK_LT(current_scroll_segment_, | 343 DCHECK_LT(current_move_segment_, static_cast<int>(params_.distances.size())); |
238 static_cast<int>(params_.distances.size())); | |
239 int64 total_duration_in_us = static_cast<int64>( | 344 int64 total_duration_in_us = static_cast<int64>( |
240 1e6 * (params_.distances[current_scroll_segment_].Length() / | 345 1e6 * (params_.distances[current_move_segment_].Length() / |
241 params_.speed_in_pixels_s)); | 346 params_.speed_in_pixels_s)); |
242 DCHECK_GT(total_duration_in_us, 0); | 347 DCHECK_GT(total_duration_in_us, 0); |
243 current_scroll_segment_start_time_ = current_scroll_segment_stop_time_; | 348 current_move_segment_start_time_ = current_move_segment_stop_time_; |
244 current_scroll_segment_stop_time_ = | 349 current_move_segment_stop_time_ = |
245 current_scroll_segment_start_time_ + | 350 current_move_segment_start_time_ + |
246 base::TimeDelta::FromMicroseconds(total_duration_in_us); | 351 base::TimeDelta::FromMicroseconds(total_duration_in_us); |
247 } | 352 } |
248 | 353 |
249 base::TimeTicks SyntheticSmoothScrollGesture::ClampTimestamp( | 354 base::TimeTicks SyntheticSmoothMoveGesture::ClampTimestamp( |
250 const base::TimeTicks& timestamp) const { | 355 const base::TimeTicks& timestamp) const { |
251 return std::min(timestamp, current_scroll_segment_stop_time_); | 356 return std::min(timestamp, current_move_segment_stop_time_); |
252 } | 357 } |
253 | 358 |
254 bool SyntheticSmoothScrollGesture::FinishedCurrentScrollSegment( | 359 bool SyntheticSmoothMoveGesture::FinishedCurrentMoveSegment( |
255 const base::TimeTicks& timestamp) const { | 360 const base::TimeTicks& timestamp) const { |
256 return timestamp >= current_scroll_segment_stop_time_; | 361 return timestamp >= current_move_segment_stop_time_; |
257 } | 362 } |
258 | 363 |
259 bool SyntheticSmoothScrollGesture::IsLastScrollSegment() const { | 364 bool SyntheticSmoothMoveGesture::IsLastMoveSegment() const { |
260 DCHECK_LT(current_scroll_segment_, | 365 DCHECK_LT(current_move_segment_, static_cast<int>(params_.distances.size())); |
261 static_cast<int>(params_.distances.size())); | 366 return current_move_segment_ == |
262 return current_scroll_segment_ == | |
263 static_cast<int>(params_.distances.size()) - 1; | 367 static_cast<int>(params_.distances.size()) - 1; |
264 } | 368 } |
265 | 369 |
266 bool SyntheticSmoothScrollGesture::ScrollIsNoOp() const { | 370 bool SyntheticSmoothMoveGesture::MoveIsNoOp() const { |
267 return params_.distances.size() == 0 || params_.distances[0].IsZero(); | 371 return params_.distances.size() == 0 || params_.distances[0].IsZero(); |
268 } | 372 } |
269 | 373 |
270 } // namespace content | 374 } // namespace content |
OLD | NEW |