Unverified Commit 17f86df8 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate SemanticsBinding to onSemanticsActionEvent (#128254)

Follow-up to https://github.com/flutter/engine/pull/42493.
parent 130e84ec
...@@ -221,11 +221,12 @@ abstract class BindingBase { ...@@ -221,11 +221,12 @@ abstract class BindingBase {
/// [BindingBase], e.g., [ServicesBinding], [RendererBinding], and /// [BindingBase], e.g., [ServicesBinding], [RendererBinding], and
/// [WidgetsBinding]. Each of these bindings define behaviors that interact /// [WidgetsBinding]. Each of these bindings define behaviors that interact
/// with a [ui.PlatformDispatcher], e.g., [ServicesBinding] registers /// with a [ui.PlatformDispatcher], e.g., [ServicesBinding] registers
/// listeners with the [ChannelBuffers], and [RendererBinding] /// listeners with the [ChannelBuffers], [RendererBinding]
/// registers [ui.PlatformDispatcher.onMetricsChanged], /// registers [ui.PlatformDispatcher.onMetricsChanged],
/// [ui.PlatformDispatcher.onTextScaleFactorChanged], /// [ui.PlatformDispatcher.onTextScaleFactorChanged], and [SemanticsBinding]
/// [ui.PlatformDispatcher.onSemanticsEnabledChanged], and /// registers [ui.PlatformDispatcher.onSemanticsEnabledChanged],
/// [ui.PlatformDispatcher.onSemanticsAction] handlers. /// [ui.PlatformDispatcher.onSemanticsActionEvent], and
/// [ui.PlatformDispatcher.onAccessibilityFeaturesChanged] handlers.
/// ///
/// Each of these other bindings could individually access a /// Each of these other bindings could individually access a
/// [ui.PlatformDispatcher] statically, but that would preclude the ability to /// [ui.PlatformDispatcher] statically, but that would preclude the ability to
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' as ui show AccessibilityFeatures, SemanticsAction, SemanticsUpdateBuilder; import 'dart:ui' as ui show AccessibilityFeatures, SemanticsActionEvent, SemanticsUpdateBuilder;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'debug.dart'; import 'debug.dart';
export 'dart:ui' show AccessibilityFeatures, SemanticsUpdateBuilder; export 'dart:ui' show AccessibilityFeatures, SemanticsActionEvent, SemanticsUpdateBuilder;
/// The glue between the semantics layer and the Flutter engine. /// The glue between the semantics layer and the Flutter engine.
mixin SemanticsBinding on BindingBase { mixin SemanticsBinding on BindingBase {
...@@ -20,7 +20,7 @@ mixin SemanticsBinding on BindingBase { ...@@ -20,7 +20,7 @@ mixin SemanticsBinding on BindingBase {
_accessibilityFeatures = platformDispatcher.accessibilityFeatures; _accessibilityFeatures = platformDispatcher.accessibilityFeatures;
platformDispatcher platformDispatcher
..onSemanticsEnabledChanged = _handleSemanticsEnabledChanged ..onSemanticsEnabledChanged = _handleSemanticsEnabledChanged
..onSemanticsAction = _handleSemanticsAction ..onSemanticsActionEvent = _handleSemanticsActionEvent
..onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged; ..onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged;
_handleSemanticsEnabledChanged(); _handleSemanticsEnabledChanged();
} }
...@@ -111,12 +111,12 @@ mixin SemanticsBinding on BindingBase { ...@@ -111,12 +111,12 @@ mixin SemanticsBinding on BindingBase {
} }
} }
void _handleSemanticsAction(int id, ui.SemanticsAction action, ByteData? args) { void _handleSemanticsActionEvent(ui.SemanticsActionEvent action) {
performSemanticsAction(SemanticsActionEvent( final Object? arguments = action.arguments;
nodeId: id, final ui.SemanticsActionEvent decodedAction = arguments is ByteData
type: action, ? action.copyWith(arguments: const StandardMessageCodec().decodeMessage(arguments))
arguments: args != null ? const StandardMessageCodec().decodeMessage(args) : null, : action;
)); performSemanticsAction(decodedAction);
} }
/// Called whenever the platform requests an action to be performed on a /// Called whenever the platform requests an action to be performed on a
...@@ -130,9 +130,9 @@ mixin SemanticsBinding on BindingBase { ...@@ -130,9 +130,9 @@ mixin SemanticsBinding on BindingBase {
/// perform the given `action` on the [SemanticsNode] specified by /// perform the given `action` on the [SemanticsNode] specified by
/// [SemanticsActionEvent.nodeId]. /// [SemanticsActionEvent.nodeId].
/// ///
/// See [dart:ui.PlatformDispatcher.onSemanticsAction]. /// See [dart:ui.PlatformDispatcher.onSemanticsActionEvent].
@protected @protected
void performSemanticsAction(SemanticsActionEvent action); void performSemanticsAction(ui.SemanticsActionEvent action);
/// The currently active set of [AccessibilityFeatures]. /// The currently active set of [AccessibilityFeatures].
/// ///
...@@ -180,27 +180,6 @@ mixin SemanticsBinding on BindingBase { ...@@ -180,27 +180,6 @@ mixin SemanticsBinding on BindingBase {
} }
} }
/// An event to request a [SemanticsAction] of [type] to be performed on the
/// [SemanticsNode] identified by [nodeId].
///
/// Used by [SemanticsBinding.performSemanticsAction].
@immutable
class SemanticsActionEvent {
/// Creates a [SemanticsActionEvent].
///
/// The [type] and [nodeId] are required.
const SemanticsActionEvent({required this.type, required this.nodeId, this.arguments});
/// The type of action to be performed.
final ui.SemanticsAction type;
/// The id of the [SemanticsNode] on which the action is to be performed.
final int nodeId;
/// Optional arguments for the action.
final Object? arguments;
}
/// A reference to the semantics information generated by the framework. /// A reference to the semantics information generated by the framework.
/// ///
/// Semantics information are only collected when there are clients interested /// Semantics information are only collected when there are clients interested
......
...@@ -42,6 +42,7 @@ void main() { ...@@ -42,6 +42,7 @@ void main() {
tester.binding.performSemanticsAction(SemanticsActionEvent( tester.binding.performSemanticsAction(SemanticsActionEvent(
type: SemanticsAction.showOnScreen, type: SemanticsAction.showOnScreen,
nodeId: nodeId, nodeId: nodeId,
viewId: tester.view.viewId,
)); ));
semantics.dispose(); semantics.dispose();
}); });
......
...@@ -395,10 +395,10 @@ class TestPlatformDispatcher implements PlatformDispatcher { ...@@ -395,10 +395,10 @@ class TestPlatformDispatcher implements PlatformDispatcher {
} }
@override @override
SemanticsActionCallback? get onSemanticsAction => _platformDispatcher.onSemanticsAction; SemanticsActionEventCallback? get onSemanticsActionEvent => _platformDispatcher.onSemanticsActionEvent;
@override @override
set onSemanticsAction(SemanticsActionCallback? callback) { set onSemanticsActionEvent(SemanticsActionEventCallback? callback) {
_platformDispatcher.onSemanticsAction = callback; _platformDispatcher.onSemanticsActionEvent = callback;
} }
@override @override
...@@ -1880,23 +1880,6 @@ class TestWindow implements SingletonFlutterWindow { ...@@ -1880,23 +1880,6 @@ class TestWindow implements SingletonFlutterWindow {
platformDispatcher.onSemanticsEnabledChanged = callback; platformDispatcher.onSemanticsEnabledChanged = callback;
} }
@Deprecated(
'Use WidgetTester.platformDispatcher.onSemanticsAction instead. '
'Deprecated to prepare for the upcoming multi-window support. '
'This feature was deprecated after v3.9.0-0.1.pre.'
)
@override
SemanticsActionCallback? get onSemanticsAction => platformDispatcher.onSemanticsAction;
@Deprecated(
'Use WidgetTester.platformDispatcher.onSemanticsAction instead. '
'Deprecated to prepare for the upcoming multi-window support. '
'This feature was deprecated after v3.9.0-0.1.pre.'
)
@override
set onSemanticsAction(SemanticsActionCallback? callback) {
platformDispatcher.onSemanticsAction = callback;
}
@Deprecated( @Deprecated(
'Use WidgetTester.platformDispatcher.accessibilityFeatures instead. ' 'Use WidgetTester.platformDispatcher.accessibilityFeatures instead. '
'Deprecated to prepare for the upcoming multi-window support. ' 'Deprecated to prepare for the upcoming multi-window support. '
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment