已开启
ActionNames适配virtual node #2725
qianchuang创建于 6 天前
ActionNames适配virtual node #2725
已开启
共 1 个文件变更+70-12
Minterfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_element.cpp+70-12
| @@ -1548,7 +1548,11 @@ void NAccessibilityElement::GetElementInfoSupportedActionNames( | |||
| 1548 | if (!CheckElementInfoParameter(callbackInfo, value)) { | 1548 | if (!CheckElementInfoParameter(callbackInfo, value)) { |
| 1549 | return; | 1549 | return; |
| 1550 | } | 1550 | } |
| 1551 | - | 1551 | + if (callbackInfo->accessibilityElement_.elementInfo_->GetSourceType() == |
| 1552 | + AccessibilitySourceType::ADDED_FROM_ACCESSIBILITY_VIRTUAL_NODE) { | ||
| 1553 | + GetElementInfoVirtualSupportedActionNames(callbackInfo, value); | ||
| 1554 | + return; | ||
| 1555 | + } | ||
| 1552 | std::vector<std::string> actionNames {}; | 1556 | std::vector<std::string> actionNames {}; |
| 1553 | std::vector<AccessibleAction> operations = callbackInfo->accessibilityElement_.elementInfo_->GetActionList(); | 1557 | std::vector<AccessibleAction> operations = callbackInfo->accessibilityElement_.elementInfo_->GetActionList(); |
| 1554 | HILOG_DEBUG("action list size is %{public}zu", operations.size()); | 1558 | HILOG_DEBUG("action list size is %{public}zu", operations.size()); |
| @@ -1561,6 +1565,56 @@ void NAccessibilityElement::GetElementInfoSupportedActionNames( | |||
| 1561 | ConvertStringVecToJS(callbackInfo->env_, value, actionNames); | 1565 | ConvertStringVecToJS(callbackInfo->env_, value, actionNames); |
| 1562 | } | 1566 | } |
| 1563 | 1567 | ||
| 1568 | +void NAccessibilityElement::GetElementInfoVirtualSupportedActionNames( | ||
| 1569 | + NAccessibilityElementData* callbackInfo, napi_value& value) | ||
| 1570 | +{ | ||
| 1571 | + if (!CheckElementInfoParameter(callbackInfo, value)) { | ||
| 1572 | + return; | ||
| 1573 | + } | ||
| 1574 | + uint64_t virtualSupportAction = callbackInfo->accessibilityElement_.elementInfo_->GetVirtualSupportAction(); | ||
| 1575 | + static const std::vector<ActionType> actionTypes = { | ||
| 1576 | + ActionType::ACCESSIBILITY_ACTION_FOCUS, | ||
| 1577 | + ActionType::ACCESSIBILITY_ACTION_CLEAR_FOCUS, | ||
| 1578 | + ActionType::ACCESSIBILITY_ACTION_SELECT, | ||
| 1579 | + ActionType::ACCESSIBILITY_ACTION_CLEAR_SELECTION, | ||
| 1580 | + ActionType::ACCESSIBILITY_ACTION_CLICK, | ||
| 1581 | + ActionType::ACCESSIBILITY_ACTION_LONG_CLICK, | ||
| 1582 | + ActionType::ACCESSIBILITY_ACTION_ACCESSIBILITY_FOCUS, | ||
| 1583 | + ActionType::ACCESSIBILITY_ACTION_CLEAR_ACCESSIBILITY_FOCUS, | ||
| 1584 | + ActionType::ACCESSIBILITY_ACTION_SCROLL_FORWARD, | ||
| 1585 | + ActionType::ACCESSIBILITY_ACTION_SCROLL_BACKWARD, | ||
| 1586 | + ActionType::ACCESSIBILITY_ACTION_COPY, | ||
| 1587 | + ActionType::ACCESSIBILITY_ACTION_PASTE, | ||
| 1588 | + ActionType::ACCESSIBILITY_ACTION_CUT, | ||
| 1589 | + ActionType::ACCESSIBILITY_ACTION_SET_SELECTION, | ||
| 1590 | + ActionType::ACCESSIBILITY_ACTION_SET_CURSOR_POSITION, | ||
| 1591 | + ActionType::ACCESSIBILITY_ACTION_COMMON, | ||
| 1592 | + ActionType::ACCESSIBILITY_ACTION_SET_TEXT, | ||
| 1593 | + ActionType::ACCESSIBILITY_ACTION_DELETED, | ||
| 1594 | + ActionType::ACCESSIBILITY_ACTION_HOME, | ||
| 1595 | + ActionType::ACCESSIBILITY_ACTION_BACK, | ||
| 1596 | + ActionType::ACCESSIBILITY_ACTION_RECENTTASK, | ||
| 1597 | + ActionType::ACCESSIBILITY_ACTION_NOTIFICATIONCENTER, | ||
| 1598 | + ActionType::ACCESSIBILITY_ACTION_CONTROLCENTER, | ||
| 1599 | + ActionType::ACCESSIBILITY_ACTION_SPAN_CLICK, | ||
| 1600 | + ActionType::ACCESSIBILITY_ACTION_CUSTOM, | ||
| 1601 | + ActionType::ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, | ||
| 1602 | + ActionType::ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, | ||
| 1603 | + ActionType::ACCESSIBILITY_ACTION_INJECT_ACTION | ||
| 1604 | + }; | ||
| 1605 | + std::vector<std::string> actionNames; | ||
| 1606 | + for (size_t i = 0; i < actionTypes.size(); i++) { | ||
| 1607 | + if ((virtualSupportAction & (1UL << i)) != 0) { | ||
| 1608 | + std::string actionName = ConvertOperationTypeToString(actionTypes[i]); | ||
| 1609 | + if (!actionName.empty()) { | ||
| 1610 | + actionNames.push_back(actionName); | ||
| 1611 | + } | ||
| 1612 | + } | ||
| 1613 | + } | ||
| 1614 | + napi_create_array(callbackInfo->env_, &value); | ||
| 1615 | + ConvertStringVecToJS(callbackInfo->env_, value, actionNames); | ||
| 1616 | +} | ||
| 1617 | + | ||
| 1564 | void NAccessibilityElement::GetElementInfoChildrenTreeId(NAccessibilityElementData *callbackInfo, napi_value &value) | 1618 | void NAccessibilityElement::GetElementInfoChildrenTreeId(NAccessibilityElementData *callbackInfo, napi_value &value) |
| 1565 | { | 1619 | { |
| 1566 | if (!CheckElementInfoParameter(callbackInfo, value)) { | 1620 | if (!CheckElementInfoParameter(callbackInfo, value)) { |
| @@ -2161,17 +2215,21 @@ void NAccessibilityElement::ActionNamesComplete(napi_env env, napi_status status | |||
| 2161 | } | 2215 | } |
| 2162 | 2216 | ||
| 2163 | if (callbackInfo->accessibilityElement_.elementInfo_) { | 2217 | if (callbackInfo->accessibilityElement_.elementInfo_) { |
| 2164 | - std::vector<std::string> actionNames {}; | 2218 | + if (callbackInfo->accessibilityElement_.elementInfo_->GetSourceType() == |
| 2165 | - std::vector<AccessibleAction> operations = | 2219 | + AccessibilitySourceType::ADDED_FROM_ACCESSIBILITY_VIRTUAL_NODE) { |
| 2166 | - callbackInfo->accessibilityElement_.elementInfo_->GetActionList(); | 2220 | + GetElementInfoVirtualSupportedActionNames(callbackInfo, result[PARAM1]); |
| 2167 | - HILOG_DEBUG("action list size is %{public}zu", operations.size()); | 2221 | + } else { |
| 2168 | - actionNames.resize(operations.size()); | 2222 | + std::vector<std::string> actionNames {}; |
| 2169 | - std::transform(operations.begin(), operations.end(), actionNames.begin(), | 2223 | + std::vector<AccessibleAction> operations = |
| 2170 | - [](const AccessibleAction operation) { | 2224 | + callbackInfo->accessibilityElement_.elementInfo_->GetActionList(); |
| 2171 | - return ConvertOperationTypeToString(operation.GetActionType()); | 2225 | + actionNames.resize(operations.size()); |
| 2172 | - }); | 2226 | + std::transform(operations.begin(), operations.end(), actionNames.begin(), |
| 2173 | - napi_create_array(env, &result[PARAM1]); | 2227 | + [](const AccessibleAction operation) { |
| 2174 | - ConvertStringVecToJS(env, result[PARAM1], actionNames); | 2228 | + return ConvertOperationTypeToString(operation.GetActionType()); |
| 2229 | + }); | ||
| 2230 | + napi_create_array(env, &result[PARAM1]); | ||
| 2231 | + ConvertStringVecToJS(env, result[PARAM1], actionNames); | ||
| 2232 | + } | ||
| 2175 | callbackInfo->ret_ = RET_OK; | 2233 | callbackInfo->ret_ = RET_OK; |
| 2176 | } else { | 2234 | } else { |
| 2177 | HILOG_ERROR("no elementInfo_"); | 2235 | HILOG_ERROR("no elementInfo_"); |