aa6bc54c0f1d826a897f737db6a89b385313af98
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / common / accessibility-gesture-detector.h
1 #ifndef DALI_INTERNAL_ACCESSIBILITY_GESTURE_DETECTOR_H
2 #define DALI_INTERNAL_ACCESSIBILITY_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
23 // INTERNAL INCLUDES
24 #include <dali/devel-api/adaptor-framework/accessibility-gesture-handler.h>
25 #include <dali/devel-api/adaptor-framework/accessibility-gesture-event.h>
26 #include <dali/integration-api/scene.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33 struct TouchEvent;
34 }
35
36 namespace Internal
37 {
38
39 namespace Adaptor
40 {
41
42 /**
43  * Detects an accessibility pan gesture and sends it to the gesture handler.
44  */
45 class AccessibilityGestureDetector : public RefObject
46 {
47 public:
48
49   /**
50    * Constructor
51    */
52   AccessibilityGestureDetector();
53
54   /**
55    * Virtual destructor.
56    */
57   ~AccessibilityGestureDetector() override;
58
59   /**
60    * Set the handler to handle accessibility gestures.
61    * @param[in] handler The Accessibility gesture handler.
62    * @note Handlers should remove themselves when they are destroyed.
63    */
64   void SetGestureHandler(AccessibilityGestureHandler& handler);
65
66   void SendEvent(const Integration::TouchEvent& event);
67
68   void SendEvent(Integration::Scene& scene, const Integration::TouchEvent& event)
69   {
70     mScene = &scene;
71     SendEvent(event);
72   }
73
74 private:
75
76   /**
77    * Emits the pan gesture event (performs some smoothing operation).
78    * @param[in]  state         The state of the pan.
79    * @param[in]  currentEvent  The latest touch event.
80    */
81   void SendPan(AccessibilityGestureEvent::State state, const Integration::TouchEvent& currentEvent);
82
83   /**
84    * Emits the pan gesture event to the gesture handler.
85    * @param[in] gesture The pan gesture event.
86    */
87   void EmitPan(const AccessibilityGestureEvent gesture);
88
89 private:
90
91   /**
92    * Internal state machine.
93    */
94   enum State
95   {
96     CLEAR,    ///< No gesture detected.
97     POSSIBLE, ///< The current touch event data suggests that a gesture is possible.
98     STARTED,  ///< A gesture has been detected.
99     FINISHED, ///< A previously started pan gesture has finished.
100     FAILED,   ///< Current touch event data suggests a pan gesture is not possible.
101   };
102
103   State mState; ///< The current state of the detector.
104
105   Integration::Scene* mScene;
106   AccessibilityGestureHandler* mGestureHandler; ///< The pointer of accessibility gesture handler
107   bool mPanning;    ///< Keep track of panning state, when panning is occuring, this is true.
108
109   std::vector<Integration::TouchEvent> mTouchEvents;     ///< A container of all touch events after an initial down event.
110
111   Vector2 mPrimaryTouchDownLocation;    ///< The initial touch down point.
112   Vector2 mThresholdAdjustmentPerFrame; ///< The adjustment per frame at the start of a slow pan.
113   Vector2 mPreviousPosition;            ///< The previous position.
114
115   unsigned int mThresholdAdjustmentsRemaining; ///< No. of threshold adjustments still to apply (for a slow-pan).
116   unsigned int mThresholdTotalAdjustments;     ///< The total number of adjustments required.
117
118   uint32_t mPrimaryTouchDownTime;       ///< The initial touch down time.
119   unsigned int mMinimumTouchesRequired; ///< The minimum touches required before a pan should be emitted.
120   unsigned int mMaximumTouchesRequired; ///< The maximum touches after which a pan should not be emitted.
121   unsigned int mMinimumDistanceSquared; ///< The minimum distance squared before pan should start.
122   unsigned int mMinimumMotionEvents;    ///< The minimum motion events before pan should start.
123   unsigned int mMotionEvents;           ///< The motion events received so far (before pan is emitted).
124 };
125
126 using AccessibilityGestureDetectorPtr = Dali::IntrusivePtr<AccessibilityGestureDetector>;
127
128 } // namespace Adaptor
129
130 } // namespace Internal
131
132 } // namespace Dali
133
134 #endif // DALI_INTERNAL_ACCESSIBILITY_GESTURE_DETECTOR_H