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_INPUT_INTERCEPTOR_H 17 #define ACCESSIBILITY_INPUT_INTERCEPTOR_H 18 19 #include <map> 20 #include <memory> 21 #include <vector> 22 23 #include "accessibility_event_transmission.h" 24 #include "accessibility_mouse_key.h" 25 #include "event_handler.h" 26 #include "i_input_event_consumer.h" 27 #include "input_manager.h" 28 #include "key_event.h" 29 #include "pointer_event.h" 30 31 namespace OHOS { 32 namespace Accessibility { 33 class AccessibleAbilityManagerService; 34 35 class AccessibilityInputEventConsumer : public MMI::IInputEventConsumer { 36 public: 37 AccessibilityInputEventConsumer(); 38 ~AccessibilityInputEventConsumer(); 39 void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 40 void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent)41 void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override {}; 42 private: 43 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr; 44 }; 45 46 class AccessibilityInputInterceptor : public EventTransmission { 47 public: 48 // Feature flag for screen magnification. 49 static constexpr uint32_t FEATURE_SCREEN_MAGNIFICATION = 0x00000001; 50 51 // Feature flag for touch exploration. 52 static constexpr uint32_t FEATURE_TOUCH_EXPLORATION = 0x00000002; 53 54 // Feature flag for filtering key events. 55 static constexpr uint32_t FEATURE_FILTER_KEY_EVENTS = 0x00000004; 56 57 // Feature flag for inject touch events. 58 static constexpr uint32_t FEATURE_INJECT_TOUCH_EVENTS = 0x00000008; 59 60 // Feature flag for mouse autoclick. 61 static constexpr uint32_t FEATURE_MOUSE_AUTOCLICK = 0x00000010; 62 63 // Feature flag for short key. 64 static constexpr uint32_t FEATURE_SHORT_KEY = 0x00000020; 65 66 // Feature flag for mouse key. 67 static constexpr uint32_t FEATURE_MOUSE_KEY = 0x00000040; 68 69 // Feature flag for screen touch. 70 static constexpr uint32_t FEATURE_SCREEN_TOUCH = 0x00000080; 71 72 static sptr<AccessibilityInputInterceptor> GetInstance(); 73 ~AccessibilityInputInterceptor(); 74 void ProcessKeyEvent(std::shared_ptr<MMI::KeyEvent> event) const; 75 void ProcessPointerEvent(std::shared_ptr<MMI::PointerEvent> event) const; 76 bool OnKeyEvent(MMI::KeyEvent &event) override; 77 bool OnPointerEvent(MMI::PointerEvent &event) override; 78 void OnMoveMouse(int32_t offsetX, int32_t offsetY) override; 79 void SetAvailableFunctions(uint32_t availableFunctions); 80 81 private: 82 AccessibilityInputInterceptor(); 83 static sptr<AccessibilityInputInterceptor> instance_; 84 void CreateTransmitters(); 85 void DestroyTransmitters(); 86 void CreatePointerEventTransmitters(); 87 void CreateKeyEventTransmitters(); 88 void SetNextEventTransmitter(sptr<EventTransmission> &header, sptr<EventTransmission> ¤t, 89 const sptr<EventTransmission> &next); 90 void UpdateInterceptor(); 91 void DestroyInterceptor(); 92 93 sptr<EventTransmission> pointerEventTransmitters_ = nullptr; 94 sptr<EventTransmission> keyEventTransmitters_ = nullptr; 95 sptr<EventTransmission> mouseKey_ = nullptr; 96 uint32_t availableFunctions_ = 0; 97 int32_t interceptorId_ = -1; 98 MMI::InputManager *inputManager_ = nullptr; 99 std::shared_ptr<AccessibilityInputEventConsumer> inputEventConsumer_ = nullptr; 100 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr; 101 }; 102 } // namespace Accessibility 103 } // namespace OHOS 104 #endif // ACCESSIBILITY_INPUT_INTERCEPTOR_H 105