chromium/services/accessibility/android/public/mojom/accessibility_helper.mojom

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Next MinVersion: 26

module ax.android.mojom;

// Represents a rectangle. Note that the wire format is different from
// the one defined in geometry.mojom in ui/gfx for backward compatibility.
struct Rect {
  int32 left;
  int32 top;
  int32 right;
  int32 bottom;
};


// For future maintainers, each of the below enums were hand picked
// from their equivalents in the Android source. Keep them in the
// order given below and add as needed. The initial order matches the
// order they appear in source files.
//
// If not explicitly called out, the structs and enums below come from:
// https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html

// AccessibilityEventType lists the possible accessibility events on Android.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html
[Extensible]
enum AccessibilityEventType {
  VIEW_FOCUSED,
  VIEW_CLICKED,
  VIEW_LONG_CLICKED,
  VIEW_SELECTED,
  VIEW_TEXT_CHANGED,
  WINDOW_STATE_CHANGED,
  NOTIFICATION_STATE_CHANGED,
  VIEW_HOVER_ENTER,
  VIEW_HOVER_EXIT,
  TOUCH_EXPLORATION_GESTURE_START,
  TOUCH_EXPLORATION_GESTURE_END,
  WINDOW_CONTENT_CHANGED,
  VIEW_SCROLLED,
  VIEW_TEXT_SELECTION_CHANGED,
  ANNOUNCEMENT,
  VIEW_ACCESSIBILITY_FOCUSED,
  VIEW_ACCESSIBILITY_FOCUS_CLEARED,
  VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY,
  GESTURE_DETECTION_START,
  GESTURE_DETECTION_END,
  TOUCH_INTERACTION_START,
  TOUCH_INTERACTION_END,
  WINDOWS_CHANGED,
  VIEW_CONTEXT_CLICKED,
  ASSIST_READING_CONTEXT,
  [Default] INVALID_ENUM_VALUE,
};

// ContentChangeType lists the possible sub types of WINDOW_STATE_CHANGED and
// WINDOW_CONTENT_CHANGED events on Android ordered as same as developer guide
// of return value of getContentChangeTypes.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent?hl=en#getContentChangeTypes()
[Extensible]
enum ContentChangeType {
  CONTENT_DESCRIPTION,
  STATE_DESCRIPTION,
  SUBTREE,
  TEXT,
  PANE_TITLE,
  UNDEFINED,
  PANE_APPEARED,
  PANE_DISAPPEARED,
  [Default] INVALID_ENUM_VALUE,
};

// Possible actions that can be performed on an AccessibilityNodeInfo.
[Extensible]
enum AccessibilityActionType {
  FOCUS,
  CLEAR_FOCUS,
  SELECT,
  CLEAR_SELECTION,
  CLICK,
  LONG_CLICK,
  ACCESSIBILITY_FOCUS,
  CLEAR_ACCESSIBILITY_FOCUS,
  NEXT_AT_MOVEMENT_GRANULARITY,  // unused
  PREVIOUS_AT_MOVEMENT_GRANULARITY,  // unused
  NEXT_HTML_ELEMENT,  // unused
  PREVIOUS_HTML_ELEMENT,  // unused
  SCROLL_FORWARD,
  SCROLL_BACKWARD,
  COPY,
  PASTE,
  CUT,
  SET_SELECTION,
  EXPAND,
  COLLAPSE,
  DISMISS,
  SET_TEXT,
  CONTEXT_CLICK,
  SCROLL_DOWN,
  SCROLL_LEFT,
  SCROLL_RIGHT,
  SCROLL_TO_POSITION,
  SCROLL_UP,
  SET_PROGRESS,
  SHOW_ON_SCREEN,
  CUSTOM_ACTION,  // Not a standard action.
  GET_TEXT_LOCATION,  // Not a standard action.
  SHOW_TOOLTIP,
  HIDE_TOOLTIP,
  [Default] INVALID_ENUM_VALUE,
};

