summaryrefslogtreecommitdiffstats
path: root/ui/events/gestures/gesture_recognizer_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ui/events/gestures/gesture_recognizer_impl.cc')
-rw-r--r--ui/events/gestures/gesture_recognizer_impl.cc72
1 files changed, 63 insertions, 9 deletions
diff --git a/ui/events/gestures/gesture_recognizer_impl.cc b/ui/events/gestures/gesture_recognizer_impl.cc
index a472a0c..3e1d02a 100644
--- a/ui/events/gestures/gesture_recognizer_impl.cc
+++ b/ui/events/gestures/gesture_recognizer_impl.cc
@@ -99,8 +99,7 @@ void TransferTouchIdToConsumerMap(
////////////////////////////////////////////////////////////////////////////////
// GestureRecognizerImpl, public:
-GestureRecognizerImpl::GestureRecognizerImpl(GestureEventHelper* helper)
- : helper_(helper) {
+GestureRecognizerImpl::GestureRecognizerImpl() {
gesture_consumer_ignorer_.reset(new GestureConsumerIgnorer());
}
@@ -159,13 +158,15 @@ void GestureRecognizerImpl::TransferEventsTo(GestureConsumer* current_consumer,
// Don't send a cancel to |current_consumer|, unless |new_consumer| is NULL.
for (TouchIdToConsumerMap::iterator i = touch_id_target_.begin();
i != touch_id_target_.end(); ++i) {
- if (i->second != new_consumer &&
+ if (i->second && i->second != new_consumer &&
(i->second != current_consumer || new_consumer == NULL) &&
i->second != gesture_consumer_ignorer_.get()) {
TouchEvent touch_event(ui::ET_TOUCH_CANCELLED, gfx::Point(0, 0),
ui::EF_IS_SYNTHESIZED, i->first,
ui::EventTimeForNow(), 0.0f, 0.0f, 0.0f, 0.0f);
- helper_->DispatchCancelTouchEvent(&touch_event);
+ GestureEventHelper* helper = FindDispatchHelperForConsumer(i->second);
+ if (helper)
+ helper->DispatchCancelTouchEvent(&touch_event);
DCHECK_EQ(gesture_consumer_ignorer_.get(), i->second);
}
}
@@ -194,8 +195,8 @@ bool GestureRecognizerImpl::GetLastTouchPointForTarget(
// GestureRecognizerImpl, protected:
GestureSequence* GestureRecognizerImpl::CreateSequence(
- GestureEventHelper* helper) {
- return new GestureSequence(helper);
+ GestureSequenceDelegate* delegate) {
+ return new GestureSequence(delegate);
}
////////////////////////////////////////////////////////////////////////////////
@@ -205,7 +206,7 @@ GestureSequence* GestureRecognizerImpl::GetGestureSequenceForConsumer(
GestureConsumer* consumer) {
GestureSequence* gesture_sequence = consumer_sequence_[consumer];
if (!gesture_sequence) {
- gesture_sequence = CreateSequence(helper_);
+ gesture_sequence = CreateSequence(this);
consumer_sequence_[consumer] = gesture_sequence;
}
return gesture_sequence;
@@ -243,9 +244,62 @@ void GestureRecognizerImpl::CleanupStateForConsumer(GestureConsumer* consumer) {
RemoveConsumerFromMap(consumer, &touch_id_target_for_gestures_);
}
+void GestureRecognizerImpl::AddGestureEventHelper(GestureEventHelper* helper) {
+ helpers_.push_back(helper);
+}
+
+void GestureRecognizerImpl::RemoveGestureEventHelper(
+ GestureEventHelper* helper) {
+ std::vector<GestureEventHelper*>::iterator it = std::find(helpers_.begin(),
+ helpers_.end(), helper);
+ if (it != helpers_.end())
+ helpers_.erase(it);
+}
+
+void GestureRecognizerImpl::DispatchLongPressGestureEvent(GestureEvent* event) {
+ GestureConsumer* consumer = GetTargetForGestureEvent(event);
+ if (consumer) {
+ GestureEventHelper* helper = FindDispatchHelperForConsumer(consumer);
+ if (helper)
+ helper->DispatchLongPressGestureEvent(event);
+ }
+}
+
+GestureEventHelper* GestureRecognizerImpl::FindDispatchHelperForConsumer(
+ GestureConsumer* consumer) {
+ std::vector<GestureEventHelper*>::iterator it;
+ for (it = helpers_.begin(); it != helpers_.end(); ++it) {
+ if ((*it)->CanDispatchToConsumer(consumer))
+ return (*it);
+ }
+ return NULL;
+}
+
// GestureRecognizer, static
-GestureRecognizer* GestureRecognizer::Create(GestureEventHelper* helper) {
- return new GestureRecognizerImpl(helper);
+GestureRecognizer* GestureRecognizer::Create() {
+ return new GestureRecognizerImpl();
+}
+
+static GestureRecognizerImpl* g_gesture_recognizer_instance = NULL;
+
+// GestureRecognizer, static
+GestureRecognizer* GestureRecognizer::Get() {
+ if (!g_gesture_recognizer_instance)
+ g_gesture_recognizer_instance = new GestureRecognizerImpl();
+ return g_gesture_recognizer_instance;
+}
+
+void SetGestureRecognizerForTesting(GestureRecognizer* gesture_recognizer) {
+ // Transfer helpers to the new GR.
+ std::vector<GestureEventHelper*>& helpers =
+ g_gesture_recognizer_instance->helpers();
+ std::vector<GestureEventHelper*>::iterator it;
+ for (it = helpers.begin(); it != helpers.end(); ++it)
+ gesture_recognizer->AddGestureEventHelper(*it);
+
+ helpers.clear();
+ g_gesture_recognizer_instance =
+ static_cast<GestureRecognizerImpl*>(gesture_recognizer);
}
} // namespace ui