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

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

Issue 11013043: beginSmoothScroll should send wheel ticks at constant velocity. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/render_widget_host_view_base.h" 5 #include "content/browser/renderer_host/render_widget_host_view_base.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/accessibility/browser_accessibility_manager.h" 8 #include "content/browser/accessibility/browser_accessibility_manager.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/port/browser/smooth_scroll_gesture.h" 10 #include "content/port/browser/smooth_scroll_gesture.h"
(...skipping 24 matching lines...) Expand all
35 #endif 35 #endif
36 36
37 namespace content { 37 namespace content {
38 38
39 // How long a smooth scroll gesture should run when it is a near scroll. 39 // How long a smooth scroll gesture should run when it is a near scroll.
40 static const int64 kDurationOfNearScrollGestureMs = 150; 40 static const int64 kDurationOfNearScrollGestureMs = 150;
41 41
42 // How long a smooth scroll gesture should run when it is a far scroll. 42 // How long a smooth scroll gesture should run when it is a far scroll.
43 static const int64 kDurationOfFarScrollGestureMs = 500; 43 static const int64 kDurationOfFarScrollGestureMs = 500;
44 44
45 static const int64 kWheelTicksPerSecond = 1500;
46
45 // static 47 // static
46 RenderWidgetHostViewPort* RenderWidgetHostViewPort::FromRWHV( 48 RenderWidgetHostViewPort* RenderWidgetHostViewPort::FromRWHV(
47 RenderWidgetHostView* rwhv) { 49 RenderWidgetHostView* rwhv) {
48 return static_cast<RenderWidgetHostViewPort*>(rwhv); 50 return static_cast<RenderWidgetHostViewPort*>(rwhv);
49 } 51 }
50 52
51 // static 53 // static
52 RenderWidgetHostViewPort* RenderWidgetHostViewPort::CreateViewForWidget( 54 RenderWidgetHostViewPort* RenderWidgetHostViewPort::CreateViewForWidget(
53 content::RenderWidgetHost* widget) { 55 content::RenderWidgetHost* widget) {
54 return FromRWHV(RenderWidgetHostView::CreateViewForWidget(widget)); 56 return FromRWHV(RenderWidgetHostView::CreateViewForWidget(widget));
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 impl->NotifyScreenInfoChanged(); 413 impl->NotifyScreenInfoChanged();
412 } 414 }
413 } 415 }
414 416
415 class BasicMouseWheelSmoothScrollGesture 417 class BasicMouseWheelSmoothScrollGesture
416 : public SmoothScrollGesture { 418 : public SmoothScrollGesture {
417 public: 419 public:
418 BasicMouseWheelSmoothScrollGesture(bool scroll_down, bool scroll_far, 420 BasicMouseWheelSmoothScrollGesture(bool scroll_down, bool scroll_far,
419 int mouse_event_x, int mouse_event_y) 421 int mouse_event_x, int mouse_event_y)
420 : start_time_(base::TimeTicks::HighResNow()), 422 : start_time_(base::TimeTicks::HighResNow()),
423 last_forward_time_(start_time_),
421 scroll_down_(scroll_down), 424 scroll_down_(scroll_down),
422 scroll_far_(scroll_far), 425 scroll_far_(scroll_far),
423 mouse_event_x_(mouse_event_x), 426 mouse_event_x_(mouse_event_x),
424 mouse_event_y_(mouse_event_y) { } 427 mouse_event_y_(mouse_event_y) { }
425 428
426 virtual bool ForwardInputEvents(base::TimeTicks now, 429 virtual bool ForwardInputEvents(base::TimeTicks now,
427 RenderWidgetHost* host) OVERRIDE { 430 RenderWidgetHost* host) OVERRIDE {
428 int64 duration_in_ms; 431 int64 duration_in_ms;
429 if (scroll_far_) 432 if (scroll_far_)
430 duration_in_ms = kDurationOfFarScrollGestureMs; 433 duration_in_ms = kDurationOfFarScrollGestureMs;
431 else 434 else
432 duration_in_ms = kDurationOfNearScrollGestureMs; 435 duration_in_ms = kDurationOfNearScrollGestureMs;
433 436
434 if (now - start_time_ > base::TimeDelta::FromMilliseconds(duration_in_ms)) 437 if (now - start_time_ > base::TimeDelta::FromMilliseconds(duration_in_ms))
435 return false; 438 return false;
436 439
440 // Figure out how many wheel ticks to send.
441 double seconds_since_last_tick = (now - last_forward_time_).InSecondsF();
442 int num_wheel_ticks = static_cast<int>(
443 seconds_since_last_tick * kWheelTicksPerSecond);
444 if (!num_wheel_ticks) {
445 TRACE_EVENT_INSTANT1("input", "NoMovement",
446 "seconds_since_last_tick", seconds_since_last_tick);
447 return true;
448 }
449
450 last_forward_time_ = now;
451
437 WebKit::WebMouseWheelEvent event; 452 WebKit::WebMouseWheelEvent event;
438 event.type = WebKit::WebInputEvent::MouseWheel; 453 event.type = WebKit::WebInputEvent::MouseWheel;
439 // TODO(nduca): Figure out plausible value. 454 // TODO(nduca): Figure out plausible value.
440 event.deltaY = scroll_down_ ? -10 : 10; 455 event.deltaY = scroll_down_ ? -10 : 10;
441 event.wheelTicksY = scroll_down_ ? 1 : -1; 456 event.wheelTicksY = (scroll_down_ ? 1 : -1) * num_wheel_ticks;
442 event.modifiers = 0; 457 event.modifiers = 0;
443 458
444 // TODO(nduca): Figure out plausible x and y values. 459 // TODO(nduca): Figure out plausible x and y values.
445 event.globalX = 0; 460 event.globalX = 0;
446 event.globalY = 0; 461 event.globalY = 0;
447 event.x = mouse_event_x_; 462 event.x = mouse_event_x_;
448 event.y = mouse_event_y_; 463 event.y = mouse_event_y_;
449 event.windowX = event.x; 464 event.windowX = event.x;
450 event.windowY = event.y; 465 event.windowY = event.y;
451 host->ForwardWheelEvent(event); 466 host->ForwardWheelEvent(event);
452 return true; 467 return true;
453 } 468 }
454 469
455 private: 470 private:
456 virtual ~BasicMouseWheelSmoothScrollGesture() { } 471 virtual ~BasicMouseWheelSmoothScrollGesture() { }
457 base::TimeTicks start_time_; 472 base::TimeTicks start_time_;
473 base::TimeTicks last_forward_time_;
458 bool scroll_down_; 474 bool scroll_down_;
459 bool scroll_far_; 475 bool scroll_far_;
460 int mouse_event_x_; 476 int mouse_event_x_;
461 int mouse_event_y_; 477 int mouse_event_y_;
462 }; 478 };
463 479
464 SmoothScrollGesture* RenderWidgetHostViewBase::CreateSmoothScrollGesture( 480 SmoothScrollGesture* RenderWidgetHostViewBase::CreateSmoothScrollGesture(
465 bool scroll_down, bool scroll_far, int mouse_event_x, int mouse_event_y) { 481 bool scroll_down, bool scroll_far, int mouse_event_x, int mouse_event_y) {
466 return new BasicMouseWheelSmoothScrollGesture(scroll_down, scroll_far, 482 return new BasicMouseWheelSmoothScrollGesture(scroll_down, scroll_far,
467 mouse_event_x, mouse_event_y); 483 mouse_event_x, mouse_event_y);
468 } 484 }
469 485
470 } // namespace content 486 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698