diff --git a/shell/platform/ohos/accessibility/native_accessibility_channel.cpp b/shell/platform/ohos/accessibility/native_accessibility_channel.cpp index b772ab6603ff9644ba3e6bd7e34c878bbadac634..7d571f3528bd1d3484c97909e4cbacc28fc304cc 100644 --- a/shell/platform/ohos/accessibility/native_accessibility_channel.cpp +++ b/shell/platform/ohos/accessibility/native_accessibility_channel.cpp @@ -73,7 +73,7 @@ namespace flutter { { auto ohos_shell_holder = reinterpret_cast(shellHolderId); - ohos_shell_holder->GetPlatformView()->PlatformView::DispatchSemanticsAction(id, action, fml::MallocMapping()); + ohos_shell_holder->GetPlatformView()->PlatformView::DispatchSemanticsAction(id, action, std::move(args)); } /** diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index d173fdba5c19d5b428740f408ed4d3d1dad646b2..dbb1a076e9f5bad61c48d76558c3fe68aef5513d 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -44,16 +44,16 @@ OhosAccessibilityBridge* OhosAccessibilityBridge::GetInstance() } OhosAccessibilityBridge::OhosAccessibilityBridge() - : isFlutterNavigated_(false), provider_(nullptr), isAccessibilityEnabled_(false) {} + : isFlutterNavigated_(false), provider_(nullptr), + isAccessibilityEnabled_(false) {} /** * 监听当前ohos平台是否开启无障碍屏幕朗读服务 */ void OhosAccessibilityBridge::OnOhosAccessibilityStateChange( - int64_t shellHolderId, - bool ohosAccessibilityEnabled) + bool ohosAccessibilityEnabled, int64_t shellholderId) { - native_shell_holder_id_ = shellHolderId; + native_shell_holder_id_ = shellholderId; provider_ = XComponentAdapter::GetInstance()->accessibilityProvider_; nativeAccessibilityChannel_ = std::make_shared(); accessibilityFeatures_ = std::make_shared(); @@ -81,15 +81,16 @@ void OhosAccessibilityBridge::UpdateSemantics( flutter::CustomAccessibilityActionUpdates actions) { FML_DLOG(INFO) << "OhosAccessibilityBridge::UpdateSemantics()"; + provider_ = XComponentAdapter::GetInstance()->accessibilityProvider_; std::vector updatedFlutterNodes; // 当flutter页面状态更新(路由新页面)时,自动请求root节点组件获焦(规避滑动组件更新干扰) if (isFlutterNavigated_) { - Flutter_SendAccessibilityAsyncEvent(0, - ArkUI_AccessibilityEventType:: - ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_STATE_UPDATE); - RequestFocusWhenPageUpdate(0); - isFlutterNavigated_ = false; + Flutter_SendAccessibilityAsyncEvent(0, + ArkUI_AccessibilityEventType:: + ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_STATE_UPDATE); + RequestFocusWhenPageUpdate(0); + isFlutterNavigated_ = false; } /** 获取并分析每个语义节点的更新属性 */ @@ -104,11 +105,7 @@ void OhosAccessibilityBridge::UpdateSemantics( GetSemanticsNodeDebugInfo(nodeEx); GetSemanticsFlagsDebugInfo(nodeEx); - /** - * 构建flutter无障碍语义节点树 - * NOTE: 若使用g_flutterSemanticsTree.insert({node.id, node})方式 - * 来添加新增的语义节点会导致已有key值自动忽略,不会更新原有key对应的value - */ + // 构建flutter无障碍语义节点树 g_flutterSemanticsTree[nodeEx.id] = nodeEx; // 若当前节点为获焦 @@ -273,10 +270,8 @@ void OhosAccessibilityBridge::FlutterScrollExecution( void OhosAccessibilityBridge::RequestFocusWhenPageUpdate(int32_t requestFocusId) { if (OHOS_API_VERSION < 13) { return; } - CHECK_NULL_PTR(provider_, RequestFocusWhenPageUpdate); - if (provider_ == nullptr) { - return; - } + provider_ = XComponentAdapter::GetInstance()->accessibilityProvider_; + CHECK_NULL_PTR_RET_VOID(provider_, RequestFocusWhenPageUpdate); auto OH_ArkUI_CreateAccessibilityEventInfo = OhosAccessibilityDDL::DLLoadCreateEventInfoFunc(ArkUIAccessibilityConstant::ARKUI_CREATE_EVENT); @@ -980,8 +975,7 @@ int32_t OhosAccessibilityBridge::FindAccessibilityNodeInfosById( if (OHOS_API_VERSION < 13) { return ARKUI_FAILED_CODE; } FML_DLOG(INFO) << "#### FindAccessibilityNodeInfosById input-params ####: elementId = " - << elementId << " mode=" << mode << " requestId=" << requestId - << " elementList= " << elementList; + << elementId << " mode=" << mode; CHECK_NULL_PTR_WITH_RET(elementList, FindAccessibilityNodeInfosById); if (g_flutterSemanticsTree.size() == 0) { @@ -1033,6 +1027,7 @@ int32_t OhosAccessibilityBridge::FindAccessibilityNodeInfosById( FlutterSetElementInfoProperties(elementInfoFromList, elementId); } FML_DLOG(INFO) << "--- FindAccessibilityNodeInfosById is end ---"; + return ARKUI_ACCESSIBILITY_NATIVE_RESULT_SUCCESSFUL; } @@ -1047,7 +1042,7 @@ void OhosAccessibilityBridge::DispatchSemanticsAction( nativeAccessibilityChannel_->DispatchSemanticsAction(native_shell_holder_id_, id, action, - fml::MallocMapping()); + std::move(args)); } /** @@ -1372,9 +1367,7 @@ int32_t OhosAccessibilityBridge::ExecuteAccessibilityAction( int32_t requestId) { FML_DLOG(INFO) << "ExecuteAccessibilityAction input-params-> elementId=" - << elementId << " action=" << action - << " requestId=" << requestId - << " *actionArguments=" << actionArguments; + << elementId << " action=" << action; CHECK_NULL_PTR_WITH_RET(actionArguments, ExecuteAccessibilityAction); // 获取当前elementid对应的flutter语义节点 @@ -1572,9 +1565,8 @@ void OhosAccessibilityBridge::Flutter_SendAccessibilityAnnounceEvent( ArkUI_AccessibilityEventType eventType) { if (OHOS_API_VERSION < 13) { return; } - - CHECK_NULL_PTR(provider_, Flutter_SendAccessibilityAnnounceEvent); - if (provider_ == nullptr) { return; } + provider_ = XComponentAdapter::GetInstance()->accessibilityProvider_; + CHECK_NULL_PTR_RET_VOID(provider_, Flutter_SendAccessibilityAnnounceEvent); // 创建并设置屏幕朗读事件 auto OH_ArkUI_CreateAccessibilityEventInfo = @@ -1622,9 +1614,8 @@ void OhosAccessibilityBridge::Flutter_SendAccessibilityAsyncEvent( ArkUI_AccessibilityEventType eventType) { if (OHOS_API_VERSION < 13) { return; } - - CHECK_NULL_PTR(provider_, Flutter_SendAccessibilityAsyncEvent); - if (provider_ == nullptr) { return; } + provider_ = XComponentAdapter::GetInstance()->accessibilityProvider_; + CHECK_NULL_PTR_RET_VOID(provider_, Flutter_SendAccessibilityAsyncEvent); // 创建eventInfo对象 auto OH_ArkUI_CreateAccessibilityEventInfo = diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h index d3ae2d4bf2b96a7a608ddb9c7eb5cccbe62763d8..f4e03364ce919ed2d80743e5c48c986d4257616e 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h @@ -82,9 +82,7 @@ public: int64_t native_shell_holder_id_; ArkUI_AccessibilityProvider* provider_; - void OnOhosAccessibilityStateChange( - int64_t shellHolderId, - bool ohosAccessibilityEnabled); + void OnOhosAccessibilityStateChange(bool ohosAccessibilityEnabled, int64_t shellholderId); void SetNativeShellHolderId(int64_t id); @@ -163,8 +161,8 @@ private: std::shared_ptr nativeAccessibilityChannel_; std::shared_ptr accessibilityFeatures_; + std::unordered_map g_flutterSemanticsTree; std::vector> g_parentChildIdVec; - std::map g_flutterSemanticsTree; std::unordered_map g_screenRectMap; SemanticsNodeExtent inputFocusedNode; @@ -325,6 +323,7 @@ private: std::pair GetRealScaleFactor(); void DoubleClickRouteToNewPage(SemanticsNodeExtent node); void GetSemanticsDebugInfo(); + void AccessibiltiyChangesWithXComponentId(); }; enum class AccessibilityAction : int32_t { diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 1fc61d507a57df09687c1d3e6393f50007084516..d1bf9ed4725e9298687873967201de3e48c2efde 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1850,14 +1850,14 @@ napi_value PlatformViewOHOSNapi::nativeAccessibilityStateChange( << ret; return nullptr; } - int64_t shell_holder_id; - ret = napi_get_value_int64(env, args[0], &shell_holder_id); + + int64_t shellHolder = 0; + ret = napi_get_value_int64(env, args[0], &shellHolder); if (ret != napi_ok) { - FML_DLOG(ERROR) << "PlatformViewOHOSNapi::nativeAccessibilityStateChange " - "napi_get_value_int64 error:" - << ret; + LOGE("nativeAccessibilityStateChange shellHolder napi_get_value_int64 error"); return nullptr; } + bool state = false; ret = napi_get_value_bool(env, args[1], &state); if (ret != napi_ok) { @@ -1866,17 +1866,13 @@ napi_value PlatformViewOHOSNapi::nativeAccessibilityStateChange( << ret; return nullptr; } - LOGD( - "PlatformViewOHOSNapi::nativeAccessibilityStateChange state is: " - "%{public}s", - (state ? "true" : "false")); + LOGD("PlatformViewOHOSNapi::nativeAccessibilityStateChange state is: " + "%{public}s, shellholderId: %{public}ld", (state ? "true" : "false"), shellHolder); //send to accessibility bridge if (OHOS_API_VERSION >= 13) { - OhosAccessibilityBridge::GetInstance()->OnOhosAccessibilityStateChange(shell_holder_id, state); + OhosAccessibilityBridge::GetInstance()->OnOhosAccessibilityStateChange(state, shellHolder); } - FML_DLOG(INFO) << "nativeAccessibilityStateChange: state=" << state - << " shell_holder_id=" << shell_holder_id; return nullptr; } diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 8490fd1ade79946bfb2d04587d27985b3ed16629..424123a0c64ccc522e4b29259ebd392b54460644 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -366,14 +366,12 @@ void XComponentBase::DetachFlutterEngine() { void XComponentBase::RegisterArkUIAccessibilityService(OH_NativeXComponent* nativeXComponent) { - if (OH_GetSdkApiVersion() < 13) { return; } - LOGD("api version: %{public}d", OH_GetSdkApiVersion()); - BindAccessibilityProviderCallback(); auto OH_NativeXComponent_GetNativeAccessibilityProvider = OhosAccessibilityDDL::DLLoadGetNativeA11yProvider(ArkUIAccessibilityConstant::OH_GET_A11Y_PROVIDER); CHECK_DLL_NULL_PTR(OH_NativeXComponent_GetNativeAccessibilityProvider); + ArkUI_AccessibilityProvider* a11yProvider = nullptr; ARKUI_ACCESSIBILITY_CALL_CHECK( OH_NativeXComponent_GetNativeAccessibilityProvider(nativeXComponent, &a11yProvider) @@ -388,6 +386,7 @@ void XComponentBase::RegisterArkUIAccessibilityService(OH_NativeXComponent* nati ); XComponentAdapter::GetInstance()->accessibilityProvider_ = a11yProvider; + FML_DLOG(INFO) << "RegisterArkUIAccessibilityService is finished"; } @@ -398,7 +397,9 @@ void XComponentBase::SetNativeXComponent(OH_NativeXComponent* nativeXComponent){ OH_NativeXComponent_RegisterCallback(nativeXComponent_, &callback_); OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent_, &mouseCallback_); // register the OH_ArkUI accessibility callbacks - RegisterArkUIAccessibilityService(nativeXComponent_); + if (OH_GetSdkApiVersion() >= 13) { + RegisterArkUIAccessibilityService(nativeXComponent_); + } } } @@ -455,6 +456,7 @@ void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, void* wind void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, void* window) { window_ = nullptr; + XComponentAdapter::GetInstance()->accessibilityProvider_ = nullptr; LOGD("XComponentManger::OnSurfaceDestroyed"); if (isEngineAttached_) { PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index 529a1d226bd696811f9b9bc0e242286a7787b323..7698e3a8f2cb44c9be00d65370badaad71ae55e3 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -20,6 +20,7 @@ #include #include #include + #include "flutter/shell/platform/ohos/ohos_touch_processor.h" #include "flutter/shell/platform/ohos/napi/platform_view_ohos_napi.h" #include "napi/native_api.h" @@ -66,6 +67,7 @@ public: uint64_t width_; uint64_t height_; OhosTouchProcessor ohosTouchProcessor_; + ArkUI_AccessibilityProvider* accessibilityProvider_; }; diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index 2ba37590a3c446987780e057a660fcdd80c863a8..6d860f66aa1bd0d2d71161f8ed44301f1093a5e7 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -27,6 +27,7 @@ #include "flutter/shell/platform/ohos/platform_view_ohos_delegate.h" #include + namespace flutter { OhosSurfaceFactoryImpl::OhosSurfaceFactoryImpl( @@ -297,9 +298,12 @@ void PlatformViewOHOS::UpdateAssetResolverByType( void PlatformViewOHOS::UpdateSemantics( flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) { - FML_DLOG(INFO) << "PlatformViewOHOS::UpdateSemantics is called"; - auto nativeAccessibilityChannel_ = std::make_shared(); - nativeAccessibilityChannel_->UpdateSemantics(update, actions); + task_runners_.GetPlatformTaskRunner()->PostTask( + [update = std::move(update), actions = std::move(actions)]() { + auto nativeAccessibilityChannel_ = std::make_shared(); + nativeAccessibilityChannel_->UpdateSemantics(update, actions); + FML_DLOG(INFO) << "PlatformViewOHOS::UpdateSemantics is called"; + }); } // |PlatformView| diff --git a/shell/platform/ohos/utils/ddl_utils.h b/shell/platform/ohos/utils/ddl_utils.h index 0e5eca65a87d369ba8950de9e5bdfac54db7fa7e..60f89db6d3c38387acfa069180bea25f67514840 100644 --- a/shell/platform/ohos/utils/ddl_utils.h +++ b/shell/platform/ohos/utils/ddl_utils.h @@ -62,4 +62,13 @@ using LIBHANDLE = void*; } \ } while (false) \ +#define CHECK_NULL_PTR_RET_VOID(PARAM, FUNC) \ + do { \ + if (PARAM == nullptr) { \ + LOGE("Error: %{public}s -> %{public}s is nullptr", \ + #FUNC, #PARAM); \ + return; \ + } \ + } while (false) \ + #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_UTILS_H