Index: content/browser/renderer_host/basic_mouse_wheel_smooth_scroll_gesture.cc |
diff --git a/content/browser/renderer_host/basic_mouse_wheel_smooth_scroll_gesture.cc b/content/browser/renderer_host/basic_mouse_wheel_smooth_scroll_gesture.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e17b765d47c1b10895238218263df64e02b06c79 |
--- /dev/null |
+++ b/content/browser/renderer_host/basic_mouse_wheel_smooth_scroll_gesture.cc |
@@ -0,0 +1,64 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/renderer_host/basic_mouse_wheel_smooth_scroll_gesture.h" |
+ |
+#include "base/debug/trace_event.h" |
+#include "content/browser/renderer_host/render_widget_host_impl.h" |
+ |
+namespace content { |
+ |
+BasicMouseWheelSmoothScrollGesture::BasicMouseWheelSmoothScrollGesture( |
+ bool scroll_down, int pixels_to_scroll, |
+ int mouse_event_x, int mouse_event_y) |
+ : scroll_down_(scroll_down), |
+ pixels_scrolled_(0), |
+ pixels_to_scroll_(pixels_to_scroll), |
+ mouse_event_x_(mouse_event_x), |
+ mouse_event_y_(mouse_event_y) { } |
+ |
+BasicMouseWheelSmoothScrollGesture::~BasicMouseWheelSmoothScrollGesture() { } |
+ |
+bool BasicMouseWheelSmoothScrollGesture::ForwardInputEvents( |
+ base::TimeTicks now, RenderWidgetHost* host) { |
+ |
+ if (pixels_scrolled_ >= pixels_to_scroll_) |
+ return false; |
+ |
+ double positionDelta = 10; |
+ if (!last_tick_time_.is_null()) { |
+ double desiredIntervalMs = host->SyntheticScrollMessageInterval(); |
+ double velocity = 10 / desiredIntervalMs; |
+ double timeDelta = (now - last_tick_time_).InMillisecondsF(); |
+ positionDelta = velocity * timeDelta; |
+ } |
+ |
+ last_tick_time_ = now; |
+ |
+ WebKit::WebMouseWheelEvent event; |
+ event.type = WebKit::WebInputEvent::MouseWheel; |
+ // TODO(nduca): Figure out plausible value. |
+ event.deltaY = scroll_down_ ? -positionDelta : positionDelta; |
+ event.wheelTicksY = (scroll_down_ ? 1 : -1); |
+ event.modifiers = 0; |
+ |
+ // TODO(nduca): Figure out plausible x and y values. |
+ event.globalX = 0; |
+ event.globalY = 0; |
+ event.x = mouse_event_x_; |
+ event.y = mouse_event_y_; |
+ event.windowX = event.x; |
+ event.windowY = event.y; |
+ host->ForwardWheelEvent(event); |
+ |
+ pixels_scrolled_ += abs(event.deltaY); |
+ |
+ TRACE_COUNTER_ID1( |
+ "gpu", "smooth_scroll_by_pixels_scrolled", this, pixels_scrolled_); |
+ |
+ return true; |
+} |
+ |
+} // content |
+ |