Add an environment variable for long press gesture
[platform/core/uifw/dali-core.git] / dali / internal / event / events / long-press-gesture / long-press-gesture-recognizer.h
1 #ifndef DALI_INTERNAL_LONG_PRESS_GESTURE_RECOGNIZER_H
2 #define DALI_INTERNAL_LONG_PRESS_GESTURE_RECOGNIZER_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
24 // INTERNAL INCLUDES
25 #include <dali/internal/event/events/gesture-recognizer.h>
26 #include <dali/internal/event/events/long-press-gesture/long-press-gesture-event.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33 struct TouchEvent;
34
35 }
36
37 namespace Internal
38 {
39
40 struct LongPressGestureRequest;
41 class CoreEventInterface;
42
43 /**
44  * When given a set of touch events, this detector attempts to determine if a long press gesture has taken place.
45  * Emits a LongPressGestureEvent (state = Started) when a long press has been detected (Touch held down for more than duration).
46  * Emits a further LongPressGestureEvent (state = Finished) when a long press has been completed (Touch Release).
47  */
48 class LongPressGestureRecognizer : public GestureRecognizer
49 {
50 public:
51
52   using Observer = RecognizerObserver<LongPressGestureEvent>;
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    * @param[in] minimumHoldingTime The minimum holding time required in milliseconds.
60    */
61   LongPressGestureRecognizer( Observer& observer, Vector2 screenSize, const LongPressGestureRequest& request, uint32_t minimumHoldingTime );
62
63   /**
64    * Virtual destructor.
65    */
66   virtual ~LongPressGestureRecognizer();
67
68 public:
69
70   /**
71    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
72    */
73   virtual void SendEvent(const Integration::TouchEvent& event);
74
75   /**
76    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
77    */
78   virtual void Update(const GestureRequest& request);
79
80   /**
81    * @brief This method sets the minimum holding time required to be recognized as a long press gesture
82    *
83    * @param[in] value The time value in milliseconds
84    */
85   void SetMinimumHoldingTime( uint32_t time );
86
87 private:
88
89   /**
90    * Timer Callback
91    * @return will return false; one-shot timer.
92    */
93   bool TimerCallback();
94
95   /**
96    * Emits the long press gesture if all conditions are applicable.
97    * @param[in] state The state of this gesture event.
98    */
99   void EmitGesture(Gesture::State state);
100
101 private:
102
103   // Reference to the gesture processor for this recognizer
104   Observer& mObserver;
105
106   /**
107    * Internal state machine.
108    */
109   enum State
110   {
111     Clear,      ///< No gesture detected.
112     Touched,    ///< User is touching the screen.
113     Failed,     ///< Gesture has failed.
114     Finished    ///< Gesture has been detected and sent.
115   };
116
117   State mState; ///< The current state of the detector.
118
119   unsigned int mMinimumTouchesRequired;   ///< The minimum touches required before emitting a long press.
120   unsigned int mMaximumTouchesRequired;   ///< The maximum touches allowable. Any more and a long press is not emitted.
121
122   std::map<int, Vector2> mTouchPositions; ///< A map with all the touch down positions.
123   uint32_t mTouchTime;               ///< The time we first pressed down.
124
125   uint32_t mTimerId;
126
127   uint32_t mMinimumHoldingTime;
128 };
129
130 } // namespace Internal
131
132 } // namespace Dali
133
134 #endif // DALI_INTERNAL_LONG_PRESS_GESTURE_RECOGNIZER_H