Skip to content

Commit

Permalink
Deprecate platform_dispatcher apis in favor of updateSemantics in F…
Browse files Browse the repository at this point in the history
…lutterView
  • Loading branch information
a-wallen committed Oct 8, 2022
1 parent 9090078 commit ccc5c13
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 9 deletions.
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 flutter view. To update
semantics, use PlatformDispatcher.instance.views to get a flutter view and
call `updateSemantics`.
''')
void updateSemantics(SemanticsUpdate update) => _updateSemantics(update);

@FfiNative<Void Function(Pointer<Void>)>('PlatformConfigurationNativeApi::UpdateSemantics')
Expand Down
20 changes: 20 additions & 0 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 platform dispatcher.
///
/// If [semanticsEnabled] is true, the user has requested that this function
/// be called whenever the semantic content of this platform dispatcher
/// changes.
///
/// In either case, 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 @@ -730,6 +743,13 @@ class SingletonFlutterWindow extends FlutterWindow {
///
/// In either case, this function disposes the given update, which means the
/// semantics update cannot be used further.
@override
@Deprecated('''
A singleton flutter window no longer manages semantics trees. In a multi-view
world, each flutter view must manage its own semantics tree.
Call updateSemantics() from FlutterView instead.
''')
void updateSemantics(SemanticsUpdate update) => platformDispatcher.updateSemantics(update);

/// Sends a message to a platform-specific plugin.
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 flutter view. To update
semantics, use PlatformDispatcher.instance.views to get a flutter view 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 flutter view. To update
semantics, use PlatformDispatcher.instance.views to get a flutter view and
call `updateSemantics`.
''')
void updateSemantics(ui.SemanticsUpdate update) {
EngineSemanticsOwner.instance.updateSemantics(update);
}
Expand Down
8 changes: 8 additions & 0 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,6 +131,13 @@ abstract class SingletonFlutterWindow extends FlutterWindow {
platformDispatcher.onAccessibilityFeaturesChanged = callback;
}

@override
@Deprecated('''
A singleton flutter window no longer manages semantics trees. In a multi-view
world, each flutter view must manage its own semantics tree.
Call updateSemantics() from FlutterView instead.
''')
void updateSemantics(SemanticsUpdate update) => platformDispatcher.updateSemantics(update);

void sendPlatformMessage(
Expand Down
6 changes: 5 additions & 1 deletion shell/platform/embedder/fixtures/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ void a11y_main() async {
label: 'Archive',
hint: 'archive message',
);
PlatformDispatcher.instance.updateSemantics(builder.build());

PlatformDispatcher.instance.views.forEach((FlutterView view) {
view.updateSemantics(builder.build());
});

signalNativeTest();

// Await semantics action from embedder.
Expand Down
27 changes: 19 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,13 @@ class LocaleInitialization extends Scenario {
childrenInTraversalOrder: Int32List(0),
childrenInHitTestOrder: Int32List(0),
additionalActions: Int32List(0),
)).build()
);
);

final SemanticsUpdate semanticsUpdate = semanticsUpdateBuilder.build();

for (final FlutterView view in dispatcher.views) {
view.updateSemantics(semanticsUpdate);
}
}

/// Handle taps.
Expand All @@ -98,8 +103,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 +139,14 @@ class LocaleInitialization extends Scenario {
childrenInTraversalOrder: Int32List(0),
childrenInHitTestOrder: Int32List(0),
additionalActions: Int32List(0),
)).build()
);
);

final SemanticsUpdate semanticsUpdate = semanticsUpdateBuilder.build();

for (final FlutterView view in dispatcher.views) {
view.updateSemantics(semanticsUpdate);
}

_tapCount++;
}
}

0 comments on commit ccc5c13

Please sign in to comment.