gesture_provider.h revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
18b7521eb38878822be3817270cc074ee1e22095dKenny Root// Copyright 2014 The Chromium Authors. All rights reserved. 28b7521eb38878822be3817270cc074ee1e22095dKenny Root// Use of this source code is governed by a BSD-style license that can be 38b7521eb38878822be3817270cc074ee1e22095dKenny Root// found in the LICENSE file. 48b7521eb38878822be3817270cc074ee1e22095dKenny Root 58b7521eb38878822be3817270cc074ee1e22095dKenny Root#ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_ 68b7521eb38878822be3817270cc074ee1e22095dKenny Root#define UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_ 78b7521eb38878822be3817270cc074ee1e22095dKenny Root 88b7521eb38878822be3817270cc074ee1e22095dKenny Root#include "base/basictypes.h" 98b7521eb38878822be3817270cc074ee1e22095dKenny Root#include "base/memory/scoped_ptr.h" 108b7521eb38878822be3817270cc074ee1e22095dKenny Root#include "ui/events/gesture_detection/gesture_detection_export.h" 118b7521eb38878822be3817270cc074ee1e22095dKenny Root#include "ui/events/gesture_detection/gesture_detector.h" 128b7521eb38878822be3817270cc074ee1e22095dKenny Root#include "ui/events/gesture_detection/gesture_event_data.h" 138b7521eb38878822be3817270cc074ee1e22095dKenny Root#include "ui/events/gesture_detection/scale_gesture_detector.h" 148b7521eb38878822be3817270cc074ee1e22095dKenny Root#include "ui/events/gesture_detection/snap_scroll_controller.h" 158b7521eb38878822be3817270cc074ee1e22095dKenny Root#include "ui/gfx/display.h" 168b7521eb38878822be3817270cc074ee1e22095dKenny Root 17860d2707ce126ef8f66e3eac7ceeab6d24218cd8Kenny Rootnamespace ui { 188b7521eb38878822be3817270cc074ee1e22095dKenny Root 198b7521eb38878822be3817270cc074ee1e22095dKenny Rootclass GESTURE_DETECTION_EXPORT GestureProviderClient { 208b7521eb38878822be3817270cc074ee1e22095dKenny Root public: 218b7521eb38878822be3817270cc074ee1e22095dKenny Root virtual ~GestureProviderClient() {} 228b7521eb38878822be3817270cc074ee1e22095dKenny Root virtual void OnGestureEvent(const GestureEventData& gesture) = 0; 238b7521eb38878822be3817270cc074ee1e22095dKenny Root}; 24f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root 258b7521eb38878822be3817270cc074ee1e22095dKenny Root// Given a stream of |MotionEvent|'s, provides gesture detection and gesture 268b7521eb38878822be3817270cc074ee1e22095dKenny Root// event dispatch. 278b7521eb38878822be3817270cc074ee1e22095dKenny Rootclass GESTURE_DETECTION_EXPORT GestureProvider { 2811b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root public: 2911b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root struct GESTURE_DETECTION_EXPORT Config { 308b7521eb38878822be3817270cc074ee1e22095dKenny Root Config(); 318b7521eb38878822be3817270cc074ee1e22095dKenny Root ~Config(); 3247cc520bd63c1eabfdef23cbab10457701f2a395Kenny Root gfx::Display display; 338b7521eb38878822be3817270cc074ee1e22095dKenny Root GestureDetector::Config gesture_detector_config; 348b7521eb38878822be3817270cc074ee1e22095dKenny Root ScaleGestureDetector::Config scale_gesture_detector_config; 358b7521eb38878822be3817270cc074ee1e22095dKenny Root 368b7521eb38878822be3817270cc074ee1e22095dKenny Root // If |disable_click_delay| is true and double-tap support is disabled, 378b7521eb38878822be3817270cc074ee1e22095dKenny Root // there will be no delay before tap events. When double-tap support is 388b7521eb38878822be3817270cc074ee1e22095dKenny Root // enabled, there will always be a delay before a tap event is fired, in 398b7521eb38878822be3817270cc074ee1e22095dKenny Root // order to allow the double tap gesture to occur without firing any tap 408b7521eb38878822be3817270cc074ee1e22095dKenny Root // events. 418b7521eb38878822be3817270cc074ee1e22095dKenny Root bool disable_click_delay; 428b7521eb38878822be3817270cc074ee1e22095dKenny Root 438b7521eb38878822be3817270cc074ee1e22095dKenny Root // If |gesture_begin_end_types_enabled| is true, fire an ET_GESTURE_BEGIN 448b7521eb38878822be3817270cc074ee1e22095dKenny Root // event for every added touch point, and an ET_GESTURE_END event for every 458b7521eb38878822be3817270cc074ee1e22095dKenny Root // removed touch point. This requires one ACTION_CANCEL event to be sent per 4647cc520bd63c1eabfdef23cbab10457701f2a395Kenny Root // touch point, which only occurs on Aura. Defaults to false. 4738c70d393f14cf0963a289caefb72e6ac14e23d3Joel Dice bool gesture_begin_end_types_enabled; 4847cc520bd63c1eabfdef23cbab10457701f2a395Kenny Root 4947cc520bd63c1eabfdef23cbab10457701f2a395Kenny Root // The min and max size (both length and width, in dips) of the generated 5047cc520bd63c1eabfdef23cbab10457701f2a395Kenny Root // bounding box for all gesture types. This is useful for touch streams 5147cc520bd63c1eabfdef23cbab10457701f2a395Kenny Root // that may report zero or unreasonably small or large touch sizes. 5211b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root // Note that these bounds are only applied for touch or unknown tool types; 5311b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root // mouse and stylus-derived gestures will not be affected. 54d4600d69dba0f1df24e8df7328fa473632c32822Kenny Root // Both values default to 0 (disabled). 5511b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root float min_gesture_bounds_length; 5611b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root float max_gesture_bounds_length; 5711b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root }; 5811b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root 5911b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root GestureProvider(const Config& config, GestureProviderClient* client); 6011b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root ~GestureProvider(); 6111b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root 6211b3e7025853f061e2f0e0ce1e248e730eca721eKenny Root // Handle the incoming MotionEvent, returning false if the event could not 63f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root // be handled. 64f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root bool OnTouchEvent(const MotionEvent& event); 65f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root 66f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root // Update whether multi-touch pinch zoom is supported by the platform. 67f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root void SetMultiTouchZoomSupportEnabled(bool enabled); 68f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root 69f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root // Update whether double-tap gestures are supported by the platform. 70f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root void SetDoubleTapSupportForPlatformEnabled(bool enabled); 71f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root 72f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root // Update whether double-tap gesture detection should be suppressed, e.g., 73dac92c69d3a147ea57bc7bd28c96b6365c1988e2Kenny Root // if the page scale is fixed or the page has a mobile viewport. This disables 74dac92c69d3a147ea57bc7bd28c96b6365c1988e2Kenny Root // the tap delay, allowing rapid and responsive single-tap gestures. 75dac92c69d3a147ea57bc7bd28c96b6365c1988e2Kenny Root void SetDoubleTapSupportForPageEnabled(bool enabled); 76dac92c69d3a147ea57bc7bd28c96b6365c1988e2Kenny Root 77f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root // Whether a scroll gesture is in-progress. 78f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root bool IsScrollInProgress() const; 798b7521eb38878822be3817270cc074ee1e22095dKenny Root 808b7521eb38878822be3817270cc074ee1e22095dKenny Root // Whether a pinch gesture is in-progress (i.e. a pinch update has been 818b7521eb38878822be3817270cc074ee1e22095dKenny Root // forwarded and detection is still active). 828b7521eb38878822be3817270cc074ee1e22095dKenny Root bool IsPinchInProgress() const; 83f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root 84f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root // Whether a double-tap gesture is in-progress (either double-tap or 85f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root // double-tap drag zoom). 86f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root bool IsDoubleTapInProgress() const; 87f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root 88f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root // May be NULL if there is no currently active touch sequence. 89f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root const ui::MotionEvent* current_down_event() const { 90f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root return current_down_event_.get(); 91f24ba0620d88b7d71ddb089b97d29fb1b073718dKenny Root } 928b7521eb38878822be3817270cc074ee1e22095dKenny Root 938b7521eb38878822be3817270cc074ee1e22095dKenny Root private: 948b7521eb38878822be3817270cc074ee1e22095dKenny Root void InitGestureDetectors(const Config& config); 958b7521eb38878822be3817270cc074ee1e22095dKenny Root 968b7521eb38878822be3817270cc074ee1e22095dKenny Root bool CanHandle(const MotionEvent& event) const; 978b7521eb38878822be3817270cc074ee1e22095dKenny Root 988b7521eb38878822be3817270cc074ee1e22095dKenny Root void Fling(const MotionEvent& e, float velocity_x, float velocity_y); 998b7521eb38878822be3817270cc074ee1e22095dKenny Root void Send(GestureEventData gesture); 1008b7521eb38878822be3817270cc074ee1e22095dKenny Root bool SendLongTapIfNecessary(const MotionEvent& event); 1018b7521eb38878822be3817270cc074ee1e22095dKenny Root void EndTouchScrollIfNecessary(const MotionEvent& event, 1028b7521eb38878822be3817270cc074ee1e22095dKenny Root bool send_scroll_end_event); 1038b7521eb38878822be3817270cc074ee1e22095dKenny Root void OnTouchEventHandlingBegin(const MotionEvent& event); 1048b7521eb38878822be3817270cc074ee1e22095dKenny Root void OnTouchEventHandlingEnd(const MotionEvent& event); 1058b7521eb38878822be3817270cc074ee1e22095dKenny Root void UpdateDoubleTapDetectionSupport(); 1068b7521eb38878822be3817270cc074ee1e22095dKenny Root 107ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root GestureProviderClient* const client_; 108ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root 109ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root class GestureListenerImpl; 110ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root friend class GestureListenerImpl; 111ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root scoped_ptr<GestureListenerImpl> gesture_listener_; 112ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root 113ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root class ScaleGestureListenerImpl; 114ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root friend class ScaleGestureListenerImpl; 115ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root scoped_ptr<ScaleGestureListenerImpl> scale_gesture_listener_; 1168b7521eb38878822be3817270cc074ee1e22095dKenny Root 1178b7521eb38878822be3817270cc074ee1e22095dKenny Root scoped_ptr<MotionEvent> current_down_event_; 1188b7521eb38878822be3817270cc074ee1e22095dKenny Root 1198b7521eb38878822be3817270cc074ee1e22095dKenny Root // Whether the respective {SCROLL,PINCH}_BEGIN gestures have been terminated 1208b7521eb38878822be3817270cc074ee1e22095dKenny Root // with a {SCROLL,PINCH}_END. 121ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root bool touch_scroll_in_progress_; 122ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root bool pinch_in_progress_; 123ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root 124ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root // Whether double-tap gesture detection is currently supported. 125ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root bool double_tap_support_for_page_; 126ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root bool double_tap_support_for_platform_; 127ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root 128ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root // Keeps track of the current GESTURE_LONG_PRESS event. If a context menu is 129ba1ea0caa5d6059e73b67068819e5948cfa1bc95Kenny Root // opened after a GESTURE_LONG_PRESS, this is used to insert a 1308b7521eb38878822be3817270cc074ee1e22095dKenny Root // GESTURE_TAP_CANCEL for removing any ::active styling. 1318b7521eb38878822be3817270cc074ee1e22095dKenny Root base::TimeTicks current_longpress_time_; 1328b7521eb38878822be3817270cc074ee1e22095dKenny Root 1338b7521eb38878822be3817270cc074ee1e22095dKenny Root const bool gesture_begin_end_types_enabled_; 1348b7521eb38878822be3817270cc074ee1e22095dKenny Root 1358b7521eb38878822be3817270cc074ee1e22095dKenny Root const float min_gesture_bounds_length_; 1368b7521eb38878822be3817270cc074ee1e22095dKenny Root const float max_gesture_bounds_length_; 1378b7521eb38878822be3817270cc074ee1e22095dKenny Root}; 1388b7521eb38878822be3817270cc074ee1e22095dKenny Root 1398b7521eb38878822be3817270cc074ee1e22095dKenny Root} // namespace ui 140f42ec17cfa43a002814e901d63ae8a93d77f7fc3Kenny Root 141f42ec17cfa43a002814e901d63ae8a93d77f7fc3Kenny Root#endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_ 142f42ec17cfa43a002814e901d63ae8a93d77f7fc3Kenny Root