• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "accessibility_zoom_gesture.h"
26 #include "event_handler.h"
27 #include "ffrt.h"
28 #include "i_input_event_consumer.h"
29 #include "input_manager.h"
30 #include "key_event.h"
31 #include "pointer_event.h"
32 #include "window_magnification_gesture.h"
33 
34 namespace OHOS {
35 namespace Accessibility {
36 class AccessibleAbilityManagerService;
37 
38 class AccessibilityInputEventConsumer : public MMI::IInputEventConsumer {
39 public:
40     AccessibilityInputEventConsumer();
41     ~AccessibilityInputEventConsumer();
42     void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
43     void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent)44     void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override {};
45 private:
46     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
47 };
48 
49 class AccessibilityInputInterceptor : public EventTransmission {
50 public:
51     // Feature flag for screen magnification.
52     static constexpr uint32_t FEATURE_SCREEN_MAGNIFICATION = 0x00000001;
53 
54     // Feature flag for touch exploration.
55     static constexpr uint32_t FEATURE_TOUCH_EXPLORATION = 0x00000002;
56 
57     // Feature flag for filtering key events.
58     static constexpr uint32_t FEATURE_FILTER_KEY_EVENTS = 0x00000004;
59 
60     // Feature flag for inject touch events.
61     static constexpr uint32_t FEATURE_INJECT_TOUCH_EVENTS = 0x00000008;
62 
63     // Feature flag for mouse autoclick.
64     static constexpr uint32_t FEATURE_MOUSE_AUTOCLICK = 0x00000010;
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 constexpr uint32_t PRIORITY_EVENT = 500;
73 
74     static sptr<AccessibilityInputInterceptor> GetInstance();
75     ~AccessibilityInputInterceptor();
76     void ProcessKeyEvent(std::shared_ptr<MMI::KeyEvent> event);
77     void ProcessPointerEvent(std::shared_ptr<MMI::PointerEvent> event);
78     bool OnKeyEvent(MMI::KeyEvent &event) override;
79     bool OnPointerEvent(MMI::PointerEvent &event) override;
80     void OnMoveMouse(int32_t offsetX, int32_t offsetY) override;
81     void SetAvailableFunctions(uint32_t availableFunctions);
82 
83     // flag = true shield zoom gesture | flag = false restore zoom gesture
84     void ShieldZoomGesture(bool flag);
85     void RefreshDisplayInfo();
86     void StartMagnificationInteract(uint32_t mode);
87     void EnableGesture(uint32_t mode);
88     void DisableGesture(uint32_t mode);
89 
90 private:
91     AccessibilityInputInterceptor();
92     static sptr<AccessibilityInputInterceptor> instance_;
93     void CreateTransmitters();
94     void DestroyTransmitters();
95     void CreatePointerEventTransmitters();
96     void CreateKeyEventTransmitters();
97     void SetNextEventTransmitter(sptr<EventTransmission> &header, sptr<EventTransmission> &current,
98         const sptr<EventTransmission> &next);
99     void UpdateInterceptor();
100     void DestroyInterceptor();
101     void CreateMagnificationGesture(sptr<EventTransmission> &header, sptr<EventTransmission> &current);
102     void CreatZoomGesture();
103     void CreatWindowMagnificationGesture();
104     void ClearMagnificationGesture();
105 
106     sptr<EventTransmission> pointerEventTransmitters_ = nullptr;
107     sptr<EventTransmission> keyEventTransmitters_ = nullptr;
108     sptr<EventTransmission> mouseKey_ = nullptr;
109     uint32_t availableFunctions_ = 0;
110     int32_t interceptorId_ = -1;
111     MMI::InputManager *inputManager_ = nullptr;
112     std::shared_ptr<AccessibilityInputEventConsumer> inputEventConsumer_ = nullptr;
113     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
114     ffrt::mutex mutex_;
115 
116     sptr<AccessibilityZoomGesture> zoomGesture_ = nullptr;
117     sptr<WindowMagnificationGesture> windowMagnificationGesture_ = nullptr;
118     bool needInteractMagnification_ = false;
119 };
120 } // namespace Accessibility
121 } // namespace OHOS
122 #endif // ACCESSIBILITY_INPUT_INTERCEPTOR_H
123