• 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_EXTENSION_CONTEXT_H
17 #define ACCESSIBILITY_EXTENSION_CONTEXT_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <memory>
22 #include <optional>
23 
24 #include "accessibility_element_info.h"
25 #include "accessibility_window_info.h"
26 #include "display_resize_controller.h"
27 #include "extension_context.h"
28 #include "gesture_simulation.h"
29 #include "key_event.h"
30 
31 namespace OHOS {
32 namespace Accessibility {
33 enum GlobalAction : uint32_t {
34     GLOBAL_ACTION_INVALID = 0x0000,
35     GLOBAL_ACTION_BACK = 0x0001,
36     GLOBAL_ACTION_HOME = 0x0002,
37     GLOBAL_ACTION_RECENT = 0x0003,
38     GLOBAL_ACTION_NOTIFICATION = 0x0004,
39     GLOBAL_ACTION_POP_UP_POWER_DIALOG = 0x0006,
40     GLOBAL_ACTION_DIVIDE_SCREEN = 0x0007,
41     GLOBAL_ACTION_LOCK_SCREEN = 0x0008,
42     GLOBAL_ACTION_CAPTURE_SCREEN = 0x0009
43 };
44 
45 class AccessibilityExtensionContext : public AbilityRuntime::ExtensionContext {
46 public:
47     AccessibilityExtensionContext() = default;
48     virtual ~AccessibilityExtensionContext() = default;
49 
50     /**
51      * @brief Obtains elementInfo of focus.
52      * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY.
53      * @param elementInfo The accessibilityElementInfo of focus.
54      * @return Return true if obtains elementInfo successfully, else return false.
55      */
56     bool GetFocusElementInfo(uint32_t focusType, std::optional<AccessibilityElementInfo>& elementInfo);
57 
58     /**
59      * @brief Sends simulate gestures to the screen.
60      * @param gesturePathDefineList The gesture which need to send.
61      * @param listener The listener of the gesture.
62      * @return Return true if the gesture sends successfully, else return false.
63      */
64     bool GestureSimulate(uint32_t sequence, const std::vector<GesturePathDefine>& gesturePathDefineList,
65         const std::shared_ptr<GestureResultListener>& listener);
66 
67     /**
68      * @brief Obtains the default displayResize controller.
69      * @param
70      * @return Return the default displayResize controller.
71      */
72     std::shared_ptr<DisplayResizeController>& GetDisplayResizeController();
73 
74     /**
75      * @brief Obtains the specified displayResize controller by displayId.
76      * @param displayId The id of display.
77      * @return Return the specified displayResize controller.
78      */
79     std::shared_ptr<DisplayResizeController>& GetDisplayResizeController(uint32_t displayId);
80 
81     /**
82      * @brief Obtains elementInfo of the accessible root node.
83      * @param elementInfo The elementInfo of the accessible root node.
84      * @return Return true if obtains elementInfo successfully, else return false.
85      */
86     bool GetRootElementInfo(std::optional<AccessibilityElementInfo>& elementInfo);
87 
88     /**
89      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
90      * @param
91      * @return The information of windows.
92      */
93     std::vector<AccessibilityWindowInfo>& GetWindows();
94 
95     /**
96      * @brief Executes a specified action.
97      * @param action The action of OHOS::Accessibility::GlobalAction.
98      * @return Return true if executes action successfully, else return false.
99      */
100     bool ExecuteCommonAction(uint32_t action);
101 
102     /**
103      * @brief Dispatch the result of simulation gesture.
104      * @param sequence The sequence of gesture.
105      * @param result The result of gesture completion.
106      * @return
107      */
108     void DispatchOnSimulationGestureResult(uint32_t sequence, bool result);
109 
110     /**
111      * @brief Set channelId.
112      * @param channelId The id of channel.
113      * @return
114      */
115     void SetChannelId(uint32_t channelId);
116 
117 private:
118     /**
119      * @brief Check the type of common action.
120      * @param action The type of common action.
121      * @return Return true if the type of common action is right, else return false.
122      */
123     bool CheckCommonAction(uint32_t action);
124 
125     uint32_t channelId_ = 0xFFFFFFFF;
126     std::vector<AccessibilityWindowInfo> accessibilityWindow_ {};
127     std::map<uint32_t, std::shared_ptr<GestureResultListener>> gestureResultListenerInfos_;
128     std::map<uint32_t, std::shared_ptr<DisplayResizeController>> displayResizeControllers_;
129 };
130 } // namespace Accessibility
131 } // namespace OHOS
132 #endif // ACCESSIBILITY_EXTENSION_CONTEXT_H