@@ -33,8 +33,12 @@ typedef PointerDataPacketCallback = void Function(PointerDataPacket packet);
3333typedef KeyDataCallback = bool Function (KeyData data);
3434
3535/// Signature for [PlatformDispatcher.onSemanticsAction] .
36+ // TODO(goderbauer): Deprecate/remove this when the framework has migrated to SemanticsActionEventCallback.
3637typedef SemanticsActionCallback = void Function (int nodeId, SemanticsAction action, ByteData ? args);
3738
39+ /// Signature for [PlatformDispatcher.onSemanticsActionEvent] .
40+ typedef SemanticsActionEventCallback = void Function (SemanticsActionEvent action);
41+
3842/// Signature for responses to platform messages.
3943///
4044/// Used as a parameter to [PlatformDispatcher.sendPlatformMessage] and
@@ -174,7 +178,11 @@ class PlatformDispatcher {
174178 ///
175179 /// If any of their configurations change, [onMetricsChanged] will be called.
176180 Iterable <FlutterView > get views => _views.values;
177- final Map <Object , FlutterView > _views = < Object , FlutterView > {};
181+ final Map <int , FlutterView > _views = < int , FlutterView > {};
182+
183+ /// Returns the [FlutterView] with the provided ID if one exists, or null
184+ /// otherwise.
185+ FlutterView ? view ({required int id}) => _views[id];
178186
179187 // A map of opaque platform view identifiers to view configurations.
180188 final Map <Object , _ViewConfiguration > _viewConfigurations = < Object , _ViewConfiguration > {};
@@ -250,7 +258,7 @@ class PlatformDispatcher {
250258 //
251259 // Updates the metrics of the window with the given id.
252260 void _updateWindowMetrics (
253- Object id,
261+ int id,
254262 double devicePixelRatio,
255263 double width,
256264 double height,
@@ -436,6 +444,7 @@ class PlatformDispatcher {
436444 for (int i = 0 ; i < length; ++ i) {
437445 int offset = i * _kPointerDataFieldCount;
438446 data.add (PointerData (
447+ // TODO(goderbauer): Wire up viewId.
439448 embedderId: packet.getInt64 (kStride * offset++ , _kFakeHostEndian),
440449 timeStamp: Duration (microseconds: packet.getInt64 (kStride * offset++ , _kFakeHostEndian)),
441450 change: PointerChange .values[packet.getInt64 (kStride * offset++ , _kFakeHostEndian)],
@@ -1150,6 +1159,7 @@ class PlatformDispatcher {
11501159 ///
11511160 /// The framework invokes this callback in the same zone in which the
11521161 /// callback was set.
1162+ // TODO(goderbauer): Deprecate/remove this when the framework has migrated to onSemanticsActionEvent.
11531163 SemanticsActionCallback ? get onSemanticsAction => _onSemanticsAction;
11541164 SemanticsActionCallback ? _onSemanticsAction;
11551165 Zone _onSemanticsActionZone = Zone .root;
@@ -1158,6 +1168,22 @@ class PlatformDispatcher {
11581168 _onSemanticsActionZone = Zone .current;
11591169 }
11601170
1171+ /// A callback that is invoked whenever the user requests an action to be
1172+ /// performed on a semantics node.
1173+ ///
1174+ /// This callback is used when the user expresses the action they wish to
1175+ /// perform based on the semantics node supplied by updateSemantics.
1176+ ///
1177+ /// The framework invokes this callback in the same zone in which the
1178+ /// callback was set.
1179+ SemanticsActionEventCallback ? get onSemanticsActionEvent => _onSemanticsActionEvent;
1180+ SemanticsActionEventCallback ? _onSemanticsActionEvent;
1181+ Zone _onSemanticsActionEventZone = Zone .root;
1182+ set onSemanticsActionEvent (SemanticsActionEventCallback ? callback) {
1183+ _onSemanticsActionEvent = callback;
1184+ _onSemanticsActionEventZone = Zone .current;
1185+ }
1186+
11611187 // Called from the engine via hooks.dart.
11621188 void _updateFrameData (int frameNumber) {
11631189 final FrameData previous = _frameData;
@@ -1190,6 +1216,16 @@ class PlatformDispatcher {
11901216 SemanticsAction .fromIndex (action)! ,
11911217 args,
11921218 );
1219+ _invoke1 <SemanticsActionEvent >(
1220+ onSemanticsActionEvent,
1221+ _onSemanticsActionEventZone,
1222+ SemanticsActionEvent (
1223+ type: SemanticsAction .fromIndex (action)! ,
1224+ nodeId: nodeId,
1225+ viewId: 0 , // TODO(goderbauer): Wire up the real view ID.
1226+ arguments: args,
1227+ ),
1228+ );
11931229 }
11941230
11951231 ErrorCallback ? _onError;
@@ -2350,3 +2386,49 @@ enum DartPerformanceMode {
23502386 /// frequently performing work.
23512387 memory,
23522388}
2389+
2390+ /// An event to request a [SemanticsAction] of [type] to be performed on the
2391+ /// [SemanticsNode] identified by [nodeId] owned by the [FlutterView] identified
2392+ /// by [viewId] .
2393+ ///
2394+ /// Used by [SemanticsBinding.performSemanticsAction] .
2395+ class SemanticsActionEvent {
2396+ /// Creates a [SemanticsActionEvent] .
2397+ const SemanticsActionEvent ({
2398+ required this .type,
2399+ required this .viewId,
2400+ required this .nodeId,
2401+ this .arguments,
2402+ });
2403+
2404+ /// The type of action to be performed.
2405+ final SemanticsAction type;
2406+
2407+ /// The id of the [FlutterView] the [SemanticsNode] identified by [nodeId] is
2408+ /// associated with.
2409+ final int viewId;
2410+
2411+ /// The id of the [SemanticsNode] on which the action is to be performed.
2412+ final int nodeId;
2413+
2414+ /// Optional arguments for the action.
2415+ final Object ? arguments;
2416+
2417+ static const Object _noArgumentPlaceholder = Object ();
2418+
2419+ /// Create a clone of the [SemanticsActionEvent] but with provided parameters
2420+ /// replaced.
2421+ SemanticsActionEvent copyWith ({
2422+ SemanticsAction ? type,
2423+ int ? viewId,
2424+ int ? nodeId,
2425+ Object ? arguments = _noArgumentPlaceholder,
2426+ }) {
2427+ return SemanticsActionEvent (
2428+ type: type ?? this .type,
2429+ viewId: viewId ?? this .viewId,
2430+ nodeId: nodeId ?? this .nodeId,
2431+ arguments: arguments == _noArgumentPlaceholder ? this .arguments : arguments,
2432+ );
2433+ }
2434+ }
0 commit comments