1 /* 2 * Copyright (C) 2022 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_ZOOM_HANDLER_H 17 #define ACCESSIBILITY_ZOOM_HANDLER_H 18 19 #include <vector> 20 #include <mutex> 21 #include "accessibility_event_transmission.h" 22 #include "accessibility_zoom_proxy.h" 23 #include "accessibility_zoom_gesture.h" 24 25 namespace OHOS { 26 namespace Accessibility { 27 /** 28 * @brief Zoom state machine. 29 * When the magnifying function is turned on, it is in ReadyState. 30 * After the triple event, it will enter the ZoomInState. 31 * After another triple event, it will exit the magnifying state 32 * and enter the ReadyState again. 33 * In the amplification state, if the two fingers are pressed down, 34 * it will enter the SlidingState, and any finger will be lifted 35 * up to exit the SlidingState and enter the ZoomInState again. 36 * 37 * (ReadyState) 38 * | ^ 39 * Triple | | (Triple|Action_cancel|screen_off) 40 * V | 41 * (ZoomInState) 42 * | ^ 43 * Two fingers down | | Any finger up 44 * V | 45 * (SlidingState) 46 * 47 */ 48 enum ACCESSIBILITY_ZOOM_STATE { 49 READY_STATE, 50 ZOOMIN_STATE, 51 SLIDING_STATE 52 }; 53 54 class ZoomObserver { 55 public: ZoomObserver()56 ZoomObserver() {} ~ZoomObserver()57 virtual ~ZoomObserver() {} OnTransitionTo(const int state)58 virtual void OnTransitionTo(const int state) {} OnBack(MMI::PointerEvent & event)59 virtual void OnBack(MMI::PointerEvent &event) {} OnZoomIn()60 virtual void OnZoomIn() {} OnZoomOut()61 virtual void OnZoomOut() {} 62 }; 63 64 class ZoomState { 65 public: Enter()66 virtual void Enter() {} Exit()67 virtual void Exit() {} OnPointerEvent(MMI::PointerEvent & event)68 virtual void OnPointerEvent(MMI::PointerEvent &event) {} 69 std::vector<ZoomObserver> observer_ {}; 70 71 public: Register(ZoomObserver & observer)72 void Register(ZoomObserver &observer) 73 { 74 observer_.push_back(observer); 75 } UnRegisterAll()76 void UnRegisterAll() 77 { 78 observer_.erase(observer_.begin(), observer_.end()); 79 } 80 81 private: 82 }; 83 84 /** 85 * @brief The event processing. 86 * 87 * @since 1.0 88 * @version 1.0 89 */ 90 class AccessibilityZoomHandler : public ZoomObserver, public EventTransmission { 91 public: 92 /** 93 * @brief A constructor used to create a zoom handler. 94 * 95 * @param proxy AccessibilityZoomProxy reference. 96 * @param displayId The Logical display id. 97 * @since 1.0 98 * @version 1.0 99 */ 100 explicit AccessibilityZoomHandler(int displayId); 101 102 /** 103 * @brief A destructor used to delete the zoom handler. 104 * 105 * @since 1.0 106 * @version 1.0 107 */ 108 virtual ~AccessibilityZoomHandler(); 109 110 /** 111 * @brief Callback function when handle a motion event. 112 * 113 * @since 1.0 114 * @version 1.0 115 */ 116 virtual void OnPointerEvent(MMI::PointerEvent &event) override; 117 118 private: 119 120 class ReadyState : public ZoomState { 121 public: 122 virtual void Enter() override; 123 virtual void Exit() override; 124 virtual void OnPointerEvent(MMI::PointerEvent &event) override; 125 private: 126 AccessibilityZoomGesture gesture_ {}; 127 }; 128 129 /** 130 * Triple down. 131 */ 132 class ZoomInState : public ZoomState { 133 public: 134 virtual void Enter() override; 135 virtual void Exit() override; 136 virtual void OnPointerEvent(MMI::PointerEvent &event) override; 137 private: 138 AccessibilityZoomGesture gesture_ {}; 139 }; 140 141 /** 142 * the two fingers are pressed down. 143 */ 144 class SlidingState : public ZoomState { 145 public: 146 virtual void Enter() override; 147 virtual void Exit() override; 148 virtual void OnPointerEvent(MMI::PointerEvent &event) override; 149 virtual bool OnScroll(); 150 virtual bool OnScale(); 151 }; 152 153 ZoomState currentState_ {}; 154 ReadyState readyState_ {}; 155 ZoomInState zoomInState_ {}; 156 SlidingState slidingState_ {}; 157 std::recursive_mutex stateMutex_ {}; 158 int displayId_ = 0; 159 void Initialize(); 160 void OnBack(MMI::PointerEvent &event) override; 161 void OnTransitionTo(const int state) override; 162 void OnZoomIn() override; 163 void OnZoomOut() override; 164 }; 165 } // namespace Accessibility 166 } // namespace OHOS 167 #endif // ACCESSIBILITY_ZOOM_HANDLER_H 168