// Possible boolean properties set on an AccessibilityNodeInfo.
// The enum values appear in the same order as they do within
// AccessibilityNodeInfo.java.
[Extensible]
enum AccessibilityBooleanProperty {
  CHECKABLE,
  CHECKED,
  FOCUSABLE,
  FOCUSED,
  SELECTED,
  CLICKABLE,
  LONG_CLICKABLE,
  ENABLED,
  PASSWORD,
  SCROLLABLE,
  ACCESSIBILITY_FOCUSED,
  VISIBLE_TO_USER,
  EDITABLE,
  OPENS_POPUP,
  DISMISSABLE,
  MULTI_LINE,
  CONTENT_INVALID,
  CONTEXT_CLICKABLE,
  IMPORTANCE,
  SCREEN_READER_FOCUSABLE,
  SHOWING_HINT_TEXT,
  HEADING,
  SUPPORTS_TEXT_LOCATION,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from string instance members of
// AccessibilityNodeInfo.
[Extensible]
enum AccessibilityStringProperty {
  PACKAGE_NAME,
  CLASS_NAME,
  TEXT,
  CONTENT_DESCRIPTION,
  VIEW_ID_RESOURCE_NAME,
  CHROME_ROLE,  // Chrome only
  ROLE_DESCRIPTION,  // Chrome only
  TOOLTIP,
  PANE_TITLE,
  HINT_TEXT,
  STATE_DESCRIPTION,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from int instance members of
// AccessibilityNodeInfo.
[Extensible]
enum AccessibilityIntProperty {
  LABEL_FOR,
  LABELED_BY,
  TRAVERSAL_BEFORE,
  TRAVERSAL_AFTER,
  MAX_TEXT_LENGTH,
  TEXT_SELECTION_START,
  TEXT_SELECTION_END,
  INPUT_TYPE,
  LIVE_REGION,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from List<int> instance members of
// AccessibilityNodeInfo.
[Extensible]
enum AccessibilityIntListProperty {
  CHILD_NODE_IDS,
  CUSTOM_ACTION_IDS_DEPRECATED,
  STANDARD_ACTION_IDS_DEPRECATED,
  [Default] INVALID_ENUM_VALUE,
};

// Deprecated
// These fields are taken from List<String> instance members of
// AccessibilityNodeInfo.
[Extensible]
enum AccessibilityStringListProperty {
  CUSTOM_ACTION_DESCRIPTIONS,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from boolean properties of
// AccessibilityWindowInfo.
[Extensible]
enum AccessibilityWindowBooleanProperty {
  ACCESSIBILITY_FOCUSED,
  FOCUSED,
  IN_PICTURE_IN_PICTURE_MODE,
  WINDOW_ACTIVE,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from int attributes of
// AccessibilityWindowInfo.
[Extensible]
enum AccessibilityWindowIntProperty {
  ANCHOR_NODE_ID,
  LAYER_ORDER,
  PARENT_WINDOW_ID,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from String attributes of
// AccessibilityWindowInfo.
[Extensible]
enum AccessibilityWindowStringProperty {
  TITLE,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from List<Integer> instance members of
// AccessibilityWindowInfo.
[Extensible]
enum AccessibilityWindowIntListProperty {
  CHILD_WINDOW_IDS,
  [Default] INVALID_ENUM_VALUE,
};

// This type is a subset of spans available under android.text.style.
[Extensible]
enum SpanType {
  URL,
  CLICKABLE,
  [Default] INVALID_ENUM_VALUE,
};

// Groups data about a Spannable.
struct SpanEntry {
  int32 start;
  int32 end;
  SpanType span_type;
};

// These fields are taken from AccessibilityNodeInfo.CollectionItemInfo.
[Extensible]
enum AccessibilitySelectionMode {
  NONE,
  SINGLE,
  MULTIPLE,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from AccessibilityNodeInfo.CollectionInfo.
struct AccessibilityCollectionInfoData {
  int32 row_count;
  int32 column_count;
  bool is_hierarchical;
  AccessibilitySelectionMode selection_mode;
};

// These fields are taken from AccessibilityNodeInfo.CollectionItemInfo.
struct AccessibilityCollectionItemInfoData {
  int32 row_index;
  int32 column_index;
  int32 row_span;
  int32 column_span;
  bool is_heading;
  bool is_selected;
};

// These fields are taken from AccessibilityNodeInfo.RangeInfo.
[Extensible]
enum AccessibilityRangeType {
  INT,
  FLOAT,
  PERCENT,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from AccessibilityNodeInfo.RangeInfo.
struct AccessibilityRangeInfoData {
  AccessibilityRangeType range_type;
  float min;
  float max;
  float current;
};

// These fields are taken from View.ACCESSIBILITY_LIVE_REGION_*.
[Extensible]
enum AccessibilityLiveRegionType {
  NONE,
  POLITE,
  ASSERTIVE,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from AccessibilityWindowInfo's window types.
[Extensible]
enum AccessibilityWindowType {
  TYPE_ACCESSIBILITY_OVERLAY,
  TYPE_APPLICATION,
  TYPE_INPUT_METHOD,
  TYPE_SPLIT_SCREEN_DIVIDER,
  TYPE_SYSTEM,
  [Default] INVALID_ENUM_VALUE,
};

// AccessibilityActionInAndroid is a struct to send information of
// available AccessibilityAction in Android to Chrome.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.AccessibilityAction.html
struct AccessibilityActionInAndroid {
  int32 id;
  string? label;
};

// AccessibilityNodeInfoData is a struct to contain info of
// AccessibilityNodeInfo in Android.
struct AccessibilityNodeInfoData {
  Rect bounds_in_screen;
  [MinVersion=1] int32 id;
  [MinVersion=1] map<AccessibilityBooleanProperty, bool>? boolean_properties;
  [MinVersion=1] map<AccessibilityStringProperty, string>? string_properties;
  [MinVersion=1] map<AccessibilityIntProperty, int32>? int_properties;
  [MinVersion=1]
      map<AccessibilityIntListProperty, array<int32>>? int_list_properties;
  [MinVersion=3] map<AccessibilityStringListProperty, array<string>>?
      string_list_properties; // Deprecated
  [MinVersion=5] map<AccessibilityStringProperty, array<SpanEntry>>?
      spannable_string_properties;
  [MinVersion=5] AccessibilityCollectionInfoData? collection_info;
  [MinVersion=5] AccessibilityCollectionItemInfoData? collection_item_info;
  [MinVersion=5] AccessibilityRangeInfoData? range_info;
  [MinVersion=12] int32 window_id;
  [MinVersion=20] bool is_virtual_node;
  [MinVersion=24] array<AccessibilityActionInAndroid>? standard_actions;
  [MinVersion=24] array<AccessibilityActionInAndroid>? custom_actions;
};

// AccessibilityWindowInfoData is a struct to contain info about
// AccessibilityWindowInfo in Android.
struct AccessibilityWindowInfoData {
  int32 window_id;
  int32 root_node_id;
  Rect bounds_in_screen;
  AccessibilityWindowType window_type;
  map<AccessibilityWindowBooleanProperty, bool>? boolean_properties;
  map<AccessibilityWindowStringProperty, string>? string_properties;
  map<AccessibilityWindowIntProperty, int32>? int_properties;
  map<AccessibilityWindowIntListProperty, array<int32>>? int_list_properties;
};

// Filters the event type (and implicitly the data) sent by the ARC
// accessibility service.
[Extensible]
enum AccessibilityFilterType {
  // No events will be sent.
  OFF,

