• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 ACCESSIBILITY_SCREEN_TOUCH_H
17 #define ACCESSIBILITY_SCREEN_TOUCH_H
18 
19 #include <atomic>
20 #include <string>
21 #include <thread>
22 #include "accessibility_event_transmission.h"
23 #include "accessibility_gesture_recognizer.h"
24 
25 namespace OHOS {
26 namespace Accessibility {
27 
28 enum ScreenTouchState : int32_t {
29     DEFAULT_STATE,
30     CLICK_RESPONSE_DELAY_STATE,
31     IGNORE_REPEAT_CLICK_STATE,
32     BOTH_RESPONSE_DELAY_IGNORE_REPEAT_CLICK
33 };
34 
35 class AccessibilityScreenTouch;
36 class ScreenTouchHandler : public AppExecFwk::EventHandler {
37 public:
38     ScreenTouchHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner, AccessibilityScreenTouch &server);
39     virtual ~ScreenTouchHandler() = default;
40     /**
41      * @brief Process the event of install system bundles.
42      * @param event Indicates the event to be processed.
43      */
44     virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
45 private:
46     AccessibilityScreenTouch &server_;
47 };
48 
49 class AccessibilityScreenTouch : public EventTransmission {
50 public:
51     static constexpr uint32_t FINGER_DOWN_DELAY_MSG = 0;
52 
53     /**
54      * @brief A constructor used to create a screen touch instance.
55      */
56     AccessibilityScreenTouch();
57 
58     /**
59      * @brief A destructor used to delete the screen touch instance.
60      */
61     ~AccessibilityScreenTouch();
62 
63     /**
64      * @brief Handle pointer events from previous event stream node.
65      *
66      * @param event  the pointer event to be handled.
67      * @return true: the event has been processed and does not need to be passed to the next node;
68      *         false: the event is not processed.
69      */
70     bool OnPointerEvent(MMI::PointerEvent &event) override;
71 
72     uint32_t GetRealClickResponseTime();
73     uint32_t GetRealIgnoreRepeatClickTime();
74     bool GetRealIgnoreRepeatClickState();
75     void SendInterceptedEvent();
76 private:
77     void HandleResponseDelayStateInnerDown(MMI::PointerEvent &event);
78     void HandleResponseDelayStateInnerMove(MMI::PointerEvent &event);
79     void HandleResponseDelayStateInnerUp(MMI::PointerEvent &event);
80     void HandleResponseDelayState(MMI::PointerEvent &event);
81 
82     void HandleIgnoreRepeatClickStateInnerDown(MMI::PointerEvent &event);
83     void HandleIgnoreRepeatClickStateInnerMove(MMI::PointerEvent &event);
84     void HandleIgnoreRepeatClickStateInnerUp(MMI::PointerEvent &event);
85     void HandleIgnoreRepeatClickState(MMI::PointerEvent &event);
86 
87     void HandleBothStateInnerDown(MMI::PointerEvent &event);
88     void HandleBothStateInnerMove(MMI::PointerEvent &event);
89     void HandleBothStateInnerUp(MMI::PointerEvent &event);
90     void HandleBothState(MMI::PointerEvent &event);
91 
92     void Clear();
93 
94     void ConversionCoordinates(MMI::PointerEvent::PointerItem &item);
95     void DrawCircleProgress();
96 
97     bool isMoveBeyondThreshold_ = false;
98     int64_t startTime_ = 0; // microsecond
99     std::shared_ptr<MMI::PointerEvent::PointerItem> startPointer_ = nullptr;
100     int32_t screenId_ = 0;
101 
102     int64_t lastUpTime_ = 0;
103     bool isInterceptClick_ = false;
104 
105     ScreenTouchState currentState_;
106     uint32_t clickResponseTime_;
107     bool ignoreRepeatClickState_;
108     uint32_t ignoreRepeatClickTime_;
109 
110     std::atomic<int32_t> circleCenterPhysicalX_;
111     std::atomic<int32_t> circleCenterPhysicalY_;
112     int32_t startAngle_ = 0;
113     std::atomic<bool> isStopDrawCircle_;
114     std::shared_ptr<std::thread> drawCircleThread_ = nullptr;
115 
116     static int64_t lastUpTime; // global last up time
117 
118     std::shared_ptr<ScreenTouchHandler> handler_ = nullptr;
119     std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
120 
121     std::list<MMI::PointerEvent> cachedDownPointerEvents_ {};
122 };
123 } // namespace Accessibility
124 } // namespace OHOS
125 #endif // ACCESSIBILITY_TOUCH_GUIDER_H