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