// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.Maui.Platform.Linux.Services;
///
/// Interface for accessibility services using AT-SPI2.
/// Provides screen reader support on Linux.
///
public interface IAccessibilityService
{
///
/// Gets whether accessibility is enabled.
///
bool IsEnabled { get; }
///
/// Initializes the accessibility service.
///
void Initialize();
///
/// Registers an accessible object.
///
/// The accessible object to register.
void Register(IAccessible accessible);
///
/// Unregisters an accessible object.
///
/// The accessible object to unregister.
void Unregister(IAccessible accessible);
///
/// Notifies that focus has changed.
///
/// The newly focused accessible object.
void NotifyFocusChanged(IAccessible? accessible);
///
/// Notifies that a property has changed.
///
/// The accessible object.
/// The property that changed.
void NotifyPropertyChanged(IAccessible accessible, AccessibleProperty property);
///
/// Notifies that an accessible's state has changed.
///
/// The accessible object.
/// The state that changed.
/// The new value of the state.
void NotifyStateChanged(IAccessible accessible, AccessibleState state, bool value);
///
/// Announces text to the screen reader.
///
/// The text to announce.
/// The announcement priority.
void Announce(string text, AnnouncementPriority priority = AnnouncementPriority.Polite);
///
/// Shuts down the accessibility service.
///
void Shutdown();
}
///
/// Interface for accessible objects.
///
public interface IAccessible
{
///
/// Gets the unique identifier for this accessible.
///
string AccessibleId { get; }
///
/// Gets the accessible name (label for screen readers).
///
string AccessibleName { get; }
///
/// Gets the accessible description (additional context).
///
string AccessibleDescription { get; }
///
/// Gets the accessible role.
///
AccessibleRole Role { get; }
///
/// Gets the accessible states.
///
AccessibleStates States { get; }
///
/// Gets the parent accessible.
///
IAccessible? Parent { get; }
///
/// Gets the child accessibles.
///
IReadOnlyList Children { get; }
///
/// Gets the bounding rectangle in screen coordinates.
///
AccessibleRect Bounds { get; }
///
/// Gets the available actions.
///
IReadOnlyList Actions { get; }
///
/// Performs an action.
///
/// The name of the action to perform.
/// True if the action was performed.
bool DoAction(string actionName);
///
/// Gets the accessible value (for sliders, progress bars, etc.).
///
double? Value { get; }
///
/// Gets the minimum value.
///
double? MinValue { get; }
///
/// Gets the maximum value.
///
double? MaxValue { get; }
///
/// Sets the accessible value.
///
bool SetValue(double value);
}
///
/// Interface for accessible text components.
///
public interface IAccessibleText : IAccessible
{
///
/// Gets the text content.
///
string Text { get; }
///
/// Gets the caret offset.
///
int CaretOffset { get; }
///
/// Gets the number of selections.
///
int SelectionCount { get; }
///
/// Gets the selection at the specified index.
///
(int Start, int End) GetSelection(int index);
///
/// Sets the selection.
///
bool SetSelection(int index, int start, int end);
///
/// Gets the character at the specified offset.
///
char GetCharacterAtOffset(int offset);
///
/// Gets the text in the specified range.
///
string GetTextInRange(int start, int end);
///
/// Gets the bounds of the character at the specified offset.
///
AccessibleRect GetCharacterBounds(int offset);
}
///
/// Interface for editable text components.
///
public interface IAccessibleEditableText : IAccessibleText
{
///
/// Sets the text content.
///
bool SetText(string text);
///
/// Inserts text at the specified position.
///
bool InsertText(int position, string text);
///
/// Deletes text in the specified range.
///
bool DeleteText(int start, int end);
///
/// Copies text to clipboard.
///
bool CopyText(int start, int end);
///
/// Cuts text to clipboard.
///
bool CutText(int start, int end);
///
/// Pastes text from clipboard.
///
bool PasteText(int position);
}
///
/// Accessible roles (based on AT-SPI2 roles).
///
public enum AccessibleRole
{
Unknown,
Window,
Application,
Panel,
Frame,
Button,
CheckBox,
RadioButton,
ComboBox,
Entry,
Label,
List,
ListItem,
Menu,
MenuBar,
MenuItem,
ScrollBar,
Slider,
SpinButton,
StatusBar,
Tab,
TabPanel,
Text,
ToggleButton,
ToolBar,
ToolTip,
Tree,
TreeItem,
Image,
ProgressBar,
Separator,
Link,
Table,
TableCell,
TableRow,
TableColumnHeader,
TableRowHeader,
PageTab,
PageTabList,
Dialog,
Alert,
Filler,
Icon,
Canvas
}
///
/// Accessible states.
///
[Flags]
public enum AccessibleStates : long
{
None = 0,
Active = 1L << 0,
Armed = 1L << 1,
Busy = 1L << 2,
Checked = 1L << 3,
Collapsed = 1L << 4,
Defunct = 1L << 5,
Editable = 1L << 6,
Enabled = 1L << 7,
Expandable = 1L << 8,
Expanded = 1L << 9,
Focusable = 1L << 10,
Focused = 1L << 11,
HasToolTip = 1L << 12,
Horizontal = 1L << 13,
Iconified = 1L << 14,
Modal = 1L << 15,
MultiLine = 1L << 16,
MultiSelectable = 1L << 17,
Opaque = 1L << 18,
Pressed = 1L << 19,
Resizable = 1L << 20,
Selectable = 1L << 21,
Selected = 1L << 22,
Sensitive = 1L << 23,
Showing = 1L << 24,
SingleLine = 1L << 25,
Stale = 1L << 26,
Transient = 1L << 27,
Vertical = 1L << 28,
Visible = 1L << 29,
ManagesDescendants = 1L << 30,
Indeterminate = 1L << 31,
Required = 1L << 32,
Truncated = 1L << 33,
Animated = 1L << 34,
InvalidEntry = 1L << 35,
SupportsAutocompletion = 1L << 36,
SelectableText = 1L << 37,
IsDefault = 1L << 38,
Visited = 1L << 39,
ReadOnly = 1L << 40
}
///
/// Accessible state enumeration for notifications.
///
public enum AccessibleState
{
Active,
Armed,
Busy,
Checked,
Collapsed,
Defunct,
Editable,
Enabled,
Expandable,
Expanded,
Focusable,
Focused,
Horizontal,
Iconified,
Modal,
MultiLine,
Opaque,
Pressed,
Resizable,
Selectable,
Selected,
Sensitive,
Showing,
SingleLine,
Stale,
Transient,
Vertical,
Visible,
ManagesDescendants,
Indeterminate,
Required,
InvalidEntry,
ReadOnly
}
///
/// Accessible property for notifications.
///
public enum AccessibleProperty
{
Name,
Description,
Role,
Value,
Parent,
Children
}
///
/// Announcement priority.
///
public enum AnnouncementPriority
{
///
/// Low priority - can be interrupted.
///
Polite,
///
/// High priority - interrupts current speech.
///
Assertive
}
///
/// Represents an accessible action.
///
public class AccessibleAction
{
///
/// The action name.
///
public string Name { get; set; } = string.Empty;
///
/// The action description.
///
public string Description { get; set; } = string.Empty;
///
/// The keyboard shortcut for this action.
///
public string? KeyBinding { get; set; }
}
///
/// Represents a rectangle in accessible coordinates.
///
public struct AccessibleRect
{
public int X { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public AccessibleRect(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
}