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

Commit 999e5e5

Browse files
authored
Rebase all (#38855)
1 parent 7721881 commit 999e5e5

10 files changed

+139
-97
lines changed

shell/platform/darwin/macos/framework/Headers/FlutterEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Some single-view APIs will eventually be replaced by their multi-view
2424
* variant. During the deprecation period, the single-view APIs will coexist with
2525
* and work with the multi-view APIs as if the other views don't exist. For
26-
* backward compatibility, single-view APIs will always operate the view with
26+
* backward compatibility, single-view APIs will always operate on the view with
2727
* this ID. Also, the first view assigned to the engine will also have this ID.
2828
*/
2929
extern const uint64_t kFlutterDefaultViewId;

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

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ void DispatchMacOSNotification(gfx::NativeViewAccessible native_node,
3232
} // namespace
3333
} // namespace flutter::testing
3434

35-
@interface AccessibilityBridgeTestEngine : FlutterEngine
36-
- (std::shared_ptr<flutter::AccessibilityBridgeMac>)
37-
createAccessibilityBridge:(nonnull FlutterEngine*)engine
38-
viewController:(nonnull FlutterViewController*)viewController;
35+
@interface AccessibilityBridgeTestViewController : FlutterViewController
36+
- (std::shared_ptr<flutter::AccessibilityBridgeMac>)createAccessibilityBridgeWithEngine:
37+
(nonnull FlutterEngine*)engine;
3938
@end
4039

