Add trace log for touch, wheel and 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) 2021 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 namespace Integration
31 {
32 struct TouchEvent;
33
34 }
35
36 namespace Internal
37 {
38 struct LongPressGestureRequest;
39 class CoreEventInterface;
40
41 /**
42  * When given a set of touch events, this detector attempts to determine if a long press gesture has taken place.
43  * Emits a LongPressGestureEvent (state = GestureState::STARTED) when a long press has been detected (Touch held down for more than duration).
44  * Emits a further LongPressGestureEvent (state = GestureState::FINISHED) when a long press has been completed (Touch Release).
45  */
46 class LongPressGestureRecognizer : public GestureRecognizer
47 {
48 public:
49   using Observer = RecognizerObserver<LongPressGestureEvent>;
50
51   /**
52    * Constructor
53    * @param[in] coreEventInterface Used to send events to Core.
54    * @param[in] screenSize  The size of the screen.
55    * @param[in] request     The long press gesture request.
56    * @param[in] minimumHoldingTime The minimum holding time required in milliseconds.
57    */
58   LongPressGestureRecognizer(Observer& observer, Vector2 screenSize, const LongPressGestureRequest& request, uint32_t minimumHoldingTime);
59
60   /**
61    * Virtual destructor.
62    */
63   ~LongPressGestureRecognizer() override;
64
65 public:
66   /**
67    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
68    */
69   void SendEvent(const Integration::TouchEvent& event) override;
70
71   /**
72    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
73    */
74   void Update(const GestureRequest& request) override;
75
76   /**
77    * @brief This method sets the minimum holding time required to be recognized as a long press gesture
78    *
79    * @param[in] value The time value in milliseconds
80    */
81   void SetMinimumHoldingTime(uint32_t time);
82
83 private:
84   /**
85    * Timer Callback
86    * @return will return false; one-shot timer.
87    */
88   bool TimerCallback();
89
90   /**
91    * Emits the long press gesture if all conditions are applicable.
92    * @param[in] state The state of this gesture event.
93    */
94   void EmitGesture(GestureState state);
95
96 private:
97   // Reference to the gesture processor for this recognizer
98   Observer& mObserver;
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   State mState; ///< The current state of the detector.
112
113   unsigned int mMinimumTouchesRequired; ///< The minimum touches required before emitting a long press.
114   unsigned int mMaximumTouchesRequired; ///< The maximum touches allowable. Any more and a long press is not emitted.
115
116   std::map<int, Vector2> mTouchPositions; ///< A map with all the touch down positions.
117   uint32_t               mTouchTime;      ///< The time we first pressed down.
118
119   uint32_t mTimerId;
120
121   uint32_t mMinimumHoldingTime;
122 };
123
124 } // namespace Internal
125
126 } // namespace Dali
127
128 #endif // DALI_INTERNAL_LONG_PRESS_GESTURE_RECOGNIZER_H