/src/mozilla-central/accessible/xul/XULTreeAccessible.h
Line | Count | Source (jump to first uncovered line) |
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 mozilla_a11y_XULTreeAccessible_h__ |
7 | | #define mozilla_a11y_XULTreeAccessible_h__ |
8 | | |
9 | | #include "nsITreeBoxObject.h" |
10 | | #include "nsITreeView.h" |
11 | | #include "XULListboxAccessible.h" |
12 | | |
13 | | class nsTreeBodyFrame; |
14 | | class nsTreeColumn; |
15 | | |
16 | | namespace mozilla { |
17 | | namespace a11y { |
18 | | |
19 | | class XULTreeGridCellAccessible; |
20 | | |
21 | | /* |
22 | | * A class the represents the XUL Tree widget. |
23 | | */ |
24 | | const uint32_t kMaxTreeColumns = 100; |
25 | | const uint32_t kDefaultTreeCacheLength = 128; |
26 | | |
27 | | /** |
28 | | * Accessible class for XUL tree element. |
29 | | */ |
30 | | |
31 | | class XULTreeAccessible : public AccessibleWrap |
32 | | { |
33 | | public: |
34 | | XULTreeAccessible(nsIContent* aContent, DocAccessible* aDoc, |
35 | | nsTreeBodyFrame* aTreeframe); |
36 | | |
37 | | // nsISupports and cycle collection |
38 | | NS_DECL_ISUPPORTS_INHERITED |
39 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeAccessible, Accessible) |
40 | | |
41 | | // Accessible |
42 | | virtual void Shutdown() override; |
43 | | virtual void Value(nsString& aValue) const override; |
44 | | virtual a11y::role NativeRole() const override; |
45 | | virtual uint64_t NativeState() const override; |
46 | | virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY, |
47 | | EWhichChildAtPoint aWhichChild) override; |
48 | | |
49 | | virtual Accessible* GetChildAt(uint32_t aIndex) const override; |
50 | | virtual uint32_t ChildCount() const override; |
51 | | virtual Relation RelationByType(RelationType aType) const override; |
52 | | |
53 | | // SelectAccessible |
54 | | virtual void SelectedItems(nsTArray<Accessible*>* aItems) override; |
55 | | virtual uint32_t SelectedItemCount() override; |
56 | | virtual Accessible* GetSelectedItem(uint32_t aIndex) override; |
57 | | virtual bool IsItemSelected(uint32_t aIndex) override; |
58 | | virtual bool AddItemToSelection(uint32_t aIndex) override; |
59 | | virtual bool RemoveItemFromSelection(uint32_t aIndex) override; |
60 | | virtual bool SelectAll() override; |
61 | | virtual bool UnselectAll() override; |
62 | | |
63 | | // Widgets |
64 | | virtual bool IsWidget() const override; |
65 | | virtual bool IsActiveWidget() const override; |
66 | | virtual bool AreItemsOperable() const override; |
67 | | virtual Accessible* CurrentItem() const override; |
68 | | virtual void SetCurrentItem(const Accessible* aItem) override; |
69 | | |
70 | | virtual Accessible* ContainerWidget() const override; |
71 | | |
72 | | // XULTreeAccessible |
73 | | |
74 | | /** |
75 | | * Return tree item accessible at the givem row. If accessible doesn't exist |
76 | | * in the cache then create and cache it. |
77 | | * |
78 | | * @param aRow [in] the given row index |
79 | | */ |
80 | | Accessible* GetTreeItemAccessible(int32_t aRow) const; |
81 | | |
82 | | /** |
83 | | * Invalidates the number of cached treeitem accessibles. |
84 | | * |
85 | | * @param aRow [in] row index the invalidation starts from |
86 | | * @param aCount [in] the number of treeitem accessibles to invalidate, |
87 | | * the number sign specifies whether rows have been |
88 | | * inserted (plus) or removed (minus) |
89 | | */ |
90 | | void InvalidateCache(int32_t aRow, int32_t aCount); |
91 | | |
92 | | /** |
93 | | * Fires name change events for invalidated area of tree. |
94 | | * |
95 | | * @param aStartRow [in] row index invalidation starts from |
96 | | * @param aEndRow [in] row index invalidation ends, -1 means last row index |
97 | | * @param aStartCol [in] column index invalidation starts from |
98 | | * @param aEndCol [in] column index invalidation ends, -1 mens last column |
99 | | * index |
100 | | */ |
101 | | void TreeViewInvalidated(int32_t aStartRow, int32_t aEndRow, |
102 | | int32_t aStartCol, int32_t aEndCol); |
103 | | |
104 | | /** |
105 | | * Invalidates children created for previous tree view. |
106 | | */ |
107 | | void TreeViewChanged(nsITreeView* aView); |
108 | | |
109 | | protected: |
110 | | virtual ~XULTreeAccessible(); |
111 | | |
112 | | /** |
113 | | * Creates tree item accessible for the given row index. |
114 | | */ |
115 | | virtual already_AddRefed<Accessible> |
116 | | CreateTreeItemAccessible(int32_t aRow) const; |
117 | | |
118 | | nsCOMPtr<nsITreeBoxObject> mTree; |
119 | | nsITreeView* mTreeView; |
120 | | mutable AccessibleHashtable mAccessibleCache; |
121 | | }; |
122 | | |
123 | | /** |
124 | | * Base class for tree item accessibles. |
125 | | */ |
126 | | |
127 | | #define XULTREEITEMBASEACCESSIBLE_IMPL_CID \ |
128 | | { /* 1ab79ae7-766a-443c-940b-b1e6b0831dfc */ \ |
129 | | 0x1ab79ae7, \ |
130 | | 0x766a, \ |
131 | | 0x443c, \ |
132 | | { 0x94, 0x0b, 0xb1, 0xe6, 0xb0, 0x83, 0x1d, 0xfc } \ |
133 | | } |
134 | | |
135 | | class XULTreeItemAccessibleBase : public AccessibleWrap |
136 | | { |
137 | | public: |
138 | | XULTreeItemAccessibleBase(nsIContent* aContent, DocAccessible* aDoc, |
139 | | Accessible* aParent, nsITreeBoxObject* aTree, |
140 | | nsITreeView* aTreeView, int32_t aRow); |
141 | | |
142 | | // nsISupports and cycle collection |
143 | | NS_DECL_ISUPPORTS_INHERITED |
144 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessibleBase, |
145 | | AccessibleWrap) |
146 | | |
147 | | // Accessible |
148 | | virtual void Shutdown() override; |
149 | | virtual nsRect BoundsInAppUnits() const override; |
150 | | virtual nsIntRect BoundsInCSSPixels() const override; |
151 | | virtual GroupPos GroupPosition() override; |
152 | | virtual uint64_t NativeState() const override; |
153 | | virtual uint64_t NativeInteractiveState() const override; |
154 | | virtual int32_t IndexInParent() const override; |
155 | | virtual Relation RelationByType(RelationType aType) const override; |
156 | | virtual Accessible* FocusedChild() override; |
157 | | virtual void SetSelected(bool aSelect) override; |
158 | | virtual void TakeFocus() const override; |
159 | | |
160 | | // ActionAccessible |
161 | | virtual uint8_t ActionCount() const override; |
162 | | virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override; |
163 | | virtual bool DoAction(uint8_t aIndex) const override; |
164 | | |
165 | | // Widgets |
166 | | virtual Accessible* ContainerWidget() const override; |
167 | | |
168 | | // XULTreeItemAccessibleBase |
169 | | NS_DECLARE_STATIC_IID_ACCESSOR(XULTREEITEMBASEACCESSIBLE_IMPL_CID) |
170 | | |
171 | | /** |
172 | | * Return row index associated with the accessible. |
173 | | */ |
174 | 0 | int32_t GetRowIndex() const { return mRow; } |
175 | | |
176 | | /** |
177 | | * Return cell accessible for the given column. If XUL tree accessible is not |
178 | | * accessible table then return null. |
179 | | */ |
180 | | virtual XULTreeGridCellAccessible* GetCellAccessible(nsTreeColumn* aColumn) const |
181 | 0 | { return nullptr; } |
182 | | |
183 | | /** |
184 | | * Proccess row invalidation. Used to fires name change events. |
185 | | */ |
186 | | virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) = 0; |
187 | | |
188 | | protected: |
189 | | virtual ~XULTreeItemAccessibleBase(); |
190 | | |
191 | | enum { eAction_Click = 0, eAction_Expand = 1 }; |
192 | | |
193 | | // Accessible |
194 | | virtual void DispatchClickEvent(nsIContent *aContent, |
195 | | uint32_t aActionIndex) const override; |
196 | | virtual Accessible* GetSiblingAtOffset(int32_t aOffset, |
197 | | nsresult *aError = nullptr) const override; |
198 | | |
199 | | // XULTreeItemAccessibleBase |
200 | | |
201 | | /** |
202 | | * Return true if the tree item accessible is expandable (contains subrows). |
203 | | */ |
204 | | bool IsExpandable() const; |
205 | | |
206 | | /** |
207 | | * Return name for cell at the given column. |
208 | | */ |
209 | | void GetCellName(nsTreeColumn* aColumn, nsAString& aName) const; |
210 | | |
211 | | nsCOMPtr<nsITreeBoxObject> mTree; |
212 | | nsITreeView* mTreeView; |
213 | | int32_t mRow; |
214 | | }; |
215 | | |
216 | | NS_DEFINE_STATIC_IID_ACCESSOR(XULTreeItemAccessibleBase, |
217 | | XULTREEITEMBASEACCESSIBLE_IMPL_CID) |
218 | | |
219 | | |
220 | | /** |
221 | | * Accessible class for items for XUL tree. |
222 | | */ |
223 | | class XULTreeItemAccessible : public XULTreeItemAccessibleBase |
224 | | { |
225 | | public: |
226 | | XULTreeItemAccessible(nsIContent* aContent, DocAccessible* aDoc, |
227 | | Accessible* aParent, nsITreeBoxObject* aTree, |
228 | | nsITreeView* aTreeView, int32_t aRow); |
229 | | |
230 | | // nsISupports and cycle collection |
231 | | NS_DECL_ISUPPORTS_INHERITED |
232 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessible, |
233 | | XULTreeItemAccessibleBase) |
234 | | |
235 | | // Accessible |
236 | | virtual void Shutdown() override; |
237 | | virtual ENameValueFlag Name(nsString& aName) const override; |
238 | | virtual a11y::role NativeRole() const override; |
239 | | |
240 | | // XULTreeItemAccessibleBase |
241 | | virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) override; |
242 | | |
243 | | protected: |
244 | | virtual ~XULTreeItemAccessible(); |
245 | | |
246 | | // XULTreeItemAccessible |
247 | | RefPtr<nsTreeColumn> mColumn; |
248 | | nsString mCachedName; |
249 | | }; |
250 | | |
251 | | |
252 | | /** |
253 | | * Accessible class for columns element of XUL tree. |
254 | | */ |
255 | | class XULTreeColumAccessible : public XULColumAccessible |
256 | | { |
257 | | public: |
258 | | XULTreeColumAccessible(nsIContent* aContent, DocAccessible* aDoc); |
259 | | |
260 | | protected: |
261 | | |
262 | | // Accessible |
263 | | virtual Accessible* GetSiblingAtOffset(int32_t aOffset, |
264 | | nsresult* aError = nullptr) const |
265 | | override; |
266 | | }; |
267 | | |
268 | | |
269 | | //////////////////////////////////////////////////////////////////////////////// |
270 | | // Accessible downcasting method |
271 | | |
272 | | inline XULTreeAccessible* |
273 | | Accessible::AsXULTree() |
274 | 0 | { |
275 | 0 | return IsXULTree() ? static_cast<XULTreeAccessible*>(this) : nullptr; |
276 | 0 | } |
277 | | |
278 | | } // namespace a11y |
279 | | } // namespace mozilla |
280 | | |
281 | | #endif |