OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/gestures/gesture_recognizer_impl.h" | 5 #include "ui/events/gestures/gesture_recognizer_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 GestureConsumer* GestureRecognizerImpl::GetTargetForGestureEvent( | 72 GestureConsumer* GestureRecognizerImpl::GetTargetForGestureEvent( |
73 const GestureEvent& event) { | 73 const GestureEvent& event) { |
74 GestureConsumer* target = NULL; | 74 GestureConsumer* target = NULL; |
75 int touch_id = event.GetLowestTouchId(); | 75 int touch_id = event.GetLowestTouchId(); |
76 target = touch_id_target_for_gestures_[touch_id]; | 76 target = touch_id_target_for_gestures_[touch_id]; |
77 return target; | 77 return target; |
78 } | 78 } |
79 | 79 |
80 GestureConsumer* GestureRecognizerImpl::GetTargetForLocation( | 80 GestureConsumer* GestureRecognizerImpl::GetTargetForLocation( |
81 const gfx::Point& location) { | 81 const gfx::Point& location, int source_device_id) { |
82 const GesturePoint* closest_point = NULL; | 82 const GesturePoint* closest_point = NULL; |
83 int64 closest_distance_squared = 0; | 83 int64 closest_distance_squared = 0; |
84 std::map<GestureConsumer*, GestureSequence*>::iterator i; | 84 std::map<GestureConsumer*, GestureSequence*>::iterator i; |
85 for (i = consumer_sequence_.begin(); i != consumer_sequence_.end(); ++i) { | 85 for (i = consumer_sequence_.begin(); i != consumer_sequence_.end(); ++i) { |
86 const GesturePoint* points = i->second->points(); | 86 const GesturePoint* points = i->second->points(); |
87 for (int j = 0; j < GestureSequence::kMaxGesturePoints; ++j) { | 87 for (int j = 0; j < GestureSequence::kMaxGesturePoints; ++j) { |
88 if (!points[j].in_use()) | 88 if (!points[j].in_use() || |
| 89 source_device_id != points[j].source_device_id()) { |
89 continue; | 90 continue; |
| 91 } |
90 gfx::Vector2d delta = points[j].last_touch_position() - location; | 92 gfx::Vector2d delta = points[j].last_touch_position() - location; |
91 // Relative distance is all we need here, so LengthSquared() is | 93 // Relative distance is all we need here, so LengthSquared() is |
92 // appropriate, and cheaper than Length(). | 94 // appropriate, and cheaper than Length(). |
93 int64 distance_squared = delta.LengthSquared(); | 95 int64 distance_squared = delta.LengthSquared(); |
94 if (!closest_point || distance_squared < closest_distance_squared) { | 96 if (!closest_point || distance_squared < closest_distance_squared) { |
95 closest_point = &points[j]; | 97 closest_point = &points[j]; |
96 closest_distance_squared = distance_squared; | 98 closest_distance_squared = distance_squared; |
97 } | 99 } |
98 } | 100 } |
99 } | 101 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 266 |
265 static GestureRecognizerImpl* g_gesture_recognizer_instance = NULL; | 267 static GestureRecognizerImpl* g_gesture_recognizer_instance = NULL; |
266 | 268 |
267 // GestureRecognizer, static | 269 // GestureRecognizer, static |
268 GestureRecognizer* GestureRecognizer::Get() { | 270 GestureRecognizer* GestureRecognizer::Get() { |
269 if (!g_gesture_recognizer_instance) | 271 if (!g_gesture_recognizer_instance) |
270 g_gesture_recognizer_instance = new GestureRecognizerImpl(); | 272 g_gesture_recognizer_instance = new GestureRecognizerImpl(); |
271 return g_gesture_recognizer_instance; | 273 return g_gesture_recognizer_instance; |
272 } | 274 } |
273 | 275 |
| 276 // GestureRecognizer, static |
| 277 void GestureRecognizer::Reset() { |
| 278 g_gesture_recognizer_instance = NULL; |
| 279 } |
| 280 |
274 void SetGestureRecognizerForTesting(GestureRecognizer* gesture_recognizer) { | 281 void SetGestureRecognizerForTesting(GestureRecognizer* gesture_recognizer) { |
275 // Transfer helpers to the new GR. | 282 // Transfer helpers to the new GR. |
276 std::vector<GestureEventHelper*>& helpers = | 283 std::vector<GestureEventHelper*>& helpers = |
277 g_gesture_recognizer_instance->helpers(); | 284 g_gesture_recognizer_instance->helpers(); |
278 std::vector<GestureEventHelper*>::iterator it; | 285 std::vector<GestureEventHelper*>::iterator it; |
279 for (it = helpers.begin(); it != helpers.end(); ++it) | 286 for (it = helpers.begin(); it != helpers.end(); ++it) |
280 gesture_recognizer->AddGestureEventHelper(*it); | 287 gesture_recognizer->AddGestureEventHelper(*it); |
281 | 288 |
282 helpers.clear(); | 289 helpers.clear(); |
283 g_gesture_recognizer_instance = | 290 g_gesture_recognizer_instance = |
284 static_cast<GestureRecognizerImpl*>(gesture_recognizer); | 291 static_cast<GestureRecognizerImpl*>(gesture_recognizer); |
285 } | 292 } |
286 | 293 |
287 } // namespace ui | 294 } // namespace ui |
OLD | NEW |