mirror of
https://gitee.com/openharmony/accessibility
synced 2024-11-27 00:51:07 +00:00
!964 扩展findElement接口使用elementId查询
Merge pull request !964 from fanzexuan/master
This commit is contained in:
commit
3c832375d9
@ -226,6 +226,14 @@ public:
|
||||
virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child,
|
||||
AccessibilityElementInfo &parent) override;
|
||||
|
||||
/**
|
||||
* @brief Get node information based on element id in active window.
|
||||
* @param elementId The target element id.
|
||||
* @param targetElementInfo The element info of specified content.
|
||||
* @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure.
|
||||
*/
|
||||
virtual RetError GetByElementId(const int64_t elementId, AccessibilityElementInfo &targetElementInfo) override;
|
||||
|
||||
/**
|
||||
* @brief Executes a specified action.
|
||||
* @param elementInfo The source info to execute action.
|
||||
|
@ -754,6 +754,36 @@ RetError AccessibleAbilityClientImpl::GetParentElementInfo(const AccessibilityEl
|
||||
return SearchElementInfoFromAce(windowId, elementId, cacheMode_, parent);
|
||||
}
|
||||
|
||||
RetError AccessibleAbilityClientImpl::GetByElementId(const int64_t elementId,
|
||||
AccessibilityElementInfo &targetElementInfo)
|
||||
{
|
||||
HILOG_DEBUG();
|
||||
if (!isConnected_) {
|
||||
HILOG_ERROR("connection is broken");
|
||||
return RET_ERR_NO_CONNECTION;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!serviceProxy_) {
|
||||
HILOG_ERROR("failed to connect to aams");
|
||||
return RET_ERR_SAMGR;
|
||||
}
|
||||
|
||||
if (!channelClient_) {
|
||||
HILOG_ERROR("channel is invalid.");
|
||||
return RET_ERR_NO_CONNECTION;
|
||||
}
|
||||
|
||||
int32_t activeWindow = serviceProxy_->GetActiveWindow();
|
||||
HILOG_DEBUG("activeWindow[%{public}d]", activeWindow);
|
||||
if (GetCacheElementInfo(activeWindow, elementId, targetElementInfo)) {
|
||||
HILOG_DEBUG("get element info from cache");
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
return SearchElementInfoFromAce(activeWindow, elementId, cacheMode_, targetElementInfo);
|
||||
}
|
||||
|
||||
RetError AccessibleAbilityClientImpl::ExecuteAction(const AccessibilityElementInfo &elementInfo,
|
||||
const ActionType action, const std::map<std::string, std::string> &actionArguments)
|
||||
{
|
||||
|
@ -214,6 +214,15 @@ RetError AccessibleAbilityClientImpl::GetParentElementInfo(const AccessibilityEl
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
RetError AccessibleAbilityClientImpl::GetByElementId(const int64_t elementId,
|
||||
AccessibilityElementInfo &targetElementInfo)
|
||||
{
|
||||
HILOG_DEBUG();
|
||||
(void)elementId;
|
||||
(void)targetElementInfo;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
RetError AccessibleAbilityClientImpl::ExecuteAction(const AccessibilityElementInfo &elementInfo,
|
||||
const ActionType action, const std::map<std::string, std::string> &actionArguments)
|
||||
{
|
||||
|
@ -560,6 +560,35 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetParentElementInfo_002, TestSize.Lev
|
||||
GTEST_LOG_(INFO) << "GetParentElementInfo_002 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetByElementId_001
|
||||
* @tc.name: GetByElementId
|
||||
* @tc.desc: Test function GetByElementId
|
||||
*/
|
||||
HWTEST_F(AccessibleAbilityClientImplTest, GetByElementId_001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "GetByElementId_001 start";
|
||||
Connect();
|
||||
int64_t elementId = 10;
|
||||
AccessibilityElementInfo targetElementInfo {};
|
||||
EXPECT_EQ(instance_->GetByElementId(elementId, targetElementInfo), RET_ERR_TIME_OUT);
|
||||
GTEST_LOG_(INFO) << "GetByElementId_001 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: GetByElementId_002
|
||||
* @tc.name: GetByElementId
|
||||
* @tc.desc: Test function GetByElementId
|
||||
*/
|
||||
HWTEST_F(AccessibleAbilityClientImplTest, GetByElementId_002, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "GetByElementId_002 start";
|
||||
int64_t elementId = 10;
|
||||
AccessibilityElementInfo targetElementInfo {};
|
||||
EXPECT_EQ(instance_->GetByElementId(elementId, targetElementInfo), RET_ERR_NO_CONNECTION);
|
||||
GTEST_LOG_(INFO) << "GetByElementId_002 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: ExecuteAction_001
|
||||
* @tc.name: ExecuteAction
|
||||
|
@ -181,6 +181,14 @@ public:
|
||||
*/
|
||||
virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get node information based on element id in active window.
|
||||
* @param elementId The target element id.
|
||||
* @param targetElementInfo The element info of specified content.
|
||||
* @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure.
|
||||
*/
|
||||
virtual RetError GetByElementId(const int64_t elementId, AccessibilityElementInfo &targetElementInfo) = 0;
|
||||
|
||||
/**
|
||||
* @brief Executes a specified action.
|
||||
* @param elementInfo The source info to execute action.
|
||||
|
@ -43,6 +43,7 @@ bool ParseBool(napi_env env, bool& param, napi_value args);
|
||||
bool ParseString(napi_env env, std::string& param, napi_value args);
|
||||
bool ParseNumber(napi_env env, napi_value args);
|
||||
bool ParseInt32(napi_env env, int32_t& param, napi_value args);
|
||||
bool ParseInt64(napi_env env, int64_t& param, napi_value args);
|
||||
bool ParseDouble(napi_env env, double& param, napi_value args);
|
||||
bool CheckJsFunction(napi_env env, napi_value args);
|
||||
NAccessibilityErrMsg QueryRetMsg(OHOS::Accessibility::RetError errorCode);
|
||||
|
@ -40,6 +40,7 @@ enum FindElementCondition {
|
||||
FIND_ELEMENT_CONDITION_CONTENT,
|
||||
FIND_ELEMENT_CONDITION_FOCUS_TYPE,
|
||||
FIND_ELEMENT_CONDITION_FOCUS_DIRECTION,
|
||||
FIND_ELEMENT_CONDITION_ELEMENT_ID,
|
||||
FIND_ELEMENT_CONDITION_INVALID
|
||||
};
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <cinttypes>
|
||||
#include "accessible_ability_client.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "accessibility_utils.h"
|
||||
@ -1359,7 +1360,8 @@ void NAccessibilityElement::FindElementConstructCallbackInfo(napi_env env, size_
|
||||
HILOG_DEBUG("conditionType = %{public}s", conditionType.c_str());
|
||||
if (std::strcmp(conditionType.c_str(), "content") != 0 &&
|
||||
std::strcmp(conditionType.c_str(), "focusType") != 0 &&
|
||||
std::strcmp(conditionType.c_str(), "focusDirection") != 0) {
|
||||
std::strcmp(conditionType.c_str(), "focusDirection") != 0 &&
|
||||
std::strcmp(conditionType.c_str(), "elementId") != 0) {
|
||||
HILOG_ERROR("argv[PARAM0] is wrong[%{public}s", conditionType.c_str());
|
||||
errCode = NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM;
|
||||
} else {
|
||||
@ -1371,9 +1373,14 @@ void NAccessibilityElement::FindElementConstructCallbackInfo(napi_env env, size_
|
||||
|
||||
// Parse queryData name
|
||||
std::string queryData = "";
|
||||
int64_t elementId;
|
||||
if (ParseString(env, queryData, argv[PARAM1])) {
|
||||
HILOG_DEBUG("queryData = %{public}s", queryData.c_str());
|
||||
callbackInfo->condition_ = queryData;
|
||||
} else if (ParseInt64(env, elementId, argv[PARAM1])) {
|
||||
queryData = std::to_string(elementId);
|
||||
HILOG_DEBUG("queryData = %{public}s", queryData.c_str());
|
||||
callbackInfo->condition_ = queryData;
|
||||
} else {
|
||||
errCode = NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM;
|
||||
}
|
||||
@ -1426,6 +1433,14 @@ void NAccessibilityElement::FindElementExecute(napi_env env, void* data)
|
||||
callbackInfo->nodeInfo_);
|
||||
}
|
||||
break;
|
||||
case FindElementCondition::FIND_ELEMENT_CONDITION_ELEMENT_ID:
|
||||
{
|
||||
int64_t elementId = std::stoll(callbackInfo->condition_);
|
||||
HILOG_DEBUG("elementId is %{public}" PRId64 "", elementId);
|
||||
callbackInfo->ret_ = AccessibleAbilityClient::GetInstance()->GetByElementId(
|
||||
elementId, callbackInfo->nodeInfo_);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1500,6 +1515,14 @@ void NAccessibilityElement::GetElement(NAccessibilityElementData *callbackInfo,
|
||||
ConvertElementInfoToJS(env, value, callbackInfo->nodeInfo_);
|
||||
}
|
||||
break;
|
||||
case FindElementCondition::FIND_ELEMENT_CONDITION_ELEMENT_ID:
|
||||
{
|
||||
napi_value constructor = nullptr;
|
||||
napi_get_reference_value(env, NAccessibilityElement::consRef_, &constructor);
|
||||
napi_new_instance(env, constructor, 0, nullptr, &value);
|
||||
ConvertElementInfoToJS(env, value, callbackInfo->nodeInfo_);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1564,7 +1587,8 @@ FindElementCondition NAccessibilityElement::ConvertStringToCondition(const std::
|
||||
static const std::map<std::string, FindElementCondition> findElementConditionTable = {
|
||||
{"content", FindElementCondition::FIND_ELEMENT_CONDITION_CONTENT},
|
||||
{"focusType", FindElementCondition::FIND_ELEMENT_CONDITION_FOCUS_TYPE},
|
||||
{"focusDirection", FindElementCondition::FIND_ELEMENT_CONDITION_FOCUS_DIRECTION}
|
||||
{"focusDirection", FindElementCondition::FIND_ELEMENT_CONDITION_FOCUS_DIRECTION},
|
||||
{"elementId", FindElementCondition::FIND_ELEMENT_CONDITION_ELEMENT_ID}
|
||||
};
|
||||
|
||||
if (findElementConditionTable.find(str) == findElementConditionTable.end()) {
|
||||
|
@ -137,6 +137,16 @@ bool ParseInt32(napi_env env, int32_t& param, napi_value args)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseInt64(napi_env env, int64_t& param, napi_value args)
|
||||
{
|
||||
if (!ParseNumber(env, args)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
napi_get_value_int64(env, args, ¶m);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseDouble(napi_env env, double& param, napi_value args)
|
||||
{
|
||||
if (!ParseNumber(env, args)) {
|
||||
|
Loading…
Reference in New Issue
Block a user