mirror of
https://gitee.com/openharmony/accessibility
synced 2024-11-23 06:50:30 +00:00
commit
51c7f12f00
@ -113,6 +113,7 @@ void ConvertStringArrayJSToNAPI(napi_env env, napi_value object,
|
||||
napi_value propertyNameValue, bool &hasProperty, std::vector<std::string> &stringArray);
|
||||
void ConvertStringArrayJSToNAPICommon(napi_env env, napi_value object, std::vector<std::string> &stringArray);
|
||||
void ConvertSpanToJS(napi_env env, napi_value result, const Accessibility::SpanInfo& span);
|
||||
bool IsColorWithMagic(const std::string& colorStr);
|
||||
|
||||
OHOS::Accessibility::ActionType ConvertStringToAccessibleOperationType(const std::string &type);
|
||||
OHOS::Accessibility::AccessibilityAbilityTypes ConvertStringToAccessibilityAbilityTypes(const std::string &type);
|
||||
|
@ -214,6 +214,15 @@ napi_value NAccessibilityElement::AttributeNames(napi_env env, napi_callback_inf
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &argv, &thisVar, &data));
|
||||
HILOG_DEBUG("argc = %{public}d", (int)argc);
|
||||
|
||||
AccessibilityElement* accessibilityElement = nullptr;
|
||||
napi_status status = napi_unwrap(env, thisVar, (void**)&accessibilityElement);
|
||||
if (!accessibilityElement || status != napi_ok) {
|
||||
HILOG_ERROR("accessibilityElement is null or status[%{public}d] is wrong", status);
|
||||
napi_value err = CreateBusinessError(env, RetError::RET_ERR_NULLPTR);
|
||||
napi_throw(env, err);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NAccessibilityElementData *callbackInfo = new(std::nothrow) NAccessibilityElementData();
|
||||
if (callbackInfo == nullptr) {
|
||||
HILOG_ERROR("Failed to create callbackInfo.");
|
||||
@ -235,12 +244,6 @@ napi_value NAccessibilityElement::AttributeNames(napi_env env, napi_callback_inf
|
||||
napi_create_promise(env, &callbackInfo->deferred_, &promise);
|
||||
}
|
||||
|
||||
AccessibilityElement* accessibilityElement = nullptr;
|
||||
napi_status status = napi_unwrap(env, thisVar, (void**)&accessibilityElement);
|
||||
if (!accessibilityElement || status != napi_ok) {
|
||||
HILOG_ERROR("accessibilityElement is null or status[%{public}d] is wrong", status);
|
||||
return ErrorOperation(callbackInfo);
|
||||
}
|
||||
callbackInfo->accessibilityElement_ = *accessibilityElement;
|
||||
|
||||
napi_value resource = nullptr;
|
||||
@ -1540,12 +1543,18 @@ napi_value NAccessibilityElement::ActionNames(napi_env env, napi_callback_info i
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &argv, &thisVar, &data));
|
||||
HILOG_DEBUG("argc = %{public}zu", argc);
|
||||
|
||||
AccessibilityElement* accessibilityElement = UnrapAccessibilityElement(env, thisVar);
|
||||
if (!accessibilityElement) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NAccessibilityElementData *callbackInfo = new(std::nothrow) NAccessibilityElementData();
|
||||
if (callbackInfo == nullptr) {
|
||||
HILOG_ERROR("Failed to create callbackInfo.");
|
||||
return nullptr;
|
||||
}
|
||||
callbackInfo->env_ = env;
|
||||
callbackInfo->accessibilityElement_ = *accessibilityElement;
|
||||
|
||||
napi_value promise = nullptr;
|
||||
if (argc > ARGS_SIZE_ONE - 1) {
|
||||
@ -1561,18 +1570,6 @@ napi_value NAccessibilityElement::ActionNames(napi_env env, napi_callback_info i
|
||||
napi_create_promise(env, &callbackInfo->deferred_, &promise);
|
||||
}
|
||||
|
||||
AccessibilityElement* accessibilityElement = nullptr;
|
||||
napi_status status = napi_unwrap(env, thisVar, (void**)&accessibilityElement);
|
||||
if (!accessibilityElement || status != napi_ok) {
|
||||
HILOG_ERROR("accessibilityElement is null or status[%{public}d] is wrong", status);
|
||||
return ErrorOperation(callbackInfo);
|
||||
}
|
||||
callbackInfo->accessibilityElement_ = *accessibilityElement;
|
||||
if (!callbackInfo->accessibilityElement_.isElementInfo_) {
|
||||
HILOG_ERROR("it is not element info");
|
||||
return ErrorOperation(callbackInfo);
|
||||
}
|
||||
|
||||
napi_value resource = nullptr;
|
||||
napi_create_string_utf8(env, "ActionNames", NAPI_AUTO_LENGTH, &resource);
|
||||
if (resource == nullptr) {
|
||||
|
@ -37,9 +37,11 @@ namespace {
|
||||
const uint32_t COLOR_GRAY = 0xffc0c0c0;
|
||||
|
||||
constexpr uint32_t COLOR_STRING_SIZE_STANDARD = 8;
|
||||
constexpr uint32_t COLOR_STRING_SIZE_4 = 4;
|
||||
constexpr uint32_t COLOR_STRING_SIZE_5 = 5;
|
||||
constexpr uint32_t COLOR_STRING_SIZE_7 = 7;
|
||||
constexpr uint32_t COLOR_STRING_SIZE_9 = 9;
|
||||
constexpr uint32_t COLOR_STRING_BASE = 16;
|
||||
const std::regex COLOR_WITH_MAGIC("#[0-9A-Fa-f]{6,8}");
|
||||
const std::regex COLOR_WITH_MAGIC_MINI("#[0-9A-Fa-f]{3,4}");
|
||||
constexpr uint32_t COLOR_ALPHA_MASK = 0xff000000;
|
||||
|
||||
constexpr int32_t RGB_LENGTH = 6;
|
||||
@ -49,6 +51,7 @@ namespace {
|
||||
const char UNICODE_BODY = '0';
|
||||
const std::string HALF_VALUE = "0";
|
||||
const std::string FULL_VALUE = "1";
|
||||
const std::string NUMBER_VALID_CHARS = "0123456789ABCDEFabcdef";
|
||||
} // namespace
|
||||
using namespace OHOS::Accessibility;
|
||||
using namespace OHOS::AccessibilityConfig;
|
||||
@ -1654,10 +1657,26 @@ uint32_t ConvertColorStringToNumer(std::string colorStr)
|
||||
return color;
|
||||
}
|
||||
|
||||
bool IsColorWithMagic(const std::string& colorStr)
|
||||
{
|
||||
if (colorStr.size() < 1 || colorStr.substr(0, 1) != "#") {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 1; i < colorStr.size(); i++) {
|
||||
if (NUMBER_VALID_CHARS.find(colorStr[i]) == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColorRegexMatch(std::string colorStr, uint32_t &color)
|
||||
{
|
||||
// Regex match for #909090 or #90909090.
|
||||
if (std::regex_match(colorStr, COLOR_WITH_MAGIC)) {
|
||||
// for example #909090 or #90909090. avoid use regex match #[0-9A-Fa-f]{6,8}.
|
||||
if (IsColorWithMagic(colorStr) &&
|
||||
(colorStr.size() == COLOR_STRING_SIZE_7 || colorStr.size() == COLOR_STRING_SIZE_9)) {
|
||||
colorStr.erase(0, 1);
|
||||
auto colorValue = stoul(colorStr, nullptr, COLOR_STRING_BASE);
|
||||
if (colorStr.length() < COLOR_STRING_SIZE_STANDARD) {
|
||||
@ -1671,8 +1690,9 @@ bool ColorRegexMatch(std::string colorStr, uint32_t &color)
|
||||
color = colorValue;
|
||||
return true;
|
||||
}
|
||||
// Regex match for #rgb or #rgba.
|
||||
if (std::regex_match(colorStr, COLOR_WITH_MAGIC_MINI)) {
|
||||
// for #rgb or #rgba. avoid use regex match #[0-9A-Fa-f]{3,4}.
|
||||
if (IsColorWithMagic(colorStr) &&
|
||||
(colorStr.size() == COLOR_STRING_SIZE_4 || colorStr.size() == COLOR_STRING_SIZE_5)) {
|
||||
colorStr.erase(0, 1);
|
||||
std::string newColorStr;
|
||||
// Translate #rgb or #rgba to #rrggbb or #rrggbbaa
|
||||
|
Loading…
Reference in New Issue
Block a user