diff options
author | tdresser@chromium.org <tdresser@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-10 19:52:57 +0000 |
---|---|---|
committer | tdresser@chromium.org <tdresser@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-10 19:52:57 +0000 |
commit | 45796c6f11586c40763b6b5bd6d38773a332ecd5 (patch) | |
tree | b6947c32696730408a71d796ac7fabf9513e76ef /ui/events | |
parent | c55c2571fd0f9a55de313cc6fee44437f5fa264b (diff) | |
download | chromium_src-45796c6f11586c40763b6b5bd6d38773a332ecd5.zip chromium_src-45796c6f11586c40763b6b5bd6d38773a332ecd5.tar.gz chromium_src-45796c6f11586c40763b6b5bd6d38773a332ecd5.tar.bz2 |
Target touches to the correct display.
ui::TouchEvents now know the id of their source device.
The target of a touch can't be effected by a touch on another display.
Relanding https://codereview.chromium.org/103173004/, after it was
reverted https://codereview.chromium.org/103173004. When ensuring that
the GR wasn't reused between tests, I had neglected to delete the old
GR.
BUG=315651
TEST=GestureRecognizerTest.GestureEventTouchLockIgnoresOtherScreens
Review URL: https://codereview.chromium.org/132123004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244220 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/events')
-rw-r--r-- | ui/events/event.cc | 16 | ||||
-rw-r--r-- | ui/events/event.h | 10 | ||||
-rw-r--r-- | ui/events/gestures/gesture_point.cc | 4 | ||||
-rw-r--r-- | ui/events/gestures/gesture_point.h | 7 | ||||
-rw-r--r-- | ui/events/gestures/gesture_recognizer.h | 11 | ||||
-rw-r--r-- | ui/events/gestures/gesture_recognizer_impl.cc | 12 | ||||
-rw-r--r-- | ui/events/gestures/gesture_recognizer_impl.h | 2 | ||||
-rw-r--r-- | ui/events/gestures/gesture_sequence.cc | 1 |
8 files changed, 51 insertions, 12 deletions
diff --git a/ui/events/event.cc b/ui/events/event.cc index 22e1625..936139f 100644 --- a/ui/events/event.cc +++ b/ui/events/event.cc @@ -5,6 +5,7 @@ #include "ui/events/event.h" #if defined(USE_X11) +#include <X11/extensions/XInput2.h> #include <X11/Xlib.h> #endif @@ -437,7 +438,8 @@ TouchEvent::TouchEvent(const base::NativeEvent& native_event) radius_x_(GetTouchRadiusX(native_event)), radius_y_(GetTouchRadiusY(native_event)), rotation_angle_(GetTouchAngle(native_event)), - force_(GetTouchForce(native_event)) { + force_(GetTouchForce(native_event)), + source_device_id_(-1) { latency()->AddLatencyNumberWithTimestamp( INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, @@ -445,6 +447,12 @@ TouchEvent::TouchEvent(const base::NativeEvent& native_event) base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1, true); + +#if defined(USE_X11) + XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); + source_device_id_ = xiev->deviceid; +#endif + latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); } @@ -457,7 +465,8 @@ TouchEvent::TouchEvent(EventType type, radius_x_(0.0f), radius_y_(0.0f), rotation_angle_(0.0f), - force_(0.0f) { + force_(0.0f), + source_device_id_(-1) { latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); } @@ -475,7 +484,8 @@ TouchEvent::TouchEvent(EventType type, radius_x_(radius_x), radius_y_(radius_y), rotation_angle_(angle), - force_(force) { + force_(force), + source_device_id_(-1) { latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); } diff --git a/ui/events/event.h b/ui/events/event.h index 596f31e..55687035 100644 --- a/ui/events/event.h +++ b/ui/events/event.h @@ -437,7 +437,8 @@ class EVENTS_EXPORT TouchEvent : public LocatedEvent { radius_x_(model.radius_x_), radius_y_(model.radius_y_), rotation_angle_(model.rotation_angle_), - force_(model.force_) { + force_(model.force_), + source_device_id_(model.source_device_id_) { } TouchEvent(EventType type, @@ -462,6 +463,7 @@ class EVENTS_EXPORT TouchEvent : public LocatedEvent { float radius_y() const { return radius_y_; } float rotation_angle() const { return rotation_angle_; } float force() const { return force_; } + int source_device_id() const { return source_device_id_; } // Relocate the touch-point to a new |origin|. // This is useful when touch event is in X Root Window coordinates, @@ -471,6 +473,9 @@ class EVENTS_EXPORT TouchEvent : public LocatedEvent { // Used for unit tests. void set_radius_x(const float r) { radius_x_ = r; } void set_radius_y(const float r) { radius_y_ = r; } + void set_source_device_id(int source_device_id) { + source_device_id_ = source_device_id; + } // Overridden from LocatedEvent. virtual void UpdateForRootTransform( @@ -504,6 +509,9 @@ class EVENTS_EXPORT TouchEvent : public LocatedEvent { // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. float force_; + + // The device id of the screen the event came from. Default to be -1. + int source_device_id_; }; class EVENTS_EXPORT KeyEvent : public Event { diff --git a/ui/events/gestures/gesture_point.cc b/ui/events/gestures/gesture_point.cc index fa47727..eafd344 100644 --- a/ui/events/gestures/gesture_point.cc +++ b/ui/events/gestures/gesture_point.cc @@ -24,7 +24,8 @@ GesturePoint::GesturePoint() velocity_calculator_( GestureConfiguration::points_buffered_for_velocity()), point_id_(-1), - touch_id_(-1) { + touch_id_(-1), + source_device_id_(-1) { } GesturePoint::~GesturePoint() {} @@ -34,6 +35,7 @@ void GesturePoint::Reset() { ResetVelocity(); point_id_ = -1; clear_enclosing_rectangle(); + source_device_id_ = -1; } void GesturePoint::ResetVelocity() { diff --git a/ui/events/gestures/gesture_point.h b/ui/events/gestures/gesture_point.h index f9540fa..85cfd84 100644 --- a/ui/events/gestures/gesture_point.h +++ b/ui/events/gestures/gesture_point.h @@ -79,6 +79,11 @@ class GesturePoint { const gfx::Rect& enclosing_rectangle() const { return enclosing_rect_; } + void set_source_device_id(int source_device_id) { + source_device_id_ = source_device_id; + } + int source_device_id() const { return source_device_id_; } + private: // Various statistical functions to manipulate gestures. @@ -131,6 +136,8 @@ class GesturePoint { // Count of the number of events with same direction. gfx::Vector2d same_direction_count_; + int source_device_id_; + DISALLOW_COPY_AND_ASSIGN(GesturePoint); }; diff --git a/ui/events/gestures/gesture_recognizer.h b/ui/events/gestures/gesture_recognizer.h index 92d225a..4b53c2f 100644 --- a/ui/events/gestures/gesture_recognizer.h +++ b/ui/events/gestures/gesture_recognizer.h @@ -19,6 +19,7 @@ class EVENTS_EXPORT GestureRecognizer { public: static GestureRecognizer* Create(); static GestureRecognizer* Get(); + static void Reset(); // List of GestureEvent*. typedef ScopedVector<GestureEvent> Gestures; @@ -46,10 +47,12 @@ class EVENTS_EXPORT GestureRecognizer { virtual GestureConsumer* GetTargetForGestureEvent( const GestureEvent& event) = 0; - // If there is an active touch within - // 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; + // Returns the target of the nearest active touch with source device of + // |source_device_id|, within + // GestureConfiguration::max_separation_for_gesture_touches_in_pixels of + // |location|, or NULL if no such point exists. + virtual GestureConsumer* GetTargetForLocation( + const gfx::Point& location, int source_device_id) = 0; // Makes |new_consumer| the target for events previously targeting // |current_consumer|. All other targets are canceled. diff --git a/ui/events/gestures/gesture_recognizer_impl.cc b/ui/events/gestures/gesture_recognizer_impl.cc index 4a59934..c166658 100644 --- a/ui/events/gestures/gesture_recognizer_impl.cc +++ b/ui/events/gestures/gesture_recognizer_impl.cc @@ -78,15 +78,17 @@ GestureConsumer* GestureRecognizerImpl::GetTargetForGestureEvent( } GestureConsumer* GestureRecognizerImpl::GetTargetForLocation( - const gfx::Point& location) { + const gfx::Point& location, int source_device_id) { const GesturePoint* closest_point = NULL; int64 closest_distance_squared = 0; std::map<GestureConsumer*, GestureSequence*>::iterator i; for (i = consumer_sequence_.begin(); i != consumer_sequence_.end(); ++i) { const GesturePoint* points = i->second->points(); for (int j = 0; j < GestureSequence::kMaxGesturePoints; ++j) { - if (!points[j].in_use()) + if (!points[j].in_use() || + source_device_id != points[j].source_device_id()) { continue; + } gfx::Vector2d delta = points[j].last_touch_position() - location; // Relative distance is all we need here, so LengthSquared() is // appropriate, and cheaper than Length(). @@ -271,6 +273,12 @@ GestureRecognizer* GestureRecognizer::Get() { return g_gesture_recognizer_instance; } +// GestureRecognizer, static +void GestureRecognizer::Reset() { + delete g_gesture_recognizer_instance; + g_gesture_recognizer_instance = NULL; +} + void SetGestureRecognizerForTesting(GestureRecognizer* gesture_recognizer) { // Transfer helpers to the new GR. std::vector<GestureEventHelper*>& helpers = diff --git a/ui/events/gestures/gesture_recognizer_impl.h b/ui/events/gestures/gesture_recognizer_impl.h index 59c92cf..16ba7a4 100644 --- a/ui/events/gestures/gesture_recognizer_impl.h +++ b/ui/events/gestures/gesture_recognizer_impl.h @@ -39,7 +39,7 @@ class EVENTS_EXPORT GestureRecognizerImpl : public GestureRecognizer, virtual GestureConsumer* GetTargetForGestureEvent( const GestureEvent& event) OVERRIDE; virtual GestureConsumer* GetTargetForLocation( - const gfx::Point& location) OVERRIDE; + const gfx::Point& location, int source_device_id) OVERRIDE; virtual void TransferEventsTo(GestureConsumer* current_consumer, GestureConsumer* new_consumer) OVERRIDE; virtual bool GetLastTouchPointForTarget(GestureConsumer* consumer, diff --git a/ui/events/gestures/gesture_sequence.cc b/ui/events/gestures/gesture_sequence.cc index 65d813a..7b37f45 100644 --- a/ui/events/gestures/gesture_sequence.cc +++ b/ui/events/gestures/gesture_sequence.cc @@ -520,6 +520,7 @@ GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture( } new_point->set_point_id(point_count_++); new_point->set_touch_id(event.touch_id()); + new_point->set_source_device_id(event.source_device_id()); } GestureState last_state = state_; |