| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UI_AURA_GESTURES_GESTURE_POINT_H_ |
| 6 #define UI_AURA_GESTURES_GESTURE_POINT_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "ui/gfx/point.h" |
| 11 |
| 12 namespace aura { |
| 13 class TouchEvent; |
| 14 |
| 15 // Gesture state. |
| 16 enum GestureState { |
| 17 GS_NO_GESTURE, |
| 18 GS_PENDING_SYNTHETIC_CLICK, |
| 19 GS_SCROLL, |
| 20 }; |
| 21 |
| 22 // A GesturePoint represents a single touch-point/finger during a gesture |
| 23 // recognition process. |
| 24 class GesturePoint { |
| 25 public: |
| 26 GesturePoint(); |
| 27 virtual ~GesturePoint() {} |
| 28 |
| 29 // Resets various states. |
| 30 void Reset(); |
| 31 |
| 32 // Updates some states when a Tap gesture has been recognized for this point. |
| 33 void UpdateForTap(); |
| 34 |
| 35 // Updates some states when a Scroll gesture has been recognized for this |
| 36 // point. |
| 37 void UpdateForScroll(); |
| 38 |
| 39 // Updates states depending on the event and the gesture-state. |
| 40 void UpdateValues(const TouchEvent& event, GestureState state); |
| 41 |
| 42 // Responds according to the state of the gesture point (i.e. the point can |
| 43 // represent a click or scroll etc.) |
| 44 bool IsInClickWindow(const TouchEvent& event) const; |
| 45 bool IsInDoubleClickWindow(const TouchEvent& event) const; |
| 46 bool IsInScrollWindow(const TouchEvent& event) const; |
| 47 bool IsInFlickWindow(const TouchEvent& event) const; |
| 48 |
| 49 const gfx::Point& first_touch_position() const { |
| 50 return first_touch_position_; |
| 51 } |
| 52 |
| 53 double last_touch_time() const { return last_touch_time_; } |
| 54 const gfx::Point& last_touch_position() const { return last_touch_position_; } |
| 55 |
| 56 double x_delta() const { |
| 57 return last_touch_position_.x() - first_touch_position_.x(); |
| 58 } |
| 59 |
| 60 double y_delta() const { |
| 61 return last_touch_position_.y() - first_touch_position_.y(); |
| 62 } |
| 63 |
| 64 float x_velocity() const { return x_velocity_; } |
| 65 float y_velocity() const { return y_velocity_; } |
| 66 |
| 67 private: |
| 68 // Various statistical functions to manipulate gestures. |
| 69 bool IsInClickTimeWindow() const; |
| 70 bool IsInSecondClickTimeWindow() const; |
| 71 bool IsInsideManhattanSquare(const TouchEvent& event) const; |
| 72 bool IsSecondClickInsideManhattanSquare(const TouchEvent& event) const; |
| 73 bool IsOverMinFlickSpeed() const; |
| 74 |
| 75 gfx::Point first_touch_position_; |
| 76 double first_touch_time_; |
| 77 gfx::Point last_touch_position_; |
| 78 double last_touch_time_; |
| 79 |
| 80 double last_tap_time_; |
| 81 gfx::Point last_tap_position_; |
| 82 |
| 83 float x_velocity_; |
| 84 float y_velocity_; |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(GesturePoint); |
| 87 }; |
| 88 |
| 89 } // namespace aura |
| 90 |
| 91 #endif // UI_AURA_GESTURES_GESTURE_POINT_H_ |
| OLD | NEW |