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 #ifndef TEST_WUKONG_COMPONENT_MANAGER_H 16 #define TEST_WUKONG_COMPONENT_MANAGER_H 17 18 #include "accessibility_element_info.h" 19 #include "component_tree.h" 20 #include "wukong_define.h" 21 22 namespace OHOS { 23 namespace WuKong { 24 enum ComponentStatus { 25 COMPONENT_STATUS_DISCONNECT, 26 COMPONENT_STATUS_CONNECTED, 27 COMPONENT_STATUS_CONNECTING 28 }; 29 30 class ComponentManagerListener { 31 public: 32 virtual void OnStatusUpdated(ComponentStatus status) = 0; 33 virtual void OnScreenUpdated() = 0; 34 virtual void OnPermissionScreenShown() = 0; 35 }; 36 class ComponentManager : public DelayedSingleton<ComponentManager> { 37 public: 38 bool Connect(); 39 40 void Disconnect(); 41 42 uint32_t AddRegisterListener(std::shared_ptr<ComponentManagerListener> listener); 43 44 void DeleteRegisterListener(const uint32_t handle); 45 46 ErrCode GetReportInfo(std::string& info); 47 48 ErrCode PermoissionInput(); 49 50 std::vector<std::shared_ptr<ComponentManagerListener>> GetListenerList(); 51 52 /** 53 * @brief input multimode event for the current page. 54 * @param elementInfo current component 55 * @param actionType the action type of current component 56 * @return Return ERR_OK on success, others on failure. 57 */ 58 ErrCode ComponentEventInput(OHOS::Accessibility::AccessibilityElementInfo& elementInfo, const int actionType); 59 60 /** 61 * @brief input back event for the current page. 62 * @return Return ERR_OK on success, others on failure. 63 */ 64 ErrCode BackToPrePage(); 65 66 DECLARE_DELAYED_SINGLETON(ComponentManager); 67 68 private: 69 bool connected_ = false; 70 71 int32_t startX_ = -1; 72 int32_t endX_ = -1; 73 int32_t startY_ = -1; 74 int32_t endY_ = -1; 75 76 std::vector<std::shared_ptr<ComponentManagerListener>> listenerList_; 77 std::map<int, std::function<ErrCode(Accessibility::AccessibilityElementInfo&)>> componentMap_; 78 79 /** 80 * @brief get the positin of current component . 81 * @param elementInfo current component. 82 */ 83 void GetComponentPosition(Accessibility::AccessibilityElementInfo& elementInfo); 84 85 /** 86 * @brief input up swap event for the current component. 87 * @param elementInfo current component. 88 * @return Return ERR_OK on success, others on failure. 89 */ 90 ErrCode ComponentUpSwapInput(Accessibility::AccessibilityElementInfo& elementInfo); 91 92 /** 93 * @brief input dowan swap event for the target component. 94 * @param elementInfo element, also call component. 95 * @return Return ERR_OK on success, others on failure. 96 */ 97 ErrCode ComponentDownSwapInput(Accessibility::AccessibilityElementInfo& elementInfo); 98 99 /** 100 * @brief input keyboard event for the target component. 101 * @param elementInfo element, also call component. 102 * @return Return ERR_OK on success, others on failure. 103 */ 104 ErrCode ComponentMultikeyInput(Accessibility::AccessibilityElementInfo& elementInfo); 105 106 /** 107 * @brief input left swap event for the target component. 108 * @param elementInfo element, also call component. 109 * @return Return ERR_OK on success, others on failure. 110 */ 111 ErrCode ComponentLeftSwapInput(Accessibility::AccessibilityElementInfo& elementInfo); 112 113 /** 114 * @brief input touch event for the target component. 115 * @param elementInfo element, also call component. 116 * @return Return ERR_OK on success, others on failure. 117 */ 118 ErrCode ComponentTouchInput(Accessibility::AccessibilityElementInfo& elementInfo); 119 120 /** 121 * @brief Create a Event Input Map. 122 * @return Return ERR_OK on success, others on failure. 123 */ 124 ErrCode CreateEventInputMap(); 125 }; 126 } // namespace WuKong 127 } // namespace OHOS 128 #endif // TEST_WUKONG_COMPONENT_MANAGER_H 129