From 305e6e486e0cbd830fcabcab4af9581875df4e8c Mon Sep 17 00:00:00 2001 From: shijie Date: Wed, 23 Oct 2024 18:32:52 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E8=A7=A3=E5=86=B3getContext(this)?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E8=8E=B7=E5=8F=96=E7=9A=84window=E6=98=AFund?= =?UTF-8?q?efine=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shijie --- .../src/main/ets/embedding/ohos/FlutterAbility.ets | 2 +- .../src/main/ets/embedding/ohos/FlutterManager.ets | 11 ++++++----- .../flutter/src/main/ets/plugin/PlatformPlugin.ets | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index 4013fed189..c011613e1d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -179,7 +179,7 @@ export class FlutterAbility extends UIAbility implements Host { Log.i(TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); }); - FlutterManager.getInstance().setUseFullScreen(true); + FlutterManager.getInstance().setUseFullScreen(true, this.context); } catch (exception) { Log.e(TAG, 'Failed to enable the listener for window stage event changes. Cause:' + JSON.stringify(exception)); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets index e2ef4d772b..363878dd12 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets @@ -109,8 +109,8 @@ export default class FlutterManager { return this.mFullScreenListener; } - setUseFullScreen(use: boolean) { - this.mFullScreenListener.setUseFullScreen(use) + setUseFullScreen(use: boolean, context?: Context) { + this.mFullScreenListener.setUseFullScreen(use, context); } useFullScreen(): boolean { @@ -120,7 +120,7 @@ export default class FlutterManager { export interface FullScreenListener { useFullScreen(): boolean; - setUseFullScreen(useFullScreen: boolean): void; + setUseFullScreen(useFullScreen: boolean, context?: Context): void; onScreenStateChanged(data: window.WindowStatusType): void; } @@ -132,12 +132,13 @@ export class DefaultFullScreenListener implements FullScreenListener { return this.fullScreen; } - setUseFullScreen(useFullScreen: boolean): void { + setUseFullScreen(useFullScreen: boolean, context?: Context): void { this.fullScreen = useFullScreen; this.skipCheck = true; + context = context??getContext(this); let window = FlutterManager.getInstance() - .getWindowStage(FlutterManager.getInstance().getUIAbility(getContext(this))); + .getWindowStage(FlutterManager.getInstance().getUIAbility(context)); window.getMainWindowSync().setWindowLayoutFullScreen(useFullScreen); Log.i(TAG, "WindowLayoutFullScreen is on") } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets index 949480ec65..500390aeb9 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets @@ -279,13 +279,13 @@ export class PlatformPluginCallback implements PlatformMessageHandler { let uiConfig: ('status' | 'navigation')[] = []; if (mode == SystemUiMode.LEAN_BACK) { //全屏显示,通过点击显示器上的任何位置都可以显示状态和导航栏 - FlutterManager.getInstance().setUseFullScreen(true); + FlutterManager.getInstance().setUseFullScreen(true, null); } else if (mode == SystemUiMode.IMMERSIVE) { //全屏显示,通过在显示器边缘的滑动手势可以显示状态和导航栏,应用程序不会接收到此手势 - FlutterManager.getInstance().setUseFullScreen(true); + FlutterManager.getInstance().setUseFullScreen(true, null); } else if (mode == SystemUiMode.IMMERSIVE_STICKY) { //全屏显示,通过在显示器边缘的滑动手势可以显示状态和导航栏,此手势由应用程序接收 - FlutterManager.getInstance().setUseFullScreen(true); + FlutterManager.getInstance().setUseFullScreen(true, null); } else if (mode == SystemUiMode.EDGE_TO_EDGE) { uiConfig = ['status', 'navigation']; } else { -- Gitee From 8877a568dabfff5855ef581fe1f6ef3faba25399 Mon Sep 17 00:00:00 2001 From: shijie Date: Wed, 23 Oct 2024 19:41:14 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E6=8A=A5=E9=94=99=EF=BC=9AArgument=20of=20type=20'null'=20is?= =?UTF-8?q?=20not=20assignable=20to=20parameter=20of=20type=20'Context=20|?= =?UTF-8?q?=20undefined'=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shijie --- .../flutter/src/main/ets/embedding/ohos/FlutterManager.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets index 363878dd12..0f449572ed 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets @@ -109,7 +109,7 @@ export default class FlutterManager { return this.mFullScreenListener; } - setUseFullScreen(use: boolean, context?: Context) { + setUseFullScreen(use: boolean, context?: Context | null | undefined) { this.mFullScreenListener.setUseFullScreen(use, context); } @@ -120,7 +120,7 @@ export default class FlutterManager { export interface FullScreenListener { useFullScreen(): boolean; - setUseFullScreen(useFullScreen: boolean, context?: Context): void; + setUseFullScreen(useFullScreen: boolean, context?: Context | null | undefined): void; onScreenStateChanged(data: window.WindowStatusType): void; } @@ -132,7 +132,7 @@ export class DefaultFullScreenListener implements FullScreenListener { return this.fullScreen; } - setUseFullScreen(useFullScreen: boolean, context?: Context): void { + setUseFullScreen(useFullScreen: boolean, context?: Context | null | undefined): void { this.fullScreen = useFullScreen; this.skipCheck = true; -- Gitee From f1f6ab6836531ca0dc117c043b7f6fdf1ec05a75 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Thu, 24 Oct 2024 19:58:21 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9ets=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E7=A8=B3=E5=AE=9A=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../src/main/ets/embedding/ohos/FlutterPage.ets | 2 +- .../src/main/ets/plugin/editing/TextInputPlugin.ets | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 1634db5f6f..de520a54ea 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -183,7 +183,7 @@ export struct FlutterPage { aboutToDisappear() { this.flutterView?.removeFirstFrameListener(this); - getContext().eventHub.off(OHOS_FLUTTER_PAGE_UPDATE) + getContext()?.eventHub.off(OHOS_FLUTTER_PAGE_UPDATE) } onFirstFrame() { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index 2d5c4ac2a3..89f07262f5 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -293,12 +293,12 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } cancelListenKeyBoardEvent(): void { - this.inputMethodController.off('insertText', this.insertTextCallback); - this.inputMethodController.off('deleteLeft', this.deleteLeftCallback); - this.inputMethodController.off('deleteRight', this.deleteRightCallback); - this.inputMethodController.off('sendFunctionKey', this.sendFunctionKeyCallback); - this.inputMethodController.off('sendKeyboardStatus', this.sendKeyboardStatusCallback); - this.inputMethodController.off('selectByRange', this.selectByRangeCallback); + this.inputMethodController?.off('insertText', this.insertTextCallback); + this.inputMethodController?.off('deleteLeft', this.deleteLeftCallback); + this.inputMethodController?.off('deleteRight', this.deleteRightCallback); + this.inputMethodController?.off('sendFunctionKey', this.sendFunctionKeyCallback); + this.inputMethodController?.off('sendKeyboardStatus', this.sendKeyboardStatusCallback); + this.inputMethodController?.off('selectByRange', this.selectByRangeCallback); this.imcFlag = false; } -- Gitee From afda2a78cc605c7ecf4ff9790b5a618ea9766d79 Mon Sep 17 00:00:00 2001 From: zjxi Date: Thu, 23 Jan 2025 16:12:52 +0800 Subject: [PATCH 04/16] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8DpostTask=E5=BC=95?= =?UTF-8?q?=E8=B5=B7=E7=9A=84=E7=A9=BA=E6=8C=87=E9=92=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- shell/platform/ohos/platform_view_ohos.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index 6d860f66aa..28c626a4f2 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -298,12 +298,9 @@ void PlatformViewOHOS::UpdateAssetResolverByType( void PlatformViewOHOS::UpdateSemantics( flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates 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"; - }); + FML_DLOG(INFO) << "PlatformViewOHOS::UpdateSemantics()"; + auto nativeAccessibilityChannel_ = std::make_shared(); + nativeAccessibilityChannel_->UpdateSemantics(update, actions); } // |PlatformView| -- Gitee From 306134ac49e328f9e6e242d90682c343d861d011 Mon Sep 17 00:00:00 2001 From: zjxi Date: Mon, 20 Jan 2025 13:02:02 +0800 Subject: [PATCH 05/16] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=97=A0=E9=9A=9C?= =?UTF-8?q?=E7=A2=8D=E5=8D=95=E5=AE=9E=E4=BE=8Bxcomponent=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E9=97=AA=E9=80=80=E9=97=AE=E9=A2=98=E3=80=81=E7=9B=B8?= =?UTF-8?q?=E5=AF=B9-=E7=BB=9D=E5=AF=B9=E5=9D=90=E6=A0=87=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E7=AE=97=E6=B3=95bug=E5=AF=BC=E8=87=B4hypium=E4=B8=8B?= =?UTF-8?q?=E6=BB=91=E5=8A=A8=E5=B8=83=E5=B1=80=E8=8A=82=E7=82=B9=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../ohos_accessibility_bridge.cpp | 224 +++++++++++------- .../accessibility/ohos_accessibility_bridge.h | 20 +- .../platform/ohos/ohos_xcomponent_adapter.cpp | 24 +- shell/platform/ohos/ohos_xcomponent_adapter.h | 8 +- 4 files changed, 173 insertions(+), 103 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index dbb1a076e9..bd180fb3a5 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -21,8 +21,6 @@ #include "flutter/shell/common/platform_view.h" #include "flutter/shell/platform/embedder/embedder.h" #include "flutter/shell/platform/ohos/ohos_shell_holder.h" -#include "third_party/skia/include/core/SkMatrix.h" -#include "third_party/skia/include/core/SkScalar.h" #include "flutter/shell/platform/ohos/ohos_xcomponent_adapter.h" namespace flutter { @@ -31,6 +29,34 @@ const int32_t OhosAccessibilityBridge::OHOS_API_VERSION = OH_GetSdkApiVersion(); std::unique_ptr OhosAccessibilityBridge::bridgeInstance_ = nullptr; +/** + * flutter无障碍相关语义树、句柄指针provider等参数 + * 跟随xcomponentid显示切换,而加载对应xcomponent的语义树和provider指针 + * @NOTE: 当屏幕同时显示多个xcomponent时,无法通过聚焦事件而触发xcomponentid改变 + */ +void OhosAccessibilityBridge::AccessibiltiyChangesWithXComponentId() +{ + auto xcompMap = XComponentAdapter::GetInstance()->xcomponetMap_; + // 获取当前显示的xcomponetid + std::string currXcompId = XComponentAdapter::GetInstance()->currentXComponentId_; + if (xcomponentId_ == currXcompId) { return; } + + auto it = xcompMap.find(currXcompId); + if (!xcompMap.empty() && it != xcompMap.end()) { + // 更新xcompid,shellholderId,provider指针 + xcomponentId_ = currXcompId; + native_shell_holder_id_ = std::stoll(it->second->shellholderId_); + g_flutterSemanticsTree = g_flutterSemanticsTreeXComponents[xcomponentId_]; + g_parentChildIdVec = g_parentChildIdVecXComponents[xcomponentId_]; + FML_DLOG(INFO) << "AccessibiltiyChangesWithXComponentId -> xcomponentid:" << xcomponentId_; + } else { + xcomponentId_ = "oh_flutter_1"; + g_flutterSemanticsTree = g_flutterSemanticsTreeXComponents[xcomponentId_]; + g_parentChildIdVec = g_parentChildIdVecXComponents[xcomponentId_]; + FML_DLOG(INFO) << "AccessibiltiyChangesWithXComponentId -> xcomponentid:" << xcomponentId_; + } +} + /** * 采用局部静态变量配合call-once特性,实现线程安全的单例模式 */ @@ -44,7 +70,7 @@ OhosAccessibilityBridge* OhosAccessibilityBridge::GetInstance() } OhosAccessibilityBridge::OhosAccessibilityBridge() - : isFlutterNavigated_(false), provider_(nullptr), + : isFlutterNavigated_(false), isAccessibilityEnabled_(false) {} /** @@ -54,7 +80,7 @@ void OhosAccessibilityBridge::OnOhosAccessibilityStateChange( bool ohosAccessibilityEnabled, int64_t shellholderId) { native_shell_holder_id_ = shellholderId; - provider_ = XComponentAdapter::GetInstance()->accessibilityProvider_; + AccessibiltiyChangesWithXComponentId(); nativeAccessibilityChannel_ = std::make_shared(); accessibilityFeatures_ = std::make_shared(); @@ -67,9 +93,18 @@ void OhosAccessibilityBridge::OnOhosAccessibilityStateChange( } } -void OhosAccessibilityBridge::SetNativeShellHolderId(int64_t id) +/** + * build the id mapping betwween parent node and its children nodes + */ +void OhosAccessibilityBridge::BuildParentChildNodeIdRelation( + const SemanticsNodeExtent& node) { - this->native_shell_holder_id_ = id; + if (!IsNodeVisible(node)) { return; } + for (const auto& childId : node.childrenInTraversalOrder) { + auto childNode = GetFlutterSemanticsNode(childId); + if (!IsNodeVisible(childNode)) { continue; } + g_parentChildIdVec.emplace_back(std::make_pair(node.id, childId)); + } } /** @@ -81,14 +116,10 @@ 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; } @@ -97,16 +128,20 @@ void OhosAccessibilityBridge::UpdateSemantics( for (const auto& item : update) { // 获取当前更新的节点node const auto& node = item.second; - + FML_DLOG(INFO) << "*#*#* node.id=" << node.id; // 更新扩展的SemanticsNode信息 auto nodeEx = UpdatetSemanticsNodeExtent(node); + // 构建flutter无障碍语义节点树 + g_flutterSemanticsTree[nodeEx.id] = nodeEx; + // 构建flutter节点的父子id映射关系 + BuildParentChildNodeIdRelation(nodeEx); + //print semantics node and flags info for debugging GetSemanticsNodeDebugInfo(nodeEx); GetSemanticsFlagsDebugInfo(nodeEx); - // 构建flutter无障碍语义节点树 - g_flutterSemanticsTree[nodeEx.id] = nodeEx; + if (!IsNodeVisible(nodeEx)) { continue; } // 若当前节点为获焦 if (IsNodeFocused(nodeEx)) { @@ -115,12 +150,7 @@ void OhosAccessibilityBridge::UpdateSemantics( // 若当前节点和更新前节点信息不同,则加入更新节点数组 if (nodeEx.hadPreviousConfig) { updatedFlutterNodes.emplace_back(nodeEx); - } - - // 获取当前flutter节点的全部子节点数量,并构建父子节点id映射关系 - int32_t childNodeCount = nodeEx.childrenInTraversalOrder.size(); - for (int32_t i = 0; i < childNodeCount; i++) { - g_parentChildIdVec.emplace_back(std::make_pair(nodeEx.id, nodeEx.childrenInTraversalOrder[i])); + FML_DLOG(INFO) << "updatedFlutterNodes -> node.id=" << nodeEx.id; } } @@ -131,10 +161,12 @@ void OhosAccessibilityBridge::UpdateSemantics( LOGD("Flutter_SendAccessibilityAsyncEvent -> PAGE_CONTENT_UPDATE"); /* 针对更新后的节点进行事件处理 */ - for (const auto& nodeEx: updatedFlutterNodes) { + for (auto& nodeEx: updatedFlutterNodes) { + FML_DLOG(INFO) << "*#*#* updated node.id=" << nodeEx.id; + // 当滑动节点产生滑动,并执行滑动处理 if (HasScrolled(nodeEx)) { - LOGD("UpdateSemantics -> has scrolled"); + LOGD("UpdateSemantics -> nodeId = %{public}d has scrolled", nodeEx.id); auto OH_ArkUI_CreateAccessibilityElementInfo = OhosAccessibilityDDL::DLLoadCreateElemInfoFunc(ArkUIAccessibilityConstant::ARKUI_CREATE_NODE); CHECK_DLL_NULL_PTR(OH_ArkUI_CreateAccessibilityElementInfo); @@ -156,16 +188,16 @@ void OhosAccessibilityBridge::UpdateSemantics( _elementInfo = nullptr; } - // 判断是否触发liveRegion活动区,当前节点是否活跃 + // 判断是否触发liveRegion活动区,当前节点是否活跃 nodeEx.HasFlag(FLAGS_::kIsLiveRegion) if (nodeEx.HasFlag(FLAGS_::kIsLiveRegion) && HasChangedLabel(nodeEx)) { - FML_DLOG(INFO) << "UpdateSemantics -> page content update, nodeEx.id=" << nodeEx.id; + FML_DLOG(INFO) << "liveRegion -> page content update, nodeEx.id=" << nodeEx.id; Flutter_SendAccessibilityAsyncEvent(static_cast(nodeEx.id), ArkUI_AccessibilityEventType:: ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_CONTENT_UPDATE); - LOGD("Flutter_SendAccessibilityAsyncEvent -> PAGE_CONTENT_UPDATE"); } } - + // calculate the global tranfomr matrix for each node + ComputeGlobalTransform(); // 输出flutter语义树相关重要语义信息debug日志 GetSemanticsDebugInfo(); FML_DLOG(INFO) << "=== UpdateSemantics() is finished ==="; @@ -205,7 +237,7 @@ void OhosAccessibilityBridge::FlutterScrollExecution( if (node.HasAction(ACTIONS_::kScrollUp) || node.HasAction(ACTIONS_::kScrollDown)) { } else if (node.HasAction(ACTIONS_::kScrollLeft) || - node.HasAction(ACTIONS_::kScrollRight)) { + node.HasAction(ACTIONS_::kScrollRight)) { LOGD("current flutterNode has scroll up/down/left/right"); } @@ -270,7 +302,8 @@ void OhosAccessibilityBridge::FlutterScrollExecution( void OhosAccessibilityBridge::RequestFocusWhenPageUpdate(int32_t requestFocusId) { if (OHOS_API_VERSION < 13) { return; } - provider_ = XComponentAdapter::GetInstance()->accessibilityProvider_; + std::lock_guard lock(XComponentAdapter::GetInstance()->mutex_); + auto provider_ = XComponentAdapter::GetInstance()->GetAccessibilityProvider(xcomponentId_); CHECK_NULL_PTR_RET_VOID(provider_, RequestFocusWhenPageUpdate); auto OH_ArkUI_CreateAccessibilityEventInfo = @@ -462,68 +495,66 @@ std::pair OhosAccessibilityBridge::GetRealScaleFactor() } /** - * flutter语义树中相对坐标系转化为屏幕绝对坐标的映射算法实现 - * NOTE:目前暂未考虑旋转、透视场景,不影响屏幕朗读功能 - * (SkMatrix::kMSkewX, SkMatrix::kMSkewY, SkMatrix::kMPersp0, - * SkMatrix::kMPersp1, SkMatrix::kMPersp2) + * calculate the global transform matrix for each node */ -void OhosAccessibilityBridge::FlutterRelativeRectToScreenRect( - SemanticsNodeExtent currNode) -{ - // 获取当前flutter节点的相对rect - auto [currLeft, currTop, currRight, currBottom] = currNode.rect; - - // 获取当前flutter节点的缩放、平移、透视等矩阵坐标转换以下矩阵坐标变换参数 - SkMatrix transform = currNode.transform.asM33(); - auto _kMScaleX = transform.get(SkMatrix::kMScaleX); - auto _kMTransX = transform.get(SkMatrix::kMTransX); - auto _kMScaleY = transform.get(SkMatrix::kMScaleY); - auto _kMTransY = transform.get(SkMatrix::kMTransY); - - // 获取当前flutter节点的父节点的相对rect - int32_t parentId = GetParentId(currNode.id); - auto parentNode = GetFlutterSemanticsNode(parentId); - if (g_flutterSemanticsTree.find(parentId) == g_flutterSemanticsTree.end()) { - LOGE("FlutterRelativeRectToScreenRect: GetFlutterSemanticsNode id=%{public}d null", parentId); - } - - // 获取当前flutter节点的父节点的绝对坐标 - auto [realParentLeft, realParentTop, realParentRight, realParentBottom] = GetAbsoluteScreenRect(parentNode); - - //获取root节点的绝对坐标 - auto rootNode = GetFlutterSemanticsNode(0); - auto rootRect = GetAbsoluteScreenRect(rootNode); - auto rootWidth = rootRect.right; - auto rootHeight = rootRect.bottom; - - // 获取真实缩放系数 - auto [realScaleXFactor, realScaleYFactor] = GetRealScaleFactor(); - - // 更新后的节点屏幕坐标,子节点的屏幕绝对坐标转换,包括offset偏移值计算、缩放系数变换 - bool isRectScaleChanged = _kMScaleX > 1 && _kMScaleY > 1; - float newLeft = isRectScaleChanged ? - currLeft + _kMTransX * _kMScaleX : (currLeft + _kMTransX) * realScaleXFactor + realParentLeft; - float newTop = isRectScaleChanged ? - currTop + _kMTransY * _kMScaleY : (currTop + _kMTransY) * realScaleYFactor + realParentTop; - float newRight = isRectScaleChanged ? - currRight * _kMScaleX : newLeft + currRight * realScaleXFactor; - float newBottom = isRectScaleChanged ? - currBottom * _kMScaleY : newTop + currBottom * realScaleYFactor; - - // 若子节点rect超过父节点则跳过显示(单个屏幕显示不下,滑动再重新显示) - const bool isExceedScreeArea = newLeft < realParentLeft || newTop < realParentTop || - newRight > realParentRight || newBottom > realParentBottom || - newLeft >= newRight || newTop >= newBottom || - newRight > rootWidth || newBottom > rootHeight; - if (isExceedScreeArea) { - FML_DLOG(WARNING) << "RelativeRectToScreenRect -> childRect exceeds parentRect {Id: " - << currNode.id << ", (" << newLeft << ", " << newTop - << ", " << newRight << ", " << newBottom << ")}"; - // 防止滑动场景下绿框坐标超出屏幕范围,进行正则化处理 - SetAbsoluteScreenRect(currNode, rootWidth, rootHeight, 0, 0); - } else { - SetAbsoluteScreenRect(currNode, newLeft, newTop, newRight, newBottom); +void OhosAccessibilityBridge::ComputeGlobalTransform() +{ + std::queue semanticsQue; + + auto root = GetFlutterSemanticsNode(0); + semanticsQue.push(root); + g_globalTransformMap[root.id] = root.transform; + + while (!semanticsQue.empty()) { + uint32_t queSize = semanticsQue.size(); + for (uint32_t i=0; i Transformed points can't make a rect "; } + globalRect.setBounds(points, 4); + + SetAbsoluteScreenRect(node, globalRect.left(), globalRect.top(), + globalRect.right(), globalRect.bottom()); } /** @@ -655,7 +686,7 @@ void OhosAccessibilityBridge::FlutterSetElementInfoProperties( rect = {static_cast(left), static_cast(top), static_cast(right), static_cast(bottom)}; } else { // 若当前节点为id >= 1的节点 - FlutterRelativeRectToScreenRect(flutterNode); + RelativeRectToScreenRect(flutterNode); auto [left, top, right, bottom] = GetAbsoluteScreenRect(flutterNode); rect = {static_cast(left), static_cast(top), static_cast(right), static_cast(bottom)}; @@ -889,7 +920,8 @@ void OhosAccessibilityBridge::FlutterSetElementInfoProperties( OhosAccessibilityDDL::DLLoadSetElemStringFunc(ArkUIAccessibilityConstant::ARKUI_SET_A11Y_LEVEL); CHECK_DLL_NULL_PTR(OH_ArkUI_AccessibilityElementInfoSetAccessibilityLevel); ARKUI_ACCESSIBILITY_CALL_CHECK( - OH_ArkUI_AccessibilityElementInfoSetAccessibilityLevel(elementInfoFromList, "yes"); + OH_ArkUI_AccessibilityElementInfoSetAccessibilityLevel( + elementInfoFromList, componentTypeName != OTHER_WIDGET_NAME ? "yes" : "no"); ); // 无障碍组,设置为true时表示该组件及其所有子组件为一整个可以选中的组件,无障碍服务将不再关注其子组件内容。默认值:false auto OH_ArkUI_AccessibilityElementInfoSetAccessibilityGroup = @@ -917,6 +949,7 @@ std::vector OhosAccessibilityBridge::GetLevelOrderTraversalTree(int32_t uint32_t queSize = semanticsQue.size(); for (uint32_t i=0; i(currNode.id)); @@ -924,6 +957,7 @@ std::vector OhosAccessibilityBridge::GetLevelOrderTraversalTree(int32_t currNode.childrenInTraversalOrder.end()); for (const auto& childId: currNode.childrenInTraversalOrder) { auto childNode = GetFlutterSemanticsNode(childId); + semanticsQue.push(childNode); } } @@ -1565,7 +1599,9 @@ void OhosAccessibilityBridge::Flutter_SendAccessibilityAnnounceEvent( ArkUI_AccessibilityEventType eventType) { if (OHOS_API_VERSION < 13) { return; } - provider_ = XComponentAdapter::GetInstance()->accessibilityProvider_; + AccessibiltiyChangesWithXComponentId(); + std::lock_guard lock(XComponentAdapter::GetInstance()->mutex_); + auto provider_ = XComponentAdapter::GetInstance()->GetAccessibilityProvider(xcomponentId_); CHECK_NULL_PTR_RET_VOID(provider_, Flutter_SendAccessibilityAnnounceEvent); // 创建并设置屏幕朗读事件 @@ -1614,7 +1650,9 @@ void OhosAccessibilityBridge::Flutter_SendAccessibilityAsyncEvent( ArkUI_AccessibilityEventType eventType) { if (OHOS_API_VERSION < 13) { return; } - provider_ = XComponentAdapter::GetInstance()->accessibilityProvider_; + AccessibiltiyChangesWithXComponentId(); + std::lock_guard lock(XComponentAdapter::GetInstance()->mutex_); + auto provider_ = XComponentAdapter::GetInstance()->GetAccessibilityProvider(xcomponentId_); CHECK_NULL_PTR_RET_VOID(provider_, Flutter_SendAccessibilityAsyncEvent); // 创建eventInfo对象 @@ -1967,6 +2005,10 @@ void OhosAccessibilityBridge::ClearFlutterSemanticsCaches() g_flutterSemanticsTree.clear(); g_parentChildIdVec.clear(); g_screenRectMap.clear(); + Flutter_SendAccessibilityAsyncEvent( + accessibilityFocusedNode.id, + ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_ACCESSIBILITY_FOCUS_CLEARED); + accessibilityFocusedNode = {}; } /** diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h index f4e03364ce..73aa59dec9 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h @@ -30,6 +30,9 @@ #include "ohos_accessibility_ddl.h" #include "flutter/shell/platform/ohos/utils/ohos_utils.h" #include "flutter/shell/platform/ohos/utils/arkui_accessibility_constant.h" +#include "third_party/skia/include/core/SkMatrix.h" +#include "third_party/skia/include/core/SkScalar.h" +#include "third_party/skia/include/core/SkPoint.h" namespace flutter { typedef flutter::SemanticsFlags FLAGS_; @@ -43,9 +46,15 @@ struct AbsoluteRect { static constexpr AbsoluteRect MakeEmpty() { return AbsoluteRect{0.0, 0.0, 0.0, 0.0}; } + static constexpr AbsoluteRect MakeRect( + float left, float top, float right, float bottom) { + return AbsoluteRect{left, top, right, bottom}; + } + }; struct SemanticsNodeExtent : flutter::SemanticsNode { bool isNull = false; + SkM44 globalTransform = SkM44{}; AbsoluteRect absoluteRect = AbsoluteRect::MakeEmpty(); int32_t parentId = -1; bool hadPreviousConfig = false; @@ -80,12 +89,9 @@ public: bool isFlutterNavigated_; int64_t native_shell_holder_id_; - ArkUI_AccessibilityProvider* provider_; void OnOhosAccessibilityStateChange(bool ohosAccessibilityEnabled, int64_t shellholderId); - void SetNativeShellHolderId(int64_t id); - void UpdateSemantics(flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions); @@ -138,7 +144,7 @@ public: std::unique_ptr& message, ArkUI_AccessibilityEventType eventType); - void FlutterRelativeRectToScreenRect(SemanticsNodeExtent node); + void RelativeRectToScreenRect(SemanticsNodeExtent& node); AbsoluteRect GetAbsoluteScreenRect(SemanticsNodeExtent& flutterNode); void SetAbsoluteScreenRect(SemanticsNodeExtent& flutterNode, float left, @@ -164,6 +170,7 @@ private: std::unordered_map g_flutterSemanticsTree; std::vector> g_parentChildIdVec; std::unordered_map g_screenRectMap; + std::unordered_map g_globalTransformMap; SemanticsNodeExtent inputFocusedNode; SemanticsNodeExtent lastInputFocusedNode; @@ -250,6 +257,11 @@ private: flutter::SemanticsAction ArkuiActionsToFlutterActions( ArkUI_Accessibility_ActionType arkui_action); + void BuildParentChildNodeIdRelation(const SemanticsNodeExtent& node); + void ComputeGlobalTransform(); + void ConvertRectToGlobal(SemanticsNodeExtent& node); + SkPoint ApplyTransform(SkPoint& point, const SkM44& transform); + bool HasScrolled(const SemanticsNodeExtent& flutterNode); bool HasChangedLabel(const SemanticsNodeExtent& flutterNode); diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 424123a0c6..9a0416e488 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -195,6 +195,7 @@ void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window) { } void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) { + std::lock_guard lock(XComponentAdapter::GetInstance()->mutex_); for(auto it = XComponentAdapter::GetInstance()->xcomponetMap_.begin(); it != XComponentAdapter::GetInstance()->xcomponetMap_.end();) { @@ -364,6 +365,16 @@ void XComponentBase::DetachFlutterEngine() { isEngineAttached_ = false; } +ArkUI_AccessibilityProvider* XComponentAdapter::GetAccessibilityProvider(const std::string& xcompId) +{ + auto it = xcomponetMap_.find(xcompId); + if (it != xcomponetMap_.end()) { + return it->second->accessibilityProvider_; + } else { + return nullptr; + } +} + void XComponentBase::RegisterArkUIAccessibilityService(OH_NativeXComponent* nativeXComponent) { BindAccessibilityProviderCallback(); @@ -385,8 +396,11 @@ void XComponentBase::RegisterArkUIAccessibilityService(OH_NativeXComponent* nati OH_ArkUI_AccessibilityProviderRegisterCallback(a11yProvider, &accessibilityProviderCallback_) ); - XComponentAdapter::GetInstance()->accessibilityProvider_ = a11yProvider; - + std::lock_guard lock(XComponentAdapter::GetInstance()->mutex_); + auto* base = XComponentAdapter::GetInstance()->xcomponetMap_[id_]; + base->accessibilityProvider_ = a11yProvider; + base->nativeXComponent_ = nativeXComponent; + FML_DLOG(INFO) << "RegisterArkUIAccessibilityService is finished"; } @@ -397,9 +411,8 @@ void XComponentBase::SetNativeXComponent(OH_NativeXComponent* nativeXComponent){ OH_NativeXComponent_RegisterCallback(nativeXComponent_, &callback_); OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent_, &mouseCallback_); // register the OH_ArkUI accessibility callbacks - if (OH_GetSdkApiVersion() >= 13) { - RegisterArkUIAccessibilityService(nativeXComponent_); - } + if (OH_GetSdkApiVersion() < 13) { return; } + RegisterArkUIAccessibilityService(nativeXComponent_); } } @@ -456,7 +469,6 @@ 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 7698e3a8f2..e98ba03f9a 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -20,7 +20,7 @@ #include #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" @@ -51,7 +51,8 @@ public: void OnDispatchMouseEvent(OH_NativeXComponent* component, void* window); void OnDispatchMouseWheelEvent(mouseWheelEvent event); - void RegisterArkUIAccessibilityService(OH_NativeXComponent* nativeXComponent); + void RegisterArkUIAccessibilityService( + OH_NativeXComponent* nativeXComponent); OH_NativeXComponent_TouchEvent touchEvent_; OH_NativeXComponent_Callback callback_; @@ -83,9 +84,12 @@ class XComponentAdapter { void DetachFlutterEngine(std::string& id); void OnMouseWheel(std::string& id, mouseWheelEvent event); + ArkUI_AccessibilityProvider* GetAccessibilityProvider(const std::string& xcompId); + public: std::map xcomponetMap_; ArkUI_AccessibilityProvider* accessibilityProvider_; + std::mutex mutex_; private: static XComponentAdapter mXComponentAdapter; -- Gitee From 03bcdf30ca605183eb35f373b0fe0a5970cffe34 Mon Sep 17 00:00:00 2001 From: zjxi Date: Fri, 24 Jan 2025 11:12:20 +0800 Subject: [PATCH 06/16] =?UTF-8?q?refactor:=E4=BC=98=E5=8C=96=E5=9D=90?= =?UTF-8?q?=E6=A0=87=E5=AE=B9=E5=99=A8=E5=AD=98=E5=82=A8=E4=B8=BA=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BD=93=E5=AD=97=E6=AE=B5=E5=AD=98=E5=82=A8=EF=BC=8C?= =?UTF-8?q?=E5=87=8F=E5=B0=91=E5=86=85=E5=AD=98=E5=BC=80=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../ohos_accessibility_bridge.cpp | 20 +++++++++---------- .../accessibility/ohos_accessibility_bridge.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index bd180fb3a5..7a1b1ed237 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -466,20 +466,21 @@ void OhosAccessibilityBridge::SetAbsoluteScreenRect(SemanticsNodeExtent& flutter float right, float bottom) { - g_screenRectMap[flutterNode.id] = AbsoluteRect{left, top, right, bottom}; + flutterNode.absoluteRect = {left, top, right, bottom}; FML_DLOG(INFO) << "SetAbsoluteScreenRect -> id=" << flutterNode.id << ", {" << left << ", " << top << ", " << right << ", "<< bottom << "> }"; } -AbsoluteRect OhosAccessibilityBridge::GetAbsoluteScreenRect(SemanticsNodeExtent& flutterNode) +AbsoluteRect OhosAccessibilityBridge::GetAbsoluteScreenRect(const SemanticsNodeExtent& flutterNode) { - if (!g_screenRectMap.empty() && g_screenRectMap.count(flutterNode.id) > 0) { - return g_screenRectMap.at(flutterNode.id); - } else { - FML_DLOG(ERROR) << "GetAbsoluteScreenRect -> flutterNodeId=" - << flutterNode.id << " is not found !"; - return {}; - } + return flutterNode.absoluteRect; + // if (!g_screenRectMap.empty() && g_screenRectMap.count(flutterNode.id) > 0) { + // return g_screenRectMap.at(flutterNode.id); + // } else { + // FML_DLOG(ERROR) << "GetAbsoluteScreenRect -> flutterNodeId=" + // << flutterNode.id << " is not found !"; + // return {}; + // } } /** @@ -2004,7 +2005,6 @@ void OhosAccessibilityBridge::ClearFlutterSemanticsCaches() { g_flutterSemanticsTree.clear(); g_parentChildIdVec.clear(); - g_screenRectMap.clear(); Flutter_SendAccessibilityAsyncEvent( accessibilityFocusedNode.id, ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_ACCESSIBILITY_FOCUS_CLEARED); diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h index 73aa59dec9..1271baddfb 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h @@ -145,7 +145,7 @@ public: ArkUI_AccessibilityEventType eventType); void RelativeRectToScreenRect(SemanticsNodeExtent& node); - AbsoluteRect GetAbsoluteScreenRect(SemanticsNodeExtent& flutterNode); + AbsoluteRect GetAbsoluteScreenRect(const SemanticsNodeExtent& flutterNode); void SetAbsoluteScreenRect(SemanticsNodeExtent& flutterNode, float left, float top, @@ -169,7 +169,7 @@ private: std::unordered_map g_flutterSemanticsTree; std::vector> g_parentChildIdVec; - std::unordered_map g_screenRectMap; + // std::unordered_map g_screenRectMap; std::unordered_map g_globalTransformMap; SemanticsNodeExtent inputFocusedNode; -- Gitee From 30ef4c1468b79c82eefd9fcb6a668896f67683dd Mon Sep 17 00:00:00 2001 From: zjxi Date: Fri, 24 Jan 2025 15:08:23 +0800 Subject: [PATCH 07/16] =?UTF-8?q?refactor:=E6=97=A0=E9=9A=9C=E7=A2=8D?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96-=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E9=9D=9E=E5=BF=85=E8=A6=81=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E5=86=85=E5=AD=98=E5=BC=80=E5=AD=A6=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=87=8F=E5=B0=91=E5=86=97=E4=BD=99=E9=81=8D?= =?UTF-8?q?=E5=8E=86=E5=BC=80=E9=94=80=EF=BC=8C=E6=8F=90=E5=8D=87=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BD=93=E9=AA=8C=E6=B5=81=E7=95=85=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../ohos_accessibility_bridge.cpp | 147 +++++++----------- .../accessibility/ohos_accessibility_bridge.h | 10 +- 2 files changed, 56 insertions(+), 101 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index 7a1b1ed237..72f27ef313 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -47,12 +47,10 @@ void OhosAccessibilityBridge::AccessibiltiyChangesWithXComponentId() xcomponentId_ = currXcompId; native_shell_holder_id_ = std::stoll(it->second->shellholderId_); g_flutterSemanticsTree = g_flutterSemanticsTreeXComponents[xcomponentId_]; - g_parentChildIdVec = g_parentChildIdVecXComponents[xcomponentId_]; FML_DLOG(INFO) << "AccessibiltiyChangesWithXComponentId -> xcomponentid:" << xcomponentId_; } else { xcomponentId_ = "oh_flutter_1"; g_flutterSemanticsTree = g_flutterSemanticsTreeXComponents[xcomponentId_]; - g_parentChildIdVec = g_parentChildIdVecXComponents[xcomponentId_]; FML_DLOG(INFO) << "AccessibiltiyChangesWithXComponentId -> xcomponentid:" << xcomponentId_; } } @@ -93,20 +91,6 @@ void OhosAccessibilityBridge::OnOhosAccessibilityStateChange( } } -/** - * build the id mapping betwween parent node and its children nodes - */ -void OhosAccessibilityBridge::BuildParentChildNodeIdRelation( - const SemanticsNodeExtent& node) -{ - if (!IsNodeVisible(node)) { return; } - for (const auto& childId : node.childrenInTraversalOrder) { - auto childNode = GetFlutterSemanticsNode(childId); - if (!IsNodeVisible(childNode)) { continue; } - g_parentChildIdVec.emplace_back(std::make_pair(node.id, childId)); - } -} - /** * 从dart侧传递到c++侧的flutter无障碍语义树节点更新过程, * 路由新页面、滑动页面等操作会自动触发该语义树的更新 @@ -134,14 +118,8 @@ void OhosAccessibilityBridge::UpdateSemantics( // 构建flutter无障碍语义节点树 g_flutterSemanticsTree[nodeEx.id] = nodeEx; - // 构建flutter节点的父子id映射关系 - BuildParentChildNodeIdRelation(nodeEx); - //print semantics node and flags info for debugging - GetSemanticsNodeDebugInfo(nodeEx); - GetSemanticsFlagsDebugInfo(nodeEx); - - if (!IsNodeVisible(nodeEx)) { continue; } + // if (!IsNodeVisible(nodeEx)) { continue; } // 若当前节点为获焦 if (IsNodeFocused(nodeEx)) { @@ -154,16 +132,20 @@ void OhosAccessibilityBridge::UpdateSemantics( } } - // 页面内容更新事件 - Flutter_SendAccessibilityAsyncEvent(0, - ArkUI_AccessibilityEventType:: - ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_CONTENT_UPDATE); - LOGD("Flutter_SendAccessibilityAsyncEvent -> PAGE_CONTENT_UPDATE"); + // calculate the global tranfomr matrix and parent id for each node + ComputeGlobalTransformAndParentId(); + + // 将更新后的flutter语义树和父子节点id映射缓存,保存到相应的xcomponent里面 + g_flutterSemanticsTreeXComponents[xcomponentId_] = g_flutterSemanticsTree; /* 针对更新后的节点进行事件处理 */ for (auto& nodeEx: updatedFlutterNodes) { FML_DLOG(INFO) << "*#*#* updated node.id=" << nodeEx.id; + //print semantics node and flags info for debugging + GetSemanticsNodeDebugInfo(nodeEx); + GetSemanticsFlagsDebugInfo(nodeEx); + // 当滑动节点产生滑动,并执行滑动处理 if (HasScrolled(nodeEx)) { LOGD("UpdateSemantics -> nodeId = %{public}d has scrolled", nodeEx.id); @@ -196,8 +178,6 @@ void OhosAccessibilityBridge::UpdateSemantics( ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_CONTENT_UPDATE); } } - // calculate the global tranfomr matrix for each node - ComputeGlobalTransform(); // 输出flutter语义树相关重要语义信息debug日志 GetSemanticsDebugInfo(); FML_DLOG(INFO) << "=== UpdateSemantics() is finished ==="; @@ -441,20 +421,16 @@ SemanticsNodeExtent OhosAccessibilityBridge::GetFlutterSemanticsNode( */ int32_t OhosAccessibilityBridge::GetParentId(int64_t elementId) { - if (!g_parentChildIdVec.size()) { - FML_DLOG(WARNING) << "OhosAccessibilityBridge::GetParentId parentChildIdMap.size()=0"; - return ARKUI_ACCESSIBILITY_ROOT_PARENT_ID; - } if (elementId == -1 || elementId == 0) { return ARKUI_ACCESSIBILITY_ROOT_PARENT_ID; } - int32_t childElementId = static_cast(elementId); - for (const auto& item : g_parentChildIdVec) { - if (item.second == childElementId) { - return item.first; - } + int32_t id = static_cast(elementId); + auto node = GetFlutterSemanticsNode(id); + if (!g_flutterSemanticsTree.count(id)) { + LOGE("GetParentId: %{public}d is null", id); + return -1; } - return RET_ERROR_STATE_CODE; + return node.parentId; } /** @@ -474,37 +450,20 @@ void OhosAccessibilityBridge::SetAbsoluteScreenRect(SemanticsNodeExtent& flutter AbsoluteRect OhosAccessibilityBridge::GetAbsoluteScreenRect(const SemanticsNodeExtent& flutterNode) { return flutterNode.absoluteRect; - // if (!g_screenRectMap.empty() && g_screenRectMap.count(flutterNode.id) > 0) { - // return g_screenRectMap.at(flutterNode.id); - // } else { - // FML_DLOG(ERROR) << "GetAbsoluteScreenRect -> flutterNodeId=" - // << flutterNode.id << " is not found !"; - // return {}; - // } -} - -/** - * 获取flutter相对-绝对坐标映射的真实缩放系数 - */ -std::pair OhosAccessibilityBridge::GetRealScaleFactor() -{ - auto secondNode = GetFlutterSemanticsNode(1); - SkMatrix transform = secondNode.transform.asM33(); - auto scaleX = transform.get(SkMatrix::kMScaleX); - auto scaleY = transform.get(SkMatrix::kMScaleY); - return std::make_pair(scaleX, scaleY); } /** * calculate the global transform matrix for each node */ -void OhosAccessibilityBridge::ComputeGlobalTransform() +void OhosAccessibilityBridge::ComputeGlobalTransformAndParentId() { std::queue semanticsQue; - auto root = GetFlutterSemanticsNode(0); - semanticsQue.push(root); - g_globalTransformMap[root.id] = root.transform; + auto rootNode = GetFlutterSemanticsNode(0); + rootNode.globalTransform = rootNode.transform; + rootNode.parentId = ARKUI_ACCESSIBILITY_ROOT_PARENT_ID; + g_flutterSemanticsTree[rootNode.id] = rootNode; + semanticsQue.push(rootNode); while (!semanticsQue.empty()) { uint32_t queSize = semanticsQue.size(); @@ -514,8 +473,10 @@ void OhosAccessibilityBridge::ComputeGlobalTransform() for (const auto& childId: currNode.childrenInTraversalOrder) { auto childNode = GetFlutterSemanticsNode(childId); + childNode.parentId = currNode.id; + childNode.globalTransform = currNode.globalTransform * childNode.transform; + g_flutterSemanticsTree[childId] = childNode; semanticsQue.push(childNode); - g_globalTransformMap[childId] = g_globalTransformMap[currNode.id] * childNode.transform; } } } @@ -534,7 +495,8 @@ SkPoint OhosAccessibilityBridge::ApplyTransform( void OhosAccessibilityBridge::RelativeRectToScreenRect(SemanticsNodeExtent& node) { auto [left, top, right, bottom] = node.rect; - SkM44 globalTransform = g_globalTransformMap[node.id]; + // SkM44 globalTransform = g_globalTransformMap[node.id]; + SkM44 globalTransform = node.globalTransform; SkPoint points[4] = { SkPoint::Make(left, top), // top-left point @@ -1984,17 +1946,6 @@ void OhosAccessibilityBridge::RemoveSemanticsNode( "g_flutterSemanticsTree.szie()=0"; return; } - if (g_flutterSemanticsTree.find(nodeToBeRemoved.id) == - g_flutterSemanticsTree.end()) { - FML_DLOG(INFO) << "Attempted to remove a node that is not in the tree."; - } - int32_t nodeToBeRemovedParentId = GetParentId(nodeToBeRemoved.id); - for (auto it = g_parentChildIdVec.begin(); it != g_parentChildIdVec.end(); it++) { - if (it->first == nodeToBeRemovedParentId && - it->second == nodeToBeRemoved.id) { - g_parentChildIdVec.erase(it); - } - } } /** @@ -2004,7 +1955,6 @@ void OhosAccessibilityBridge::RemoveSemanticsNode( void OhosAccessibilityBridge::ClearFlutterSemanticsCaches() { g_flutterSemanticsTree.clear(); - g_parentChildIdVec.clear(); Flutter_SendAccessibilityAsyncEvent( accessibilityFocusedNode.id, ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_ACCESSIBILITY_FOCUS_CLEARED); @@ -2019,19 +1969,31 @@ SemanticsNodeExtent OhosAccessibilityBridge::UpdatetSemanticsNodeExtent( { SemanticsNodeExtent nodeEx = SemanticsNodeExtent(); // 获取更新前的flutter节点信息 - if (g_flutterSemanticsTree.size() > 0) { - auto prevNode = GetFlutterSemanticsNode(node.id); - nodeEx.hadPreviousConfig = true; - nodeEx.previousFlags = prevNode.flags; - nodeEx.previousActions = prevNode.actions; - nodeEx.previousTextSelectionBase = prevNode.textSelectionBase; - nodeEx.previousTextSelectionExtent = prevNode.textSelectionExtent; - nodeEx.previousScrollPosition = prevNode.scrollPosition; - nodeEx.previousScrollExtentMax = prevNode.scrollExtentMax; - nodeEx.previousScrollExtentMin = prevNode.scrollExtentMin; - nodeEx.previousValue = prevNode.value; - nodeEx.previousLabel = prevNode.label; - } + // if (g_flutterSemanticsTree.size() > 0) { + // auto prevNode = GetFlutterSemanticsNode(node.id); + // nodeEx.hadPreviousConfig = true; + // nodeEx.previousFlags = prevNode.flags; + // nodeEx.previousActions = prevNode.actions; + // nodeEx.previousTextSelectionBase = prevNode.textSelectionBase; + // nodeEx.previousTextSelectionExtent = prevNode.textSelectionExtent; + // nodeEx.previousScrollPosition = prevNode.scrollPosition; + // nodeEx.previousScrollExtentMax = prevNode.scrollExtentMax; + // nodeEx.previousScrollExtentMin = prevNode.scrollExtentMin; + // nodeEx.previousValue = prevNode.value; + // nodeEx.previousLabel = prevNode.label; + // } + + nodeEx.hadPreviousConfig = true; + nodeEx.previousFlags = nodeEx.flags; + nodeEx.previousActions = nodeEx.actions; + nodeEx.previousTextSelectionBase = nodeEx.textSelectionBase; + nodeEx.previousTextSelectionExtent = nodeEx.textSelectionExtent; + nodeEx.previousScrollPosition = nodeEx.scrollPosition; + nodeEx.previousScrollExtentMax = nodeEx.scrollExtentMax; + nodeEx.previousScrollExtentMin = nodeEx.scrollExtentMin; + nodeEx.previousValue = nodeEx.value; + nodeEx.previousLabel = nodeEx.label; + // 更新当前flutter节点信息 nodeEx.isNull = false; nodeEx.id = std::move(node.id); @@ -2075,6 +2037,7 @@ void OhosAccessibilityBridge::GetSemanticsNodeDebugInfo( FML_DLOG(INFO) << "-------------------SemanticsNode------------------"; SkMatrix _transform = node.transform.asM33(); FML_DLOG(INFO) << "node.id=" << node.id; + FML_DLOG(INFO) << "node.parentId=" << node.parentId; FML_DLOG(INFO) << "node.label=" << node.label; FML_DLOG(INFO) << "node.previousLabel=" << node.previousLabel; FML_DLOG(INFO) << "node.tooltip=" << node.tooltip; @@ -2209,10 +2172,6 @@ void OhosAccessibilityBridge::GetSemanticsDebugInfo() FML_DLOG(INFO) << "g_flutterSemanticsTree -> {" << item.first << ", " << item.second.id << "}"; } - for (const auto& item : g_parentChildIdVec) { - FML_DLOG(INFO) << "g_parentChildIdVec -> (" << item.first << ", " - << item.second << ")"; - } //打印按层次遍历排序的flutter语义树节点id数组 std::vector levelOrderTraversalTree = GetLevelOrderTraversalTree(0); for (const auto& item: levelOrderTraversalTree) { diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h index 1271baddfb..42b21b14f6 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h @@ -166,11 +166,9 @@ private: static std::unique_ptr bridgeInstance_; std::shared_ptr nativeAccessibilityChannel_; std::shared_ptr accessibilityFeatures_; - + std::unordered_map g_flutterSemanticsTree; - std::vector> g_parentChildIdVec; - // std::unordered_map g_screenRectMap; - std::unordered_map g_globalTransformMap; + std::unordered_map> g_flutterSemanticsTreeXComponents; SemanticsNodeExtent inputFocusedNode; SemanticsNodeExtent lastInputFocusedNode; @@ -257,8 +255,7 @@ private: flutter::SemanticsAction ArkuiActionsToFlutterActions( ArkUI_Accessibility_ActionType arkui_action); - void BuildParentChildNodeIdRelation(const SemanticsNodeExtent& node); - void ComputeGlobalTransform(); + void ComputeGlobalTransformAndParentId(); void ConvertRectToGlobal(SemanticsNodeExtent& node); SkPoint ApplyTransform(SkPoint& point, const SkM44& transform); @@ -332,7 +329,6 @@ private: void RequestFocusWhenPageUpdate(int32_t requestFocusId); bool Contains(const std::string source, const std::string target); - std::pair GetRealScaleFactor(); void DoubleClickRouteToNewPage(SemanticsNodeExtent node); void GetSemanticsDebugInfo(); void AccessibiltiyChangesWithXComponentId(); -- Gitee From f9f4d5aa000bf1fecbe8c1c91a168af7cad0e25e Mon Sep 17 00:00:00 2001 From: zjxi Date: Wed, 5 Feb 2025 20:24:32 +0800 Subject: [PATCH 08/16] =?UTF-8?q?refactor:=E4=BC=98=E5=8C=96=E6=97=A0?= =?UTF-8?q?=E9=9A=9C=E7=A2=8D=E8=8A=82=E7=82=B9=E5=8A=A8=E4=BD=9C=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=AE=9E=E7=8E=B0=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E8=8A=82=E7=82=B9=E7=8A=B6=E6=80=81=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=86=97=E4=BD=99sort=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../ohos_accessibility_bridge.cpp | 240 +++++++----------- .../accessibility/ohos_accessibility_bridge.h | 36 +-- 2 files changed, 97 insertions(+), 179 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index 72f27ef313..bcaa5d8898 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "flutter/fml/logging.h" #include "flutter/shell/platform/ohos/ohos_logging.h" #include "flutter/shell/common/platform_view.h" @@ -100,7 +101,7 @@ void OhosAccessibilityBridge::UpdateSemantics( flutter::CustomAccessibilityActionUpdates actions) { FML_DLOG(INFO) << "OhosAccessibilityBridge::UpdateSemantics()"; - std::vector updatedFlutterNodes; + std::unordered_set updatedFlutterNodes; // 当flutter页面状态更新(路由新页面)时,自动请求root节点组件获焦(规避滑动组件更新干扰) if (isFlutterNavigated_) { @@ -112,29 +113,31 @@ void OhosAccessibilityBridge::UpdateSemantics( for (const auto& item : update) { // 获取当前更新的节点node const auto& node = item.second; - FML_DLOG(INFO) << "*#*#* node.id=" << node.id; // 更新扩展的SemanticsNode信息 auto nodeEx = UpdatetSemanticsNodeExtent(node); // 构建flutter无障碍语义节点树 g_flutterSemanticsTree[nodeEx.id] = nodeEx; - // if (!IsNodeVisible(nodeEx)) { continue; } + // print semantics node and flags info for debugging + GetSemanticsNodeDebugInfo(nodeEx); + GetSemanticsFlagsDebugInfo(nodeEx); + + if (!IsNodeVisible(nodeEx)) { continue; } - // 若当前节点为获焦 - if (IsNodeFocused(nodeEx)) { - inputFocusedNode = nodeEx; - } // 若当前节点和更新前节点信息不同,则加入更新节点数组 if (nodeEx.hadPreviousConfig) { - updatedFlutterNodes.emplace_back(nodeEx); + updatedFlutterNodes.emplace(nodeEx); FML_DLOG(INFO) << "updatedFlutterNodes -> node.id=" << nodeEx.id; } } - // calculate the global tranfomr matrix and parent id for each node + // calculate the global tranfom matrix and parent id for each node ComputeGlobalTransformAndParentId(); + Flutter_SendAccessibilityAsyncEvent( + 0, ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_CONTENT_UPDATE); + // 将更新后的flutter语义树和父子节点id映射缓存,保存到相应的xcomponent里面 g_flutterSemanticsTreeXComponents[xcomponentId_] = g_flutterSemanticsTree; @@ -142,10 +145,6 @@ void OhosAccessibilityBridge::UpdateSemantics( for (auto& nodeEx: updatedFlutterNodes) { FML_DLOG(INFO) << "*#*#* updated node.id=" << nodeEx.id; - //print semantics node and flags info for debugging - GetSemanticsNodeDebugInfo(nodeEx); - GetSemanticsFlagsDebugInfo(nodeEx); - // 当滑动节点产生滑动,并执行滑动处理 if (HasScrolled(nodeEx)) { LOGD("UpdateSemantics -> nodeId = %{public}d has scrolled", nodeEx.id); @@ -170,7 +169,7 @@ void OhosAccessibilityBridge::UpdateSemantics( _elementInfo = nullptr; } - // 判断是否触发liveRegion活动区,当前节点是否活跃 nodeEx.HasFlag(FLAGS_::kIsLiveRegion) + // 判断是否触发liveRegion活动区,当前节点是否活跃 if (nodeEx.HasFlag(FLAGS_::kIsLiveRegion) && HasChangedLabel(nodeEx)) { FML_DLOG(INFO) << "liveRegion -> page content update, nodeEx.id=" << nodeEx.id; Flutter_SendAccessibilityAsyncEvent(static_cast(nodeEx.id), @@ -178,8 +177,6 @@ void OhosAccessibilityBridge::UpdateSemantics( ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_CONTENT_UPDATE); } } - // 输出flutter语义树相关重要语义信息debug日志 - GetSemanticsDebugInfo(); FML_DLOG(INFO) << "=== UpdateSemantics() is finished ==="; } @@ -391,15 +388,7 @@ void OhosAccessibilityBridge::OnTooltip(std::unique_ptr& message) //获取根节点 SemanticsNodeExtent OhosAccessibilityBridge::GetFlutterRootSemanticsNode() { - if (!g_flutterSemanticsTree.size()) { - LOGE("GetFlutterRootSemanticsNode: g_flutterSemanticsTree.size()=0"); - return {}; - } - if (g_flutterSemanticsTree.find(0) == g_flutterSemanticsTree.end()) { - LOGE("GetFlutterRootSemanticsNod: g_flutterSemanticsTree has no root id"); - return {}; - } - return g_flutterSemanticsTree.at(0); + return GetFlutterSemanticsNode(0); } /** @@ -408,12 +397,11 @@ SemanticsNodeExtent OhosAccessibilityBridge::GetFlutterRootSemanticsNode() SemanticsNodeExtent OhosAccessibilityBridge::GetFlutterSemanticsNode( int32_t id) { - if (g_flutterSemanticsTree.count(id) > 0) { - return g_flutterSemanticsTree.at(id); - } else { - LOGE("GetFlutterSemanticsNode g_flutterSemanticsTree = null"); - return {}; + auto it = g_flutterSemanticsTree.find(id); + if (it != g_flutterSemanticsTree.end()) { + return it->second; } + return {}; } /** @@ -426,7 +414,7 @@ int32_t OhosAccessibilityBridge::GetParentId(int64_t elementId) } int32_t id = static_cast(elementId); auto node = GetFlutterSemanticsNode(id); - if (!g_flutterSemanticsTree.count(id)) { + if (g_flutterSemanticsTree.find(id) == g_flutterSemanticsTree.end()) { LOGE("GetParentId: %{public}d is null", id); return -1; } @@ -525,95 +513,78 @@ void OhosAccessibilityBridge::RelativeRectToScreenRect(SemanticsNodeExtent& node */ void OhosAccessibilityBridge::FlutterSetElementInfoOperationActions( ArkUI_AccessibilityElementInfo* elementInfoFromList, - std::string widget_type) + const SemanticsNodeExtent& node) { if (OHOS_API_VERSION < 13) { return; } auto OH_ArkUI_AccessibilityElementInfoSetOperationActions = OhosAccessibilityDDL::DLLoadSetElemOperActionsFunc(ArkUIAccessibilityConstant::ARKUI_SET_ACTIONS); CHECK_DLL_NULL_PTR(OH_ArkUI_AccessibilityElementInfoSetOperationActions); - if (OHOSUtils::Contains(widget_type, EDIT_TEXT_WIDGET_NAME) || - OHOSUtils::Contains(widget_type, EDIT_MULTILINE_TEXT_WIDGET_NAME)) { - // set elementinfo action types - int32_t actionTypeNum = 10; - ArkUI_AccessibleAction actions[actionTypeNum]; - int32_t idx = 0; - actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS; - actions[idx++].description = "获取焦点"; - actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS; - actions[idx++].description = "清除焦点"; + + int32_t actionTypeNum = 30; // declare an unreachable array length + ArkUI_AccessibleAction actions[actionTypeNum]; + size_t idx = 0; // real length of array + if (node.HasAction(ACTIONS_::kTap)) { actions[idx].actionType = ArkUI_Accessibility_ActionType:: ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLICK; - actions[idx++].description = "点击操作"; + actions[idx++].description = "click action"; + } + if (node.HasAction(ACTIONS_::kLongPress)) { actions[idx].actionType = ArkUI_Accessibility_ActionType:: ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_LONG_CLICK; - actions[idx++].description = "长按操作"; - actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_COPY; - actions[idx++].description = "文本复制"; - actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_PASTE; - actions[idx++].description = "文本粘贴"; - actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CUT; - actions[idx++].description = "文本剪切"; - actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SELECT_TEXT; - actions[idx++].description = "文本选择"; + actions[idx++].description = "longClick action"; + } + if (node.HasAction(ACTIONS_::kSetText)) { actions[idx].actionType = ArkUI_Accessibility_ActionType:: ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SET_TEXT; - actions[idx++].description = "文本内容设置"; + actions[idx++].description = "setText action"; + } + if (node.HasAction(ACTIONS_::kSetSelection)) { actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SET_CURSOR_POSITION; - actions[idx].description = "光标位置设置"; - - ARKUI_ACCESSIBILITY_CALL_CHECK( - OH_ArkUI_AccessibilityElementInfoSetOperationActions(elementInfoFromList, actionTypeNum, actions) - ); - } else if (OHOSUtils::Contains(widget_type, SCROLL_WIDGET_NAME)) { - // if node is a scrollable component - int32_t actionTypeNum = 5; - ArkUI_AccessibleAction actions[actionTypeNum]; - int32_t idx = 0; + ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SELECT_TEXT; + actions[idx++].description = "setSelection action"; + } + if (node.HasAction(ACTIONS_::kCopy)) { actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS; - actions[idx++].description = "获取焦点"; + ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_COPY; + actions[idx++].description = "copy action"; + } + if (node.HasAction(ACTIONS_::kCut)) { actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS; - actions[idx++].description = "清除焦点"; + ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CUT; + actions[idx++].description = "cut action"; + } + if (node.HasAction(ACTIONS_::kPaste)) { actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLICK; - actions[idx++].description = "点击动作"; + ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_PASTE; + actions[idx++].description = "paste action"; + } + if (node.HasAction(ACTIONS_::kScrollLeft) || + node.HasAction(ACTIONS_::kScrollUp) || + node.HasAction(ACTIONS_::kIncrease)) { actions[idx].actionType = ArkUI_Accessibility_ActionType:: ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SCROLL_FORWARD; - actions[idx++].description = "向上滑动"; + actions[idx++].description = "scrollForward action"; + } + if (node.HasAction(ACTIONS_::kScrollRight) || + node.HasAction(ACTIONS_::kScrollDown) || + node.HasAction(ACTIONS_::kDecrease)) { actions[idx].actionType = ArkUI_Accessibility_ActionType:: ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SCROLL_BACKWARD; - actions[idx].description = "向下滑动"; - - ARKUI_ACCESSIBILITY_CALL_CHECK( - OH_ArkUI_AccessibilityElementInfoSetOperationActions(elementInfoFromList, actionTypeNum, actions) - ); - } else { - // set common component action types - int32_t actionTypeNum = 3; - ArkUI_AccessibleAction actions[actionTypeNum]; - int32_t idx = 0; - actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS; - actions[idx++].description = "获取焦点"; + actions[idx++].description = "scrollBackward action"; + } + if (accessibilityFocusedNode.id != 0 && + accessibilityFocusedNode.id == node.id) { actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS; - actions[idx++].description = "清除焦点"; + ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS; + actions[idx++].description = "clearFocus action"; + } else { actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLICK; - actions[idx].description = "点击动作"; - - ARKUI_ACCESSIBILITY_CALL_CHECK( - OH_ArkUI_AccessibilityElementInfoSetOperationActions(elementInfoFromList, actionTypeNum, actions) - ); + ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS; + actions[idx++].description = "focus action"; } + ARKUI_ACCESSIBILITY_CALL_CHECK( + OH_ArkUI_AccessibilityElementInfoSetOperationActions(elementInfoFromList, idx, actions) + ); } /** @@ -665,9 +636,9 @@ void OhosAccessibilityBridge::FlutterSetElementInfoProperties( // 设置root节点的action类型 std::string widgeType = GetNodeComponentType(flutterNode); if (elementId < 1) { - FlutterSetElementInfoOperationActions(elementInfoFromList, OTHER_WIDGET_NAME); + FlutterSetElementInfoOperationActions(elementInfoFromList, flutterNode); } else { - FlutterSetElementInfoOperationActions(elementInfoFromList, widgeType); + FlutterSetElementInfoOperationActions(elementInfoFromList, flutterNode); } // 设置当前节点的父节点id @@ -710,7 +681,6 @@ void OhosAccessibilityBridge::FlutterSetElementInfoProperties( int32_t childCount = flutterNode.childrenInTraversalOrder.size(); if (childCount > 0) { auto childrenIdsVec = flutterNode.childrenInTraversalOrder; - std::sort(childrenIdsVec.begin(), childrenIdsVec.end()); int64_t childNodeIds[childCount]; for (int32_t i = 0; i < childCount; i++) { childNodeIds[i] = static_cast(childrenIdsVec[i]); @@ -912,15 +882,11 @@ std::vector OhosAccessibilityBridge::GetLevelOrderTraversalTree(int32_t uint32_t queSize = semanticsQue.size(); for (uint32_t i=0; i(currNode.id)); - - std::sort(currNode.childrenInTraversalOrder.begin(), - currNode.childrenInTraversalOrder.end()); + for (const auto& childId: currNode.childrenInTraversalOrder) { auto childNode = GetFlutterSemanticsNode(childId); - semanticsQue.push(childNode); } } @@ -1067,8 +1033,6 @@ void OhosAccessibilityBridge::PerformClickAction( << ")" << " event: click(" << clickEventType << ")"; auto flutterTapAction = ArkuiActionsToFlutterActions(action); DispatchSemanticsAction(static_cast(elementId), flutterTapAction, {}); - // double click at button-like node for pushing page update - DoubleClickRouteToNewPage(flutterNode); } /** @@ -1161,16 +1125,6 @@ void OhosAccessibilityBridge::PerformScrollUpAction( elementId, ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_SELECTED); DispatchSemanticsAction(static_cast(elementId), ACTIONS_::kIncrease, {}); } - std::string currComponetType = GetNodeComponentType(flutterNode); - if (OHOSUtils::Contains(currComponetType, SCROLL_WIDGET_NAME)) { - /** Scrolled event, sent when a scrollable component experiences a scroll event. 4096 */ - ArkUI_AccessibilityEventType scrollEventType1 = - ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_SCROLLED; - Flutter_SendAccessibilityAsyncEvent(elementId, scrollEventType1); - FML_DLOG(INFO) - << "ExecuteAccessibilityAction -> action: scroll forward(" << action - << ")" << " event: scroll forward(" << scrollEventType1 << ")"; - } } /** @@ -1195,17 +1149,6 @@ void OhosAccessibilityBridge::PerformScrollDownAction( elementId, ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_SELECTED); DispatchSemanticsAction(static_cast(elementId), ACTIONS_::kDecrease, {}); } - std::string currComponetType = GetNodeComponentType(flutterNode); - if (OHOSUtils::Contains(currComponetType, SCROLL_WIDGET_NAME)) { - /** Scrolled event, sent when a scrollable component experiences a - * scroll event. 4096 */ - ArkUI_AccessibilityEventType scrollEventType1 = - ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_SCROLLED; - Flutter_SendAccessibilityAsyncEvent(elementId, scrollEventType1); - FML_DLOG(INFO) - << "ExecuteAccessibilityAction -> action: scroll forward(" << action - << ")" << " event: scroll forward(" << scrollEventType1 << ")"; - } } /** * perform invalid action in accessibility status @@ -1969,33 +1912,22 @@ SemanticsNodeExtent OhosAccessibilityBridge::UpdatetSemanticsNodeExtent( { SemanticsNodeExtent nodeEx = SemanticsNodeExtent(); // 获取更新前的flutter节点信息 - // if (g_flutterSemanticsTree.size() > 0) { - // auto prevNode = GetFlutterSemanticsNode(node.id); - // nodeEx.hadPreviousConfig = true; - // nodeEx.previousFlags = prevNode.flags; - // nodeEx.previousActions = prevNode.actions; - // nodeEx.previousTextSelectionBase = prevNode.textSelectionBase; - // nodeEx.previousTextSelectionExtent = prevNode.textSelectionExtent; - // nodeEx.previousScrollPosition = prevNode.scrollPosition; - // nodeEx.previousScrollExtentMax = prevNode.scrollExtentMax; - // nodeEx.previousScrollExtentMin = prevNode.scrollExtentMin; - // nodeEx.previousValue = prevNode.value; - // nodeEx.previousLabel = prevNode.label; - // } - - nodeEx.hadPreviousConfig = true; - nodeEx.previousFlags = nodeEx.flags; - nodeEx.previousActions = nodeEx.actions; - nodeEx.previousTextSelectionBase = nodeEx.textSelectionBase; - nodeEx.previousTextSelectionExtent = nodeEx.textSelectionExtent; - nodeEx.previousScrollPosition = nodeEx.scrollPosition; - nodeEx.previousScrollExtentMax = nodeEx.scrollExtentMax; - nodeEx.previousScrollExtentMin = nodeEx.scrollExtentMin; - nodeEx.previousValue = nodeEx.value; - nodeEx.previousLabel = nodeEx.label; + if (!g_flutterSemanticsTree.size()) { + auto prevNode = GetFlutterSemanticsNode(node.id); + nodeEx.hadPreviousConfig = true; + nodeEx.parentId = prevNode.parentId; + nodeEx.previousFlags = prevNode.flags; + nodeEx.previousActions = prevNode.actions; + nodeEx.previousTextSelectionBase = prevNode.textSelectionBase; + nodeEx.previousTextSelectionExtent = prevNode.textSelectionExtent; + nodeEx.previousScrollPosition = prevNode.scrollPosition; + nodeEx.previousScrollExtentMax = prevNode.scrollExtentMax; + nodeEx.previousScrollExtentMin = prevNode.scrollExtentMin; + nodeEx.previousValue = prevNode.value; + nodeEx.previousLabel = prevNode.label; + } // 更新当前flutter节点信息 - nodeEx.isNull = false; nodeEx.id = std::move(node.id); nodeEx.flags = std::move(node.flags); nodeEx.actions = std::move(node.actions); diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h index 42b21b14f6..55af605de4 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h @@ -53,7 +53,6 @@ struct AbsoluteRect { }; struct SemanticsNodeExtent : flutter::SemanticsNode { - bool isNull = false; SkM44 globalTransform = SkM44{}; AbsoluteRect absoluteRect = AbsoluteRect::MakeEmpty(); int32_t parentId = -1; @@ -68,14 +67,20 @@ struct SemanticsNodeExtent : flutter::SemanticsNode { double previousScrollExtentMin = std::nan(""); std::string previousValue; std::string previousLabel; - bool HasPrevAction(SemanticsAction action) const - { + bool HasPrevAction(SemanticsAction action) const { return (previousActions & this->actions) != 0; } - bool HasPrevFlag(SemanticsFlags flag) const - { + bool HasPrevFlag(SemanticsFlags flag) const { return (previousFlags & this->flags) != 0; } + bool operator==(const SemanticsNodeExtent& other) const { + return id == other.id; + } + struct Hash { + std::size_t operator()(const SemanticsNodeExtent& obj) const { + return std::hash()(obj.id); + } + }; }; /** @@ -170,8 +175,6 @@ private: std::unordered_map g_flutterSemanticsTree; std::unordered_map> g_flutterSemanticsTreeXComponents; - SemanticsNodeExtent inputFocusedNode; - SemanticsNodeExtent lastInputFocusedNode; SemanticsNodeExtent accessibilityFocusedNode; static const int32_t OHOS_API_VERSION; @@ -200,23 +203,6 @@ private: const std::string SWITCH_WIDGET_NAME = "Toggle"; const std::string SEEKBAR_WIDGET_NAME = "SeekBar"; - const std::map - ArkUI_ACTION_TYPE_MAP_ = { - {"invalid", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_INVALID}, - {"click", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLICK}, - {"long press", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_LONG_CLICK}, - {"focus acquisition", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS}, - {"focus clearance", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS}, - {"forward scroll", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SCROLL_FORWARD}, - {"backward scroll", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SCROLL_BACKWARD}, - {"copy text", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_COPY}, - {"paste text", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_PASTE}, - {"cut text", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CUT}, - {"text selection", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SELECT_TEXT}, - {"set text", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SET_TEXT}, - {"text cursor position setting", ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SET_CURSOR_POSITION}, - }; - static const int32_t FOCUSABLE_FLAGS = static_cast(FLAGS_::kHasCheckedState) | static_cast(FLAGS_::kIsChecked) | @@ -243,7 +229,7 @@ private: int64_t elementId); void FlutterSetElementInfoOperationActions( ArkUI_AccessibilityElementInfo* elementInfoFromList, - std::string widget_type); + const SemanticsNodeExtent& node); void BuildArkUISemanticsTree( int64_t elementId, ArkUI_AccessibilityElementInfo* elementInfoFromList, -- Gitee From 5639c40a6b268f8f2ccb685d46009601b0bd15d2 Mon Sep 17 00:00:00 2001 From: zjxi Date: Sat, 8 Feb 2025 16:46:32 +0800 Subject: [PATCH 09/16] =?UTF-8?q?refactor:=E5=A2=9E=E5=8A=A0=E5=B7=B2?= =?UTF-8?q?=E5=88=A0=E9=99=A4xcomponent=E5=AE=9E=E4=BE=8B=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84flutter=E8=AF=AD=E4=B9=89=E6=A0=91=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E7=9A=84=E5=88=A0=E9=99=A4=EF=BC=8C=E5=AF=B9=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=96=B9=E6=B3=95=E7=9A=84=E5=8F=82=E6=95=B0=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BB=A5=E5=87=8F=E5=B0=91=E6=8B=B7=E8=B4=9D=E5=BC=80?= =?UTF-8?q?=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../native_accessibility_channel.cpp | 2 +- .../ohos_accessibility_bridge.cpp | 186 ++++++------------ .../accessibility/ohos_accessibility_bridge.h | 125 +++--------- .../platform/ohos/ohos_xcomponent_adapter.cpp | 2 + shell/platform/ohos/platform_view_ohos.cpp | 2 +- 5 files changed, 101 insertions(+), 216 deletions(-) diff --git a/shell/platform/ohos/accessibility/native_accessibility_channel.cpp b/shell/platform/ohos/accessibility/native_accessibility_channel.cpp index 7d571f3528..aeb65841ba 100644 --- a/shell/platform/ohos/accessibility/native_accessibility_channel.cpp +++ b/shell/platform/ohos/accessibility/native_accessibility_channel.cpp @@ -83,7 +83,7 @@ namespace flutter { flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) { - OhosAccessibilityBridge::GetInstance()->UpdateSemantics(update, actions); + OhosAccessibilityBridge::GetInstance()->UpdateSemantics(std::move(update), std::move(actions)); } /** diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index bcaa5d8898..84ee22f23d 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -114,7 +114,7 @@ void OhosAccessibilityBridge::UpdateSemantics( // 获取当前更新的节点node const auto& node = item.second; // 更新扩展的SemanticsNode信息 - auto nodeEx = UpdatetSemanticsNodeExtent(node); + auto nodeEx = UpdatetSemanticsNodeExtent(std::move(node)); // 构建flutter无障碍语义节点树 g_flutterSemanticsTree[nodeEx.id] = nodeEx; @@ -1008,23 +1008,13 @@ void OhosAccessibilityBridge::DispatchSemanticsAction( std::move(args)); } -/** - * flutter按钮节点双击跳转新页面时,发送页面更新事件 - */ -void OhosAccessibilityBridge::DoubleClickRouteToNewPage(SemanticsNodeExtent node) -{ - if (node.HasFlag(FLAGS_::kIsButton)) { - RequestFocusWhenPageUpdate(0); - } -} - /** * perform click action in accessibility status */ void OhosAccessibilityBridge::PerformClickAction( int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { /** Click event, sent after the UI component responds. 1 */ auto clickEventType = ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_CLICKED; @@ -1041,7 +1031,7 @@ void OhosAccessibilityBridge::PerformClickAction( void OhosAccessibilityBridge::PerformLongClickAction( int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { /** Long click event, sent after the UI component responds. 2 */ auto longClickEventType = ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_LONG_CLICKED; @@ -1059,7 +1049,7 @@ void OhosAccessibilityBridge::PerformLongClickAction( void OhosAccessibilityBridge::PerformGainFocusnAction( int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { // 感知获焦flutter节点 accessibilityFocusedNode = flutterNode; @@ -1088,7 +1078,7 @@ void OhosAccessibilityBridge::PerformGainFocusnAction( void OhosAccessibilityBridge::PerformClearFocusAction( int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { // 解析arkui的失焦 -> flutter对应节点的失焦 auto flutterLoseFocusAction = ArkuiActionsToFlutterActions(action); @@ -1109,7 +1099,7 @@ void OhosAccessibilityBridge::PerformClearFocusAction( void OhosAccessibilityBridge::PerformScrollUpAction( int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode) + SemanticsNodeExtent& flutterNode) { // flutter scroll forward with different situations if (flutterNode.HasAction(ACTIONS_::kScrollUp)) { @@ -1133,7 +1123,7 @@ void OhosAccessibilityBridge::PerformScrollUpAction( void OhosAccessibilityBridge::PerformScrollDownAction( int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode) + SemanticsNodeExtent& flutterNode) { // flutter scroll down with different situations if (flutterNode.HasAction(ACTIONS_::kScrollDown)) { @@ -1155,7 +1145,7 @@ void OhosAccessibilityBridge::PerformScrollDownAction( */ void OhosAccessibilityBridge::PerformClipboardAction( int64_t elementId, - ArkUI_Accessibility_ActionType action) + const ArkUI_Accessibility_ActionType& action) { if (action == ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_COPY) { FML_DLOG(INFO) << "ExecuteAccessibilityAction -> action: copy(" << action << ")"; @@ -1174,7 +1164,7 @@ void OhosAccessibilityBridge::PerformClipboardAction( void OhosAccessibilityBridge::PerformInvalidAction( int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { /** Invalid event. 0 */ ArkUI_AccessibilityEventType invalidEventType = @@ -1188,7 +1178,7 @@ void OhosAccessibilityBridge::PerformInvalidAction( * 设置输入框文本 */ void OhosAccessibilityBridge::PerformSetText( - SemanticsNodeExtent flutterNode, + SemanticsNodeExtent& flutterNode, ArkUI_Accessibility_ActionType action, ArkUI_AccessibilityActionArguments* actionArguments) { @@ -1215,7 +1205,7 @@ void OhosAccessibilityBridge::PerformSetText( * perform select text (from base to extent) in accessibility status */ void OhosAccessibilityBridge::PerformSelectText( - SemanticsNodeExtent flutterNode, + const SemanticsNodeExtent& flutterNode, ArkUI_Accessibility_ActionType action, ArkUI_AccessibilityActionArguments* actionArguments) { @@ -1278,7 +1268,7 @@ void OhosAccessibilityBridge::PerformSetCursorPosition( * perform custom action in accessibility status */ void OhosAccessibilityBridge::PerformCustomAction( - SemanticsNodeExtent flutterNode, + const SemanticsNodeExtent& flutterNode, ArkUI_Accessibility_ActionType action, ArkUI_AccessibilityActionArguments* actionArguments) { @@ -1290,7 +1280,8 @@ void OhosAccessibilityBridge::PerformCustomAction( /** * perform show on screen action in accessibility status */ -void OhosAccessibilityBridge::PerformShowOnScreenAction(SemanticsNodeExtent flutterNode) +void OhosAccessibilityBridge::PerformShowOnScreenAction( + const SemanticsNodeExtent& flutterNode) { if (!IsNodeShowOnScreen(flutterNode)) { DispatchSemanticsAction(flutterNode.id, ACTIONS_::kShowOnScreen, {}); @@ -1677,14 +1668,16 @@ std::string OhosAccessibilityBridge::GetNodeComponentType( /** * 判断当前节点是否为textfield文本框 */ -bool OhosAccessibilityBridge::IsTextField(SemanticsNodeExtent flutterNode) +bool OhosAccessibilityBridge::IsTextField( + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasFlag(FLAGS_::kIsTextField); } /** * 判断当前节点是否为滑动条slider类型 */ -bool OhosAccessibilityBridge::IsSlider(SemanticsNodeExtent flutterNode) +bool OhosAccessibilityBridge::IsSlider( + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasFlag(FLAGS_::kIsSlider); } @@ -1692,7 +1685,7 @@ bool OhosAccessibilityBridge::IsSlider(SemanticsNodeExtent flutterNode) * 判断当前flutter节点组件是否可点击 */ bool OhosAccessibilityBridge::IsNodeClickable( - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasAction(ACTIONS_::kTap); } @@ -1700,7 +1693,7 @@ bool OhosAccessibilityBridge::IsNodeClickable( * 判断当前flutter节点组件是否可显示 */ bool OhosAccessibilityBridge::IsNodeVisible( - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { return !flutterNode.HasFlag(FLAGS_::kIsHidden); } @@ -1708,7 +1701,7 @@ bool OhosAccessibilityBridge::IsNodeVisible( * 判断当前flutter节点组件是否具备checkable属性 */ bool OhosAccessibilityBridge::IsNodeCheckable( - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasFlag(FLAGS_::kHasCheckedState) || flutterNode.HasFlag(FLAGS_::kHasToggledState); @@ -1717,7 +1710,7 @@ bool OhosAccessibilityBridge::IsNodeCheckable( * 判断当前flutter节点组件是否checked/unchecked(checkbox、radio button) */ bool OhosAccessibilityBridge::IsNodeChecked( - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasFlag(FLAGS_::kIsChecked) || flutterNode.HasFlag(FLAGS_::kIsToggled); @@ -1726,7 +1719,7 @@ bool OhosAccessibilityBridge::IsNodeChecked( * 判断当前flutter节点组件是否选中 */ bool OhosAccessibilityBridge::IsNodeSelected( - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasFlag(FLAGS_::kIsSelected); } @@ -1734,7 +1727,7 @@ bool OhosAccessibilityBridge::IsNodeSelected( * 判断当前flutter节点组件是否为密码输入框 */ bool OhosAccessibilityBridge::IsNodePassword( - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasFlag(FLAGS_::kIsTextField) && flutterNode.HasFlag(FLAGS_::kIsObscured); @@ -1743,7 +1736,7 @@ bool OhosAccessibilityBridge::IsNodePassword( * 判断当前flutter节点组件是否支持长按功能 */ bool OhosAccessibilityBridge::IsNodeHasLongPress( - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasAction(ACTIONS_::kLongPress); } @@ -1751,7 +1744,7 @@ bool OhosAccessibilityBridge::IsNodeHasLongPress( * 判断当前flutter节点是否enabled */ bool OhosAccessibilityBridge::IsNodeEnabled( - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { return !flutterNode.HasFlag(FLAGS_::kHasEnabledState) || flutterNode.HasFlag(FLAGS_::kIsEnabled); @@ -1759,7 +1752,8 @@ bool OhosAccessibilityBridge::IsNodeEnabled( /** * 判断当前flutter节点是否在当前屏幕上显示 */ -bool OhosAccessibilityBridge::IsNodeShowOnScreen(SemanticsNodeExtent flutterNode) +bool OhosAccessibilityBridge::IsNodeShowOnScreen( + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasAction(ACTIONS_::kShowOnScreen); } @@ -1825,7 +1819,7 @@ bool OhosAccessibilityBridge::IsNodeFocused(const SemanticsNodeExtent& flutterNo * 判断是否可滑动 */ bool OhosAccessibilityBridge::IsNodeScrollable( - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasAction(ACTIONS_::kScrollLeft) || flutterNode.HasAction(ACTIONS_::kScrollRight) || @@ -1836,61 +1830,11 @@ bool OhosAccessibilityBridge::IsNodeScrollable( * 判断当前节点组件是否是滑动组件,如: listview, gridview等 */ bool OhosAccessibilityBridge::IsScrollableWidget( - SemanticsNodeExtent flutterNode) + const SemanticsNodeExtent& flutterNode) { return flutterNode.HasFlag(FLAGS_::kHasImplicitScrolling); } -void OhosAccessibilityBridge::AddRouteNodes( - std::vector edges, - SemanticsNodeExtent node) -{ - if (node.HasFlag(FLAGS_::kScopesRoute)) { - edges.emplace_back(node); - } - for (auto& childNodeId : node.childrenInTraversalOrder) { - auto childNode = GetFlutterSemanticsNode(childNodeId); - AddRouteNodes(edges, childNode); - } -} - -std::string OhosAccessibilityBridge::GetRouteName(SemanticsNodeExtent node) -{ - if (node.HasFlag(FLAGS_::kNamesRoute) && !node.label.empty()) { - return node.label; - } - for (auto& childNodeId : node.childrenInTraversalOrder) { - auto childNode = GetFlutterSemanticsNode(childNodeId); - std::string newName = GetRouteName(childNode); - if (!newName.empty()) { - return newName; - } - } - return ""; -} - -void OhosAccessibilityBridge::OnWindowNameChange(SemanticsNodeExtent route) -{ - std::string routeName = GetRouteName(route); - if (routeName.empty()) { - routeName = " "; - } - Flutter_SendAccessibilityAsyncEvent( - static_cast(route.id), - ArkUI_AccessibilityEventType:: - ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_CONTENT_UPDATE); -} - -void OhosAccessibilityBridge::RemoveSemanticsNode( - SemanticsNodeExtent nodeToBeRemoved) -{ - if (!g_flutterSemanticsTree.size()) { - FML_DLOG(ERROR) << "OhosAccessibilityBridge::removeSemanticsNode -> " - "g_flutterSemanticsTree.szie()=0"; - return; - } -} - /** * when the system accessibility service is shut down, * clear all the flutter semantics-relevant caches like maps, vectors @@ -1928,43 +1872,43 @@ SemanticsNodeExtent OhosAccessibilityBridge::UpdatetSemanticsNodeExtent( } // 更新当前flutter节点信息 - nodeEx.id = std::move(node.id); - nodeEx.flags = std::move(node.flags); - nodeEx.actions = std::move(node.actions); - nodeEx.maxValueLength = std::move(node.maxValueLength); - nodeEx.currentValueLength = std::move(node.currentValueLength); - nodeEx.textSelectionBase = std::move(node.textSelectionBase); - nodeEx.textSelectionExtent = std::move(node.textSelectionExtent); - nodeEx.platformViewId = std::move(node.platformViewId); - nodeEx.scrollChildren = std::move(node.scrollChildren); - nodeEx.scrollIndex = std::move(node.scrollIndex); - nodeEx.scrollPosition = std::move(node.scrollPosition); - nodeEx.scrollExtentMax = std::move(node.scrollExtentMax); - nodeEx.scrollExtentMin = std::move(node.scrollExtentMin); - nodeEx.elevation = std::move(node.elevation); - nodeEx.thickness = std::move(node.thickness); - nodeEx.label = std::move(node.label); - nodeEx.labelAttributes = std::move(node.labelAttributes); - nodeEx.hint = std::move(node.hint); - nodeEx.hintAttributes = std::move(node.hintAttributes); - nodeEx.value = std::move(node.value); - nodeEx.valueAttributes = std::move(node.valueAttributes); - nodeEx.increasedValue = std::move(node.increasedValue); - nodeEx.increasedValueAttributes = std::move(node.increasedValueAttributes); - nodeEx.decreasedValue = std::move(node.decreasedValue); - nodeEx.decreasedValueAttributes = std::move(node.decreasedValueAttributes); - nodeEx.tooltip = std::move(node.tooltip); - nodeEx.textDirection = std::move(node.textDirection); - nodeEx.rect = std::move(node.rect); - nodeEx.transform = std::move(node.transform); - nodeEx.childrenInTraversalOrder = std::move(node.childrenInTraversalOrder); - nodeEx.childrenInHitTestOrder = std::move(node.childrenInHitTestOrder); - nodeEx.customAccessibilityActions = std::move(node.customAccessibilityActions); + nodeEx.id = node.id; + nodeEx.flags = node.flags; + nodeEx.actions = node.actions; + nodeEx.maxValueLength = node.maxValueLength; + nodeEx.currentValueLength = node.currentValueLength; + nodeEx.textSelectionBase = node.textSelectionBase; + nodeEx.textSelectionExtent = node.textSelectionExtent; + nodeEx.platformViewId = node.platformViewId; + nodeEx.scrollChildren = node.scrollChildren; + nodeEx.scrollIndex = node.scrollIndex; + nodeEx.scrollPosition = node.scrollPosition; + nodeEx.scrollExtentMax = node.scrollExtentMax; + nodeEx.scrollExtentMin = node.scrollExtentMin; + nodeEx.elevation = node.elevation; + nodeEx.thickness = node.thickness; + nodeEx.label = node.label; + nodeEx.labelAttributes = node.labelAttributes; + nodeEx.hint = node.hint; + nodeEx.hintAttributes = node.hintAttributes; + nodeEx.value = node.value; + nodeEx.valueAttributes = node.valueAttributes; + nodeEx.increasedValue = node.increasedValue; + nodeEx.increasedValueAttributes = node.increasedValueAttributes; + nodeEx.decreasedValue = node.decreasedValue; + nodeEx.decreasedValueAttributes = node.decreasedValueAttributes; + nodeEx.tooltip = node.tooltip; + nodeEx.textDirection = node.textDirection; + nodeEx.rect = node.rect; + nodeEx.transform = node.transform; + nodeEx.childrenInTraversalOrder = node.childrenInTraversalOrder; + nodeEx.childrenInHitTestOrder = node.childrenInHitTestOrder; + nodeEx.customAccessibilityActions = node.customAccessibilityActions; return nodeEx; } void OhosAccessibilityBridge::GetSemanticsNodeDebugInfo( - SemanticsNodeExtent node) + const SemanticsNodeExtent& node) { FML_DLOG(INFO) << "-------------------SemanticsNode------------------"; SkMatrix _transform = node.transform.asM33(); @@ -2042,7 +1986,7 @@ void OhosAccessibilityBridge::GetSemanticsNodeDebugInfo( } void OhosAccessibilityBridge::GetSemanticsFlagsDebugInfo( - SemanticsNodeExtent node) + const SemanticsNodeExtent& node) { FML_DLOG(INFO) << "----------------SemanticsFlags-------------------------"; FML_DLOG(INFO) << "node.id=" << node.id; @@ -2083,7 +2027,7 @@ void OhosAccessibilityBridge::GetSemanticsFlagsDebugInfo( } void OhosAccessibilityBridge::GetCustomActionDebugInfo( - flutter::CustomAccessibilityAction customAccessibilityAction) + const flutter::CustomAccessibilityAction& customAccessibilityAction) { FML_DLOG(INFO) << "--------------CustomAccessibilityAction------------"; FML_DLOG(INFO) << "customAccessibilityAction.id=" diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h index 55af605de4..1df841dced 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h @@ -95,6 +95,9 @@ public: bool isFlutterNavigated_; int64_t native_shell_holder_id_; + std::unordered_map g_flutterSemanticsTree; + std::unordered_map> g_flutterSemanticsTreeXComponents; + void OnOhosAccessibilityStateChange(bool ohosAccessibilityEnabled, int64_t shellholderId); void UpdateSemantics(flutter::SemanticsNodeUpdates update, @@ -171,9 +174,6 @@ private: static std::unique_ptr bridgeInstance_; std::shared_ptr nativeAccessibilityChannel_; std::shared_ptr accessibilityFeatures_; - - std::unordered_map g_flutterSemanticsTree; - std::unordered_map> g_flutterSemanticsTreeXComponents; SemanticsNodeExtent accessibilityFocusedNode; @@ -250,127 +250,66 @@ private: bool IsNodeFocusable(const SemanticsNodeExtent& flutterNode); bool IsNodeFocused(const SemanticsNodeExtent& flutterNode); - bool IsNodeCheckable(SemanticsNodeExtent flutterNode); - bool IsNodeChecked(SemanticsNodeExtent flutterNode); - bool IsNodeSelected(SemanticsNodeExtent flutterNode); - bool IsNodeClickable(SemanticsNodeExtent flutterNode); - bool IsNodeScrollable(SemanticsNodeExtent flutterNode); - bool IsNodePassword(SemanticsNodeExtent flutterNode); - bool IsNodeVisible(SemanticsNodeExtent flutterNode); - bool IsNodeEnabled(SemanticsNodeExtent flutterNode); - bool IsNodeHasLongPress(SemanticsNodeExtent flutterNode); - bool IsNodeShowOnScreen(SemanticsNodeExtent flutterNode); - - bool IsTextField(SemanticsNodeExtent flutterNode); - bool IsSlider(SemanticsNodeExtent flutterNode); - bool IsScrollableWidget(SemanticsNodeExtent flutterNode); + bool IsNodeCheckable(const SemanticsNodeExtent& flutterNode); + bool IsNodeChecked(const SemanticsNodeExtent& flutterNode); + bool IsNodeSelected(const SemanticsNodeExtent& flutterNode); + bool IsNodeClickable(const SemanticsNodeExtent& flutterNode); + bool IsNodeScrollable(const SemanticsNodeExtent& flutterNode); + bool IsNodePassword(const SemanticsNodeExtent& flutterNode); + bool IsNodeVisible(const SemanticsNodeExtent& flutterNode); + bool IsNodeEnabled(const SemanticsNodeExtent& flutterNode); + bool IsNodeHasLongPress(const SemanticsNodeExtent& flutterNode); + bool IsNodeShowOnScreen(const SemanticsNodeExtent& flutterNode); + bool IsTextField(const SemanticsNodeExtent& flutterNode); + bool IsSlider(const SemanticsNodeExtent& flutterNode); + bool IsScrollableWidget(const SemanticsNodeExtent& flutterNode); void PerformClickAction(int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode); + const SemanticsNodeExtent& flutterNode); void PerformLongClickAction(int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode); + const SemanticsNodeExtent& flutterNode); void PerformGainFocusnAction(int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode); + const SemanticsNodeExtent& flutterNode); void PerformClearFocusAction(int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode); + const SemanticsNodeExtent& flutterNode); void PerformScrollUpAction(int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode); + SemanticsNodeExtent& flutterNode); void PerformScrollDownAction(int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode); + SemanticsNodeExtent& flutterNode); void PerformClipboardAction(int64_t elementId, - ArkUI_Accessibility_ActionType action); + const ArkUI_Accessibility_ActionType& action); void PerformInvalidAction(int64_t elementId, ArkUI_Accessibility_ActionType action, - SemanticsNodeExtent flutterNode); - void PerformSetText(SemanticsNodeExtent flutterNode, + const SemanticsNodeExtent& flutterNode); + void PerformSetText(SemanticsNodeExtent& flutterNode, ArkUI_Accessibility_ActionType action, ArkUI_AccessibilityActionArguments* actionArguments); - void PerformSelectText(SemanticsNodeExtent flutterNode, + void PerformSelectText(const SemanticsNodeExtent& flutterNode, ArkUI_Accessibility_ActionType action, ArkUI_AccessibilityActionArguments* actionArguments); void PerformSetCursorPosition(SemanticsNodeExtent flutterNode, ArkUI_Accessibility_ActionType action, ArkUI_AccessibilityActionArguments* actionArguments); - void PerformCustomAction(SemanticsNodeExtent flutterNode, + void PerformCustomAction(const SemanticsNodeExtent& flutterNode, ArkUI_Accessibility_ActionType action, ArkUI_AccessibilityActionArguments* actionArguments); - void PerformShowOnScreenAction(SemanticsNodeExtent flutterNode); - - void AddRouteNodes(std::vector edges, - SemanticsNodeExtent node); - std::string GetRouteName(SemanticsNodeExtent node); - void OnWindowNameChange(SemanticsNodeExtent route); - void RemoveSemanticsNode(SemanticsNodeExtent nodeToBeRemoved); + void PerformShowOnScreenAction(const SemanticsNodeExtent& flutterNode); - void GetSemanticsNodeDebugInfo(SemanticsNodeExtent node); - void GetSemanticsFlagsDebugInfo(SemanticsNodeExtent node); + void GetSemanticsNodeDebugInfo(const SemanticsNodeExtent& node); + void GetSemanticsFlagsDebugInfo(const SemanticsNodeExtent& node); void GetCustomActionDebugInfo( - flutter::CustomAccessibilityAction customAccessibilityAction); + const flutter::CustomAccessibilityAction& customAccessibilityAction); void RequestFocusWhenPageUpdate(int32_t requestFocusId); - bool Contains(const std::string source, const std::string target); - void DoubleClickRouteToNewPage(SemanticsNodeExtent node); void GetSemanticsDebugInfo(); void AccessibiltiyChangesWithXComponentId(); -}; - -enum class AccessibilityAction : int32_t { - kTap = 1 << 0, - kLongPress = 1 << 1, - kScrollLeft = 1 << 2, - kScrollRight = 1 << 3, - kScrollUp = 1 << 4, - kScrollDown = 1 << 5, - kIncrease = 1 << 6, - kDecrease = 1 << 7, - kShowOnScreen = 1 << 8, - kMoveCursorForwardByCharacter = 1 << 9, - kMoveCursorBackwardByCharacter = 1 << 10, - kSetSelection = 1 << 11, - kCopy = 1 << 12, - kCut = 1 << 13, - kPaste = 1 << 14, - kDidGainAccessibilityFocus = 1 << 15, - kDidLoseAccessibilityFocus = 1 << 16, - kCustomAction = 1 << 17, - kDismiss = 1 << 18, - kMoveCursorForwardByWord = 1 << 19, - kMoveCursorBackwardByWord = 1 << 20, - kSetText = 1 << 21, -}; -enum class AccessibilityFlags : int32_t { - kHasCheckedState = 1 << 0, - kIsChecked = 1 << 1, - kIsSelected = 1 << 2, - kIsButton = 1 << 3, - kIsTextField = 1 << 4, - kIsFocused = 1 << 5, - kHasEnabledState = 1 << 6, - kIsEnabled = 1 << 7, - kIsInMutuallyExclusiveGroup = 1 << 8, - kIsHeader = 1 << 9, - kIsObscured = 1 << 10, - kScopesRoute = 1 << 11, - kNamesRoute = 1 << 12, - kIsHidden = 1 << 13, - kIsImage = 1 << 14, - kIsLiveRegion = 1 << 15, - kHasToggledState = 1 << 16, - kIsToggled = 1 << 17, - kHasImplicitScrolling = 1 << 18, - kIsMultiline = 1 << 19, - kIsReadOnly = 1 << 20, - kIsFocusable = 1 << 21, - kIsLink = 1 << 22, - kIsSlider = 1 << 23, - kIsKeyboardKey = 1 << 24, - kIsCheckStateMixed = 1 << 25, + void GetFlutterSemanticsTreeWithInstance(const char* instanceId); }; } // namespace flutter diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 9a0416e488..3ef8a70045 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -203,6 +203,8 @@ void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) { it->second->OnSurfaceDestroyed(component, window); delete it->second; it = XComponentAdapter::GetInstance()->xcomponetMap_.erase(it); + // delete the semantics tree of the destroyed xcomponent + OhosAccessibilityBridge::GetInstance()->g_flutterSemanticsTreeXComponents.erase(it->first); } else { ++it; } diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index 28c626a4f2..242a8a78e9 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -300,7 +300,7 @@ void PlatformViewOHOS::UpdateSemantics( flutter::CustomAccessibilityActionUpdates actions) { FML_DLOG(INFO) << "PlatformViewOHOS::UpdateSemantics()"; auto nativeAccessibilityChannel_ = std::make_shared(); - nativeAccessibilityChannel_->UpdateSemantics(update, actions); + nativeAccessibilityChannel_->UpdateSemantics(std::move(update), std::move(actions)); } // |PlatformView| -- Gitee From 9fc1f49b5182fd6d339d0c939d9dc060c5b7d43e Mon Sep 17 00:00:00 2001 From: zjxi Date: Tue, 7 Jan 2025 15:02:36 +0800 Subject: [PATCH 10/16] =?UTF-8?q?fix:=E6=97=A0=E9=9A=9C=E7=A2=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9Axcomponent=E5=9C=BA=E6=99=AF=EF=BC=8C?= =?UTF-8?q?=E4=BD=86=E4=BC=9A=E5=81=B6=E7=8E=B0=E9=87=8E=E6=8C=87=E9=92=88?= =?UTF-8?q?=E9=97=AA=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../ohos_accessibility_bridge.cpp | 4 +++ .../accessibility/ohos_accessibility_bridge.h | 7 +++++ .../src/main/cpp/types/libflutter/index.d.ets | 4 ++- .../main/ets/embedding/ohos/FlutterPage.ets | 30 +++++++++++++++++-- shell/platform/ohos/library_loader.cpp | 3 ++ .../ohos/napi/platform_view_ohos_napi.cpp | 19 ++++++++++++ .../ohos/napi/platform_view_ohos_napi.h | 4 +++ .../platform/ohos/ohos_xcomponent_adapter.cpp | 6 ++++ shell/platform/ohos/ohos_xcomponent_adapter.h | 3 +- 9 files changed, 74 insertions(+), 6 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index 84ee22f23d..0facf81ad3 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -941,6 +941,8 @@ int32_t OhosAccessibilityBridge::FindAccessibilityNodeInfosById( << elementId << " mode=" << mode; CHECK_NULL_PTR_WITH_RET(elementList, FindAccessibilityNodeInfosById); + AccessibiltiyChangesWithXComponentId(); + if (g_flutterSemanticsTree.size() == 0) { FML_DLOG(INFO) << "FindAccessibilityNodeInfosById g_flutterSemanticsTree is null"; @@ -1301,6 +1303,8 @@ int32_t OhosAccessibilityBridge::ExecuteAccessibilityAction( << elementId << " action=" << action; CHECK_NULL_PTR_WITH_RET(actionArguments, ExecuteAccessibilityAction); + AccessibiltiyChangesWithXComponentId(); + // 获取当前elementid对应的flutter语义节点 auto flutterNode = GetFlutterSemanticsNode(static_cast(elementId)); if (!g_flutterSemanticsTree.count(flutterNode.id)) { diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h index 1df841dced..59bba3a7bc 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h @@ -92,6 +92,7 @@ public: OhosAccessibilityBridge(const OhosAccessibilityBridge&) = delete; OhosAccessibilityBridge& operator=(const OhosAccessibilityBridge&) = delete; + std::string xcomponentId_; bool isFlutterNavigated_; int64_t native_shell_holder_id_; @@ -175,6 +176,12 @@ private: std::shared_ptr nativeAccessibilityChannel_; std::shared_ptr accessibilityFeatures_; + std::unordered_map g_flutterSemanticsTree; + std::vector> g_parentChildIdVec; + std::unordered_map g_screenRectMap; + + SemanticsNodeExtent inputFocusedNode; + SemanticsNodeExtent lastInputFocusedNode; SemanticsNodeExtent accessibilityFocusedNode; static const int32_t OHOS_API_VERSION; diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets index 279c97baa1..a683639641 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets @@ -175,4 +175,6 @@ export const nativeUnicodeIsEmojiModifierBase: (code: number) => number; export const nativeUnicodeIsVariationSelector: (code: number) => number; -export const nativeUnicodeIsRegionalIndicatorSymbol: (code: number) => number; \ No newline at end of file +export const nativeUnicodeIsRegionalIndicatorSymbol: (code: number) => number; + +export const nativeGetXComponentId: (id: string) => number; \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 533e1e6a51..64497b3d8c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -17,7 +17,7 @@ import Log from '../../util/Log'; import { FlutterView } from '../../view/FlutterView'; import FlutterManager from './FlutterManager'; import { DVModel, DVModelChildren, DynamicView } from '../../view/DynamicView/dynamicView'; - +import flutter from 'libflutter.so'; const TAG = "FlutterPage"; export const OHOS_FLUTTER_PAGE_UPDATE = "ohos_flutter_page_update"; @@ -56,7 +56,19 @@ export struct FlutterPage { .onLoad((context) => { this.flutterView?.onSurfaceCreated() Log.d(TAG, "XComponent onLoad "); - this.flutterView?.onAccessibilityIsOpen() + // 当xcomponent窗口部分显示或完全隐藏时触发回调 + this.getUIContext()?.getAttachedFrameNodeById(this.viewId)?.commonEvent.setOnVisibleAreaApproximateChange( + { ratios: [0.0, 1.0], expectedUpdateInterval: 0 }, + (ratioInc: boolean, ratio: number) => { + if (ratioInc) { + Log.i(TAG, "setOnVisibleAreaApproximateChange -> xcomponentId: " + this.viewId + + " ratioInc: " + ratioInc + " ratio: " + ratio); + flutter.nativeGetXComponentId(this.viewId); + // 保证获取xcomponentid之后再使用无障碍 + this.flutterView?.onAccessibilityIsOpen(); + } + } + ) }) .onDestroy(() => { Log.d(TAG, "XComponent onDestroy "); @@ -136,7 +148,19 @@ export struct FlutterPage { .onLoad((context) => { this.flutterView?.onSurfaceCreated() Log.d(TAG, "XComponent onLoad "); - this.flutterView?.onAccessibilityIsOpen() + // 当xcomponent窗口部分显示或完全隐藏时触发回调 + this.getUIContext()?.getAttachedFrameNodeById(this.viewId)?.commonEvent.setOnVisibleAreaApproximateChange( + { ratios: [0.0, 1.0], expectedUpdateInterval: 0 }, + (ratioInc: boolean, ratio: number) => { + if (ratioInc) { + Log.i(TAG, "setOnVisibleAreaApproximateChange -> xcomponentId: " + this.viewId + + " ratioInc: " + ratioInc + " ratio: " + ratio); + flutter.nativeGetXComponentId(this.viewId); + // 保证获取xcomponentid之后再使用无障碍 + this.flutterView?.onAccessibilityIsOpen(); + } + } + ) }) .onDestroy(() => { Log.d(TAG, "XComponent onDestroy "); diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index 7b2c7da1c0..91ceec8956 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -190,6 +190,9 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_FUNCTION( "nativeUnicodeIsRegionalIndicatorSymbol", flutter::PlatformViewOHOSNapi::nativeUnicodeIsRegionalIndicatorSymbol), + DECLARE_NAPI_FUNCTION( + "nativeGetXComponentId", + flutter::PlatformViewOHOSNapi::nativeGetXComponentId), }; FML_DLOG(INFO) << "Init NAPI size=" << sizeof(desc) / sizeof(desc[0]); diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index d1bf9ed472..78f4cc842f 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -2277,4 +2277,23 @@ napi_value PlatformViewOHOSNapi::nativeUnicodeIsRegionalIndicatorSymbol(napi_env napi_create_int32(env, (int)is_emoji, &result); return result; } + +napi_value PlatformViewOHOSNapi::nativeGetXComponentId(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + std::string xcomponentId; + bool ret = fml::napi::GetString(env, args[0], xcomponentId); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "nativeGetXComponentId xcomponentId: " << xcomponentId; + return nullptr; + } + // obtain the current visible xcomponent id from the ets callback event + XComponentAdapter::GetInstance()->currentXComponentId_ = xcomponentId; + FML_DLOG(ERROR) << "nativeGetXComponentId -> xcomponentId: " << xcomponentId; + return nullptr; +} + } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 013557aeae..84ea45af1e 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -269,6 +269,10 @@ class PlatformViewOHOSNapi { napi_env env, napi_callback_info info); + static napi_value nativeGetXComponentId( + napi_env env, + napi_callback_info info); + private: static napi_env env_; napi_ref ref_napi_obj_; diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 3ef8a70045..7e13c1e4e3 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -99,6 +99,10 @@ void XComponentAdapter::AttachFlutterEngine(std::string& id, auto findIter = xcomponetMap_.find(id); if (findIter != xcomponetMap_.end()) { findIter->second->AttachFlutterEngine(shellholderId); + // register the OH_ArkUI accessibility callbacks + if (OH_GetSdkApiVersion() >= 13) { + findIter->second->RegisterArkUIAccessibilityService(findIter->second->nativeXComponent_, shellholderId); + } } } @@ -202,6 +206,8 @@ void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) { if(it->second->nativeXComponent_ == component) { it->second->OnSurfaceDestroyed(component, window); delete it->second; + // 将当前要销毁的xcomponent对应的无障碍provider指针置nullptr + it->second->accessibilityProvider_ = nullptr; it = XComponentAdapter::GetInstance()->xcomponetMap_.erase(it); // delete the semantics tree of the destroyed xcomponent OhosAccessibilityBridge::GetInstance()->g_flutterSemanticsTreeXComponents.erase(it->first); diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index e98ba03f9a..632e9d216d 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -69,7 +69,6 @@ public: uint64_t height_; OhosTouchProcessor ohosTouchProcessor_; ArkUI_AccessibilityProvider* accessibilityProvider_; - }; class XComponentAdapter { @@ -88,7 +87,7 @@ class XComponentAdapter { public: std::map xcomponetMap_; - ArkUI_AccessibilityProvider* accessibilityProvider_; + std::string currentXComponentId_; std::mutex mutex_; private: -- Gitee From c28bbeee97eae4aeb3f5161eb10823e878c3132c Mon Sep 17 00:00:00 2001 From: zjxi Date: Tue, 18 Feb 2025 11:54:25 +0800 Subject: [PATCH 11/16] fix:add touchGuideStateChange lister to avoid long screenshot with the appearance of green rect Signed-off-by: zjxi --- .../ohos_accessibility_bridge.cpp | 94 +++++++++++-------- .../accessibility/ohos_accessibility_bridge.h | 8 +- .../src/main/cpp/types/libflutter/index.d.ets | 6 +- .../main/ets/embedding/engine/FlutterNapi.ets | 5 + .../main/ets/embedding/ohos/FlutterPage.ets | 2 + .../flutter/src/main/ets/view/FlutterView.ets | 17 ++++ shell/platform/ohos/library_loader.cpp | 3 + .../ohos/napi/platform_view_ohos_napi.cpp | 19 +++- .../ohos/napi/platform_view_ohos_napi.h | 4 + .../platform/ohos/ohos_xcomponent_adapter.cpp | 4 - 10 files changed, 110 insertions(+), 52 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index 0facf81ad3..0f38dbd30e 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -30,6 +30,25 @@ const int32_t OhosAccessibilityBridge::OHOS_API_VERSION = OH_GetSdkApiVersion(); std::unique_ptr OhosAccessibilityBridge::bridgeInstance_ = nullptr; +/** + * 采用局部静态变量配合call-once特性,实现线程安全的单例模式 + */ +OhosAccessibilityBridge* OhosAccessibilityBridge::GetInstance() +{ + static std::once_flag onceFlag; + std::call_once(onceFlag, []() { + bridgeInstance_.reset(new OhosAccessibilityBridge()); + }); + return bridgeInstance_.get(); +} + +OhosAccessibilityBridge::OhosAccessibilityBridge() +: xcomponentId_("oh_flutter_1"), + native_shell_holder_id_(0), + isFlutterNavigated_(false), + isTouchGuideOn_(false), + isAccessibilityEnabled_(false) {} + /** * flutter无障碍相关语义树、句柄指针provider等参数 * 跟随xcomponentid显示切换,而加载对应xcomponent的语义树和provider指针 @@ -40,7 +59,10 @@ void OhosAccessibilityBridge::AccessibiltiyChangesWithXComponentId() auto xcompMap = XComponentAdapter::GetInstance()->xcomponetMap_; // 获取当前显示的xcomponetid std::string currXcompId = XComponentAdapter::GetInstance()->currentXComponentId_; - if (xcomponentId_ == currXcompId) { return; } + if (xcomponentId_ == currXcompId) { + xcomponentId_ = currXcompId; + return; + } auto it = xcompMap.find(currXcompId); if (!xcompMap.empty() && it != xcompMap.end()) { @@ -56,22 +78,6 @@ void OhosAccessibilityBridge::AccessibiltiyChangesWithXComponentId() } } -/** - * 采用局部静态变量配合call-once特性,实现线程安全的单例模式 - */ -OhosAccessibilityBridge* OhosAccessibilityBridge::GetInstance() -{ - static std::once_flag onceFlag; - std::call_once(onceFlag, []() { - bridgeInstance_.reset(new OhosAccessibilityBridge()); - }); - return bridgeInstance_.get(); -} - -OhosAccessibilityBridge::OhosAccessibilityBridge() - : isFlutterNavigated_(false), - isAccessibilityEnabled_(false) {} - /** * 监听当前ohos平台是否开启无障碍屏幕朗读服务 */ @@ -102,8 +108,10 @@ void OhosAccessibilityBridge::UpdateSemantics( { FML_DLOG(INFO) << "OhosAccessibilityBridge::UpdateSemantics()"; std::unordered_set updatedFlutterNodes; + AccessibiltiyChangesWithXComponentId(); - // 当flutter页面状态更新(路由新页面)时,自动请求root节点组件获焦(规避滑动组件更新干扰) + // request rootNode when routes a new flutter page + // on touch guide mode (screen reader is on) if (isFlutterNavigated_) { RequestFocusWhenPageUpdate(0); isFlutterNavigated_ = false; @@ -119,10 +127,6 @@ void OhosAccessibilityBridge::UpdateSemantics( // 构建flutter无障碍语义节点树 g_flutterSemanticsTree[nodeEx.id] = nodeEx; - // print semantics node and flags info for debugging - GetSemanticsNodeDebugInfo(nodeEx); - GetSemanticsFlagsDebugInfo(nodeEx); - if (!IsNodeVisible(nodeEx)) { continue; } // 若当前节点和更新前节点信息不同,则加入更新节点数组 @@ -131,7 +135,6 @@ void OhosAccessibilityBridge::UpdateSemantics( FML_DLOG(INFO) << "updatedFlutterNodes -> node.id=" << nodeEx.id; } } - // calculate the global tranfom matrix and parent id for each node ComputeGlobalTransformAndParentId(); @@ -140,6 +143,13 @@ void OhosAccessibilityBridge::UpdateSemantics( // 将更新后的flutter语义树和父子节点id映射缓存,保存到相应的xcomponent里面 g_flutterSemanticsTreeXComponents[xcomponentId_] = g_flutterSemanticsTree; + + // if the screen reader starts (touch guide state is true), + // sending the a11y event and draw the green rect + if (1) { + Flutter_SendAccessibilityAsyncEvent( + 0, ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_CONTENT_UPDATE); + } /* 针对更新后的节点进行事件处理 */ for (auto& nodeEx: updatedFlutterNodes) { @@ -158,9 +168,11 @@ void OhosAccessibilityBridge::UpdateSemantics( FlutterScrollExecution(nodeEx, _elementInfo); // 屏幕朗读状态下双指滑动,获焦节点绿框实时跟随节点滑动 - Flutter_SendAccessibilityAsyncEvent( - static_cast(accessibilityFocusedNode.id), - ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_FOCUS_NODE_UPDATE); + if (1) { + Flutter_SendAccessibilityAsyncEvent( + static_cast(accessibilityFocusedNode.id), + ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_FOCUS_NODE_UPDATE); + } auto OH_ArkUI_DestoryAccessibilityElementInfo = OhosAccessibilityDDL::DLLoadDestroyElemFunc(ArkUIAccessibilityConstant::ARKUI_DESTORY_NODE); @@ -170,7 +182,7 @@ void OhosAccessibilityBridge::UpdateSemantics( } // 判断是否触发liveRegion活动区,当前节点是否活跃 - if (nodeEx.HasFlag(FLAGS_::kIsLiveRegion) && HasChangedLabel(nodeEx)) { + if (nodeEx.HasFlag(FLAGS_::kIsLiveRegion) && HasChangedLabel(nodeEx) && isTouchGuideOn_) { FML_DLOG(INFO) << "liveRegion -> page content update, nodeEx.id=" << nodeEx.id; Flutter_SendAccessibilityAsyncEvent(static_cast(nodeEx.id), ArkUI_AccessibilityEventType:: @@ -572,16 +584,22 @@ void OhosAccessibilityBridge::FlutterSetElementInfoOperationActions( ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SCROLL_BACKWARD; actions[idx++].description = "scrollBackward action"; } - if (accessibilityFocusedNode.id != 0 && - accessibilityFocusedNode.id == node.id) { - actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS; - actions[idx++].description = "clearFocus action"; - } else { - actions[idx].actionType = ArkUI_Accessibility_ActionType:: + // if (accessibilityFocusedNode.id != 0 && + // accessibilityFocusedNode.id == node.id) { + // actions[idx].actionType = ArkUI_Accessibility_ActionType:: + // ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS; + // actions[idx++].description = "clearFocus action"; + // } else { + // actions[idx].actionType = ArkUI_Accessibility_ActionType:: + // ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS; + // actions[idx++].description = "focus action"; + // } + actions[idx].actionType = ArkUI_Accessibility_ActionType:: ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS; - actions[idx++].description = "focus action"; - } + actions[idx++].description = "focus action"; + actions[idx].actionType = ArkUI_Accessibility_ActionType:: + ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS; + actions[idx++].description = "clearFocus action"; ARKUI_ACCESSIBILITY_CALL_CHECK( OH_ArkUI_AccessibilityElementInfoSetOperationActions(elementInfoFromList, idx, actions) ); @@ -1799,10 +1817,6 @@ bool OhosAccessibilityBridge::IsNodeFocusable( if (node.IsPlatformViewNode()) { return true; } - // Always consider actionable nodes focusable. - if (node.actions != 0) { - return true; - } if ((node.flags & FOCUSABLE_FLAGS) != 0) { return true; } diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h index 59bba3a7bc..0dde97c7c1 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h @@ -93,8 +93,9 @@ public: OhosAccessibilityBridge& operator=(const OhosAccessibilityBridge&) = delete; std::string xcomponentId_; - bool isFlutterNavigated_; int64_t native_shell_holder_id_; + bool isFlutterNavigated_; + bool isTouchGuideOn_; std::unordered_map g_flutterSemanticsTree; std::unordered_map> g_flutterSemanticsTreeXComponents; @@ -176,10 +177,6 @@ private: std::shared_ptr nativeAccessibilityChannel_; std::shared_ptr accessibilityFeatures_; - std::unordered_map g_flutterSemanticsTree; - std::vector> g_parentChildIdVec; - std::unordered_map g_screenRectMap; - SemanticsNodeExtent inputFocusedNode; SemanticsNodeExtent lastInputFocusedNode; SemanticsNodeExtent accessibilityFocusedNode; @@ -316,7 +313,6 @@ private: void RequestFocusWhenPageUpdate(int32_t requestFocusId); void GetSemanticsDebugInfo(); void AccessibiltiyChangesWithXComponentId(); - void GetFlutterSemanticsTreeWithInstance(const char* instanceId); }; } // namespace flutter diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets index a683639641..4185733a25 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets @@ -177,4 +177,8 @@ export const nativeUnicodeIsVariationSelector: (code: number) => number; export const nativeUnicodeIsRegionalIndicatorSymbol: (code: number) => number; -export const nativeGetXComponentId: (id: string) => number; \ No newline at end of file +export const nativeGetXComponentId: (id: string) => number; + +export const nativeSetDVsyncSwitch: (nativeShellHolderId: number, isEnable: boolean) => void; + +export const nativeTouchGuideStateChange: (state: Boolean) => void; diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets index e36a566682..b9f5cb3398 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets @@ -391,6 +391,11 @@ export default class FlutterNapi { flutter.nativeAccessibilityStateChange(this.nativeShellHolderId!, state); } + touchGuideStateChange(state: Boolean): void { + this.ensureRunningOnMainThread(); + flutter.nativeTouchGuideStateChange(state); + } + setLocalizationPlugin(localizationPlugin: LocalizationPlugin | null): void { this.localizationPlugin = localizationPlugin; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 64497b3d8c..ead59a58d1 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -65,6 +65,7 @@ export struct FlutterPage { " ratioInc: " + ratioInc + " ratio: " + ratio); flutter.nativeGetXComponentId(this.viewId); // 保证获取xcomponentid之后再使用无障碍 + this.flutterView?.onTouchGuideIsOpen(); this.flutterView?.onAccessibilityIsOpen(); } } @@ -157,6 +158,7 @@ export struct FlutterPage { " ratioInc: " + ratioInc + " ratio: " + ratio); flutter.nativeGetXComponentId(this.viewId); // 保证获取xcomponentid之后再使用无障碍 + this.flutterView?.onTouchGuideIsOpen(); this.flutterView?.onAccessibilityIsOpen(); } } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets index c38327f4fb..11d7a00833 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets @@ -214,6 +214,12 @@ export class FlutterView { this.mainWindow?.on('avoidAreaChange', this.avoidAreaChangeCallback); this.mainWindow?.on('windowStatusChange', this.windowStatusChangeCallback); + // listen the touchGuideStateChange, when screen reader is on that + // the callback data of this lister event is true + accessibility.on('touchGuideStateChange', (data: boolean) => { + this.flutterEngine?.getFlutterNapi()?.touchGuideStateChange(data); + console.info(`subscribe touch guide state change, result: ${JSON.stringify(data)}`); + }); //监听系统无障碍服务状态改变 accessibility.on('accessibilityStateChange', (data: boolean) => { Log.i(TAG, `subscribe accessibility state change, result: ${JSON.stringify(data)}`); @@ -377,6 +383,9 @@ export class FlutterView { this.mainWindow?.off('windowSizeChange', this.windowSizeChangeCallback); this.mainWindow?.off('avoidAreaChange', this.avoidAreaChangeCallback); this.mainWindow?.off('windowStatusChange', this.windowStatusChangeCallback); + accessibility.off('touchGuideStateChange', (data: boolean) => { + Log.i(TAG, `subscribe touch guide state change, result: ${JSON.stringify(data)}`); + }); accessibility.off('accessibilityStateChange', (data: boolean) => { Log.i(TAG, `unsubscribe accessibility state change, result: ${JSON.stringify(data)}`); }); @@ -500,6 +509,14 @@ export class FlutterView { Log.i(TAG, `accessibility isOpen state -> ${JSON.stringify(accessibilityState)}`); } + onTouchGuideIsOpen() { + let touchGuideState: boolean = accessibility.isOpenTouchGuideSync(); + if(touchGuideState) { + this.flutterEngine?.getFlutterNapi()?.touchGuideStateChange(touchGuideState) + } + Log.i(TAG, `Touch Guide isOpen state -> ${JSON.stringify(touchGuideState)}`); + } + onAreaChange(newArea: Area | null, setFullScreen: boolean = false) { const originalMetrics = this.viewportMetrics.clone(); diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index 91ceec8956..ac5020abfa 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -193,6 +193,9 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_FUNCTION( "nativeGetXComponentId", flutter::PlatformViewOHOSNapi::nativeGetXComponentId), + DECLARE_NAPI_FUNCTION( + "nativeTouchGuideStateChange", + flutter::PlatformViewOHOSNapi::NativeTouchGuideStateChange), }; FML_DLOG(INFO) << "Init NAPI size=" << sizeof(desc) / sizeof(desc[0]); diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 78f4cc842f..ceec4e6893 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -2292,8 +2292,25 @@ napi_value PlatformViewOHOSNapi::nativeGetXComponentId(napi_env env, napi_callba } // obtain the current visible xcomponent id from the ets callback event XComponentAdapter::GetInstance()->currentXComponentId_ = xcomponentId; - FML_DLOG(ERROR) << "nativeGetXComponentId -> xcomponentId: " << xcomponentId; + FML_DLOG(INFO) << "nativeGetXComponentId -> xcomponentId: " << xcomponentId; return nullptr; } +napi_value PlatformViewOHOSNapi::NativeTouchGuideStateChange(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + bool touchGuideState = false; + bool ret = napi_get_value_bool(env, args[0], &touchGuideState); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "NativeTouchGuideStateChange touchGuideState: " << touchGuideState; + return nullptr; + } + + OhosAccessibilityBridge::GetInstance()->isTouchGuideOn_ = touchGuideState; + FML_DLOG(INFO) << "NativeTouchGuideStateChange -> touchGuideState: " << touchGuideState; + return nullptr; +} } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 84ea45af1e..9fd5394e80 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -273,6 +273,10 @@ class PlatformViewOHOSNapi { napi_env env, napi_callback_info info); + static napi_value NativeTouchGuideStateChange( + napi_env env, + napi_callback_info info); + private: static napi_env env_; napi_ref ref_napi_obj_; diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 7e13c1e4e3..6193b2df6f 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -99,10 +99,6 @@ void XComponentAdapter::AttachFlutterEngine(std::string& id, auto findIter = xcomponetMap_.find(id); if (findIter != xcomponetMap_.end()) { findIter->second->AttachFlutterEngine(shellholderId); - // register the OH_ArkUI accessibility callbacks - if (OH_GetSdkApiVersion() >= 13) { - findIter->second->RegisterArkUIAccessibilityService(findIter->second->nativeXComponent_, shellholderId); - } } } -- Gitee From e70f4a2c81d089bf7fe33038251f27fb7f607d97 Mon Sep 17 00:00:00 2001 From: zjxi Date: Thu, 20 Feb 2025 16:57:53 +0800 Subject: [PATCH 12/16] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E9=9D=9E=E8=A7=A6?= =?UTF-8?q?=E6=91=B8=E6=A8=A1=E6=80=81=E4=B8=8B=E9=95=BF=E6=88=AA=E5=B1=8F?= =?UTF-8?q?=E3=80=81=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B5=8B=E8=AF=95=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E7=BB=BF=E6=A1=86=E7=8E=B0=E8=B1=A1;=20=E5=87=8F?= =?UTF-8?q?=E5=B0=91=E6=97=A0=E9=9A=9C=E7=A2=8D=E5=B1=82=E6=AC=A1=E9=81=8D?= =?UTF-8?q?=E5=8E=86=E5=86=97=E4=BD=99=E9=81=8D=E5=8E=86=20Signed-off-by:?= =?UTF-8?q?=20zjxi=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ohos_accessibility_bridge.cpp | 57 ++++++------------- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index 0f38dbd30e..48437826b3 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -146,10 +146,9 @@ void OhosAccessibilityBridge::UpdateSemantics( // if the screen reader starts (touch guide state is true), // sending the a11y event and draw the green rect - if (1) { - Flutter_SendAccessibilityAsyncEvent( - 0, ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_CONTENT_UPDATE); - } + Flutter_SendAccessibilityAsyncEvent( + 0, ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_PAGE_CONTENT_UPDATE); + /* 针对更新后的节点进行事件处理 */ for (auto& nodeEx: updatedFlutterNodes) { @@ -167,8 +166,8 @@ void OhosAccessibilityBridge::UpdateSemantics( // flutter滑动组件滑动处理逻辑 FlutterScrollExecution(nodeEx, _elementInfo); - // 屏幕朗读状态下双指滑动,获焦节点绿框实时跟随节点滑动 - if (1) { + // when screen reader is on and the touch guide is active + if (isTouchGuideOn_) { Flutter_SendAccessibilityAsyncEvent( static_cast(accessibilityFocusedNode.id), ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_FOCUS_NODE_UPDATE); @@ -182,7 +181,7 @@ void OhosAccessibilityBridge::UpdateSemantics( } // 判断是否触发liveRegion活动区,当前节点是否活跃 - if (nodeEx.HasFlag(FLAGS_::kIsLiveRegion) && HasChangedLabel(nodeEx) && isTouchGuideOn_) { + if (nodeEx.HasFlag(FLAGS_::kIsLiveRegion) && HasChangedLabel(nodeEx)) { FML_DLOG(INFO) << "liveRegion -> page content update, nodeEx.id=" << nodeEx.id; Flutter_SendAccessibilityAsyncEvent(static_cast(nodeEx.id), ArkUI_AccessibilityEventType:: @@ -223,13 +222,6 @@ void OhosAccessibilityBridge::FlutterScrollExecution( nodePosition -= node.scrollExtentMin; } - if (node.HasAction(ACTIONS_::kScrollUp) || - node.HasAction(ACTIONS_::kScrollDown)) { - } else if (node.HasAction(ACTIONS_::kScrollLeft) || - node.HasAction(ACTIONS_::kScrollRight)) { - LOGD("current flutterNode has scroll up/down/left/right"); - } - // 当可滑动组件存在滑动子节点 if (node.scrollChildren > 0) { // 配置当前滑动组件的子节点总数 @@ -495,7 +487,6 @@ SkPoint OhosAccessibilityBridge::ApplyTransform( void OhosAccessibilityBridge::RelativeRectToScreenRect(SemanticsNodeExtent& node) { auto [left, top, right, bottom] = node.rect; - // SkM44 globalTransform = g_globalTransformMap[node.id]; SkM44 globalTransform = node.globalTransform; SkPoint points[4] = { @@ -584,22 +575,13 @@ void OhosAccessibilityBridge::FlutterSetElementInfoOperationActions( ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_SCROLL_BACKWARD; actions[idx++].description = "scrollBackward action"; } - // if (accessibilityFocusedNode.id != 0 && - // accessibilityFocusedNode.id == node.id) { - // actions[idx].actionType = ArkUI_Accessibility_ActionType:: - // ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS; - // actions[idx++].description = "clearFocus action"; - // } else { - // actions[idx].actionType = ArkUI_Accessibility_ActionType:: - // ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS; - // actions[idx++].description = "focus action"; - // } actions[idx].actionType = ArkUI_Accessibility_ActionType:: - ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS; + ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS; actions[idx++].description = "focus action"; actions[idx].actionType = ArkUI_Accessibility_ActionType:: ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS; actions[idx++].description = "clearFocus action"; + ARKUI_ACCESSIBILITY_CALL_CHECK( OH_ArkUI_AccessibilityElementInfoSetOperationActions(elementInfoFromList, idx, actions) ); @@ -897,8 +879,6 @@ std::vector OhosAccessibilityBridge::GetLevelOrderTraversalTree(int32_t semanticsQue.push(root); while (!semanticsQue.empty()) { - uint32_t queSize = semanticsQue.size(); - for (uint32_t i=0; i(currNode.id)); @@ -907,7 +887,6 @@ std::vector OhosAccessibilityBridge::GetLevelOrderTraversalTree(int32_t auto childNode = GetFlutterSemanticsNode(childId); semanticsQue.push(childNode); } - } } return levelOrderTraversalTree; } @@ -1906,22 +1885,22 @@ SemanticsNodeExtent OhosAccessibilityBridge::UpdatetSemanticsNodeExtent( nodeEx.elevation = node.elevation; nodeEx.thickness = node.thickness; nodeEx.label = node.label; - nodeEx.labelAttributes = node.labelAttributes; + nodeEx.labelAttributes = std::move(node.labelAttributes); nodeEx.hint = node.hint; - nodeEx.hintAttributes = node.hintAttributes; + nodeEx.hintAttributes = std::move(node.hintAttributes); nodeEx.value = node.value; - nodeEx.valueAttributes = node.valueAttributes; + nodeEx.valueAttributes = std::move(node.valueAttributes); nodeEx.increasedValue = node.increasedValue; - nodeEx.increasedValueAttributes = node.increasedValueAttributes; + nodeEx.increasedValueAttributes = std::move(node.increasedValueAttributes); nodeEx.decreasedValue = node.decreasedValue; - nodeEx.decreasedValueAttributes = node.decreasedValueAttributes; + nodeEx.decreasedValueAttributes = std::move(node.decreasedValueAttributes); nodeEx.tooltip = node.tooltip; nodeEx.textDirection = node.textDirection; - nodeEx.rect = node.rect; - nodeEx.transform = node.transform; - nodeEx.childrenInTraversalOrder = node.childrenInTraversalOrder; - nodeEx.childrenInHitTestOrder = node.childrenInHitTestOrder; - nodeEx.customAccessibilityActions = node.customAccessibilityActions; + nodeEx.rect = std::move(node.rect); + nodeEx.transform = std::move(node.transform); + nodeEx.childrenInTraversalOrder = std::move(node.childrenInTraversalOrder); + nodeEx.childrenInHitTestOrder = std::move(node.childrenInHitTestOrder); + nodeEx.customAccessibilityActions = std::move(node.customAccessibilityActions); return nodeEx; } -- Gitee From cb10f517293dc2b46337c29492c54894539311ee Mon Sep 17 00:00:00 2001 From: zjxi Date: Thu, 20 Feb 2025 17:36:53 +0800 Subject: [PATCH 13/16] =?UTF-8?q?refactor:=20=E5=88=A0=E9=99=A4=E5=86=97?= =?UTF-8?q?=E4=BD=99=E9=81=8D=E5=8E=86=20Signed-off-by:=20zjxi=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/ohos/accessibility/ohos_accessibility_bridge.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index 48437826b3..e506c961d1 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -458,8 +458,6 @@ void OhosAccessibilityBridge::ComputeGlobalTransformAndParentId() semanticsQue.push(rootNode); while (!semanticsQue.empty()) { - uint32_t queSize = semanticsQue.size(); - for (uint32_t i=0; i Date: Thu, 20 Feb 2025 20:00:22 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- shell/platform/ohos/BUILD.gn | 2 - .../ohos_accessibility_manager.cpp | 39 ------------------ .../ohos_accessibility_manager.h | 40 ------------------- 3 files changed, 81 deletions(-) delete mode 100644 shell/platform/ohos/accessibility/ohos_accessibility_manager.cpp delete mode 100644 shell/platform/ohos/accessibility/ohos_accessibility_manager.h diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index 62c781f18d..d4edca3eb4 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -87,7 +87,6 @@ source_set("flutter_ohos_sources") { "platform_view_ohos_delegate.h", "./accessibility/ohos_accessibility_bridge.h", "./accessibility/ohos_accessibility_features.h", - "./accessibility/ohos_accessibility_manager.h", "./accessibility/native_accessibility_channel.h", "./accessibility/ohos_accessibility_ddl.h", "./utils/ddl_utils.h", @@ -126,7 +125,6 @@ source_set("flutter_ohos_sources") { "platform_view_ohos_delegate.cpp", "./accessibility/ohos_accessibility_bridge.cpp", "./accessibility/ohos_accessibility_features.cpp", - "./accessibility/ohos_accessibility_manager.cpp", "./accessibility/native_accessibility_channel.cpp", "./accessibility/ohos_accessibility_ddl.cpp", "./utils/ohos_utils.cpp" diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_manager.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_manager.cpp deleted file mode 100644 index e9b1499f70..0000000000 --- a/shell/platform/ohos/accessibility/ohos_accessibility_manager.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "ohos_accessibility_manager.h" - -namespace flutter { - -OhosAccessibilityManager::OhosAccessibilityManager() {} - -OhosAccessibilityManager::~OhosAccessibilityManager() {} - -/** - * 监听ohos平台是否开启无障碍屏幕朗读功能 - */ -void OhosAccessibilityManager::OnAccessibilityStateChanged( - bool ohosAccessibilityEnabled) {} - -void OhosAccessibilityManager::SetOhosAccessibilityEnabled(bool isEnabled) -{ - this->isOhosAccessibilityEnabled_ = isEnabled; -} - -bool OhosAccessibilityManager::GetOhosAccessibilityEnabled() -{ - return this->isOhosAccessibilityEnabled_; -} - -} // namespace flutter diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_manager.h b/shell/platform/ohos/accessibility/ohos_accessibility_manager.h deleted file mode 100644 index e3c873fe8c..0000000000 --- a/shell/platform/ohos/accessibility/ohos_accessibility_manager.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef OHOS_ACCESSIBILITY_MANAGER_H -#define OHOS_ACCESSIBILITY_MANAGER_H -#include - -namespace flutter { -/** - * 无障碍辅助管理类 - */ -class OhosAccessibilityManager { - public: - OhosAccessibilityManager(); - ~OhosAccessibilityManager(); - - void OnAccessibilityStateChanged(bool ohosAccessibilityEnabled); - - bool GetOhosAccessibilityEnabled(); - - void SetOhosAccessibilityEnabled(bool isEnabled); - - private: - bool isOhosAccessibilityEnabled_; -}; - -} // namespace flutter - -#endif \ No newline at end of file -- Gitee From f05ac2dbc69cd2e2b8c17177efdaf5c7438608c2 Mon Sep 17 00:00:00 2001 From: zjxi Date: Fri, 21 Feb 2025 15:52:09 +0800 Subject: [PATCH 15/16] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9if=E7=9A=84?= =?UTF-8?q?=E9=9D=9E=E7=A9=BA=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../platform/ohos/accessibility/ohos_accessibility_bridge.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index 4f78e1f31a..0978ed1f4e 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -1838,8 +1838,8 @@ SemanticsNodeExtent OhosAccessibilityBridge::UpdatetSemanticsNodeExtent( flutter::SemanticsNode node) { SemanticsNodeExtent nodeEx = SemanticsNodeExtent(); - // 获取更新前的flutter节点信息 - if (!g_flutterSemanticsTree.size()) { + // + if (!g_flutterSemanticsTree.empty()) { auto prevNode = GetFlutterSemanticsNode(node.id); nodeEx.hadPreviousConfig = true; nodeEx.parentId = prevNode.parentId; -- Gitee From 0bff6dd56b7946a189b977d6531402ce0633d208 Mon Sep 17 00:00:00 2001 From: zjxi Date: Fri, 21 Feb 2025 16:58:43 +0800 Subject: [PATCH 16/16] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../ohos_accessibility_bridge.cpp | 19 ++++++++++--------- .../accessibility/ohos_accessibility_bridge.h | 5 +---- .../platform/ohos/ohos_xcomponent_adapter.cpp | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp index 0978ed1f4e..d564367082 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.cpp @@ -426,7 +426,8 @@ void OhosAccessibilityBridge::SetAbsoluteScreenRect(SemanticsNodeExtent& flutter << ", {" << left << ", " << top << ", " << right << ", "<< bottom << "> }"; } -AbsoluteRect OhosAccessibilityBridge::GetAbsoluteScreenRect(const SemanticsNodeExtent& flutterNode) +const AbsoluteRect& OhosAccessibilityBridge::GetAbsoluteScreenRect( + const SemanticsNodeExtent& flutterNode) { return flutterNode.absoluteRect; } @@ -1850,8 +1851,8 @@ SemanticsNodeExtent OhosAccessibilityBridge::UpdatetSemanticsNodeExtent( nodeEx.previousScrollPosition = prevNode.scrollPosition; nodeEx.previousScrollExtentMax = prevNode.scrollExtentMax; nodeEx.previousScrollExtentMin = prevNode.scrollExtentMin; - nodeEx.previousValue = prevNode.value; - nodeEx.previousLabel = prevNode.label; + nodeEx.previousValue = std::move(prevNode.value); + nodeEx.previousLabel = std::move(prevNode.label); } // 更新当前flutter节点信息 @@ -1870,17 +1871,17 @@ SemanticsNodeExtent OhosAccessibilityBridge::UpdatetSemanticsNodeExtent( nodeEx.scrollExtentMin = node.scrollExtentMin; nodeEx.elevation = node.elevation; nodeEx.thickness = node.thickness; - nodeEx.label = node.label; + nodeEx.label = std::move(node.label); nodeEx.labelAttributes = std::move(node.labelAttributes); - nodeEx.hint = node.hint; + nodeEx.hint = std::move(node.hint); nodeEx.hintAttributes = std::move(node.hintAttributes); - nodeEx.value = node.value; + nodeEx.value = std::move(node.value); nodeEx.valueAttributes = std::move(node.valueAttributes); - nodeEx.increasedValue = node.increasedValue; + nodeEx.increasedValue = std::move(node.increasedValue); nodeEx.increasedValueAttributes = std::move(node.increasedValueAttributes); - nodeEx.decreasedValue = node.decreasedValue; + nodeEx.decreasedValue = std::move(node.decreasedValue); nodeEx.decreasedValueAttributes = std::move(node.decreasedValueAttributes); - nodeEx.tooltip = node.tooltip; + nodeEx.tooltip = std::move(node.tooltip); nodeEx.textDirection = node.textDirection; nodeEx.rect = std::move(node.rect); nodeEx.transform = std::move(node.transform); diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h index 8f6452af63..dd51c4553f 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h +++ b/shell/platform/ohos/accessibility/ohos_accessibility_bridge.h @@ -24,9 +24,6 @@ #include "third_party/skia/include/core/SkMatrix.h" #include "third_party/skia/include/core/SkScalar.h" #include "third_party/skia/include/core/SkPoint.h" -#include "third_party/skia/include/core/SkMatrix.h" -#include "third_party/skia/include/core/SkScalar.h" -#include "third_party/skia/include/core/SkPoint.h" namespace flutter { typedef flutter::SemanticsFlags FLAGS_; @@ -149,7 +146,7 @@ public: ArkUI_AccessibilityEventType eventType); void RelativeRectToScreenRect(SemanticsNodeExtent& node); - AbsoluteRect GetAbsoluteScreenRect(const SemanticsNodeExtent& flutterNode); + const AbsoluteRect& GetAbsoluteScreenRect(const SemanticsNodeExtent& flutterNode); void SetAbsoluteScreenRect(SemanticsNodeExtent& flutterNode, float left, float top, diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index bb1287bef6..a7da244df7 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -195,9 +195,9 @@ void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) { delete it->second; // 将当前要销毁的xcomponent对应的无障碍provider指针置nullptr it->second->accessibilityProvider_ = nullptr; - it = XComponentAdapter::GetInstance()->xcomponetMap_.erase(it); // delete the semantics tree of the destroyed xcomponent OhosAccessibilityBridge::GetInstance()->g_flutterSemanticsTreeXComponents.erase(it->first); + it = XComponentAdapter::GetInstance()->xcomponetMap_.erase(it); } else { ++it; } -- Gitee