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/base/gestures/gesture_recognizer_impl.h" | 5 #include "ui/base/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.h" | 9 #include "base/time.h" |
10 #include "ui/base/events/event.h" | 10 #include "ui/base/events/event.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 GestureConsumer* GestureRecognizerImpl::GetTargetForLocation( | 125 GestureConsumer* GestureRecognizerImpl::GetTargetForLocation( |
126 const gfx::Point& location) { | 126 const gfx::Point& location) { |
127 const GesturePoint* closest_point = NULL; | 127 const GesturePoint* closest_point = NULL; |
128 int closest_distance_squared = 0; | 128 int closest_distance_squared = 0; |
129 std::map<GestureConsumer*, GestureSequence*>::iterator i; | 129 std::map<GestureConsumer*, GestureSequence*>::iterator i; |
130 for (i = consumer_sequence_.begin(); i != consumer_sequence_.end(); ++i) { | 130 for (i = consumer_sequence_.begin(); i != consumer_sequence_.end(); ++i) { |
131 const GesturePoint* points = i->second->points(); | 131 const GesturePoint* points = i->second->points(); |
132 for (int j = 0; j < GestureSequence::kMaxGesturePoints; ++j) { | 132 for (int j = 0; j < GestureSequence::kMaxGesturePoints; ++j) { |
133 if (!points[j].in_use()) | 133 if (!points[j].in_use()) |
134 continue; | 134 continue; |
135 gfx::Point delta = | 135 gfx::Vector2d delta = points[j].last_touch_position() - location; |
136 points[j].last_touch_position().Subtract(location); | |
137 int distance = delta.x() * delta.x() + delta.y() * delta.y(); | 136 int distance = delta.x() * delta.x() + delta.y() * delta.y(); |
Peter Kasting
2012/10/30 01:14:14
Nit: Use LengthSquared() and add comments/change n
| |
138 if (!closest_point || distance < closest_distance_squared) { | 137 if (!closest_point || distance < closest_distance_squared) { |
139 closest_point = &points[j]; | 138 closest_point = &points[j]; |
140 closest_distance_squared = distance; | 139 closest_distance_squared = distance; |
141 } | 140 } |
142 } | 141 } |
143 } | 142 } |
144 | 143 |
145 const int max_distance = | 144 const int max_distance = |
146 GestureConfiguration::max_separation_for_gesture_touches_in_pixels(); | 145 GestureConfiguration::max_separation_for_gesture_touches_in_pixels(); |
147 | 146 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 RemoveConsumerFromMap(consumer, &touch_id_target_); | 237 RemoveConsumerFromMap(consumer, &touch_id_target_); |
239 RemoveConsumerFromMap(consumer, &touch_id_target_for_gestures_); | 238 RemoveConsumerFromMap(consumer, &touch_id_target_for_gestures_); |
240 } | 239 } |
241 | 240 |
242 // GestureRecognizer, static | 241 // GestureRecognizer, static |
243 GestureRecognizer* GestureRecognizer::Create(GestureEventHelper* helper) { | 242 GestureRecognizer* GestureRecognizer::Create(GestureEventHelper* helper) { |
244 return new GestureRecognizerImpl(helper); | 243 return new GestureRecognizerImpl(helper); |
245 } | 244 } |
246 | 245 |
247 } // namespace ui | 246 } // namespace ui |
OLD | NEW |