OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 "blimp/client/input/blimp_input_manager.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/location.h" | |
9 #include "ui/events/blink/blink_event_util.h" | |
10 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | |
11 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" | |
12 | |
13 namespace blimp { | |
14 | |
15 scoped_ptr<BlimpInputManager> BlimpInputManager::Create( | |
16 BlimpInputManagerClient* client, | |
17 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
18 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | |
19 const base::WeakPtr<cc::InputHandler>& input_handler) { | |
20 return make_scoped_ptr(new BlimpInputManager(client, | |
21 main_task_runner, | |
22 compositor_task_runner, | |
23 input_handler)); | |
24 } | |
25 | |
26 BlimpInputManager::BlimpInputManager( | |
27 BlimpInputManagerClient* client, | |
28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
29 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | |
30 const base::WeakPtr<cc::InputHandler>& input_handler) | |
31 : client_(client), | |
32 main_task_runner_(main_task_runner), | |
33 compositor_task_runner_(compositor_task_runner), | |
34 gesture_provider_(ui::GetGestureProviderConfig( | |
35 ui::GestureProviderConfigType::CURRENT_PLATFORM), | |
36 this) { | |
37 DCHECK(IsMainThread()); | |
38 DCHECK(client_); | |
39 compositor_task_runner_->PostTask( | |
40 FROM_HERE, | |
41 base::Bind( | |
42 &BlimpInputManager::CreateInputHandlerProxyOnCompositorThread, | |
43 base::Unretained(this), input_handler)); | |
David Trainor- moved to gerrit
2015/12/02 03:49:06
Are we sure we want unretained for this? Unretain
Khushal
2015/12/03 11:31:38
You're right, its not safe to use Unretained for t
Khushal
2015/12/03 12:44:30
Looking at this again, we'll still need to post a
| |
44 } | |
45 | |
46 BlimpInputManager::~BlimpInputManager() { | |
47 DCHECK(IsMainThread()); | |
48 } | |
49 | |
50 bool BlimpInputManager::OnTouchEvent(const ui::MotionEvent& motion_event) { | |
51 DCHECK(IsMainThread()); | |
52 | |
53 ui::FilteredGestureProvider::TouchHandlingResult result = | |
54 gesture_provider_.OnTouchEvent(motion_event); | |
55 if (!result.succeeded) | |
56 return false; | |
57 | |
58 blink::WebTouchEvent touch = | |
59 ui::CreateWebTouchEventFromMotionEvent(motion_event, | |
60 result.did_generate_scroll); | |
61 | |
62 // Touch events are queued in the Gesture Provider until acknowledged to | |
63 // allow them to be consumed by the touch event handlers in blink which can | |
64 // prevent-default on the event. Since we currently do not support touch | |
65 // handlers the event is always acknowledged as not consumed. | |
66 gesture_provider_.OnTouchEventAck(touch.uniqueTouchEventId, false); | |
67 | |
68 return true; | |
69 } | |
70 | |
71 void BlimpInputManager::WillShutdown() { | |
72 DCHECK(IsCompositorThread()); | |
73 | |
74 input_handler_proxy_.reset(); | |
75 } | |
76 | |
77 void BlimpInputManager::TransferActiveWheelFlingAnimation( | |
78 const blink::WebActiveWheelFlingParameters& params) { | |
79 DCHECK(IsCompositorThread()); | |
80 | |
81 NOTIMPLEMENTED()<< | |
David Trainor- moved to gerrit
2015/12/02 03:49:06
space between () and <<?
Khushal
2015/12/03 11:31:38
Done.
| |
82 "Transferring Fling Animations to the engine is not supported"; | |
83 } | |
84 | |
85 blink::WebGestureCurve* BlimpInputManager::CreateFlingAnimationCurve( | |
86 blink::WebGestureDevice device_source, | |
87 const blink::WebFloatPoint& velocity, | |
88 const blink::WebSize& cumulative_scroll) { | |
89 DCHECK(IsCompositorThread()); | |
90 | |
91 return ui::WebGestureCurveImpl::CreateFromDefaultPlatformCurve( | |
92 gfx::Vector2dF(velocity.x, velocity.y), | |
93 gfx::Vector2dF(cumulative_scroll.width, | |
94 cumulative_scroll.height), | |
95 false /* on_main_thread */).release(); | |
96 } | |
97 | |
98 void BlimpInputManager::DidOverscroll( | |
99 const gfx::Vector2dF& accumulated_overscroll, | |
100 const gfx::Vector2dF& latest_overscroll_delta, | |
101 const gfx::Vector2dF& current_fling_velocity, | |
102 const gfx::PointF& causal_event_viewport_point) { | |
103 DCHECK(IsCompositorThread()); | |
104 } | |
105 | |
106 void BlimpInputManager::DidStopFlinging() { | |
107 DCHECK(IsCompositorThread()); | |
108 } | |
109 | |
110 void BlimpInputManager::DidAnimateForInput() { | |
111 DCHECK(IsCompositorThread()); | |
112 } | |
113 | |
114 void BlimpInputManager::OnGestureEvent(const ui::GestureEventData& gesture) { | |
115 DCHECK(IsMainThread()); | |
116 | |
117 blink::WebGestureEvent web_gesture = | |
118 ui::CreateWebGestureEventFromGestureEventData(gesture); | |
119 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to | |
120 // stop providing shift meta values to synthetic MotionEvents. This prevents | |
121 // unintended shift+click interpretation of all accessibility clicks. | |
122 // See crbug.com/443247. | |
123 if (web_gesture.type == blink::WebInputEvent::GestureTap && | |
124 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { | |
125 web_gesture.modifiers = 0; | |
126 } | |
127 | |
128 compositor_task_runner_->PostTask( | |
129 FROM_HERE, | |
130 base::Bind( | |
131 &BlimpInputManager::HandleWebInputEventOnCompositorThread, | |
132 base::Unretained(this), web_gesture)); | |
133 } | |
134 | |
135 void BlimpInputManager::CreateInputHandlerProxyOnCompositorThread( | |
136 const base::WeakPtr<cc::InputHandler>& input_handler) { | |
137 DCHECK(IsCompositorThread()); | |
138 | |
139 // The input_handler might have been destroyed at this point. | |
140 if (!input_handler) | |
141 return; | |
142 | |
143 DCHECK(!input_handler_proxy_); | |
144 input_handler_proxy_ = | |
145 make_scoped_ptr(new ui::InputHandlerProxy(input_handler.get(), this)); | |
146 } | |
147 | |
148 void BlimpInputManager::HandleWebInputEventOnCompositorThread( | |
149 const blink::WebInputEvent& input_event) { | |
150 DCHECK(IsCompositorThread()); | |
151 | |
152 // We might not have the input handler proxy anymore. | |
153 if (!input_handler_proxy_) | |
154 return; | |
155 | |
156 ui::InputHandlerProxy::EventDisposition disposition = | |
157 input_handler_proxy_->HandleInputEvent(input_event); | |
158 | |
159 if (disposition == ui::InputHandlerProxy::DID_NOT_HANDLE) { | |
160 main_task_runner_->PostTask( | |
161 FROM_HERE, | |
162 base::Bind(&BlimpInputManager::SendWebInputEvent, | |
163 base::Unretained(this), input_event)); | |
164 } | |
165 } | |
166 | |
167 void BlimpInputManager::SendWebInputEvent( | |
168 const blink::WebInputEvent& input_event) { | |
169 DCHECK(IsMainThread()); | |
170 | |
171 client_->SendWebInputEvent(input_event); | |
172 } | |
173 | |
174 bool BlimpInputManager::IsMainThread() const { | |
175 return main_task_runner_->BelongsToCurrentThread(); | |
176 } | |
177 | |
178 bool BlimpInputManager::IsCompositorThread() const { | |
179 return compositor_task_runner_->BelongsToCurrentThread(); | |
180 } | |
181 | |
182 } // namespace blimp | |
OLD | NEW |