| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/browser/renderer_host/touch_smooth_scroll_gesture_aura.h" | |
| 6 | |
| 7 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
| 8 #include "ui/aura/root_window.h" | |
| 9 #include "ui/aura/window.h" | |
| 10 #include "ui/events/event.h" | |
| 11 #include "ui/events/event_utils.h" | |
| 12 #include "ui/gfx/transform.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 void InjectTouchEvent(const gfx::Point& location, | |
| 17 ui::EventType type, | |
| 18 aura::Window* window) { | |
| 19 gfx::Point screen_location = location; | |
| 20 aura::Window* root_window = window->GetRootWindow(); | |
| 21 // First convert the location from Window to RootWindow. | |
| 22 aura::Window::ConvertPointToTarget(window, root_window, &screen_location); | |
| 23 // Then convert the location from RootWindow to screen. | |
| 24 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); | |
| 25 dispatcher->ConvertPointToHost(&screen_location); | |
| 26 ui::TouchEvent touch(type, screen_location, 0, 0, ui::EventTimeForNow(), | |
| 27 1.0f, 1.0f, 1.0f, 1.0f); | |
| 28 dispatcher->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch); | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 namespace content { | |
| 34 | |
| 35 TouchSmoothScrollGestureAura::TouchSmoothScrollGestureAura(bool scroll_down, | |
| 36 int pixels_to_scroll, | |
| 37 int mouse_event_x, | |
| 38 int mouse_event_y, | |
| 39 aura::Window* window) | |
| 40 : scroll_down_(scroll_down), | |
| 41 pixels_to_scroll_(pixels_to_scroll), | |
| 42 pixels_scrolled_(0), | |
| 43 location_(mouse_event_x, mouse_event_y), | |
| 44 window_(window) { | |
| 45 } | |
| 46 | |
| 47 TouchSmoothScrollGestureAura::~TouchSmoothScrollGestureAura() {} | |
| 48 | |
| 49 bool TouchSmoothScrollGestureAura::ForwardInputEvents( | |
| 50 base::TimeTicks now, | |
| 51 RenderWidgetHost* host) { | |
| 52 if (pixels_scrolled_ >= pixels_to_scroll_) | |
| 53 return false; | |
| 54 | |
| 55 RenderWidgetHostImpl* host_impl = RenderWidgetHostImpl::From(host); | |
| 56 float position_delta = synthetic_gesture_calculator_.GetDelta(now, | |
| 57 host_impl->GetSyntheticGestureMessageInterval()); | |
| 58 | |
| 59 if (pixels_scrolled_ == 0) { | |
| 60 InjectTouchEvent(location_, ui::ET_TOUCH_PRESSED, window_); | |
| 61 } | |
| 62 | |
| 63 location_.Offset(0, scroll_down_ ? -position_delta : position_delta); | |
| 64 InjectTouchEvent(location_, ui::ET_TOUCH_MOVED, window_); | |
| 65 | |
| 66 pixels_scrolled_ += abs(position_delta); | |
| 67 | |
| 68 if (pixels_scrolled_ >= pixels_to_scroll_) { | |
| 69 InjectTouchEvent(location_, ui::ET_TOUCH_RELEASED, window_); | |
| 70 } | |
| 71 | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 } // namespace content | |
| OLD | NEW |