tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Accessible.h (25349B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef _Accessible_H_
      7 #define _Accessible_H_
      8 
      9 #include "mozilla/a11y/Role.h"
     10 #include "mozilla/a11y/AccTypes.h"
     11 #include "nsStringFwd.h"
     12 #include "nsRect.h"
     13 #include "Units.h"
     14 
     15 class nsAtom;
     16 class nsStaticAtom;
     17 
     18 struct nsRoleMapEntry;
     19 
     20 class nsIURI;
     21 
     22 namespace mozilla {
     23 class WritingMode;
     24 
     25 namespace a11y {
     26 
     27 class AccAttributes;
     28 class AccGroupInfo;
     29 class HyperTextAccessibleBase;
     30 class LocalAccessible;
     31 class Relation;
     32 enum class RelationType;
     33 class RemoteAccessible;
     34 class TableAccessible;
     35 class TableCellAccessible;
     36 
     37 /**
     38 * Name type flags.
     39 */
     40 enum ENameValueFlag {
     41  /**
     42   * Name either
     43   *  a) present (not empty): !name.IsEmpty()
     44   *  b) no name (was missed): name.IsVoid()
     45   */
     46  eNameOK,
     47 
     48  /**
     49   * Name was computed from the subtree.
     50   */
     51  eNameFromSubtree,
     52 
     53  /**
     54   * Tooltip was used as a name.
     55   */
     56  eNameFromTooltip,
     57 
     58  /**
     59   * Labelling relations were used for the name.
     60   */
     61  eNameFromRelations,
     62 };
     63 
     64 /**
     65 * Description type flags.
     66 */
     67 enum EDescriptionValueFlag {
     68  /**
     69   * Description either
     70   *  a) present (not empty): !description.IsEmpty()
     71   *  b) no description (was missed): IsVoid() or IsEmpty(),
     72   *     or NameAndDescription caching domain is not active.
     73   */
     74  eDescriptionOK,
     75 
     76  /**
     77   * Description was provided by ARIA (either aria-description or
     78   * aria-describedby)
     79   */
     80  eDescriptionFromARIA,
     81 };
     82 
     83 /**
     84 * Group position (level, position in set and set size).
     85 */
     86 struct GroupPos {
     87  GroupPos() : level(0), posInSet(0), setSize(0) {}
     88  GroupPos(int32_t aLevel, int32_t aPosInSet, int32_t aSetSize)
     89      : level(aLevel), posInSet(aPosInSet), setSize(aSetSize) {}
     90 
     91  int32_t level;
     92  int32_t posInSet;
     93  int32_t setSize;
     94 };
     95 
     96 /**
     97 * Represent key binding associated with accessible (such as access key and
     98 * global keyboard shortcuts).
     99 */
    100 class KeyBinding {
    101 public:
    102  /**
    103   * Modifier mask values.
    104   */
    105  static const uint32_t kShift = 1;
    106  static const uint32_t kControl = 2;
    107  static const uint32_t kAlt = 4;
    108  static const uint32_t kMeta = 8;
    109 
    110  static uint32_t AccelModifier();
    111 
    112  KeyBinding() : mKey(0), mModifierMask(0) {}
    113  KeyBinding(uint32_t aKey, uint32_t aModifierMask)
    114      : mKey(aKey), mModifierMask(aModifierMask) {}
    115  explicit KeyBinding(uint64_t aSerialized) : mSerialized(aSerialized) {}
    116 
    117  inline bool IsEmpty() const { return !mKey; }
    118  inline uint32_t Key() const { return mKey; }
    119  inline uint32_t ModifierMask() const { return mModifierMask; }
    120 
    121  /**
    122   * Serialize this KeyBinding to a uint64_t for use in the parent process
    123   * cache. This is simpler than custom IPDL serialization for this simple case.
    124   */
    125  uint64_t Serialize() { return mSerialized; }
    126 
    127  enum Format { ePlatformFormat, eAtkFormat };
    128 
    129  /**
    130   * Return formatted string for this key binding depending on the given format.
    131   */
    132  inline void ToString(nsAString& aValue,
    133                       Format aFormat = ePlatformFormat) const {
    134    aValue.Truncate();
    135    AppendToString(aValue, aFormat);
    136  }
    137  inline void AppendToString(nsAString& aValue,
    138                             Format aFormat = ePlatformFormat) const {
    139    if (mKey) {
    140      if (aFormat == ePlatformFormat) {
    141        ToPlatformFormat(aValue);
    142      } else {
    143        ToAtkFormat(aValue);
    144      }
    145    }
    146  }
    147 
    148 private:
    149  void ToPlatformFormat(nsAString& aValue) const;
    150  void ToAtkFormat(nsAString& aValue) const;
    151 
    152  union {
    153    struct {
    154      uint32_t mKey;
    155      uint32_t mModifierMask;
    156    };
    157    uint64_t mSerialized;
    158  };
    159 };
    160 
    161 /**
    162 * The base type for an accessibility tree node. Methods and attributes in this
    163 * class are available in both the content process and the parent process.
    164 * Overrides for these methods live primarily in LocalAccessible and
    165 * RemoteAccessibleBase.
    166 */
    167 class Accessible {
    168 protected:
    169  Accessible();
    170 
    171  Accessible(AccType aType, AccGenericType aGenericTypes,
    172             uint8_t aRoleMapEntryIndex);
    173 
    174 public:
    175  /**
    176   * Return an id for this Accessible which is unique within the document.
    177   * Use nsAccUtils::GetAccessibleByID to retrieve an Accessible given an id
    178   * returned from this method.
    179   */
    180  virtual uint64_t ID() const = 0;
    181 
    182  virtual Accessible* Parent() const = 0;
    183 
    184  virtual role NativeRole() const = 0;
    185 
    186  /**
    187   * Return child accessible at the given index.
    188   */
    189  virtual Accessible* ChildAt(uint32_t aIndex) const = 0;
    190 
    191  virtual Accessible* NextSibling() const = 0;
    192  virtual Accessible* PrevSibling() const = 0;
    193 
    194  virtual uint32_t ChildCount() const = 0;
    195 
    196  virtual int32_t IndexInParent() const = 0;
    197 
    198  /**
    199   * Returns the accessible's calculated, final, role.
    200   */
    201  role Role() const;
    202 
    203  bool HasChildren() const { return !!FirstChild(); }
    204 
    205  inline Accessible* FirstChild() const {
    206    return ChildCount() ? ChildAt(0) : nullptr;
    207  }
    208 
    209  inline Accessible* LastChild() const {
    210    uint32_t childCount = ChildCount();
    211    return childCount ? ChildAt(childCount - 1) : nullptr;
    212  }
    213 
    214  /**
    215   * Return true if this Accessible is before another Accessible in the tree.
    216   */
    217  bool IsBefore(const Accessible* aAcc) const;
    218 
    219  /**
    220   * A utility enum for controlling FindAncestorIf.
    221   *   Continue: this is not the desired ancestor node, keep searching
    222   *   Found:    this is the desired ancestor node
    223   *   NotFound: this is not the desired ancestor node, stop searching
    224   */
    225  enum class AncestorSearchOption { Continue, Found, NotFound };
    226  /**
    227   * Return a non-generic ancestor for which the given predicate returns
    228   * AncestorSearchOption::Found, if any exist. If none exist, return nullptr.
    229   * The predicate may choose to return options from AncestorSearchOption to
    230   * control the flow of the ancestor search.
    231   */
    232  template <typename Callable>
    233  Accessible* FindAncestorIf(Callable&& aPredicate) const {
    234    static_assert(
    235        std::is_same_v<std::invoke_result_t<Callable, const Accessible&>,
    236                       AncestorSearchOption>,
    237        "Given callable must return AncestorSearchOption.");
    238    static_assert(std::is_invocable_v<Callable, const Accessible&>,
    239                  "Given callable must accept const Accessible&.");
    240    Accessible* search = GetNonGenericParent();
    241    while (search) {
    242      const AncestorSearchOption option = aPredicate(*search);
    243      switch (option) {
    244        case AncestorSearchOption::Continue:
    245          search = search->GetNonGenericParent();
    246          continue;
    247        case AncestorSearchOption::Found:
    248          return search;
    249        case AncestorSearchOption::NotFound:
    250          return nullptr;
    251        default:
    252          MOZ_ASSERT(false, "Unhandled AncestorSearchOption");
    253          break;
    254      }
    255    }
    256    return nullptr;
    257  }
    258 
    259  bool IsAncestorOf(const Accessible* aAcc) const {
    260    for (const Accessible* parent = aAcc->Parent(); parent;
    261         parent = parent->Parent()) {
    262      if (parent == this) {
    263        return true;
    264      }
    265    }
    266    return false;
    267  }
    268 
    269  /**
    270   * Return the closest common ancestor of `this` and `aAcc`, potentially
    271   * including `this`. That is, if `aAcc` is `this` or a descendant, this method
    272   * will return `this`.
    273   */
    274  const Accessible* GetClosestCommonInclusiveAncestor(
    275      const Accessible* aAcc) const;
    276 
    277  Accessible* GetClosestCommonInclusiveAncestor(Accessible* aAcc) {
    278    const Accessible* common =
    279        const_cast<const Accessible*>(this)->GetClosestCommonInclusiveAncestor(
    280            aAcc);
    281    return const_cast<Accessible*>(common);
    282  }
    283 
    284  /**
    285   * Used by ChildAtPoint() method to get direct or deepest child at point.
    286   */
    287  enum class EWhichChildAtPoint { DirectChild, DeepestChild };
    288 
    289  virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY,
    290                                   EWhichChildAtPoint aWhichChild) = 0;
    291 
    292  /**
    293   * Return the focused child if any.
    294   */
    295  virtual Accessible* FocusedChild();
    296 
    297  /**
    298   * Return ARIA role map if any.
    299   */
    300  const nsRoleMapEntry* ARIARoleMap() const;
    301 
    302  /**
    303   * Return true if ARIA role is specified on the element.
    304   */
    305  bool HasARIARole() const;
    306  bool IsARIARole(nsAtom* aARIARole) const;
    307  bool HasStrongARIARole() const;
    308 
    309  /**
    310   * Return true if the accessible belongs to the given accessible type.
    311   */
    312  bool HasGenericType(AccGenericType aType) const;
    313 
    314  /**
    315   * Return group position (level, position in set and set size).
    316   */
    317  virtual GroupPos GroupPosition();
    318 
    319  /**
    320   * Return embedded accessible children count.
    321   */
    322  virtual uint32_t EmbeddedChildCount() = 0;
    323 
    324  /**
    325   * Return embedded accessible child at the given index.
    326   */
    327  virtual Accessible* EmbeddedChildAt(uint32_t aIndex) = 0;
    328 
    329  /**
    330   * Return index of the given embedded accessible child.
    331   */
    332  virtual int32_t IndexOfEmbeddedChild(Accessible* aChild) = 0;
    333 
    334  // Methods that potentially access a cache.
    335 
    336  /*
    337   * Get the name of this accessible.
    338   */
    339  virtual ENameValueFlag Name(nsString& aName) const = 0;
    340 
    341  /*
    342   * Return true if the accessible name is empty.
    343   */
    344  bool NameIsEmpty() const;
    345 
    346  /*
    347   * Get the description of this accessible.
    348   */
    349  virtual EDescriptionValueFlag Description(nsString& aDescription) const = 0;
    350 
    351  /**
    352   * Get the value of this accessible.
    353   */
    354  virtual void Value(nsString& aValue) const = 0;
    355 
    356  virtual double CurValue() const = 0;
    357  virtual double MinValue() const = 0;
    358  virtual double MaxValue() const = 0;
    359  virtual double Step() const = 0;
    360  virtual bool SetCurValue(double aValue) = 0;
    361 
    362  /**
    363   * Return boundaries in screen coordinates in device pixels.
    364   */
    365  virtual LayoutDeviceIntRect Bounds() const = 0;
    366 
    367  /**
    368   * Return boundaries in screen coordinates in app units.
    369   */
    370  virtual nsRect BoundsInAppUnits() const = 0;
    371 
    372  /**
    373   * Return boundaries in screen coordinates in CSS pixels.
    374   */
    375  virtual nsIntRect BoundsInCSSPixels() const;
    376 
    377  /**
    378   * Returns text of accessible if accessible has text role otherwise empty
    379   * string.
    380   *
    381   * @param aText         [in] returned text of the accessible
    382   * @param aStartOffset  [in, optional] start offset inside of the accessible,
    383   *                        if missed entire text is appended
    384   * @param aLength       [in, optional] required length of text, if missed
    385   *                        then text from start offset till the end is appended
    386   */
    387  virtual void AppendTextTo(nsAString& aText, uint32_t aStartOffset = 0,
    388                            uint32_t aLength = UINT32_MAX) = 0;
    389 
    390  /**
    391   * Return all states of accessible (including ARIA states).
    392   */
    393  virtual uint64_t State() = 0;
    394 
    395  /**
    396   * Return the start offset of the embedded object within the parent
    397   * HyperTextAccessibleBase.
    398   */
    399  virtual uint32_t StartOffset();
    400 
    401  /**
    402   * Return the end offset of the link within the parent
    403   * HyperTextAccessibleBase.
    404   */
    405  virtual uint32_t EndOffset();
    406 
    407  /**
    408   * Return object attributes for the accessible.
    409   */
    410  virtual already_AddRefed<AccAttributes> Attributes() = 0;
    411 
    412  virtual already_AddRefed<nsAtom> DisplayStyle() const = 0;
    413 
    414  virtual float Opacity() const = 0;
    415 
    416  virtual WritingMode GetWritingMode() const = 0;
    417 
    418  /**
    419   * Get the live region attributes (if any) for this single Accessible. This
    420   * does not propagate attributes from ancestors. If any argument is null, that
    421   * attribute is not fetched.
    422   */
    423  virtual void LiveRegionAttributes(nsAString* aLive, nsAString* aRelevant,
    424                                    Maybe<bool>* aAtomic,
    425                                    nsAString* aBusy) const = 0;
    426 
    427  /**
    428   * Get the aria-selected state. aria-selected not being specified is not
    429   * always the same as aria-selected="false". If not specified, Nothing() will
    430   * be returned.
    431   */
    432  virtual Maybe<bool> ARIASelected() const = 0;
    433 
    434  LayoutDeviceIntSize Size() const;
    435 
    436  LayoutDeviceIntPoint Position(uint32_t aCoordType);
    437 
    438  virtual Maybe<int32_t> GetIntARIAAttr(nsAtom* aAttrName) const = 0;
    439 
    440  virtual bool GetStringARIAAttr(nsAtom* aAttrName,
    441                                 nsAString& aAttrValue) const = 0;
    442 
    443  virtual bool ARIAAttrValueIs(nsAtom* aAttrName, nsAtom* aAttrValue) const = 0;
    444 
    445  virtual bool HasARIAAttr(nsAtom* aAttrName) const = 0;
    446 
    447  /**
    448   * Get the relation of the given type.
    449   */
    450  virtual Relation RelationByType(RelationType aType) const = 0;
    451 
    452  /**
    453   * Get the language associated with the accessible.
    454   */
    455  virtual void Language(nsAString& aLocale) = 0;
    456 
    457  /**
    458   * Get the role of this Accessible as an ARIA role token. This might have been
    459   * set explicitly (e.g. role="button") or it might be implicit in native
    460   * markup (e.g. <button> returns "button").
    461   */
    462  nsStaticAtom* ComputedARIARole() const;
    463 
    464  // Methods that interact with content.
    465 
    466  virtual void TakeFocus() const = 0;
    467 
    468  /**
    469   * Scroll the accessible into view.
    470   */
    471  MOZ_CAN_RUN_SCRIPT
    472  virtual void ScrollTo(uint32_t aHow) const = 0;
    473 
    474  /**
    475   * Scroll the accessible to the given point.
    476   */
    477  virtual void ScrollToPoint(uint32_t aCoordinateType, int32_t aX,
    478                             int32_t aY) = 0;
    479 
    480  /**
    481   * Return true if the accessible is scrollable.
    482   */
    483  virtual bool IsScrollable() const = 0;
    484 
    485  /**
    486   * Return tag name of associated DOM node.
    487   */
    488  virtual nsAtom* TagName() const = 0;
    489 
    490  /**
    491   * Return a landmark role if applied.
    492   */
    493  nsStaticAtom* LandmarkRole() const;
    494 
    495  /**
    496   * Return the id of the DOM node this Accessible represents.
    497   */
    498  virtual void DOMNodeID(nsString& aID) const = 0;
    499 
    500  /**
    501   * Return the class of the DOM node this Accessible represents.
    502   */
    503  virtual void DOMNodeClass(nsString& aClass) const = 0;
    504 
    505  //////////////////////////////////////////////////////////////////////////////
    506  // ActionAccessible
    507 
    508  /**
    509   * Return the number of actions that can be performed on this accessible.
    510   */
    511  virtual uint8_t ActionCount() const = 0;
    512 
    513  /**
    514   * Return action name at given index.
    515   */
    516  virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) = 0;
    517 
    518  /**
    519   * Default to localized action name.
    520   */
    521  void ActionDescriptionAt(uint8_t aIndex, nsAString& aDescription) {
    522    nsAutoString name;
    523    ActionNameAt(aIndex, name);
    524    TranslateString(name, aDescription);
    525  }
    526 
    527  /**
    528   * Invoke the accessible action.
    529   */
    530  virtual bool DoAction(uint8_t aIndex) const = 0;
    531 
    532  /**
    533   * Return access key, such as Alt+D.
    534   */
    535  virtual KeyBinding AccessKey() const = 0;
    536 
    537  //////////////////////////////////////////////////////////////////////////////
    538  // SelectAccessible
    539 
    540  /**
    541   * Return an array of selected items.
    542   */
    543  virtual void SelectedItems(nsTArray<Accessible*>* aItems) = 0;
    544 
    545  /**
    546   * Return the number of selected items.
    547   */
    548  virtual uint32_t SelectedItemCount() = 0;
    549 
    550  /**
    551   * Return selected item at the given index.
    552   */
    553  virtual Accessible* GetSelectedItem(uint32_t aIndex) = 0;
    554 
    555  /**
    556   * Determine if item at the given index is selected.
    557   */
    558  virtual bool IsItemSelected(uint32_t aIndex) = 0;
    559 
    560  /**
    561   * Add item at the given index the selection. Return true if success.
    562   */
    563  virtual bool AddItemToSelection(uint32_t aIndex) = 0;
    564 
    565  /**
    566   * Remove item at the given index from the selection. Return if success.
    567   */
    568  virtual bool RemoveItemFromSelection(uint32_t aIndex) = 0;
    569 
    570  /**
    571   * Select all items. Return true if success.
    572   */
    573  virtual bool SelectAll() = 0;
    574 
    575  /**
    576   * Unselect all items. Return true if success.
    577   */
    578  virtual bool UnselectAll() = 0;
    579 
    580  virtual void TakeSelection() = 0;
    581 
    582  virtual void SetSelected(bool aSelect) = 0;
    583 
    584  // Type "is" methods
    585 
    586  bool IsAbbreviation() const { return mType == eHTMLAbbrevType; }
    587 
    588  bool IsDoc() const { return HasGenericType(eDocument); }
    589 
    590  bool IsTableRow() const { return HasGenericType(eTableRow); }
    591 
    592  bool IsTableCell() const {
    593    // The eTableCell type defined in the ARIA map is used in
    594    // nsAccessibilityService::CreateAccessible to specify when
    595    // ARIAGridCellAccessible should be used for object creation. However, an
    596    // invalid table structure might cause this class not to be used after all.
    597    // To make sure we're really dealing with a cell, only check the generic
    598    // type defined by the class, not the type defined in the ARIA map.
    599    return mGenericTypes & eTableCell;
    600  }
    601 
    602  bool IsTable() const { return HasGenericType(eTable); }
    603 
    604  bool IsHyperText() const { return HasGenericType(eHyperText); }
    605 
    606  bool IsSelect() const { return HasGenericType(eSelect); }
    607 
    608  bool IsText() const { return mGenericTypes & eText; }
    609 
    610  bool IsImage() const { return mType == eImageType; }
    611 
    612  bool IsApplication() const { return mType == eApplicationType; }
    613 
    614  bool IsAlert() const { return HasGenericType(eAlert); }
    615 
    616  bool IsButton() const { return HasGenericType(eButton); }
    617 
    618  bool IsCombobox() const { return HasGenericType(eCombobox); }
    619 
    620  virtual bool IsLink() const = 0;
    621 
    622  /**
    623   * Return true if the used ARIA role (if any) allows the hypertext accessible
    624   * to expose text interfaces.
    625   */
    626  bool IsTextRole();
    627 
    628  virtual bool IsEditable() const = 0;
    629 
    630  bool IsEditableRoot() const;
    631 
    632  bool IsGenericHyperText() const { return mType == eHyperTextType; }
    633 
    634  bool IsHTMLBr() const { return mType == eHTMLBRType; }
    635  bool IsHTMLCaption() const { return mType == eHTMLCaptionType; }
    636  bool IsHTMLCombobox() const { return mType == eHTMLComboboxType; }
    637  bool IsHTMLFileInput() const { return mType == eHTMLFileInputType; }
    638 
    639  bool IsHTMLListItem() const { return mType == eHTMLLiType; }
    640 
    641  bool IsHTMLLink() const { return mType == eHTMLLinkType; }
    642 
    643  bool IsHTMLOptGroup() const { return mType == eHTMLOptGroupType; }
    644 
    645  bool IsHTMLRadioButton() const { return mType == eHTMLRadioButtonType; }
    646 
    647  bool IsHTMLSpinner() const { return mType == eHTMLSpinnerType; }
    648 
    649  bool IsHTMLTable() const { return mType == eHTMLTableType; }
    650  bool IsHTMLTableCell() const { return mType == eHTMLTableCellType; }
    651  bool IsHTMLTableRow() const { return mType == eHTMLTableRowType; }
    652 
    653  bool IsImageMap() const { return mType == eImageMapType; }
    654 
    655  bool IsList() const { return HasGenericType(eList); }
    656 
    657  bool IsListControl() const { return HasGenericType(eListControl); }
    658 
    659  bool IsMenuButton() const { return HasGenericType(eMenuButton); }
    660 
    661  bool IsMenuPopup() const { return mType == eMenuPopupType; }
    662 
    663  bool IsOuterDoc() const { return mType == eOuterDocType; }
    664 
    665  bool IsProgress() const { return mType == eProgressType; }
    666 
    667  virtual bool IsPopover() const = 0;
    668 
    669  bool IsRoot() const { return mType == eRootType; }
    670 
    671  bool IsPassword() const { return mType == eHTMLTextPasswordFieldType; }
    672 
    673  bool IsTextLeaf() const { return mType == eTextLeafType; }
    674 
    675  bool IsXULLabel() const { return mType == eXULLabelType; }
    676 
    677  bool IsXULListItem() const { return mType == eXULListItemType; }
    678 
    679  bool IsXULTabpanels() const { return mType == eXULTabpanelsType; }
    680 
    681  bool IsXULTooltip() const { return mType == eXULTooltipType; }
    682 
    683  bool IsXULTree() const { return mType == eXULTreeType; }
    684 
    685  bool IsAutoCompletePopup() const {
    686    return HasGenericType(eAutoCompletePopup);
    687  }
    688 
    689  bool IsTextField() const {
    690    return mType == eHTMLTextFieldType || mType == eHTMLTextPasswordFieldType;
    691  }
    692 
    693  bool IsDateTimeField() const { return mType == eHTMLDateTimeFieldType; }
    694 
    695  virtual bool HasNumericValue() const = 0;
    696 
    697  /**
    698   * Returns true if this is a generic container element that has no meaning on
    699   * its own.
    700   */
    701  bool IsGeneric() const {
    702    role accRole = Role();
    703    return accRole == roles::TEXT || accRole == roles::TEXT_CONTAINER ||
    704           accRole == roles::SECTION;
    705  }
    706 
    707  /**
    708   * Returns the nearest ancestor in the document which is not a generic
    709   * element.
    710   */
    711  Accessible* GetNonGenericParent() const {
    712    for (Accessible* parent = Parent(); parent; parent = parent->Parent()) {
    713      if (parent->IsDoc() || !parent->IsGeneric()) {
    714        return parent;
    715      }
    716    }
    717    return nullptr;
    718  }
    719 
    720  /**
    721   * Returns true if the accessible is non-interactive.
    722   */
    723  bool IsNonInteractive() const {
    724    if (IsGeneric()) {
    725      return true;
    726    }
    727    const role accRole = Role();
    728    return accRole == role::LANDMARK || accRole == role::REGION;
    729  }
    730 
    731  /**
    732   * Return true if the link is valid (e. g. points to a valid URL).
    733   */
    734  bool IsLinkValid();
    735 
    736  /**
    737   * Return the number of anchors within the link.
    738   */
    739  uint32_t AnchorCount();
    740 
    741  /**
    742   * Returns an anchor URI at the given index.
    743   */
    744  virtual already_AddRefed<nsIURI> AnchorURIAt(uint32_t aAnchorIndex) const;
    745 
    746  /**
    747   * Returns an anchor accessible at the given index.
    748   */
    749  Accessible* AnchorAt(uint32_t aAnchorIndex) const;
    750 
    751  // Remote/Local types
    752 
    753  virtual bool IsRemote() const = 0;
    754  RemoteAccessible* AsRemote();
    755 
    756  bool IsLocal() const { return !IsRemote(); }
    757  LocalAccessible* AsLocal();
    758 
    759  virtual HyperTextAccessibleBase* AsHyperTextBase() { return nullptr; }
    760 
    761  virtual TableAccessible* AsTable() { return nullptr; }
    762  virtual TableCellAccessible* AsTableCell() { return nullptr; }
    763 
    764 #ifdef A11Y_LOG
    765  /**
    766   * Provide a human readable description of the accessible,
    767   * including memory address, role, name, DOM tag and DOM ID.
    768   */
    769  void DebugDescription(nsCString& aDesc) const;
    770 
    771  static void DebugPrint(const char* aPrefix, const Accessible* aAccessible);
    772 #endif
    773 
    774  /**
    775   * Return the localized string for the given key.
    776   */
    777  static void TranslateString(const nsString& aKey, nsAString& aStringOut,
    778                              const nsTArray<nsString>& aParams = {});
    779 
    780  /*
    781   * Return calculated group level based on accessible hierarchy.
    782   *
    783   * @param aFast  [in] Don't climb up tree. Calculate level from aria and
    784   *                    roles.
    785   */
    786  virtual int32_t GetLevel(bool aFast) const;
    787 
    788  /**
    789   * Return true if accessible has a primary action directly related to it, like
    790   * "click", "activate", "press", "jump", "open", "close", etc. A non-primary
    791   * action would be a complementary one like "showlongdesc".
    792   * If an accessible has an action that is associated with an ancestor, it is
    793   * not a primary action either.
    794   */
    795  virtual bool HasPrimaryAction() const = 0;
    796 
    797  /**
    798   * Return true if this Accessible has custom actions, even if those actions
    799   * aren't currently available. Custom actions are secondary actions provided
    800   * by the author using associated elements (e.g. via aria-actions), in
    801   * contrast to actions provided by Gecko on the element itself (e.g. click).
    802   * Custom actions are queried using RelationByType(RelationType::ACTION).
    803   * However, there can be cases where there are associated custom actions, but
    804   * the target elements are hidden; e.g. because the origin element isn't
    805   * focused. The client might need to know there are actions even if it can't
    806   * currently query them. For this case, this function will return true, even
    807   * though RelationByType will return nothing.
    808   */
    809  virtual bool HasCustomActions() const = 0;
    810 
    811 protected:
    812  // Some abstracted group utility methods.
    813 
    814  /**
    815   * Get ARIA group attributes.
    816   */
    817  virtual void ARIAGroupPosition(int32_t* aLevel, int32_t* aSetSize,
    818                                 int32_t* aPosInSet) const = 0;
    819 
    820  /**
    821   * Return group info if there is an up-to-date version.
    822   */
    823  virtual AccGroupInfo* GetGroupInfo() const = 0;
    824 
    825  /**
    826   * Return group info or create and update.
    827   */
    828  virtual AccGroupInfo* GetOrCreateGroupInfo() = 0;
    829 
    830  /**
    831   * Calculate position in group and group size ('posinset' and 'setsize') based
    832   * on accessible hierarchy.
    833   *
    834   * @param  aPosInSet  [out] accessible position in the group
    835   * @param  aSetSize   [out] the group size
    836   */
    837  virtual void GetPositionAndSetSize(int32_t* aPosInSet, int32_t* aSetSize);
    838 
    839  /**
    840   * Return the nearest ancestor that has a primary action, or null.
    841   */
    842  const Accessible* ActionAncestor() const;
    843 
    844  /**
    845   * Apply states which are implied by other information common to both
    846   * LocalAccessible and RemoteAccessible.
    847   */
    848  void ApplyImplicitState(uint64_t& aState) const;
    849 
    850  /**
    851   * Return the minimum role that should be used as a last resort if the element
    852   * does not have a more specific role.
    853   */
    854  mozilla::a11y::role GetMinimumRole(mozilla::a11y::role aRole) const;
    855 
    856  /**
    857   * Given a role and an accessible's state, parentage, and other attributes
    858   * transform the role to reflect its correct aria role.
    859   */
    860  mozilla::a11y::role ARIATransformRole(mozilla::a11y::role aRole) const;
    861 
    862 private:
    863  static const uint8_t kTypeBits = 6;
    864  static const uint8_t kGenericTypesBits = 18;
    865 
    866  void StaticAsserts() const;
    867 
    868  /*
    869   * This function assumes that the current role is not valid. It searches for a
    870   * fallback role in the role attribute string, and returns it. If there is no
    871   * valid fallback role in the role attribute string, the function returns the
    872   * native role. The aRolesToSkip parameter will cause the function to skip any
    873   * roles found in the role attribute string when searching for the next valid
    874   * role.
    875   */
    876  role FindNextValidARIARole(
    877      std::initializer_list<nsStaticAtom*> aRolesToSkip) const;
    878 
    879 protected:
    880  uint32_t mType : kTypeBits;
    881  uint32_t mGenericTypes : kGenericTypesBits;
    882  uint8_t mRoleMapEntryIndex;
    883 
    884  friend class DocAccessibleChild;
    885  friend class AccGroupInfo;
    886 };
    887 
    888 }  // namespace a11y
    889 }  // namespace mozilla
    890 
    891 #endif