OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 CHROME_RENDERER_GESTURE_MANAGER_H_ |
| 6 #define CHROME_RENDERER_GESTURE_MANAGER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/singleton.h" |
| 10 |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
| 12 |
| 13 class RenderWidget; |
| 14 |
| 15 namespace WebKit { |
| 16 class WebTouchEvent; |
| 17 class WebTouchPoint; |
| 18 } |
| 19 |
| 20 // A GestureManager singleton detects gestures occurring in the |
| 21 // incoming feed of touch events in the Renderer. In response to |
| 22 // a given touch event, the GestureManager, updates its internal state |
| 23 // and optionally dispatches synthetic events to the invoking |
| 24 // RenderWidget. |
| 25 // |
| 26 // This GestureManager is a singleton in the renderer process and differs |
| 27 // from the GestureManager found in the browser process. |
| 28 // A subsequent CL will unify these and provide more complete |
| 29 // functionality. |
| 30 class GestureManager /* : public AbstractGestureManager */ { |
| 31 public: |
| 32 // The states of the gesture manager state machine. |
| 33 enum SyntheticCandidateGesture { |
| 34 NO_GESTURE, |
| 35 PENDING_SYNTHETIC_CLICK, |
| 36 SCROLL, |
| 37 }; |
| 38 |
| 39 virtual ~GestureManager(); |
| 40 static GestureManager* Get(); |
| 41 |
| 42 // Invoked for each touch event that could contribute to the current gesture. |
| 43 // Takes the event and the RenderWidget that originated it and which will also |
| 44 // be the target of any generated synthetic event. Finally, previously_handled |
| 45 // specifies if the event was actually handled explicitly by a WebWidget. |
| 46 // Returns true if the event resulted in firing a synthetic event. |
| 47 virtual bool ProcessTouchEventForGesture(const WebKit::WebTouchEvent& event, |
| 48 RenderWidget* source, |
| 49 bool previously_handled); |
| 50 |
| 51 protected: |
| 52 GestureManager(); |
| 53 |
| 54 private: |
| 55 // Dispatch a mouseDown/mouseUp/Click sequence. |
| 56 void DispatchSyntheticClick(RenderWidget* w, |
| 57 const WebKit::WebTouchEvent& event, |
| 58 const WebKit::WebTouchPoint& p); |
| 59 |
| 60 // True for a time within the click interval. |
| 61 bool IsInClickTimeWindow(double ts); |
| 62 |
| 63 // True for a point p still inside the thresholded square. |
| 64 bool IsInsideManhattanSquare(const WebKit::WebTouchPoint& p); |
| 65 |
| 66 // Scroll the screen. |
| 67 void ScrollViaTouchMotion(const WebKit::WebTouchPoint& p, RenderWidget* w); |
| 68 |
| 69 friend struct DefaultSingletonTraits<GestureManager>; |
| 70 |
| 71 // The synthetic candidate gesture to fire at the end of a touch event |
| 72 // sequence. |
| 73 SyntheticCandidateGesture candidate_gesture_; |
| 74 |
| 75 // Location of first touch. |
| 76 WebKit::WebPoint first_touch_position_; |
| 77 |
| 78 // Time of first touch. |
| 79 double first_touch_time_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(GestureManager); |
| 82 }; |
| 83 |
| 84 #endif // CHROME_RENDERER_GESTURE_MANAGER_H_ |
OLD | NEW |