Line data Source code
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 "nsITreeColumns.h"
12 : #include "XULListboxAccessible.h"
13 :
14 : class nsTreeBodyFrame;
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 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeAccessible, Accessible)
40 :
41 : // Accessible
42 : virtual void Shutdown() override;
43 : virtual void Value(nsString& aValue) override;
44 : virtual a11y::role NativeRole() override;
45 : virtual uint64_t NativeState() 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) 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() override;
68 : virtual void SetCurrentItem(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 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessibleBase,
145 : AccessibleWrap)
146 :
147 : // Accessible
148 : virtual void Shutdown() override;
149 : virtual nsIntRect Bounds() const override;
150 : virtual GroupPos GroupPosition() override;
151 : virtual uint64_t NativeState() override;
152 : virtual uint64_t NativeInteractiveState() const override;
153 : virtual int32_t IndexInParent() const override;
154 : virtual Relation RelationByType(RelationType aType) override;
155 : virtual Accessible* FocusedChild() override;
156 : virtual void SetSelected(bool aSelect) override;
157 : virtual void TakeFocus() override;
158 :
159 : // ActionAccessible
160 : virtual uint8_t ActionCount() override;
161 : virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;
162 : virtual bool DoAction(uint8_t aIndex) override;
163 :
164 : // Widgets
165 : virtual Accessible* ContainerWidget() const override;
166 :
167 : // XULTreeItemAccessibleBase
168 : NS_DECLARE_STATIC_IID_ACCESSOR(XULTREEITEMBASEACCESSIBLE_IMPL_CID)
169 :
170 : /**
171 : * Return row index associated with the accessible.
172 : */
173 : int32_t GetRowIndex() const { return mRow; }
174 :
175 : /**
176 : * Return cell accessible for the given column. If XUL tree accessible is not
177 : * accessible table then return null.
178 : */
179 0 : virtual XULTreeGridCellAccessible* GetCellAccessible(nsITreeColumn* aColumn) const
180 0 : { return nullptr; }
181 :
182 : /**
183 : * Proccess row invalidation. Used to fires name change events.
184 : */
185 : virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) = 0;
186 :
187 : protected:
188 : virtual ~XULTreeItemAccessibleBase();
189 :
190 : enum { eAction_Click = 0, eAction_Expand = 1 };
191 :
192 : // Accessible
193 : virtual void DispatchClickEvent(nsIContent *aContent, uint32_t aActionIndex) override;
194 : virtual Accessible* GetSiblingAtOffset(int32_t aOffset,
195 : nsresult *aError = nullptr) const override;
196 :
197 : // XULTreeItemAccessibleBase
198 :
199 : /**
200 : * Return true if the tree item accessible is expandable (contains subrows).
201 : */
202 : bool IsExpandable();
203 :
204 : /**
205 : * Return name for cell at the given column.
206 : */
207 : void GetCellName(nsITreeColumn* aColumn, nsAString& aName);
208 :
209 : nsCOMPtr<nsITreeBoxObject> mTree;
210 : nsITreeView* mTreeView;
211 : int32_t mRow;
212 : };
213 :
214 : NS_DEFINE_STATIC_IID_ACCESSOR(XULTreeItemAccessibleBase,
215 : XULTREEITEMBASEACCESSIBLE_IMPL_CID)
216 :
217 :
218 : /**
219 : * Accessible class for items for XUL tree.
220 : */
221 : class XULTreeItemAccessible : public XULTreeItemAccessibleBase
222 : {
223 : public:
224 : XULTreeItemAccessible(nsIContent* aContent, DocAccessible* aDoc,
225 : Accessible* aParent, nsITreeBoxObject* aTree,
226 : nsITreeView* aTreeView, int32_t aRow);
227 :
228 : // nsISupports and cycle collection
229 : NS_DECL_ISUPPORTS_INHERITED
230 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessible,
231 : XULTreeItemAccessibleBase)
232 :
233 : // Accessible
234 : virtual void Shutdown() override;
235 : virtual ENameValueFlag Name(nsString& aName) override;
236 : virtual a11y::role NativeRole() override;
237 :
238 : // XULTreeItemAccessibleBase
239 : virtual void RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) override;
240 :
241 : protected:
242 : virtual ~XULTreeItemAccessible();
243 :
244 : // XULTreeItemAccessible
245 : nsCOMPtr<nsITreeColumn> mColumn;
246 : nsString mCachedName;
247 : };
248 :
249 :
250 : /**
251 : * Accessible class for columns element of XUL tree.
252 : */
253 0 : class XULTreeColumAccessible : public XULColumAccessible
254 : {
255 : public:
256 : XULTreeColumAccessible(nsIContent* aContent, DocAccessible* aDoc);
257 :
258 : protected:
259 :
260 : // Accessible
261 : virtual Accessible* GetSiblingAtOffset(int32_t aOffset,
262 : nsresult* aError = nullptr) const
263 : override;
264 : };
265 :
266 :
267 : ////////////////////////////////////////////////////////////////////////////////
268 : // Accessible downcasting method
269 :
270 : inline XULTreeAccessible*
271 0 : Accessible::AsXULTree()
272 : {
273 0 : return IsXULTree() ? static_cast<XULTreeAccessible*>(this) : nullptr;
274 : }
275 :
276 : } // namespace a11y
277 : } // namespace mozilla
278 :
279 : #endif
|