/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef _Accessible_H_ #define _Accessible_H_ #include "mozilla/a11y/Role.h" #include "mozilla/a11y/AccTypes.h" #include "nsString.h" #include "nsRect.h" #include "Units.h" class nsAtom; class nsStaticAtom; struct nsRoleMapEntry; class nsIURI; namespace mozilla { namespace a11y { class AccAttributes; class AccGroupInfo; class HyperTextAccessibleBase; class LocalAccessible; class Relation; enum class RelationType; class RemoteAccessible; class TableAccessible; class TableCellAccessible; /** * Name type flags. */ enum ENameValueFlag { /** * Name either * a) present (not empty): !name.IsEmpty() * b) no name (was missed): name.IsVoid() */ eNameOK, /** * Name was computed from the subtree. */ eNameFromSubtree, /** * Tooltip was used as a name. */ eNameFromTooltip }; /** * Group position (level, position in set and set size). */ struct GroupPos { GroupPos() : level(0), posInSet(0), setSize(0) {} GroupPos(int32_t aLevel, int32_t aPosInSet, int32_t aSetSize) : level(aLevel), posInSet(aPosInSet), setSize(aSetSize) {} int32_t level; int32_t posInSet; int32_t setSize; }; /** * Represent key binding associated with accessible (such as access key and * global keyboard shortcuts). */ class KeyBinding { public: /** * Modifier mask values. */ static const uint32_t kShift = 1; static const uint32_t kControl = 2; static const uint32_t kAlt = 4; static const uint32_t kMeta = 8; static uint32_t AccelModifier(); KeyBinding() : mKey(0), mModifierMask(0) {} KeyBinding(uint32_t aKey, uint32_t aModifierMask) : mKey(aKey), mModifierMask(aModifierMask) {} explicit KeyBinding(uint64_t aSerialized) : mSerialized(aSerialized) {} inline bool IsEmpty() const { return !mKey; } inline uint32_t Key() const { return mKey; } inline uint32_t ModifierMask() const { return mModifierMask; } /** * Serialize this KeyBinding to a uint64_t for use in the parent process * cache. This is simpler than custom IPDL serialization for this simple case. */ uint64_t Serialize() { return mSerialized; } enum Format { ePlatformFormat, eAtkFormat }; /** * Return formatted string for this key binding depending on the given format. */ inline void ToString(nsAString& aValue, Format aFormat = ePlatformFormat) const { aValue.Truncate(); AppendToString(aValue, aFormat); } inline void AppendToString(nsAString& aValue, Format aFormat = ePlatformFormat) const { if (mKey) { if (aFormat == ePlatformFormat) { ToPlatformFormat(aValue); } else { ToAtkFormat(aValue); } } } private: void ToPlatformFormat(nsAString& aValue) const; void ToAtkFormat(nsAString& aValue) const; union { struct { uint32_t mKey; uint32_t mModifierMask; }; uint64_t mSerialized; }; }; /** * The base type for an accessibility tree node. Methods and attributes in this * class are available in both the content process and the parent process. * Overrides for these methods live primarily in LocalAccessible and * RemoteAccessibleBase. */ class Accessible { protected: Accessible(); Accessible(AccType aType, AccGenericType aGenericTypes, uint8_t aRoleMapEntryIndex); public: /** * Return an id for this Accessible which is unique within the document. * Use nsAccUtils::GetAccessibleByID to retrieve an Accessible given an id * returned from this method. */ virtual uint64_t ID() const = 0; virtual Accessible* Parent() const = 0; virtual role Role() const = 0; /** * Return child accessible at the given index. */ virtual Accessible* ChildAt(uint32_t aIndex) const = 0; virtual Accessible* NextSibling() const = 0; virtual Accessible* PrevSibling() const = 0; virtual uint32_t ChildCount() const = 0; virtual int32_t IndexInParent() const = 0; bool HasChildren() const { return !!FirstChild(); } inline Accessible* FirstChild() const { return ChildCount() ? ChildAt(0) : nullptr; } inline Accessible* LastChild() const { uint32_t childCount = ChildCount(); return childCount ? ChildAt(childCount - 1) : nullptr; } /** * Return true if this Accessible is before another Accessible in the tree. */ bool IsBefore(const Accessible* aAcc) const; bool IsAncestorOf(const Accessible* aAcc) const { for (const Accessible* parent = aAcc->Parent(); parent; parent = parent->Parent()) { if (parent == this) { return true; } } return false; } /** * Used by ChildAtPoint() method to get direct or deepest child at point. */ enum class EWhichChildAtPoint { DirectChild, DeepestChild }; virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY, EWhichChildAtPoint aWhichChild) = 0; /** * Return the focused child if any. */ virtual Accessible* FocusedChild(); /** * Return ARIA role map if any. */ const nsRoleMapEntry* ARIARoleMap() const; /** * Return true if ARIA role is specified on the element. */ bool HasARIARole() const; bool IsARIARole(nsAtom* aARIARole) const; bool HasStrongARIARole() const; /** * Return true if the accessible belongs to the given accessible type. */ bool HasGenericType(AccGenericType aType) const; /** * Return group position (level, position in set and set size). */ virtual GroupPos GroupPosition(); /** * Return embedded accessible children count. */ virtual uint32_t EmbeddedChildCount() = 0; /** * Return embedded accessible child at the given index. */ virtual Accessible* EmbeddedChildAt(uint32_t aIndex) = 0; /** * Return index of the given embedded accessible child. */ virtual int32_t IndexOfEmbeddedChild(Accessible* aChild) = 0; // Methods that potentially access a cache. /* * Get the name of this accessible. */ virtual ENameValueFlag Name(nsString& aName) const = 0; /* * Return true if the accessible name is empty. */ bool NameIsEmpty() const; /* * Get the description of this accessible. */ virtual void Description(nsString& aDescription) const = 0; /** * Get the value of this accessible. */ virtual void Value(nsString& aValue) const = 0; virtual double CurValue() const = 0; virtual double MinValue() const = 0; virtual double MaxValue() const = 0; virtual double Step() const = 0; virtual bool SetCurValue(double aValue) = 0; /** * Return boundaries in screen coordinates in device pixels. */ virtual LayoutDeviceIntRect Bounds() const = 0; /** * Return boundaries in screen coordinates in app units. */ virtual nsRect BoundsInAppUnits() const = 0; /** * Return boundaries in screen coordinates in CSS pixels. */ virtual nsIntRect BoundsInCSSPixels() const; /** * Returns text of accessible if accessible has text role otherwise empty * string. * * @param aText [in] returned text of the accessible * @param aStartOffset [in, optional] start offset inside of the accessible, * if missed entire text is appended * @param aLength [in, optional] required length of text, if missed * then text from start offset till the end is appended */ virtual void AppendTextTo(nsAString& aText, uint32_t aStartOffset = 0, uint32_t aLength = UINT32_MAX) = 0; /** * Return all states of accessible (including ARIA states). */ virtual uint64_t State() = 0; /** * Return the start offset of the embedded object within the parent * HyperTextAccessibleBase. */ virtual uint32_t StartOffset(); /** * Return the end offset of the link within the parent * HyperTextAccessibleBase. */ virtual uint32_t EndOffset(); /** * Return object attributes for the accessible. */ virtual already_AddRefed Attributes() = 0; virtual already_AddRefed DisplayStyle() const = 0; virtual float Opacity() const = 0; /** * Get the live region attributes (if any) for this single Accessible. This * does not propagate attributes from ancestors. If any argument is null, that * attribute is not fetched. */ virtual void LiveRegionAttributes(nsAString* aLive, nsAString* aRelevant, Maybe* aAtomic, nsAString* aBusy) const = 0; /** * Get the aria-selected state. aria-selected not being specified is not * always the same as aria-selected="false". If not specified, Nothing() will * be returned. */ virtual Maybe ARIASelected() const = 0; LayoutDeviceIntSize Size() const; LayoutDeviceIntPoint Position(uint32_t aCoordType); virtual Maybe GetIntARIAAttr(nsAtom* aAttrName) const = 0; /** * Get the relation of the given type. */ virtual Relation RelationByType(RelationType aType) const = 0; /** * Get the language associated with the accessible. */ virtual void Language(nsAString& aLocale) = 0; /** * Get the role of this Accessible as an ARIA role token. This might have been * set explicitly (e.g. role="button") or it might be implicit in native * markup (e.g.