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

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: Adderessed comments. Created 5 years, 9 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(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
jdduke (slow) 2015/02/25 15:58:25 Thanks, could you also file a bug for this and lin
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
81 void SyntheticSmoothMoveGesture::ForwardTouchInputEvents(
82 const base::TimeTicks& timestamp,
83 SyntheticGestureTarget* target) {
66 base::TimeTicks event_timestamp = timestamp; 84 base::TimeTicks event_timestamp = timestamp;
67 switch (state_) { 85 switch (state_) {
68 case STARTED: 86 case STARTED:
69 if (ScrollIsNoOp()) { 87 if (MoveIsNoOp()) {
70 state_ = DONE; 88 state_ = DONE;
71 break; 89 break;
72 } 90 }
73 AddTouchSlopToFirstDistance(target); 91 if (params_.add_slop)
74 ComputeNextScrollSegment(); 92 AddTouchSlopToFirstDistance(target);
75 current_scroll_segment_start_position_ = params_.anchor; 93 ComputeNextMoveSegment();
76 PressTouchPoint(target, event_timestamp); 94 PressTouchPoint(target, event_timestamp);
77 state_ = MOVING; 95 state_ = MOVING;
78 break; 96 break;
79 case MOVING: { 97 case MOVING: {
80 event_timestamp = ClampTimestamp(timestamp); 98 event_timestamp = ClampTimestamp(timestamp);
81 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp); 99 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp);
82 MoveTouchPoint(target, delta, event_timestamp); 100 MoveTouchPoint(target, delta, event_timestamp);
83 101
84 if (FinishedCurrentScrollSegment(event_timestamp)) { 102 if (FinishedCurrentMoveSegment(event_timestamp)) {
85 if (!IsLastScrollSegment()) { 103 if (!IsLastMoveSegment()) {
86 current_scroll_segment_start_position_ += 104 current_move_segment_start_position_ +=
87 params_.distances[current_scroll_segment_]; 105 params_.distances[current_move_segment_];
88 ComputeNextScrollSegment(); 106 ComputeNextMoveSegment();
89 } else if (params_.prevent_fling) { 107 } else if (params_.prevent_fling) {
90 state_ = STOPPING; 108 state_ = STOPPING;
91 } else { 109 } else {
92 ReleaseTouchPoint(target, event_timestamp); 110 ReleaseTouchPoint(target, event_timestamp);
93 state_ = DONE; 111 state_ = DONE;
94 } 112 }
95 } 113 }
96 } break; 114 } break;
97 case STOPPING: 115 case STOPPING:
98 if (timestamp - current_scroll_segment_stop_time_ >= 116 if (timestamp - current_move_segment_stop_time_ >=
99 target->PointerAssumedStoppedTime()) { 117 target->PointerAssumedStoppedTime()) {
100 event_timestamp = current_scroll_segment_stop_time_ + 118 event_timestamp = current_move_segment_stop_time_ +
101 target->PointerAssumedStoppedTime(); 119 target->PointerAssumedStoppedTime();
102 ReleaseTouchPoint(target, event_timestamp); 120 ReleaseTouchPoint(target, event_timestamp);
103 state_ = DONE; 121 state_ = DONE;
104 } 122 }
105 break; 123 break;
106 case SETUP: 124 case SETUP:
107 NOTREACHED() 125 NOTREACHED()
108 << "State STARTED invalid for synthetic scroll using touch input."; 126 << "State SETUP invalid for synthetic scroll using touch input.";
109 case DONE: 127 case DONE:
110 NOTREACHED() 128 NOTREACHED()
111 << "State DONE invalid for synthetic scroll using touch input."; 129 << "State DONE invalid for synthetic scroll using touch input.";
112 } 130 }
113 } 131 }
114 132
115 void SyntheticSmoothScrollGesture::ForwardMouseInputEvents( 133 void SyntheticSmoothMoveGesture::ForwardMouseWheelInputEvents(
116 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { 134 const base::TimeTicks& timestamp,
135 SyntheticGestureTarget* target) {
117 switch (state_) { 136 switch (state_) {
118 case STARTED: 137 case STARTED:
119 if (ScrollIsNoOp()) { 138 if (MoveIsNoOp()) {
120 state_ = DONE; 139 state_ = DONE;
121 break; 140 break;
122 } 141 }
123 ComputeNextScrollSegment(); 142 ComputeNextMoveSegment();
124 state_ = MOVING; 143 state_ = MOVING;
125 // Fall through to forward the first event. 144 // Fall through to forward the first event.
126 case MOVING: { 145 case MOVING: {
127 // Even though WebMouseWheelEvents take floating point deltas, 146 // Even though WebMouseWheelEvents take floating point deltas,
128 // internally the scroll position is stored as an integer. We therefore 147 // internally the scroll position is stored as an integer. We therefore
129 // keep track of the discrete delta which is consistent with the 148 // keep track of the discrete delta which is consistent with the
130 // internal scrolling state. This ensures that when the gesture has 149 // internal scrolling state. This ensures that when the gesture has
131 // finished we've scrolled exactly the specified distance. 150 // finished we've scrolled exactly the specified distance.
132 base::TimeTicks event_timestamp = ClampTimestamp(timestamp); 151 base::TimeTicks event_timestamp = ClampTimestamp(timestamp);
133 gfx::Vector2dF current_scroll_segment_total_delta = 152 gfx::Vector2dF current_move_segment_total_delta =
134 GetPositionDeltaAtTime(event_timestamp); 153 GetPositionDeltaAtTime(event_timestamp);
135 gfx::Vector2d delta_discrete = 154 gfx::Vector2d delta_discrete =
136 FloorTowardZero(current_scroll_segment_total_delta - 155 FloorTowardZero(current_move_segment_total_delta -
137 current_scroll_segment_total_delta_discrete_); 156 current_move_segment_total_delta_discrete_);
138 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp); 157 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp);
139 current_scroll_segment_total_delta_discrete_ += delta_discrete; 158 current_move_segment_total_delta_discrete_ += delta_discrete;
140 159
141 if (FinishedCurrentScrollSegment(event_timestamp)) { 160 if (FinishedCurrentMoveSegment(event_timestamp)) {
142 if (!IsLastScrollSegment()) { 161 if (!IsLastMoveSegment()) {
143 current_scroll_segment_total_delta_discrete_ = gfx::Vector2d(); 162 current_move_segment_total_delta_discrete_ = gfx::Vector2d();
144 ComputeNextScrollSegment(); 163 ComputeNextMoveSegment();
145 ForwardMouseInputEvents(timestamp, target); 164 ForwardMouseWheelInputEvents(timestamp, target);
146 } else { 165 } else {
147 state_ = DONE; 166 state_ = DONE;
148 } 167 }
149 } 168 }
150 } break; 169 } break;
151 case SETUP: 170 case SETUP:
152 NOTREACHED() 171 NOTREACHED() << "State SETUP invalid for synthetic scroll using mouse "
153 << "State STARTED invalid for synthetic scroll using touch input."; 172 "wheel input.";
154 case STOPPING: 173 case STOPPING:
155 NOTREACHED() 174 NOTREACHED() << "State STOPPING invalid for synthetic scroll using mouse "
156 << "State STOPPING invalid for synthetic scroll using touch input."; 175 "wheel input.";
157 case DONE: 176 case DONE:
158 NOTREACHED() 177 NOTREACHED()
159 << "State DONE invalid for synthetic scroll using touch input."; 178 << "State DONE invalid for synthetic scroll using mouse wheel input.";
160 } 179 }
161 } 180 }
162 181
163 void SyntheticSmoothScrollGesture::ForwardTouchEvent( 182 void SyntheticSmoothMoveGesture::ForwardMouseClickInputEvents(
164 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { 183 const base::TimeTicks& timestamp,
184 SyntheticGestureTarget* target) {
185 base::TimeTicks event_timestamp = timestamp;
186 switch (state_) {
187 case STARTED:
188 if (MoveIsNoOp()) {
189 state_ = DONE;
190 break;
191 }
192 ComputeNextMoveSegment();
193 PressMousePoint(target, event_timestamp);
194 state_ = MOVING;
195 // Fall through to forward the first event.
jdduke (slow) 2015/02/25 15:58:25 Why fall through? We don't do that for touch event
ssid 2015/02/25 16:25:42 It was added because we do it in mouse wheel scrol
196 case MOVING: {
197 base::TimeTicks event_timestamp = ClampTimestamp(timestamp);
198 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp);
199 MoveMousePoint(target, delta, event_timestamp);
200
201 if (FinishedCurrentMoveSegment(event_timestamp)) {
202 if (!IsLastMoveSegment()) {
203 current_move_segment_start_position_ +=
204 params_.distances[current_move_segment_];
205 ComputeNextMoveSegment();
206 } else {
207 ReleaseMousePoint(target, event_timestamp);
208 state_ = DONE;
209 }
210 }
211 } break;
212 case STOPPING:
213 NOTREACHED()
214 << "State STOPPING invalid for synthetic drag using mouse input.";
215 case SETUP:
216 NOTREACHED()
217 << "State SETUP invalid for synthetic drag using mouse input.";
218 case DONE:
219 NOTREACHED()
220 << "State DONE invalid for synthetic drag using mouse input.";
221 }
222 }
223
224 void SyntheticSmoothMoveGesture::ForwardTouchEvent(
225 SyntheticGestureTarget* target,
226 const base::TimeTicks& timestamp) {
165 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); 227 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp);
166 228
167 target->DispatchInputEventToPlatform(touch_event_); 229 target->DispatchInputEventToPlatform(touch_event_);
168 } 230 }
169 231
170 void SyntheticSmoothScrollGesture::ForwardMouseWheelEvent( 232 void SyntheticSmoothMoveGesture::ForwardMouseWheelEvent(
171 SyntheticGestureTarget* target, 233 SyntheticGestureTarget* target,
172 const gfx::Vector2dF& delta, 234 const gfx::Vector2dF& delta,
173 const base::TimeTicks& timestamp) const { 235 const base::TimeTicks& timestamp) const {
174 blink::WebMouseWheelEvent mouse_wheel_event = 236 blink::WebMouseWheelEvent mouse_wheel_event =
175 SyntheticWebMouseWheelEventBuilder::Build(delta.x(), delta.y(), 0, false); 237 SyntheticWebMouseWheelEventBuilder::Build(delta.x(), delta.y(), 0, false);
176 238
177 mouse_wheel_event.x = params_.anchor.x(); 239 mouse_wheel_event.x = current_move_segment_start_position_.x();
178 mouse_wheel_event.y = params_.anchor.y(); 240 mouse_wheel_event.y = current_move_segment_start_position_.y();
179 241
180 mouse_wheel_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); 242 mouse_wheel_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp);
181 243
182 target->DispatchInputEventToPlatform(mouse_wheel_event); 244 target->DispatchInputEventToPlatform(mouse_wheel_event);
183 } 245 }
184 246
185 void SyntheticSmoothScrollGesture::PressTouchPoint( 247 void SyntheticSmoothMoveGesture::PressTouchPoint(
186 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { 248 SyntheticGestureTarget* target,
187 DCHECK_EQ(current_scroll_segment_, 0); 249 const base::TimeTicks& timestamp) {
188 touch_event_.PressPoint(params_.anchor.x(), params_.anchor.y()); 250 DCHECK_EQ(current_move_segment_, 0);
251 touch_event_.PressPoint(current_move_segment_start_position_.x(),
252 current_move_segment_start_position_.y());
189 ForwardTouchEvent(target, timestamp); 253 ForwardTouchEvent(target, timestamp);
190 } 254 }
191 255
192 void SyntheticSmoothScrollGesture::MoveTouchPoint( 256 void SyntheticSmoothMoveGesture::MoveTouchPoint(
193 SyntheticGestureTarget* target, 257 SyntheticGestureTarget* target,
194 const gfx::Vector2dF& delta, 258 const gfx::Vector2dF& delta,
195 const base::TimeTicks& timestamp) { 259 const base::TimeTicks& timestamp) {
196 DCHECK_GE(current_scroll_segment_, 0); 260 DCHECK_GE(current_move_segment_, 0);
197 DCHECK_LT(current_scroll_segment_, 261 DCHECK_LT(current_move_segment_, static_cast<int>(params_.distances.size()));
198 static_cast<int>(params_.distances.size())); 262 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()); 263 touch_event_.MovePoint(0, touch_position.x(), touch_position.y());
201 ForwardTouchEvent(target, timestamp); 264 ForwardTouchEvent(target, timestamp);
202 } 265 }
203 266
204 void SyntheticSmoothScrollGesture::ReleaseTouchPoint( 267 void SyntheticSmoothMoveGesture::ReleaseTouchPoint(
205 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { 268 SyntheticGestureTarget* target,
206 DCHECK_EQ(current_scroll_segment_, 269 const base::TimeTicks& timestamp) {
270 DCHECK_EQ(current_move_segment_,
207 static_cast<int>(params_.distances.size()) - 1); 271 static_cast<int>(params_.distances.size()) - 1);
208 touch_event_.ReleasePoint(0); 272 touch_event_.ReleasePoint(0);
209 ForwardTouchEvent(target, timestamp); 273 ForwardTouchEvent(target, timestamp);
210 } 274 }
211 275
212 void SyntheticSmoothScrollGesture::AddTouchSlopToFirstDistance( 276 void SyntheticSmoothMoveGesture::PressMousePoint(
277 SyntheticGestureTarget* target,
278 const base::TimeTicks& timestamp) {
279 DCHECK(params_.input_type ==
jdduke (slow) 2015/02/25 15:58:25 Nit: DCHECK_EQ
ssid 2015/02/25 16:25:42 Done.
280 SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT);
281 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build(
282 blink::WebInputEvent::MouseDown, current_move_segment_start_position_.x(),
283 current_move_segment_start_position_.y(), 0);
284 mouse_event.clickCount = 1;
285 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp);
286 target->DispatchInputEventToPlatform(mouse_event);
287 }
288
289 void SyntheticSmoothMoveGesture::ReleaseMousePoint(
290 SyntheticGestureTarget* target,
291 const base::TimeTicks& timestamp) {
292 DCHECK(params_.input_type ==
jdduke (slow) 2015/02/25 15:58:25 DCHECK_EQ
ssid 2015/02/25 16:25:42 Done.
293 SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT);
294 gfx::PointF mouse_position =
295 current_move_segment_start_position_ + GetPositionDeltaAtTime(timestamp);
296 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build(
297 blink::WebInputEvent::MouseUp, mouse_position.x(), mouse_position.y(), 0);
298 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp);
299 target->DispatchInputEventToPlatform(mouse_event);
300 }
301
302 void SyntheticSmoothMoveGesture::MoveMousePoint(
303 SyntheticGestureTarget* target,
304 const gfx::Vector2dF& delta,
305 const base::TimeTicks& timestamp) {
306 gfx::PointF mouse_position = current_move_segment_start_position_ + delta;
307 DCHECK(params_.input_type ==
jdduke (slow) 2015/02/25 15:58:25 DCHECK_EQ
ssid 2015/02/25 16:25:42 Done.
308 SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT);
309 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build(
310 blink::WebInputEvent::MouseMove, mouse_position.x(), mouse_position.y(),
311 0);
312 mouse_event.button = blink::WebMouseEvent::ButtonLeft;
jdduke (slow) 2015/02/25 15:58:25 Would we ever want to simulate mouse movement with
ssid 2015/02/25 16:25:42 The current consumer for the drag gestures will be
313 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp);
314 target->DispatchInputEventToPlatform(mouse_event);
315 }
316
317 void SyntheticSmoothMoveGesture::AddTouchSlopToFirstDistance(
213 SyntheticGestureTarget* target) { 318 SyntheticGestureTarget* target) {
214 DCHECK_GE(params_.distances.size(), 1ul); 319 DCHECK_GE(params_.distances.size(), 1ul);
215 gfx::Vector2d& first_scroll_distance = params_.distances[0]; 320 gfx::Vector2dF& first_move_distance = params_.distances[0];
216 DCHECK_GT(first_scroll_distance.Length(), 0); 321 DCHECK_GT(first_move_distance.Length(), 0);
217 first_scroll_distance += CeilFromZero(ProjectScalarOntoVector( 322 first_move_distance += CeilFromZero(ProjectScalarOntoVector(
218 target->GetTouchSlopInDips(), first_scroll_distance)); 323 target->GetTouchSlopInDips(), first_move_distance));
219 } 324 }
220 325
221 gfx::Vector2dF SyntheticSmoothScrollGesture::GetPositionDeltaAtTime( 326 gfx::Vector2dF SyntheticSmoothMoveGesture::GetPositionDeltaAtTime(
222 const base::TimeTicks& timestamp) const { 327 const base::TimeTicks& timestamp) const {
223 // Make sure the final delta is correct. Using the computation below can lead 328 // Make sure the final delta is correct. Using the computation below can lead
224 // to issues with floating point precision. 329 // to issues with floating point precision.
225 if (FinishedCurrentScrollSegment(timestamp)) 330 if (FinishedCurrentMoveSegment(timestamp))
226 return params_.distances[current_scroll_segment_]; 331 return params_.distances[current_move_segment_];
227 332
228 float delta_length = 333 float delta_length =
229 params_.speed_in_pixels_s * 334 params_.speed_in_pixels_s *
230 (timestamp - current_scroll_segment_start_time_).InSecondsF(); 335 (timestamp - current_move_segment_start_time_).InSecondsF();
231 return ProjectScalarOntoVector(delta_length, 336 return ProjectScalarOntoVector(delta_length,
232 params_.distances[current_scroll_segment_]); 337 params_.distances[current_move_segment_]);
233 } 338 }
234 339
235 void SyntheticSmoothScrollGesture::ComputeNextScrollSegment() { 340 void SyntheticSmoothMoveGesture::ComputeNextMoveSegment() {
236 current_scroll_segment_++; 341 current_move_segment_++;
237 DCHECK_LT(current_scroll_segment_, 342 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>( 343 int64 total_duration_in_us = static_cast<int64>(
240 1e6 * (params_.distances[current_scroll_segment_].Length() / 344 1e6 * (params_.distances[current_move_segment_].Length() /
241 params_.speed_in_pixels_s)); 345 params_.speed_in_pixels_s));
242 DCHECK_GT(total_duration_in_us, 0); 346 DCHECK_GT(total_duration_in_us, 0);
243 current_scroll_segment_start_time_ = current_scroll_segment_stop_time_; 347 current_move_segment_start_time_ = current_move_segment_stop_time_;
244 current_scroll_segment_stop_time_ = 348 current_move_segment_stop_time_ =
245 current_scroll_segment_start_time_ + 349 current_move_segment_start_time_ +
246 base::TimeDelta::FromMicroseconds(total_duration_in_us); 350 base::TimeDelta::FromMicroseconds(total_duration_in_us);
247 } 351 }
248 352
249 base::TimeTicks SyntheticSmoothScrollGesture::ClampTimestamp( 353 base::TimeTicks SyntheticSmoothMoveGesture::ClampTimestamp(
250 const base::TimeTicks& timestamp) const { 354 const base::TimeTicks& timestamp) const {
251 return std::min(timestamp, current_scroll_segment_stop_time_); 355 return std::min(timestamp, current_move_segment_stop_time_);
252 } 356 }
253 357
254 bool SyntheticSmoothScrollGesture::FinishedCurrentScrollSegment( 358 bool SyntheticSmoothMoveGesture::FinishedCurrentMoveSegment(
255 const base::TimeTicks& timestamp) const { 359 const base::TimeTicks& timestamp) const {
256 return timestamp >= current_scroll_segment_stop_time_; 360 return timestamp >= current_move_segment_stop_time_;
257 } 361 }
258 362
259 bool SyntheticSmoothScrollGesture::IsLastScrollSegment() const { 363 bool SyntheticSmoothMoveGesture::IsLastMoveSegment() const {
260 DCHECK_LT(current_scroll_segment_, 364 DCHECK_LT(current_move_segment_, static_cast<int>(params_.distances.size()));
261 static_cast<int>(params_.distances.size())); 365 return current_move_segment_ ==
262 return current_scroll_segment_ ==
263 static_cast<int>(params_.distances.size()) - 1; 366 static_cast<int>(params_.distances.size()) - 1;
264 } 367 }
265 368
266 bool SyntheticSmoothScrollGesture::ScrollIsNoOp() const { 369 bool SyntheticSmoothMoveGesture::MoveIsNoOp() const {
267 return params_.distances.size() == 0 || params_.distances[0].IsZero(); 370 return params_.distances.size() == 0 || params_.distances[0].IsZero();
268 } 371 }
269 372
270 } // namespace content 373 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698