OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/overscroll_controller.h" | 5 #include "content/browser/renderer_host/overscroll_controller.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/browser/renderer_host/overscroll_controller_delegate.h" | 9 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
10 #include "content/public/browser/overscroll_configuration.h" | 10 #include "content/public/browser/overscroll_configuration.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 215 |
216 ProcessOverscroll(wheel.deltaX * wheel.accelerationRatioX, | 216 ProcessOverscroll(wheel.deltaX * wheel.accelerationRatioX, |
217 wheel.deltaY * wheel.accelerationRatioY, | 217 wheel.deltaY * wheel.accelerationRatioY, |
218 wheel.type); | 218 wheel.type); |
219 event_processed = true; | 219 event_processed = true; |
220 break; | 220 break; |
221 } | 221 } |
222 case blink::WebInputEvent::GestureScrollUpdate: { | 222 case blink::WebInputEvent::GestureScrollUpdate: { |
223 const blink::WebGestureEvent& gesture = | 223 const blink::WebGestureEvent& gesture = |
224 static_cast<const blink::WebGestureEvent&>(event); | 224 static_cast<const blink::WebGestureEvent&>(event); |
225 ProcessOverscroll(gesture.data.scrollUpdate.deltaX, | 225 event_processed = ProcessOverscroll(gesture.data.scrollUpdate.deltaX, |
226 gesture.data.scrollUpdate.deltaY, | 226 gesture.data.scrollUpdate.deltaY, |
227 gesture.type); | 227 gesture.type); |
228 event_processed = true; | |
229 break; | 228 break; |
230 } | 229 } |
231 case blink::WebInputEvent::GestureFlingStart: { | 230 case blink::WebInputEvent::GestureFlingStart: { |
232 const float kFlingVelocityThreshold = 1100.f; | 231 const float kFlingVelocityThreshold = 1100.f; |
233 const blink::WebGestureEvent& gesture = | 232 const blink::WebGestureEvent& gesture = |
234 static_cast<const blink::WebGestureEvent&>(event); | 233 static_cast<const blink::WebGestureEvent&>(event); |
235 float velocity_x = gesture.data.flingStart.velocityX; | 234 float velocity_x = gesture.data.flingStart.velocityX; |
236 float velocity_y = gesture.data.flingStart.velocityY; | 235 float velocity_y = gesture.data.flingStart.velocityY; |
237 if (fabs(velocity_x) > kFlingVelocityThreshold) { | 236 if (fabs(velocity_x) > kFlingVelocityThreshold) { |
238 if ((overscroll_mode_ == OVERSCROLL_WEST && velocity_x < 0) || | 237 if ((overscroll_mode_ == OVERSCROLL_WEST && velocity_x < 0) || |
(...skipping 17 matching lines...) Expand all Loading... |
256 } | 255 } |
257 | 256 |
258 default: | 257 default: |
259 DCHECK(blink::WebInputEvent::isGestureEventType(event.type) || | 258 DCHECK(blink::WebInputEvent::isGestureEventType(event.type) || |
260 blink::WebInputEvent::isTouchEventType(event.type)) | 259 blink::WebInputEvent::isTouchEventType(event.type)) |
261 << "Received unexpected event: " << event.type; | 260 << "Received unexpected event: " << event.type; |
262 } | 261 } |
263 return event_processed; | 262 return event_processed; |
264 } | 263 } |
265 | 264 |
266 void OverscrollController::ProcessOverscroll(float delta_x, | 265 bool OverscrollController::ProcessOverscroll(float delta_x, |
267 float delta_y, | 266 float delta_y, |
268 blink::WebInputEvent::Type type) { | 267 blink::WebInputEvent::Type type) { |
269 if (scroll_state_ != STATE_CONTENT_SCROLLING) | 268 if (scroll_state_ != STATE_CONTENT_SCROLLING) |
270 overscroll_delta_x_ += delta_x; | 269 overscroll_delta_x_ += delta_x; |
271 overscroll_delta_y_ += delta_y; | 270 overscroll_delta_y_ += delta_y; |
272 | 271 |
273 float horiz_threshold = GetOverscrollConfig( | 272 float horiz_threshold = GetOverscrollConfig( |
274 WebInputEvent::isGestureEventType(type) ? | 273 WebInputEvent::isGestureEventType(type) ? |
275 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN : | 274 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN : |
276 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD); | 275 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD); |
277 float vert_threshold = GetOverscrollConfig( | 276 float vert_threshold = GetOverscrollConfig( |
278 OVERSCROLL_CONFIG_VERT_THRESHOLD_START); | 277 OVERSCROLL_CONFIG_VERT_THRESHOLD_START); |
279 if (fabs(overscroll_delta_x_) <= horiz_threshold && | 278 if (fabs(overscroll_delta_x_) <= horiz_threshold && |
280 fabs(overscroll_delta_y_) <= vert_threshold) { | 279 fabs(overscroll_delta_y_) <= vert_threshold) { |
281 SetOverscrollMode(OVERSCROLL_NONE); | 280 SetOverscrollMode(OVERSCROLL_NONE); |
282 return; | 281 return false; |
283 } | 282 } |
284 | 283 |
285 // Compute the current overscroll direction. If the direction is different | 284 // Compute the current overscroll direction. If the direction is different |
286 // from the current direction, then always switch to no-overscroll mode first | 285 // from the current direction, then always switch to no-overscroll mode first |
287 // to make sure that subsequent scroll events go through to the page first. | 286 // to make sure that subsequent scroll events go through to the page first. |
288 OverscrollMode new_mode = OVERSCROLL_NONE; | 287 OverscrollMode new_mode = OVERSCROLL_NONE; |
289 const float kMinRatio = 2.5; | 288 const float kMinRatio = 2.5; |
290 if (fabs(overscroll_delta_x_) > horiz_threshold && | 289 if (fabs(overscroll_delta_x_) > horiz_threshold && |
291 fabs(overscroll_delta_x_) > fabs(overscroll_delta_y_) * kMinRatio) | 290 fabs(overscroll_delta_x_) > fabs(overscroll_delta_y_) * kMinRatio) |
292 new_mode = overscroll_delta_x_ > 0.f ? OVERSCROLL_EAST : OVERSCROLL_WEST; | 291 new_mode = overscroll_delta_x_ > 0.f ? OVERSCROLL_EAST : OVERSCROLL_WEST; |
293 else if (fabs(overscroll_delta_y_) > vert_threshold && | 292 else if (fabs(overscroll_delta_y_) > vert_threshold && |
294 fabs(overscroll_delta_y_) > fabs(overscroll_delta_x_) * kMinRatio) | 293 fabs(overscroll_delta_y_) > fabs(overscroll_delta_x_) * kMinRatio) |
295 new_mode = overscroll_delta_y_ > 0.f ? OVERSCROLL_SOUTH : OVERSCROLL_NORTH; | 294 new_mode = overscroll_delta_y_ > 0.f ? OVERSCROLL_SOUTH : OVERSCROLL_NORTH; |
296 | 295 |
297 // The vertical oversrcoll currently does not have any UX effects other then | 296 // The vertical oversrcoll currently does not have any UX effects other then |
298 // for the scroll end effect, so testing if it is enabled. | 297 // for the scroll end effect, so testing if it is enabled. |
299 if ((new_mode == OVERSCROLL_SOUTH || new_mode == OVERSCROLL_NORTH) && | 298 if ((new_mode == OVERSCROLL_SOUTH || new_mode == OVERSCROLL_NORTH) && |
300 !IsScrollEndEffectEnabled()) | 299 !IsScrollEndEffectEnabled()) |
301 new_mode = OVERSCROLL_NONE; | 300 new_mode = OVERSCROLL_NONE; |
302 | 301 |
303 if (overscroll_mode_ == OVERSCROLL_NONE) | 302 if (overscroll_mode_ == OVERSCROLL_NONE) |
304 SetOverscrollMode(new_mode); | 303 SetOverscrollMode(new_mode); |
305 else if (new_mode != overscroll_mode_) | 304 else if (new_mode != overscroll_mode_) |
306 SetOverscrollMode(OVERSCROLL_NONE); | 305 SetOverscrollMode(OVERSCROLL_NONE); |
307 | 306 |
308 if (overscroll_mode_ == OVERSCROLL_NONE) | 307 if (overscroll_mode_ == OVERSCROLL_NONE) |
309 return; | 308 return false; |
310 | 309 |
311 // Tell the delegate about the overscroll update so that it can update | 310 // Tell the delegate about the overscroll update so that it can update |
312 // the display accordingly (e.g. show history preview etc.). | 311 // the display accordingly (e.g. show history preview etc.). |
313 if (delegate_) { | 312 if (delegate_) { |
314 // Do not include the threshold amount when sending the deltas to the | 313 // Do not include the threshold amount when sending the deltas to the |
315 // delegate. | 314 // delegate. |
316 float delegate_delta_x = overscroll_delta_x_; | 315 float delegate_delta_x = overscroll_delta_x_; |
317 if (fabs(delegate_delta_x) > horiz_threshold) { | 316 if (fabs(delegate_delta_x) > horiz_threshold) { |
318 if (delegate_delta_x < 0) | 317 if (delegate_delta_x < 0) |
319 delegate_delta_x += horiz_threshold; | 318 delegate_delta_x += horiz_threshold; |
320 else | 319 else |
321 delegate_delta_x -= horiz_threshold; | 320 delegate_delta_x -= horiz_threshold; |
322 } else { | 321 } else { |
323 delegate_delta_x = 0.f; | 322 delegate_delta_x = 0.f; |
324 } | 323 } |
325 | 324 |
326 float delegate_delta_y = overscroll_delta_y_; | 325 float delegate_delta_y = overscroll_delta_y_; |
327 if (fabs(delegate_delta_y) > vert_threshold) { | 326 if (fabs(delegate_delta_y) > vert_threshold) { |
328 if (delegate_delta_y < 0) | 327 if (delegate_delta_y < 0) |
329 delegate_delta_y += vert_threshold; | 328 delegate_delta_y += vert_threshold; |
330 else | 329 else |
331 delegate_delta_y -= vert_threshold; | 330 delegate_delta_y -= vert_threshold; |
332 } else { | 331 } else { |
333 delegate_delta_y = 0.f; | 332 delegate_delta_y = 0.f; |
334 } | 333 } |
335 delegate_->OnOverscrollUpdate(delegate_delta_x, delegate_delta_y); | 334 return delegate_->OnOverscrollUpdate(delegate_delta_x, delegate_delta_y); |
336 } | 335 } |
| 336 return false; |
337 } | 337 } |
338 | 338 |
339 void OverscrollController::CompleteAction() { | 339 void OverscrollController::CompleteAction() { |
340 if (delegate_) | 340 if (delegate_) |
341 delegate_->OnOverscrollComplete(overscroll_mode_); | 341 delegate_->OnOverscrollComplete(overscroll_mode_); |
342 overscroll_mode_ = OVERSCROLL_NONE; | 342 overscroll_mode_ = OVERSCROLL_NONE; |
343 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; | 343 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; |
344 } | 344 } |
345 | 345 |
346 void OverscrollController::SetOverscrollMode(OverscrollMode mode) { | 346 void OverscrollController::SetOverscrollMode(OverscrollMode mode) { |
347 if (overscroll_mode_ == mode) | 347 if (overscroll_mode_ == mode) |
348 return; | 348 return; |
349 OverscrollMode old_mode = overscroll_mode_; | 349 OverscrollMode old_mode = overscroll_mode_; |
350 overscroll_mode_ = mode; | 350 overscroll_mode_ = mode; |
351 if (overscroll_mode_ == OVERSCROLL_NONE) | 351 if (overscroll_mode_ == OVERSCROLL_NONE) |
352 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; | 352 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; |
353 else | 353 else |
354 scroll_state_ = STATE_OVERSCROLLING; | 354 scroll_state_ = STATE_OVERSCROLLING; |
355 if (delegate_) | 355 if (delegate_) |
356 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); | 356 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); |
357 } | 357 } |
358 | 358 |
359 } // namespace content | 359 } // namespace content |
OLD | NEW |