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_HTMLTableAccessible_h__
7 : #define mozilla_a11y_HTMLTableAccessible_h__
8 :
9 : #include "HyperTextAccessibleWrap.h"
10 : #include "TableAccessible.h"
11 : #include "TableCellAccessible.h"
12 :
13 : class nsITableCellLayout;
14 :
15 : namespace mozilla {
16 : namespace a11y {
17 :
18 : /**
19 : * HTML table cell accessible (html:td).
20 : */
21 : class HTMLTableCellAccessible : public HyperTextAccessibleWrap,
22 : public TableCellAccessible
23 : {
24 : public:
25 : HTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc);
26 :
27 : // nsISupports
28 : NS_DECL_ISUPPORTS_INHERITED
29 :
30 : // Accessible
31 0 : virtual TableCellAccessible* AsTableCell() override { return this; }
32 : virtual a11y::role NativeRole() override;
33 : virtual uint64_t NativeState() override;
34 : virtual uint64_t NativeInteractiveState() const override;
35 : virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override;
36 : virtual mozilla::a11y::GroupPos GroupPosition() override;
37 :
38 : // TableCellAccessible
39 : virtual TableAccessible* Table() const override;
40 : virtual uint32_t ColIdx() const override;
41 : virtual uint32_t RowIdx() const override;
42 : virtual uint32_t ColExtent() const override;
43 : virtual uint32_t RowExtent() const override;
44 : virtual void ColHeaderCells(nsTArray<Accessible*>* aCells) override;
45 : virtual void RowHeaderCells(nsTArray<Accessible*>* aCells) override;
46 : virtual bool Selected() override;
47 :
48 : protected:
49 0 : virtual ~HTMLTableCellAccessible() {}
50 :
51 : /**
52 : * Return nsITableCellLayout of the table cell frame.
53 : */
54 : nsITableCellLayout* GetCellLayout() const;
55 :
56 : /**
57 : * Return row and column indices of the cell.
58 : */
59 : nsresult GetCellIndexes(int32_t& aRowIdx, int32_t& aColIdx) const;
60 : };
61 :
62 :
63 : /**
64 : * HTML table row/column header accessible (html:th or html:td@scope).
65 : */
66 0 : class HTMLTableHeaderCellAccessible : public HTMLTableCellAccessible
67 : {
68 : public:
69 : HTMLTableHeaderCellAccessible(nsIContent* aContent, DocAccessible* aDoc);
70 :
71 : // Accessible
72 : virtual a11y::role NativeRole() override;
73 : };
74 :
75 :
76 : /**
77 : * HTML table row accessible (html:tr).
78 : */
79 : class HTMLTableRowAccessible : public AccessibleWrap
80 : {
81 : public:
82 0 : HTMLTableRowAccessible(nsIContent* aContent, DocAccessible* aDoc) :
83 0 : AccessibleWrap(aContent, aDoc)
84 : {
85 0 : mType = eHTMLTableRowType;
86 0 : mGenericTypes |= eTableRow;
87 0 : }
88 :
89 : NS_DECL_ISUPPORTS_INHERITED
90 :
91 : // Accessible
92 : virtual a11y::role NativeRole() override;
93 : virtual mozilla::a11y::GroupPos GroupPosition() override;
94 :
95 : protected:
96 0 : virtual ~HTMLTableRowAccessible() { }
97 : };
98 :
99 :
100 : /**
101 : * HTML table accessible (html:table).
102 : */
103 :
104 : // To turn on table debugging descriptions define SHOW_LAYOUT_HEURISTIC
105 : // This allow release trunk builds to be used by testers to refine the
106 : // data vs. layout heuristic
107 : // #define SHOW_LAYOUT_HEURISTIC
108 :
109 : class HTMLTableAccessible : public AccessibleWrap,
110 : public TableAccessible
111 : {
112 : public:
113 0 : HTMLTableAccessible(nsIContent* aContent, DocAccessible* aDoc) :
114 0 : AccessibleWrap(aContent, aDoc)
115 : {
116 0 : mType = eHTMLTableType;
117 0 : mGenericTypes |= eTable;
118 0 : }
119 :
120 : NS_DECL_ISUPPORTS_INHERITED
121 :
122 : // TableAccessible
123 : virtual Accessible* Caption() const override;
124 : virtual void Summary(nsString& aSummary) override;
125 : virtual uint32_t ColCount() override;
126 : virtual uint32_t RowCount() override;
127 : virtual Accessible* CellAt(uint32_t aRowIndex, uint32_t aColumnIndex) override;
128 : virtual int32_t CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx) override;
129 : virtual int32_t ColIndexAt(uint32_t aCellIdx) override;
130 : virtual int32_t RowIndexAt(uint32_t aCellIdx) override;
131 : virtual void RowAndColIndicesAt(uint32_t aCellIdx, int32_t* aRowIdx,
132 : int32_t* aColIdx) override;
133 : virtual uint32_t ColExtentAt(uint32_t aRowIdx, uint32_t aColIdx) override;
134 : virtual uint32_t RowExtentAt(uint32_t aRowIdx, uint32_t aColIdx) override;
135 : virtual bool IsColSelected(uint32_t aColIdx) override;
136 : virtual bool IsRowSelected(uint32_t aRowIdx) override;
137 : virtual bool IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx) override;
138 : virtual uint32_t SelectedCellCount() override;
139 : virtual uint32_t SelectedColCount() override;
140 : virtual uint32_t SelectedRowCount() override;
141 : virtual void SelectedCells(nsTArray<Accessible*>* aCells) override;
142 : virtual void SelectedCellIndices(nsTArray<uint32_t>* aCells) override;
143 : virtual void SelectedColIndices(nsTArray<uint32_t>* aCols) override;
144 : virtual void SelectedRowIndices(nsTArray<uint32_t>* aRows) override;
145 : virtual void SelectCol(uint32_t aColIdx) override;
146 : virtual void SelectRow(uint32_t aRowIdx) override;
147 : virtual void UnselectCol(uint32_t aColIdx) override;
148 : virtual void UnselectRow(uint32_t aRowIdx) override;
149 : virtual bool IsProbablyLayoutTable() override;
150 0 : virtual Accessible* AsAccessible() override { return this; }
151 :
152 : // Accessible
153 0 : virtual TableAccessible* AsTable() override { return this; }
154 : virtual void Description(nsString& aDescription) override;
155 : virtual a11y::role NativeRole() override;
156 : virtual uint64_t NativeState() override;
157 : virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override;
158 : virtual Relation RelationByType(RelationType aRelationType) override;
159 :
160 : virtual bool InsertChildAt(uint32_t aIndex, Accessible* aChild) override;
161 :
162 : protected:
163 0 : virtual ~HTMLTableAccessible() {}
164 :
165 : // Accessible
166 : virtual ENameValueFlag NativeName(nsString& aName) override;
167 :
168 : // HTMLTableAccessible
169 :
170 : /**
171 : * Add row or column to selection.
172 : *
173 : * @param aIndex [in] index of row or column to be selected
174 : * @param aTarget [in] indicates what should be selected, either row or column
175 : * (see nsISelectionPrivate)
176 : */
177 : nsresult AddRowOrColumnToSelection(int32_t aIndex, uint32_t aTarget);
178 :
179 : /**
180 : * Removes rows or columns at the given index or outside it from selection.
181 : *
182 : * @param aIndex [in] row or column index
183 : * @param aTarget [in] indicates whether row or column should unselected
184 : * @param aIsOuter [in] indicates whether all rows or column excepting
185 : * the given one should be unselected or the given one
186 : * should be unselected only
187 : */
188 : nsresult RemoveRowsOrColumnsFromSelection(int32_t aIndex,
189 : uint32_t aTarget,
190 : bool aIsOuter);
191 :
192 : /**
193 : * Return true if table has an element with the given tag name.
194 : *
195 : * @param aTagName [in] tag name of searched element
196 : * @param aAllowEmpty [in, optional] points if found element can be empty
197 : * or contain whitespace text only.
198 : */
199 : bool HasDescendant(const nsAString& aTagName, bool aAllowEmpty = true);
200 :
201 : #ifdef SHOW_LAYOUT_HEURISTIC
202 : nsString mLayoutHeuristic;
203 : #endif
204 : };
205 :
206 : /**
207 : * HTML caption accessible (html:caption).
208 : */
209 : class HTMLCaptionAccessible : public HyperTextAccessibleWrap
210 : {
211 : public:
212 0 : HTMLCaptionAccessible(nsIContent* aContent, DocAccessible* aDoc) :
213 0 : HyperTextAccessibleWrap(aContent, aDoc) { mType = eHTMLCaptionType; }
214 :
215 : // Accessible
216 : virtual a11y::role NativeRole() override;
217 : virtual Relation RelationByType(RelationType aRelationType) override;
218 :
219 : protected:
220 0 : virtual ~HTMLCaptionAccessible() { }
221 : };
222 :
223 : } // namespace a11y
224 : } // namespace mozilla
225 :
226 : #endif
|