Index: content/browser/renderer_host/input/touch_scroll_smooth_gesture.cc |
diff --git a/content/browser/renderer_host/input/touch_scroll_smooth_gesture.cc b/content/browser/renderer_host/input/touch_scroll_smooth_gesture.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..05bb3152843bbe53cda294a1bb34686dc7bd3b23 |
--- /dev/null |
+++ b/content/browser/renderer_host/input/touch_scroll_smooth_gesture.cc |
@@ -0,0 +1,97 @@ |
+// Copyright (c) 2013 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/input/touch_scroll_smooth_gesture.h" |
+#include "content/browser/renderer_host/render_widget_host_impl.h" |
+#include "content/common/input/input_event.h" |
+#include "content/port/browser/render_widget_host_view_port.h" |
+ |
+#include "third_party/WebKit/public/web/WebInputEvent.h" |
+ |
+namespace content { |
+ |
+TouchSmoothScrollGesture::TouchSmoothScrollGesture(bool scroll_down, |
+ int pixels_to_scroll, |
+ int mouse_event_x, |
+ int mouse_event_y) |
+ : scroll_down_(scroll_down), |
+ pixels_to_scroll_(pixels_to_scroll), |
+ pixels_scrolled_(0), |
+ mouse_event_x_(mouse_event_x), |
+ mouse_event_y_(mouse_event_y) { |
+} |
+ |
+TouchSmoothScrollGesture::~TouchSmoothScrollGesture() {} |
+ |
+namespace { |
+ |
+void InjectTouchEvent( |
+ RenderWidgetHostViewPort* view, |
+ WebKit::WebInputEvent::Type type, |
+ WebKit::WebTouchPoint::State state, |
+ int x, int y) { |
+ WebKit::WebTouchEvent touch_event; |
+ touch_event.type = type; |
+ touch_event.touchesLength = 1; |
+ touch_event.touches[0].id = 1; |
+ touch_event.touches[0].state = state; |
+ // screenPosition is unused for RWHV::QueueInputEventToPlatform |
+ touch_event.touches[0].screenPosition.x = 0; |
+ touch_event.touches[0].screenPosition.y = 0; |
+ touch_event.touches[0].position.x = x; |
+ touch_event.touches[0].position.y = y; |
+ touch_event.touches[0].radiusX = 1; |
+ touch_event.touches[0].radiusY = 1; |
+ touch_event.touches[0].rotationAngle = 1.0f; |
+ touch_event.touches[0].force = 1.0f; |
+ |
+ InputEvent input_event(touch_event, ui::LatencyInfo(), false); |
+ view->QueueInputEventToPlatform(input_event); |
+} |
+ |
+} // namespace |
+ |
+bool TouchSmoothScrollGesture::ForwardInputEvents( |
+ base::TimeTicks now, |
+ RenderWidgetHost* host) { |
+ if (pixels_scrolled_ >= pixels_to_scroll_) |
+ return false; |
+ |
+ RenderWidgetHostImpl* host_impl = RenderWidgetHostImpl::From(host); |
+ float position_delta = synthetic_gesture_calculator_.GetDelta(now, |
+ host_impl->GetSyntheticGestureMessageInterval()); |
+ |
+ // Note: we will be able to get this directly in the new I/F |
+ RenderWidgetHostViewPort* view = |
+ RenderWidgetHostViewPort::FromRWHV(host->GetView()); |
+ if (!view) |
+ return false; |
+ |
+ if (pixels_scrolled_ == 0) { |
+ InjectTouchEvent(view, |
+ WebKit::WebInputEvent::TouchStart, |
+ WebKit::WebTouchPoint::StatePressed, |
+ mouse_event_x_, mouse_event_y_); |
+ } |
+ |
+ mouse_event_y_ += scroll_down_ ? -position_delta : position_delta; |
+ |
+ InjectTouchEvent(view, |
+ WebKit::WebInputEvent::TouchMove, |
+ WebKit::WebTouchPoint::StateMoved, |
+ mouse_event_x_, mouse_event_y_); |
+ |
+ pixels_scrolled_ += abs(position_delta); |
+ |
+ if (pixels_scrolled_ >= pixels_to_scroll_) { |
+ InjectTouchEvent(view, |
+ WebKit::WebInputEvent::TouchEnd, |
+ WebKit::WebTouchPoint::StateReleased, |
+ mouse_event_x_, mouse_event_y_); |
+ } |
+ |
+ return true; |
+} |
+ |
+} // namespace content |