OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/events/gestures/gesture_recognizer_impl.h" | 5 #include "ui/events/gestures/gesture_recognizer_impl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 event.type() == ui::ET_TOUCH_CANCELLED) { | 258 event.type() == ui::ET_TOUCH_CANCELLED) { |
259 touch_id_target_.erase(event.touch_id()); | 259 touch_id_target_.erase(event.touch_id()); |
260 } else if (event.type() == ui::ET_TOUCH_PRESSED) { | 260 } else if (event.type() == ui::ET_TOUCH_PRESSED) { |
261 touch_id_target_[event.touch_id()] = target; | 261 touch_id_target_[event.touch_id()] = target; |
262 if (target) | 262 if (target) |
263 touch_id_target_for_gestures_[event.touch_id()] = target; | 263 touch_id_target_for_gestures_[event.touch_id()] = target; |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 void GestureRecognizerImpl::CancelTouches( | 267 void GestureRecognizerImpl::CancelTouches( |
268 std::vector<std::pair<int, GestureConsumer*> >* touches) { | 268 std::vector<std::pair<int, GestureConsumer*> >* touches) { |
tdresser
2014/08/13 19:57:58
Can't we just look up the GestureProvider here, an
lanwei
2014/08/14 00:38:46
Yes, we can, but I feel if we do this for each tou
tdresser
2014/08/14 12:16:39
An n^2 algorithm when n nearly always 1 or 2 isn't
| |
269 std::map<int, gfx::PointF> map = | |
270 GroupGestureConsumerWithTouchPoints(touches); | |
269 while (!touches->empty()) { | 271 while (!touches->empty()) { |
270 int touch_id = touches->begin()->first; | 272 int touch_id = touches->begin()->first; |
271 GestureConsumer* target = touches->begin()->second; | 273 GestureConsumer* target = touches->begin()->second; |
272 TouchEvent touch_event(ui::ET_TOUCH_CANCELLED, gfx::PointF(0, 0), | 274 gfx::PointF point(0, 0); |
275 if(map.count(touch_id) > 0) { | |
276 point = map[touch_id]; | |
277 } | |
278 TouchEvent touch_event(ui::ET_TOUCH_CANCELLED, point, | |
273 ui::EF_IS_SYNTHESIZED, touch_id, | 279 ui::EF_IS_SYNTHESIZED, touch_id, |
274 ui::EventTimeForNow(), 0.0f, 0.0f, 0.0f, 0.0f); | 280 ui::EventTimeForNow(), 0.0f, 0.0f, 0.0f, 0.0f); |
275 GestureEventHelper* helper = FindDispatchHelperForConsumer(target); | 281 GestureEventHelper* helper = FindDispatchHelperForConsumer(target); |
276 if (helper) | 282 if (helper) |
277 helper->DispatchCancelTouchEvent(&touch_event); | 283 helper->DispatchCancelTouchEvent(&touch_event); |
278 touches->erase(touches->begin()); | 284 touches->erase(touches->begin()); |
279 } | 285 } |
280 } | 286 } |
281 | 287 |
288 std::map<int, gfx::PointF> | |
289 GestureRecognizerImpl::GroupGestureConsumerWithTouchPoints( | |
290 std::vector<std::pair<int, GestureConsumer*> >* touches) { | |
291 std::map<int, gfx::PointF> map; | |
292 std::set<GestureConsumer*> consumerSet; | |
293 for (std::vector<std::pair<int, GestureConsumer*> >::iterator | |
294 it = touches->begin(); it != touches->end(); ++it) { | |
295 consumerSet.insert(it->second); | |
296 } | |
297 for (std::set<GestureConsumer*>::iterator iter = consumerSet.begin(); | |
298 iter != consumerSet.end(); ++iter) { | |
299 std::map<int, gfx::PointF> subMap = MapTouchIDWithPointLocation(*iter); | |
300 map.insert(subMap.begin(), subMap.end()); | |
301 } | |
302 return map; | |
303 } | |
304 | |
305 std::map<int, gfx::PointF> GestureRecognizerImpl::MapTouchIDWithPointLocation( | |
306 GestureConsumer* consumer) { | |
307 std::map<int, gfx::PointF> map; | |
308 if (use_unified_gesture_detector_) { | |
309 GestureProviderAura* gesture_provider = | |
310 consumer_gesture_provider_[consumer]; | |
311 const MotionEventAura& pointer_state = gesture_provider->pointer_state(); | |
312 for (size_t i = 0; i < pointer_state.GetPointerCount(); ++i) { | |
313 gfx::PointF point(pointer_state.GetX(i), pointer_state.GetY(i)); | |
314 map[pointer_state.GetPointerId(i)] = point; | |
315 } | |
316 } | |
317 return map; | |
318 } | |
319 | |
282 void GestureRecognizerImpl::DispatchGestureEvent(GestureEvent* event) { | 320 void GestureRecognizerImpl::DispatchGestureEvent(GestureEvent* event) { |
283 GestureConsumer* consumer = GetTargetForGestureEvent(*event); | 321 GestureConsumer* consumer = GetTargetForGestureEvent(*event); |
284 if (consumer) { | 322 if (consumer) { |
285 GestureEventHelper* helper = FindDispatchHelperForConsumer(consumer); | 323 GestureEventHelper* helper = FindDispatchHelperForConsumer(consumer); |
286 if (helper) | 324 if (helper) |
287 helper->DispatchGestureEvent(event); | 325 helper->DispatchGestureEvent(event); |
288 } | 326 } |
289 } | 327 } |
290 | 328 |
291 bool GestureRecognizerImpl::ProcessTouchEventPreDispatch( | 329 bool GestureRecognizerImpl::ProcessTouchEventPreDispatch( |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 std::vector<GestureEventHelper*>::iterator it; | 458 std::vector<GestureEventHelper*>::iterator it; |
421 for (it = helpers.begin(); it != helpers.end(); ++it) | 459 for (it = helpers.begin(); it != helpers.end(); ++it) |
422 gesture_recognizer->AddGestureEventHelper(*it); | 460 gesture_recognizer->AddGestureEventHelper(*it); |
423 | 461 |
424 helpers.clear(); | 462 helpers.clear(); |
425 g_gesture_recognizer_instance = | 463 g_gesture_recognizer_instance = |
426 static_cast<GestureRecognizerImpl*>(gesture_recognizer); | 464 static_cast<GestureRecognizerImpl*>(gesture_recognizer); |
427 } | 465 } |
428 | 466 |
429 } // namespace ui | 467 } // namespace ui |
OLD | NEW |