41-
@implementation AccessibilityBridgeTestEngine
42-
- (std::shared_ptr<flutter::AccessibilityBridgeMac>)
43-
createAccessibilityBridge:(nonnull FlutterEngine*)engine
44-
viewController:(nonnull FlutterViewController*)viewController {
45-
return std::make_shared<flutter::testing::AccessibilityBridgeMacSpy>(engine, viewController);
40+
@implementation AccessibilityBridgeTestViewController
41+
- (std::shared_ptr<flutter::AccessibilityBridgeMac>)createAccessibilityBridgeWithEngine:
42+
(nonnull FlutterEngine*)engine {
43+
return std::make_shared<flutter::testing::AccessibilityBridgeMacSpy>(engine, self);
4644
}
4745
@end
4846

@@ -56,10 +54,7 @@ @implementation AccessibilityBridgeTestEngine
5654
FlutterDartProject* project = [[FlutterDartProject alloc]
5755
initWithAssetsPath:fixtures
5856
ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
59-
FlutterEngine* engine = [[AccessibilityBridgeTestEngine alloc] initWithName:@"test"
60-
project:project
61-
allowHeadlessExecution:true];
62-
return [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
57+
return [[AccessibilityBridgeTestViewController alloc] initWithProject:project];
6358
}
6459
} // namespace
6560

@@ -76,8 +71,8 @@ @implementation AccessibilityBridgeTestEngine
7671
// Setting up bridge so that the AccessibilityBridgeMacDelegateSpy
7772
// can query semantics information from.
7873
engine.semanticsEnabled = YES;
79-
auto bridge =
80-
std::reinterpret_pointer_cast<AccessibilityBridgeMacSpy>(engine.accessibilityBridge.lock());
74+
auto bridge = std::reinterpret_pointer_cast<AccessibilityBridgeMacSpy>(
75+
viewController.accessibilityBridge.lock());
8176
FlutterSemanticsNode root;
8277
root.id = 0;
8378
root.flags = static_cast<FlutterSemanticsFlag>(0);
@@ -124,8 +119,8 @@ @implementation AccessibilityBridgeTestEngine
124119
// Setting up bridge so that the AccessibilityBridgeMacDelegateSpy
125120
// can query semantics information from.
126121
engine.semanticsEnabled = YES;
127-
auto bridge =
128-
std::reinterpret_pointer_cast<AccessibilityBridgeMacSpy>(engine.accessibilityBridge.lock());
122+
auto bridge = std::reinterpret_pointer_cast<AccessibilityBridgeMacSpy>(
123+
viewController.accessibilityBridge.lock());
129124
FlutterSemanticsNode root;
130125
root.id = 0;
131126
root.flags = static_cast<FlutterSemanticsFlag>(0);
@@ -171,8 +166,8 @@ @implementation AccessibilityBridgeTestEngine
171166
// Setting up bridge so that the AccessibilityBridgeMacDelegateSpy
172167
// can query semantics information from.
173168
engine.semanticsEnabled = YES;
174-
auto bridge =
175-
std::reinterpret_pointer_cast<AccessibilityBridgeMacSpy>(engine.accessibilityBridge.lock());
169+
auto bridge = std::reinterpret_pointer_cast<AccessibilityBridgeMacSpy>(
170+
viewController.accessibilityBridge.lock());
176171
FlutterSemanticsNode root;
177172
root.id = 0;
178173
root.flags = static_cast<FlutterSemanticsFlag>(0);

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

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,6 @@ @implementation FlutterEngine {
194194
// The embedding-API-level engine object.
195195
FLUTTER_API_SYMBOL(FlutterEngine) _engine;
196196

197-
// The private member for accessibility.
198-
std::shared_ptr<flutter::AccessibilityBridgeMac> _bridge;
199-
200197
// The project being run by this engine.
201198
FlutterDartProject* _project;
202199

@@ -315,7 +312,7 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
315312
flutterArguments.update_semantics_callback = [](const FlutterSemanticsUpdate* update,
316313
void* user_data) {
317314
FlutterEngine* engine = (__bridge FlutterEngine*)user_data;
318-
[engine updateSemantics:update];
315+
[engine.viewController updateSemantics:update];
319316
};
320317
flutterArguments.custom_dart_entrypoint = entrypoint.UTF8String;
321318
flutterArguments.shutdown_dart_vm_when_done = true;
@@ -543,10 +540,6 @@ - (void)sendInitialSettings {
543540
return _embedderAPI;
544541
}
545542

546-
- (std::weak_ptr<flutter::AccessibilityBridgeMac>)accessibilityBridge {
547-
return _bridge;
548-
}
549-
550543
- (nonnull NSString*)executableName {
551544
return [[[NSProcessInfo processInfo] arguments] firstObject] ?: @"Flutter";
552545
}
@@ -586,24 +579,10 @@ - (void)setSemanticsEnabled:(BOOL)enabled {
586579
return;
587580
}
588581
_semanticsEnabled = enabled;
589-
// Remove the accessibility children from flutter view before reseting the bridge.
590-
if (!_semanticsEnabled && self.viewController.viewLoaded) {
591-
self.viewController.flutterView.accessibilityChildren = nil;
592-
}
593-
if (!_semanticsEnabled && _bridge) {
594-
_bridge.reset();
595-
} else if (_semanticsEnabled && !_bridge) {
596-
_bridge = [self createAccessibilityBridge:self viewController:self.viewController];
597-
}
582+
[_viewController notifySemanticsEnabledChanged];
598583
_embedderAPI.UpdateSemanticsEnabled(_engine, _semanticsEnabled);
599584
}
600585

601-
- (std::shared_ptr<flutter::AccessibilityBridgeMac>)
602-
createAccessibilityBridge:(nonnull FlutterEngine*)engine
603-
viewController:(nonnull FlutterViewController*)viewController {
604-
return std::make_shared<flutter::AccessibilityBridgeMac>(engine, _viewController);
605-
}
606-
607586
- (void)dispatchSemanticsAction:(FlutterSemanticsAction)action
608587
toTarget:(uint16_t)target
609588
withData:(fml::MallocMapping)data {
@@ -939,36 +918,6 @@ - (BOOL)unregisterTextureWithID:(int64_t)textureID {
939918
return _embedderAPI.UnregisterExternalTexture(_engine, textureID) == kSuccess;
940919
}
941920

942-
- (void)updateSemantics:(const FlutterSemanticsUpdate*)update {
943-
NSAssert(_bridge, @"The accessibility bridge must be initialized.");
944-
for (size_t i = 0; i < update->nodes_count; i++) {
945-
const FlutterSemanticsNode* node = &update->nodes[i];
946-
_bridge->AddFlutterSemanticsNodeUpdate(node);
947-
}
948-
949-
for (size_t i = 0; i < update->custom_actions_count; i++) {
950-
const FlutterSemanticsCustomAction* action = &update->custom_actions[i];
951-
_bridge->AddFlutterSemanticsCustomActionUpdate(action);
952-
}
953-
954-
_bridge->CommitUpdates();
955-
956-
// Accessibility tree can only be used when the view is loaded.
957-
if (!self.viewController.viewLoaded) {
958-
return;
959-
}
960-
// Attaches the accessibility root to the flutter view.
961-
auto root = _bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
962-
if (root) {
963-
if ([self.viewController.flutterView.accessibilityChildren count] == 0) {
964-
NSAccessibilityElement* native_root = root->GetNativeViewAccessible();
965-
self.viewController.flutterView.accessibilityChildren = @[ native_root ];
966-
}
967-
} else {
968-
self.viewController.flutterView.accessibilityChildren = nil;
969-
}
970-
}
971-
972921
#pragma mark - Task runner integration
973922

974923
- (void)runTaskOnEmbedder:(FlutterTask)task {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,31 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
348348
EXPECT_EQ(engine.viewController, nil);
349349
}
350350

351+
TEST_F(FlutterEngineTest, ProducesAccessibilityTreeWhenAddingViews) {
352+
FlutterEngine* engine = GetFlutterEngine();
353+
EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
354+
355+
// Enable the semantics without attaching a view controller.
356+
bool enabled_called = false;
357+
engine.embedderAPI.UpdateSemanticsEnabled =
358+
MOCK_ENGINE_PROC(UpdateSemanticsEnabled, ([&enabled_called](auto engine, bool enabled) {
359+
enabled_called = enabled;
360+
return kSuccess;
361+
}));
362+
engine.semanticsEnabled = YES;
363+
EXPECT_TRUE(enabled_called);
364+
365+
EXPECT_EQ(engine.viewController, nil);
366+
367+
// Assign the view controller after enabling semantics
368+
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
369+
nibName:nil
370+
bundle:nil];
371+
engine.viewController = viewController;
372+
373+
EXPECT_NE(viewController.accessibilityBridge.lock(), nullptr);
374+
}
375+
351376
TEST_F(FlutterEngineTest, NativeCallbacks) {
352377
fml::AutoResetWaitableEvent latch;
353378
bool latch_called = false;

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
*/
3232
@property(nonatomic) FlutterEngineProcTable& embedderAPI;
3333

34-
@property(nonatomic, readonly) std::weak_ptr<flutter::AccessibilityBridgeMac> accessibilityBridge;
35-
3634
/**
3735
* True if the semantics is enabled. The Flutter framework starts sending
3836
* semantics update through the embedder as soon as it is set to YES.
@@ -94,14 +92,3 @@
9492
withData:(fml::MallocMapping)data;
9593

9694
@end
97-
98-
@interface FlutterEngine (TestMethods)
99-
/* Creates an accessibility bridge with the provided parameters.
100-
*
101-
* By default this method calls AccessibilityBridgeMac's initializer. Exposing
102-
* this method allows unit tests to override in order to capture information.
103-
*/
104-
- (std::shared_ptr<flutter::AccessibilityBridgeMac>)
105-
createAccessibilityBridge:(nonnull FlutterEngine*)engine
106-
viewController:(nonnull FlutterViewController*)viewController;
107-
@end

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
FlutterViewController* viewController = CreateTestViewController();
3434
FlutterEngine* engine = viewController.engine;
3535
engine.semanticsEnabled = YES;
36-
auto bridge = engine.accessibilityBridge.lock();
36+
auto bridge = viewController.accessibilityBridge.lock();
3737
// Initialize ax node data.
3838
FlutterSemanticsNode root;
3939
root.id = 0;
@@ -69,7 +69,7 @@
6969
FlutterViewController* viewController = CreateTestViewController();
7070
FlutterEngine* engine = viewController.engine;
7171
engine.semanticsEnabled = YES;
72-
auto bridge = engine.accessibilityBridge.lock();
72+
auto bridge = viewController.accessibilityBridge.lock();
7373
// Initialize ax node data.
7474
FlutterSemanticsNode root;
7575
root.id = 0;
@@ -111,7 +111,7 @@
111111
FlutterViewController* viewController = CreateTestViewController();
112112
FlutterEngine* engine = viewController.engine;
113113
engine.semanticsEnabled = YES;
114-
auto bridge = engine.accessibilityBridge.lock();
114+
auto bridge = viewController.accessibilityBridge.lock();
115115
// Initialize ax node data.
116116
FlutterSemanticsNode root;
117117
root.id = 0;
@@ -158,7 +158,7 @@
158158
window.contentView = viewController.view;
159159

160160
engine.semanticsEnabled = YES;
161-
auto bridge = engine.accessibilityBridge.lock();
161+
auto bridge = viewController.accessibilityBridge.lock();
162162
// Initialize ax node data.
163163
FlutterSemanticsNode root;
164164
root.id = 0;
@@ -233,7 +233,7 @@
233233
window.contentView = viewController.view;
234234
engine.semanticsEnabled = YES;
235235

236-
auto bridge = engine.accessibilityBridge.lock();
236+
auto bridge = viewController.accessibilityBridge.lock();
237237
// Initialize ax node data.
238238
FlutterSemanticsNode root;
239239
root.id = 0;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,14 +1414,14 @@ - (bool)testSelectorsAreForwardedToFramework {
14141414

14151415
engine.semanticsEnabled = YES;
14161416

1417-
auto bridge = engine.accessibilityBridge.lock();
1417+
auto bridge = viewController.accessibilityBridge.lock();
14181418
FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
14191419
ui::AXTree tree;
14201420
ui::AXNode ax_node(&tree, nullptr, 0, 0);
14211421
ui::AXNodeData node_data;
14221422
node_data.SetValue("initial text");
14231423
ax_node.SetData(node_data);
1424-
delegate.Init(engine.accessibilityBridge, &ax_node);
1424+
delegate.Init(viewController.accessibilityBridge, &ax_node);
14251425
{
14261426
FlutterTextPlatformNode text_platform_node(&delegate, viewController);
14271427

@@ -1480,14 +1480,14 @@ - (bool)testSelectorsAreForwardedToFramework {
14801480

14811481
engine.semanticsEnabled = YES;
14821482

1483-
auto bridge = engine.accessibilityBridge.lock();
1483+
auto bridge = viewController.accessibilityBridge.lock();
14841484
FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
14851485
ui::AXTree tree;
14861486
ui::AXNode ax_node(&tree, nullptr, 0, 0);
14871487
ui::AXNodeData node_data;
14881488
node_data.SetValue("initial text");
14891489
ax_node.SetData(node_data);
1490-
delegate.Init(engine.accessibilityBridge, &ax_node);
1490+
delegate.Init(viewController.accessibilityBridge, &ax_node);
14911491
FlutterTextPlatformNode text_platform_node(&delegate, viewController);
14921492

14931493
FlutterTextField* textField = text_platform_node.GetNativeViewAccessible();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141

4242
engine.semanticsEnabled = YES;
4343

44-
auto bridge = engine.accessibilityBridge.lock();
44+
auto bridge = viewController.accessibilityBridge.lock();
4545
FlutterPlatformNodeDelegateMac delegate(bridge, viewController);
4646
ui::AXTree tree;
4747
ui::AXNode ax_node(&tree, nullptr, 0, 0);
4848
ui::AXNodeData node_data;
4949
node_data.SetValue("initial text");
5050
ax_node.SetData(node_data);
51-
delegate.Init(engine.accessibilityBridge, &ax_node);
51+
delegate.Init(viewController.accessibilityBridge, &ax_node);
5252
// Verify that a FlutterTextField is attached to the view.
5353
FlutterTextPlatformNode text_platform_node(&delegate, viewController);
5454
id native_accessibility = text_platform_node.GetNativeViewAccessible();

0 commit comments

Comments
 (0)