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

Side by Side Diff: content/browser/renderer_host/overscroll_controller.cc

Issue 18603008: Seperate horizontal and vertical overscrolling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed broken unit test Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
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/overscroll_controller_delegate.h" 7 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
8 #include "content/browser/renderer_host/render_widget_host_impl.h" 8 #include "content/browser/renderer_host/render_widget_host_impl.h"
9 #include "content/public/browser/overscroll_configuration.h" 9 #include "content/public/browser/overscroll_configuration.h"
10 #include "content/public/browser/render_widget_host_view.h" 10 #include "content/public/browser/render_widget_host_view.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 270 }
271 271
272 default: 272 default:
273 DCHECK(WebKit::WebInputEvent::isGestureEventType(event.type) || 273 DCHECK(WebKit::WebInputEvent::isGestureEventType(event.type) ||
274 WebKit::WebInputEvent::isTouchEventType(event.type)) 274 WebKit::WebInputEvent::isTouchEventType(event.type))
275 << "Received unexpected event: " << event.type; 275 << "Received unexpected event: " << event.type;
276 } 276 }
277 } 277 }
278 278
279 void OverscrollController::ProcessOverscroll(float delta_x, float delta_y) { 279 void OverscrollController::ProcessOverscroll(float delta_x, float delta_y) {
280 if (scroll_state_ == STATE_CONTENT_SCROLLING) 280 if (scroll_state_ != STATE_CONTENT_SCROLLING)
281 return; 281 overscroll_delta_x_ += delta_x;
282 overscroll_delta_x_ += delta_x;
283 overscroll_delta_y_ += delta_y; 282 overscroll_delta_y_ += delta_y;
284 283
285 float threshold = GetOverscrollConfig(OVERSCROLL_CONFIG_MIN_THRESHOLD_START); 284 float horiz_threshold = GetOverscrollConfig(
286 if (fabs(overscroll_delta_x_) < threshold && 285 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START);
287 fabs(overscroll_delta_y_) < threshold) { 286 float vert_threshold = GetOverscrollConfig(
287 OVERSCROLL_CONFIG_VERT_THRESHOLD_START);
288 if (fabs(overscroll_delta_x_) <= horiz_threshold &&
289 fabs(overscroll_delta_y_) <= vert_threshold) {
288 SetOverscrollMode(OVERSCROLL_NONE); 290 SetOverscrollMode(OVERSCROLL_NONE);
289 return; 291 return;
290 } 292 }
291 293
292 // Compute the current overscroll direction. If the direction is different 294 // Compute the current overscroll direction. If the direction is different
293 // from the current direction, then always switch to no-overscroll mode first 295 // from the current direction, then always switch to no-overscroll mode first
294 // to make sure that subsequent scroll events go through to the page first. 296 // to make sure that subsequent scroll events go through to the page first.
295 OverscrollMode new_mode = OVERSCROLL_NONE; 297 OverscrollMode new_mode = OVERSCROLL_NONE;
296 const float kMinRatio = 2.5; 298 const float kMinRatio = 2.5;
297 if (fabs(overscroll_delta_x_) > fabs(overscroll_delta_y_) * kMinRatio) 299 if (fabs(overscroll_delta_x_) > horiz_threshold &&
300 fabs(overscroll_delta_x_) > fabs(overscroll_delta_y_) * kMinRatio)
298 new_mode = overscroll_delta_x_ > 0.f ? OVERSCROLL_EAST : OVERSCROLL_WEST; 301 new_mode = overscroll_delta_x_ > 0.f ? OVERSCROLL_EAST : OVERSCROLL_WEST;
299 else if (fabs(overscroll_delta_y_) > fabs(overscroll_delta_x_) * kMinRatio) 302 else if (fabs(overscroll_delta_y_) > vert_threshold &&
303 fabs(overscroll_delta_y_) > fabs(overscroll_delta_x_) * kMinRatio)
300 new_mode = overscroll_delta_y_ > 0.f ? OVERSCROLL_SOUTH : OVERSCROLL_NORTH; 304 new_mode = overscroll_delta_y_ > 0.f ? OVERSCROLL_SOUTH : OVERSCROLL_NORTH;
301 305
302 if (overscroll_mode_ == OVERSCROLL_NONE) { 306 if (overscroll_mode_ == OVERSCROLL_NONE)
303 SetOverscrollMode(new_mode); 307 SetOverscrollMode(new_mode);
304 } else if (new_mode != overscroll_mode_) { 308 else if (new_mode != overscroll_mode_)
305 SetOverscrollMode(OVERSCROLL_NONE); 309 SetOverscrollMode(OVERSCROLL_NONE);
310
311 if (overscroll_mode_ == OVERSCROLL_NONE)
306 return; 312 return;
307 }
308 313
309 // Tell the delegate about the overscroll update so that it can update 314 // Tell the delegate about the overscroll update so that it can update
310 // the display accordingly (e.g. show history preview etc.). 315 // the display accordingly (e.g. show history preview etc.).
311 if (delegate_) { 316 if (delegate_) {
312 // Do not include the threshold amount when sending the deltas to the 317 // Do not include the threshold amount when sending the deltas to the
313 // delegate. 318 // delegate.
314 float delegate_delta_x = overscroll_delta_x_; 319 float delegate_delta_x = overscroll_delta_x_;
315 if (fabs(delegate_delta_x) > threshold) { 320 if (fabs(delegate_delta_x) > horiz_threshold) {
316 if (delegate_delta_x < 0) 321 if (delegate_delta_x < 0)
317 delegate_delta_x += threshold; 322 delegate_delta_x += horiz_threshold;
318 else 323 else
319 delegate_delta_x -= threshold; 324 delegate_delta_x -= horiz_threshold;
320 } else { 325 } else {
321 delegate_delta_x = 0.f; 326 delegate_delta_x = 0.f;
322 } 327 }
323 328
324 float delegate_delta_y = overscroll_delta_y_; 329 float delegate_delta_y = overscroll_delta_y_;
325 if (fabs(delegate_delta_y) > threshold) { 330 if (fabs(delegate_delta_y) > vert_threshold) {
326 if (delegate_delta_y < 0) 331 if (delegate_delta_y < 0)
327 delegate_delta_y += threshold; 332 delegate_delta_y += vert_threshold;
328 else 333 else
329 delegate_delta_y -= threshold; 334 delegate_delta_y -= vert_threshold;
330 } else { 335 } else {
331 delegate_delta_y = 0.f; 336 delegate_delta_y = 0.f;
332 } 337 }
333 delegate_->OnOverscrollUpdate(delegate_delta_x, delegate_delta_y); 338 delegate_->OnOverscrollUpdate(delegate_delta_x, delegate_delta_y);
334 } 339 }
335 } 340 }
336 341
337 void OverscrollController::CompleteAction() { 342 void OverscrollController::CompleteAction() {
338 if (delegate_) 343 if (delegate_)
339 delegate_->OnOverscrollComplete(overscroll_mode_); 344 delegate_->OnOverscrollComplete(overscroll_mode_);
(...skipping 18 matching lines...) Expand all
358 const WebKit::WebInputEvent& event) const { 363 const WebKit::WebInputEvent& event) const {
359 if (!WebKit::WebInputEvent::isGestureEventType(event.type)) 364 if (!WebKit::WebInputEvent::isGestureEventType(event.type))
360 return false; 365 return false;
361 366
362 // If the RenderWidgetHost already processed this event, then the event must 367 // If the RenderWidgetHost already processed this event, then the event must
363 // not be sent again. 368 // not be sent again.
364 return !render_widget_host_->HasQueuedGestureEvents(); 369 return !render_widget_host_->HasQueuedGestureEvents();
365 } 370 }
366 371
367 } // namespace content 372 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698