Skip to content

Commit 17f86df

Browse files
authored
Migrate SemanticsBinding to onSemanticsActionEvent (flutter#128254)
Follow-up to flutter/engine#42493.
1 parent 130e84e commit 17f86df

File tree

4 files changed

+20
-56
lines changed

4 files changed

+20
-56
lines changed

packages/flutter/lib/src/foundation/binding.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,12 @@ abstract class BindingBase {
221221
/// [BindingBase], e.g., [ServicesBinding], [RendererBinding], and
222222
/// [WidgetsBinding]. Each of these bindings define behaviors that interact
223223
/// with a [ui.PlatformDispatcher], e.g., [ServicesBinding] registers
224-
/// listeners with the [ChannelBuffers], and [RendererBinding]
224+
/// listeners with the [ChannelBuffers], [RendererBinding]
225225
/// registers [ui.PlatformDispatcher.onMetricsChanged],
226-
/// [ui.PlatformDispatcher.onTextScaleFactorChanged],
227-
/// [ui.PlatformDispatcher.onSemanticsEnabledChanged], and
228-
/// [ui.PlatformDispatcher.onSemanticsAction] handlers.
226+
/// [ui.PlatformDispatcher.onTextScaleFactorChanged], and [SemanticsBinding]
227+
/// registers [ui.PlatformDispatcher.onSemanticsEnabledChanged],
228+
/// [ui.PlatformDispatcher.onSemanticsActionEvent], and
229+
/// [ui.PlatformDispatcher.onAccessibilityFeaturesChanged] handlers.
229230
///
230231
/// Each of these other bindings could individually access a
231232
/// [ui.PlatformDispatcher] statically, but that would preclude the ability to

packages/flutter/lib/src/semantics/binding.dart

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:ui' as ui show AccessibilityFeatures, SemanticsAction, SemanticsUpdateBuilder;
5+
import 'dart:ui' as ui show AccessibilityFeatures, SemanticsActionEvent, SemanticsUpdateBuilder;
66

77
import 'package:flutter/foundation.dart';
88
import 'package:flutter/services.dart';
99

1010
import 'debug.dart';
1111

12-
export 'dart:ui' show AccessibilityFeatures, SemanticsUpdateBuilder;
12+
export 'dart:ui' show AccessibilityFeatures, SemanticsActionEvent, SemanticsUpdateBuilder;
1313

1414
/// The glue between the semantics layer and the Flutter engine.
1515
mixin SemanticsBinding on BindingBase {
@@ -20,7 +20,7 @@ mixin SemanticsBinding on BindingBase {
2020
_accessibilityFeatures = platformDispatcher.accessibilityFeatures;
2121
platformDispatcher
2222
..onSemanticsEnabledChanged = _handleSemanticsEnabledChanged
23-
..onSemanticsAction = _handleSemanticsAction
23+
..onSemanticsActionEvent = _handleSemanticsActionEvent
2424
..onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged;
2525
_handleSemanticsEnabledChanged();
2626
}
@@ -111,12 +111,12 @@ mixin SemanticsBinding on BindingBase {
111111
}
112112
}
113113

114-
void _handleSemanticsAction(int id, ui.SemanticsAction action, ByteData? args) {
115-
performSemanticsAction(SemanticsActionEvent(
116-
nodeId: id,
117-
type: action,
118-
arguments: args != null ? const StandardMessageCodec().decodeMessage(args) : null,
119-
));
114+
void _handleSemanticsActionEvent(ui.SemanticsActionEvent action) {
115+
final Object? arguments = action.arguments;
116+
final ui.SemanticsActionEvent decodedAction = arguments is ByteData
117+
? action.copyWith(arguments: const StandardMessageCodec().decodeMessage(arguments))
118+
: action;
119+
performSemanticsAction(decodedAction);
120120
}
121121

122122
/// Called whenever the platform requests an action to be performed on a
@@ -130,9 +130,9 @@ mixin SemanticsBinding on BindingBase {
130130
/// perform the given `action` on the [SemanticsNode] specified by
131131
/// [SemanticsActionEvent.nodeId].
132132
///
133-
/// See [dart:ui.PlatformDispatcher.onSemanticsAction].
133+
/// See [dart:ui.PlatformDispatcher.onSemanticsActionEvent].
134134
@protected
135-
void performSemanticsAction(SemanticsActionEvent action);
135+
void performSemanticsAction(ui.SemanticsActionEvent action);
136136

137137
/// The currently active set of [AccessibilityFeatures].
138138
///
@@ -180,27 +180,6 @@ mixin SemanticsBinding on BindingBase {
180180
}
181181
}
182182

183-
/// An event to request a [SemanticsAction] of [type] to be performed on the
184-
/// [SemanticsNode] identified by [nodeId].
185-
///
186-
/// Used by [SemanticsBinding.performSemanticsAction].
187-
@immutable
188-
class SemanticsActionEvent {
189-
/// Creates a [SemanticsActionEvent].
190-
///
191-
/// The [type] and [nodeId] are required.
192-
const SemanticsActionEvent({required this.type, required this.nodeId, this.arguments});
193-
194-
/// The type of action to be performed.
195-
final ui.SemanticsAction type;
196-
197-
/// The id of the [SemanticsNode] on which the action is to be performed.
198-
final int nodeId;
199-
200-
/// Optional arguments for the action.
201-
final Object? arguments;
202-
}
203-
204183
/// A reference to the semantics information generated by the framework.
205184
///
206185
/// Semantics information are only collected when there are clients interested

packages/flutter/test/semantics/semantics_owner_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void main() {
4242
tester.binding.performSemanticsAction(SemanticsActionEvent(
4343
type: SemanticsAction.showOnScreen,
4444
nodeId: nodeId,
45+
viewId: tester.view.viewId,
4546
));
4647
semantics.dispose();
4748
});

packages/flutter_test/lib/src/window.dart

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,10 @@ class TestPlatformDispatcher implements PlatformDispatcher {
395395
}
396396

397397
@override
398-
SemanticsActionCallback? get onSemanticsAction => _platformDispatcher.onSemanticsAction;
398+
SemanticsActionEventCallback? get onSemanticsActionEvent => _platformDispatcher.onSemanticsActionEvent;
399399
@override
400-
set onSemanticsAction(SemanticsActionCallback? callback) {
401-
_platformDispatcher.onSemanticsAction = callback;
400+
set onSemanticsActionEvent(SemanticsActionEventCallback? callback) {
401+
_platformDispatcher.onSemanticsActionEvent = callback;
402402
}
403403

404404
@override
@@ -1880,23 +1880,6 @@ class TestWindow implements SingletonFlutterWindow {
18801880
platformDispatcher.onSemanticsEnabledChanged = callback;
18811881
}
18821882

1883-
@Deprecated(
1884-
'Use WidgetTester.platformDispatcher.onSemanticsAction instead. '
1885-
'Deprecated to prepare for the upcoming multi-window support. '
1886-
'This feature was deprecated after v3.9.0-0.1.pre.'
1887-
)
1888-
@override
1889-
SemanticsActionCallback? get onSemanticsAction => platformDispatcher.onSemanticsAction;
1890-
@Deprecated(
1891-
'Use WidgetTester.platformDispatcher.onSemanticsAction instead. '
1892-
'Deprecated to prepare for the upcoming multi-window support. '
1893-
'This feature was deprecated after v3.9.0-0.1.pre.'
1894-
)
1895-
@override
1896-
set onSemanticsAction(SemanticsActionCallback? callback) {
1897-
platformDispatcher.onSemanticsAction = callback;
1898-
}
1899-
19001883
@Deprecated(
19011884
'Use WidgetTester.platformDispatcher.accessibilityFeatures instead. '
19021885
'Deprecated to prepare for the upcoming multi-window support. '

0 commit comments

Comments
 (0)