1885b47fbSopenharmony_ci/*
2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License.
5885b47fbSopenharmony_ci * You may obtain a copy of the License at
6885b47fbSopenharmony_ci *
7885b47fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8885b47fbSopenharmony_ci *
9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and
13885b47fbSopenharmony_ci * limitations under the License.
14885b47fbSopenharmony_ci */
15885b47fbSopenharmony_ci
16885b47fbSopenharmony_ci#ifndef ACCESSIBILITY_TOUCH_GUIDER_H
17885b47fbSopenharmony_ci#define ACCESSIBILITY_TOUCH_GUIDER_H
18885b47fbSopenharmony_ci
19885b47fbSopenharmony_ci#include <string>
20885b47fbSopenharmony_ci#include "accessibility_element_info.h"
21885b47fbSopenharmony_ci#include "accessibility_element_operator_callback_stub.h"
22885b47fbSopenharmony_ci#include "accessibility_event_transmission.h"
23885b47fbSopenharmony_ci#include "accessibility_gesture_recognizer.h"
24885b47fbSopenharmony_ci#include "accessibility_multifinger_multitap.h"
25885b47fbSopenharmony_ci#include "accessible_ability_manager_service.h"
26885b47fbSopenharmony_ci
27885b47fbSopenharmony_cinamespace OHOS {
28885b47fbSopenharmony_cinamespace Accessibility {
29885b47fbSopenharmony_ciclass TouchGuider;
30885b47fbSopenharmony_ci
31885b47fbSopenharmony_ciconst int64_t EXIT_GESTURE_REC_TIMEOUT = 400; // millisecond
32885b47fbSopenharmony_ciconst double MAX_DRAG_GESTURE_COSINE = 0.525321989;
33885b47fbSopenharmony_ciconst int32_t MINI_POINTER_DISTANCE_DIP = 200;
34885b47fbSopenharmony_ciconst int32_t INDEX_0 = 0;
35885b47fbSopenharmony_ciconst int32_t INDEX_1 = 1;
36885b47fbSopenharmony_ciconst int32_t INIT_POINT_ID = -1;
37885b47fbSopenharmony_ciconst float INIT_MMIPOINT = 0.0f;
38885b47fbSopenharmony_ciconst int32_t INIT_POINT_DISPLAY = 0;
39885b47fbSopenharmony_ci#define DIVIDE_2(num) ((num) / 2)
40885b47fbSopenharmony_ci#define EPSINON 0.01
41885b47fbSopenharmony_ci
42885b47fbSopenharmony_ci/**
43885b47fbSopenharmony_ci * @brief touch Guider state define
44885b47fbSopenharmony_ci */
45885b47fbSopenharmony_cienum class TouchGuideState : int32_t {
46885b47fbSopenharmony_ci    TOUCH_GUIDING,
47885b47fbSopenharmony_ci    DRAGGING,
48885b47fbSopenharmony_ci    TRANSMITTING,
49885b47fbSopenharmony_ci    GESTURE_RECOGNIZING,
50885b47fbSopenharmony_ci    PASSING_THROUGH
51885b47fbSopenharmony_ci};
52885b47fbSopenharmony_ci
53885b47fbSopenharmony_ci/**
54885b47fbSopenharmony_ci * @brief Click location define
55885b47fbSopenharmony_ci */
56885b47fbSopenharmony_cienum ClickLocation : int32_t {
57885b47fbSopenharmony_ci    CLICK_NONE,
58885b47fbSopenharmony_ci    CLICK_ACCESSIBILITY_FOCUS,
59885b47fbSopenharmony_ci    CLICK_LAST_TOUCH_GUIDE
60885b47fbSopenharmony_ci};
61885b47fbSopenharmony_ci
62885b47fbSopenharmony_ci/**
63885b47fbSopenharmony_ci * @brief struct to record injected pointers.
64885b47fbSopenharmony_ci */
65885b47fbSopenharmony_cistruct InjectedEventRecorder {
66885b47fbSopenharmony_ci    std::set<int32_t> downPointers {};
67885b47fbSopenharmony_ci    int32_t downPointerNum;
68885b47fbSopenharmony_ci    int64_t lastDownTime;
69885b47fbSopenharmony_ci    std::shared_ptr<MMI::PointerEvent> lastHoverEvent;
70885b47fbSopenharmony_ci};
71885b47fbSopenharmony_ci
72885b47fbSopenharmony_ci/**
73885b47fbSopenharmony_ci * @brief struct to record received pointers.
74885b47fbSopenharmony_ci */
75885b47fbSopenharmony_cistruct ReceivedEventRecorder {
76885b47fbSopenharmony_ci    std::map<int32_t, int32_t> pointerDownX;
77885b47fbSopenharmony_ci    std::map<int32_t, int32_t> pointerDownY;
78885b47fbSopenharmony_ci    std::map<int32_t, int64_t> pointerActionTime;
79885b47fbSopenharmony_ci    std::shared_ptr<MMI::PointerEvent> lastEvent;
80885b47fbSopenharmony_ci};
81885b47fbSopenharmony_ci
82885b47fbSopenharmony_cienum ChangeAction : int32_t {
83885b47fbSopenharmony_ci    NO_CHANGE,
84885b47fbSopenharmony_ci    HOVER_MOVE,
85885b47fbSopenharmony_ci    POINTER_DOWN,
86885b47fbSopenharmony_ci    POINTER_UP,
87885b47fbSopenharmony_ci    POINTER_MOVE,
88885b47fbSopenharmony_ci    HOVER_ENTER,
89885b47fbSopenharmony_ci    HOVER_EXIT,
90885b47fbSopenharmony_ci};
91885b47fbSopenharmony_ci
92885b47fbSopenharmony_ciclass TGEventHandler : public AppExecFwk::EventHandler {
93885b47fbSopenharmony_cipublic:
94885b47fbSopenharmony_ci    TGEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
95885b47fbSopenharmony_ci                 TouchGuider &tgServer);
96885b47fbSopenharmony_ci    virtual ~TGEventHandler() = default;
97885b47fbSopenharmony_ci    /**
98885b47fbSopenharmony_ci     * @brief Process the event of install system bundles.
99885b47fbSopenharmony_ci     * @param event Indicates the event to be processed.
100885b47fbSopenharmony_ci     */
101885b47fbSopenharmony_ci    virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
102885b47fbSopenharmony_ci
103885b47fbSopenharmony_ciprivate:
104885b47fbSopenharmony_ci    /**
105885b47fbSopenharmony_ci     * @brief Send HoverEnter and HoverMove to Multimodal.
106885b47fbSopenharmony_ci     */
107885b47fbSopenharmony_ci    void HoverEnterAndMoveRunner();
108885b47fbSopenharmony_ci
109885b47fbSopenharmony_ci    /**
110885b47fbSopenharmony_ci     * @brief Send HoverExit to Multimodal.
111885b47fbSopenharmony_ci     */
112885b47fbSopenharmony_ci    void HoverExitRunner();
113885b47fbSopenharmony_ci    TouchGuider &tgServer_;
114885b47fbSopenharmony_ci};
115885b47fbSopenharmony_ci
116885b47fbSopenharmony_ciclass TouchGuider : public EventTransmission {
117885b47fbSopenharmony_cipublic:
118885b47fbSopenharmony_ci    static constexpr uint32_t EXIT_GESTURE_REC_MSG = 0;
119885b47fbSopenharmony_ci    static constexpr uint32_t SEND_HOVER_ENTER_MOVE_MSG = 1;
120885b47fbSopenharmony_ci    static constexpr uint32_t SEND_HOVER_EXIT_MSG = 2;
121885b47fbSopenharmony_ci    static constexpr uint32_t SEND_TOUCH_INTERACTION_END_MSG = 3;
122885b47fbSopenharmony_ci    static constexpr uint32_t SEND_TOUCH_GUIDE_END_MSG = 4;
123885b47fbSopenharmony_ci
124885b47fbSopenharmony_ci    /**
125885b47fbSopenharmony_ci     * @brief A constructor used to create a touchGuide instance.
126885b47fbSopenharmony_ci     */
127885b47fbSopenharmony_ci    TouchGuider();
128885b47fbSopenharmony_ci
129885b47fbSopenharmony_ci    /**
130885b47fbSopenharmony_ci     * @brief A destructor used to delete the touchGuide instance.
131885b47fbSopenharmony_ci     */
132885b47fbSopenharmony_ci    ~TouchGuider() {}
133885b47fbSopenharmony_ci
134885b47fbSopenharmony_ci    /**
135885b47fbSopenharmony_ci     * @brief TouchGuide start up.
136885b47fbSopenharmony_ci     */
137885b47fbSopenharmony_ci    void StartUp();
138885b47fbSopenharmony_ci
139885b47fbSopenharmony_ci    /**
140885b47fbSopenharmony_ci     * @brief Handle pointer events from previous event stream node.
141885b47fbSopenharmony_ci     *
142885b47fbSopenharmony_ci     * @param event  the pointer event to be handled.
143885b47fbSopenharmony_ci     * @return true: the event has been processed and does not need to be passed to the next node;
144885b47fbSopenharmony_ci     *         false: the event is not processed.
145885b47fbSopenharmony_ci     */
146885b47fbSopenharmony_ci    bool OnPointerEvent(MMI::PointerEvent &event) override;
147885b47fbSopenharmony_ci
148885b47fbSopenharmony_ci    /**
149885b47fbSopenharmony_ci     * @brief Handle pointer events from previous event stream node.
150885b47fbSopenharmony_ci     *
151885b47fbSopenharmony_ci     * @param event  the pointer event to be handled.
152885b47fbSopenharmony_ci     */
153885b47fbSopenharmony_ci    void HandlePointerEvent(MMI::PointerEvent &event);
154885b47fbSopenharmony_ci
155885b47fbSopenharmony_ci    /**
156885b47fbSopenharmony_ci     * @brief Destroy event state.
157885b47fbSopenharmony_ci     */
158885b47fbSopenharmony_ci    void DestroyEvents() override;
159885b47fbSopenharmony_ci
160885b47fbSopenharmony_ci    /**
161885b47fbSopenharmony_ci     * @brief Send pointer down event to multimodal input.
162885b47fbSopenharmony_ci     * @param event event the touch event from Multimodal, set the down point to the event and send.
163885b47fbSopenharmony_ci     * @param action point action send to multimode.
164885b47fbSopenharmony_ci     */
165885b47fbSopenharmony_ci    void SendPointerDownEventToMultimodal(MMI::PointerEvent event, int32_t action);
166885b47fbSopenharmony_ci
167885b47fbSopenharmony_ci    /**
168885b47fbSopenharmony_ci     * @brief Send event to multimodal input.
169885b47fbSopenharmony_ci     * @param event the event prepared to send to Multimodal
170885b47fbSopenharmony_ci     * @param action the action of the event
171885b47fbSopenharmony_ci     */
172885b47fbSopenharmony_ci    void SendEventToMultimodal(MMI::PointerEvent &event, int32_t action);
173885b47fbSopenharmony_ci
174885b47fbSopenharmony_ci    /**
175885b47fbSopenharmony_ci     * @brief Send accessibility event to specific AccessibleAbility.
176885b47fbSopenharmony_ci     * @param eventType the type of the event
177885b47fbSopenharmony_ci     */
178885b47fbSopenharmony_ci    void SendAccessibilityEventToAA(EventType eventType);
179885b47fbSopenharmony_ci
180885b47fbSopenharmony_ci    /**
181885b47fbSopenharmony_ci     * @brief Send gesture event to specific AccessibleAbility.
182885b47fbSopenharmony_ci     * @param gestureId the gesture id of the event
183885b47fbSopenharmony_ci     */
184885b47fbSopenharmony_ci    void SendGestureEventToAA(GestureType gestureId);
185885b47fbSopenharmony_ci
186885b47fbSopenharmony_ci    /**
187885b47fbSopenharmony_ci     * @brief Get hover enter and move event.
188885b47fbSopenharmony_ci     * @return Returns pointerEvents_ list.
189885b47fbSopenharmony_ci     */
190885b47fbSopenharmony_ci    std::list<MMI::PointerEvent> getHoverEnterAndMoveEvent();
191885b47fbSopenharmony_ci
192885b47fbSopenharmony_ci    /**
193885b47fbSopenharmony_ci     * @brief Clear hover enter and move event.
194885b47fbSopenharmony_ci     */
195885b47fbSopenharmony_ci    void ClearHoverEnterAndMoveEvent();
196885b47fbSopenharmony_ci
197885b47fbSopenharmony_ci    /**
198885b47fbSopenharmony_ci     * @brief Get last received event.
199885b47fbSopenharmony_ci     * @return Returns last event ptr.
200885b47fbSopenharmony_ci     */
201885b47fbSopenharmony_ci    std::shared_ptr<MMI::PointerEvent> getLastReceivedEvent();
202885b47fbSopenharmony_ci
203885b47fbSopenharmony_ci     /* For TouchGuide */
204885b47fbSopenharmony_ci    inline void OnTouchInteractionStart()
205885b47fbSopenharmony_ci    {
206885b47fbSopenharmony_ci        isTouchStart_ = true;
207885b47fbSopenharmony_ci    }
208885b47fbSopenharmony_ci
209885b47fbSopenharmony_ci    inline void OnTouchInteractionEnd()
210885b47fbSopenharmony_ci    {
211885b47fbSopenharmony_ci        isTouchStart_ = false;
212885b47fbSopenharmony_ci    }
213885b47fbSopenharmony_ci
214885b47fbSopenharmony_ci    /**
215885b47fbSopenharmony_ci     * @brief whether touch guide end.
216885b47fbSopenharmony_ci     * @return true if touch guide end, else false.
217885b47fbSopenharmony_ci     */
218885b47fbSopenharmony_ci    inline bool IsTouchInteractionEnd()
219885b47fbSopenharmony_ci    {
220885b47fbSopenharmony_ci        return isTouchStart_ == false;
221885b47fbSopenharmony_ci    }
222885b47fbSopenharmony_ci
223885b47fbSopenharmony_ci    /**
224885b47fbSopenharmony_ci     * @brief Perform action on Accessibility Focus.
225885b47fbSopenharmony_ci     * @param action the action of Accessibility node.
226885b47fbSopenharmony_ci     * @return Returns true if the action perform successfully; returns false code otherwise.
227885b47fbSopenharmony_ci     */
228885b47fbSopenharmony_ci    bool ExecuteActionOnAccessibilityFocused(const ActionType &action);
229885b47fbSopenharmony_ci
230885b47fbSopenharmony_ci    static int64_t lastDoubleTapTime;
231885b47fbSopenharmony_ciprivate:
232885b47fbSopenharmony_ci    class TouchGuideListener : public AccessibilityGestureRecognizeListener {
233885b47fbSopenharmony_ci    public:
234885b47fbSopenharmony_ci        /**
235885b47fbSopenharmony_ci         * @brief A constructor used to create a TouchGuideListener instance.
236885b47fbSopenharmony_ci         */
237885b47fbSopenharmony_ci        explicit TouchGuideListener(TouchGuider &server) : server_(server) {};
238885b47fbSopenharmony_ci
239885b47fbSopenharmony_ci        /**
240885b47fbSopenharmony_ci         * @brief Prepare to send the event corresponding to the single tap to the Multimodal.
241885b47fbSopenharmony_ci         * @param event the touch event from Multimodal
242885b47fbSopenharmony_ci         */
243885b47fbSopenharmony_ci        bool OnDoubleTap(MMI::PointerEvent &event) override;
244885b47fbSopenharmony_ci
245885b47fbSopenharmony_ci        /**
246885b47fbSopenharmony_ci         * @brief Send GESTURE_BEGIN to AccessibleAbility.
247885b47fbSopenharmony_ci         */
248885b47fbSopenharmony_ci        bool OnStarted() override;
249885b47fbSopenharmony_ci
250885b47fbSopenharmony_ci        /**
251885b47fbSopenharmony_ci         * @brief Send GESTURE_BEGIN to AccessibleAbility when multi finger gesture start.
252885b47fbSopenharmony_ci         * @param isTwoFingerGesture whether the gesture is triggered by two finger.
253885b47fbSopenharmony_ci         */
254885b47fbSopenharmony_ci        void MultiFingerGestureOnStarted(bool isTwoFingerGesture) override;
255885b47fbSopenharmony_ci
256885b47fbSopenharmony_ci        /**
257885b47fbSopenharmony_ci         * @brief Send GESTURE_END and TOUCH_END to AccessibleAbility.
258885b47fbSopenharmony_ci         * @param gestureId the id of gesture
259885b47fbSopenharmony_ci         */
260885b47fbSopenharmony_ci        bool OnCompleted(GestureType gestureId) override;
261885b47fbSopenharmony_ci
262885b47fbSopenharmony_ci        /**
263885b47fbSopenharmony_ci         * @brief Send GESTURE_END and TOUCH_END to AccessibleAbility when multi finger gesture complete.
264885b47fbSopenharmony_ci         * @param gestureId the id of gesture.
265885b47fbSopenharmony_ci         */
266885b47fbSopenharmony_ci        void MultiFingerGestureOnCompleted(GestureType gestureId) override;
267885b47fbSopenharmony_ci
268885b47fbSopenharmony_ci        /**
269885b47fbSopenharmony_ci         * @brief The gesture has been cancelled.
270885b47fbSopenharmony_ci         * @param event the touch event from Multimodal
271885b47fbSopenharmony_ci         */
272885b47fbSopenharmony_ci        bool OnCancelled(MMI::PointerEvent &event) override;
273885b47fbSopenharmony_ci
274885b47fbSopenharmony_ci        /**
275885b47fbSopenharmony_ci         * @brief The gesture has been cancelled.
276885b47fbSopenharmony_ci         * @param isNoDelayFlag  whether the gesture recognize process is immediately canceled.
277885b47fbSopenharmony_ci         */
278885b47fbSopenharmony_ci        void MultiFingerGestureOnCancelled(const bool isNoDelayFlag) override;
279885b47fbSopenharmony_ci    private:
280885b47fbSopenharmony_ci        TouchGuider &server_;
281885b47fbSopenharmony_ci    };
282885b47fbSopenharmony_ci
283885b47fbSopenharmony_ci    class ElementOperatorCallbackImpl : public AccessibilityElementOperatorCallbackStub {
284885b47fbSopenharmony_ci    public:
285885b47fbSopenharmony_ci        ElementOperatorCallbackImpl() = default;
286885b47fbSopenharmony_ci        ~ElementOperatorCallbackImpl() = default;
287885b47fbSopenharmony_ci
288885b47fbSopenharmony_ci        virtual void SetSearchElementInfoByAccessibilityIdResult(const std::vector<AccessibilityElementInfo> &infos,
289885b47fbSopenharmony_ci            const int32_t requestId) override;
290885b47fbSopenharmony_ci        virtual void SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> &infos,
291885b47fbSopenharmony_ci            const int32_t requestId) override;
292885b47fbSopenharmony_ci        virtual void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info,
293885b47fbSopenharmony_ci            const int32_t requestId) override;
294885b47fbSopenharmony_ci        virtual void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int32_t requestId) override;
295885b47fbSopenharmony_ci        virtual void SetExecuteActionResult(const bool succeeded, const int32_t requestId) override;
296885b47fbSopenharmony_ci
297885b47fbSopenharmony_ci    private:
298885b47fbSopenharmony_ci        ffrt::promise<void> promise_;
299885b47fbSopenharmony_ci        bool executeActionResult_ = false;
300885b47fbSopenharmony_ci        AccessibilityElementInfo accessibilityInfoResult_ = {};
301885b47fbSopenharmony_ci        std::vector<AccessibilityElementInfo> elementInfosResult_;
302885b47fbSopenharmony_ci
303885b47fbSopenharmony_ci        friend class TouchGuider;
304885b47fbSopenharmony_ci    };
305885b47fbSopenharmony_ci
306885b47fbSopenharmony_ci    /**
307885b47fbSopenharmony_ci     * @brief Determine whether to clear the touchguide.
308885b47fbSopenharmony_ci     */
309885b47fbSopenharmony_ci    void Clear();
310885b47fbSopenharmony_ci
311885b47fbSopenharmony_ci    /**
312885b47fbSopenharmony_ci     * @brief clear the touchguide.
313885b47fbSopenharmony_ci     * @param event the last event from Multimodal
314885b47fbSopenharmony_ci     */
315885b47fbSopenharmony_ci    void Clear(MMI::PointerEvent &event);
316885b47fbSopenharmony_ci
317885b47fbSopenharmony_ci    /**
318885b47fbSopenharmony_ci     * @brief Handle touch events on touchExploring state.
319885b47fbSopenharmony_ci     * @param event the touch event from Multimodal
320885b47fbSopenharmony_ci     */
321885b47fbSopenharmony_ci    void HandleTouchGuidingState(MMI::PointerEvent &event);
322885b47fbSopenharmony_ci
323885b47fbSopenharmony_ci    /**
324885b47fbSopenharmony_ci     * @brief Handle touch events on dragging state.
325885b47fbSopenharmony_ci     * @param event the touch event from Multimodal
326885b47fbSopenharmony_ci     */
327885b47fbSopenharmony_ci    void HandleDraggingState(MMI::PointerEvent &event);
328885b47fbSopenharmony_ci
329885b47fbSopenharmony_ci    /**
330885b47fbSopenharmony_ci     * @brief Handle touch events on transmitting state.
331885b47fbSopenharmony_ci     * @param event the touch event from Multimodal
332885b47fbSopenharmony_ci     */
333885b47fbSopenharmony_ci    void HandleTransmitingState(MMI::PointerEvent &event);
334885b47fbSopenharmony_ci
335885b47fbSopenharmony_ci    /**
336885b47fbSopenharmony_ci     * @brief Handle touch events on passing through state.
337885b47fbSopenharmony_ci     * @param event the touch event from Multimodal
338885b47fbSopenharmony_ci     */
339885b47fbSopenharmony_ci    void HandlePassingThroughState(MMI::PointerEvent &event);
340885b47fbSopenharmony_ci
341885b47fbSopenharmony_ci    /**
342885b47fbSopenharmony_ci     * @brief Determine whether it is a drag gesture.
343885b47fbSopenharmony_ci     * @param event the touch event from Multimodal
344885b47fbSopenharmony_ci     * @return whether the dragGesture is accepted.
345885b47fbSopenharmony_ci     */
346885b47fbSopenharmony_ci    bool IsDragGestureAccept(MMI::PointerEvent &event);
347885b47fbSopenharmony_ci
348885b47fbSopenharmony_ci    /**
349885b47fbSopenharmony_ci     * @brief Get the offset of current points and touch down points.
350885b47fbSopenharmony_ci     * @param event the current touch event from Multimodal.
351885b47fbSopenharmony_ci     * @param firstPointOffset the first finger offset result, xAxis offset and yAxis offset.
352885b47fbSopenharmony_ci     * @param firstPointOffset the second finger offset result, xAxis offset and yAxis offset.
353885b47fbSopenharmony_ci     */
354885b47fbSopenharmony_ci    void GetPointOffset(MMI::PointerEvent &event, std::vector<float> &firstPointOffset,
355885b47fbSopenharmony_ci        std::vector<float> &secondPointOffset) const;
356885b47fbSopenharmony_ci
357885b47fbSopenharmony_ci    /**
358885b47fbSopenharmony_ci     * @brief Determine whether it is a move gesture.
359885b47fbSopenharmony_ci     * @param event the touch event from Multimodal.
360885b47fbSopenharmony_ci     * @return whether this is a scolling.
361885b47fbSopenharmony_ci     */
362885b47fbSopenharmony_ci    bool IsRealMoveState(MMI::PointerEvent &event) const;
363885b47fbSopenharmony_ci
364885b47fbSopenharmony_ci    /**
365885b47fbSopenharmony_ci     * @brief Get Angle Cos value.
366885b47fbSopenharmony_ci     * @param offsetX the X value
367885b47fbSopenharmony_ci     * @param offsetY the Y value
368885b47fbSopenharmony_ci     * @param isGetX whether is the Angle corresponding to the X axis
369885b47fbSopenharmony_ci     * @return Angle Cos value.
370885b47fbSopenharmony_ci     */
371885b47fbSopenharmony_ci    float GetAngleCos(float offsetX, float offsetY, bool isGetX);
372885b47fbSopenharmony_ci
373885b47fbSopenharmony_ci    /**
374885b47fbSopenharmony_ci     * @brief Get the info of injected event.
375885b47fbSopenharmony_ci     * @param event the event prepared to send to Multimodal
376885b47fbSopenharmony_ci     */
377885b47fbSopenharmony_ci    void RecordInjectedEvent(MMI::PointerEvent &event);
378885b47fbSopenharmony_ci
379885b47fbSopenharmony_ci    /**
380885b47fbSopenharmony_ci     * @brief Get the info of Received event.
381885b47fbSopenharmony_ci     * @param event event the touch event from Multimodal
382885b47fbSopenharmony_ci     */
383885b47fbSopenharmony_ci    void RecordReceivedEvent(MMI::PointerEvent &event);
384885b47fbSopenharmony_ci
385885b47fbSopenharmony_ci    /**
386885b47fbSopenharmony_ci     * @brief Send touch event to specific AccessibleAbility.
387885b47fbSopenharmony_ci     * @param event the touch event from Multimodal
388885b47fbSopenharmony_ci     */
389885b47fbSopenharmony_ci    void SendTouchEventToAA(MMI::PointerEvent &event);
390885b47fbSopenharmony_ci
391885b47fbSopenharmony_ci    /**
392885b47fbSopenharmony_ci     * @brief Clear received recorder info.
393885b47fbSopenharmony_ci     */
394885b47fbSopenharmony_ci    void ClearReceivedEventRecorder();
395885b47fbSopenharmony_ci
396885b47fbSopenharmony_ci    /**
397885b47fbSopenharmony_ci     * @brief Clear Injected recorder info.
398885b47fbSopenharmony_ci     */
399885b47fbSopenharmony_ci    void ClearInjectedEventRecorder();
400885b47fbSopenharmony_ci
401885b47fbSopenharmony_ci    /**
402885b47fbSopenharmony_ci     * @brief Send exit event to multimodal.
403885b47fbSopenharmony_ci     */
404885b47fbSopenharmony_ci    void SendExitEvents();
405885b47fbSopenharmony_ci
406885b47fbSopenharmony_ci    /**
407885b47fbSopenharmony_ci     * @brief Send all down events to multimodal.
408885b47fbSopenharmony_ci     * @param event the event prepared to send to Multimodal
409885b47fbSopenharmony_ci     */
410885b47fbSopenharmony_ci    void SendAllDownEvents(MMI::PointerEvent &event);
411885b47fbSopenharmony_ci
412885b47fbSopenharmony_ci    /**
413885b47fbSopenharmony_ci     * @brief Send all up events to multimodal.
414885b47fbSopenharmony_ci     * @param event the event prepared to send to Multimodal
415885b47fbSopenharmony_ci     */
416885b47fbSopenharmony_ci    void SendAllUpEvents(MMI::PointerEvent &event);
417885b47fbSopenharmony_ci
418885b47fbSopenharmony_ci    /**
419885b47fbSopenharmony_ci     * @brief Send all up events to multimodal.
420885b47fbSopenharmony_ci     * @param event the event prepared to send to Multimodal
421885b47fbSopenharmony_ci     */
422885b47fbSopenharmony_ci    void SendUpForAllInjectedEvent(MMI::PointerEvent &event);
423885b47fbSopenharmony_ci
424885b47fbSopenharmony_ci    /**
425885b47fbSopenharmony_ci     * @brief Send exit message.
426885b47fbSopenharmony_ci     */
427885b47fbSopenharmony_ci    void PostGestureRecognizeExit();
428885b47fbSopenharmony_ci
429885b47fbSopenharmony_ci    /**
430885b47fbSopenharmony_ci     * @brief Send enter and move message.
431885b47fbSopenharmony_ci     * @param event event the touch event from Multimodal
432885b47fbSopenharmony_ci     */
433885b47fbSopenharmony_ci    void PostHoverEnterAndMove(MMI::PointerEvent &event);
434885b47fbSopenharmony_ci
435885b47fbSopenharmony_ci    /**
436885b47fbSopenharmony_ci     * @brief Send exit message.
437885b47fbSopenharmony_ci     */
438885b47fbSopenharmony_ci    void PostHoverExit();
439885b47fbSopenharmony_ci
440885b47fbSopenharmony_ci    /**
441885b47fbSopenharmony_ci     * @brief Send accessibility event message.
442885b47fbSopenharmony_ci     * @param innerEventID the id of inner event
443885b47fbSopenharmony_ci     */
444885b47fbSopenharmony_ci    void PostAccessibilityEvent(uint32_t innerEventID);
445885b47fbSopenharmony_ci
446885b47fbSopenharmony_ci    /**
447885b47fbSopenharmony_ci     * @brief Cancel message.
448885b47fbSopenharmony_ci     * @param innerEventID the id of inner event
449885b47fbSopenharmony_ci     */
450885b47fbSopenharmony_ci    void CancelPostEvent(uint32_t innerEventID);
451885b47fbSopenharmony_ci
452885b47fbSopenharmony_ci    /**
453885b47fbSopenharmony_ci     * @brief Cancel message if it has been sent.
454885b47fbSopenharmony_ci     * @param innerEventID the id of inner event
455885b47fbSopenharmony_ci     */
456885b47fbSopenharmony_ci    void CancelPostEventIfNeed(uint32_t innerEventID);
457885b47fbSopenharmony_ci
458885b47fbSopenharmony_ci    /**
459885b47fbSopenharmony_ci     * @brief Check whether it has been sending.
460885b47fbSopenharmony_ci     * @param innerEventID the id of inner event
461885b47fbSopenharmony_ci     */
462885b47fbSopenharmony_ci    bool HasEventPending(uint32_t innerEventID);
463885b47fbSopenharmony_ci
464885b47fbSopenharmony_ci    /**
465885b47fbSopenharmony_ci     * @brief Force send and remove event.
466885b47fbSopenharmony_ci     * @param innerEventID the id of inner event
467885b47fbSopenharmony_ci     * @param event event the touch event from Multimodal
468885b47fbSopenharmony_ci     */
469885b47fbSopenharmony_ci    void ForceSendAndRemoveEvent(uint32_t innerEventID, MMI::PointerEvent &event);
470885b47fbSopenharmony_ci
471885b47fbSopenharmony_ci    /**
472885b47fbSopenharmony_ci     * @brief Handle down events on touchExploring state.
473885b47fbSopenharmony_ci     * @param event event the touch event from Multimodal
474885b47fbSopenharmony_ci     */
475885b47fbSopenharmony_ci    void HandleTouchGuidingStateInnerDown(MMI::PointerEvent &event);
476885b47fbSopenharmony_ci
477885b47fbSopenharmony_ci    /**
478885b47fbSopenharmony_ci     * @brief Handle move events on touchExploring state.
479885b47fbSopenharmony_ci     * @param event event the touch event from Multimodal
480885b47fbSopenharmony_ci     */
481885b47fbSopenharmony_ci    void HandleTouchGuidingStateInnerMove(MMI::PointerEvent &event);
482885b47fbSopenharmony_ci
483885b47fbSopenharmony_ci    /**
484885b47fbSopenharmony_ci     * @brief Handle move events on dragging state.
485885b47fbSopenharmony_ci     * @param event event the touch event from Multimodal
486885b47fbSopenharmony_ci     */
487885b47fbSopenharmony_ci    void HandleDraggingStateInnerMove(MMI::PointerEvent &event);
488885b47fbSopenharmony_ci
489885b47fbSopenharmony_ci    /**
490885b47fbSopenharmony_ci     * @brief Ignore repeat execute action.
491885b47fbSopenharmony_ci     */
492885b47fbSopenharmony_ci    bool IgnoreRepeatExecuteAction();
493885b47fbSopenharmony_ci
494885b47fbSopenharmony_ci    /**
495885b47fbSopenharmony_ci     * @brief Calculate Offset.
496885b47fbSopenharmony_ci     * @param event event the touch event from Multimodal
497885b47fbSopenharmony_ci     */
498885b47fbSopenharmony_ci    void OffsetEvent(MMI::PointerEvent &event);
499885b47fbSopenharmony_ci
500885b47fbSopenharmony_ci    /**
501885b47fbSopenharmony_ci     * @brief Find Focused Element.
502885b47fbSopenharmony_ci     * @param elementInfo the focused element.
503885b47fbSopenharmony_ci     * @return Returns true if find focused flement successfully; returns false code otherwise.
504885b47fbSopenharmony_ci     */
505885b47fbSopenharmony_ci    bool FindFocusedElement(AccessibilityElementInfo &elementInfo);
506885b47fbSopenharmony_ci
507885b47fbSopenharmony_ci    int32_t currentState_ = -1;
508885b47fbSopenharmony_ci    int32_t longPressPointId_ = INIT_POINT_ID;
509885b47fbSopenharmony_ci    float longPressOffsetX_ = INIT_MMIPOINT;
510885b47fbSopenharmony_ci    float longPressOffsetY_ = INIT_MMIPOINT;
511885b47fbSopenharmony_ci    bool isTouchStart_ = false;
512885b47fbSopenharmony_ci    bool isTouchGuiding_ = false;
513885b47fbSopenharmony_ci    ReceivedEventRecorder receivedRecorder_ = {};
514885b47fbSopenharmony_ci    InjectedEventRecorder injectedRecorder_ = {};
515885b47fbSopenharmony_ci    std::list<MMI::PointerEvent> pointerEvents_ {};
516885b47fbSopenharmony_ci    AccessibilityGestureRecognizer gestureRecognizer_;
517885b47fbSopenharmony_ci    AccessibilityMultiTapGestureRecognizer multiFingerGestureRecognizer_;
518885b47fbSopenharmony_ci    std::unique_ptr<TouchGuideListener> touchGuideListener_ = nullptr;
519885b47fbSopenharmony_ci    std::shared_ptr<TGEventHandler> handler_ = nullptr;
520885b47fbSopenharmony_ci    std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
521885b47fbSopenharmony_ci    std::shared_ptr<MMI::PointerEvent> doubleTapLongPressDownEvent_ = nullptr;
522885b47fbSopenharmony_ci    bool focusedElementExist_ = false;
523885b47fbSopenharmony_ci    int32_t leftTopX_ = INIT_POINT_DISPLAY;
524885b47fbSopenharmony_ci    int32_t leftTopY_ = INIT_POINT_DISPLAY;
525885b47fbSopenharmony_ci    int32_t rightBottomX_ = INIT_POINT_DISPLAY;
526885b47fbSopenharmony_ci    int32_t rightBottomY_ = INIT_POINT_DISPLAY;
527885b47fbSopenharmony_ci    int32_t currentPid_ = -1;
528885b47fbSopenharmony_ci    std::list<MMI::PointerEvent> cachedPointerEvents_ {};
529885b47fbSopenharmony_ci};
530885b47fbSopenharmony_ci} // namespace Accessibility
531885b47fbSopenharmony_ci} // namespace OHOS
532885b47fbSopenharmony_ci#endif // ACCESSIBILITY_TOUCH_GUIDER_H