Merge "Add deprcated macro to newly deprecated Window API" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / common / 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) 2019 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 <cstdint> // uint32_t
23 #include <dali/integration-api/events/tap-gesture-event.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/integration-api/events/point.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/internal/input/common/gesture-detector.h>
29
30 namespace Dali
31 {
32
33 namespace Integration
34 {
35 struct TouchEvent;
36 struct TapGestureRequest;
37 }
38
39 namespace Internal
40 {
41
42 namespace Adaptor
43 {
44
45 class CoreEventInterface;
46
47 /**
48  * When given a set of touch events, this detector attempts to determine if a tap gesture has taken place.
49  */
50 class TapGestureDetector : public GestureDetector
51 {
52 public:
53
54   /**
55    * Constructor
56    * @param[in] coreEventInterface Used to send events to Core.
57    * @param[in]  screenSize  The size of the screen.
58    * @param[in]  request     The tap gesture request.
59    */
60   TapGestureDetector(CoreEventInterface& coreEventInterface, Vector2 screenSize, const Integration::TapGestureRequest& request);
61
62   /**
63    * Virtual destructor.
64    */
65   virtual ~TapGestureDetector();
66
67 public:
68
69   /**
70    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
71    */
72   virtual void SendEvent(const Integration::TouchEvent& event);
73
74   /**
75    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
76    */
77   virtual void Update(const Integration::GestureRequest& request);
78
79 private:
80
81   /**
82    * Checks if registered taps are within required bounds and emits tap gesture if they are.
83    *
84    * @param[in] state current state of incomplete gesture
85    * @param[in] time time of this latest touch event
86    */
87   void EmitGesture( Gesture::State state, uint32_t time );
88
89   /**
90    * Initialises tap gesture detector for next tap sequence
91    *
92    * @param[in] event registered touch event
93    * @param[in] point position touch event occurred
94    */
95   void SetupForTouchDown( const Integration::TouchEvent& event, const Integration::Point& point );
96
97   /**
98    * Emit a touch down event for hit testing
99    *
100    * @param[in] event registered touch event
101    */
102   void EmitPossibleState( const Integration::TouchEvent& event );
103
104   /**
105    * Force a touch event sequence to be treated as a single tap
106    *
107    * @param[in] time time of this latest touch event
108    * @param[in] point position touch event occurred
109     */
110   void EmitSingleTap( uint32_t time, const Integration::Point& point );
111
112   /**
113    * Emit a tap event
114    *
115    * @param[in] time time of this latest touch event
116    * @param[in] event registered touch event
117    */
118   void EmitTap( uint32_t time, Integration::TapGestureEvent& event );
119
120 private:
121
122   /**
123    * Internal state machine.
124    */
125   enum State
126   {
127     Clear,      ///< No gesture detected.
128     Touched,    ///< User is touching the screen.
129     Registered, ///< At least one tap has been registered.
130     Failed,     ///< Gesture has failed.
131   };
132
133   CoreEventInterface& mCoreEventInterface; ///< Used to send events to Core.
134   State mState; ///< Current state of the detector.
135
136   int mMinimumTapsRequired; ///< Minimum number of taps required.
137   int mMaximumTapsRequired; ///< Maximum number of taps required.
138   int mTapsRegistered;      ///< In current detection, the number of taps registered.
139
140   Vector2 mTouchPosition;   ///< The initial touch down position.
141   uint32_t mTouchTime;      ///< The initial touch down time.
142   uint32_t mLastTapTime;    ///< Time last tap gesture was registered
143
144 };
145
146 } // namespace Adaptor
147
148 } // namespace Internal
149
150 } // namespace Dali
151
152 #endif // DALI_INTERNAL_TAP_GESTURE_DETECTOR_H