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

Side by Side Diff: trunk/src/ui/events/gestures/gesture_recognizer_impl.cc

Issue 132363004: Revert 243974 "Target touches to the correct display." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 11 months 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/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
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, int source_device_id) { 81 const gfx::Point& location) {
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()) {
90 continue; 89 continue;
91 }
92 gfx::Vector2d delta = points[j].last_touch_position() - location; 90 gfx::Vector2d delta = points[j].last_touch_position() - location;
93 // Relative distance is all we need here, so LengthSquared() is 91 // Relative distance is all we need here, so LengthSquared() is
94 // appropriate, and cheaper than Length(). 92 // appropriate, and cheaper than Length().
95 int64 distance_squared = delta.LengthSquared(); 93 int64 distance_squared = delta.LengthSquared();
96 if (!closest_point || distance_squared < closest_distance_squared) { 94 if (!closest_point || distance_squared < closest_distance_squared) {
97 closest_point = &points[j]; 95 closest_point = &points[j];
98 closest_distance_squared = distance_squared; 96 closest_distance_squared = distance_squared;
99 } 97 }
100 } 98 }
101 } 99 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 264
267 static GestureRecognizerImpl* g_gesture_recognizer_instance = NULL; 265 static GestureRecognizerImpl* g_gesture_recognizer_instance = NULL;
268 266
269 // GestureRecognizer, static 267 // GestureRecognizer, static
270 GestureRecognizer* GestureRecognizer::Get() { 268 GestureRecognizer* GestureRecognizer::Get() {
271 if (!g_gesture_recognizer_instance) 269 if (!g_gesture_recognizer_instance)
272 g_gesture_recognizer_instance = new GestureRecognizerImpl(); 270 g_gesture_recognizer_instance = new GestureRecognizerImpl();
273 return g_gesture_recognizer_instance; 271 return g_gesture_recognizer_instance;
274 } 272 }
275 273
276 // GestureRecognizer, static
277 void GestureRecognizer::Reset() {
278 g_gesture_recognizer_instance = NULL;
279 }
280
281 void SetGestureRecognizerForTesting(GestureRecognizer* gesture_recognizer) { 274 void SetGestureRecognizerForTesting(GestureRecognizer* gesture_recognizer) {
282 // Transfer helpers to the new GR. 275 // Transfer helpers to the new GR.
283 std::vector<GestureEventHelper*>& helpers = 276 std::vector<GestureEventHelper*>& helpers =
284 g_gesture_recognizer_instance->helpers(); 277 g_gesture_recognizer_instance->helpers();
285 std::vector<GestureEventHelper*>::iterator it; 278 std::vector<GestureEventHelper*>::iterator it;
286 for (it = helpers.begin(); it != helpers.end(); ++it) 279 for (it = helpers.begin(); it != helpers.end(); ++it)
287 gesture_recognizer->AddGestureEventHelper(*it); 280 gesture_recognizer->AddGestureEventHelper(*it);
288 281
289 helpers.clear(); 282 helpers.clear();
290 g_gesture_recognizer_instance = 283 g_gesture_recognizer_instance =
291 static_cast<GestureRecognizerImpl*>(gesture_recognizer); 284 static_cast<GestureRecognizerImpl*>(gesture_recognizer);
292 } 285 }
293 286
294 } // namespace ui 287 } // namespace ui
OLDNEW
« no previous file with comments | « trunk/src/ui/events/gestures/gesture_recognizer_impl.h ('k') | trunk/src/ui/events/gestures/gesture_sequence.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698