  // Only send focus events along with the source focus node.
  FOCUS,

  // Send a complete tree from the event source's root for every event.
  ALL,
  [Default] INVALID_ENUM_VALUE,
};

[Extensible]
enum AccessibilityNotificationStateType {
  // Surface for a notification is created. OnNotificationStateChanged of
  // SURFACE_CREATED for a notification must be called before
  // OnAccessibilityEvent of WINDOW_STATE_CHANGED for it is called.
  SURFACE_CREATED,

  // Surface for a notification is removed.
  SURFACE_REMOVED,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from int attributes of
// AccessibilityEvent and AccessibilityRecord.
[Extensible]
enum AccessibilityEventIntProperty {
  ACTION,
  FROM_INDEX,
  TO_INDEX,
  ITEM_COUNT,
  CURRENT_ITEM_INDEX,
  SCROLL_X,
  SCROLL_Y,
  MAX_SCROLL_X,
  MAX_SCROLL_Y,
  SCROLL_DELTA_X,
  SCROLL_DELTA_Y,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from string attributes of
// AccessibilityEvent and AccessibilityRecord.
[Extensible]
enum AccessibilityEventStringProperty {
  CLASS_NAME,
  PACKAGE_NAME,
  CONTENT_DESCRIPTION,
  [Default] INVALID_ENUM_VALUE,
};

// These fields are taken from List<Integer> like instance members of
// AccessibilityEvent and AccessibilityRecord.
[Extensible]
enum AccessibilityEventIntListProperty{
  CONTENT_CHANGE_TYPES,
  [Default] INVALID_ENUM_VALUE,
};

// AccessibilityEventData is a struct to contain info of
// AccessibilityEvent in Android.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html
struct AccessibilityEventData {
  AccessibilityEventType event_type;
  int32 source_id;
  array<AccessibilityNodeInfoData> node_data;

  // notification_key is set only for an event on an Android notification.
  [MinVersion=6] string? notification_key;

  // window_id where this event is dispatched for. This does not match
  // AccessibilityWindowInfo window ids, instead it is a mapping to from
  // unique IDs in an Android task to nodes in Chrome.
  [MinVersion=6] int32 window_id;

  // Task associated with this event (usually the front task when this event
  // gets dispatched).
  [MinVersion=8] int32 task_id;

  // The window data for the tree. This may not be populated if
  // only one node needs to be returned, for example if the event
  // filter type is AccessibilityFilterType.FOCUS.
  [MinVersion=12] array<AccessibilityWindowInfoData>? window_data;

  // True if this event has happened on
  // AccessibilityWindowInfo.TYPE_INPUT_METHOD.
  [MinVersion=14] bool is_input_method_window;

  // Retrieved from AccessibilityRecord.getText().
  [MinVersion=15] array<string>? event_text;

