| 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 IsInClickAggregateTimeWindow(last_tap_time_, last_touch_time_) && |
| 95 IsSecondClickInsideManhattanSquare(event); | 98 IsPointInsideManhattanSquare(event.location(), last_tap_position_); |
| 99 } |
| 100 |
| 101 bool GesturePoint::IsInTripleClickWindow(const TouchEvent& event) const { |
| 102 return IsInClickAggregateTimeWindow(last_tap_time_, last_touch_time_) && |
| 103 IsInClickAggregateTimeWindow(second_last_tap_time_, last_tap_time_) && |
| 104 IsPointInsideManhattanSquare(event.location(), last_tap_position_) && |
| 105 IsPointInsideManhattanSquare(last_tap_position_, |
| 106 second_last_tap_position_); |
| 96 } | 107 } |
| 97 | 108 |
| 98 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const { | 109 bool GesturePoint::IsInScrollWindow(const TouchEvent& event) const { |
| 99 return event.type() == ui::ET_TOUCH_MOVED && | 110 return event.type() == ui::ET_TOUCH_MOVED && |
| 100 !IsInsideManhattanSquare(event); | 111 !IsInsideManhattanSquare(event); |
| 101 } | 112 } |
| 102 | 113 |
| 103 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) { | 114 bool GesturePoint::IsInFlickWindow(const TouchEvent& event) { |
| 104 return IsOverMinFlickSpeed() && | 115 return IsOverMinFlickSpeed() && |
| 105 event.type() != ui::ET_TOUCH_CANCELLED; | 116 event.type() != ui::ET_TOUCH_CANCELLED; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 165 } |
| 155 | 166 |
| 156 bool GesturePoint::IsInClickTimeWindow() const { | 167 bool GesturePoint::IsInClickTimeWindow() const { |
| 157 double duration = last_touch_time_ - first_touch_time_; | 168 double duration = last_touch_time_ - first_touch_time_; |
| 158 return duration >= | 169 return duration >= |
| 159 GestureConfiguration::min_touch_down_duration_in_seconds_for_click() && | 170 GestureConfiguration::min_touch_down_duration_in_seconds_for_click() && |
| 160 duration < | 171 duration < |
| 161 GestureConfiguration::max_touch_down_duration_in_seconds_for_click(); | 172 GestureConfiguration::max_touch_down_duration_in_seconds_for_click(); |
| 162 } | 173 } |
| 163 | 174 |
| 164 bool GesturePoint::IsInSecondClickTimeWindow() const { | 175 bool GesturePoint::IsInClickAggregateTimeWindow(double before, |
| 165 double duration = last_touch_time_ - last_tap_time_; | 176 double after) const { |
| 177 double duration = after - before; |
| 166 return duration < GestureConfiguration::max_seconds_between_double_click(); | 178 return duration < GestureConfiguration::max_seconds_between_double_click(); |
| 167 } | 179 } |
| 168 | 180 |
| 169 bool GesturePoint::IsInsideManhattanSquare(const TouchEvent& event) const { | 181 bool GesturePoint::IsInsideManhattanSquare(const TouchEvent& event) const { |
| 170 return ui::gestures::IsInsideManhattanSquare(event.location(), | 182 return ui::gestures::IsInsideManhattanSquare(event.location(), |
| 171 first_touch_position_); | 183 first_touch_position_); |
| 172 } | 184 } |
| 173 | 185 |
| 174 bool GesturePoint::IsSecondClickInsideManhattanSquare( | 186 bool GesturePoint::IsPointInsideManhattanSquare(gfx::Point p1, |
| 175 const TouchEvent& event) const { | 187 gfx::Point p2) const { |
| 176 int manhattan_distance = abs(event.location().x() - last_tap_position_.x()) + | 188 int manhattan_distance = abs(p1.x() - p2.x()) + abs(p1.y() - p2.y()); |
| 177 abs(event.location().y() - last_tap_position_.y()); | |
| 178 return manhattan_distance < | 189 return manhattan_distance < |
| 179 GestureConfiguration::max_distance_between_taps_for_double_tap(); | 190 GestureConfiguration::max_distance_between_taps_for_double_tap(); |
| 180 } | 191 } |
| 181 | 192 |
| 182 bool GesturePoint::IsOverMinFlickSpeed() { | 193 bool GesturePoint::IsOverMinFlickSpeed() { |
| 183 return velocity_calculator_.VelocitySquared() > | 194 return velocity_calculator_.VelocitySquared() > |
| 184 GestureConfiguration::min_flick_speed_squared(); | 195 GestureConfiguration::min_flick_speed_squared(); |
| 185 } | 196 } |
| 186 | 197 |
| 187 void GesturePoint::UpdateEnclosingRectangle(const TouchEvent& event) { | 198 void GesturePoint::UpdateEnclosingRectangle(const TouchEvent& event) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 208 event.location().y() - radius, | 219 event.location().y() - radius, |
| 209 radius * 2, | 220 radius * 2, |
| 210 radius * 2); | 221 radius * 2); |
| 211 if (IsInClickWindow(event)) | 222 if (IsInClickWindow(event)) |
| 212 enclosing_rect_.Union(rect); | 223 enclosing_rect_.Union(rect); |
| 213 else | 224 else |
| 214 enclosing_rect_ = rect; | 225 enclosing_rect_ = rect; |
| 215 } | 226 } |
| 216 | 227 |
| 217 } // namespace ui | 228 } // namespace ui |
| OLD | NEW |