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/aura/gestures/gesture_point.h" | 5 #include "ui/aura/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/aura/event.h" | 10 #include "ui/aura/event.h" |
| 11 #include "ui/aura/gestures/gesture_configuration.h" | 11 #include "ui/aura/gestures/gesture_configuration.h" |
| 12 #include "ui/base/events.h" | 12 #include "ui/base/events.h" |
| 13 | 13 |
| 14 namespace { | |
| 15 | |
| 16 const int kMinRailBreakVelocity = 200; | |
| 17 const int kMinScrollDeltaSquared = 5 * 5; | |
| 18 const int kRailBreakProportion = 15; | |
| 19 const int kRailStartProportion = 2; | |
| 20 const int kBufferedPoints = 10; | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 namespace aura { | 14 namespace aura { |
| 25 | 15 |
| 26 GesturePoint::GesturePoint() | 16 GesturePoint::GesturePoint() |
| 27 : first_touch_time_(0.0), | 17 : first_touch_time_(0.0), |
| 28 last_touch_time_(0.0), | 18 last_touch_time_(0.0), |
| 29 last_tap_time_(0.0), | 19 last_tap_time_(0.0), |
| 30 velocity_calculator_(kBufferedPoints), | 20 velocity_calculator_( |
| 21 GestureConfiguration::points_buffered_for_velocity()), | |
|
girard
2012/03/20 18:30:59
As per my other comment. This should not be confi
| |
| 31 point_id_(-1) { | 22 point_id_(-1) { |
| 32 } | 23 } |
| 33 | 24 |
| 34 GesturePoint::~GesturePoint() {} | 25 GesturePoint::~GesturePoint() {} |
| 35 | 26 |
| 36 void GesturePoint::Reset() { | 27 void GesturePoint::Reset() { |
| 37 first_touch_time_ = last_touch_time_ = 0.0; | 28 first_touch_time_ = last_touch_time_ = 0.0; |
| 38 velocity_calculator_.ClearHistory(); | 29 velocity_calculator_.ClearHistory(); |
| 39 point_id_ = -1; | 30 point_id_ = -1; |
| 40 } | 31 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 float x_diff = point.last_touch_position_.x() - last_touch_position_.x(); | 94 float x_diff = point.last_touch_position_.x() - last_touch_position_.x(); |
| 104 float y_diff = point.last_touch_position_.y() - last_touch_position_.y(); | 95 float y_diff = point.last_touch_position_.y() - last_touch_position_.y(); |
| 105 return sqrt(x_diff * x_diff + y_diff * y_diff); | 96 return sqrt(x_diff * x_diff + y_diff * y_diff); |
| 106 } | 97 } |
| 107 | 98 |
| 108 bool GesturePoint::HasEnoughDataToEstablishRail() const { | 99 bool GesturePoint::HasEnoughDataToEstablishRail() const { |
| 109 int dx = x_delta(); | 100 int dx = x_delta(); |
| 110 int dy = y_delta(); | 101 int dy = y_delta(); |
| 111 | 102 |
| 112 int delta_squared = dx * dx + dy * dy; | 103 int delta_squared = dx * dx + dy * dy; |
| 113 return delta_squared > kMinScrollDeltaSquared; | 104 return delta_squared > GestureConfiguration::min_scroll_delta_squared(); |
| 114 } | 105 } |
| 115 | 106 |
| 116 bool GesturePoint::IsInHorizontalRailWindow() const { | 107 bool GesturePoint::IsInHorizontalRailWindow() const { |
| 117 int dx = x_delta(); | 108 int dx = x_delta(); |
| 118 int dy = y_delta(); | 109 int dy = y_delta(); |
| 119 return abs(dx) > kRailStartProportion * abs(dy); | 110 return abs(dx) > GestureConfiguration::rail_start_proportion() * abs(dy); |
| 120 } | 111 } |
| 121 | 112 |
| 122 bool GesturePoint::IsInVerticalRailWindow() const { | 113 bool GesturePoint::IsInVerticalRailWindow() const { |
| 123 int dx = x_delta(); | 114 int dx = x_delta(); |
| 124 int dy = y_delta(); | 115 int dy = y_delta(); |
| 125 return abs(dy) > kRailStartProportion * abs(dx); | 116 return abs(dy) > GestureConfiguration::rail_start_proportion() * abs(dx); |
| 126 } | 117 } |
| 127 | 118 |
| 128 bool GesturePoint::BreaksHorizontalRail() { | 119 bool GesturePoint::BreaksHorizontalRail() { |
| 129 float vx = XVelocity(); | 120 float vx = XVelocity(); |
| 130 float vy = YVelocity(); | 121 float vy = YVelocity(); |
| 131 return fabs(vy) > kRailBreakProportion * fabs(vx) + kMinRailBreakVelocity; | 122 return fabs(vy) > GestureConfiguration::rail_break_proportion() * fabs(vx) + |
| 123 GestureConfiguration::min_rail_break_velocity(); | |
| 132 } | 124 } |
| 133 | 125 |
| 134 bool GesturePoint::BreaksVerticalRail() { | 126 bool GesturePoint::BreaksVerticalRail() { |
| 135 float vx = XVelocity(); | 127 float vx = XVelocity(); |
| 136 float vy = YVelocity(); | 128 float vy = YVelocity(); |
| 137 return fabs(vx) > kRailBreakProportion * fabs(vy) + kMinRailBreakVelocity; | 129 return fabs(vx) > GestureConfiguration::rail_break_proportion() * fabs(vy) + |
| 130 GestureConfiguration::min_rail_break_velocity(); | |
| 138 } | 131 } |
| 139 | 132 |
| 140 bool GesturePoint::IsInClickTimeWindow() const { | 133 bool GesturePoint::IsInClickTimeWindow() const { |
| 141 double duration = last_touch_time_ - first_touch_time_; | 134 double duration = last_touch_time_ - first_touch_time_; |
| 142 return duration >= | 135 return duration >= |
| 143 GestureConfiguration::min_touch_down_duration_in_seconds_for_click() && | 136 GestureConfiguration::min_touch_down_duration_in_seconds_for_click() && |
| 144 duration < | 137 duration < |
| 145 GestureConfiguration::max_touch_down_duration_in_seconds_for_click(); | 138 GestureConfiguration::max_touch_down_duration_in_seconds_for_click(); |
| 146 } | 139 } |
| 147 | 140 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 164 return manhattanDistance < | 157 return manhattanDistance < |
| 165 GestureConfiguration::max_touch_move_in_pixels_for_click(); | 158 GestureConfiguration::max_touch_move_in_pixels_for_click(); |
| 166 } | 159 } |
| 167 | 160 |
| 168 bool GesturePoint::IsOverMinFlickSpeed() { | 161 bool GesturePoint::IsOverMinFlickSpeed() { |
| 169 return velocity_calculator_.VelocitySquared() > | 162 return velocity_calculator_.VelocitySquared() > |
| 170 GestureConfiguration::min_flick_speed_squared(); | 163 GestureConfiguration::min_flick_speed_squared(); |
| 171 } | 164 } |
| 172 | 165 |
| 173 } // namespace aura | 166 } // namespace aura |
| OLD | NEW |