Merge "Add deprcated macro to newly deprecated Window API" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / common / long-press-gesture-detector.h
1 #ifndef DALI_INTERNAL_LONG_PRESS_GESTURE_DETECTOR_H
2 #define DALI_INTERNAL_LONG_PRESS_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 <map>
23 #include <dali/public-api/adaptor-framework/timer.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/input/common/gesture-detector.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33 struct TouchEvent;
34 struct LongPressGestureRequest;
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 long press gesture has taken place.
47  * Emits a LongPressGestureEvent (state = Started) when a long press has been detected (Touch held down for more than duration).
48  * Emits a further LongPressGestureEvent (state = Finished) when a long press has been completed (Touch Release).
49  */
50 class LongPressGestureDetector : 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 long press gesture request.
59    */
60   LongPressGestureDetector(CoreEventInterface& coreEventInterface, Vector2 screenSize, const Integration::LongPressGestureRequest& request);
61
62   /**
63    * Virtual destructor.
64    */
65   virtual ~LongPressGestureDetector();
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    * Timer Callback
83    * @return will return false; one-shot timer.
84    */
85   bool TimerCallback();
86
87   /**
88    * Emits the long press gesture if all conditions are applicable.
89    * @param[in] state The state of this gesture event.
90    */
91   void EmitGesture(Gesture::State state);
92
93   /**
94    * Get current system setting value for tap and hold gesture
95    * @return system value for tap and hold gesture [ms]
96    */
97   int GetSystemValue();
98
99 private:
100
101   /**
102    * Internal state machine.
103    */
104   enum State
105   {
106     Clear,      ///< No gesture detected.
107     Touched,    ///< User is touching the screen.
108     Failed,     ///< Gesture has failed.
109     Finished    ///< Gesture has been detected and sent.
110   };
111
112   CoreEventInterface& mCoreEventInterface; ///< Used to send events to Core.
113   State mState; ///< The current state of the detector.
114
115   unsigned int mMinimumTouchesRequired;   ///< The minimum touches required before emitting a long press.
116   unsigned int mMaximumTouchesRequired;   ///< The maximum touches allowable. Any more and a long press is not emitted.
117
118   std::map<int, Vector2> mTouchPositions; ///< A map with all the touch down positions.
119   uint32_t mTouchTime;               ///< The time we first pressed down.
120
121   Dali::Timer mTimer;                     ///< The timer used to determine a long press.
122   SlotDelegate< LongPressGestureDetector > mTimerSlot;
123 };
124
125 } // namespace Adaptor
126
127 } // namespace Internal
128
129 } // namespace Dali
130
131 #endif // DALI_INTERNAL_LONG_PRESS_GESTURE_DETECTOR_H