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 : public EventTransmission { 36 public: 37 /** 38 * @brief A constructor used to create a screen touch instance. 39 */ 40 AccessibilityScreenTouch(); 41 42 /** 43 * @brief A destructor used to delete the screen touch instance. 44 */ 45 ~AccessibilityScreenTouch(); 46 47 /** 48 * @brief Handle pointer events from previous event stream node. 49 * 50 * @param event the pointer event to be handled. 51 * @return true: the event has been processed and does not need to be passed to the next node; 52 * false: the event is not processed. 53 */ 54 bool OnPointerEvent(MMI::PointerEvent &event) override; 55 56 uint32_t GetRealClickResponseTime(); 57 uint32_t GetRealIgnoreRepeatClickTime(); 58 bool GetRealIgnoreRepeatClickState(); 59 private: 60 void HandleResponseDelayStateInnerDown(MMI::PointerEvent &event); 61 void HandleResponseDelayStateInnerMove(MMI::PointerEvent &event); 62 void HandleResponseDelayStateInnerUp(MMI::PointerEvent &event); 63 void HandleResponseDelayState(MMI::PointerEvent &event); 64 65 void HandleIgnoreRepeatClickStateInnerDown(MMI::PointerEvent &event); 66 void HandleIgnoreRepeatClickStateInnerMove(MMI::PointerEvent &event); 67 void HandleIgnoreRepeatClickStateInnerUp(MMI::PointerEvent &event); 68 void HandleIgnoreRepeatClickState(MMI::PointerEvent &event); 69 70 void HandleBothStateInnerDown(MMI::PointerEvent &event); 71 void HandleBothStateInnerMove(MMI::PointerEvent &event); 72 void HandleBothStateInnerUp(MMI::PointerEvent &event); 73 void HandleBothState(MMI::PointerEvent &event); 74 75 void Clear(); 76 77 void DrawCircleProgress(); 78 79 bool isFirstDownEvent_ = false; 80 bool isMoveBeyondThreshold_ = false; 81 int64_t startTime_ = 0; // microsecond 82 double threshold_ = 0.0; 83 MMI::PointerEvent::PointerItem startPointer_ = {}; 84 85 int64_t lastUpTime_ = 0; 86 bool isInterceptClick_ = false; 87 88 ScreenTouchState currentState_; 89 uint32_t clickResponseTime_; 90 bool ignoreRepeatClickState_; 91 uint32_t ignoreRepeatClickTime_; 92 93 std::atomic<int32_t> circleCenterPhysicalX_; 94 std::atomic<int32_t> circleCenterPhysicalY_; 95 std::atomic<bool> isStopDrawCircle_; 96 std::shared_ptr<std::thread> drawCircleThread_ = nullptr; 97 98 static int64_t lastUpTime; // global last up time 99 }; 100 } // namespace Accessibility 101 } // namespace OHOS 102 #endif // ACCESSIBILITY_TOUCH_GUIDER_H