Skip to content
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
9 changes: 5 additions & 4 deletions packages/flutter/lib/src/foundation/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,12 @@ abstract class BindingBase {
/// [BindingBase], e.g., [ServicesBinding], [RendererBinding], and
/// [WidgetsBinding]. Each of these bindings define behaviors that interact
/// with a [ui.PlatformDispatcher], e.g., [ServicesBinding] registers
/// listeners with the [ChannelBuffers], and [RendererBinding]
/// listeners with the [ChannelBuffers], [RendererBinding]
/// registers [ui.PlatformDispatcher.onMetricsChanged],
/// [ui.PlatformDispatcher.onTextScaleFactorChanged],
/// [ui.PlatformDispatcher.onSemanticsEnabledChanged], and
/// [ui.PlatformDispatcher.onSemanticsAction] handlers.
/// [ui.PlatformDispatcher.onTextScaleFactorChanged], and [SemanticsBinding]
/// registers [ui.PlatformDispatcher.onSemanticsEnabledChanged],
/// [ui.PlatformDispatcher.onSemanticsActionEvent], and
/// [ui.PlatformDispatcher.onAccessibilityFeaturesChanged] handlers.
///
/// Each of these other bindings could individually access a
/// [ui.PlatformDispatcher] statically, but that would preclude the ability to
Expand Down
43 changes: 11 additions & 32 deletions packages/flutter/lib/src/semantics/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// 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/services.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.
mixin SemanticsBinding on BindingBase {
Expand All @@ -20,7 +20,7 @@ mixin SemanticsBinding on BindingBase {
_accessibilityFeatures = platformDispatcher.accessibilityFeatures;
platformDispatcher
..onSemanticsEnabledChanged = _handleSemanticsEnabledChanged
..onSemanticsAction = _handleSemanticsAction
..onSemanticsActionEvent = _handleSemanticsActionEvent
..onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged;
_handleSemanticsEnabledChanged();
}
Expand Down Expand Up @@ -111,12 +111,12 @@ mixin SemanticsBinding on BindingBase {
}
}

void _handleSemanticsAction(int id, ui.SemanticsAction action, ByteData? args) {
performSemanticsAction(SemanticsActionEvent(
nodeId: id,
type: action,
arguments: args != null ? const StandardMessageCodec().decodeMessage(args) : null,
));
void _handleSemanticsActionEvent(ui.SemanticsActionEvent action) {
final Object? arguments = action.arguments;
final ui.SemanticsActionEvent decodedAction = arguments is ByteData
? action.copyWith(arguments: const StandardMessageCodec().decodeMessage(arguments))
: action;
performSemanticsAction(decodedAction);
}

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

/// The currently active set of [AccessibilityFeatures].
///
Expand Down Expand Up @@ -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.
///
/// Semantics information are only collected when there are clients interested
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/test/semantics/semantics_owner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void main() {
tester.binding.performSemanticsAction(SemanticsActionEvent(
type: SemanticsAction.showOnScreen,
nodeId: nodeId,
viewId: tester.view.viewId,
));
semantics.dispose();
});
Expand Down
23 changes: 3 additions & 20 deletions packages/flutter_test/lib/src/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ class TestPlatformDispatcher implements PlatformDispatcher {
}

@override
SemanticsActionCallback? get onSemanticsAction => _platformDispatcher.onSemanticsAction;
SemanticsActionEventCallback? get onSemanticsActionEvent => _platformDispatcher.onSemanticsActionEvent;
@override
set onSemanticsAction(SemanticsActionCallback? callback) {
_platformDispatcher.onSemanticsAction = callback;
set onSemanticsActionEvent(SemanticsActionEventCallback? callback) {
_platformDispatcher.onSemanticsActionEvent = callback;
}

@override
Expand Down Expand Up @@ -1880,23 +1880,6 @@ class TestWindow implements SingletonFlutterWindow {
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(
'Use WidgetTester.platformDispatcher.accessibilityFeatures instead. '
'Deprecated to prepare for the upcoming multi-window support. '
Expand Down