-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement iOS VoiceOver support #18016
Open
IsaMorphic
wants to merge
35
commits into
AvaloniaUI:master
Choose a base branch
from
IsaMorphic:feature/ios-voiceover
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+388
−23
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
863e06c
Implement iOS VoiceOver support
IsaMorphic 709c212
Merge branch 'master' into feature/ios-voiceover
IsaMorphic e632ea7
Some investigation (it is not working)
87376b3
Progress
230a542
Functional prototype for iOS VoiceOver support
IsaMorphic ddff15a
Improved VoiceOver control function
bf9933d
Implement traits and accessibility actions for VoiceOver
IsaMorphic f9ed243
Merge branch 'master' into feature/ios-voiceover
IsaMorphic 9287158
Remove unused using statement
IsaMorphic a3df775
Default IsOffscreenBehavior should be based on IsEffectivelyVisible
IsaMorphic 5aa082c
Use most specific activation function first
IsaMorphic b0ac5ab
Merge branch 'master' into feature/ios-voiceover
IsaMorphic d627697
Ensure that offscreen UIAccessibilityElements are removed
IsaMorphic 1abc92b
Fix interrupted speech upon focusing element
IsaMorphic 093cfbd
Accessibility improvements based on tests with low vision users
IsaMorphic 9b28c9c
More improvements to iOS VoiceOver access
ccdf460
Final fixes for iOS VoiceOver
e4af6d2
Merge branch 'master' into feature/ios-voiceover
IsaMorphic c39f2c0
Merge branch 'master' into feature/ios-voiceover
IsaMorphic 173fcab
Merge branch 'master' into feature/ios-voiceover
IsaMorphic 8327938
Merge branch 'master' into feature/ios-voiceover
IsaMorphic 58bd060
Merge branch 'master' into feature/ios-voiceover
IsaMorphic 3cffb12
Add informative comments
IsaMorphic ae28f62
Merge branch 'master' into feature/ios-voiceover
IsaMorphic e6fb5e0
Merge branch 'master' into feature/ios-voiceover
IsaMorphic b11b5af
Implement review suggestions for iOS VoiceOver
IsaMorphic 2fb061f
Fixed bugs in determining whether controls are offscreen
IsaMorphic 1e33213
Ensure that AutomationPeer children are updated
IsaMorphic 0b12e0f
Fix failing tests for IsEffectivelyVisible & CompositorHitTesting
IsaMorphic 0abc5b5
Merge branch 'master' into feature/ios-voiceover
IsaMorphic 6d37a96
Merge branch 'master' into feature/ios-voiceover
IsaMorphic 254313c
Merge branch 'master' into feature/ios-voiceover
IsaMorphic eccdba6
Merge branch 'master' into feature/ios-voiceover
IsaMorphic 7783e26
Merge branch 'master' into feature/ios-voiceover
IsaMorphic 7b65e56
Merge branch 'master' into feature/ios-voiceover
IsaMorphic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,284 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Avalonia.Automation; | ||
using Avalonia.Automation.Peers; | ||
using Avalonia.Automation.Provider; | ||
using CoreGraphics; | ||
using Foundation; | ||
using UIKit; | ||
|
||
namespace Avalonia.iOS | ||
{ | ||
internal class AutomationPeerWrapper : UIAccessibilityElement | ||
{ | ||
private static readonly IReadOnlyDictionary<AutomationProperty, Action<AutomationPeerWrapper>> s_propertySetters = | ||
new Dictionary<AutomationProperty, Action<AutomationPeerWrapper>>() | ||
{ | ||
{ AutomationElementIdentifiers.NameProperty, UpdateName }, | ||
{ AutomationElementIdentifiers.HelpTextProperty, UpdateHelpText }, | ||
{ AutomationElementIdentifiers.BoundingRectangleProperty, UpdateBoundingRectangle }, | ||
|
||
{ RangeValuePatternIdentifiers.IsReadOnlyProperty, UpdateIsReadOnly }, | ||
{ RangeValuePatternIdentifiers.ValueProperty, UpdateValue }, | ||
|
||
{ ValuePatternIdentifiers.IsReadOnlyProperty, UpdateIsReadOnly }, | ||
{ ValuePatternIdentifiers.ValueProperty, UpdateValue }, | ||
}; | ||
|
||
private readonly AvaloniaView _view; | ||
private readonly AutomationPeer _peer; | ||
|
||
public AutomationPeerWrapper(AvaloniaView view, AutomationPeer? peer = null) : base(view) | ||
{ | ||
_view = view; | ||
_peer = peer ?? ControlAutomationPeer.CreatePeerForElement(view.TopLevel); | ||
|
||
_peer.PropertyChanged += PeerPropertyChanged; | ||
_peer.ChildrenChanged += PeerChildrenChanged; | ||
|
||
AccessibilityContainer = _view; | ||
AccessibilityIdentifier = _peer.GetAutomationId(); | ||
} | ||
|
||
private static void UpdateName(AutomationPeerWrapper self) | ||
{ | ||
AutomationPeer peer = self; | ||
self.AccessibilityLabel = peer.GetName(); | ||
} | ||
|
||
private static void UpdateHelpText(AutomationPeerWrapper self) | ||
{ | ||
AutomationPeer peer = self; | ||
self.AccessibilityHint = peer.GetHelpText(); | ||
} | ||
|
||
private static void UpdateBoundingRectangle(AutomationPeerWrapper self) | ||
{ | ||
AutomationPeer peer = self; | ||
Rect bounds = peer.GetBoundingRectangle(); | ||
PixelRect screenRect = new PixelRect( | ||
self._view.TopLevel.PointToScreen(bounds.TopLeft), | ||
self._view.TopLevel.PointToScreen(bounds.BottomRight) | ||
); | ||
CGRect nativeRect = new CGRect( | ||
screenRect.X, screenRect.Y, | ||
screenRect.Width, screenRect.Height | ||
); | ||
if (self.AccessibilityFrame != nativeRect) | ||
{ | ||
self.AccessibilityFrame = nativeRect; | ||
UIAccessibility.PostNotification(UIAccessibilityPostNotification.LayoutChanged, null); | ||
} | ||
} | ||
|
||
private static void UpdateIsReadOnly(AutomationPeerWrapper self) | ||
{ | ||
AutomationPeer peer = self; | ||
self.AccessibilityRespondsToUserInteraction = | ||
peer.GetProvider<IValueProvider>()?.IsReadOnly ?? | ||
peer.GetProvider<IRangeValueProvider>()?.IsReadOnly ?? | ||
peer.IsEnabled(); | ||
} | ||
|
||
private static void UpdateValue(AutomationPeerWrapper self) | ||
{ | ||
AutomationPeer peer = self; | ||
string? newValue = | ||
peer.GetProvider<IRangeValueProvider>()?.Value.ToString("0.##") ?? | ||
peer.GetProvider<IValueProvider>()?.Value; | ||
if (self.AccessibilityValue != newValue) | ||
{ | ||
self.AccessibilityValue = newValue; | ||
UIAccessibility.PostNotification(UIAccessibilityPostNotification.Announcement, null); | ||
} | ||
} | ||
|
||
private void PeerChildrenChanged(object? sender, EventArgs e) | ||
{ | ||
_view.UpdateChildren(_peer); | ||
UIAccessibility.PostNotification(UIAccessibilityPostNotification.ScreenChanged, null); | ||
} | ||
|
||
private void PeerPropertyChanged(object? sender, AutomationPropertyChangedEventArgs e) => | ||
UpdateProperties(e.Property); | ||
|
||
private void UpdateProperties(params AutomationProperty[] properties) | ||
{ | ||
HashSet<Action<AutomationPeerWrapper>> calledSetters = new(); | ||
foreach (AutomationProperty property in properties) | ||
{ | ||
if (s_propertySetters.TryGetValue(property, | ||
out Action<AutomationPeerWrapper>? setter) && | ||
!calledSetters.Contains(setter)) | ||
{ | ||
calledSetters.Add(setter); | ||
setter.Invoke(this); | ||
} | ||
} | ||
} | ||
|
||
public bool UpdatePropertiesIfValid() | ||
{ | ||
if (_peer.IsContentElement() && !_peer.IsOffscreen()) | ||
{ | ||
UpdateProperties(s_propertySetters.Keys.ToArray()); | ||
return IsAccessibilityElement = true; | ||
} | ||
else | ||
{ | ||
return IsAccessibilityElement = false; | ||
} | ||
} | ||
|
||
public void UpdateTraits() | ||
{ | ||
UIAccessibilityTrait traits = UIAccessibilityTrait.None; | ||
|
||
switch (_peer.GetAutomationControlType()) | ||
{ | ||
case AutomationControlType.Button: | ||
traits |= UIAccessibilityTrait.Button; | ||
break; | ||
case AutomationControlType.Header: | ||
traits |= UIAccessibilityTrait.Header; | ||
break; | ||
case AutomationControlType.Hyperlink: | ||
traits |= UIAccessibilityTrait.Link; | ||
break; | ||
case AutomationControlType.Image: | ||
traits |= UIAccessibilityTrait.Image; | ||
break; | ||
} | ||
|
||
if (_peer.GetProvider<IRangeValueProvider>()?.IsReadOnly == false) | ||
{ | ||
traits |= UIAccessibilityTrait.Adjustable; | ||
} | ||
|
||
if (_peer.GetProvider<ISelectionItemProvider>()?.IsSelected == true) | ||
{ | ||
traits |= UIAccessibilityTrait.Selected; | ||
} | ||
|
||
if (_peer.GetProvider<IValueProvider>()?.IsReadOnly == false) | ||
{ | ||
traits |= UIAccessibilityTrait.UpdatesFrequently; | ||
} | ||
|
||
if (_peer.IsEnabled() == false) | ||
{ | ||
traits |= UIAccessibilityTrait.NotEnabled; | ||
} | ||
|
||
AccessibilityTraits = (ulong)traits; | ||
} | ||
|
||
[Export("accessibilityActivate")] | ||
public bool AccessibilityActivate() | ||
{ | ||
IToggleProvider? toggleProvider = _peer.GetProvider<IToggleProvider>(); | ||
IInvokeProvider? invokeProvider = _peer.GetProvider<IInvokeProvider>(); | ||
if (toggleProvider is not null) | ||
{ | ||
toggleProvider.Toggle(); | ||
return true; | ||
} | ||
else if (invokeProvider is not null) | ||
{ | ||
invokeProvider.Invoke(); | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public override bool AccessibilityElementIsFocused() | ||
{ | ||
base.AccessibilityElementIsFocused(); | ||
return _peer.HasKeyboardFocus(); | ||
} | ||
|
||
public override void AccessibilityElementDidBecomeFocused() | ||
{ | ||
base.AccessibilityElementDidBecomeFocused(); | ||
_peer.BringIntoView(); | ||
} | ||
|
||
public override void AccessibilityDecrement() | ||
{ | ||
base.AccessibilityDecrement(); | ||
IRangeValueProvider? provider = _peer.GetProvider<IRangeValueProvider>(); | ||
if (provider is not null) | ||
{ | ||
double value = provider.Value; | ||
provider.SetValue(value - provider.SmallChange); | ||
} | ||
} | ||
|
||
public override void AccessibilityIncrement() | ||
{ | ||
base.AccessibilityIncrement(); | ||
IRangeValueProvider? provider = _peer.GetProvider<IRangeValueProvider>(); | ||
if (provider is not null) | ||
{ | ||
double value = provider.Value; | ||
provider.SetValue(value + provider.SmallChange); | ||
} | ||
} | ||
|
||
public override bool AccessibilityScroll(UIAccessibilityScrollDirection direction) | ||
{ | ||
base.AccessibilityScroll(direction); | ||
IScrollProvider? scrollProvider = _peer.GetProvider<IScrollProvider>(); | ||
if (scrollProvider is not null) | ||
{ | ||
bool didScroll; | ||
ScrollAmount verticalAmount, horizontalAmount; | ||
switch (direction) | ||
{ | ||
case UIAccessibilityScrollDirection.Up: | ||
verticalAmount = ScrollAmount.SmallIncrement; | ||
horizontalAmount = ScrollAmount.NoAmount; | ||
didScroll = true; | ||
break; | ||
case UIAccessibilityScrollDirection.Down: | ||
verticalAmount = ScrollAmount.SmallDecrement; | ||
horizontalAmount = ScrollAmount.NoAmount; | ||
didScroll = true; | ||
break; | ||
case UIAccessibilityScrollDirection.Left: | ||
verticalAmount = ScrollAmount.NoAmount; | ||
horizontalAmount = ScrollAmount.SmallIncrement; | ||
didScroll = true; | ||
break; | ||
case UIAccessibilityScrollDirection.Right: | ||
verticalAmount = ScrollAmount.NoAmount; | ||
horizontalAmount = ScrollAmount.SmallDecrement; | ||
didScroll = true; | ||
break; | ||
default: | ||
verticalAmount = ScrollAmount.NoAmount; | ||
horizontalAmount = ScrollAmount.NoAmount; | ||
didScroll = false; | ||
break; | ||
} | ||
|
||
scrollProvider.Scroll(verticalAmount, horizontalAmount); | ||
if (didScroll) | ||
{ | ||
UIAccessibility.PostNotification(UIAccessibilityPostNotification.PageScrolled, null); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static implicit operator AutomationPeer(AutomationPeerWrapper instance) | ||
{ | ||
return instance._peer; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @grokys, is it fine to switch to Effectively Visible? Or do other backends handle inherited visibility on their own?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other backends handle this only in-so-far as they handle the hit testing in Avalonia code. This is in contrast to iOS which is the only target platform that performs the hit testing on the OS side. Therefore, I argue that this adaptation is necessary.