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.
5 #include "content/browser/renderer_host/basic_mouse_wheel_smooth_scroll_gesture.h"
7 #include "base/debug/trace_event.h"
8 #include "content/browser/renderer_host/render_widget_host_impl.h"
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),
17 pixels_to_scroll_(pixels_to_scroll),
18 mouse_event_x_(mouse_event_x),
19 mouse_event_y_(mouse_event_y) { }
21 BasicMouseWheelSmoothScrollGesture::~BasicMouseWheelSmoothScrollGesture() { }
23 bool BasicMouseWheelSmoothScrollGesture::ForwardInputEvents(
24 base::TimeTicks now, RenderWidgetHost* host) {
26 if (pixels_scrolled_ >= pixels_to_scroll_)
29 float position_delta = synthetic_gesture_calculator_.GetDelta(
31 RenderWidgetHostImpl::From(host)->GetSyntheticGestureMessageInterval());
34 WebKit::WebMouseWheelEvent event;
35 event.type = WebKit::WebInputEvent::MouseWheel;
36 event.hasPreciseScrollingDeltas = 0;
37 event.deltaY = scroll_down_ ? -position_delta : position_delta;
38 // TODO(vollick): find a proper way to access
39 // WebCore::WheelEvent::tickMultiplier.
40 event.wheelTicksY = event.deltaY / 120;
43 // TODO(nduca): Figure out plausible x and y values.
46 event.x = mouse_event_x_;
47 event.y = mouse_event_y_;
48 event.windowX = event.x;
49 event.windowY = event.y;
50 host->ForwardWheelEvent(event);
52 pixels_scrolled_ += abs(event.deltaY);
55 "gpu", "smooth_scroll_by_pixels_scrolled", this, pixels_scrolled_);