diff options
author | tdresser@chromium.org <tdresser@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-17 19:25:25 +0000 |
---|---|---|
committer | tdresser@chromium.org <tdresser@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-17 19:25:25 +0000 |
commit | cc1fad52a7d5f4317d63404022a251724e13f667 (patch) | |
tree | a64da9f22c64fdd6c000d01983049e7fd029cab0 /ui/base | |
parent | a58c97e519a34d9d48d6154f37e7d44346ada85e (diff) | |
download | chromium_src-cc1fad52a7d5f4317d63404022a251724e13f667.zip chromium_src-cc1fad52a7d5f4317d63404022a251724e13f667.tar.gz chromium_src-cc1fad52a7d5f4317d63404022a251724e13f667.tar.bz2 |
On touch capture, cancel non-captured touches.
When a touch capture occurs, any touches locked to other windows are cancelled.
These touches are then locked to a GestureConsumer which ignores all
further events, until the touch is released.
BUG=123211
TEST=WindowTest.TouchCaptureCancelsOtherTouches, TouchCaptureDoesntCancelCapturedTouches
Review URL: http://codereview.chromium.org/10038030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132619 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r-- | ui/base/gestures/gesture_recognizer.h | 10 | ||||
-rw-r--r-- | ui/base/gestures/gesture_recognizer_impl.cc | 35 | ||||
-rw-r--r-- | ui/base/gestures/gesture_recognizer_impl.h | 16 | ||||
-rw-r--r-- | ui/base/gestures/gesture_sequence.cc | 1 | ||||
-rw-r--r-- | ui/base/gestures/gesture_types.h | 23 |
5 files changed, 71 insertions, 14 deletions
diff --git a/ui/base/gestures/gesture_recognizer.h b/ui/base/gestures/gesture_recognizer.h index 541d823..84085e5 100644 --- a/ui/base/gestures/gesture_recognizer.h +++ b/ui/base/gestures/gesture_recognizer.h @@ -48,10 +48,9 @@ class UI_EXPORT GestureRecognizer { virtual void FlushTouchQueue(GestureConsumer* consumer) = 0; // Return the window which should handle this TouchEvent, in the case where - // the touch is already associated with a target, or the touch occurs - // near another touch. + // the touch is already associated with a target. // Otherwise, returns null. - virtual GestureConsumer* GetTargetForTouchEvent(TouchEvent* event) = 0; + virtual GestureConsumer* GetTouchLockedTarget(TouchEvent* event) = 0; // Return the window which should handle this GestureEvent. virtual GestureConsumer* GetTargetForGestureEvent(GestureEvent* event) = 0; @@ -60,6 +59,11 @@ class UI_EXPORT GestureRecognizer { // GestureConfiguration::max_separation_for_gesture_touches_in_pixels, // of |location|, returns the target of the nearest active touch. virtual GestureConsumer* GetTargetForLocation(const gfx::Point& location) = 0; + + // For each touch on windows other than |capturer|, a cancel event + // is fired. These touches are then ignored until they are released + // and pressed again. + virtual void CancelNonCapturedTouches(GestureConsumer* capturer) = 0; }; } // namespace ui diff --git a/ui/base/gestures/gesture_recognizer_impl.cc b/ui/base/gestures/gesture_recognizer_impl.cc index 2b9269f..ead6aa0 100644 --- a/ui/base/gestures/gesture_recognizer_impl.cc +++ b/ui/base/gestures/gesture_recognizer_impl.cc @@ -70,6 +70,15 @@ class CancelledTouchEvent : public ui::TouchEvent { DISALLOW_COPY_AND_ASSIGN(CancelledTouchEvent); }; +// Touches which are cancelled by a touch capture are routed to a +// GestureEventIgnorer, which ignores them. +class GestureConsumerIgnorer : public ui::GestureConsumer { + public: + GestureConsumerIgnorer() + : GestureConsumer(true) { + } +}; + } // namespace namespace ui { @@ -79,17 +88,15 @@ namespace ui { GestureRecognizerImpl::GestureRecognizerImpl(GestureEventHelper* helper) : helper_(helper) { + gesture_consumer_ignorer_.reset(new GestureConsumerIgnorer()); } GestureRecognizerImpl::~GestureRecognizerImpl() { } -GestureConsumer* GestureRecognizerImpl::GetTargetForTouchEvent( - TouchEvent* event) { - GestureConsumer* target = touch_id_target_[event->GetTouchId()]; - if (!target) - target = GetTargetForLocation(event->GetLocation()); - return target; +GestureConsumer* GestureRecognizerImpl::GetTouchLockedTarget( + TouchEvent* event) { + return touch_id_target_[event->GetTouchId()]; } GestureConsumer* GestureRecognizerImpl::GetTargetForGestureEvent( @@ -129,6 +136,22 @@ GestureConsumer* GestureRecognizerImpl::GetTargetForLocation( return NULL; } +void GestureRecognizerImpl::CancelNonCapturedTouches( + GestureConsumer* capturer) { + std::map<int, GestureConsumer*>::iterator i; + // Fire touch cancels, and target touch_ids to gesture_consumer_ignorer. + for (i = touch_id_target_.begin(); i != touch_id_target_.end(); ++i) { + if (capturer != i->second) { + scoped_ptr<TouchEvent> touchEvent(helper_->CreateTouchEvent( + ui::ET_TOUCH_CANCELLED, gfx::Point(0, 0), + i->first, + base::Time::NowFromSystemTime() - base::Time())); + helper_->DispatchCancelTouchEvent(touchEvent.get()); + touch_id_target_[i->first] = gesture_consumer_ignorer_.get(); + } + } +} + //////////////////////////////////////////////////////////////////////////////// // GestureRecognizerImpl, protected: diff --git a/ui/base/gestures/gesture_recognizer_impl.h b/ui/base/gestures/gesture_recognizer_impl.h index cb91f33..9c659eb 100644 --- a/ui/base/gestures/gesture_recognizer_impl.h +++ b/ui/base/gestures/gesture_recognizer_impl.h @@ -30,11 +30,8 @@ class UI_EXPORT GestureRecognizerImpl : public GestureRecognizer { virtual ~GestureRecognizerImpl(); // Checks if this finger is already down, if so, returns the current target. - // Otherwise, if the finger is within - // GestureConfiguration::max_separation_for_gesture_touches_in_pixels - // of another touch, returns the target of the closest touch. - // If there is no nearby touch, return null. - virtual GestureConsumer* GetTargetForTouchEvent(TouchEvent* event) OVERRIDE; + // Otherwise, returns NULL. + virtual GestureConsumer* GetTouchLockedTarget(TouchEvent* event) OVERRIDE; // Returns the target of the touches the gesture is composed of. virtual GestureConsumer* GetTargetForGestureEvent( @@ -43,6 +40,11 @@ class UI_EXPORT GestureRecognizerImpl : public GestureRecognizer { virtual GestureConsumer* GetTargetForLocation( const gfx::Point& location) OVERRIDE; + // Each touch which isn't targeted to capturer results in a touch + // cancel event. These touches are then targeted to + // gesture_consumer_ignorer. + virtual void CancelNonCapturedTouches(GestureConsumer* capturer) OVERRIDE; + protected: virtual GestureSequence* CreateSequence(GestureEventHelper* helper); virtual GestureSequence* GetGestureSequenceForConsumer(GestureConsumer* c); @@ -70,6 +72,10 @@ class UI_EXPORT GestureRecognizerImpl : public GestureRecognizer { // removed. std::map<int, GestureConsumer*> touch_id_target_; std::map<int, GestureConsumer*> touch_id_target_for_gestures_; + + // Touches cancelled by touch capture are routed to the + // gesture_consumer_ignorer_. + scoped_ptr<GestureConsumer> gesture_consumer_ignorer_; GestureEventHelper* helper_; DISALLOW_COPY_AND_ASSIGN(GestureRecognizerImpl); diff --git a/ui/base/gestures/gesture_sequence.cc b/ui/base/gestures/gesture_sequence.cc index 321211b..fcab299 100644 --- a/ui/base/gestures/gesture_sequence.cc +++ b/ui/base/gestures/gesture_sequence.cc @@ -314,6 +314,7 @@ void GestureSequence::Reset() { set_state(GS_NO_GESTURE); for (int i = 0; i < kMaxGesturePoints; ++i) points_[i].Reset(); + point_count_ = 0; } //////////////////////////////////////////////////////////////////////////////// diff --git a/ui/base/gestures/gesture_types.h b/ui/base/gestures/gesture_types.h index 27e04d8..b857171 100644 --- a/ui/base/gestures/gesture_types.h +++ b/ui/base/gestures/gesture_types.h @@ -41,12 +41,29 @@ class UI_EXPORT GestureEvent { // An abstract type for consumers of gesture-events created by the // gesture-recognizer. class UI_EXPORT GestureConsumer { + public: + GestureConsumer() + : ignores_events_(false) { + } + + explicit GestureConsumer(bool ignores_events) + : ignores_events_(ignores_events) { + } + + virtual ~GestureConsumer() {} + bool ignores_events() { return ignores_events_; } + + private: + const bool ignores_events_; }; // GestureEventHelper creates implementation-specific gesture events and // can dispatch them. class UI_EXPORT GestureEventHelper { public: + virtual ~GestureEventHelper() { + } + // |flags| is ui::EventFlags. The meaning of |param_first| and |param_second| // depends on the specific gesture type (|type|). virtual GestureEvent* CreateGestureEvent(EventType type, @@ -57,7 +74,13 @@ class UI_EXPORT GestureEventHelper { float param_second, unsigned int touch_id_bitfield) = 0; + virtual TouchEvent* CreateTouchEvent(EventType type, + const gfx::Point& location, + int touch_id, + base::TimeDelta time_stamp) = 0; + virtual bool DispatchLongPressGestureEvent(GestureEvent* event) = 0; + virtual bool DispatchCancelTouchEvent(TouchEvent* event) = 0; }; } // namespace ui |