Merge "Set proper locale to harfbuzz" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / common / events / tap-gesture-detector.h
1 #ifndef __DALI_INTERNAL_TAP_GESTURE_DETECTOR_H__
2 #define __DALI_INTERNAL_TAP_GESTURE_DETECTOR_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/events/tap-gesture-event.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/integration-api/events/point.h>
25
26 // INTERNAL INCLUDES
27 #include <events/gesture-detector.h>
28
29 namespace Dali
30 {
31
32 namespace Integration
33 {
34 struct TouchEvent;
35 struct TapGestureRequest;
36 }
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43
44 class CoreEventInterface;
45
46 /**
47  * When given a set of touch events, this detector attempts to determine if a tap gesture has taken place.
48  */
49 class TapGestureDetector : public GestureDetector
50 {
51 public:
52
53   /**
54    * Constructor
55    * @param[in] coreEventInterface Used to send events to Core.
56    * @param[in]  screenSize  The size of the screen.
57    * @param[in]  request     The tap gesture request.
58    */
59   TapGestureDetector(CoreEventInterface& coreEventInterface, Vector2 screenSize, const Integration::TapGestureRequest& request);
60
61   /**
62    * Virtual destructor.
63    */
64   virtual ~TapGestureDetector();
65
66 public:
67
68   /**
69    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
70    */
71   virtual void SendEvent(const Integration::TouchEvent& event);
72
73   /**
74    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
75    */
76   virtual void Update(const Integration::GestureRequest& request);
77
78 private:
79
80   /**
81    * Checks if registered taps are within required bounds and emits tap gesture if they are.
82    *
83    * @param[in] state current state of incomplete gesture
84    * @param[in] time time of this latest touch event
85    */
86   void EmitGesture( Gesture::State state, unsigned int time );
87
88   /**
89    * Initialises tap gesture detector for next tap sequence
90    *
91    * @param[in] event registered touch event
92    * @param[in] point position touch event occurred
93    */
94   void SetupForTouchDown( const Integration::TouchEvent& event, const Integration::Point& point );
95
96   /**
97    * Emit a touch down event for hit testing
98    *
99    * @param[in] event registered touch event
100    */
101   void EmitPossibleState( const Integration::TouchEvent& event );
102
103   /**
104    * Force a touch event sequence to be treated as a single tap
105    *
106    * @param[in] time time of this latest touch event
107    * @param[in] point position touch event occurred
108     */
109   void EmitSingleTap( unsigned int time, const Integration::Point& point );
110
111   /**
112    * Emit a tap event
113    *
114    * @param[in] time time of this latest touch event
115    * @param[in] event registered touch event
116    */
117   void EmitTap( unsigned int time, Integration::TapGestureEvent& event );
118
119 private:
120
121   /**
122    * Internal state machine.
123    */
124   enum State
125   {
126     Clear,      ///< No gesture detected.
127     Touched,    ///< User is touching the screen.
128     Registered, ///< At least one tap has been registered.
129     Failed,     ///< Gesture has failed.
130   };
131
132   CoreEventInterface& mCoreEventInterface; ///< Used to send events to Core.
133   State mState; ///< Current state of the detector.
134
135   int mMinimumTapsRequired; ///< Minimum number of taps required.
136   int mMaximumTapsRequired; ///< Maximum number of taps required.
137   int mTapsRegistered;      ///< In current detection, the number of taps registered.
138
139   Vector2 mTouchPosition;   ///< The initial touch down position.
140   unsigned long mTouchTime; ///< The initial touch down time.
141   unsigned long mLastTapTime; ///< Time last tap gesture was registered
142
143 };
144
145 } // namespace Adaptor
146
147 } // namespace Internal
148
149 } // namespace Dali
150
151 #endif // __DALI_INTERNAL_TAP_GESTURE_DETECTOR_H__