Bug 1526581 [wpt PR 15249] - CODEOWNERS cleanup, a=testonly
[gecko.git] / accessible / ipc / ProxyAccessibleBase.h
blob15c7f74c0c43bd2be0a372ef25dc39fca17ad37e
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"
14 #include "nsString.h"
15 #include "nsTArray.h"
16 #include "nsRect.h"
17 #include "Accessible.h"
19 namespace mozilla {
20 namespace a11y {
22 class Accessible;
23 class Attribute;
24 class DocAccessibleParent;
25 class ProxyAccessible;
26 enum class RelationType;
28 enum Interfaces {
29 HYPERTEXT = 1,
30 HYPERLINK = 1 << 1,
31 IMAGE = 1 << 2,
32 VALUE = 1 << 3,
33 TABLE = 1 << 4,
34 TABLECELL = 1 << 5,
35 DOCUMENT = 1 << 6,
36 SELECTION = 1 << 7,
37 ACTION = 1 << 8,
40 template <class Derived>
41 class ProxyAccessibleBase {
42 public:
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]
64 : nullptr;
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);
75 void Shutdown();
77 void SetChildDoc(DocAccessibleParent* aChildDoc);
78 void ClearChildDoc(DocAccessibleParent* aChildDoc);
80 /**
81 * Remove The given child.
83 void RemoveChild(Derived* aChild) { mChildren.RemoveElement(aChild); }
85 /**
86 * Return the proxy for the parent of the wrapped accessible.
88 Derived* Parent() const;
90 Accessible* OuterDocOfRemoteBrowser() const;
92 /**
93 * Get the role of the accessible we're proxying.
95 role Role() const { return mRole; }
97 /**
98 * Return true if this is an embedded object.
100 bool IsEmbeddedObject() const {
101 role role = Role();
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
119 * document.
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);
144 protected:
145 ProxyAccessibleBase(uint64_t aID, Derived* aParent, DocAccessibleParent* aDoc,
146 role aRole, uint32_t aInterfaces)
147 : mParent(aParent->ID()),
148 mDoc(aDoc),
149 mWrapper(0),
150 mID(aID),
151 mRole(aRole),
152 mOuterDoc(false),
153 mIsDoc(false),
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),
161 mDoc(aThisAsDoc),
162 mWrapper(0),
163 mID(0),
164 mRole(roles::DOCUMENT),
165 mOuterDoc(false),
166 mIsDoc(true),
167 mHasValue(false),
168 mIsHyperLink(false),
169 mIsHyperText(false),
170 mIsSelection(false) {}
172 protected:
173 void SetParent(Derived* aParent);
175 private:
176 uintptr_t mParent;
177 static const uintptr_t kNoParent = UINTPTR_MAX;
179 friend Derived;
181 nsTArray<Derived*> mChildren;
182 DocAccessibleParent* mDoc;
183 uintptr_t mWrapper;
184 uint64_t mID;
186 protected:
187 // XXX DocAccessibleParent gets to change this to change the role of
188 // documents.
189 role mRole : 27;
191 private:
192 bool mOuterDoc : 1;
194 public:
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>;
204 } // namespace a11y
205 } // namespace mozilla
207 #endif