Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: content/browser/renderer_host/input/synthetic_smooth_move_gesture.cc

Issue 929333002: Adding synthetic touch/mouse drag [Part1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Splitting CL and adding unittests. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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::Vector2dF& 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 input_type,
34 : params_(params), 34 gfx::PointF start_point,
35 gesture_source_type_(SyntheticGestureParams::DEFAULT_INPUT), 35 std::vector<gfx::Vector2dF> move_distances,
36 state_(SETUP) {} 36 int speed_in_pixels_s,
37 bool prevent_fling)
38 : current_move_segment_start_position_(start_point),
39 input_type_(input_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 (input_type_ == TOUCH_SCROLL_INPUT || input_type_ == TOUCH_DRAG_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 (input_type_ == MOUSE_DRAG_INPUT)
56 ForwardMouseInputEvents(timestamp, target); 59 ForwardMouseClickInputEvents(timestamp, target);
60 else if (input_type_ == MOUSE_WHEEL_INPUT)
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 // TODO (ssid) clean up the switch statements by adding functions, instead of
70 // large code, in the Forward*Events functions.
71
72 void SyntheticSmoothMoveGesture::ForwardTouchInputEvents(
65 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { 73 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) {
66 base::TimeTicks event_timestamp = timestamp; 74 base::TimeTicks event_timestamp = timestamp;
67 switch (state_) { 75 switch (state_) {
68 case STARTED: 76 case STARTED:
69 if (ScrollIsNoOp()) { 77 if (MoveIsNoOp()) {
70 state_ = DONE; 78 state_ = DONE;
71 break; 79 break;
72 } 80 }
73 AddTouchSlopToFirstDistance(target); 81 if (input_type_ == TOUCH_SCROLL_INPUT)
74 ComputeNextScrollSegment(); 82 AddTouchSlopToFirstDistance(target);
75 current_scroll_segment_start_position_ = params_.anchor; 83 ComputeNextMoveSegment();
76 PressTouchPoint(target, event_timestamp); 84 PressTouchPoint(target, event_timestamp);
77 state_ = MOVING; 85 state_ = MOVING;
78 break; 86 break;
79 case MOVING: { 87 case MOVING: {
80 event_timestamp = ClampTimestamp(timestamp); 88 event_timestamp = ClampTimestamp(timestamp);
81 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp); 89 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp);
82 MoveTouchPoint(target, delta, event_timestamp); 90 MoveTouchPoint(target, delta, event_timestamp);
83 91
84 if (FinishedCurrentScrollSegment(event_timestamp)) { 92 if (FinishedCurrentMoveSegment(event_timestamp)) {
85 if (!IsLastScrollSegment()) { 93 if (!IsLastMoveSegment()) {
86 current_scroll_segment_start_position_ += 94 current_move_segment_start_position_ +=
87 params_.distances[current_scroll_segment_]; 95 move_distances_[current_move_segment_];
88 ComputeNextScrollSegment(); 96 ComputeNextMoveSegment();
89 } else if (params_.prevent_fling) { 97 } else if (prevent_fling_) {
90 state_ = STOPPING; 98 state_ = STOPPING;
91 } else { 99 } else {
92 ReleaseTouchPoint(target, event_timestamp); 100 ReleaseTouchPoint(target, event_timestamp);
93 state_ = DONE; 101 state_ = DONE;
94 } 102 }
95 } 103 }
96 } break; 104 } break;
97 case STOPPING: 105 case STOPPING:
98 if (timestamp - current_scroll_segment_stop_time_ >= 106 if (timestamp - current_move_segment_stop_time_ >=
99 target->PointerAssumedStoppedTime()) { 107 target->PointerAssumedStoppedTime()) {
100 event_timestamp = current_scroll_segment_stop_time_ + 108 event_timestamp = current_move_segment_stop_time_ +
101 target->PointerAssumedStoppedTime(); 109 target->PointerAssumedStoppedTime();
102 ReleaseTouchPoint(target, event_timestamp); 110 ReleaseTouchPoint(target, event_timestamp);
103 state_ = DONE; 111 state_ = DONE;
104 } 112 }
105 break; 113 break;
106 case SETUP: 114 case SETUP:
107 NOTREACHED() 115 NOTREACHED()
108 << "State STARTED invalid for synthetic scroll using touch input."; 116 << "State SETUP invalid for synthetic scroll using touch input.";
109 case DONE: 117 case DONE:
110 NOTREACHED() 118 NOTREACHED()
111 << "State DONE invalid for synthetic scroll using touch input."; 119 << "State DONE invalid for synthetic scroll using touch input.";
112 } 120 }
113 } 121 }
114 122
115 void SyntheticSmoothScrollGesture::ForwardMouseInputEvents( 123 void SyntheticSmoothMoveGesture::ForwardMouseWheelInputEvents(
116 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { 124 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) {
117 switch (state_) { 125 switch (state_) {
118 case STARTED: 126 case STARTED:
119 if (ScrollIsNoOp()) { 127 if (MoveIsNoOp()) {
120 state_ = DONE; 128 state_ = DONE;
121 break; 129 break;
122 } 130 }
123 ComputeNextScrollSegment(); 131 ComputeNextMoveSegment();
124 state_ = MOVING; 132 state_ = MOVING;
125 // Fall through to forward the first event. 133 // Fall through to forward the first event.
126 case MOVING: { 134 case MOVING: {
127 // Even though WebMouseWheelEvents take floating point deltas, 135 // Even though WebMouseWheelEvents take floating point deltas,
128 // internally the scroll position is stored as an integer. We therefore 136 // internally the scroll position is stored as an integer. We therefore
129 // keep track of the discrete delta which is consistent with the 137 // keep track of the discrete delta which is consistent with the
130 // internal scrolling state. This ensures that when the gesture has 138 // internal scrolling state. This ensures that when the gesture has
131 // finished we've scrolled exactly the specified distance. 139 // finished we've scrolled exactly the specified distance.
132 base::TimeTicks event_timestamp = ClampTimestamp(timestamp); 140 base::TimeTicks event_timestamp = ClampTimestamp(timestamp);
133 gfx::Vector2dF current_scroll_segment_total_delta = 141 gfx::Vector2dF current_move_segment_total_delta =
134 GetPositionDeltaAtTime(event_timestamp); 142 GetPositionDeltaAtTime(event_timestamp);
135 gfx::Vector2d delta_discrete = 143 gfx::Vector2d delta_discrete =
136 FloorTowardZero(current_scroll_segment_total_delta - 144 FloorTowardZero(current_move_segment_total_delta -
137 current_scroll_segment_total_delta_discrete_); 145 current_move_segment_total_delta_discrete_);
138 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp); 146 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp);
139 current_scroll_segment_total_delta_discrete_ += delta_discrete; 147 current_move_segment_total_delta_discrete_ += delta_discrete;
140 148
141 if (FinishedCurrentScrollSegment(event_timestamp)) { 149 if (FinishedCurrentMoveSegment(event_timestamp)) {
142 if (!IsLastScrollSegment()) { 150 if (!IsLastMoveSegment()) {
143 current_scroll_segment_total_delta_discrete_ = gfx::Vector2d(); 151 current_move_segment_total_delta_discrete_ = gfx::Vector2d();
144 ComputeNextScrollSegment(); 152 ComputeNextMoveSegment();
145 ForwardMouseInputEvents(timestamp, target); 153 ForwardMouseWheelInputEvents(timestamp, target);
146 } else { 154 } else {
147 state_ = DONE; 155 state_ = DONE;
148 } 156 }
149 } 157 }
150 } break; 158 } break;
151 case SETUP: 159 case SETUP:
152 NOTREACHED() 160 NOTREACHED()
153 << "State STARTED invalid for synthetic scroll using touch input."; 161 << "State SETUP invalid for synthetic scroll using mouse "
162 "wheel input.";
154 case STOPPING: 163 case STOPPING:
155 NOTREACHED() 164 NOTREACHED()
156 << "State STOPPING invalid for synthetic scroll using touch input."; 165 << "State STOPPING invalid for synthetic scroll using mouse "
166 "wheel input.";
157 case DONE: 167 case DONE:
158 NOTREACHED() 168 NOTREACHED()
159 << "State DONE invalid for synthetic scroll using touch input."; 169 << "State DONE invalid for synthetic scroll using mouse wheel input.";
160 } 170 }
161 } 171 }
162 172
163 void SyntheticSmoothScrollGesture::ForwardTouchEvent( 173 void SyntheticSmoothMoveGesture::ForwardMouseClickInputEvents(
174 const base::TimeTicks& timestamp,
175 SyntheticGestureTarget* target) {
176 base::TimeTicks event_timestamp = timestamp;
177 switch (state_) {
178 case STARTED:
179 if (MoveIsNoOp()) {
180 state_ = DONE;
181 break;
182 }
183 ComputeNextMoveSegment();
184 PressMousePoint(target, event_timestamp);
185 state_ = MOVING;
186 // Fall through to forward the first event.
petrcermak 2015/02/20 12:21:09 nit: I think that this should be indented two more
ssid 2015/02/20 15:58:30 Thanks!
187 case MOVING: {
188 base::TimeTicks event_timestamp = ClampTimestamp(timestamp);
189 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp);
190 MoveMousePoint(target, delta, event_timestamp);
191
192 if (FinishedCurrentMoveSegment(event_timestamp)) {
193 if (!IsLastMoveSegment()) {
194 current_move_segment_start_position_ +=
195 move_distances_[current_move_segment_];
196 ComputeNextMoveSegment();
197 } else {
198 ReleaseMousePoint(target, event_timestamp);
199 state_ = DONE;
200 }
201 }
202 } break;
203 case STOPPING:
204 NOTREACHED()
205 << "State STOPPING invalid for synthetic drag using mouse input.";
206 case SETUP:
207 NOTREACHED()
208 << "State SETUP invalid for synthetic drag using mouse input.";
209 case DONE:
210 NOTREACHED()
211 << "State DONE invalid for synthetic drag using mouse input.";
212 }
213 }
214
215 void SyntheticSmoothMoveGesture::ForwardTouchEvent(
164 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { 216 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) {
165 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); 217 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp);
166 218
167 target->DispatchInputEventToPlatform(touch_event_); 219 target->DispatchInputEventToPlatform(touch_event_);
168 } 220 }
169 221
170 void SyntheticSmoothScrollGesture::ForwardMouseWheelEvent( 222 void SyntheticSmoothMoveGesture::ForwardMouseWheelEvent(
171 SyntheticGestureTarget* target, 223 SyntheticGestureTarget* target,
172 const gfx::Vector2dF& delta, 224 const gfx::Vector2dF& delta,
173 const base::TimeTicks& timestamp) const { 225 const base::TimeTicks& timestamp) const {
174 blink::WebMouseWheelEvent mouse_wheel_event = 226 blink::WebMouseWheelEvent mouse_wheel_event =
175 SyntheticWebMouseWheelEventBuilder::Build(delta.x(), delta.y(), 0, false); 227 SyntheticWebMouseWheelEventBuilder::Build(delta.x(), delta.y(), 0, false);
176 228
177 mouse_wheel_event.x = params_.anchor.x(); 229 mouse_wheel_event.x = current_move_segment_start_position_.x();
178 mouse_wheel_event.y = params_.anchor.y(); 230 mouse_wheel_event.y = current_move_segment_start_position_.y();
179 231
180 mouse_wheel_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); 232 mouse_wheel_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp);
181 233
182 target->DispatchInputEventToPlatform(mouse_wheel_event); 234 target->DispatchInputEventToPlatform(mouse_wheel_event);
183 } 235 }
184 236
185 void SyntheticSmoothScrollGesture::PressTouchPoint( 237 void SyntheticSmoothMoveGesture::PressTouchPoint(
186 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { 238 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) {
187 DCHECK_EQ(current_scroll_segment_, 0); 239 DCHECK_EQ(current_move_segment_, 0);
188 touch_event_.PressPoint(params_.anchor.x(), params_.anchor.y()); 240 touch_event_.PressPoint(current_move_segment_start_position_.x(),
241 current_move_segment_start_position_.y());
189 ForwardTouchEvent(target, timestamp); 242 ForwardTouchEvent(target, timestamp);
190 } 243 }
191 244
192 void SyntheticSmoothScrollGesture::MoveTouchPoint( 245 void SyntheticSmoothMoveGesture::MoveTouchPoint(
193 SyntheticGestureTarget* target, 246 SyntheticGestureTarget* target,
194 const gfx::Vector2dF& delta, 247 const gfx::Vector2dF& delta,
195 const base::TimeTicks& timestamp) { 248 const base::TimeTicks& timestamp) {
196 DCHECK_GE(current_scroll_segment_, 0); 249 DCHECK_GE(current_move_segment_, 0);
197 DCHECK_LT(current_scroll_segment_, 250 DCHECK_LT(current_move_segment_, static_cast<int>(move_distances_.size()));
198 static_cast<int>(params_.distances.size())); 251 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()); 252 touch_event_.MovePoint(0, touch_position.x(), touch_position.y());
201 ForwardTouchEvent(target, timestamp); 253 ForwardTouchEvent(target, timestamp);
202 } 254 }
203 255
204 void SyntheticSmoothScrollGesture::ReleaseTouchPoint( 256 void SyntheticSmoothMoveGesture::ReleaseTouchPoint(
205 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { 257 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) {
206 DCHECK_EQ(current_scroll_segment_, 258 DCHECK_EQ(current_move_segment_,
207 static_cast<int>(params_.distances.size()) - 1); 259 static_cast<int>(move_distances_.size()) - 1);
208 touch_event_.ReleasePoint(0); 260 touch_event_.ReleasePoint(0);
209 ForwardTouchEvent(target, timestamp); 261 ForwardTouchEvent(target, timestamp);
210 } 262 }
211 263
212 void SyntheticSmoothScrollGesture::AddTouchSlopToFirstDistance( 264 void SyntheticSmoothMoveGesture::PressMousePoint(SyntheticGestureTarget* target,
213 SyntheticGestureTarget* target) { 265 const base::TimeTicks& timestamp) {
214 DCHECK_GE(params_.distances.size(), 1ul); 266 DCHECK(input_type_ == MOUSE_DRAG_INPUT);
215 gfx::Vector2d& first_scroll_distance = params_.distances[0]; 267 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build(
216 DCHECK_GT(first_scroll_distance.Length(), 0); 268 blink::WebInputEvent::MouseDown, current_move_segment_start_position_.x(),
217 first_scroll_distance += CeilFromZero(ProjectScalarOntoVector( 269 current_move_segment_start_position_.y(), 0);
218 target->GetTouchSlopInDips(), first_scroll_distance)); 270 mouse_event.clickCount = 1;
271 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp);
272 target->DispatchInputEventToPlatform(mouse_event);
219 } 273 }
220 274
221 gfx::Vector2dF SyntheticSmoothScrollGesture::GetPositionDeltaAtTime( 275 void SyntheticSmoothMoveGesture::ReleaseMousePoint(
276 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) {
277 DCHECK(input_type_ == MOUSE_DRAG_INPUT);
278 gfx::PointF mouse_position =
279 current_move_segment_start_position_ + GetPositionDeltaAtTime(timestamp);
280 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build(
281 blink::WebInputEvent::MouseUp, mouse_position.x(), mouse_position.y(), 0);
282 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp);
283 target->DispatchInputEventToPlatform(mouse_event);
284 }
285
286 void SyntheticSmoothMoveGesture::MoveMousePoint(SyntheticGestureTarget* target,
287 const gfx::Vector2dF& delta,
288 const base::TimeTicks& timestamp) {
289 gfx::PointF mouse_position = current_move_segment_start_position_ + delta;
290 DCHECK(input_type_ == MOUSE_DRAG_INPUT);
291 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build(
292 blink::WebInputEvent::MouseMove, mouse_position.x(), mouse_position.y(),
293 0);
294 mouse_event.button = blink::WebMouseEvent::ButtonLeft;
295 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp);
296 target->DispatchInputEventToPlatform(mouse_event);
297 }
298
299 void SyntheticSmoothMoveGesture::AddTouchSlopToFirstDistance(
300 SyntheticGestureTarget* target) {
301 DCHECK_GE(move_distances_.size(), 1ul);
302 gfx::Vector2dF& first_move_distance = move_distances_[0];
303 DCHECK_GT(first_move_distance.Length(), 0);
304 first_move_distance += CeilFromZero(ProjectScalarOntoVector(
305 target->GetTouchSlopInDips(), first_move_distance));
306 }
307
308 gfx::Vector2dF SyntheticSmoothMoveGesture::GetPositionDeltaAtTime(
222 const base::TimeTicks& timestamp) const { 309 const base::TimeTicks& timestamp) const {
223 // Make sure the final delta is correct. Using the computation below can lead 310 // Make sure the final delta is correct. Using the computation below can lead
224 // to issues with floating point precision. 311 // to issues with floating point precision.
225 if (FinishedCurrentScrollSegment(timestamp)) 312 if (FinishedCurrentMoveSegment(timestamp))
226 return params_.distances[current_scroll_segment_]; 313 return move_distances_[current_move_segment_];
227 314
228 float delta_length = 315 float delta_length =
229 params_.speed_in_pixels_s * 316 speed_in_pixels_s_ *
230 (timestamp - current_scroll_segment_start_time_).InSecondsF(); 317 (timestamp - current_move_segment_start_time_).InSecondsF();
231 return ProjectScalarOntoVector(delta_length, 318 return ProjectScalarOntoVector(delta_length,
232 params_.distances[current_scroll_segment_]); 319 move_distances_[current_move_segment_]);
233 } 320 }
234 321
235 void SyntheticSmoothScrollGesture::ComputeNextScrollSegment() { 322 void SyntheticSmoothMoveGesture::ComputeNextMoveSegment() {
236 current_scroll_segment_++; 323 current_move_segment_++;
237 DCHECK_LT(current_scroll_segment_, 324 DCHECK_LT(current_move_segment_,
238 static_cast<int>(params_.distances.size())); 325 static_cast<int>(move_distances_.size()));
239 int64 total_duration_in_us = static_cast<int64>( 326 int64 total_duration_in_us = static_cast<int64>(
240 1e6 * (params_.distances[current_scroll_segment_].Length() / 327 1e6 *
241 params_.speed_in_pixels_s)); 328 (move_distances_[current_move_segment_].Length() / speed_in_pixels_s_));
242 DCHECK_GT(total_duration_in_us, 0); 329 DCHECK_GT(total_duration_in_us, 0);
243 current_scroll_segment_start_time_ = current_scroll_segment_stop_time_; 330 current_move_segment_start_time_ = current_move_segment_stop_time_;
244 current_scroll_segment_stop_time_ = 331 current_move_segment_stop_time_ =
245 current_scroll_segment_start_time_ + 332 current_move_segment_start_time_ +
246 base::TimeDelta::FromMicroseconds(total_duration_in_us); 333 base::TimeDelta::FromMicroseconds(total_duration_in_us);
247 } 334 }
248 335
249 base::TimeTicks SyntheticSmoothScrollGesture::ClampTimestamp( 336 base::TimeTicks SyntheticSmoothMoveGesture::ClampTimestamp(
250 const base::TimeTicks& timestamp) const { 337 const base::TimeTicks& timestamp) const {
251 return std::min(timestamp, current_scroll_segment_stop_time_); 338 return std::min(timestamp, current_move_segment_stop_time_);
252 } 339 }
253 340
254 bool SyntheticSmoothScrollGesture::FinishedCurrentScrollSegment( 341 bool SyntheticSmoothMoveGesture::FinishedCurrentMoveSegment(
255 const base::TimeTicks& timestamp) const { 342 const base::TimeTicks& timestamp) const {
256 return timestamp >= current_scroll_segment_stop_time_; 343 return timestamp >= current_move_segment_stop_time_;
257 } 344 }
258 345
259 bool SyntheticSmoothScrollGesture::IsLastScrollSegment() const { 346 bool SyntheticSmoothMoveGesture::IsLastMoveSegment() const {
260 DCHECK_LT(current_scroll_segment_, 347 DCHECK_LT(current_move_segment_, static_cast<int>(move_distances_.size()));
261 static_cast<int>(params_.distances.size())); 348 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 } 349 }
265 350
266 bool SyntheticSmoothScrollGesture::ScrollIsNoOp() const { 351 bool SyntheticSmoothMoveGesture::MoveIsNoOp() const {
267 return params_.distances.size() == 0 || params_.distances[0].IsZero(); 352 return move_distances_.size() == 0 || move_distances_[0].IsZero();
268 } 353 }
269 354
270 } // namespace content 355 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698