OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/renderer_host/basic_mouse_wheel_smooth_scroll_gesture.
h" |
| 6 |
| 7 #include "base/debug/trace_event.h" |
| 8 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 BasicMouseWheelSmoothScrollGesture::BasicMouseWheelSmoothScrollGesture( |
| 13 bool scroll_down, int pixels_to_scroll, |
| 14 int mouse_event_x, int mouse_event_y) |
| 15 : scroll_down_(scroll_down), |
| 16 pixels_scrolled_(0), |
| 17 pixels_to_scroll_(pixels_to_scroll), |
| 18 mouse_event_x_(mouse_event_x), |
| 19 mouse_event_y_(mouse_event_y) { } |
| 20 |
| 21 BasicMouseWheelSmoothScrollGesture::~BasicMouseWheelSmoothScrollGesture() { } |
| 22 |
| 23 bool BasicMouseWheelSmoothScrollGesture::ForwardInputEvents( |
| 24 base::TimeTicks now, RenderWidgetHost* host) { |
| 25 |
| 26 if (pixels_scrolled_ >= pixels_to_scroll_) |
| 27 return false; |
| 28 |
| 29 double positionDelta = 10; |
| 30 if (!last_tick_time_.is_null()) { |
| 31 double desiredIntervalMs = host->SyntheticScrollMessageInterval(); |
| 32 double velocity = 10 / desiredIntervalMs; |
| 33 double timeDelta = (now - last_tick_time_).InMillisecondsF(); |
| 34 positionDelta = velocity * timeDelta; |
| 35 } |
| 36 |
| 37 last_tick_time_ = now; |
| 38 |
| 39 WebKit::WebMouseWheelEvent event; |
| 40 event.type = WebKit::WebInputEvent::MouseWheel; |
| 41 // TODO(nduca): Figure out plausible value. |
| 42 event.deltaY = scroll_down_ ? -positionDelta : positionDelta; |
| 43 event.wheelTicksY = (scroll_down_ ? 1 : -1); |
| 44 event.modifiers = 0; |
| 45 |
| 46 // TODO(nduca): Figure out plausible x and y values. |
| 47 event.globalX = 0; |
| 48 event.globalY = 0; |
| 49 event.x = mouse_event_x_; |
| 50 event.y = mouse_event_y_; |
| 51 event.windowX = event.x; |
| 52 event.windowY = event.y; |
| 53 host->ForwardWheelEvent(event); |
| 54 |
| 55 pixels_scrolled_ += abs(event.deltaY); |
| 56 |
| 57 TRACE_COUNTER_ID1( |
| 58 "gpu", "smooth_scroll_by_pixels_scrolled", this, pixels_scrolled_); |
| 59 |
| 60 return true; |
| 61 } |
| 62 |
| 63 } // content |
| 64 |
OLD | NEW |