License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / internal / 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 <vector>
23 #include <dali/public-api/adaptor-framework/common/timer.h>
24
25 // INTERNAL INCLUDES
26 #include <internal/common/events/gesture-detector.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33 struct TouchEvent;
34 struct TapGestureRequest;
35 }
36
37 namespace Internal
38 {
39
40 namespace Adaptor
41 {
42
43 class CoreEventInterface;
44
45 /**
46  * When given a set of touch events, this detector attempts to determine if a tap gesture has taken place.
47  */
48 class TapGestureDetector : public GestureDetector
49 {
50 public:
51
52   /**
53    * Constructor
54    * @param[in] coreEventInterface Used to send events to Core.
55    * @param[in]  screenSize  The size of the screen.
56    * @param[in]  request     The tap gesture request.
57    */
58   TapGestureDetector(CoreEventInterface& coreEventInterface, Vector2 screenSize, const Integration::TapGestureRequest& request);
59
60   /**
61    * Virtual destructor.
62    */
63   virtual ~TapGestureDetector();
64
65 public:
66
67   /**
68    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
69    */
70   virtual void SendEvent(const Integration::TouchEvent& event);
71
72   /**
73    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
74    */
75   virtual void Update(const Integration::GestureRequest& request);
76
77 private:
78
79   /**
80    * Timer Callback
81    * @return will return false; one-shot timer.
82    */
83   bool TimerCallback();
84
85   /**
86    * Checks if registered taps are within required bounds and emits tap gesture if they are.
87    */
88   void EmitGesture( Gesture::State state, unsigned int time );
89
90 private:
91
92   /**
93    * Internal state machine.
94    */
95   enum State
96   {
97     Clear,      ///< No gesture detected.
98     Touched,    ///< User is touching the screen.
99     Registered, ///< At least one tap has been registered.
100     Failed,     ///< Gesture has failed.
101   };
102
103   CoreEventInterface& mCoreEventInterface; ///< Used to send events to Core.
104   State mState; ///< Current state of the detector.
105
106   int mMinimumTapsRequired; ///< Minimum number of taps required.
107   int mMaximumTapsRequired; ///< Maximum number of taps required.
108   int mTapsRegistered;      ///< In current detection, the number of taps registered.
109
110   Vector2 mTouchPosition;   ///< The initial touch down position.
111   unsigned long mTouchTime; ///< The initial touch down time.
112
113   Dali::Timer mTimer;       ///< The timer to start when we have registered the tap. We have to register all taps within a certain time frame.
114   SlotDelegate< TapGestureDetector > mTimerSlot;
115 };
116
117 } // namespace Adaptor
118
119 } // namespace Internal
120
121 } // namespace Dali
122
123 #endif // __DALI_INTERNAL_TAP_GESTURE_DETECTOR_H__