diff --git a/engine/src/flutter/lib/ui/platform_dispatcher.dart b/engine/src/flutter/lib/ui/platform_dispatcher.dart index 5509ccb3f1..c2f7a223ab 100644 --- a/engine/src/flutter/lib/ui/platform_dispatcher.dart +++ b/engine/src/flutter/lib/ui/platform_dispatcher.dart @@ -758,6 +758,14 @@ class PlatformDispatcher { /// /// In either case, this function disposes the given update, which means the /// semantics update cannot be used further. + @Deprecated(''' + In a multi-view world, the platform dispatcher can no longer provide apis + to update semantics since each view will host its own semantics tree. + + Semantics updates must be passed to an individual [FlutterView]. To update + semantics, use PlatformDispatcher.instance.views to get a [FlutterView] and + call `updateSemantics`. + ''') void updateSemantics(SemanticsUpdate update) => _updateSemantics(update); @FfiNative)>('PlatformConfigurationNativeApi::UpdateSemantics') diff --git a/engine/src/flutter/lib/ui/window.dart b/engine/src/flutter/lib/ui/window.dart index 4e0c07d4d3..6450fad95c 100644 --- a/engine/src/flutter/lib/ui/window.dart +++ b/engine/src/flutter/lib/ui/window.dart @@ -266,6 +266,19 @@ abstract class FlutterView { @FfiNative)>('PlatformConfigurationNativeApi::Render') external static void _render(Scene scene); + + /// Change the retained semantics data about this [FlutterView]. + /// + /// If [PlatformDispatcher.semanticsEnabled] is true, the user has requested that this function + /// be called whenever the semantic content of this [FlutterView] + /// changes. + /// + /// This function disposes the given update, which means the semantics update + /// cannot be used further. + void updateSemantics(SemanticsUpdate update) => _updateSemantics(update); + + @FfiNative)>('PlatformConfigurationNativeApi::UpdateSemantics') + external static void _updateSemantics(SemanticsUpdate update); } /// A top-level platform window displaying a Flutter layer tree drawn from a @@ -721,17 +734,6 @@ class SingletonFlutterWindow extends FlutterWindow { platformDispatcher.onAccessibilityFeaturesChanged = callback; } - /// Change the retained semantics data about this window. - /// - /// {@macro dart.ui.window.functionForwardWarning} - /// - /// If [semanticsEnabled] is true, the user has requested that this function - /// be called whenever the semantic content of this window changes. - /// - /// In either case, this function disposes the given update, which means the - /// semantics update cannot be used further. - void updateSemantics(SemanticsUpdate update) => platformDispatcher.updateSemantics(update); - /// Sends a message to a platform-specific plugin. /// /// {@macro dart.ui.window.functionForwardWarning} diff --git a/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart b/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart index 7c67e7c3d5..6d508576df 100644 --- a/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart +++ b/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart @@ -83,6 +83,14 @@ abstract class PlatformDispatcher { VoidCallback? get onAccessibilityFeaturesChanged; set onAccessibilityFeaturesChanged(VoidCallback? callback); + @Deprecated(''' + In a multi-view world, the platform dispatcher can no longer provide apis + to update semantics since each view will host its own semantics tree. + + Semantics updates must be passed to an individual [FlutterView]. To update + semantics, use PlatformDispatcher.instance.views to get a [FlutterView] and + call `updateSemantics`. + ''') void updateSemantics(SemanticsUpdate update); Locale get locale; diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 5f59713698..3cfbffeb1f 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -698,6 +698,14 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { /// In either case, this function disposes the given update, which means the /// semantics update cannot be used further. @override + @Deprecated(''' + In a multi-view world, the platform dispatcher can no longer provide apis + to update semantics since each view will host its own semantics tree. + + Semantics updates must be passed to an individual [FlutterView]. To update + semantics, use PlatformDispatcher.instance.views to get a [FlutterView] and + call `updateSemantics`. + ''') void updateSemantics(ui.SemanticsUpdate update) { EngineSemanticsOwner.instance.updateSemantics(update); } diff --git a/engine/src/flutter/lib/web_ui/lib/window.dart b/engine/src/flutter/lib/web_ui/lib/window.dart index bbb033b42e..ee4e0e35ec 100644 --- a/engine/src/flutter/lib/web_ui/lib/window.dart +++ b/engine/src/flutter/lib/web_ui/lib/window.dart @@ -16,6 +16,7 @@ abstract class FlutterView { WindowPadding get padding => viewConfiguration.padding; List get displayFeatures => viewConfiguration.displayFeatures; void render(Scene scene) => platformDispatcher.render(scene, this); + void updateSemantics(SemanticsUpdate update) => platformDispatcher.updateSemantics(update); } abstract class FlutterWindow extends FlutterView { @@ -130,8 +131,6 @@ abstract class SingletonFlutterWindow extends FlutterWindow { platformDispatcher.onAccessibilityFeaturesChanged = callback; } - void updateSemantics(SemanticsUpdate update) => platformDispatcher.updateSemantics(update); - void sendPlatformMessage( String name, ByteData? data, diff --git a/engine/src/flutter/shell/platform/embedder/fixtures/main.dart b/engine/src/flutter/shell/platform/embedder/fixtures/main.dart index 41d9a2fda8..23dd2a371f 100644 --- a/engine/src/flutter/shell/platform/embedder/fixtures/main.dart +++ b/engine/src/flutter/shell/platform/embedder/fixtures/main.dart @@ -264,7 +264,9 @@ void a11y_main() async { label: 'Archive', hint: 'archive message', ); - PlatformDispatcher.instance.updateSemantics(builder.build()); + + PlatformDispatcher.instance.views.first.updateSemantics(builder.build()); + signalNativeTest(); // Await semantics action from embedder. diff --git a/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart b/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart index d6a9afcdae..2cdfc43f24 100644 --- a/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart +++ b/engine/src/flutter/testing/scenario_app/lib/src/locale_initialization.dart @@ -43,8 +43,8 @@ class LocaleInitialization extends Scenario { // On the first frame, pretend that it drew a text field. Send the // corresponding semantics tree comprised of 1 node with the locale data // as the label. - window.updateSemantics((SemanticsUpdateBuilder() - ..updateNode( + final SemanticsUpdateBuilder semanticsUpdateBuilder = + SemanticsUpdateBuilder()..updateNode( id: 0, // SemanticsFlag.isTextField. flags: 16, @@ -79,8 +79,11 @@ class LocaleInitialization extends Scenario { childrenInTraversalOrder: Int32List(0), childrenInHitTestOrder: Int32List(0), additionalActions: Int32List(0), - )).build() - ); + ); + + final SemanticsUpdate semanticsUpdate = semanticsUpdateBuilder.build(); + + dispatcher.views.first.updateSemantics(semanticsUpdate); } /// Handle taps. @@ -98,8 +101,8 @@ class LocaleInitialization extends Scenario { // Expand for other test cases. } - window.updateSemantics((SemanticsUpdateBuilder() - ..updateNode( + final SemanticsUpdateBuilder semanticsUpdateBuilder = + SemanticsUpdateBuilder()..updateNode( id: 0, // SemanticsFlag.isTextField. flags: 16, @@ -134,8 +137,12 @@ class LocaleInitialization extends Scenario { childrenInTraversalOrder: Int32List(0), childrenInHitTestOrder: Int32List(0), additionalActions: Int32List(0), - )).build() - ); + ); + + final SemanticsUpdate semanticsUpdate = semanticsUpdateBuilder.build(); + + dispatcher.views.first.updateSemantics(semanticsUpdate); + _tapCount++; } }