fix: Allow VoiceOver to navigate "back into" web contents (#24655)

* fix: Use ElectronAdaptedContentView

* fix: Actually, nevermind, it's "BrowserAccessebilityCocoa"

* chore: Remove things instead of manually keeping them
This commit is contained in:
Felix Rieseberg 2020-07-22 15:29:01 -07:00 committed by GitHub
parent 734753dd7a
commit b57f5086ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -121,29 +121,21 @@ bool ScopedDisableResize::disable_resize_ = false;
if (![attribute isEqualToString:@"AXChildren"])
return [super accessibilityAttributeValue:attribute];
// Filter out objects that aren't the title bar buttons. This has the effect
// of removing the window title, which VoiceOver already sees.
// We want to remove the window title (also known as
// NSAccessibilityReparentingCellProxy), which VoiceOver already sees.
// * when VoiceOver is disabled, this causes Cmd+C to be used for TTS but
// still leaves the buttons available in the accessibility tree.
// * when VoiceOver is enabled, the full accessibility tree is used.
// Without removing the title and with VO disabled, the TTS would always read
// the window title instead of using Cmd+C to get the selected text.
NSPredicate* predicate = [NSPredicate
predicateWithFormat:@"(self isKindOfClass: %@) OR (self.className == %@)",
[NSButtonCell class], @"RenderWidgetHostViewCocoa"];
NSPredicate* predicate =
[NSPredicate predicateWithFormat:@"(self.className != %@)",
@"NSAccessibilityReparentingCellProxy"];
NSArray* children = [super accessibilityAttributeValue:attribute];
NSMutableArray* mutableChildren = [[children mutableCopy] autorelease];
[mutableChildren filterUsingPredicate:predicate];
// We need to add the web contents: Without us doing so, VoiceOver
// users will be able to navigate up the a11y tree, but not back down.
// The content view contains the "web contents", which VoiceOver
// immediately understands.
NSView* contentView =
[shell_->GetNativeWindow().GetNativeNSWindow() contentView];
[mutableChildren addObject:contentView];
return mutableChildren;
}