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