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