Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: ui/base/gestures/gesture_recognizer_impl.cc

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RenderText fixup Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 GestureEvent* event) { 118 GestureEvent* event) {
119 GestureConsumer* target = NULL; 119 GestureConsumer* target = NULL;
120 int touch_id = event->GetLowestTouchId(); 120 int touch_id = event->GetLowestTouchId();
121 target = touch_id_target_for_gestures_[touch_id]; 121 target = touch_id_target_for_gestures_[touch_id];
122 return target; 122 return target;
123 } 123 }
124 124
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 int64 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); 136 // Relative distance is all we need here, so LengthSquared() is
137 int distance = delta.x() * delta.x() + delta.y() * delta.y(); 137 // appropriate, and cheaper than Length().
138 if (!closest_point || distance < closest_distance_squared) { 138 int64 distance_squared = delta.LengthSquared();
139 if (!closest_point || distance_squared < closest_distance_squared) {
139 closest_point = &points[j]; 140 closest_point = &points[j];
140 closest_distance_squared = distance; 141 closest_distance_squared = distance_squared;
141 } 142 }
142 } 143 }
143 } 144 }
144 145
145 const int max_distance = 146 const int max_distance =
146 GestureConfiguration::max_separation_for_gesture_touches_in_pixels(); 147 GestureConfiguration::max_separation_for_gesture_touches_in_pixels();
147 148
148 if (closest_distance_squared < max_distance * max_distance && closest_point) 149 if (closest_distance_squared < max_distance * max_distance && closest_point)
149 return touch_id_target_[closest_point->touch_id()]; 150 return touch_id_target_[closest_point->touch_id()];
150 else 151 else
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 RemoveConsumerFromMap(consumer, &touch_id_target_); 239 RemoveConsumerFromMap(consumer, &touch_id_target_);
239 RemoveConsumerFromMap(consumer, &touch_id_target_for_gestures_); 240 RemoveConsumerFromMap(consumer, &touch_id_target_for_gestures_);
240 } 241 }
241 242
242 // GestureRecognizer, static 243 // GestureRecognizer, static
243 GestureRecognizer* GestureRecognizer::Create(GestureEventHelper* helper) { 244 GestureRecognizer* GestureRecognizer::Create(GestureEventHelper* helper) {
244 return new GestureRecognizerImpl(helper); 245 return new GestureRecognizerImpl(helper);
245 } 246 }
246 247
247 } // namespace ui 248 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698