OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 5 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
6 | 6 |
7 #include "base/debug/dump_without_crashing.h" | |
8 #include "cc/quads/surface_draw_quad.h" | 7 #include "cc/quads/surface_draw_quad.h" |
9 #include "cc/surfaces/surface_id_allocator.h" | 8 #include "cc/surfaces/surface_id_allocator.h" |
10 #include "cc/surfaces/surface_manager.h" | 9 #include "cc/surfaces/surface_manager.h" |
11 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 10 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
12 #include "content/common/frame_messages.h" | 11 #include "content/common/frame_messages.h" |
13 #include "third_party/WebKit/public/web/WebInputEvent.h" | 12 #include "third_party/WebKit/public/web/WebInputEvent.h" |
14 | 13 |
15 namespace { | 14 namespace { |
16 | 15 |
17 void TransformEventTouchPositions(blink::WebTouchEvent* event, | 16 void TransformEventTouchPositions(blink::WebTouchEvent* event, |
18 const gfx::Vector2d& delta) { | 17 const gfx::Vector2d& delta) { |
19 for (unsigned i = 0; i < event->touchesLength; ++i) { | 18 for (unsigned i = 0; i < event->touchesLength; ++i) { |
20 event->touches[i].position.x += delta.x(); | 19 event->touches[i].position.x += delta.x(); |
21 event->touches[i].position.y += delta.y(); | 20 event->touches[i].position.y += delta.y(); |
22 } | 21 } |
23 } | 22 } |
24 | 23 |
25 } // anonymous namespace | 24 } // anonymous namespace |
26 | 25 |
27 namespace content { | 26 namespace content { |
28 | 27 |
29 // Code to assist debugging https://crbug.com/592319. | |
30 RenderWidgetHostInputEventRouter::GestureQueueDebugData::GestureQueueDebugData() | |
31 : number_of_gesture_targets_enqueued(0), | |
32 number_of_gesture_targets_dequeued(0), | |
33 next_gesture_event_index(0), | |
34 next_touch_event_index(0) { | |
35 for (unsigned i = 0; i < kNumLastEventTypes; ++i) { | |
36 last_gesture_event_types[i] = blink::WebInputEvent::Undefined; | |
37 last_touch_event_types[i] = blink::WebInputEvent::Undefined; | |
38 } | |
39 } | |
40 | |
41 void RenderWidgetHostInputEventRouter::OnRenderWidgetHostViewBaseDestroyed( | 28 void RenderWidgetHostInputEventRouter::OnRenderWidgetHostViewBaseDestroyed( |
42 RenderWidgetHostViewBase* view) { | 29 RenderWidgetHostViewBase* view) { |
43 view->RemoveObserver(this); | 30 view->RemoveObserver(this); |
44 | 31 |
45 // Remove this view from the owner_map. | 32 // Remove this view from the owner_map. |
46 for (auto entry : owner_map_) { | 33 for (auto entry : owner_map_) { |
47 if (entry.second == view) { | 34 if (entry.second == view) { |
48 owner_map_.erase(entry.first); | 35 owner_map_.erase(entry.first); |
49 // There will only be one instance of a particular view in the map. | 36 // There will only be one instance of a particular view in the map. |
50 break; | 37 break; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 RenderWidgetHostViewBase* root_view, | 164 RenderWidgetHostViewBase* root_view, |
178 blink::WebGestureEvent* event, | 165 blink::WebGestureEvent* event, |
179 const ui::LatencyInfo& latency) { | 166 const ui::LatencyInfo& latency) { |
180 // We use GestureTapDown to detect the start of a gesture sequence since there | 167 // We use GestureTapDown to detect the start of a gesture sequence since there |
181 // is no WebGestureEvent equivalent for ET_GESTURE_BEGIN. Note that this | 168 // is no WebGestureEvent equivalent for ET_GESTURE_BEGIN. Note that this |
182 // means the GestureFlingCancel that always comes between ET_GESTURE_BEGIN and | 169 // means the GestureFlingCancel that always comes between ET_GESTURE_BEGIN and |
183 // GestureTapDown is sent to the previous target, in case it is still in a | 170 // GestureTapDown is sent to the previous target, in case it is still in a |
184 // fling. | 171 // fling. |
185 if (event->type == blink::WebInputEvent::GestureTapDown) { | 172 if (event->type == blink::WebInputEvent::GestureTapDown) { |
186 if (gesture_target_queue_.empty()) { | 173 if (gesture_target_queue_.empty()) { |
187 // Collect data to assist debugging https://crbug.com/592319. | |
188 // We'll assume for now if there's no target that we should just ignore | |
189 // the event. | |
190 LOG(ERROR) << "Gesture sequence start detected with no target available."; | 174 LOG(ERROR) << "Gesture sequence start detected with no target available."; |
191 base::debug::DumpWithoutCrashing(); | 175 // Ignore this gesture sequence as no target is available. |
| 176 // TODO(wjmaclean): this only happens on Windows, and should not happen. |
| 177 // https://crbug.com/595422 |
| 178 gesture_target_ = nullptr; |
192 return; | 179 return; |
193 } | 180 } |
194 | 181 |
195 const GestureTargetData& data = gesture_target_queue_.front(); | 182 const GestureTargetData& data = gesture_target_queue_.front(); |
196 gesture_target_ = data.target; | 183 gesture_target_ = data.target; |
197 gesture_delta_ = data.delta; | 184 gesture_delta_ = data.delta; |
198 gesture_target_queue_.pop_front(); | 185 gesture_target_queue_.pop_front(); |
199 // Code to assist debugging https://crbug.com/592319. | |
200 debug_data_.number_of_gesture_targets_dequeued++; | |
201 } | 186 } |
202 | 187 |
203 // Code to assist debugging https://crbug.com/592319. | |
204 debug_data_.last_gesture_event_types[debug_data_.next_gesture_event_index] = | |
205 event->type; | |
206 debug_data_.next_gesture_event_index = | |
207 (debug_data_.next_gesture_event_index + 1) % kNumLastEventTypes; | |
208 | |
209 if (!gesture_target_) | 188 if (!gesture_target_) |
210 return; | 189 return; |
211 | 190 |
212 event->x += gesture_delta_.x(); | 191 event->x += gesture_delta_.x(); |
213 event->y += gesture_delta_.y(); | 192 event->y += gesture_delta_.y(); |
214 gesture_target_->ProcessGestureEvent(*event, latency); | 193 gesture_target_->ProcessGestureEvent(*event, latency); |
215 } | 194 } |
216 | 195 |
217 void RenderWidgetHostInputEventRouter::RouteTouchEvent( | 196 void RenderWidgetHostInputEventRouter::RouteTouchEvent( |
218 RenderWidgetHostViewBase* root_view, | 197 RenderWidgetHostViewBase* root_view, |
219 blink::WebTouchEvent* event, | 198 blink::WebTouchEvent* event, |
220 const ui::LatencyInfo& latency) { | 199 const ui::LatencyInfo& latency) { |
221 // Code to assist debugging https://crbug.com/592319. | |
222 debug_data_.last_touch_event_types[debug_data_.next_touch_event_index] = | |
223 event->type; | |
224 debug_data_.next_touch_event_index = | |
225 (debug_data_.next_touch_event_index + 1) % kNumLastEventTypes; | |
226 | |
227 switch (event->type) { | 200 switch (event->type) { |
228 case blink::WebInputEvent::TouchStart: { | 201 case blink::WebInputEvent::TouchStart: { |
229 if (!active_touches_) { | 202 if (!active_touches_) { |
230 // Since this is the first touch, it defines the target for the rest | 203 // Since this is the first touch, it defines the target for the rest |
231 // of this sequence. | 204 // of this sequence. |
232 DCHECK(!touch_target_); | 205 DCHECK(!touch_target_); |
233 gfx::Point transformed_point; | 206 gfx::Point transformed_point; |
234 gfx::Point original_point(event->touches[0].position.x, | 207 gfx::Point original_point(event->touches[0].position.x, |
235 event->touches[0].position.y); | 208 event->touches[0].position.y); |
236 touch_target_ = | 209 touch_target_ = |
237 FindEventTarget(root_view, original_point, &transformed_point); | 210 FindEventTarget(root_view, original_point, &transformed_point); |
238 | 211 |
239 // TODO(wjmaclean): Instead of just computing a delta, we should extract | 212 // TODO(wjmaclean): Instead of just computing a delta, we should extract |
240 // the complete transform. We assume it doesn't change for the duration | 213 // the complete transform. We assume it doesn't change for the duration |
241 // of the touch sequence, though this could be wrong; a better approach | 214 // of the touch sequence, though this could be wrong; a better approach |
242 // might be to always transform each point to the touch_target_ | 215 // might be to always transform each point to the touch_target_ |
243 // for the duration of the sequence. | 216 // for the duration of the sequence. |
244 touch_delta_ = transformed_point - original_point; | 217 touch_delta_ = transformed_point - original_point; |
245 gesture_target_queue_.emplace_back(touch_target_, touch_delta_); | 218 gesture_target_queue_.emplace_back(touch_target_, touch_delta_); |
246 // Code to assist debugging https://crbug.com/592319. | |
247 debug_data_.number_of_gesture_targets_enqueued++; | |
248 | 219 |
249 if (!touch_target_) | 220 if (!touch_target_) |
250 return; | 221 return; |
251 } | 222 } |
252 ++active_touches_; | 223 ++active_touches_; |
253 if (touch_target_) { | 224 if (touch_target_) { |
254 TransformEventTouchPositions(event, touch_delta_); | 225 TransformEventTouchPositions(event, touch_delta_); |
255 touch_target_->ProcessTouchEvent(*event, latency); | 226 touch_target_->ProcessTouchEvent(*event, latency); |
256 } | 227 } |
257 break; | 228 break; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId( | 283 if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId( |
313 params.surface_id)) == owner_map_.end()) { | 284 params.surface_id)) == owner_map_.end()) { |
314 return; | 285 return; |
315 } | 286 } |
316 HittestData data; | 287 HittestData data; |
317 data.ignored_for_hittest = params.ignored_for_hittest; | 288 data.ignored_for_hittest = params.ignored_for_hittest; |
318 hittest_data_[params.surface_id] = data; | 289 hittest_data_[params.surface_id] = data; |
319 } | 290 } |
320 | 291 |
321 } // namespace content | 292 } // namespace content |
OLD | NEW |