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_WINDOW_H 17 #define ACCESSIBILITY_WINDOW_H 18 19 #include <cstdint> 20 #include <vector> 21 #include "accessibility_element_info.h" 22 #include "accessibility_event_info.h" 23 #include "parcel.h" 24 25 namespace OHOS { 26 namespace Accessibility { 27 enum WindowType : int { 28 TYPE_WINDOW_INVALID = 0, 29 TYPE_ACCESSIBILITY_OVERLAY = 0x00000001, 30 TYPE_APPLICATION = 0x00000002, 31 TYPE_INPUT_METHOD = 0x00000004, 32 TYPE_SPLIT_SCREEN_DIVIDER = 0x00000008, 33 TYPE_SYSTEM = 0x00000010, 34 }; 35 static const int INVALID_WINDOW_ID = -1; 36 static const int ANY_WINDOW_ID = -2; 37 static const int ACTIVE_WINDOW_ID = 0x7FFFFFFF; 38 39 class AccessibilityWindowInfo : public Parcelable { 40 public: 41 /** 42 * @brief Construct 43 * @param 44 * @return 45 * @since 3 46 * @sysCap Accessibility 47 */ 48 AccessibilityWindowInfo(); 49 50 /** 51 * @brief Get the title of window 52 * @param - 53 * @return The title of window 54 * @since 3 55 * @sysCap Accessibility 56 */ 57 std::string GetWindowTitle() const; 58 59 /** 60 * @brief Set the title of window 61 * @param title The title of window 62 * @return 63 * @since 3 64 * @sysCap Accessibility 65 */ 66 void SetWindowTitle(std::string &title); 67 68 /** 69 * @brief Get the window type. 70 * @param - 71 * @return The window type. Refer to [WindowType]. 72 * @since 3 73 * @sysCap Accessibility 74 */ 75 WindowType GetWindowType() const; 76 77 /** 78 * @brief Set the window type. 79 * @param type The window type. Refer to [WindowType]. 80 * @return - 81 * @since 3 82 * @sysCap Accessibility 83 */ 84 void SetWindowType(const WindowType type); 85 86 /** 87 * @brief Get The window layer 88 * @param - 89 * @return The layer of window 90 * @since 3 91 * @sysCap Accessibility 92 */ 93 int GetWindowLayer() const; 94 95 /** 96 * @brief Set The window layer 97 * @param layer The window layer 98 * @return - 99 * @since 3 100 * @sysCap Accessibility 101 */ 102 void SetWindowLayer(const int layer); 103 104 /** 105 * @brief Get the root node information of the window. 106 * @param - 107 * @return The root node information. 108 * @since 3 109 * @sysCap Accessibility 110 */ 111 bool GetRootAccessibilityInfo(AccessibilityElementInfo &elementInfo); 112 113 /** 114 * @brief Set an anchor accessibility node that anchors this window to another window. 115 * @param anchorId The accessibility id of component. 116 * @return 117 * @since 3 118 * @sysCap Accessibility 119 */ 120 void SetAnchorId(const int anchorId); 121 122 /** 123 * @brief Obtains an anchor accessibility node that anchors this window to another window. 124 * @param - 125 * @return The node information of the anchored component. 126 * @since 3 127 * @sysCap Accessibility 128 */ 129 bool GetAnchor(AccessibilityElementInfo &elementInfo); 130 131 /** 132 * @brief Get the parent window 133 * @param - 134 * @return - 135 * @since 3 136 * @sysCap Accessibility 137 */ 138 AccessibilityWindowInfo GetParent(); 139 140 /** 141 * @brief Set the parent window 142 * @param parentId The window id of the parent. 143 * @return - 144 * @since 3 145 * @sysCap Accessibility 146 */ 147 void SetParentId(const int parentId); 148 149 /** 150 * @brief Get the parent window 151 * @param - 152 * @return The window id of the parent. 153 * @since 3 154 * @sysCap Accessibility 155 */ 156 int GetParentId() const; 157 158 /** 159 * @brief Get the anchor window 160 * @param - 161 * @return The anchor id of the window. 162 * @since 3 163 * @sysCap Accessibility 164 */ 165 int GetAnchorId() const; 166 167 /** 168 * @brief Get the parent window 169 * @param - 170 * @return The window id of the parent. 171 * @since 3 172 * @sysCap Accessibility 173 */ 174 std::vector<int> GetChildIds() const; 175 176 /** 177 * @brief Get the widnow id of current window. 178 * @param - 179 * @return The widnow id of current window. 180 * @since 3 181 * @sysCap Accessibility 182 */ 183 int GetWindowId() const; 184 185 /** 186 * @brief Set the widnow id of current window. 187 * @param id The widnow id of current window. 188 * @return 189 * @since 3 190 * @sysCap Accessibility 191 */ 192 void SetWindowId(const int id); 193 194 /** 195 * @brief AAMS called to set the id of the IAccessibleAbilityChannel. 196 * @param channelId The id of the IAccessibleAbilityChannel. 197 * @return 198 * @since 3 199 * @sysCap Accessibility 200 */ 201 void SetChannelId(const int channelId); 202 203 /** 204 * @brief Get the id of the IAccessibleAbilityChannel. 205 * @param 206 * @return The id of the IAccessibleAbilityChannel. 207 * @since 3 208 * @sysCap Accessibility 209 */ 210 int GetChannelId() const; 211 212 /** 213 * @brief Get the screen pixel coordinates 214 * @param - 215 * @return The screen pixel coordinates 216 * @since 3 217 * @sysCap Accessibility 218 */ 219 Rect GetRectInScreen() const; 220 221 /** 222 * @brief Set the screen pixel coordinates 223 * @param bounds The screen pixel coordinates 224 * @return - 225 * @since 3 226 * @sysCap Accessibility 227 */ 228 void SetRectInScreen(const Rect &bounds); 229 230 /** 231 * @brief Check whether the window is active or not. 232 * @param - 233 * @return true: the window is active, otherwise is not. 234 * @since 3 235 * @sysCap Accessibility 236 */ 237 bool IsActive() const; 238 239 /** 240 * @brief Set whether the window is active or not. 241 * @param active true: the window is active, otherwise is not. 242 * @return 243 * @since 3 244 * @sysCap Accessibility 245 */ 246 void SetActive(bool active); 247 248 /** 249 * @brief Checks whether this window has gained focus. 250 * @param 251 * @return true: the window has gained focus, otherwise is not. 252 * @since 3 253 * @sysCap Accessibility 254 */ 255 bool IsFocused() const; 256 257 /** 258 * @brief Set whether this window has gained focus. 259 * @param focused true: the window has gained focus, otherwise is not. 260 * @return - 261 * @since 3 262 * @sysCap Accessibility 263 */ 264 void SetFocused(bool focused); 265 266 /** 267 * @brief Checks whether this window has gained accessibility focus. 268 * @param - 269 * @return true: this window has gained accessibility focus, otherwise is not. 270 * @since 3 271 * @sysCap Accessibility 272 */ 273 bool IsAccessibilityFocused() const; 274 275 /** 276 * @brief Set whether this window has gained accessibility focus. 277 * @param accessibilityfocused true: this window has gained accessibility focus, otherwise is not. 278 * @return - 279 * @since 3 280 * @sysCap Accessibility 281 */ 282 void SetAccessibilityFocused(const bool accessibilityfocused); 283 284 /** 285 * @brief Obtains the quantity of child windows. 286 * @param - 287 * @return The quantity of child windows. 288 * @since 3 289 * @sysCap Accessibility 290 */ 291 int GetChildNum() const; 292 293 /** 294 * @brief Obtains information about the accessibility child window at a specified index. 295 * @param index The index of the child 296 * @return The child window specified by index. 297 * @since 3 298 * @sysCap Accessibility 299 */ 300 AccessibilityWindowInfo GetChild(const int index); 301 302 /** 303 * @brief Add the child window 304 * @param childId the window id of the child 305 * @return - 306 * @since 3 307 * @sysCap Accessibility 308 */ 309 void AddChild(const int childId); 310 311 /** 312 * @brief Used for IPC communication. 313 * @param parcel Serializable data. 314 * @return true: Read parcel data successfully; otherwise is not. 315 * @since 3 316 * @sysCap Accessibility 317 */ 318 bool ReadFromParcel(Parcel &parcel); 319 320 /** 321 * @brief Used for IPC communication. 322 * @param parcel 323 * @return true: Write parcel data successfully; otherwise is not. 324 * @since 3 325 * @sysCap Accessibility 326 */ 327 virtual bool Marshalling(Parcel &parcel) const override; 328 329 /** 330 * @brief Used for IPC communication. 331 * @param parcel 332 * @return The data of AccessibilityWindowInfo 333 * @since 3 334 * @sysCap Accessibility 335 */ 336 static AccessibilityWindowInfo *Unmarshalling(Parcel &parcel); 337 338 private: 339 WindowType windowType_ = TYPE_WINDOW_INVALID; 340 int windowLayer_ = INVALID_WINDOW_ID; 341 int windowId_ = INVALID_WINDOW_ID; 342 int parentId_ = INVALID_WINDOW_ID; 343 std::string windowTitle_ = ""; 344 std::vector<int> childIds_; 345 int anchorId_ = -1; 346 int childNum_ = 0; 347 int channelId_ = INVALID_WINDOW_ID; 348 bool active_ = false; 349 bool focused_ = false; 350 bool accessibilityFocused_ = false; 351 Rect boundsInScreen_ {}; 352 }; 353 } // namespace Accessibility 354 } // namespace OHOS 355 #endif 356