X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fui%2Fevents%2Fgesture_detection%2Fgesture_detector.h;h=be8afafd82f95728897318be2439d4a783f94edd;hb=refs%2Fchanges%2F42%2F22542%2F1;hp=ff60905b39034d6b1095a1fc74b752fa0bb36f36;hpb=2f108dbacb161091e42a3479f4e171339b7e7623;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/ui/events/gesture_detection/gesture_detector.h b/src/ui/events/gesture_detection/gesture_detector.h index ff60905..be8afaf 100644 --- a/src/ui/events/gesture_detection/gesture_detector.h +++ b/src/ui/events/gesture_detection/gesture_detector.h @@ -23,13 +23,35 @@ class GestureDetector { struct GESTURE_DETECTION_EXPORT Config { Config(); ~Config(); + base::TimeDelta longpress_timeout; base::TimeDelta showpress_timeout; base::TimeDelta double_tap_timeout; - int scaled_touch_slop; - int scaled_double_tap_slop; - int scaled_minimum_fling_velocity; - int scaled_maximum_fling_velocity; + + // Distance a touch can wander before a scroll will occur (in dips). + float touch_slop; + + // Distance the first touch can wander before it is no longer considered a + // double tap (in dips). + float double_tap_slop; + + // Minimum velocity to initiate a fling (in dips/second). + float minimum_fling_velocity; + + // Maximum velocity of an initiated fling (in dips/second). + float maximum_fling_velocity; + + // Whether |OnSwipe| should be called after a secondary touch is released + // while a logical swipe gesture is active. Defaults to false. + bool swipe_enabled; + + // Minimum velocity to initiate a swipe (in dips/second). + float minimum_swipe_velocity; + + // Maximum angle of the swipe from its dominant component axis, between + // (0, 45] degrees. The closer this is to 0, the closer the dominant + // direction of the swipe must be to up, down left or right. + float maximum_swipe_deviation_angle; }; class GestureListener { @@ -39,10 +61,19 @@ class GestureDetector { virtual void OnShowPress(const MotionEvent& e) = 0; virtual bool OnSingleTapUp(const MotionEvent& e) = 0; virtual bool OnLongPress(const MotionEvent& e) = 0; - virtual bool OnScroll(const MotionEvent& e1, const MotionEvent& e2, - float distance_x, float distance_y) = 0; - virtual bool OnFling(const MotionEvent& e1, const MotionEvent& e2, - float velocity_x, float velocity_y) = 0; + virtual bool OnScroll(const MotionEvent& e1, + const MotionEvent& e2, + float distance_x, + float distance_y) = 0; + virtual bool OnFling(const MotionEvent& e1, + const MotionEvent& e2, + float velocity_x, + float velocity_y) = 0; + // Added for Chromium (Aura). + virtual bool OnSwipe(const MotionEvent& e1, + const MotionEvent& e2, + float velocity_x, + float velocity_y) = 0; }; class DoubleTapListener { @@ -65,10 +96,18 @@ class GestureDetector { virtual void OnShowPress(const MotionEvent& e) OVERRIDE; virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE; virtual bool OnLongPress(const MotionEvent& e) OVERRIDE; - virtual bool OnScroll(const MotionEvent& e1, const MotionEvent& e2, - float distance_x, float distance_y) OVERRIDE; - virtual bool OnFling(const MotionEvent& e1, const MotionEvent& e2, - float velocity_x, float velocity_y) OVERRIDE; + virtual bool OnScroll(const MotionEvent& e1, + const MotionEvent& e2, + float distance_x, + float distance_y) OVERRIDE; + virtual bool OnFling(const MotionEvent& e1, + const MotionEvent& e2, + float velocity_x, + float velocity_y) OVERRIDE; + virtual bool OnSwipe(const MotionEvent& e1, + const MotionEvent& e2, + float velocity_x, + float velocity_y) OVERRIDE; // DoubleTapListener implementation. virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE; @@ -83,16 +122,16 @@ class GestureDetector { bool OnTouchEvent(const MotionEvent& ev); - void set_doubletap_listener(DoubleTapListener* double_tap_listener) { - DCHECK(!is_double_tapping_ || double_tap_listener_); - double_tap_listener_ = double_tap_listener; - } + // Setting a valid |double_tap_listener| will enable double-tap detection, + // wherein calls to |OnSimpleTapConfirmed| are delayed by the tap timeout. + // Note: The listener must never be changed while |is_double_tapping| is true. + void SetDoubleTapListener(DoubleTapListener* double_tap_listener); + + bool has_doubletap_listener() const { return double_tap_listener_ != NULL; } - void set_is_longpress_enabled(bool is_longpress_enabled) { - is_longpress_enabled_ = is_longpress_enabled; - } + bool is_double_tapping() const { return is_double_tapping_; } - bool is_longpress_enabled() const { return is_longpress_enabled_; } + void set_longpress_enabled(bool enabled) { longpress_enabled_ = enabled; } private: void Init(const Config& config); @@ -110,11 +149,13 @@ class GestureDetector { GestureListener* const listener_; DoubleTapListener* double_tap_listener_; - int touch_slop_square_; - int double_tap_touch_slop_square_; - int double_tap_slop_square_; - int min_fling_velocity_; - int max_fling_velocity_; + float touch_slop_square_; + float double_tap_touch_slop_square_; + float double_tap_slop_square_; + float min_fling_velocity_; + float max_fling_velocity_; + float min_swipe_velocity_; + float min_swipe_direction_component_ratio_; base::TimeDelta double_tap_timeout_; bool still_down_; @@ -135,7 +176,8 @@ class GestureDetector { float down_focus_x_; float down_focus_y_; - bool is_longpress_enabled_; + bool longpress_enabled_; + bool swipe_enabled_; // Determines speed during touch scrolling. VelocityTrackerState velocity_tracker_;