Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: content/browser/renderer_host/input/touch_scroll_smooth_gesture.cc

Issue 26664002: SyntheticGestureTarget implementation for injecting synthetic input events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/input/touch_scroll_smooth_gesture.h"
6 #include "content/browser/renderer_host/render_widget_host_impl.h"
7 #include "content/common/input/input_event.h"
8 #include "content/port/browser/render_widget_host_view_port.h"
9
10 #include "third_party/WebKit/public/web/WebInputEvent.h"
11
12 namespace content {
13
14 TouchSmoothScrollGesture::TouchSmoothScrollGesture(bool scroll_down,
15 int pixels_to_scroll,
16 int mouse_event_x,
17 int mouse_event_y)
18 : scroll_down_(scroll_down),
19 pixels_to_scroll_(pixels_to_scroll),
20 pixels_scrolled_(0),
21 mouse_event_x_(mouse_event_x),
22 mouse_event_y_(mouse_event_y) {
23 }
24
25 TouchSmoothScrollGesture::~TouchSmoothScrollGesture() {}
26
27 namespace {
28
29 void InjectTouchEvent(
30 RenderWidgetHostViewPort* view,
31 WebKit::WebInputEvent::Type type,
32 WebKit::WebTouchPoint::State state,
33 int x, int y) {
34 WebKit::WebTouchEvent touch_event;
35 touch_event.type = type;
36 touch_event.touchesLength = 1;
37 touch_event.touches[0].id = 1;
38 touch_event.touches[0].state = state;
39 // screenPosition is unused for RWHV::QueueInputEventToPlatform
40 touch_event.touches[0].screenPosition.x = 0;
41 touch_event.touches[0].screenPosition.y = 0;
42 touch_event.touches[0].position.x = x;
43 touch_event.touches[0].position.y = y;
44 touch_event.touches[0].radiusX = 1;
45 touch_event.touches[0].radiusY = 1;
46 touch_event.touches[0].rotationAngle = 1.0f;
47 touch_event.touches[0].force = 1.0f;
48
49 InputEvent input_event(touch_event, ui::LatencyInfo(), false);
50 view->QueueInputEventToPlatform(input_event);
51 }
52
53 } // namespace
54
55 bool TouchSmoothScrollGesture::ForwardInputEvents(
56 base::TimeTicks now,
57 RenderWidgetHost* host) {
58 if (pixels_scrolled_ >= pixels_to_scroll_)
59 return false;
60
61 RenderWidgetHostImpl* host_impl = RenderWidgetHostImpl::From(host);
62 float position_delta = synthetic_gesture_calculator_.GetDelta(now,
63 host_impl->GetSyntheticGestureMessageInterval());
64
65 // Note: we will be able to get this directly in the new I/F
66 RenderWidgetHostViewPort* view =
67 RenderWidgetHostViewPort::FromRWHV(host->GetView());
68 if (!view)
69 return false;
70
71 if (pixels_scrolled_ == 0) {
72 InjectTouchEvent(view,
73 WebKit::WebInputEvent::TouchStart,
74 WebKit::WebTouchPoint::StatePressed,
75 mouse_event_x_, mouse_event_y_);
76 }
77
78 mouse_event_y_ += scroll_down_ ? -position_delta : position_delta;
79
80 InjectTouchEvent(view,
81 WebKit::WebInputEvent::TouchMove,
82 WebKit::WebTouchPoint::StateMoved,
83 mouse_event_x_, mouse_event_y_);
84
85 pixels_scrolled_ += abs(position_delta);
86
87 if (pixels_scrolled_ >= pixels_to_scroll_) {
88 InjectTouchEvent(view,
89 WebKit::WebInputEvent::TouchEnd,
90 WebKit::WebTouchPoint::StateReleased,
91 mouse_event_x_, mouse_event_y_);
92 }
93
94 return true;
95 }
96
97 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698