• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef MAGNIFICATION_GESTURE_H
17 #define MAGNIFICATION_GESTURE_H
18 
19 #include "accessibility_event_transmission.h"
20 #include "window_magnification_manager.h"
21 #include "hilog_wrapper.h"
22 #include "event_handler.h"
23 #include "magnification_menu_manager.h"
24 
25 namespace OHOS {
26 namespace Accessibility {
27 class WindowMagnificationGesture;
28 
29 #define BIND(func) [this](MMI::PointerEvent& event) { (func(event)); }
30 
31 enum class MagnificationGestureState : uint32_t {
32     PASSING_THROUGH,
33     INVALID,
34     READY_STATE,
35     READY_STATE_ONE_FINGER_DOWN,
36     READY_STATE_ONE_FINGER_TAP,
37     ZOOMIN_STATE,
38     ZOOMIN_STATE_ONE_FINGER_DOWN,
39     ZOOMIN_STATE_ONE_FINGER_TAP,
40     ZOOMIN_STATE_TWO_FINGERS_DOWN,
41     SLIDING_STATE,
42     TWO_FINGERS_SLIDING_STATE,
43     MENU_SLIDING_STATE,
44     DRAGGING_STATE,
45 };
46 
47 enum class MagnificationState : uint32_t {
48     MAGNIFICATION_READY_STATE,
49     MAGNIFICATION_ZOOMIN_STATE,
50     MAGNIFICATION_SLIDING_STATE
51 };
52 
53 enum class PointerCountSize : int32_t {
54     POINTER_SIZE_1 = 1,
55     POINTER_SIZE_2 = 2
56 };
57 
58 enum class MagnificationGestureMsg : uint32_t {
59     SINGLE_TAP_FAIL_MSG,
60     TRIPLE_TAP_FAIL_MSG,
61     LONG_PRESS_MSG,
62     WAIT_ANOTHER_FINGER_DOWN_MSG,
63 };
64 
65 // ms
66 enum class MagnificationTimeout : uint32_t {
67     TAP_TIMEOUT = 100,
68     DOUBLE_TAP_TIMEOUT = 250,
69     LONG_PRESS_TIMEOUT = 200,
70 };
71 
72 class MagnificationGestureEventHandler : public AppExecFwk::EventHandler {
73 public:
74     MagnificationGestureEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
75         WindowMagnificationGesture &server);
76     virtual ~MagnificationGestureEventHandler() = default;
77     /**
78      * @brief Process the event of install system bundles.
79      * @param event Indicates the event to be processed.
80      */
81     virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
82 
83 private:
84     WindowMagnificationGesture &server_;
85 };
86 
87 class WindowMagnificationGesture : public EventTransmission {
88 public:
89     WindowMagnificationGesture();
90     explicit WindowMagnificationGesture(std::shared_ptr<WindowMagnificationManager> windowMagnificationManager,
91         std::shared_ptr<MagnificationMenuManager> menuManager);
92     ~WindowMagnificationGesture() = default;
93 
94     bool OnPointerEvent(MMI::PointerEvent &event) override;
95     void DestroyEvents() override;
96 
97     void CancelPostEvent(MagnificationGestureMsg msg);
98     void SendCacheEventsToNext();
99     void ShieldZoomGesture(bool state);
100     void StartMagnificationInteract();
101     void DisableGesture();
102     void OnDrag();
103 
104     /* Set current magnification gesture state */
SetGestureState(MagnificationGestureState state,int32_t action)105     inline void SetGestureState(MagnificationGestureState state, int32_t action)
106     {
107         HILOG_INFO("gestureState changed: [%{public}d] -> [%{public}d], current action: %{public}d.",
108             gestureState_, state, action);
109         gestureState_ = state;
110     }
111 
112     /* Get current magnification gesture state */
GetGestureState()113     inline MagnificationGestureState GetGestureState()
114     {
115         return gestureState_;
116     }
117 
AddTapCount()118     inline void AddTapCount()
119     {
120         tapCount_++;
121         HILOG_INFO("add tap count, current count = [%{public}d].", tapCount_);
122     }
123 
ResetTapCount()124     inline void ResetTapCount()
125     {
126         tapCount_ = 0;
127         HILOG_INFO("reset tap count = 0");
128     }
129 
GetTapCount()130     inline uint32_t GetTapCount()
131     {
132         HILOG_INFO("get tap count = [%{public}d].", tapCount_);
133         return tapCount_;
134     }
135 
GetTapOnMenu()136     inline bool GetTapOnMenu()
137     {
138         return isTapOnMenu_;
139     }
140 
GetTripleDown()141     inline bool GetTripleDown()
142     {
143         return isTripleDown_;
144     }
145 private:
146     bool needBypassPointerEvent(MMI::PointerEvent &event);
147 
148     void OnPointerEventExcute(MMI::PointerEvent &event);
149 
150     void HandlePassingThroughState(MMI::PointerEvent &event);
151 
152     void HandleReadyStateDown(MMI::PointerEvent &event);
153     void HandleReadyStateUp(MMI::PointerEvent &event);
154     void HandleReadyStateMove(MMI::PointerEvent &event);
155     void HandleReadyStateCancel(MMI::PointerEvent &event);
156     void HandleReadyStateOneFingerDownStateDown(MMI::PointerEvent &event);
157     void HandleReadyStateOneFingerDownStateUp(MMI::PointerEvent &event);
158     void HandleReadyStateOneFingerDownStateMove(MMI::PointerEvent &event);
159     void HandleReadyStateOneFingerDownStatCancel(MMI::PointerEvent &event);
160     void HandleReadyStateOneFingerTapDown(MMI::PointerEvent &event);
161 
162     void HandleZoomInStateDown(MMI::PointerEvent &event);
163     void HandleZoomInStateUp(MMI::PointerEvent &event);
164     void HandleZoomInStateMove(MMI::PointerEvent &event);
165     void HandleZoomInStateOneFingerDownStateDown(MMI::PointerEvent &event);
166     void HandleZoomInStateOneFingerDownStateUp(MMI::PointerEvent &event);
167     void HandleZoomInStateOneFingerDownStateMove(MMI::PointerEvent &event);
168     void HandleZoomInStateOneFingerTapDown(MMI::PointerEvent &event);
169 
170     void HandleTwoFingersDownStateUp(MMI::PointerEvent &event);
171     void HandleTwoFingersDownStateMove(MMI::PointerEvent &event);
172 
173     void HandleSlidingStateDown(MMI::PointerEvent &event);
174     void HandleSlidingStateUp(MMI::PointerEvent &event);
175     void HandleSlidingStateMove(MMI::PointerEvent &event);
176 
177     void HandleMenuSlidingStateUp(MMI::PointerEvent &event);
178     void HandleMenuSlidingStateMove(MMI::PointerEvent &event);
179 
180     void HandleDraggingStateUp(MMI::PointerEvent &event);
181     void HandleDraggingStateMove(MMI::PointerEvent &event);
182 
183     void InitGestureFuncMap();
184 
185     bool IsMove(MMI::PointerEvent &startEvent, MMI::PointerEvent &endEvent, float slop);
186     void Clear();
187     void OnTripleTap(int32_t centerX, int32_t centerY);
188     void SendEventToMultimodal(MMI::PointerEvent event, bool needTransfer, bool needResetTime);
189     bool IsTapOnInputMethod(MMI::PointerEvent &event);
190     bool IsKnuckles(MMI::PointerEvent &event);
CalculateMoveThreshold(int dpi)191     inline float CalculateMoveThreshold(int dpi)
192     {
193         return dpi * COMPLEX_UNIT_MM_CONVERSION * MM_PER_CM;
194     }
195 
196     std::shared_ptr<MagnificationGestureEventHandler> handler_ = nullptr;
197     std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
198     std::shared_ptr<WindowMagnificationManager> windowMagnificationManager_ = nullptr;
199     std::shared_ptr<MagnificationMenuManager> menuManager_ = nullptr;
200     MagnificationState magnificationState_ = MagnificationState::MAGNIFICATION_READY_STATE;
201     MagnificationGestureState gestureState_ = MagnificationGestureState::READY_STATE;
202 
203     using HandleEventFunc = std::function<void(MMI::PointerEvent &)>;
204     std::map<MagnificationGestureState, std::map<int32_t, HandleEventFunc>> handleEventFuncMap_ {};
205     std::list<MMI::PointerEvent> receivedPointerEvents_ {};
206     std::shared_ptr<MMI::PointerEvent> lastDownEvent_ = nullptr;
207     std::shared_ptr<MMI::PointerEvent> lastSlidingEvent_ = nullptr;
208     bool isTapOnHotArea_ = false;
209     bool isSingleTapOnWindow_ = false;
210     bool isDoubleFingersValid_ = false;
211     bool startScale_ = false;
212     bool isTapOnMenu_ = false;
213 
214     float moveThreshold_ = 0.0f;
215     float tapDistance_ = 0.0f;
216     float multiTapDistance_ = 0.0f;
217 
218     uint32_t tapCount_ = 0;
219     float distance_ = 0.0f;
220     bool shieldZoomGestureFlag_ = false;
221     bool isTripleDown_ = false;
222 };
223 } // namespace Accessibility
224 } // namespace OHOS
225 #endif // MAGNIFICATION_GESTURE_H