  [MinVersion=21] map<AccessibilityEventIntProperty, int32>? int_properties;
  [MinVersion=21]
      map<AccessibilityEventStringProperty, string>? string_properties;
  [MinVersion=23]
      map<AccessibilityEventIntListProperty, array<int32>>? int_list_properties;
};

// This enum is used to represent the argument
// string constants for accessibility action float parameters.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#constants_1
enum ActionFloatArgumentType {
  PROGRESS_VALUE
};

// This enum is used to represent the argument
// string constants for accessibility action integer parameters.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#constants_1
enum ActionIntArgumentType {
  MOVEMENT_GRANULARITY_INT,
  SELECTION_START_INT,
  SELECTION_END_INT,
  ROW_INT,
  COLUMN_INT,
  MOVE_WINDOW_X,
  MOVE_WINDOW_Y,
  PRESS_AND_HOLD_DURATION_MILLIS_INT
};

// This enum is used to represent the argument
// string constants for accessibility action string parameters.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#constants_1
enum ActionStringArgumentType {
  HTML_ELEMENT_STRING,
  SET_TEXT_CHARSEQUENCE
};

// This enum is used to represent the argument string constants
// for accessibility action parameters that have complex types.
// https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#constants_1
enum ActionComplexArgumentType {
  ACCESSIBLE_CLICKABLE_SPAN
};

// AccessibilityActionData is a struct to send action information when Chrome
// invokes an action.
struct AccessibilityActionData {
  int32 node_id;

  AccessibilityActionType action_type;

  // custom_action_id must be set if action_type is CUSTOM_ACTION.
  int32 custom_action_id;

  // window_id where the action is performed on.
  [MinVersion=6] int32 window_id;

  // Parameters specifying indicies to get text location of node
  // in Android.
  [MinVersion=13] int32 start_index;
  [MinVersion=13] int32 end_index;

  // Parameters for action functions.
  // Ex: SCROLL_TO_POSITION would have a row and column int parameter.
  [MinVersion=25] map<ActionIntArgumentType,int32>? int_parameters;
  [MinVersion=25] map<ActionStringArgumentType,string>? string_parameters;
  [MinVersion=25] map<ActionFloatArgumentType,float>? float_parameters;
};

// Information used to identify AccessibilityWindow.
// In P or before, task_id is used. In Q or later, window_id is used.
union AccessibilityWindowKey {
  uint32 window_id;
  uint32 task_id;
};

// Interface for Android communicating to Chrome.
// Deprecated method IDs: 0
// Next method ID: 4
interface AccessibilityHelperHost {
  // OnAccessibilityEvent is called when a converted Android accessibility event
  // is sent from Android.
  OnAccessibilityEvent@1(AccessibilityEventData event_data);

  // OnNotificationStateChanged is called when state of a notification is
  // changed, e.g. surface for a notification is created.
  [MinVersion=10] OnNotificationStateChanged@2(
      string notification_key, AccessibilityNotificationStateType state);

  // OnToggleNativeChromeVoxArcSupport is called when state of ChromeVox native
  // ARC support gets changed.
  [MinVersion=18] OnToggleNativeChromeVoxArcSupport@3(bool enabled);
};

// Response code for SetNativeChromeVoxArcSupportForFocusedWindow.
[Extensible]
enum SetNativeChromeVoxResponse {
  SUCCESS,
  WINDOW_NOT_FOUND,
  TALKBACK_NOT_INSTALLED,
  FAILURE,

  // Need to notify users that TalkBack is installed but
  // it no longer support ARC++ customization.
  NEED_DEPRECATION_CONFIRMATION,
  [Default] INVALID_ENUM_VALUE,
};

// Interface for communicating to Android.
// Deprecated method IDs: 0, 1, 3, 5, 6, 10
// Next method ID: 13
interface AccessibilityHelperInstance {
  // Establishes full-duplex communication with the host.
  [MinVersion=9] Init@7(
      pending_remote<AccessibilityHelperHost> host_remote) => ();

  // Set a filter on the event types received.
  SetFilter@2(AccessibilityFilterType filter_type);

  // Perform an action on a node requested by a Chrome client.
  [MinVersion=4] PerformAction@4(AccessibilityActionData action_data)
      => (bool result);

  // Requests the service to enable or disable Explore By Touch.
  [MinVersion=11] SetExploreByTouchEnabled@8(bool enabled);

  // Refresh the current node with extra data.
  // Returns Rect specifying location, or null if textLocation is not available.
  [MinVersion=13] RefreshWithExtraData@9(AccessibilityActionData refresh_data)
      => (Rect? text_location);

  // Requests the whole accessibility tree with the specified window.
  [MinVersion=17] RequestSendAccessibilityTree@11(
      AccessibilityWindowKey window);

  // Sets the focused window's package to use ChromeVox (true) or TalkBack
  // (false).
  [MinVersion=24] SetNativeChromeVoxArcSupportForFocusedWindow@12(
      bool enabled) => (SetNativeChromeVoxResponse response);
};