1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_a11y_ProxyAccessibleBase_h
8 #define mozilla_a11y_ProxyAccessibleBase_h
10 #include "mozilla/a11y/Role.h"
11 #include "nsIAccessibleText.h"
12 #include "nsIAccessibleTypes.h"
13 #include "Accessible.h"
17 #include "Accessible.h"
24 class DocAccessibleParent
;
25 class ProxyAccessible
;
26 enum class RelationType
;
40 template <class Derived
>
41 class ProxyAccessibleBase
{
43 ~ProxyAccessibleBase() { MOZ_ASSERT(!mWrapper
); }
45 void AddChildAt(uint32_t aIdx
, Derived
* aChild
) {
46 mChildren
.InsertElementAt(aIdx
, aChild
);
49 uint32_t ChildrenCount() const { return mChildren
.Length(); }
50 Derived
* ChildAt(uint32_t aIdx
) const { return mChildren
[aIdx
]; }
51 Derived
* FirstChild() const {
52 return mChildren
.Length() ? mChildren
[0] : nullptr;
54 Derived
* LastChild() const {
55 return mChildren
.Length() ? mChildren
[mChildren
.Length() - 1] : nullptr;
57 Derived
* PrevSibling() const {
58 size_t idx
= IndexInParent();
59 return idx
> 0 ? Parent()->mChildren
[idx
- 1] : nullptr;
61 Derived
* NextSibling() const {
62 size_t idx
= IndexInParent();
63 return idx
+ 1 < Parent()->mChildren
.Length() ? Parent()->mChildren
[idx
+ 1]
67 // XXX evaluate if this is fast enough.
68 size_t IndexInParent() const {
69 return Parent()->mChildren
.IndexOf(static_cast<const Derived
*>(this));
71 uint32_t EmbeddedChildCount() const;
72 int32_t IndexOfEmbeddedChild(const Derived
* aChild
);
73 Derived
* EmbeddedChildAt(size_t aChildIdx
);
77 void SetChildDoc(DocAccessibleParent
* aChildDoc
);
78 void ClearChildDoc(DocAccessibleParent
* aChildDoc
);
81 * Remove The given child.
83 void RemoveChild(Derived
* aChild
) { mChildren
.RemoveElement(aChild
); }
86 * Return the proxy for the parent of the wrapped accessible.
88 Derived
* Parent() const;
90 Accessible
* OuterDocOfRemoteBrowser() const;
93 * Get the role of the accessible we're proxying.
95 role
Role() const { return mRole
; }
98 * Return true if this is an embedded object.
100 bool IsEmbeddedObject() const {
102 return role
!= roles::TEXT_LEAF
&& role
!= roles::WHITESPACE
&&
103 role
!= roles::STATICTEXT
;
107 * Allow the platform to store a pointers worth of data on us.
109 uintptr_t GetWrapper() const { return mWrapper
; }
110 void SetWrapper(uintptr_t aWrapper
) { mWrapper
= aWrapper
; }
113 * Return the ID of the accessible being proxied.
115 uint64_t ID() const { return mID
; }
118 * Return the document containing this proxy, or the proxy itself if it is a
121 DocAccessibleParent
* Document() const { return mDoc
; }
124 * Return true if this proxy is a DocAccessibleParent.
126 bool IsDoc() const { return mIsDoc
; }
127 DocAccessibleParent
* AsDoc() const { return IsDoc() ? mDoc
: nullptr; }
129 // XXX checking mRole alone may not result in same behavior as Accessibles
130 // due to ARIA roles. See bug 1210477.
131 inline bool IsTable() const {
132 return mRole
== roles::TABLE
|| mRole
== roles::MATHML_TABLE
;
134 inline bool IsTableRow() const {
135 return (mRole
== roles::ROW
|| mRole
== roles::MATHML_TABLE_ROW
||
136 mRole
== roles::MATHML_LABELED_ROW
);
138 inline bool IsTableCell() const {
139 return (mRole
== roles::CELL
|| mRole
== roles::COLUMNHEADER
||
140 mRole
== roles::ROWHEADER
|| mRole
== roles::GRID_CELL
||
141 mRole
== roles::MATHML_CELL
);
145 ProxyAccessibleBase(uint64_t aID
, Derived
* aParent
, DocAccessibleParent
* aDoc
,
146 role aRole
, uint32_t aInterfaces
)
147 : mParent(aParent
->ID()),
154 mHasValue(aInterfaces
& Interfaces::VALUE
),
155 mIsHyperLink(aInterfaces
& Interfaces::HYPERLINK
),
156 mIsHyperText(aInterfaces
& Interfaces::HYPERTEXT
),
157 mIsSelection(aInterfaces
& Interfaces::SELECTION
) {}
159 explicit ProxyAccessibleBase(DocAccessibleParent
* aThisAsDoc
)
160 : mParent(kNoParent
),
164 mRole(roles::DOCUMENT
),
170 mIsSelection(false) {}
173 void SetParent(Derived
* aParent
);
177 static const uintptr_t kNoParent
= UINTPTR_MAX
;
181 nsTArray
<Derived
*> mChildren
;
182 DocAccessibleParent
* mDoc
;
187 // XXX DocAccessibleParent gets to change this to change the role of
195 const bool mIsDoc
: 1;
196 const bool mHasValue
: 1;
197 const bool mIsHyperLink
: 1;
198 const bool mIsHyperText
: 1;
199 const bool mIsSelection
: 1;
202 extern template class ProxyAccessibleBase
<ProxyAccessible
>;
205 } // namespace mozilla