Chromium Code Reviews| 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 "content/browser/renderer_host/gesture_event_filter.h" | 7 #include "content/browser/renderer_host/gesture_event_filter.h" |
| 8 #include "content/browser/renderer_host/overscroll_controller_delegate.h" | 8 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 10 #include "content/public/browser/overscroll_configuration.h" | 10 #include "content/public/browser/overscroll_configuration.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 } | 272 } |
| 273 | 273 |
| 274 default: | 274 default: |
| 275 DCHECK(WebKit::WebInputEvent::isGestureEventType(event.type) || | 275 DCHECK(WebKit::WebInputEvent::isGestureEventType(event.type) || |
| 276 WebKit::WebInputEvent::isTouchEventType(event.type)) | 276 WebKit::WebInputEvent::isTouchEventType(event.type)) |
| 277 << "Received unexpected event: " << event.type; | 277 << "Received unexpected event: " << event.type; |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 void OverscrollController::ProcessOverscroll(float delta_x, float delta_y) { | 281 void OverscrollController::ProcessOverscroll(float delta_x, float delta_y) { |
| 282 if (scroll_state_ == STATE_CONTENT_SCROLLING) | 282 if (scroll_state_ != STATE_CONTENT_SCROLLING) |
| 283 return; | 283 overscroll_delta_x_ += delta_x; |
| 284 overscroll_delta_x_ += delta_x; | |
| 285 overscroll_delta_y_ += delta_y; | 284 overscroll_delta_y_ += delta_y; |
| 286 | 285 |
| 287 float threshold = GetOverscrollConfig(OVERSCROLL_CONFIG_MIN_THRESHOLD_START); | 286 float horiz_threshold = GetOverscrollConfig( |
| 288 if (fabs(overscroll_delta_x_) < threshold && | 287 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START); |
| 289 fabs(overscroll_delta_y_) < threshold) { | 288 float vert_threshold = GetOverscrollConfig( |
| 289 OVERSCROLL_CONFIG_VERT_THRESHOLD_START); | |
| 290 if (fabs(overscroll_delta_x_) <= horiz_threshold && | |
| 291 fabs(overscroll_delta_y_) <= vert_threshold) { | |
| 290 SetOverscrollMode(OVERSCROLL_NONE); | 292 SetOverscrollMode(OVERSCROLL_NONE); |
| 291 return; | 293 return; |
| 292 } | 294 } |
| 293 | 295 |
| 294 // Compute the current overscroll direction. If the direction is different | 296 // Compute the current overscroll direction. If the direction is different |
| 295 // from the current direction, then always switch to no-overscroll mode first | 297 // from the current direction, then always switch to no-overscroll mode first |
| 296 // to make sure that subsequent scroll events go through to the page first. | 298 // to make sure that subsequent scroll events go through to the page first. |
| 297 OverscrollMode new_mode = OVERSCROLL_NONE; | 299 OverscrollMode new_mode = OVERSCROLL_NONE; |
| 298 const float kMinRatio = 2.5; | 300 const float kMinRatio = 2.5; |
| 299 if (fabs(overscroll_delta_x_) > fabs(overscroll_delta_y_) * kMinRatio) | 301 if (fabs(overscroll_delta_x_) > horiz_threshold && |
| 302 fabs(overscroll_delta_x_) > fabs(overscroll_delta_y_) * kMinRatio) | |
| 300 new_mode = overscroll_delta_x_ > 0.f ? OVERSCROLL_EAST : OVERSCROLL_WEST; | 303 new_mode = overscroll_delta_x_ > 0.f ? OVERSCROLL_EAST : OVERSCROLL_WEST; |
| 301 else if (fabs(overscroll_delta_y_) > fabs(overscroll_delta_x_) * kMinRatio) | 304 else if (fabs(overscroll_delta_y_) > vert_threshold && |
| 305 fabs(overscroll_delta_y_) > fabs(overscroll_delta_x_) * kMinRatio) | |
| 302 new_mode = overscroll_delta_y_ > 0.f ? OVERSCROLL_SOUTH : OVERSCROLL_NORTH; | 306 new_mode = overscroll_delta_y_ > 0.f ? OVERSCROLL_SOUTH : OVERSCROLL_NORTH; |
| 303 | 307 |
| 304 if (overscroll_mode_ == OVERSCROLL_NONE) { | 308 if (overscroll_mode_ == OVERSCROLL_NONE) { |
| 305 SetOverscrollMode(new_mode); | 309 SetOverscrollMode(new_mode); |
|
sadrul
2013/07/18 22:51:41
Hm. There's a bug here, even in the current code.
rharrison
2013/07/23 14:36:02
Done.
| |
| 306 } else if (new_mode != overscroll_mode_) { | 310 } else if (new_mode != overscroll_mode_) { |
| 307 SetOverscrollMode(OVERSCROLL_NONE); | 311 SetOverscrollMode(OVERSCROLL_NONE); |
| 308 return; | 312 return; |
| 309 } | 313 } |
| 310 | 314 |
| 311 // Tell the delegate about the overscroll update so that it can update | 315 // Tell the delegate about the overscroll update so that it can update |
| 312 // the display accordingly (e.g. show history preview etc.). | 316 // the display accordingly (e.g. show history preview etc.). |
| 313 if (delegate_) { | 317 if (delegate_) { |
| 314 // Do not include the threshold amount when sending the deltas to the | 318 // Do not include the threshold amount when sending the deltas to the |
| 315 // delegate. | 319 // delegate. |
| 316 float delegate_delta_x = overscroll_delta_x_; | 320 float delegate_delta_x = overscroll_delta_x_; |
| 317 if (fabs(delegate_delta_x) > threshold) { | 321 if (fabs(delegate_delta_x) > horiz_threshold) { |
| 318 if (delegate_delta_x < 0) | 322 if (delegate_delta_x < 0) |
| 319 delegate_delta_x += threshold; | 323 delegate_delta_x += horiz_threshold; |
| 320 else | 324 else |
| 321 delegate_delta_x -= threshold; | 325 delegate_delta_x -= horiz_threshold; |
| 322 } else { | 326 } else { |
| 323 delegate_delta_x = 0.f; | 327 delegate_delta_x = 0.f; |
| 324 } | 328 } |
| 325 | 329 |
| 326 float delegate_delta_y = overscroll_delta_y_; | 330 float delegate_delta_y = overscroll_delta_y_; |
| 327 if (fabs(delegate_delta_y) > threshold) { | 331 if (fabs(delegate_delta_y) > vert_threshold) { |
| 328 if (delegate_delta_y < 0) | 332 if (delegate_delta_y < 0) |
| 329 delegate_delta_y += threshold; | 333 delegate_delta_y += vert_threshold; |
| 330 else | 334 else |
| 331 delegate_delta_y -= threshold; | 335 delegate_delta_y -= vert_threshold; |
| 332 } else { | 336 } else { |
| 333 delegate_delta_y = 0.f; | 337 delegate_delta_y = 0.f; |
| 334 } | 338 } |
| 335 delegate_->OnOverscrollUpdate(delegate_delta_x, delegate_delta_y); | 339 delegate_->OnOverscrollUpdate(delegate_delta_x, delegate_delta_y); |
| 336 } | 340 } |
| 337 } | 341 } |
| 338 | 342 |
| 339 void OverscrollController::CompleteAction() { | 343 void OverscrollController::CompleteAction() { |
| 340 if (delegate_) | 344 if (delegate_) |
| 341 delegate_->OnOverscrollComplete(overscroll_mode_); | 345 delegate_->OnOverscrollComplete(overscroll_mode_); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 360 const WebKit::WebInputEvent& event) const { | 364 const WebKit::WebInputEvent& event) const { |
| 361 if (!WebKit::WebInputEvent::isGestureEventType(event.type)) | 365 if (!WebKit::WebInputEvent::isGestureEventType(event.type)) |
| 362 return false; | 366 return false; |
| 363 | 367 |
| 364 // If the GestureEventFilter already processed this event, then the event must | 368 // If the GestureEventFilter already processed this event, then the event must |
| 365 // not be sent to the filter again. | 369 // not be sent to the filter again. |
| 366 return !render_widget_host_->gesture_event_filter()->HasQueuedGestureEvents(); | 370 return !render_widget_host_->gesture_event_filter()->HasQueuedGestureEvents(); |
| 367 } | 371 } |
| 368 | 372 |
| 369 } // namespace content | 373 } // namespace content |
| OLD | NEW |