Browse Source

Add parent/automationPeer null guards on AvnWindow (#19805)

* Add parent/automationPeer null guards on AvnWindow

* Add null guards on AvnView
pull/19808/head
Jumar Macato 12 months ago
committed by GitHub
parent
commit
67a88afb5d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      native/Avalonia.Native/src/OSX/AvnView.mm
  2. 20
      native/Avalonia.Native/src/OSX/AvnWindow.mm

6
native/Avalonia.Native/src/OSX/AvnView.mm

@ -943,7 +943,7 @@ static void ConvertTilt(NSPoint tilt, float* xTilt, float* yTilt)
auto window = (AvnWindow*)[self window]; auto window = (AvnWindow*)[self window];
auto peer = [window automationPeer]; auto peer = [window automationPeer];
if (!peer->IsRootProvider()) if (peer == nullptr || !peer->IsRootProvider())
return nil; return nil;
auto clientPoint = [window convertPointFromScreen:point]; auto clientPoint = [window convertPointFromScreen:point];
@ -980,6 +980,10 @@ static void ConvertTilt(NSPoint tilt, float* xTilt, float* yTilt)
// of the AvnView. // of the AvnView.
auto window = (AvnWindow*)[self window]; auto window = (AvnWindow*)[self window];
auto peer = [window automationPeer]; auto peer = [window automationPeer];
if (peer == nullptr)
{
return;
}
auto childPeers = peer->GetChildren(); auto childPeers = peer->GetChildren();
auto childCount = childPeers != nullptr ? childPeers->GetCount() : 0; auto childCount = childPeers != nullptr ? childPeers->GetCount() : 0;

20
native/Avalonia.Native/src/OSX/AvnWindow.mm

@ -605,21 +605,30 @@
- (id _Nullable) accessibilityFocusedUIElement - (id _Nullable) accessibilityFocusedUIElement
{ {
if (![self automationPeer]->IsRootProvider()) auto automationPeer = [self automationPeer];
if (automationPeer == nullptr || !automationPeer->IsRootProvider())
return nil; return nil;
auto focusedPeer = [self automationPeer]->RootProvider_GetFocus();
auto focusedPeer = automationPeer->RootProvider_GetFocus();
if (focusedPeer == nullptr)
return nil;
return [AvnAccessibilityElement acquire:focusedPeer]; return [AvnAccessibilityElement acquire:focusedPeer];
} }
- (NSString * _Nullable) accessibilityIdentifier - (NSString * _Nullable) accessibilityIdentifier
{ {
return GetNSStringAndRelease([self automationPeer]->GetAutomationId()); auto automationPeer = [self automationPeer];
if (automationPeer == nullptr)
return nil;
return GetNSStringAndRelease(automationPeer->GetAutomationId());
} }
- (IAvnAutomationPeer* _Nonnull) automationPeer - (IAvnAutomationPeer* _Nonnull) automationPeer
{ {
auto parent = _parent.tryGet(); auto parent = _parent.tryGet();
if (_automationPeer == nullptr) if (parent && _automationPeer == nullptr)
{ {
_automationPeer = parent->BaseEvents->GetAutomationPeer(); _automationPeer = parent->BaseEvents->GetAutomationPeer();
_automationNode = new AvnAutomationNode(self); _automationNode = new AvnAutomationNode(self);
@ -632,7 +641,8 @@
- (void)raiseChildrenChanged - (void)raiseChildrenChanged
{ {
auto parent = _parent.tryGet(); auto parent = _parent.tryGet();
[parent->View raiseAccessibilityChildrenChanged]; if(parent)
[parent->View raiseAccessibilityChildrenChanged];
} }
- (void)raiseFocusChanged - (void)raiseFocusChanged

Loading…
Cancel
Save