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

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

Issue 10964051: events: Clean up dispatching code for touch-events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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
« no previous file with comments | « ui/base/gestures/gesture_sequence.h ('k') | ui/ui.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_sequence.h" 5 #include "ui/base/gestures/gesture_sequence.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 12 matching lines...) Expand all
23 // Signature. 23 // Signature.
24 enum TouchState { 24 enum TouchState {
25 TS_RELEASED, 25 TS_RELEASED,
26 TS_PRESSED, 26 TS_PRESSED,
27 TS_MOVED, 27 TS_MOVED,
28 TS_STATIONARY, 28 TS_STATIONARY,
29 TS_CANCELLED, 29 TS_CANCELLED,
30 TS_UNKNOWN, 30 TS_UNKNOWN,
31 }; 31 };
32 32
33 // ui::TouchStatus is mapped to TouchStatusInternal to simply indicate whether a 33 // ui::EventResult is mapped to TouchStatusInternal to simply indicate whether a
34 // processed touch-event should affect gesture-recognition or not. 34 // processed touch-event should affect gesture-recognition or not.
35 enum TouchStatusInternal { 35 enum TouchStatusInternal {
36 TSI_NOT_PROCESSED, // The touch-event should take-part into 36 TSI_NOT_PROCESSED, // The touch-event should take-part into
37 // gesture-recognition only if the touch-event has not 37 // gesture-recognition only if the touch-event has not
38 // been processed. 38 // been processed.
39 39
40 TSI_PROCESSED, // The touch-event should affect gesture-recognition only 40 TSI_PROCESSED, // The touch-event should affect gesture-recognition only
41 // if the touch-event has been processed. For example,, 41 // if the touch-event has been processed. For example,,
42 // this means that a JavaScript touch handler called 42 // this means that a JavaScript touch handler called
43 // |preventDefault| on the associated touch event 43 // |preventDefault| on the associated touch event
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 long_press_timer_(CreateTimer()), 300 long_press_timer_(CreateTimer()),
301 point_count_(0), 301 point_count_(0),
302 helper_(helper) { 302 helper_(helper) {
303 } 303 }
304 304
305 GestureSequence::~GestureSequence() { 305 GestureSequence::~GestureSequence() {
306 } 306 }
307 307
308 GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture( 308 GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
309 const TouchEvent& event, 309 const TouchEvent& event,
310 ui::TouchStatus status) { 310 EventResult result) {
311 StopLongPressTimerIfRequired(event); 311 StopLongPressTimerIfRequired(event);
312 last_touch_location_ = event.location(); 312 last_touch_location_ = event.location();
313 if (status == ui::TOUCH_STATUS_QUEUED || 313 if (result & ER_ASYNC)
314 status == ui::TOUCH_STATUS_QUEUED_END)
315 return NULL; 314 return NULL;
316 315
317 // Set a limit on the number of simultaneous touches in a gesture. 316 // Set a limit on the number of simultaneous touches in a gesture.
318 if (event.touch_id() >= kMaxGesturePoints) 317 if (event.touch_id() >= kMaxGesturePoints)
319 return NULL; 318 return NULL;
320 319
321 if (event.type() == ui::ET_TOUCH_PRESSED) { 320 if (event.type() == ui::ET_TOUCH_PRESSED) {
322 if (point_count_ == kMaxGesturePoints) 321 if (point_count_ == kMaxGesturePoints)
323 return NULL; 322 return NULL;
324 GesturePoint* new_point = &points_[event.touch_id()]; 323 GesturePoint* new_point = &points_[event.touch_id()];
(...skipping 19 matching lines...) Expand all
344 RecreateBoundingBox(); 343 RecreateBoundingBox();
345 flags_ = event.flags(); 344 flags_ = event.flags();
346 const int point_id = point.point_id(); 345 const int point_id = point.point_id();
347 if (point_id < 0) 346 if (point_id < 0)
348 return NULL; 347 return NULL;
349 348
350 // Send GESTURE_BEGIN for any touch pressed. 349 // Send GESTURE_BEGIN for any touch pressed.
351 if (event.type() == ui::ET_TOUCH_PRESSED) 350 if (event.type() == ui::ET_TOUCH_PRESSED)
352 AppendBeginGestureEvent(point, gestures.get()); 351 AppendBeginGestureEvent(point, gestures.get());
353 352
354 TouchStatusInternal status_internal = (status == ui::TOUCH_STATUS_UNKNOWN) ? 353 CHECK_NE(ER_ASYNC, result);
354 TouchStatusInternal status_internal = (result == ER_UNHANDLED) ?
355 TSI_NOT_PROCESSED : TSI_PROCESSED; 355 TSI_NOT_PROCESSED : TSI_PROCESSED;
356 356
357 EdgeStateSignatureType signature = Signature(state_, point_id, 357 EdgeStateSignatureType signature = Signature(state_, point_id,
358 event.type(), status_internal); 358 event.type(), status_internal);
359 359
360 if (signature == GST_INVALID) 360 if (signature == GST_INVALID)
361 signature = Signature(state_, point_id, event.type(), TSI_ALWAYS); 361 signature = Signature(state_, point_id, event.type(), TSI_ALWAYS);
362 362
363 switch (signature) { 363 switch (signature) {
364 case GST_INVALID: 364 case GST_INVALID:
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 return &point; 570 return &point;
571 } 571 }
572 NOTREACHED(); 572 NOTREACHED();
573 return NULL; 573 return NULL;
574 } 574 }
575 575
576 bool GestureSequence::IsSecondTouchDownCloseEnoughForTwoFingerTap() { 576 bool GestureSequence::IsSecondTouchDownCloseEnoughForTwoFingerTap() {
577 gfx::Point p1 = GetPointByPointId(0)->last_touch_position(); 577 gfx::Point p1 = GetPointByPointId(0)->last_touch_position();
578 gfx::Point p2 = GetPointByPointId(1)->last_touch_position(); 578 gfx::Point p2 = GetPointByPointId(1)->last_touch_position();
579 double max_distance = 579 double max_distance =
580 ui::GestureConfiguration::max_distance_for_two_finger_tap_in_pixels(); 580 GestureConfiguration::max_distance_for_two_finger_tap_in_pixels();
581 double distance = (p1.x() - p2.x()) * (p1.x() - p2.x()) + 581 double distance = (p1.x() - p2.x()) * (p1.x() - p2.x()) +
582 (p1.y() - p2.y()) * (p1.y() - p2.y()); 582 (p1.y() - p2.y()) * (p1.y() - p2.y());
583 if (distance < max_distance * max_distance) 583 if (distance < max_distance * max_distance)
584 return true; 584 return true;
585 return false; 585 return false;
586 } 586 }
587 587
588 GestureEvent* GestureSequence::CreateGestureEvent( 588 GestureEvent* GestureSequence::CreateGestureEvent(
589 const GestureEventDetails& details, 589 const GestureEventDetails& details,
590 const gfx::Point& location, 590 const gfx::Point& location,
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 return; 1081 return;
1082 1082
1083 // Since long press timer has been started, there should be a non-NULL point. 1083 // Since long press timer has been started, there should be a non-NULL point.
1084 const GesturePoint* point = GetPointByPointId(0); 1084 const GesturePoint* point = GetPointByPointId(0);
1085 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), 1085 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(),
1086 event.location())) 1086 event.location()))
1087 long_press_timer_->Stop(); 1087 long_press_timer_->Stop();
1088 } 1088 }
1089 1089
1090 } // namespace ui 1090 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/gestures/gesture_sequence.h ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698