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

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

Issue 139983009: ui::LocatedEvent location() returns gfx::PointF (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Undo accidental change. Created 6 years, 7 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_point.h" 5 #include "ui/events/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/events/event.h" 10 #include "ui/events/event.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 gfx::Vector2dF GesturePoint::ScrollDelta() const { 50 gfx::Vector2dF GesturePoint::ScrollDelta() const {
51 return last_touch_position_ - second_last_touch_position_; 51 return last_touch_position_ - second_last_touch_position_;
52 } 52 }
53 53
54 void GesturePoint::UpdateValues(const TouchEvent& event) { 54 void GesturePoint::UpdateValues(const TouchEvent& event) {
55 const int64 event_timestamp_microseconds = 55 const int64 event_timestamp_microseconds =
56 event.time_stamp().InMicroseconds(); 56 event.time_stamp().InMicroseconds();
57 if (event.type() == ui::ET_TOUCH_MOVED) { 57 if (event.type() == ui::ET_TOUCH_MOVED) {
58 velocity_calculator_.PointSeen(event.location().x(), 58 velocity_calculator_.PointSeen(gfx::ToFlooredPoint(event.location()).x(),
59 event.location().y(), 59 gfx::ToFlooredPoint(event.location()).y(),
60 event_timestamp_microseconds); 60 event_timestamp_microseconds);
61 gfx::Vector2d sd(ScrollVelocityDirection(velocity_calculator_.XVelocity()), 61 gfx::Vector2d sd(ScrollVelocityDirection(velocity_calculator_.XVelocity()),
62 ScrollVelocityDirection(velocity_calculator_.YVelocity())); 62 ScrollVelocityDirection(velocity_calculator_.YVelocity()));
63 } 63 }
64 64
65 last_touch_time_ = event.time_stamp().InSecondsF(); 65 last_touch_time_ = event.time_stamp().InSecondsF();
66 last_touch_position_ = event.location_f(); 66 last_touch_position_ = event.location();
67 67
68 if (event.type() == ui::ET_TOUCH_PRESSED) { 68 if (event.type() == ui::ET_TOUCH_PRESSED) {
69 ResetVelocity(); 69 ResetVelocity();
70 clear_enclosing_rectangle(); 70 clear_enclosing_rectangle();
71 first_touch_time_ = last_touch_time_; 71 first_touch_time_ = last_touch_time_;
72 first_touch_position_ = event.location(); 72 first_touch_position_ = gfx::ToFlooredPoint(event.location());
73 second_last_touch_position_ = last_touch_position_; 73 second_last_touch_position_ = last_touch_position_;
74 second_last_touch_time_ = last_touch_time_; 74 second_last_touch_time_ = last_touch_time_;
75 velocity_calculator_.PointSeen(event.location().x(), 75 velocity_calculator_.PointSeen(gfx::ToFlooredPoint(event.location()).x(),
76 event.location().y(), 76 gfx::ToFlooredPoint(event.location()).y(),
77 event_timestamp_microseconds); 77 event_timestamp_microseconds);
78 } 78 }
79 79
80 UpdateEnclosingRectangle(event); 80 UpdateEnclosingRectangle(event);
81 } 81 }
82 82
83 void GesturePoint::UpdateForTap() { 83 void GesturePoint::UpdateForTap() {
84 // Update the tap-position and time, and reset every other state. 84 // Update the tap-position and time, and reset every other state.
85 second_last_tap_position_ = last_tap_position_; 85 second_last_tap_position_ = last_tap_position_;
86 second_last_tap_time_ = last_tap_time_; 86 second_last_tap_time_ = last_tap_time_;
87 last_tap_time_ = last_touch_time_; 87 last_tap_time_ = last_touch_time_;
88 last_tap_position_ = last_touch_position_; 88 last_tap_position_ = last_touch_position_;
89 } 89 }
90 90
91 void GesturePoint::UpdateForScroll() { 91 void GesturePoint::UpdateForScroll() {
92 second_last_touch_position_ = last_touch_position_; 92 second_last_touch_position_ = last_touch_position_;
93 second_last_touch_time_ = last_touch_time_; 93 second_last_touch_time_ = last_touch_time_;
94 } 94 }
95 95
96 bool GesturePoint::IsInClickWindow(const TouchEvent& event) const { 96 bool GesturePoint::IsInClickWindow(const TouchEvent& event) const {
97 return IsInClickTimeWindow() && IsInsideTouchSlopRegion(event); 97 return IsInClickTimeWindow() && IsInsideTouchSlopRegion(event);
98 } 98 }
99 99
100 bool GesturePoint::IsInDoubleClickWindow(const TouchEvent& event) const { 100 bool GesturePoint::IsInDoubleClickWindow(const TouchEvent& event) const {
101 return IsInClickAggregateTimeWindow(last_tap_time_, last_touch_time_) && 101 return IsInClickAggregateTimeWindow(last_tap_time_, last_touch_time_) &&
102 IsPointInsideDoubleTapTouchSlopRegion( 102 IsPointInsideDoubleTapTouchSlopRegion(
103 event.location(), last_tap_position_); 103 gfx::ToFlooredPoint(event.location()), last_tap_position_);
104 } 104 }
105 105
106 bool GesturePoint::IsInTripleClickWindow(const TouchEvent& event) const { 106 bool GesturePoint::IsInTripleClickWindow(const TouchEvent& event) const {
107 return IsInClickAggregateTimeWindow(last_tap_time_, last_touch_time_) && 107 return IsInClickAggregateTimeWindow(last_tap_time_, last_touch_time_) &&
108 IsInClickAggregateTimeWindow(second_last_tap_time_, last_tap_time_) && 108 IsInClickAggregateTimeWindow(second_last_tap_time_, last_tap_time_) &&
109 IsPointInsideDoubleTapTouchSlopRegion( 109 IsPointInsideDoubleTapTouchSlopRegion(
110 event.location(), last_tap_position_) && 110 gfx::ToFlooredPoint(event.location()), last_tap_position_) &&
111 IsPointInsideDoubleTapTouchSlopRegion(last_tap_position_, 111 IsPointInsideDoubleTapTouchSlopRegion(last_tap_position_,
112 second_last_tap_position_); 112 second_last_tap_position_);
113 } 113 }
114 114
115 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const { 115 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const {
116 return event.type() == ui::ET_TOUCH_MOVED && 116 return event.type() == ui::ET_TOUCH_MOVED &&
117 !IsInsideTouchSlopRegion(event); 117 !IsInsideTouchSlopRegion(event);
118 } 118 }
119 119
120 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) { 120 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) {
121 return IsOverMinFlickSpeed() && 121 return IsOverMinFlickSpeed() &&
122 event.type() != ui::ET_TOUCH_CANCELLED; 122 event.type() != ui::ET_TOUCH_CANCELLED;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 GestureConfiguration::max_touch_down_duration_in_seconds_for_click(); 170 GestureConfiguration::max_touch_down_duration_in_seconds_for_click();
171 } 171 }
172 172
173 bool GesturePoint::IsInClickAggregateTimeWindow(double before, 173 bool GesturePoint::IsInClickAggregateTimeWindow(double before,
174 double after) const { 174 double after) const {
175 double duration = after - before; 175 double duration = after - before;
176 return duration < GestureConfiguration::max_seconds_between_double_click(); 176 return duration < GestureConfiguration::max_seconds_between_double_click();
177 } 177 }
178 178
179 bool GesturePoint::IsInsideTouchSlopRegion(const TouchEvent& event) const { 179 bool GesturePoint::IsInsideTouchSlopRegion(const TouchEvent& event) const {
180 const gfx::PointF& p1 = event.location(); 180 const gfx::PointF& p1 = gfx::ToFlooredPoint(event.location());
181 const gfx::PointF& p2 = first_touch_position_; 181 const gfx::PointF& p2 = first_touch_position_;
182 float dx = p1.x() - p2.x(); 182 float dx = p1.x() - p2.x();
183 float dy = p1.y() - p2.y(); 183 float dy = p1.y() - p2.y();
184 float distance = dx * dx + dy * dy; 184 float distance = dx * dx + dy * dy;
185 return distance < max_touch_move_in_pixels_for_click_squared_; 185 return distance < max_touch_move_in_pixels_for_click_squared_;
186 } 186 }
187 187
188 bool GesturePoint::IsPointInsideDoubleTapTouchSlopRegion(gfx::PointF p1, 188 bool GesturePoint::IsPointInsideDoubleTapTouchSlopRegion(gfx::PointF p1,
189 gfx::PointF p2) const { 189 gfx::PointF p2) const {
190 float dx = p1.x() - p2.x(); 190 float dx = p1.x() - p2.x();
(...skipping 20 matching lines...) Expand all
211 // of the two and use this as both the x radius and the y radius of the 211 // of the two and use this as both the x radius and the y radius of the
212 // touch region. Otherwise use the default radius value. 212 // touch region. Otherwise use the default radius value.
213 // TODO(tdanderson): Implement a more specific check for the exact 213 // TODO(tdanderson): Implement a more specific check for the exact
214 // information provided by the device (0-2 radii values, force, angle) and 214 // information provided by the device (0-2 radii values, force, angle) and
215 // use this to compute a more representative rectangular touch region. 215 // use this to compute a more representative rectangular touch region.
216 if (event.radius_x() || event.radius_y()) 216 if (event.radius_x() || event.radius_y())
217 radius = std::max(event.radius_x(), event.radius_y()); 217 radius = std::max(event.radius_x(), event.radius_y());
218 else 218 else
219 radius = GestureConfiguration::default_radius(); 219 radius = GestureConfiguration::default_radius();
220 220
221 gfx::RectF rect(event.location_f().x() - radius, 221 gfx::RectF rect(event.location().x() - radius,
222 event.location_f().y() - radius, 222 event.location().y() - radius,
223 radius * 2, 223 radius * 2,
224 radius * 2); 224 radius * 2);
225 if (IsInClickWindow(event)) 225 if (IsInClickWindow(event))
226 enclosing_rect_.Union(rect); 226 enclosing_rect_.Union(rect);
227 else 227 else
228 enclosing_rect_ = rect; 228 enclosing_rect_ = rect;
229 } 229 }
230 230
231 } // namespace ui 231 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698