Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1fe1ec4

Browse files
authored
Clarify semantics action dispatch id parameter (#38356)
Previously the embedder API documented this as an action ID, but it's actually the semantics node ID. This fixes the docs and renames the parameter to clarify its purpose. This callback is registered in the framework render bindings: https://github.com/flutter/flutter/blob/9102f2fe0bd26db6074ac4a17785296cd341ecb9/packages/flutter/lib/src/rendering/binding.dart#L43 Handled by `_handleSemanticsAction`: https://github.com/flutter/flutter/blob/9102f2fe0bd26db6074ac4a17785296cd341ecb9/packages/flutter/lib/src/rendering/binding.dart#L360-L366 Which invokes `SemanticsOwner.performAction`, where the node is looked up by ID: https://github.com/flutter/flutter/blob/9102f2fe0bd26db6074ac4a17785296cd341ecb9/packages/flutter/lib/src/semantics/semantics.dart#L3258-L3277
1 parent d91e208 commit 1fe1ec4

20 files changed

+54
-48
lines changed

lib/ui/hooks.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ void _dispatchPointerDataPacket(ByteData packet) {
9292
}
9393

9494
@pragma('vm:entry-point')
95-
void _dispatchSemanticsAction(int id, int action, ByteData? args) {
96-
PlatformDispatcher.instance._dispatchSemanticsAction(id, action, args);
95+
void _dispatchSemanticsAction(int nodeId, int action, ByteData? args) {
96+
PlatformDispatcher.instance._dispatchSemanticsAction(nodeId, action, args);
9797
}
9898

9999
@pragma('vm:entry-point')

lib/ui/platform_dispatcher.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef PointerDataPacketCallback = void Function(PointerDataPacket packet);
3333
typedef KeyDataCallback = bool Function(KeyData data);
3434

3535
/// Signature for [PlatformDispatcher.onSemanticsAction].
36-
typedef SemanticsActionCallback = void Function(int id, SemanticsAction action, ByteData? args);
36+
typedef SemanticsActionCallback = void Function(int nodeId, SemanticsAction action, ByteData? args);
3737

3838
/// Signature for responses to platform messages.
3939
///
@@ -1089,10 +1089,10 @@ class PlatformDispatcher {
10891089
}
10901090

10911091
/// A callback that is invoked whenever the user requests an action to be
1092-
/// performed.
1092+
/// performed on a semantics node.
10931093
///
10941094
/// This callback is used when the user expresses the action they wish to
1095-
/// perform based on the semantics supplied by updateSemantics.
1095+
/// perform based on the semantics node supplied by updateSemantics.
10961096
///
10971097
/// The framework invokes this callback in the same zone in which the
10981098
/// callback was set.
@@ -1128,11 +1128,11 @@ class PlatformDispatcher {
11281128
}
11291129

11301130
// Called from the engine, via hooks.dart
1131-
void _dispatchSemanticsAction(int id, int action, ByteData? args) {
1131+
void _dispatchSemanticsAction(int nodeId, int action, ByteData? args) {
11321132
_invoke3<int, SemanticsAction, ByteData?>(
11331133
onSemanticsAction,
11341134
_onSemanticsActionZone,
1135-
id,
1135+
nodeId,
11361136
SemanticsAction.values[action]!,
11371137
args,
11381138
);

lib/ui/window/platform_configuration.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void PlatformConfiguration::DispatchPlatformMessage(
171171
tonic::ToDart(response_id)}));
172172
}
173173

174-
void PlatformConfiguration::DispatchSemanticsAction(int32_t id,
174+
void PlatformConfiguration::DispatchSemanticsAction(int32_t node_id,
175175
SemanticsAction action,
176176
fml::MallocMapping args) {
177177
std::shared_ptr<tonic::DartState> dart_state =
@@ -190,7 +190,7 @@ void PlatformConfiguration::DispatchSemanticsAction(int32_t id,
190190

191191
tonic::CheckAndHandleError(tonic::DartInvoke(
192192
dispatch_semantics_action_.Get(),
193-
{tonic::ToDart(id), tonic::ToDart(static_cast<int32_t>(action)),
193+
{tonic::ToDart(node_id), tonic::ToDart(static_cast<int32_t>(action)),
194194
args_handle}));
195195
}
196196

lib/ui/window/platform_configuration.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,12 @@ class PlatformConfiguration final {
325325
/// originates on the platform view and has been forwarded to the
326326
/// platform configuration here by the engine.
327327
///
328-
/// @param[in] id The identifier of the accessibility node.
328+
/// @param[in] node_id The identifier of the accessibility node.
329329
/// @param[in] action The accessibility related action performed on the
330330
/// node of the specified ID.
331331
/// @param[in] args Optional data that applies to the specified action.
332332
///
333-
void DispatchSemanticsAction(int32_t id,
333+
void DispatchSemanticsAction(int32_t node_id,
334334
SemanticsAction action,
335335
fml::MallocMapping args);
336336

lib/web_ui/lib/platform_dispatcher.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ typedef FrameCallback = void Function(Duration duration);
99
typedef TimingsCallback = void Function(List<FrameTiming> timings);
1010
typedef PointerDataPacketCallback = void Function(PointerDataPacket packet);
1111
typedef KeyDataCallback = bool Function(KeyData data);
12-
typedef SemanticsActionCallback = void Function(int id, SemanticsAction action, ByteData? args);
12+
typedef SemanticsActionCallback = void Function(int nodeId, SemanticsAction action, ByteData? args);
1313
typedef PlatformMessageResponseCallback = void Function(ByteData? data);
1414
typedef PlatformMessageCallback = void Function(
1515
String name, ByteData? data, PlatformMessageResponseCallback? callback);

lib/web_ui/lib/src/engine/platform_dispatcher.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,9 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
10841084
/// Engine code should use this method instead of the callback directly.
10851085
/// Otherwise zones won't work properly.
10861086
void invokeOnSemanticsAction(
1087-
int id, ui.SemanticsAction action, ByteData? args) {
1087+
int nodeId, ui.SemanticsAction action, ByteData? args) {
10881088
invoke3<int, ui.SemanticsAction, ByteData?>(
1089-
_onSemanticsAction, _onSemanticsActionZone, id, action, args);
1089+
_onSemanticsAction, _onSemanticsActionZone, nodeId, action, args);
10901090
}
10911091

10921092
// TODO(dnfield): make this work on web.

runtime/runtime_controller.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ bool RuntimeController::DispatchPointerDataPacket(
278278
return false;
279279
}
280280

281-
bool RuntimeController::DispatchSemanticsAction(int32_t id,
281+
bool RuntimeController::DispatchSemanticsAction(int32_t node_id,
282282
SemanticsAction action,
283283
fml::MallocMapping args) {
284284
TRACE_EVENT1("flutter", "RuntimeController::DispatchSemanticsAction", "mode",
285285
"basic");
286286
if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
287-
platform_configuration->DispatchSemanticsAction(id, action,
287+
platform_configuration->DispatchSemanticsAction(node_id, action,
288288
std::move(args));
289289
return true;
290290
}

runtime/runtime_controller.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,15 @@ class RuntimeController : public PlatformConfigurationClient {
407407
/// @brief Dispatch the semantics action to the specified accessibility
408408
/// node.
409409
///
410-
/// @param[in] id The identified of the accessibility node.
410+
/// @param[in] node_id The identified of the accessibility node.
411411
/// @param[in] action The semantics action to perform on the specified
412412
/// accessibility node.
413413
/// @param[in] args Optional data that applies to the specified action.
414414
///
415415
/// @return If the semantics action was dispatched. This may fail if an
416416
/// isolate is not running.
417417
///
418-
bool DispatchSemanticsAction(int32_t id,
418+
bool DispatchSemanticsAction(int32_t node_id,
419419
SemanticsAction action,
420420
fml::MallocMapping args);
421421

shell/common/engine.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,11 @@ void Engine::DispatchPointerDataPacket(
416416
pointer_data_dispatcher_->DispatchPacket(std::move(packet), trace_flow_id);
417417
}
418418

419-
void Engine::DispatchSemanticsAction(int id,
419+
void Engine::DispatchSemanticsAction(int node_id,
420420
SemanticsAction action,
421421
fml::MallocMapping args) {
422-
runtime_controller_->DispatchSemanticsAction(id, action, std::move(args));
422+
runtime_controller_->DispatchSemanticsAction(node_id, action,
423+
std::move(args));
423424
}
424425

425426
void Engine::SetSemanticsEnabled(bool enabled) {

shell/common/engine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,12 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
722722
/// originates on the platform view and has been forwarded to the
723723
/// engine here on the UI task runner by the shell.
724724
///
725-
/// @param[in] id The identifier of the accessibility node.
725+
/// @param[in] node_id The identifier of the accessibility node.
726726
/// @param[in] action The accessibility related action performed on the
727727
/// node of the specified ID.
728728
/// @param[in] args Optional data that applies to the specified action.
729729
///
730-
void DispatchSemanticsAction(int id,
730+
void DispatchSemanticsAction(int node_id,
731731
SemanticsAction action,
732732
fml::MallocMapping args);
733733

0 commit comments

Comments
 (0)