initial import
[vuplus_webkit] / Source / WebCore / platform / chromium / GestureRecognizerChromium.h
1 /*
2  * Copyright (c) 2011, Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef GestureRecognizerChromium_h
32 #define GestureRecognizerChromium_h
33
34 #include "PlatformGestureRecognizer.h"
35
36 #include "PlatformTouchEvent.h"
37 #include "PlatformTouchPoint.h"
38 #include <wtf/HashMap.h>
39
40 class InspectableGestureRecognizerChromium;
41
42 namespace WebCore {
43
44 class PlatformGestureEvent;
45
46 class GestureRecognizerChromium : public PlatformGestureRecognizer  {
47 public:
48     enum State {
49         NoGesture,
50         PendingSyntheticClick,
51         Scroll,
52         FirstClickReceived,
53         PendingDoubleClick,
54     };
55
56     typedef Vector<PlatformGestureEvent>* Gestures;
57     typedef bool (GestureRecognizerChromium::*GestureTransitionFunction)(const PlatformTouchPoint&, Gestures);
58
59     GestureRecognizerChromium();
60     ~GestureRecognizerChromium();
61
62     virtual void reset();
63     virtual PlatformGestureRecognizer::PassGestures  processTouchEventForGestures(const PlatformTouchEvent&, bool defaultPrevented);
64     State state() { return m_state; }
65
66 private:
67     friend class ::InspectableGestureRecognizerChromium;
68
69     static unsigned int signature(State, unsigned, PlatformTouchPoint::State, bool);
70     void addEdgeFunction(State, unsigned finger, PlatformTouchPoint::State, bool touchHandledByJavaScript, GestureTransitionFunction);
71     void appendTapDownGestureEvent(const PlatformTouchPoint&, Gestures);
72     void appendClickGestureEvent(const PlatformTouchPoint&, Gestures);
73     void appendDoubleClickGestureEvent(const PlatformTouchPoint&, Gestures);
74     void appendScrollGestureBegin(const PlatformTouchPoint&, Gestures);
75     void appendScrollGestureEnd(const PlatformTouchPoint&, Gestures);
76     void appendScrollGestureUpdate(const PlatformTouchPoint&, Gestures);
77     bool isInClickTimeWindow();
78     bool isInSecondClickTimeWindow();
79     bool isInsideManhattanSquare(const PlatformTouchPoint&);
80     void setState(State value) { m_state = value; }
81     void updateValues(double touchTime, const PlatformTouchPoint&);
82
83     bool click(const PlatformTouchPoint&, Gestures);
84     bool isClickOrScroll(const PlatformTouchPoint&, Gestures);
85     bool inScroll(const PlatformTouchPoint&, Gestures);
86     bool noGesture(const PlatformTouchPoint&, Gestures);
87     bool touchDown(const PlatformTouchPoint&, Gestures);
88     bool scrollEnd(const PlatformTouchPoint&, Gestures);
89
90     bool doubleClick(const PlatformTouchPoint&, Gestures);
91     bool maybeDoubleClick(const PlatformTouchPoint&, Gestures);
92
93     WTF::HashMap<int, GestureTransitionFunction> m_edgeFunctions;
94     IntPoint m_firstTouchPosition;
95     IntPoint m_firstTouchScreenPosition;
96     double m_firstTouchTime;
97     State m_state;
98     double m_lastTouchTime;
99     double m_lastClickTime;
100
101     bool m_ctrlKey;
102     bool m_altKey;
103     bool m_shiftKey;
104     bool m_metaKey;
105 };
106
107 } // namespace WebCore
108
109 #endif // GestureRecognizerChromium_h