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 TEST_WUKONG_COMPONENT_TREE_H 17 #define TEST_WUKONG_COMPONENT_TREE_H 18 19 #include <map> 20 21 #include "accessibility_element_info.h" 22 #include "wukong_define.h" 23 #include "wukong_tree.h" 24 25 namespace OHOS { 26 namespace WuKong { 27 class ComponentTree : public WuKongTree { 28 public: ComponentTree()29 ComponentTree() : WuKongTree(), expectedInputCount_(0) 30 { 31 type_.clear(); 32 inputTypeCountMap_.clear(); 33 } ~ComponentTree()34 virtual ~ComponentTree() 35 { 36 } 37 GetType()38 const std::string& GetType() 39 { 40 return type_; 41 } 42 IsVisible()43 bool IsVisible() 44 { 45 return isVisible_; 46 } 47 GetPosition()48 OHOS::Accessibility::Rect GetPosition() 49 { 50 return rect_; 51 } 52 GetInspectorKey()53 const std::string& GetInspectorKey() 54 { 55 return inspectorKey_; 56 } 57 SetInspectorKey(const std::string & inspectorKey)58 void SetInspectorKey(const std::string& inspectorKey) 59 { 60 inspectorKey_ = inspectorKey; 61 } 62 IsTopComponent()63 bool IsTopComponent() 64 { 65 return isTopComponent_; 66 } 67 SetTopComponent()68 void SetTopComponent() 69 { 70 isTopComponent_ = true; 71 } 72 73 private: 74 friend class TreeManager; 75 virtual bool SetNodeId() override; 76 virtual bool RecursUpdateInfo(const std::shared_ptr<ComponentTree>& source); AddTypeInputCount(uint32_t type)77 void AddTypeInputCount(uint32_t type) 78 { 79 auto it = inputTypeCountMap_.find(type); 80 if (it != inputTypeCountMap_.end()) { 81 it->second++; 82 } else { 83 inputTypeCountMap_[type] = 1; 84 } 85 } 86 OHOS::Accessibility::Rect rect_ {}; 87 bool isVisible_ = false; 88 std::string type_; 89 uint32_t expectedInputCount_; 90 std::map<uint32_t, uint32_t> inputTypeCountMap_; 91 std::string inspectorKey_; 92 bool isTopComponent_ = false; 93 }; 94 } // namespace WuKong 95 } // namespace OHOS 96 #endif // TEST_WUKONG_COMPONENT_TREE_H 97