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

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: git try 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
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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 RenderWidgetHostImpl::From(GetRenderWidgetHost()); 412 RenderWidgetHostImpl::From(GetRenderWidgetHost());
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 : start_time_(base::TimeTicks::HighResNow()), 421 : start_time_(base::TimeTicks::HighResNow()),
422 last_forward_time_(start_time_),
420 scroll_down_(scroll_down), 423 scroll_down_(scroll_down),
421 scroll_far_(scroll_far) { } 424 scroll_far_(scroll_far) { }
422 425
423 virtual bool ForwardInputEvents(base::TimeTicks now, 426 virtual bool ForwardInputEvents(base::TimeTicks now,
424 RenderWidgetHost* host) OVERRIDE { 427 RenderWidgetHost* host) OVERRIDE {
425 int64 duration_in_ms; 428 int64 duration_in_ms;
426 if (scroll_far_) 429 if (scroll_far_)
427 duration_in_ms = kDurationOfFarScrollGestureMs; 430 duration_in_ms = kDurationOfFarScrollGestureMs;
428 else 431 else
429 duration_in_ms = kDurationOfNearScrollGestureMs; 432 duration_in_ms = kDurationOfNearScrollGestureMs;
430 433
431 if (now - start_time_ > base::TimeDelta::FromMilliseconds(duration_in_ms)) 434 if (now - start_time_ > base::TimeDelta::FromMilliseconds(duration_in_ms))
432 return false; 435 return false;
433 436
437 // Figure out how many wheel ticks to send.
438 double seconds_since_last_tick = (now - last_forward_time_).InSecondsF();
439 int num_wheel_ticks = static_cast<int>(
440 seconds_since_last_tick * kWheelTicksPerSecond);
441 if (!num_wheel_ticks) {
442 TRACE_EVENT_INSTANT1("input", "NoMovement",
443 "seconds_since_last_tick", seconds_since_last_tick);
444 return true;
445 }
446
447 last_forward_time_ = now;
448
434 WebKit::WebMouseWheelEvent event; 449 WebKit::WebMouseWheelEvent event;
435 event.type = WebKit::WebInputEvent::MouseWheel; 450 event.type = WebKit::WebInputEvent::MouseWheel;
436 // TODO(nduca): Figure out plausible value. 451 // TODO(nduca): Figure out plausible value.
437 event.deltaY = scroll_down_ ? -10 : 10; 452 event.deltaY = scroll_down_ ? -10 : 10;
438 event.wheelTicksY = scroll_down_ ? 1 : -1; 453 event.wheelTicksY = (scroll_down_ ? 1 : -1) * num_wheel_ticks;
439 event.modifiers = 0; 454 event.modifiers = 0;
440 455
441 // TODO(nduca): Figure out plausible x and y values. 456 // TODO(nduca): Figure out plausible x and y values.
442 event.globalX = 0; 457 event.globalX = 0;
443 event.globalY = 0; 458 event.globalY = 0;
444 event.x = 0; 459 event.x = 0;
445 event.y = 0; 460 event.y = 0;
446 event.windowX = event.x; 461 event.windowX = event.x;
447 event.windowY = event.y; 462 event.windowY = event.y;
448 host->ForwardWheelEvent(event); 463 host->ForwardWheelEvent(event);
449 return true; 464 return true;
450 } 465 }
451 466
452 private: 467 private:
453 virtual ~BasicMouseWheelSmoothScrollGesture() { } 468 virtual ~BasicMouseWheelSmoothScrollGesture() { }
454 base::TimeTicks start_time_; 469 base::TimeTicks start_time_;
470 base::TimeTicks last_forward_time_;
455 bool scroll_down_; 471 bool scroll_down_;
456 bool scroll_far_; 472 bool scroll_far_;
457 }; 473 };
458 474
459 SmoothScrollGesture* RenderWidgetHostViewBase::CreateSmoothScrollGesture( 475 SmoothScrollGesture* RenderWidgetHostViewBase::CreateSmoothScrollGesture(
460 bool scroll_down, bool scroll_far) { 476 bool scroll_down, bool scroll_far) {
461 return new BasicMouseWheelSmoothScrollGesture(scroll_down, scroll_far); 477 return new BasicMouseWheelSmoothScrollGesture(scroll_down, scroll_far);
462 } 478 }
463 479
464 } // namespace content 480 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698