1885b47fbSopenharmony_ci/*
2885b47fbSopenharmony_ci * Copyright (C) 2023 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_SCREEN_TOUCH_H
17885b47fbSopenharmony_ci#define ACCESSIBILITY_SCREEN_TOUCH_H
18885b47fbSopenharmony_ci
19885b47fbSopenharmony_ci#include <atomic>
20885b47fbSopenharmony_ci#include <string>
21885b47fbSopenharmony_ci#include <thread>
22885b47fbSopenharmony_ci#include "accessibility_event_transmission.h"
23885b47fbSopenharmony_ci#include "accessibility_gesture_recognizer.h"
24885b47fbSopenharmony_ci
25885b47fbSopenharmony_cinamespace OHOS {
26885b47fbSopenharmony_cinamespace Accessibility {
27885b47fbSopenharmony_ci
28885b47fbSopenharmony_cienum ScreenTouchState : int32_t {
29885b47fbSopenharmony_ci    DEFAULT_STATE,
30885b47fbSopenharmony_ci    CLICK_RESPONSE_DELAY_STATE,
31885b47fbSopenharmony_ci    IGNORE_REPEAT_CLICK_STATE,
32885b47fbSopenharmony_ci    BOTH_RESPONSE_DELAY_IGNORE_REPEAT_CLICK
33885b47fbSopenharmony_ci};
34885b47fbSopenharmony_ci
35885b47fbSopenharmony_ciclass AccessibilityScreenTouch;
36885b47fbSopenharmony_ciclass ScreenTouchHandler : public AppExecFwk::EventHandler {
37885b47fbSopenharmony_cipublic:
38885b47fbSopenharmony_ci    ScreenTouchHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner, AccessibilityScreenTouch &server);
39885b47fbSopenharmony_ci    virtual ~ScreenTouchHandler() = default;
40885b47fbSopenharmony_ci    /**
41885b47fbSopenharmony_ci     * @brief Process the event of install system bundles.
42885b47fbSopenharmony_ci     * @param event Indicates the event to be processed.
43885b47fbSopenharmony_ci     */
44885b47fbSopenharmony_ci    virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
45885b47fbSopenharmony_ciprivate:
46885b47fbSopenharmony_ci    AccessibilityScreenTouch &server_;
47885b47fbSopenharmony_ci};
48885b47fbSopenharmony_ci
49885b47fbSopenharmony_ciclass AccessibilityScreenTouch : public EventTransmission {
50885b47fbSopenharmony_cipublic:
51885b47fbSopenharmony_ci    static constexpr uint32_t FINGER_DOWN_DELAY_MSG = 0;
52885b47fbSopenharmony_ci
53885b47fbSopenharmony_ci    /**
54885b47fbSopenharmony_ci     * @brief A constructor used to create a screen touch instance.
55885b47fbSopenharmony_ci     */
56885b47fbSopenharmony_ci    AccessibilityScreenTouch();
57885b47fbSopenharmony_ci
58885b47fbSopenharmony_ci    /**
59885b47fbSopenharmony_ci     * @brief A destructor used to delete the screen touch instance.
60885b47fbSopenharmony_ci     */
61885b47fbSopenharmony_ci    ~AccessibilityScreenTouch();
62885b47fbSopenharmony_ci
63885b47fbSopenharmony_ci    /**
64885b47fbSopenharmony_ci     * @brief Handle pointer events from previous event stream node.
65885b47fbSopenharmony_ci     *
66885b47fbSopenharmony_ci     * @param event  the pointer event to be handled.
67885b47fbSopenharmony_ci     * @return true: the event has been processed and does not need to be passed to the next node;
68885b47fbSopenharmony_ci     *         false: the event is not processed.
69885b47fbSopenharmony_ci     */
70885b47fbSopenharmony_ci    bool OnPointerEvent(MMI::PointerEvent &event) override;
71885b47fbSopenharmony_ci
72885b47fbSopenharmony_ci    uint32_t GetRealClickResponseTime();
73885b47fbSopenharmony_ci    uint32_t GetRealIgnoreRepeatClickTime();
74885b47fbSopenharmony_ci    bool GetRealIgnoreRepeatClickState();
75885b47fbSopenharmony_ci    void SendInterceptedEvent();
76885b47fbSopenharmony_ciprivate:
77885b47fbSopenharmony_ci    void HandleResponseDelayStateInnerDown(MMI::PointerEvent &event);
78885b47fbSopenharmony_ci    void HandleResponseDelayStateInnerMove(MMI::PointerEvent &event);
79885b47fbSopenharmony_ci    void HandleResponseDelayStateInnerUp(MMI::PointerEvent &event);
80885b47fbSopenharmony_ci    void HandleResponseDelayState(MMI::PointerEvent &event);
81885b47fbSopenharmony_ci
82885b47fbSopenharmony_ci    void HandleIgnoreRepeatClickStateInnerDown(MMI::PointerEvent &event);
83885b47fbSopenharmony_ci    void HandleIgnoreRepeatClickStateInnerMove(MMI::PointerEvent &event);
84885b47fbSopenharmony_ci    void HandleIgnoreRepeatClickStateInnerUp(MMI::PointerEvent &event);
85885b47fbSopenharmony_ci    void HandleIgnoreRepeatClickState(MMI::PointerEvent &event);
86885b47fbSopenharmony_ci
87885b47fbSopenharmony_ci    void HandleBothStateInnerDown(MMI::PointerEvent &event);
88885b47fbSopenharmony_ci    void HandleBothStateInnerMove(MMI::PointerEvent &event);
89885b47fbSopenharmony_ci    void HandleBothStateInnerUp(MMI::PointerEvent &event);
90885b47fbSopenharmony_ci    void HandleBothState(MMI::PointerEvent &event);
91885b47fbSopenharmony_ci
92885b47fbSopenharmony_ci    void Clear();
93885b47fbSopenharmony_ci
94885b47fbSopenharmony_ci    void HandleCoordinates(MMI::PointerEvent::PointerItem &item);
95885b47fbSopenharmony_ci    void ConversionCoordinates(int32_t originalX, int32_t originalY);
96885b47fbSopenharmony_ci    void DrawCircleProgress();
97885b47fbSopenharmony_ci
98885b47fbSopenharmony_ci    bool isMoveBeyondThreshold_ = false;
99885b47fbSopenharmony_ci    int64_t startTime_ = 0; // microsecond
100885b47fbSopenharmony_ci    std::shared_ptr<MMI::PointerEvent::PointerItem> startPointer_ = nullptr;
101885b47fbSopenharmony_ci    int32_t screenId_ = 0;
102885b47fbSopenharmony_ci
103885b47fbSopenharmony_ci    int64_t lastUpTime_ = 0;
104885b47fbSopenharmony_ci    bool isInterceptClick_ = false;
105885b47fbSopenharmony_ci
106885b47fbSopenharmony_ci    ScreenTouchState currentState_;
107885b47fbSopenharmony_ci    uint32_t clickResponseTime_;
108885b47fbSopenharmony_ci    bool ignoreRepeatClickState_;
109885b47fbSopenharmony_ci    uint32_t ignoreRepeatClickTime_;
110885b47fbSopenharmony_ci
111885b47fbSopenharmony_ci    std::atomic<int32_t> circleCenterPhysicalX_;
112885b47fbSopenharmony_ci    std::atomic<int32_t> circleCenterPhysicalY_;
113885b47fbSopenharmony_ci    int32_t startAngle_ = 0;
114885b47fbSopenharmony_ci    std::atomic<bool> isStopDrawCircle_;
115885b47fbSopenharmony_ci    std::shared_ptr<std::thread> drawCircleThread_ = nullptr;
116885b47fbSopenharmony_ci
117885b47fbSopenharmony_ci    static int64_t lastUpTime; // global last up time
118885b47fbSopenharmony_ci
119885b47fbSopenharmony_ci    std::shared_ptr<ScreenTouchHandler> handler_ = nullptr;
120885b47fbSopenharmony_ci    std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
121885b47fbSopenharmony_ci
122885b47fbSopenharmony_ci    std::list<MMI::PointerEvent> cachedDownPointerEvents_ {};
123885b47fbSopenharmony_ci};
124885b47fbSopenharmony_ci} // namespace Accessibility
125885b47fbSopenharmony_ci} // namespace OHOS
126885b47fbSopenharmony_ci#endif // ACCESSIBILITY_TOUCH_GUIDER_H