Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/events/event.h" | 10 #include "ui/base/events/event.h" |
| 11 #include "ui/base/events/event_constants.h" | 11 #include "ui/base/events/event_constants.h" |
| 12 #include "ui/base/gestures/gesture_configuration.h" | 12 #include "ui/base/gestures/gesture_configuration.h" |
| 13 #include "ui/base/gestures/gesture_types.h" | 13 #include "ui/base/gestures/gesture_types.h" |
| 14 #include "ui/base/gestures/gesture_util.h" | 14 #include "ui/base/gestures/gesture_util.h" |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 | 17 |
| 18 GesturePoint::GesturePoint() | 18 GesturePoint::GesturePoint() |
| 19 : first_touch_time_(0.0), | 19 : first_touch_time_(0.0), |
| 20 second_last_touch_time_(0.0), | 20 second_last_touch_time_(0.0), |
| 21 last_touch_time_(0.0), | 21 last_touch_time_(0.0), |
| 22 second_last_tap_time_(0.0), | |
| 22 last_tap_time_(0.0), | 23 last_tap_time_(0.0), |
| 23 velocity_calculator_( | 24 velocity_calculator_( |
| 24 GestureConfiguration::points_buffered_for_velocity()), | 25 GestureConfiguration::points_buffered_for_velocity()), |
| 25 point_id_(-1), | 26 point_id_(-1), |
| 26 touch_id_(-1) { | 27 touch_id_(-1) { |
| 27 } | 28 } |
| 28 | 29 |
| 29 GesturePoint::~GesturePoint() {} | 30 GesturePoint::~GesturePoint() {} |
| 30 | 31 |
| 31 void GesturePoint::Reset() { | 32 void GesturePoint::Reset() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 velocity_calculator_.PointSeen(event.location().x(), | 70 velocity_calculator_.PointSeen(event.location().x(), |
| 70 event.location().y(), | 71 event.location().y(), |
| 71 event_timestamp_microseconds); | 72 event_timestamp_microseconds); |
| 72 } | 73 } |
| 73 | 74 |
| 74 UpdateEnclosingRectangle(event); | 75 UpdateEnclosingRectangle(event); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void GesturePoint::UpdateForTap() { | 78 void GesturePoint::UpdateForTap() { |
| 78 // Update the tap-position and time, and reset every other state. | 79 // Update the tap-position and time, and reset every other state. |
| 80 second_last_tap_position_ = last_tap_position_; | |
| 81 second_last_tap_time_ = last_tap_time_; | |
| 79 last_tap_time_ = last_touch_time_; | 82 last_tap_time_ = last_touch_time_; |
| 80 last_tap_position_ = last_touch_position_; | 83 last_tap_position_ = last_touch_position_; |
| 81 } | 84 } |
| 82 | 85 |
| 83 void GesturePoint::UpdateForScroll() { | 86 void GesturePoint::UpdateForScroll() { |
| 84 second_last_touch_position_ = last_touch_position_; | 87 second_last_touch_position_ = last_touch_position_; |
| 85 second_last_touch_time_ = last_touch_time_; | 88 second_last_touch_time_ = last_touch_time_; |
| 86 same_direction_count_ = gfx::Vector2d(); | 89 same_direction_count_ = gfx::Vector2d(); |
| 87 } | 90 } |
| 88 | 91 |
| 89 bool GesturePoint::IsInClickWindow(const TouchEvent& event) const { | 92 bool GesturePoint::IsInClickWindow(const TouchEvent& event) const { |
| 90 return IsInClickTimeWindow() && IsInsideManhattanSquare(event); | 93 return IsInClickTimeWindow() && IsInsideManhattanSquare(event); |
| 91 } | 94 } |
| 92 | 95 |
| 93 bool GesturePoint::IsInDoubleClickWindow(const TouchEvent& event) const { | 96 bool GesturePoint::IsInDoubleClickWindow(const TouchEvent& event) const { |
| 94 return IsInSecondClickTimeWindow() && | 97 return IsInSecondClickTimeWindow() && |
| 95 IsSecondClickInsideManhattanSquare(event); | 98 IsSecondClickInsideManhattanSquare(event); |
| 96 } | 99 } |
| 97 | 100 |
| 101 bool GesturePoint::IsInTripleClickWindow(const TouchEvent& event) const { | |
| 102 return IsInThirdClickTimeWindow() && | |
| 103 IsThirdClickInsideManhattanSquare(event); | |
| 104 } | |
| 105 | |
| 98 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const { | 106 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const { |
| 99 return event.type() == ui::ET_TOUCH_MOVED && | 107 return event.type() == ui::ET_TOUCH_MOVED && |
| 100 !IsInsideManhattanSquare(event); | 108 !IsInsideManhattanSquare(event); |
| 101 } | 109 } |
| 102 | 110 |
| 103 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) { | 111 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) { |
| 104 return IsOverMinFlickSpeed() && | 112 return IsOverMinFlickSpeed() && |
| 105 event.type() != ui::ET_TOUCH_CANCELLED; | 113 event.type() != ui::ET_TOUCH_CANCELLED; |
| 106 } | 114 } |
| 107 | 115 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 GestureConfiguration::min_touch_down_duration_in_seconds_for_click() && | 167 GestureConfiguration::min_touch_down_duration_in_seconds_for_click() && |
| 160 duration < | 168 duration < |
| 161 GestureConfiguration::max_touch_down_duration_in_seconds_for_click(); | 169 GestureConfiguration::max_touch_down_duration_in_seconds_for_click(); |
| 162 } | 170 } |
| 163 | 171 |
| 164 bool GesturePoint::IsInSecondClickTimeWindow() const { | 172 bool GesturePoint::IsInSecondClickTimeWindow() const { |
| 165 double duration = last_touch_time_ - last_tap_time_; | 173 double duration = last_touch_time_ - last_tap_time_; |
| 166 return duration < GestureConfiguration::max_seconds_between_double_click(); | 174 return duration < GestureConfiguration::max_seconds_between_double_click(); |
| 167 } | 175 } |
| 168 | 176 |
| 177 bool GesturePoint::IsInThirdClickTimeWindow() const { | |
| 178 double duration1 = last_touch_time_ - last_tap_time_; | |
| 179 double duration2 = last_tap_time_ - second_last_tap_time_; | |
| 180 return duration1 < GestureConfiguration::max_seconds_between_double_click() && | |
| 181 duration2 < GestureConfiguration::max_seconds_between_double_click(); | |
| 182 } | |
| 183 | |
|
sadrul
2013/05/28 17:48:46
Refactor IsInSecondClickTimeWindow and IsInThirdCl
Yufeng Shen (Slow to review)
2013/05/28 19:31:44
Done.
| |
| 169 bool GesturePoint::IsInsideManhattanSquare(const TouchEvent& event) const { | 184 bool GesturePoint::IsInsideManhattanSquare(const TouchEvent& event) const { |
| 170 return ui::gestures::IsInsideManhattanSquare(event.location(), | 185 return ui::gestures::IsInsideManhattanSquare(event.location(), |
| 171 first_touch_position_); | 186 first_touch_position_); |
| 172 } | 187 } |
| 173 | 188 |
| 174 bool GesturePoint::IsSecondClickInsideManhattanSquare( | 189 bool GesturePoint::IsSecondClickInsideManhattanSquare( |
| 175 const TouchEvent& event) const { | 190 const TouchEvent& event) const { |
| 176 int manhattan_distance = abs(event.location().x() - last_tap_position_.x()) + | 191 int manhattan_distance = abs(event.location().x() - last_tap_position_.x()) + |
| 177 abs(event.location().y() - last_tap_position_.y()); | 192 abs(event.location().y() - last_tap_position_.y()); |
| 178 return manhattan_distance < | 193 return manhattan_distance < |
| 179 GestureConfiguration::max_distance_between_taps_for_double_tap(); | 194 GestureConfiguration::max_distance_between_taps_for_double_tap(); |
| 180 } | 195 } |
| 181 | 196 |
| 197 bool GesturePoint::IsThirdClickInsideManhattanSquare( | |
| 198 const TouchEvent& event) const { | |
| 199 int manhattan_distance1 = | |
| 200 abs(event.location().x() - last_tap_position_.x()) + | |
| 201 abs(event.location().y() - last_tap_position_.y()); | |
| 202 int manhattan_distance2 = | |
| 203 abs(last_tap_position_.x() - second_last_tap_position_.x()) + | |
| 204 abs(last_tap_position_.y() - second_last_tap_position_.y()); | |
| 205 | |
| 206 return manhattan_distance1 < | |
| 207 GestureConfiguration::max_distance_between_taps_for_double_tap() && | |
| 208 manhattan_distance2 < | |
| 209 GestureConfiguration::max_distance_between_taps_for_double_tap(); | |
| 210 } | |
| 211 | |
|
sadrul
2013/05/28 17:48:46
Similarly,
IsLocationsInsideManhattanSquare(poin
Yufeng Shen (Slow to review)
2013/05/28 19:31:44
Done.
| |
| 182 bool GesturePoint::IsOverMinFlickSpeed() { | 212 bool GesturePoint::IsOverMinFlickSpeed() { |
| 183 return velocity_calculator_.VelocitySquared() > | 213 return velocity_calculator_.VelocitySquared() > |
| 184 GestureConfiguration::min_flick_speed_squared(); | 214 GestureConfiguration::min_flick_speed_squared(); |
| 185 } | 215 } |
| 186 | 216 |
| 187 void GesturePoint::UpdateEnclosingRectangle(const TouchEvent& event) { | 217 void GesturePoint::UpdateEnclosingRectangle(const TouchEvent& event) { |
| 188 int radius; | 218 int radius; |
| 189 | 219 |
| 190 // Ignore this TouchEvent if it has a radius larger than the maximum | 220 // Ignore this TouchEvent if it has a radius larger than the maximum |
| 191 // allowed radius size. | 221 // allowed radius size. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 208 event.location().y() - radius, | 238 event.location().y() - radius, |
| 209 radius * 2, | 239 radius * 2, |
| 210 radius * 2); | 240 radius * 2); |
| 211 if (IsInClickWindow(event)) | 241 if (IsInClickWindow(event)) |
| 212 enclosing_rect_.Union(rect); | 242 enclosing_rect_.Union(rect); |
| 213 else | 243 else |
| 214 enclosing_rect_ = rect; | 244 enclosing_rect_ = rect; |
| 215 } | 245 } |
| 216 | 246 |
| 217 } // namespace ui | 247 } // namespace ui |
| OLD | NEW |