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

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

Issue 10831240: Remove TouchEvent interface, and rename TouchEventImpl to TouchEvent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge-tot Created 8 years, 4 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/event.cc ('k') | ui/base/gestures/gesture_recognizer_impl.cc » ('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_point.h" 5 #include "ui/base/gestures/gesture_point.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "ui/base/event.h"
10 #include "ui/base/events.h" 11 #include "ui/base/events.h"
11 #include "ui/base/gestures/gesture_configuration.h" 12 #include "ui/base/gestures/gesture_configuration.h"
12 #include "ui/base/gestures/gesture_util.h" 13 #include "ui/base/gestures/gesture_util.h"
13 #include "ui/base/gestures/gesture_types.h" 14 #include "ui/base/gestures/gesture_types.h"
14 15
15 namespace ui { 16 namespace ui {
16 17
17 GesturePoint::GesturePoint() 18 GesturePoint::GesturePoint()
18 : first_touch_time_(0.0), 19 : first_touch_time_(0.0),
19 last_touch_time_(0.0), 20 last_touch_time_(0.0),
(...skipping 12 matching lines...) Expand all
32 point_id_ = -1; 33 point_id_ = -1;
33 clear_enclosing_rectangle(); 34 clear_enclosing_rectangle();
34 } 35 }
35 36
36 void GesturePoint::ResetVelocity() { 37 void GesturePoint::ResetVelocity() {
37 velocity_calculator_.ClearHistory(); 38 velocity_calculator_.ClearHistory();
38 } 39 }
39 40
40 void GesturePoint::UpdateValues(const TouchEvent& event) { 41 void GesturePoint::UpdateValues(const TouchEvent& event) {
41 const int64 event_timestamp_microseconds = 42 const int64 event_timestamp_microseconds =
42 event.GetTimestamp().InMicroseconds(); 43 event.time_stamp().InMicroseconds();
43 if (event.GetEventType() == ui::ET_TOUCH_MOVED) { 44 if (event.type() == ui::ET_TOUCH_MOVED) {
44 velocity_calculator_.PointSeen(event.GetLocation().x(), 45 velocity_calculator_.PointSeen(event.location().x(),
45 event.GetLocation().y(), 46 event.location().y(),
46 event_timestamp_microseconds); 47 event_timestamp_microseconds);
47 } 48 }
48 49
49 last_touch_time_ = event.GetTimestamp().InSecondsF(); 50 last_touch_time_ = event.time_stamp().InSecondsF();
50 last_touch_position_ = event.GetLocation(); 51 last_touch_position_ = event.location();
51 52
52 if (event.GetEventType() == ui::ET_TOUCH_PRESSED) { 53 if (event.type() == ui::ET_TOUCH_PRESSED) {
53 first_touch_time_ = last_touch_time_; 54 first_touch_time_ = last_touch_time_;
54 first_touch_position_ = event.GetLocation(); 55 first_touch_position_ = event.location();
55 velocity_calculator_.ClearHistory(); 56 velocity_calculator_.ClearHistory();
56 velocity_calculator_.PointSeen(event.GetLocation().x(), 57 velocity_calculator_.PointSeen(event.location().x(),
57 event.GetLocation().y(), 58 event.location().y(),
58 event_timestamp_microseconds); 59 event_timestamp_microseconds);
59 clear_enclosing_rectangle(); 60 clear_enclosing_rectangle();
60 } 61 }
61 62
62 UpdateEnclosingRectangle(event); 63 UpdateEnclosingRectangle(event);
63 } 64 }
64 65
65 void GesturePoint::UpdateForTap() { 66 void GesturePoint::UpdateForTap() {
66 // Update the tap-position and time, and reset every other state. 67 // Update the tap-position and time, and reset every other state.
67 last_tap_time_ = last_touch_time_; 68 last_tap_time_ = last_touch_time_;
(...skipping 11 matching lines...) Expand all
79 bool GesturePoint::IsInClickWindow(const TouchEvent& event) const { 80 bool GesturePoint::IsInClickWindow(const TouchEvent& event) const {
80 return IsInClickTimeWindow() && IsInsideManhattanSquare(event); 81 return IsInClickTimeWindow() && IsInsideManhattanSquare(event);
81 } 82 }
82 83
83 bool GesturePoint::IsInDoubleClickWindow(const TouchEvent& event) const { 84 bool GesturePoint::IsInDoubleClickWindow(const TouchEvent& event) const {
84 return IsInSecondClickTimeWindow() && 85 return IsInSecondClickTimeWindow() &&
85 IsSecondClickInsideManhattanSquare(event); 86 IsSecondClickInsideManhattanSquare(event);
86 } 87 }
87 88
88 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const { 89 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const {
89 return event.GetEventType() == ui::ET_TOUCH_MOVED && 90 return event.type() == ui::ET_TOUCH_MOVED &&
90 !IsInsideManhattanSquare(event); 91 !IsInsideManhattanSquare(event);
91 } 92 }
92 93
93 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) { 94 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) {
94 return IsOverMinFlickSpeed() && 95 return IsOverMinFlickSpeed() &&
95 event.GetEventType() != ui::ET_TOUCH_CANCELLED; 96 event.type() != ui::ET_TOUCH_CANCELLED;
96 } 97 }
97 98
98 bool GesturePoint::DidScroll(const TouchEvent& event, int dist) const { 99 bool GesturePoint::DidScroll(const TouchEvent& event, int dist) const {
99 return abs(last_touch_position_.x() - first_touch_position_.x()) > dist || 100 return abs(last_touch_position_.x() - first_touch_position_.x()) > dist ||
100 abs(last_touch_position_.y() - first_touch_position_.y()) > dist; 101 abs(last_touch_position_.y() - first_touch_position_.y()) > dist;
101 } 102 }
102 103
103 bool GesturePoint::HasEnoughDataToEstablishRail() const { 104 bool GesturePoint::HasEnoughDataToEstablishRail() const {
104 int dx = x_delta(); 105 int dx = x_delta();
105 int dy = y_delta(); 106 int dy = y_delta();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 duration < 142 duration <
142 GestureConfiguration::max_touch_down_duration_in_seconds_for_click(); 143 GestureConfiguration::max_touch_down_duration_in_seconds_for_click();
143 } 144 }
144 145
145 bool GesturePoint::IsInSecondClickTimeWindow() const { 146 bool GesturePoint::IsInSecondClickTimeWindow() const {
146 double duration = last_touch_time_ - last_tap_time_; 147 double duration = last_touch_time_ - last_tap_time_;
147 return duration < GestureConfiguration::max_seconds_between_double_click(); 148 return duration < GestureConfiguration::max_seconds_between_double_click();
148 } 149 }
149 150
150 bool GesturePoint::IsInsideManhattanSquare(const TouchEvent& event) const { 151 bool GesturePoint::IsInsideManhattanSquare(const TouchEvent& event) const {
151 return ui::gestures::IsInsideManhattanSquare(event.GetLocation(), 152 return ui::gestures::IsInsideManhattanSquare(event.location(),
152 first_touch_position_); 153 first_touch_position_);
153 } 154 }
154 155
155 bool GesturePoint::IsSecondClickInsideManhattanSquare( 156 bool GesturePoint::IsSecondClickInsideManhattanSquare(
156 const TouchEvent& event) const { 157 const TouchEvent& event) const {
157 return ui::gestures::IsInsideManhattanSquare(event.GetLocation(), 158 return ui::gestures::IsInsideManhattanSquare(event.location(),
158 last_tap_position_); 159 last_tap_position_);
159 } 160 }
160 161
161 bool GesturePoint::IsOverMinFlickSpeed() { 162 bool GesturePoint::IsOverMinFlickSpeed() {
162 return velocity_calculator_.VelocitySquared() > 163 return velocity_calculator_.VelocitySquared() >
163 GestureConfiguration::min_flick_speed_squared(); 164 GestureConfiguration::min_flick_speed_squared();
164 } 165 }
165 166
166 void GesturePoint::UpdateEnclosingRectangle(const TouchEvent& event) { 167 void GesturePoint::UpdateEnclosingRectangle(const TouchEvent& event) {
167 int radius; 168 int radius;
168 169
169 // Ignore this TouchEvent if it has a radius larger than the maximum 170 // Ignore this TouchEvent if it has a radius larger than the maximum
170 // allowed radius size. 171 // allowed radius size.
171 if (event.RadiusX() > GestureConfiguration::max_radius() || 172 if (event.radius_x() > GestureConfiguration::max_radius() ||
172 event.RadiusY() > GestureConfiguration::max_radius()) 173 event.radius_y() > GestureConfiguration::max_radius())
173 return; 174 return;
174 175
175 // If the device provides at least one of the radius values, take the larger 176 // If the device provides at least one of the radius values, take the larger
176 // of the two and use this as both the x radius and the y radius of the 177 // of the two and use this as both the x radius and the y radius of the
177 // touch region. Otherwise use the default radius value. 178 // touch region. Otherwise use the default radius value.
178 // TODO(tdanderson): Implement a more specific check for the exact 179 // TODO(tdanderson): Implement a more specific check for the exact
179 // information provided by the device (0-2 radii values, force, angle) and 180 // information provided by the device (0-2 radii values, force, angle) and
180 // use this to compute a more representative rectangular touch region. 181 // use this to compute a more representative rectangular touch region.
181 if (event.RadiusX() || event.RadiusY()) 182 if (event.radius_x() || event.radius_y())
182 radius = std::max(event.RadiusX(), event.RadiusY()); 183 radius = std::max(event.radius_x(), event.radius_y());
183 else 184 else
184 radius = GestureConfiguration::default_radius(); 185 radius = GestureConfiguration::default_radius();
185 186
186 gfx::Rect rect(event.GetLocation().x() - radius, 187 gfx::Rect rect(event.location().x() - radius,
187 event.GetLocation().y() - radius, 188 event.location().y() - radius,
188 radius * 2, 189 radius * 2,
189 radius * 2); 190 radius * 2);
190 if (IsInClickWindow(event)) 191 if (IsInClickWindow(event))
191 enclosing_rect_ = enclosing_rect_.Union(rect); 192 enclosing_rect_ = enclosing_rect_.Union(rect);
192 else 193 else
193 enclosing_rect_ = rect; 194 enclosing_rect_ = rect;
194 } 195 }
195 196
196 } // namespace ui 197 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/event.cc ('k') | ui/base/gestures/gesture_recognizer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698