1 /* 2 * Copyright (c) 2024 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 #include "core/accessibility/native_interface_accessibility_impl.h" 17 18 #include <iterator> 19 20 #include "base/log/log.h" 21 ArkUI_AccessibilityElementInfo()22ArkUI_AccessibilityElementInfo::ArkUI_AccessibilityElementInfo() 23 { 24 screenRect.leftTopX = 0; 25 screenRect.leftTopY = 0; 26 screenRect.rightBottomX = 0; 27 screenRect.rightBottomY = 0; 28 29 rangeInfo.current = 0; 30 rangeInfo.max = 0; 31 rangeInfo.min = 0; 32 33 grid.columnCount = 0; 34 grid.rowCount = 0; 35 grid.selectionMode = 0; 36 37 gridItem.columnIndex = 0; 38 gridItem.rowIndex = 0; 39 gridItem.columnSpan = 0; 40 gridItem.rowSpan = 0; 41 gridItem.heading = false; 42 gridItem.selected = false; 43 } 44 SetRect(const ArkUI_AccessibleRect & rect)45void ArkUI_AccessibilityElementInfo::SetRect(const ArkUI_AccessibleRect& rect) 46 { 47 this->screenRect = rect; 48 } 49 SetRangeInfo(const ArkUI_AccessibleRangeInfo & rangeInfo)50void ArkUI_AccessibilityElementInfo::SetRangeInfo(const ArkUI_AccessibleRangeInfo& rangeInfo) 51 { 52 this->rangeInfo = rangeInfo; 53 } 54 SetGridInfo(const ArkUI_AccessibleGridInfo & gridInfo)55void ArkUI_AccessibilityElementInfo::SetGridInfo(const ArkUI_AccessibleGridInfo& gridInfo) 56 { 57 this->grid = gridInfo; 58 } 59 SetGridItemInfo(const ArkUI_AccessibleGridItemInfo & gridItemInfo)60void ArkUI_AccessibilityElementInfo::SetGridItemInfo(const ArkUI_AccessibleGridItemInfo& gridItemInfo) 61 { 62 this->gridItem = gridItemInfo; 63 } 64 ClearChildNodeIds()65void ArkUI_AccessibilityElementInfo::ClearChildNodeIds() 66 { 67 childNodeIds.clear(); 68 } 69 AddChildNodeId(int64_t childNodeId)70void ArkUI_AccessibilityElementInfo::AddChildNodeId(int64_t childNodeId) 71 { 72 childNodeIds.push_back(childNodeId); 73 } 74 ClearOperationActions()75void ArkUI_AccessibilityElementInfo::ClearOperationActions() 76 { 77 operationActions.clear(); 78 } 79 AddOperationAction(const ArkUI_AccessibleAction & action)80void ArkUI_AccessibilityElementInfo::AddOperationAction(const ArkUI_AccessibleAction& action) 81 { 82 operationActions.push_back(action); 83 } 84 AddAndGetElementInfo()85ArkUI_AccessibilityElementInfo* ArkUI_AccessibilityElementInfoList::AddAndGetElementInfo() 86 { 87 std::lock_guard<std::mutex> lock(mutex_); 88 elementInfos_.push_back(ArkUI_AccessibilityElementInfo()); 89 return &elementInfos_.back(); 90 } 91 CopyAccessibilityElementInfo(std::vector<ArkUI_AccessibilityElementInfo> & infos)92bool ArkUI_AccessibilityElementInfoList::CopyAccessibilityElementInfo( 93 std::vector<ArkUI_AccessibilityElementInfo>& infos) 94 { 95 std::lock_guard<std::mutex> lock(mutex_); 96 if (elementInfos_.empty()) { 97 return false; 98 } 99 100 std::copy(elementInfos_.begin(), elementInfos_.end(), std::back_inserter(infos)); 101 return true; 102 } 103 FindValueByKey(const char * key)104const char* ArkUI_AccessibilityActionArguments::FindValueByKey(const char* key) 105 { 106 auto iter = actionArguments_.find(key); 107 if (iter == actionArguments_.end()) { 108 return nullptr; 109 } 110 return iter->second.c_str(); 111 } 112