From f8b16a407ea80800b0f2de9944f13096ab082d4d Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Mon, 5 Jun 2023 15:00:54 -0700 Subject: [PATCH 1/2] Remove onSemanticsAction --- lib/ui/fixtures/ui_test.dart | 21 -------------- lib/ui/platform_dispatcher.dart | 28 ------------------- lib/ui/semantics.dart | 9 +++--- lib/ui/window.dart | 15 ---------- lib/web_ui/lib/platform_dispatcher.dart | 4 --- .../lib/src/engine/platform_dispatcher.dart | 20 ------------- lib/web_ui/lib/window.dart | 5 ---- .../test/engine/semantics/semantics_test.dart | 24 ++++++++-------- .../engine/semantics/semantics_tester.dart | 8 +++--- lib/web_ui/test/engine/window_test.dart | 8 +++--- 10 files changed, 25 insertions(+), 117 deletions(-) diff --git a/lib/ui/fixtures/ui_test.dart b/lib/ui/fixtures/ui_test.dart index 731e7b137c8a3..09caf203097dd 100644 --- a/lib/ui/fixtures/ui_test.dart +++ b/lib/ui/fixtures/ui_test.dart @@ -826,27 +826,6 @@ void hooksTests() async { expectEquals(enabled, newValue); }); - await test('onSemanticsAction preserves callback zone', () { - late Zone innerZone; - late Zone runZone; - late int id; - late int action; - - runZoned(() { - innerZone = Zone.current; - window.onSemanticsAction = (int i, SemanticsAction a, ByteData? _) { - runZone = Zone.current; - action = a.index; - id = i; - }; - }); - - _callHook('_dispatchSemanticsAction', 3, 1234, 4, null); - expectIdentical(runZone, innerZone); - expectEquals(id, 1234); - expectEquals(action, 4); - }); - await test('onSemanticsActionEvent preserves callback zone', () { late Zone innerZone; late Zone runZone; diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index cbd56a11adc68..1d479391984b3 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -32,10 +32,6 @@ typedef PointerDataPacketCallback = void Function(PointerDataPacket packet); /// framework and should not be propagated further. typedef KeyDataCallback = bool Function(KeyData data); -/// Signature for [PlatformDispatcher.onSemanticsAction]. -// TODO(goderbauer): Deprecate/remove this when the framework has migrated to SemanticsActionEventCallback. -typedef SemanticsActionCallback = void Function(int nodeId, SemanticsAction action, ByteData? args); - /// Signature for [PlatformDispatcher.onSemanticsActionEvent]. typedef SemanticsActionEventCallback = void Function(SemanticsActionEvent action); @@ -1151,23 +1147,6 @@ class PlatformDispatcher { _invoke(onSemanticsEnabledChanged, _onSemanticsEnabledChangedZone); } - /// A callback that is invoked whenever the user requests an action to be - /// performed on a semantics node. - /// - /// This callback is used when the user expresses the action they wish to - /// perform based on the semantics node supplied by updateSemantics. - /// - /// The framework invokes this callback in the same zone in which the - /// callback was set. - // TODO(goderbauer): Deprecate/remove this when the framework has migrated to onSemanticsActionEvent. - SemanticsActionCallback? get onSemanticsAction => _onSemanticsAction; - SemanticsActionCallback? _onSemanticsAction; - Zone _onSemanticsActionZone = Zone.root; - set onSemanticsAction(SemanticsActionCallback? callback) { - _onSemanticsAction = callback; - _onSemanticsActionZone = Zone.current; - } - /// A callback that is invoked whenever the user requests an action to be /// performed on a semantics node. /// @@ -1209,13 +1188,6 @@ class PlatformDispatcher { // Called from the engine, via hooks.dart void _dispatchSemanticsAction(int nodeId, int action, ByteData? args) { - _invoke3( - onSemanticsAction, - _onSemanticsActionZone, - nodeId, - SemanticsAction.fromIndex(action)!, - args, - ); _invoke1( onSemanticsActionEvent, _onSemanticsActionEventZone, diff --git a/lib/ui/semantics.dart b/lib/ui/semantics.dart index 832f56a5fdf96..e7df3aba65795 100644 --- a/lib/ui/semantics.dart +++ b/lib/ui/semantics.dart @@ -699,10 +699,11 @@ abstract class SemanticsUpdateBuilder { /// /// The `actions` are a bit field of [SemanticsAction]s that can be undertaken /// by this node. If the user wishes to undertake one of these actions on this - /// node, the [PlatformDispatcher.onSemanticsAction] will be called with `id` - /// and one of the possible [SemanticsAction]s. Because the semantics tree is - /// maintained asynchronously, the [PlatformDispatcher.onSemanticsAction] - /// callback might be called with an action that is no longer possible. + /// node, the [PlatformDispatcher.onSemanticsActionEvent] will be called with + /// a [SemanticsActionEvent] specifying the action to be performed. Because + /// the semantics tree is maintained asynchronously, the + /// [PlatformDispatcher.onSemanticsActionEvent] callback might be called with + /// an action that is no longer possible. /// /// The `label` is a string that describes this node. The `value` property /// describes the current value of the node as a string. The `increasedValue` diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 1dbf84e6a92ca..0b0e43d570334 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -756,21 +756,6 @@ class SingletonFlutterWindow extends FlutterView { platformDispatcher.onFrameDataChanged = callback; } - /// A callback that is invoked whenever the user requests an action to be - /// performed. - /// - /// {@macro dart.ui.window.accessorForwardWarning} - /// - /// This callback is used when the user expresses the action they wish to - /// perform based on the semantics supplied by [updateSemantics]. - /// - /// The framework invokes this callback in the same zone in which the - /// callback was set. - SemanticsActionCallback? get onSemanticsAction => platformDispatcher.onSemanticsAction; - set onSemanticsAction(SemanticsActionCallback? callback) { - platformDispatcher.onSemanticsAction = callback; - } - /// Additional accessibility features that may be enabled by the platform. AccessibilityFeatures get accessibilityFeatures => platformDispatcher.accessibilityFeatures; diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index 6d1870068e225..54453a0fffa20 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -9,7 +9,6 @@ typedef FrameCallback = void Function(Duration duration); typedef TimingsCallback = void Function(List timings); typedef PointerDataPacketCallback = void Function(PointerDataPacket packet); typedef KeyDataCallback = bool Function(KeyData data); -typedef SemanticsActionCallback = void Function(int nodeId, SemanticsAction action, ByteData? args); typedef SemanticsActionEventCallback = void Function(SemanticsActionEvent action); typedef PlatformMessageResponseCallback = void Function(ByteData? data); typedef PlatformMessageCallback = void Function( @@ -135,9 +134,6 @@ abstract class PlatformDispatcher { VoidCallback? get onSemanticsEnabledChanged; set onSemanticsEnabledChanged(VoidCallback? callback); - SemanticsActionCallback? get onSemanticsAction; - set onSemanticsAction(SemanticsActionCallback? callback); - SemanticsActionEventCallback? get onSemanticsActionEvent; set onSemanticsActionEvent(SemanticsActionEventCallback? callback); diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index e0cbf4897367b..4e1f641c14114 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -1193,24 +1193,6 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { invoke(_onSemanticsEnabledChanged, _onSemanticsEnabledChangedZone); } - /// A callback that is invoked whenever the user requests an action to be - /// performed. - /// - /// This callback is used when the user expresses the action they wish to - /// perform based on the semantics supplied by [updateSemantics]. - /// - /// The framework invokes this callback in the same zone in which the - /// callback was set. - @override - ui.SemanticsActionCallback? get onSemanticsAction => _onSemanticsAction; - ui.SemanticsActionCallback? _onSemanticsAction; - Zone? _onSemanticsActionZone; - @override - set onSemanticsAction(ui.SemanticsActionCallback? callback) { - _onSemanticsAction = callback; - _onSemanticsActionZone = Zone.current; - } - /// A callback that is invoked whenever the user requests an action to be /// performed on a semantics node. /// @@ -1233,8 +1215,6 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { /// Otherwise zones won't work properly. void invokeOnSemanticsAction( int nodeId, ui.SemanticsAction action, ByteData? args) { - invoke3( - _onSemanticsAction, _onSemanticsActionZone, nodeId, action, args); invoke1( _onSemanticsActionEvent, _onSemanticsActionEventZone, ui.SemanticsActionEvent( type: action, diff --git a/lib/web_ui/lib/window.dart b/lib/web_ui/lib/window.dart index f16ff8b850f72..3e31bbc03f025 100644 --- a/lib/web_ui/lib/window.dart +++ b/lib/web_ui/lib/window.dart @@ -114,11 +114,6 @@ abstract class SingletonFlutterWindow extends FlutterView { platformDispatcher.onSemanticsEnabledChanged = callback; } - SemanticsActionCallback? get onSemanticsAction => platformDispatcher.onSemanticsAction; - set onSemanticsAction(SemanticsActionCallback? callback) { - platformDispatcher.onSemanticsAction = callback; - } - FrameData get frameData => const FrameData._(); VoidCallback? get onFrameDataChanged => null; diff --git a/lib/web_ui/test/engine/semantics/semantics_test.dart b/lib/web_ui/test/engine/semantics/semantics_test.dart index 89fe404a3eae2..2ea39782e7df4 100644 --- a/lib/web_ui/test/engine/semantics/semantics_test.dart +++ b/lib/web_ui/test/engine/semantics/semantics_test.dart @@ -1102,10 +1102,10 @@ void _testVerticalScrolling() { // fired. final Zone testZone = Zone.current; - ui.window.onSemanticsAction = - (int id, ui.SemanticsAction action, ByteData? args) { - idLogController.add(id); - actionLogController.add(action); + ui.PlatformDispatcher.instance.onSemanticsActionEvent = + (ui.SemanticsActionEvent event) { + idLogController.add(event.nodeId); + actionLogController.add(event.type); testZone.run(() { expect(args, null); }); @@ -1459,8 +1459,8 @@ void _testIncrementables() { } final List capturedActions = []; - EnginePlatformDispatcher.instance.onSemanticsAction = (int nodeId, ui.SemanticsAction action, ByteData? args) { - capturedActions.add((nodeId, action, args)); + EnginePlatformDispatcher.instance.onSemanticsActionEvent = (ui.SemanticsActionEvent event) { + capturedActions.add((event.nodeId, event.type, event.arguments)); }; pumpSemantics(isFocused: false); @@ -1814,8 +1814,8 @@ void _testCheckables() { } final List capturedActions = []; - EnginePlatformDispatcher.instance.onSemanticsAction = (int nodeId, ui.SemanticsAction action, ByteData? args) { - capturedActions.add((nodeId, action, args)); + EnginePlatformDispatcher.instance.onSemanticsActionEvent = (ui.SemanticsActionEvent event) { + capturedActions.add((event.nodeId, event.type, event.arguments)); }; pumpSemantics(isFocused: false); @@ -1973,8 +1973,8 @@ void _testTappable() { } final List capturedActions = []; - EnginePlatformDispatcher.instance.onSemanticsAction = (int nodeId, ui.SemanticsAction action, ByteData? args) { - capturedActions.add((nodeId, action, args)); + EnginePlatformDispatcher.instance.onSemanticsActionEvent = (ui.SemanticsActionEvent event) { + capturedActions.add((event.nodeId, event.type, event.arguments)); }; pumpSemantics(isFocused: false); @@ -2656,8 +2656,8 @@ void _testFocusable() { } final List capturedActions = []; - EnginePlatformDispatcher.instance.onSemanticsAction = (int nodeId, ui.SemanticsAction action, ByteData? args) { - capturedActions.add((nodeId, action, args)); + EnginePlatformDispatcher.instance.onSemanticsActionEvent = (ui.SemanticsActionEvent event) { + capturedActions.add((event.nodeId, event.type, event.arguments)); }; expect(capturedActions, isEmpty); diff --git a/lib/web_ui/test/engine/semantics/semantics_tester.dart b/lib/web_ui/test/engine/semantics/semantics_tester.dart index bd2ebed3f5229..b813ad4321ad2 100644 --- a/lib/web_ui/test/engine/semantics/semantics_tester.dart +++ b/lib/web_ui/test/engine/semantics/semantics_tester.dart @@ -388,10 +388,10 @@ class SemanticsActionLogger { // fired. final Zone testZone = Zone.current; - ui.window.onSemanticsAction = - (int id, ui.SemanticsAction action, ByteData? args) { - _idLogController.add(id); - _actionLogController.add(action); + ui.PlatformDispatcher.instance.onSemanticsAction = + (ui.SemanticsActionEvent event) { + _idLogController.add(event.nodeId); + _actionLogController.add(event.type); testZone.run(() { expect(args, null); }); diff --git a/lib/web_ui/test/engine/window_test.dart b/lib/web_ui/test/engine/window_test.dart index 8c78d94283729..9c957f8c9b048 100644 --- a/lib/web_ui/test/engine/window_test.dart +++ b/lib/web_ui/test/engine/window_test.dart @@ -211,17 +211,17 @@ Future testMain() async { EnginePlatformDispatcher.instance.invokeOnSemanticsEnabledChanged(); }); - test('onSemanticsAction preserves the zone', () { + test('onSemanticsActionEvent preserves the zone', () { final Zone innerZone = Zone.current.fork(); innerZone.runGuarded(() { - void callback(int _, ui.SemanticsAction __, ByteData? ___) { + void callback(ui.SemanticsActionEvent _) { expect(Zone.current, innerZone); } - window.onSemanticsAction = callback; + ui.PlatformDispatcher.instance.onSemanticsActionEvent = callback; // Test that the getter returns the exact same callback, e.g. it doesn't wrap it. - expect(window.onSemanticsAction, same(callback)); + expect(ui.PlatformDispatcher.instance.onSemanticsActionEvent, same(callback)); }); EnginePlatformDispatcher.instance.invokeOnSemanticsAction(0, ui.SemanticsAction.tap, null); From 91992b80818ec2496f9475b9185719277b8a0c3d Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Mon, 5 Jun 2023 15:27:47 -0700 Subject: [PATCH 2/2] fix analyzer web_ui issues --- lib/web_ui/test/engine/semantics/semantics_test.dart | 4 ++-- lib/web_ui/test/engine/semantics/semantics_tester.dart | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/web_ui/test/engine/semantics/semantics_test.dart b/lib/web_ui/test/engine/semantics/semantics_test.dart index 2ea39782e7df4..cc768b3f5a350 100644 --- a/lib/web_ui/test/engine/semantics/semantics_test.dart +++ b/lib/web_ui/test/engine/semantics/semantics_test.dart @@ -1107,7 +1107,7 @@ void _testVerticalScrolling() { idLogController.add(event.nodeId); actionLogController.add(event.type); testZone.run(() { - expect(args, null); + expect(event.arguments, null); }); }; semantics() @@ -2634,7 +2634,7 @@ void _testDialog() { }); } -typedef CapturedAction = (int nodeId, ui.SemanticsAction action, ByteData? args); +typedef CapturedAction = (int nodeId, ui.SemanticsAction action, Object? args); void _testFocusable() { test('AccessibilityFocusManager can manage element focus', () async { diff --git a/lib/web_ui/test/engine/semantics/semantics_tester.dart b/lib/web_ui/test/engine/semantics/semantics_tester.dart index b813ad4321ad2..ce8817244fc3f 100644 --- a/lib/web_ui/test/engine/semantics/semantics_tester.dart +++ b/lib/web_ui/test/engine/semantics/semantics_tester.dart @@ -388,12 +388,12 @@ class SemanticsActionLogger { // fired. final Zone testZone = Zone.current; - ui.PlatformDispatcher.instance.onSemanticsAction = + ui.PlatformDispatcher.instance.onSemanticsActionEvent = (ui.SemanticsActionEvent event) { _idLogController.add(event.nodeId); _actionLogController.add(event.type); testZone.run(() { - expect(args, null); + expect(event.arguments, null); }); }; }