Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate single semantics tree assumption from platform dispatcher #36675

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/ui/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void Function(Pointer<Void>)>('PlatformConfigurationNativeApi::UpdateSemantics')
Expand Down
24 changes: 13 additions & 11 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ abstract class FlutterView {

@FfiNative<Void Function(Pointer<Void>)>('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<Void Function(Pointer<Void>)>('PlatformConfigurationNativeApi::UpdateSemantics')
external static void _updateSemantics(SemanticsUpdate update);
}

/// A top-level platform window displaying a Flutter layer tree drawn from a
Expand Down Expand Up @@ -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}
Expand Down
8 changes: 8 additions & 0 deletions lib/web_ui/lib/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/web_ui/lib/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ abstract class FlutterView {
WindowPadding get padding => viewConfiguration.padding;
List<DisplayFeature> get displayFeatures => viewConfiguration.displayFeatures;
void render(Scene scene) => platformDispatcher.render(scene, this);
void updateSemantics(SemanticsUpdate update) => platformDispatcher.updateSemantics(update);
}

abstract class FlutterWindow extends FlutterView {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/embedder/fixtures/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 15 additions & 8 deletions testing/scenario_app/lib/src/locale_initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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++;
}
}