Chromium Code Reviews| Index: ui/events/gestures/gesture_recognizer_impl.cc |
| diff --git a/ui/events/gestures/gesture_recognizer_impl.cc b/ui/events/gestures/gesture_recognizer_impl.cc |
| index 099d29f0112973af828b491cf255fe71110afd45..2c5ec7e77c1f6a2bbc98008f94fb999ea126c6a8 100644 |
| --- a/ui/events/gestures/gesture_recognizer_impl.cc |
| +++ b/ui/events/gestures/gesture_recognizer_impl.cc |
| @@ -266,10 +266,16 @@ void GestureRecognizerImpl::SetupTargets(const TouchEvent& event, |
| void GestureRecognizerImpl::CancelTouches( |
| 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
|
| + std::map<int, gfx::PointF> map = |
| + GroupGestureConsumerWithTouchPoints(touches); |
| while (!touches->empty()) { |
| int touch_id = touches->begin()->first; |
| GestureConsumer* target = touches->begin()->second; |
| - TouchEvent touch_event(ui::ET_TOUCH_CANCELLED, gfx::PointF(0, 0), |
| + gfx::PointF point(0, 0); |
| + if(map.count(touch_id) > 0) { |
| + point = map[touch_id]; |
| + } |
| + TouchEvent touch_event(ui::ET_TOUCH_CANCELLED, point, |
| ui::EF_IS_SYNTHESIZED, touch_id, |
| ui::EventTimeForNow(), 0.0f, 0.0f, 0.0f, 0.0f); |
| GestureEventHelper* helper = FindDispatchHelperForConsumer(target); |
| @@ -279,6 +285,38 @@ void GestureRecognizerImpl::CancelTouches( |
| } |
| } |
| +std::map<int, gfx::PointF> |
| +GestureRecognizerImpl::GroupGestureConsumerWithTouchPoints( |
| + std::vector<std::pair<int, GestureConsumer*> >* touches) { |
| + std::map<int, gfx::PointF> map; |
| + std::set<GestureConsumer*> consumerSet; |
| + for (std::vector<std::pair<int, GestureConsumer*> >::iterator |
| + it = touches->begin(); it != touches->end(); ++it) { |
| + consumerSet.insert(it->second); |
| + } |
| + for (std::set<GestureConsumer*>::iterator iter = consumerSet.begin(); |
| + iter != consumerSet.end(); ++iter) { |
| + std::map<int, gfx::PointF> subMap = MapTouchIDWithPointLocation(*iter); |
| + map.insert(subMap.begin(), subMap.end()); |
| + } |
| + return map; |
| +} |
| + |
| +std::map<int, gfx::PointF> GestureRecognizerImpl::MapTouchIDWithPointLocation( |
| + GestureConsumer* consumer) { |
| + std::map<int, gfx::PointF> map; |
| + if (use_unified_gesture_detector_) { |
| + GestureProviderAura* gesture_provider = |
| + consumer_gesture_provider_[consumer]; |
| + const MotionEventAura& pointer_state = gesture_provider->pointer_state(); |
| + for (size_t i = 0; i < pointer_state.GetPointerCount(); ++i) { |
| + gfx::PointF point(pointer_state.GetX(i), pointer_state.GetY(i)); |
| + map[pointer_state.GetPointerId(i)] = point; |
| + } |
| + } |
| + return map; |
| +} |
| + |
| void GestureRecognizerImpl::DispatchGestureEvent(GestureEvent* event) { |
| GestureConsumer* consumer = GetTargetForGestureEvent(*event); |
| if (consumer) { |