diff --git a/native/Avalonia.Native/src/OSX/automation.mm b/native/Avalonia.Native/src/OSX/automation.mm index 4a11f85a5a..4e79d8af6e 100644 --- a/native/Avalonia.Native/src/OSX/automation.mm +++ b/native/Avalonia.Native/src/OSX/automation.mm @@ -242,27 +242,7 @@ private: - (NSArray *)accessibilityChildren { if (_children == nullptr && _peer != nullptr) - { - auto childPeers = _peer->GetChildren(); - auto childCount = childPeers != nullptr ? childPeers->GetCount() : 0; - - if (childCount > 0) - { - _children = [[NSMutableArray alloc] initWithCapacity:childCount]; - - for (int i = 0; i < childCount; ++i) - { - IAvnAutomationPeer* child; - - if (childPeers->Get(i, &child) == S_OK) - { - auto element = [AvnAccessibilityElement acquire:child]; - [_children addObject:element]; - } - } - } - } - + [self recalculateChildren]; return _children; } @@ -392,7 +372,17 @@ private: - (void)raiseChildrenChanged { - NSAccessibilityPostNotification(self, NSAccessibilityLayoutChangedNotification); + auto changed = _children ? [NSMutableSet setWithArray:_children] : [NSMutableSet set]; + + [self recalculateChildren]; + + if (_children) + [changed addObjectsFromArray:_children]; + + NSAccessibilityPostNotificationWithUserInfo( + self, + NSAccessibilityLayoutChangedNotification, + @{ NSAccessibilityUIElementsKey: [changed allObjects]}); } - (void)raisePropertyChanged @@ -405,6 +395,32 @@ private: _peer->SetFocus(); } +- (void)recalculateChildren +{ + auto childPeers = _peer->GetChildren(); + auto childCount = childPeers != nullptr ? childPeers->GetCount() : 0; + + if (childCount > 0) + { + _children = [[NSMutableArray alloc] initWithCapacity:childCount]; + + for (int i = 0; i < childCount; ++i) + { + IAvnAutomationPeer* child; + + if (childPeers->Get(i, &child) == S_OK) + { + auto element = [AvnAccessibilityElement acquire:child]; + [_children addObject:element]; + } + } + } + else + { + _children = nil; + } +} + @end @implementation AvnRootAccessibilityElement