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

Side by Side Diff: ui/aura/gestures/gesture_point.cc

Issue 9104021: aura: Update GestureRecognizer to be able to process multi-point gestures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 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/aura/gestures/gesture_point.h ('k') | ui/aura/gestures/gesture_recognizer_aura.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/aura/gestures/gesture_point.h"
6
7 #include "ui/aura/event.h"
8 #include "ui/base/events.h"
9
10 namespace {
11
12 // TODO(girard): Make these configurable in sync with this CL
13 // http://crbug.com/100773
14 const double kMaximumTouchDownDurationInSecondsForClick = 0.8;
15 const double kMinimumTouchDownDurationInSecondsForClick = 0.01;
16 const double kMaximumSecondsBetweenDoubleClick = 0.7;
17 const int kMaximumTouchMoveInPixelsForClick = 20;
18 const float kMinFlickSpeedSquared = 550.f * 550.f;
19
20 } // namespace aura
21
22 namespace aura {
23
24 GesturePoint::GesturePoint()
25 : first_touch_time_(0.0),
26 last_touch_time_(0.0),
27 last_tap_time_(0.0),
28 x_velocity_(0.0),
29 y_velocity_(0.0) {
30 }
31
32 void GesturePoint::Reset() {
33 first_touch_time_ = last_touch_time_ = 0.0;
34 x_velocity_ = y_velocity_ = 0.0;
35 }
36
37 void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) {
38 if (state != GS_NO_GESTURE && event.type() == ui::ET_TOUCH_MOVED) {
39 double interval(event.time_stamp().InSecondsF() - last_touch_time_);
40 x_velocity_ = (event.x() - last_touch_position_.x()) / interval;
41 y_velocity_ = (event.y() - last_touch_position_.y()) / interval;
42 }
43
44 last_touch_time_ = event.time_stamp().InSecondsF();
45 last_touch_position_ = event.location();
46
47 if (state == GS_NO_GESTURE) {
48 first_touch_time_ = last_touch_time_;
49 first_touch_position_ = event.location();
50 x_velocity_ = 0.0;
51 y_velocity_ = 0.0;
52 }
53 }
54
55 void GesturePoint::UpdateForTap() {
56 // Update the tap-position and time, and reset every other state.
57 last_tap_time_ = last_touch_time_;
58 last_tap_position_ = last_touch_position_;
59 Reset();
60 }
61
62 void GesturePoint::UpdateForScroll() {
63 // Update the first-touch position and time so that the scroll-delta and
64 // scroll-velocity can be computed correctly for the next scroll gesture
65 // event.
66 first_touch_position_ = last_touch_position_;
67 first_touch_time_ = last_touch_time_;
68 }
69
70 bool GesturePoint::IsInClickWindow(const TouchEvent& event) const {
71 return IsInClickTimeWindow() && IsInsideManhattanSquare(event);
72 }
73
74 bool GesturePoint::IsInDoubleClickWindow(const TouchEvent& event) const {
75 return IsInSecondClickTimeWindow() &&
76 IsSecondClickInsideManhattanSquare(event);
77 }
78
79 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const {
80 return event.type() == ui::ET_TOUCH_MOVED &&
81 !IsInsideManhattanSquare(event);
82 }
83
84 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) const {
85 return IsOverMinFlickSpeed() && event.type() != ui::ET_TOUCH_CANCELLED;
86 }
87
88 bool GesturePoint::IsInClickTimeWindow() const {
89 double duration = last_touch_time_ - first_touch_time_;
90 return duration >= kMinimumTouchDownDurationInSecondsForClick &&
91 duration < kMaximumTouchDownDurationInSecondsForClick;
92 }
93
94 bool GesturePoint::IsInSecondClickTimeWindow() const {
95 double duration = last_touch_time_ - last_tap_time_;
96 return duration < kMaximumSecondsBetweenDoubleClick;
97 }
98
99 bool GesturePoint::IsInsideManhattanSquare(const TouchEvent& event) const {
100 int manhattanDistance = abs(event.x() - first_touch_position_.x()) +
101 abs(event.y() - first_touch_position_.y());
102 return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
103 }
104
105 bool GesturePoint::IsSecondClickInsideManhattanSquare(
106 const TouchEvent& event) const {
107 int manhattanDistance = abs(event.x() - last_tap_position_.x()) +
108 abs(event.y() - last_tap_position_.y());
109 return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
110 }
111
112 bool GesturePoint::IsOverMinFlickSpeed() const {
113 return (x_velocity_ * x_velocity_ + y_velocity_ * y_velocity_) >
114 kMinFlickSpeedSquared;
115 }
116
117 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/gestures/gesture_point.h ('k') | ui/aura/gestures/gesture_recognizer_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698