d38bccb518394557e32793351dbea33c78ec7545
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / internal / common / events / 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) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // EXTERNAL INCLUDES
21 #include <map>
22 #include <dali/public-api/adaptor-framework/common/timer.h>
23
24 // INTERNAL INCLUDES
25 #include <internal/common/events/gesture-detector.h>
26
27 namespace Dali
28 {
29
30 namespace Integration
31 {
32 struct TouchEvent;
33 struct LongPressGestureRequest;
34 }
35
36 namespace Internal
37 {
38
39 namespace Adaptor
40 {
41
42 class CoreEventInterface;
43
44 /**
45  * When given a set of touch events, this detector attempts to determine if a long press gesture has taken place.
46  * Emits a LongPressGestureEvent (state = Started) when a long press has been detected (Touch held down for more than duration).
47  * Emits a further LongPressGestureEvent (state = Finished) when a long press has been completed (Touch Release).
48  */
49 class LongPressGestureDetector : 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 long press gesture request.
58    */
59   LongPressGestureDetector(CoreEventInterface& coreEventInterface, Vector2 screenSize, const Integration::LongPressGestureRequest& request);
60
61   /**
62    * Virtual destructor.
63    */
64   virtual ~LongPressGestureDetector();
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    * Timer Callback
82    * @return will return false; one-shot timer.
83    */
84   bool TimerCallback();
85
86   /**
87    * Emits the long press gesture if all conditions are applicable.
88    * @param[in] state The state of this gesture event.
89    */
90   void EmitGesture(Gesture::State state);
91
92   /**
93    * Get current system setting value for tap and hold gesture
94    * @return system value for tap and hold gesture [ms]
95    */
96   int GetSystemValue();
97
98 private:
99
100   /**
101    * Internal state machine.
102    */
103   enum State
104   {
105     Clear,      ///< No gesture detected.
106     Touched,    ///< User is touching the screen.
107     Failed,     ///< Gesture has failed.
108     Finished    ///< Gesture has been detected and sent.
109   };
110
111   CoreEventInterface& mCoreEventInterface; ///< Used to send events to Core.
112   State mState; ///< The current state of the detector.
113
114   unsigned int mMinimumTouchesRequired;   ///< The minimum touches required before emitting a long press.
115   unsigned int mMaximumTouchesRequired;   ///< The maximum touches allowable. Any more and a long press is not emitted.
116
117   std::map<int, Vector2> mTouchPositions; ///< A map with all the touch down positions.
118   unsigned long mTouchTime;               ///< The time we first pressed down.
119
120   Dali::Timer mTimer;                     ///< The timer used to determine a long press.
121   SlotDelegate< LongPressGestureDetector > mTimerSlot;
122 };
123
124 } // namespace Adaptor
125
126 } // namespace Internal
127
128 } // namespace Dali
129
130 #endif // __DALI_INTERNAL_LONG_PRESS_GESTURE_DETECTOR_H__