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..28b07c952fbe24136cf891ac87872f9a31b10459 100644 |
| --- a/ui/events/gestures/gesture_recognizer_impl.cc |
| +++ b/ui/events/gestures/gesture_recognizer_impl.cc |
| @@ -165,18 +165,18 @@ void GestureRecognizerImpl::TransferEventsTo(GestureConsumer* current_consumer, |
| // from |touch_id_target_| in |CleanupStateForConsumer()|). So create a list |
| // of the touch-ids that need to be cancelled, and dispatch the cancel events |
| // for them at the end. |
| - std::vector<std::pair<int, GestureConsumer*> > ids; |
| + std::set<GestureConsumer*> consumers; |
|
tdresser
2014/08/15 14:22:05
Just use a vector, set has a lot more overhead.
lanwei
2014/08/27 03:54:03
Done.
|
| for (TouchIdToConsumerMap::iterator i = touch_id_target_.begin(); |
| - i != touch_id_target_.end(); ++i) { |
| + i != touch_id_target_.end(); ++i) { |
| if (i->second && i->second != new_consumer && |
| - (i->second != current_consumer || new_consumer == NULL) && |
| - i->second) { |
| - ids.push_back(std::make_pair(i->first, i->second)); |
| + (i->second != current_consumer || new_consumer == NULL)) { |
| + consumers.insert(i->second); |
| } |
| } |
| - |
| - CancelTouches(&ids); |
| - |
| + for (std::set<GestureConsumer*>::iterator iter = consumers.begin(); |
| + iter != consumers.end(); ++iter) { |
| + CancelActiveTouches(*iter); |
| + } |
| // Transfer events from |current_consumer| to |new_consumer|. |
| if (current_consumer && new_consumer) { |
| TransferTouchIdToConsumerMap(current_consumer, new_consumer, |
| @@ -210,14 +210,26 @@ bool GestureRecognizerImpl::GetLastTouchPointForTarget( |
| } |
| bool GestureRecognizerImpl::CancelActiveTouches(GestureConsumer* consumer) { |
| - std::vector<std::pair<int, GestureConsumer*> > ids; |
| - for (TouchIdToConsumerMap::const_iterator i = touch_id_target_.begin(); |
| - i != touch_id_target_.end(); ++i) { |
| - if (i->second == consumer) |
| - ids.push_back(std::make_pair(i->first, i->second)); |
| + bool cancelled_touch = false; |
| + if (use_unified_gesture_detector_) { |
| + if(consumer_gesture_provider_.count(consumer) == 0) |
| + return false; |
| + const MotionEventAura& pointer_state = |
| + consumer_gesture_provider_[consumer]->pointer_state(); |
| + size_t count = pointer_state.GetPointerCount(); |
| + for (size_t i = 0; i < count; ++i) { |
| + gfx::PointF point(pointer_state.GetX(i), pointer_state.GetY(i)); |
| + TouchEvent touch_event(ui::ET_TOUCH_CANCELLED, point, |
| + ui::EF_IS_SYNTHESIZED, |
| + pointer_state.GetPointerId(i), |
| + ui::EventTimeForNow(), |
| + 0.0f, 0.0f, 0.0f, 0.0f); |
| + GestureEventHelper* helper = FindDispatchHelperForConsumer(consumer); |
| + if (helper) |
| + helper->DispatchCancelTouchEvent(&touch_event); |
| + cancelled_touch = true; |
| + } |
| } |
| - bool cancelled_touch = !ids.empty(); |
| - CancelTouches(&ids); |
| return cancelled_touch; |
| } |
| @@ -264,21 +276,6 @@ void GestureRecognizerImpl::SetupTargets(const TouchEvent& event, |
| } |
| } |
| -void GestureRecognizerImpl::CancelTouches( |
| - std::vector<std::pair<int, GestureConsumer*> >* 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), |
| - ui::EF_IS_SYNTHESIZED, touch_id, |
| - ui::EventTimeForNow(), 0.0f, 0.0f, 0.0f, 0.0f); |
| - GestureEventHelper* helper = FindDispatchHelperForConsumer(target); |
| - if (helper) |
| - helper->DispatchCancelTouchEvent(&touch_event); |
| - touches->erase(touches->begin()); |
| - } |
| -} |
| - |
| void GestureRecognizerImpl::DispatchGestureEvent(GestureEvent* event) { |
| GestureConsumer* consumer = GetTargetForGestureEvent(*event); |
| if (consumer) { |