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

Commit d6a2c0a

Browse files
authored
[macOS] Use the new update semantics embedder API (#40584)
[macOS] Use the new update semantics embedder API
1 parent 6dbeb10 commit d6a2c0a

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

shell/platform/darwin/macos/framework/Source/FlutterEngine.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
455455
flutterArguments.command_line_argc = static_cast<int>(argv.size());
456456
flutterArguments.command_line_argv = argv.empty() ? nullptr : argv.data();
457457
flutterArguments.platform_message_callback = (FlutterPlatformMessageCallback)OnPlatformMessage;
458-
flutterArguments.update_semantics_callback = [](const FlutterSemanticsUpdate* update,
459-
void* user_data) {
458+
flutterArguments.update_semantics_callback2 = [](const FlutterSemanticsUpdate2* update,
459+
void* user_data) {
460460
// TODO(dkwingsmt): This callback only supports single-view, therefore it
461461
// only operates on the default view. To support multi-view, we need a
462462
// way to pass in the ID (probably through FlutterSemanticsUpdate).

shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
198198
FlutterEngine* engine = GetFlutterEngine();
199199
// Capture the update callbacks before the embedder API initializes.
200200
auto original_init = engine.embedderAPI.Initialize;
201-
std::function<void(const FlutterSemanticsUpdate*, void*)> update_semantics_callback;
201+
std::function<void(const FlutterSemanticsUpdate2*, void*)> update_semantics_callback;
202202
engine.embedderAPI.Initialize = MOCK_ENGINE_PROC(
203203
Initialize, ([&update_semantics_callback, &original_init](
204204
size_t version, const FlutterRendererConfig* config,
205205
const FlutterProjectArgs* args, void* user_data, auto engine_out) {
206-
update_semantics_callback = args->update_semantics_callback;
206+
update_semantics_callback = args->update_semantics_callback2;
207207
return original_init(version, config, args, user_data, engine_out);
208208
}));
209209
EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
@@ -222,7 +222,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
222222
engine.semanticsEnabled = YES;
223223
EXPECT_TRUE(enabled_called);
224224
// Send flutter semantics updates.
225-
FlutterSemanticsNode root;
225+
FlutterSemanticsNode2 root;
226226
root.id = 0;
227227
root.flags = static_cast<FlutterSemanticsFlag>(0);
228228
root.actions = static_cast<FlutterSemanticsAction>(0);
@@ -239,7 +239,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
239239
root.children_in_traversal_order = children;
240240
root.custom_accessibility_actions_count = 0;
241241

242-
FlutterSemanticsNode child1;
242+
FlutterSemanticsNode2 child1;
243243
child1.id = 1;
244244
child1.flags = static_cast<FlutterSemanticsFlag>(0);
245245
child1.actions = static_cast<FlutterSemanticsAction>(0);
@@ -254,11 +254,11 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
254254
child1.child_count = 0;
255255
child1.custom_accessibility_actions_count = 0;
256256

257-
FlutterSemanticsUpdate update;
258-
update.nodes_count = 2;
259-
FlutterSemanticsNode nodes[] = {root, child1};
257+
FlutterSemanticsUpdate2 update;
258+
update.node_count = 2;
259+
FlutterSemanticsNode2* nodes[] = {&root, &child1};
260260
update.nodes = nodes;
261-
update.custom_actions_count = 0;
261+
update.custom_action_count = 0;
262262
update_semantics_callback(&update, (__bridge void*)engine);
263263

264264
// Verify the accessibility tree is attached to the flutter view.
@@ -292,12 +292,12 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
292292
FlutterEngine* engine = GetFlutterEngine();
293293
// Capture the update callbacks before the embedder API initializes.
294294
auto original_init = engine.embedderAPI.Initialize;
295-
std::function<void(const FlutterSemanticsUpdate*, void*)> update_semantics_callback;
295+
std::function<void(const FlutterSemanticsUpdate2*, void*)> update_semantics_callback;
296296
engine.embedderAPI.Initialize = MOCK_ENGINE_PROC(
297297
Initialize, ([&update_semantics_callback, &original_init](
298298
size_t version, const FlutterRendererConfig* config,
299299
const FlutterProjectArgs* args, void* user_data, auto engine_out) {
300-
update_semantics_callback = args->update_semantics_callback;
300+
update_semantics_callback = args->update_semantics_callback2;
301301
return original_init(version, config, args, user_data, engine_out);
302302
}));
303303
EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
@@ -312,7 +312,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
312312
engine.semanticsEnabled = YES;
313313
EXPECT_TRUE(enabled_called);
314314
// Send flutter semantics updates.
315-
FlutterSemanticsNode root;
315+
FlutterSemanticsNode2 root;
316316
root.id = 0;
317317
root.flags = static_cast<FlutterSemanticsFlag>(0);
318318
root.actions = static_cast<FlutterSemanticsAction>(0);
@@ -329,7 +329,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
329329
root.children_in_traversal_order = children;
330330
root.custom_accessibility_actions_count = 0;
331331

332-
FlutterSemanticsNode child1;
332+
FlutterSemanticsNode2 child1;
333333
child1.id = 1;
334334
child1.flags = static_cast<FlutterSemanticsFlag>(0);
335335
child1.actions = static_cast<FlutterSemanticsAction>(0);
@@ -344,11 +344,11 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
344344
child1.child_count = 0;
345345
child1.custom_accessibility_actions_count = 0;
346346

347-
FlutterSemanticsUpdate update;
348-
update.nodes_count = 2;
349-
FlutterSemanticsNode nodes[] = {root, child1};
347+
FlutterSemanticsUpdate2 update;
348+
update.node_count = 2;
349+
FlutterSemanticsNode2* nodes[] = {&root, &child1};
350350
update.nodes = nodes;
351-
update.custom_actions_count = 0;
351+
update.custom_action_count = 0;
352352
// This call updates semantics for the default view, which does not exist,
353353
// and therefore this call is invalid. But the engine should not crash.
354354
update_semantics_callback(&update, (__bridge void*)engine);

shell/platform/darwin/macos/framework/Source/FlutterViewController.mm

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,17 +498,19 @@ - (BOOL)attached {
498498
return _engine != nil;
499499
}
500500

501-
- (void)updateSemantics:(const FlutterSemanticsUpdate*)update {
501+
- (void)updateSemantics:(const FlutterSemanticsUpdate2*)update {
502502
NSAssert(_engine.semanticsEnabled, @"Semantics must be enabled.");
503503
if (!_engine.semanticsEnabled) {
504504
return;
505505
}
506-
for (size_t i = 0; i < update->nodes_count; i++) {
507-
_bridge->AddFlutterSemanticsNodeUpdate(update->nodes[i]);
506+
for (size_t i = 0; i < update->node_count; i++) {
507+
const FlutterSemanticsNode2* node = update->nodes[i];
508+
_bridge->AddFlutterSemanticsNodeUpdate(*node);
508509
}
509510

510-
for (size_t i = 0; i < update->custom_actions_count; i++) {
511-
_bridge->AddFlutterSemanticsCustomActionUpdate(update->custom_actions[i]);
511+
for (size_t i = 0; i < update->custom_action_count; i++) {
512+
const FlutterSemanticsCustomAction2* action = update->custom_actions[i];
513+
_bridge->AddFlutterSemanticsCustomActionUpdate(*action);
512514
}
513515

514516
_bridge->CommitUpdates();

shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* Notify from the framework that the semantics for this view needs to be
5353
* updated.
5454
*/
55-
- (void)updateSemantics:(nonnull const FlutterSemanticsUpdate*)update;
55+
- (void)updateSemantics:(nonnull const FlutterSemanticsUpdate2*)update;
5656

5757
@end
5858

0 commit comments

Comments
 (0)