From 4a815d19e4d38f35077a89da06bd797ab7b256d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=8F=91=E5=8F=91?= Date: Tue, 22 Jul 2025 17:00:53 +0800 Subject: [PATCH] description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 小发发 --- .../common/include/accessibility_utils.h | 8 ++--- .../src/napi_accessibility_element.cpp | 12 ++++--- .../napi/src/napi_accessibility_utils.cpp | 34 +++++++++++++------ .../include/accessibility_touch_exploration.h | 2 +- ...ouch_exploration_single_finger_gesture.cpp | 18 +++++----- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/interfaces/innerkits/common/include/accessibility_utils.h b/interfaces/innerkits/common/include/accessibility_utils.h index 89e0c304..45bd6cb9 100644 --- a/interfaces/innerkits/common/include/accessibility_utils.h +++ b/interfaces/innerkits/common/include/accessibility_utils.h @@ -82,12 +82,12 @@ bool ConvertEventInfoJSToNAPIPart4( OHOS::AccessibilityConfig::DALTONIZATION_TYPE ConvertStringToDaltonizationTypes(std::string& type); OHOS::AccessibilityConfig::CLICK_RESPONSE_TIME ConvertStringToClickResponseTimeTypes(std::string& type); OHOS::AccessibilityConfig::IGNORE_REPEAT_CLICK_TIME ConvertStringToIgnoreRepeatClickTimeTypes(std::string& type); -void ConvertActionArgsJSToNAPI( +bool ConvertActionArgsJSToNAPI( napi_env env, napi_value object, std::map& args, OHOS::Accessibility::ActionType action); void SetPermCheckFlagForAction(bool checkPerm, std::map& args); -void SetScrollTypeParam(napi_env env, napi_value object, std::map& args); -void SetSelectionParam(napi_env env, napi_value object, std::map& args); -void CheckNumber(napi_env env, std::string value); +bool SetScrollTypeParam(napi_env env, napi_value object, std::map& args); +bool SetSelectionParam(napi_env env, napi_value object, std::map& args); +bool CheckNumber(napi_env env, std::string value); KeyAction TransformKeyActionValue(int32_t keyAction); bool HasKeyCode(const std::vector& pressedKeys, int32_t keyCode); diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_element.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_element.cpp index 21010060..5ea27a05 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_element.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_element.cpp @@ -2216,8 +2216,10 @@ napi_value NAccessibilityElement::PerformActionConstructPromise(napi_env env, si napi_typeof(env, argv[PARAM2], &thirdParamType); if (thirdParamType == napi_function) { if (secondParamType == napi_object) { - ConvertActionArgsJSToNAPI(env, argv[PARAM1], actionArguments, - ConvertStringToAccessibleOperationType(actionName)); + if (!ConvertActionArgsJSToNAPI(env, argv[PARAM1], actionArguments, + ConvertStringToAccessibleOperationType(actionName))) { + return nullptr; + } } napi_create_reference(env, argv[PARAM2], 1, &callbackInfo->callback_); napi_get_undefined(env, &promise); @@ -2236,8 +2238,10 @@ napi_value NAccessibilityElement::PerformActionConstructPromise(napi_env env, si napi_get_undefined(env, &promise); } else { if (valueType == napi_object) { - ConvertActionArgsJSToNAPI(env, argv[PARAM1], actionArguments, - ConvertStringToAccessibleOperationType(actionName)); + if (!ConvertActionArgsJSToNAPI(env, argv[PARAM1], actionArguments, + ConvertStringToAccessibleOperationType(actionName))) { + return nullptr; + } } HILOG_DEBUG("argc is two, use promise"); napi_create_promise(env, &callbackInfo->deferred_, &promise); diff --git a/interfaces/kits/napi/src/napi_accessibility_utils.cpp b/interfaces/kits/napi/src/napi_accessibility_utils.cpp index 977a5fe1..78ece47a 100644 --- a/interfaces/kits/napi/src/napi_accessibility_utils.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_utils.cpp @@ -1104,13 +1104,14 @@ std::string ConvertTextMoveUnitToString(TextMoveUnit type) return textMoveUnitTable.at(type); } -void ConvertActionArgsJSToNAPI( +bool ConvertActionArgsJSToNAPI( napi_env env, napi_value object, std::map& args, OHOS::Accessibility::ActionType action) { napi_value propertyNameValue = nullptr; bool hasProperty = false; std::string str = ""; bool seleFlag = false; + bool ret = true; switch (action) { case ActionType::ACCESSIBILITY_ACTION_NEXT_HTML_ITEM: case ActionType::ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM: @@ -1129,12 +1130,12 @@ void ConvertActionArgsJSToNAPI( } break; case ActionType::ACCESSIBILITY_ACTION_SET_SELECTION: - SetSelectionParam(env, object, args); + ret = SetSelectionParam(env, object, args); break; case ActionType::ACCESSIBILITY_ACTION_SET_CURSOR_POSITION: napi_create_string_utf8(env, "offset", NAPI_AUTO_LENGTH, &propertyNameValue); str = ConvertStringJSToNAPI(env, object, propertyNameValue, hasProperty); - CheckNumber(env, str); + ret = CheckNumber(env, str); if (hasProperty) { args.insert(std::pair("offset", str.c_str())); } @@ -1149,34 +1150,38 @@ void ConvertActionArgsJSToNAPI( case ActionType::ACCESSIBILITY_ACTION_SPAN_CLICK: napi_create_string_utf8(env, "spanId", NAPI_AUTO_LENGTH, &propertyNameValue); str = ConvertStringJSToNAPI(env, object, propertyNameValue, hasProperty); - CheckNumber(env, str); + ret = CheckNumber(env, str); if (hasProperty) { args.insert(std::pair("spanId", str.c_str())); } break; case ActionType::ACCESSIBILITY_ACTION_SCROLL_FORWARD: - SetScrollTypeParam(env, object, args); + ret = SetScrollTypeParam(env, object, args); break; case ActionType::ACCESSIBILITY_ACTION_SCROLL_BACKWARD: - SetScrollTypeParam(env, object, args); + ret = SetScrollTypeParam(env, object, args); break; default: break; } + return ret; } -void CheckNumber(napi_env env, std::string value) +bool CheckNumber(napi_env env, std::string value) { int num; std::stringstream streamStr; streamStr << value; if (!(streamStr >> num)) { + HILOG_ERROR("check number failed!"); napi_value err = CreateBusinessError(env, RetError::RET_ERR_INVALID_PARAM); napi_throw(env, err); + return false; } + return true; } -void SetSelectionParam(napi_env env, napi_value object, std::map& args) +bool SetSelectionParam(napi_env env, napi_value object, std::map& args) { napi_value propertyNameValue = nullptr; bool hasProperty = false; @@ -1184,13 +1189,17 @@ void SetSelectionParam(napi_env env, napi_value object, std::map("selectTextBegin", str.c_str())); } napi_create_string_utf8(env, "selectTextEnd", NAPI_AUTO_LENGTH, &propertyNameValue); str = ConvertStringJSToNAPI(env, object, propertyNameValue, hasProperty); - CheckNumber(env, str); + if (!CheckNumber(env, str)) { + return false; + } if (hasProperty) { args.insert(std::pair("selectTextEnd", str.c_str())); } @@ -1200,9 +1209,10 @@ void SetSelectionParam(napi_env env, napi_value object, std::map("selectTextInForWard", value.c_str())); } + return true; } -void SetScrollTypeParam(napi_env env, napi_value object, std::map& args) +bool SetScrollTypeParam(napi_env env, napi_value object, std::map& args) { napi_value propertyNameValue = nullptr; bool hasProperty = false; @@ -1224,9 +1234,11 @@ void SetScrollTypeParam(napi_env env, napi_value object, std::map("scrolltype", scrollValue.c_str())); } + return true; } void SetPermCheckFlagForAction(bool checkPerm, std::map& args) diff --git a/services/aams/include/accessibility_touch_exploration.h b/services/aams/include/accessibility_touch_exploration.h index 50d6ed50..f3f22437 100644 --- a/services/aams/include/accessibility_touch_exploration.h +++ b/services/aams/include/accessibility_touch_exploration.h @@ -334,7 +334,7 @@ private: std::vector GetOneFingerSwipePath(); int32_t GetSwipeDirection(const int32_t dx, const int32_t dy); bool RecordFocusedLocation(MMI::PointerEvent &event); - void OffsetEvent(MMI::PointerEvent &event); + void OffsetEvent(MMI::PointerEvent &event, bool setZOrderFlag); bool GetBasePointItem(MMI::PointerEvent::PointerItem &basePointerIterm, int32_t pId); void GetPointOffset(MMI::PointerEvent &event, std::vector &firstPointOffset, std::vector &secondPointOffset); diff --git a/services/aams/src/touch_exploration_single_finger_gesture.cpp b/services/aams/src/touch_exploration_single_finger_gesture.cpp index 1baa6acd..5c4f3748 100755 --- a/services/aams/src/touch_exploration_single_finger_gesture.cpp +++ b/services/aams/src/touch_exploration_single_finger_gesture.cpp @@ -725,7 +725,7 @@ void TouchExploration::HandleOneFingerSingleTapThenDownStateMove(MMI::PointerEve } } -void TouchExploration::OffsetEvent(MMI::PointerEvent &event) +void TouchExploration::OffsetEvent(MMI::PointerEvent &event, bool setZOrderFlag) { HILOG_DEBUG(); if (receivedPointerEvents_.empty()) { @@ -738,11 +738,13 @@ void TouchExploration::OffsetEvent(MMI::PointerEvent &event) return; } - AccessibilityWindowInfo windowInfo = {}; - if (Singleton::GetInstance().GetAccessibilityWindow(focusedWindowId_, windowInfo)) { - event.SetZOrder(static_cast(windowInfo.GetWindowLayer() + 1)); - } else { - HILOG_ERROR("get windowInfo failed"); + if (setZOrderFlag) { + AccessibilityWindowInfo windowInfo = {}; + if (Singleton::GetInstance().GetAccessibilityWindow(focusedWindowId_, windowInfo)) { + event.SetZOrder(static_cast(windowInfo.GetWindowLayer() + 1)); + } else { + HILOG_ERROR("get windowInfo failed"); + } } MMI::PointerEvent::PointerItem pointer {}; @@ -772,14 +774,14 @@ bool TouchExploration::SendDoubleTapAndLongPressDownEvent() if (!RecordFocusedLocation(receivedPointerEvents_.front())) { return false; } - OffsetEvent(receivedPointerEvents_.front()); + OffsetEvent(receivedPointerEvents_.front(), true); SendEventToMultimodal(receivedPointerEvents_.front(), ChangeAction::NO_CHANGE); return true; } void TouchExploration::HandleOneFingerDoubleTapAndLongPressState(MMI::PointerEvent &event) { - OffsetEvent(event); + OffsetEvent(event, false); SendEventToMultimodal(event, ChangeAction::NO_CHANGE); MMI::PointerEvent::PointerItem pointer {}; -- Gitee