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

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: 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
2
3 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 // 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
5 // found in the LICENSE file. 3 // found in the LICENSE file.
6 4
7 #include "content/browser/renderer_host/overscroll_controller.h" 5 #include "content/browser/renderer_host/overscroll_controller.h"
8 6
9 #include "content/browser/renderer_host/gesture_event_filter.h" 7 #include "content/browser/renderer_host/gesture_event_filter.h"
10 #include "content/browser/renderer_host/overscroll_controller_delegate.h" 8 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
11 #include "content/browser/renderer_host/render_widget_host_impl.h" 9 #include "content/browser/renderer_host/render_widget_host_impl.h"
12 #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
274 } 272 }
275 273
276 default: 274 default:
277 DCHECK(WebKit::WebInputEvent::isGestureEventType(event.type) || 275 DCHECK(WebKit::WebInputEvent::isGestureEventType(event.type) ||
278 WebKit::WebInputEvent::isTouchEventType(event.type)) 276 WebKit::WebInputEvent::isTouchEventType(event.type))
279 << "Received unexpected event: " << event.type; 277 << "Received unexpected event: " << event.type;
280 } 278 }
281 } 279 }
282 280
283 void OverscrollController::ProcessOverscroll(float delta_x, float delta_y) { 281 void OverscrollController::ProcessOverscroll(float delta_x, float delta_y) {
284 if (scroll_state_ == STATE_CONTENT_SCROLLING) 282 if (scroll_state_ != STATE_CONTENT_SCROLLING)
285 return; 283 overscroll_delta_x_ += delta_x;
286 overscroll_delta_x_ += delta_x;
287 overscroll_delta_y_ += delta_y; 284 overscroll_delta_y_ += delta_y;
288 285
289 float threshold = GetOverscrollConfig(OVERSCROLL_CONFIG_MIN_THRESHOLD_START); 286 float horiz_threshold = GetOverscrollConfig(
290 if (fabs(overscroll_delta_x_) < threshold && 287 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START);
291 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) {
292 SetOverscrollMode(OVERSCROLL_NONE); 292 SetOverscrollMode(OVERSCROLL_NONE);
293 return; 293 return;
294 } 294 }
295 295
296 // Compute the current overscroll direction. If the direction is different 296 // Compute the current overscroll direction. If the direction is different
297 // 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
298 // 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.
299 OverscrollMode new_mode = OVERSCROLL_NONE; 299 OverscrollMode new_mode = OVERSCROLL_NONE;
300 const float kMinRatio = 2.5; 300 const float kMinRatio = 2.5;
301 if (fabs(overscroll_delta_x_) > fabs(overscroll_delta_y_) * kMinRatio) 301 if (fabs(overscroll_delta_x_) > fabs(overscroll_delta_y_) * kMinRatio)
302 new_mode = overscroll_delta_x_ > 0.f ? OVERSCROLL_EAST : OVERSCROLL_WEST; 302 new_mode = overscroll_delta_x_ > 0.f ? OVERSCROLL_EAST : OVERSCROLL_WEST;
303 else if (fabs(overscroll_delta_y_) > fabs(overscroll_delta_x_) * kMinRatio) 303 else if (fabs(overscroll_delta_y_) > fabs(overscroll_delta_x_) * kMinRatio)
304 new_mode = overscroll_delta_y_ > 0.f ? OVERSCROLL_SOUTH : OVERSCROLL_NORTH; 304 new_mode = overscroll_delta_y_ > 0.f ? OVERSCROLL_SOUTH : OVERSCROLL_NORTH;
305 305
306 if (overscroll_mode_ == OVERSCROLL_NONE) { 306 if (overscroll_mode_ == OVERSCROLL_NONE) {
sadrul 2013/07/04 21:16:35 I believe in this changed code, if a scroll event
rharrison 2013/07/17 18:59:48 Good catch, I have added checks to make sure that
307 SetOverscrollMode(new_mode); 307 SetOverscrollMode(new_mode);
308 } else if (new_mode != overscroll_mode_) { 308 } else if (new_mode != overscroll_mode_) {
309 SetOverscrollMode(OVERSCROLL_NONE); 309 SetOverscrollMode(OVERSCROLL_NONE);
310 return; 310 return;
311 } 311 }
312 312
313 // Tell the delegate about the overscroll update so that it can update 313 // Tell the delegate about the overscroll update so that it can update
314 // the display accordingly (e.g. show history preview etc.). 314 // the display accordingly (e.g. show history preview etc.).
315 if (delegate_) { 315 if (delegate_) {
316 // Do not include the threshold amount when sending the deltas to the 316 // Do not include the threshold amount when sending the deltas to the
317 // delegate. 317 // delegate.
318 float delegate_delta_x = overscroll_delta_x_; 318 float delegate_delta_x = overscroll_delta_x_;
319 if (fabs(delegate_delta_x) > threshold) { 319 if (fabs(delegate_delta_x) > horiz_threshold) {
320 if (delegate_delta_x < 0) 320 if (delegate_delta_x < 0)
321 delegate_delta_x += threshold; 321 delegate_delta_x += horiz_threshold;
322 else 322 else
323 delegate_delta_x -= threshold; 323 delegate_delta_x -= horiz_threshold;
324 } else { 324 } else {
325 delegate_delta_x = 0.f; 325 delegate_delta_x = 0.f;
326 } 326 }
327 327
328 float delegate_delta_y = overscroll_delta_y_; 328 float delegate_delta_y = overscroll_delta_y_;
329 if (fabs(delegate_delta_y) > threshold) { 329 if (fabs(delegate_delta_y) > vert_threshold) {
330 if (delegate_delta_y < 0) 330 if (delegate_delta_y < 0)
331 delegate_delta_y += threshold; 331 delegate_delta_y += vert_threshold;
332 else 332 else
333 delegate_delta_y -= threshold; 333 delegate_delta_y -= vert_threshold;
334 } else { 334 } else {
335 delegate_delta_y = 0.f; 335 delegate_delta_y = 0.f;
336 } 336 }
337 delegate_->OnOverscrollUpdate(delegate_delta_x, delegate_delta_y); 337 delegate_->OnOverscrollUpdate(delegate_delta_x, delegate_delta_y);
338 } 338 }
339 } 339 }
340 340
341 void OverscrollController::CompleteAction() { 341 void OverscrollController::CompleteAction() {
342 if (delegate_) 342 if (delegate_)
343 delegate_->OnOverscrollComplete(overscroll_mode_); 343 delegate_->OnOverscrollComplete(overscroll_mode_);
(...skipping 18 matching lines...) Expand all
362 const WebKit::WebInputEvent& event) const { 362 const WebKit::WebInputEvent& event) const {
363 if (!WebKit::WebInputEvent::isGestureEventType(event.type)) 363 if (!WebKit::WebInputEvent::isGestureEventType(event.type))
364 return false; 364 return false;
365 365
366 // If the GestureEventFilter already processed this event, then the event must 366 // If the GestureEventFilter already processed this event, then the event must
367 // not be sent to the filter again. 367 // not be sent to the filter again.
368 return !render_widget_host_->gesture_event_filter()->HasQueuedGestureEvents(); 368 return !render_widget_host_->gesture_event_filter()->HasQueuedGestureEvents();
369 } 369 }
370 370
371 } // namespace content 371 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698