1 // Copyright (c) 2013 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/touch_smooth_scroll_gesture_aura.h"
7 #include "content/browser/renderer_host/render_widget_host_impl.h"
8 #include "ui/aura/root_window.h"
9 #include "ui/events/event.h"
10 #include "ui/events/event_utils.h"
11 #include "ui/gfx/transform.h"
15 void InjectTouchEvent(const gfx::Point& location,
17 aura::Window* window) {
18 gfx::Point screen_location = location;
19 aura::Window* root_window = window->GetRootWindow();
20 // First convert the location from Window to RootWindow.
21 aura::Window::ConvertPointToTarget(window, root_window, &screen_location);
22 // Then convert the location from RootWindow to screen.
23 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher();
24 dispatcher->ConvertPointToHost(&screen_location);
25 ui::TouchEvent touch(type, screen_location, 0, 0, ui::EventTimeForNow(),
26 1.0f, 1.0f, 1.0f, 1.0f);
27 dispatcher->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch);
34 TouchSmoothScrollGestureAura::TouchSmoothScrollGestureAura(bool scroll_down,
39 : scroll_down_(scroll_down),
40 pixels_to_scroll_(pixels_to_scroll),
42 location_(mouse_event_x, mouse_event_y),
46 TouchSmoothScrollGestureAura::~TouchSmoothScrollGestureAura() {}
48 bool TouchSmoothScrollGestureAura::ForwardInputEvents(
50 RenderWidgetHost* host) {
51 if (pixels_scrolled_ >= pixels_to_scroll_)
54 RenderWidgetHostImpl* host_impl = RenderWidgetHostImpl::From(host);
55 float position_delta = synthetic_gesture_calculator_.GetDelta(now,
56 host_impl->GetSyntheticGestureMessageInterval());
58 if (pixels_scrolled_ == 0) {
59 InjectTouchEvent(location_, ui::ET_TOUCH_PRESSED, window_);
62 location_.Offset(0, scroll_down_ ? -position_delta : position_delta);
63 InjectTouchEvent(location_, ui::ET_TOUCH_MOVED, window_);
65 pixels_scrolled_ += abs(position_delta);
67 if (pixels_scrolled_ >= pixels_to_scroll_) {
68 InjectTouchEvent(location_, ui::ET_TOUCH_RELEASED, window_);
74 } // namespace content