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" | |
7 #include "cc/quads/surface_draw_quad.h" | 8 #include "cc/quads/surface_draw_quad.h" |
8 #include "cc/surfaces/surface_id_allocator.h" | 9 #include "cc/surfaces/surface_id_allocator.h" |
9 #include "cc/surfaces/surface_manager.h" | 10 #include "cc/surfaces/surface_manager.h" |
10 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 11 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
11 #include "content/common/frame_messages.h" | 12 #include "content/common/frame_messages.h" |
12 #include "third_party/WebKit/public/web/WebInputEvent.h" | 13 #include "third_party/WebKit/public/web/WebInputEvent.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 void TransformEventTouchPositions(blink::WebTouchEvent* event, | 17 void TransformEventTouchPositions(blink::WebTouchEvent* event, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 const gfx::Point& point_in_quad_space) { | 84 const gfx::Point& point_in_quad_space) { |
84 auto it = hittest_data_.find(surface_quad->surface_id); | 85 auto it = hittest_data_.find(surface_quad->surface_id); |
85 if (it != hittest_data_.end() && !it->second.ignored_for_hittest) | 86 if (it != hittest_data_.end() && !it->second.ignored_for_hittest) |
86 return true; | 87 return true; |
87 return false; | 88 return false; |
88 } | 89 } |
89 | 90 |
90 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() | 91 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() |
91 : touch_target_(nullptr), | 92 : touch_target_(nullptr), |
92 gesture_target_(nullptr), | 93 gesture_target_(nullptr), |
93 active_touches_(0) {} | 94 active_touches_(0), |
95 number_of_gesture_targets_enqueued_(0), | |
96 number_of_gesture_targets_dequeued_(0), | |
97 last_gesture_event_index_(0), | |
98 last_touch_event_index_(0) { | |
99 for (unsigned i = 0; i < kNumLastEventTypes; ++i) { | |
100 last_gesture_event_types_[i] = blink::WebInputEvent::Undefined; | |
101 last_touch_event_types_[i] = blink::WebInputEvent::Undefined; | |
102 } | |
103 } | |
94 | 104 |
95 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() { | 105 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() { |
96 // We may be destroyed before some of the owners in the map, so we must | 106 // We may be destroyed before some of the owners in the map, so we must |
97 // remove ourself from their observer lists. | 107 // remove ourself from their observer lists. |
98 ClearAllObserverRegistrations(); | 108 ClearAllObserverRegistrations(); |
99 } | 109 } |
100 | 110 |
101 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget( | 111 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget( |
102 RenderWidgetHostViewBase* root_view, | 112 RenderWidgetHostViewBase* root_view, |
103 const gfx::Point& point, | 113 const gfx::Point& point, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 void RenderWidgetHostInputEventRouter::RouteGestureEvent( | 173 void RenderWidgetHostInputEventRouter::RouteGestureEvent( |
164 RenderWidgetHostViewBase* root_view, | 174 RenderWidgetHostViewBase* root_view, |
165 blink::WebGestureEvent* event, | 175 blink::WebGestureEvent* event, |
166 const ui::LatencyInfo& latency) { | 176 const ui::LatencyInfo& latency) { |
167 // We use GestureTapDown to detect the start of a gesture sequence since there | 177 // We use GestureTapDown to detect the start of a gesture sequence since there |
168 // is no WebGestureEvent equivalent for ET_GESTURE_BEGIN. Note that this | 178 // is no WebGestureEvent equivalent for ET_GESTURE_BEGIN. Note that this |
169 // means the GestureFlingCancel that always comes between ET_GESTURE_BEGIN and | 179 // means the GestureFlingCancel that always comes between ET_GESTURE_BEGIN and |
170 // GestureTapDown is sent to the previous target, in case it is still in a | 180 // GestureTapDown is sent to the previous target, in case it is still in a |
171 // fling. | 181 // fling. |
172 if (event->type == blink::WebInputEvent::GestureTapDown) { | 182 if (event->type == blink::WebInputEvent::GestureTapDown) { |
173 DCHECK(!gesture_target_queue_.empty()); | 183 if (gesture_target_queue_.empty()) { |
184 // Collect data to assist debugging https://crbug.com/592319. | |
185 // We'll assume for now if there's no target that we should just ignore | |
186 // the event. | |
187 LOG(ERROR) << "Gesture sequence start detected with no target available."; | |
188 base::debug::DumpWithoutCrashing(); | |
189 return; | |
190 } | |
191 | |
174 const GestureTargetData& data = gesture_target_queue_.front(); | 192 const GestureTargetData& data = gesture_target_queue_.front(); |
175 gesture_target_ = data.target; | 193 gesture_target_ = data.target; |
176 gesture_delta_ = data.delta; | 194 gesture_delta_ = data.delta; |
177 gesture_target_queue_.pop_front(); | 195 gesture_target_queue_.pop_front(); |
196 // Code to assist debugging https://crbug.com/592319. | |
197 number_of_gesture_targets_dequeued_++; | |
178 } | 198 } |
179 | 199 |
200 // Code to assist debugging https://crbug.com/592319. | |
201 last_gesture_event_types_[last_gesture_event_index_] = event->type; | |
202 last_gesture_event_index_ = | |
203 (last_gesture_event_index_ + 1) % kNumLastEventTypes; | |
tdresser
2016/03/09 19:53:45
Based on the code here, isn't last_gesture_event_i
wjmaclean
2016/03/09 21:28:31
Done.
| |
204 | |
180 if (!gesture_target_) | 205 if (!gesture_target_) |
181 return; | 206 return; |
182 | 207 |
183 event->x += gesture_delta_.x(); | 208 event->x += gesture_delta_.x(); |
184 event->y += gesture_delta_.y(); | 209 event->y += gesture_delta_.y(); |
185 gesture_target_->ProcessGestureEvent(*event, latency); | 210 gesture_target_->ProcessGestureEvent(*event, latency); |
186 } | 211 } |
187 | 212 |
188 void RenderWidgetHostInputEventRouter::RouteTouchEvent( | 213 void RenderWidgetHostInputEventRouter::RouteTouchEvent( |
189 RenderWidgetHostViewBase* root_view, | 214 RenderWidgetHostViewBase* root_view, |
190 blink::WebTouchEvent* event, | 215 blink::WebTouchEvent* event, |
191 const ui::LatencyInfo& latency) { | 216 const ui::LatencyInfo& latency) { |
217 // Code to assist debugging https://crbug.com/592319. | |
218 last_touch_event_types_[last_touch_event_index_] = event->type; | |
219 last_touch_event_index_ = | |
220 (last_touch_event_index_ + 1) % kNumLastEventTypes; | |
tdresser
2016/03/09 19:53:45
Looks like this is next_touch_event_index_.
wjmaclean
2016/03/09 21:28:31
Done.
| |
221 | |
192 switch (event->type) { | 222 switch (event->type) { |
193 case blink::WebInputEvent::TouchStart: { | 223 case blink::WebInputEvent::TouchStart: { |
194 if (!active_touches_) { | 224 if (!active_touches_) { |
195 // Since this is the first touch, it defines the target for the rest | 225 // Since this is the first touch, it defines the target for the rest |
196 // of this sequence. | 226 // of this sequence. |
197 DCHECK(!touch_target_); | 227 DCHECK(!touch_target_); |
198 gfx::Point transformed_point; | 228 gfx::Point transformed_point; |
199 gfx::Point original_point(event->touches[0].position.x, | 229 gfx::Point original_point(event->touches[0].position.x, |
200 event->touches[0].position.y); | 230 event->touches[0].position.y); |
201 touch_target_ = | 231 touch_target_ = |
202 FindEventTarget(root_view, original_point, &transformed_point); | 232 FindEventTarget(root_view, original_point, &transformed_point); |
203 | 233 |
204 // TODO(wjmaclean): Instead of just computing a delta, we should extract | 234 // TODO(wjmaclean): Instead of just computing a delta, we should extract |
205 // the complete transform. We assume it doesn't change for the duration | 235 // the complete transform. We assume it doesn't change for the duration |
206 // of the touch sequence, though this could be wrong; a better approach | 236 // of the touch sequence, though this could be wrong; a better approach |
207 // might be to always transform each point to the touch_target_ | 237 // might be to always transform each point to the touch_target_ |
208 // for the duration of the sequence. | 238 // for the duration of the sequence. |
209 touch_delta_ = transformed_point - original_point; | 239 touch_delta_ = transformed_point - original_point; |
210 gesture_target_queue_.emplace_back(touch_target_, touch_delta_); | 240 gesture_target_queue_.emplace_back(touch_target_, touch_delta_); |
241 // Code to assist debugging https://crbug.com/592319. | |
242 number_of_gesture_targets_enqueued_++; | |
211 | 243 |
212 if (!touch_target_) | 244 if (!touch_target_) |
213 return; | 245 return; |
214 } | 246 } |
215 ++active_touches_; | 247 ++active_touches_; |
216 if (touch_target_) { | 248 if (touch_target_) { |
217 TransformEventTouchPositions(event, touch_delta_); | 249 TransformEventTouchPositions(event, touch_delta_); |
218 touch_target_->ProcessTouchEvent(*event, latency); | 250 touch_target_->ProcessTouchEvent(*event, latency); |
219 } | 251 } |
220 break; | 252 break; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId( | 307 if (owner_map_.find(cc::SurfaceIdAllocator::NamespaceForId( |
276 params.surface_id)) == owner_map_.end()) { | 308 params.surface_id)) == owner_map_.end()) { |
277 return; | 309 return; |
278 } | 310 } |
279 HittestData data; | 311 HittestData data; |
280 data.ignored_for_hittest = params.ignored_for_hittest; | 312 data.ignored_for_hittest = params.ignored_for_hittest; |
281 hittest_data_[params.surface_id] = data; | 313 hittest_data_[params.surface_id] = data; |
282 } | 314 } |
283 | 315 |
284 } // namespace content | 316 } // namespace content |
OLD | NEW |