|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:expandtab:shiftwidth=2:tabstop=2: |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #include "ia2AccessibleTableCell.h" |
|
9 |
|
10 #include "Accessible2.h" |
|
11 #include "AccessibleTable2_i.c" |
|
12 #include "AccessibleTableCell_i.c" |
|
13 |
|
14 #include "AccessibleWrap.h" |
|
15 #include "TableAccessible.h" |
|
16 #include "TableCellAccessible.h" |
|
17 #include "IUnknownImpl.h" |
|
18 |
|
19 #include "nsCOMPtr.h" |
|
20 #include "nsString.h" |
|
21 |
|
22 using namespace mozilla::a11y; |
|
23 |
|
24 // IUnknown |
|
25 |
|
26 STDMETHODIMP |
|
27 ia2AccessibleTableCell::QueryInterface(REFIID iid, void** ppv) |
|
28 { |
|
29 if (!ppv) |
|
30 return E_INVALIDARG; |
|
31 |
|
32 *ppv = nullptr; |
|
33 |
|
34 if (IID_IAccessibleTableCell == iid) { |
|
35 *ppv = static_cast<IAccessibleTableCell*>(this); |
|
36 (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); |
|
37 return S_OK; |
|
38 } |
|
39 |
|
40 return E_NOINTERFACE; |
|
41 } |
|
42 |
|
43 //////////////////////////////////////////////////////////////////////////////// |
|
44 // IAccessibleTableCell |
|
45 |
|
46 STDMETHODIMP |
|
47 ia2AccessibleTableCell::get_table(IUnknown** aTable) |
|
48 { |
|
49 A11Y_TRYBLOCK_BEGIN |
|
50 |
|
51 if (!aTable) |
|
52 return E_INVALIDARG; |
|
53 |
|
54 *aTable = nullptr; |
|
55 if (!mTableCell) |
|
56 return CO_E_OBJNOTCONNECTED; |
|
57 |
|
58 TableAccessible* table = mTableCell->Table(); |
|
59 if (!table) |
|
60 return E_FAIL; |
|
61 |
|
62 AccessibleWrap* wrap = static_cast<AccessibleWrap*>(table->AsAccessible()); |
|
63 *aTable = static_cast<IAccessible*>(wrap); |
|
64 (*aTable)->AddRef(); |
|
65 return S_OK; |
|
66 |
|
67 A11Y_TRYBLOCK_END |
|
68 } |
|
69 |
|
70 STDMETHODIMP |
|
71 ia2AccessibleTableCell::get_columnExtent(long* aSpan) |
|
72 { |
|
73 A11Y_TRYBLOCK_BEGIN |
|
74 |
|
75 if (!aSpan) |
|
76 return E_INVALIDARG; |
|
77 |
|
78 *aSpan = 0; |
|
79 if (!mTableCell) |
|
80 return CO_E_OBJNOTCONNECTED; |
|
81 |
|
82 *aSpan = mTableCell->ColExtent(); |
|
83 |
|
84 return S_OK; |
|
85 |
|
86 A11Y_TRYBLOCK_END |
|
87 } |
|
88 |
|
89 STDMETHODIMP |
|
90 ia2AccessibleTableCell::get_columnHeaderCells(IUnknown*** aCellAccessibles, |
|
91 long* aNColumnHeaderCells) |
|
92 { |
|
93 A11Y_TRYBLOCK_BEGIN |
|
94 |
|
95 if (!aCellAccessibles || !aNColumnHeaderCells) |
|
96 return E_INVALIDARG; |
|
97 |
|
98 *aCellAccessibles = nullptr; |
|
99 *aNColumnHeaderCells = 0; |
|
100 if (!mTableCell) |
|
101 return CO_E_OBJNOTCONNECTED; |
|
102 |
|
103 nsAutoTArray<Accessible*, 10> cells; |
|
104 mTableCell->ColHeaderCells(&cells); |
|
105 |
|
106 *aNColumnHeaderCells = cells.Length(); |
|
107 *aCellAccessibles = |
|
108 static_cast<IUnknown**>(::CoTaskMemAlloc(sizeof(IUnknown*) * |
|
109 cells.Length())); |
|
110 |
|
111 if (!*aCellAccessibles) |
|
112 return E_OUTOFMEMORY; |
|
113 |
|
114 for (uint32_t i = 0; i < cells.Length(); i++) { |
|
115 AccessibleWrap* cell = static_cast<AccessibleWrap*>(cells[i]); |
|
116 (*aCellAccessibles)[i] = static_cast<IAccessible*>(cell); |
|
117 (*aCellAccessibles)[i]->AddRef(); |
|
118 } |
|
119 |
|
120 return S_OK; |
|
121 |
|
122 A11Y_TRYBLOCK_END |
|
123 } |
|
124 |
|
125 STDMETHODIMP |
|
126 ia2AccessibleTableCell::get_columnIndex(long* aColIdx) |
|
127 { |
|
128 A11Y_TRYBLOCK_BEGIN |
|
129 |
|
130 if (!aColIdx) |
|
131 return E_INVALIDARG; |
|
132 |
|
133 *aColIdx = -1; |
|
134 if (!mTableCell) |
|
135 return CO_E_OBJNOTCONNECTED; |
|
136 |
|
137 *aColIdx = mTableCell->ColIdx(); |
|
138 return S_OK; |
|
139 |
|
140 A11Y_TRYBLOCK_END |
|
141 } |
|
142 |
|
143 STDMETHODIMP |
|
144 ia2AccessibleTableCell::get_rowExtent(long* aSpan) |
|
145 { |
|
146 A11Y_TRYBLOCK_BEGIN |
|
147 |
|
148 if (!aSpan) |
|
149 return E_INVALIDARG; |
|
150 |
|
151 *aSpan = 0; |
|
152 if (!mTableCell) |
|
153 return CO_E_OBJNOTCONNECTED; |
|
154 |
|
155 *aSpan = mTableCell->RowExtent(); |
|
156 return S_OK; |
|
157 |
|
158 A11Y_TRYBLOCK_END |
|
159 } |
|
160 |
|
161 STDMETHODIMP |
|
162 ia2AccessibleTableCell::get_rowHeaderCells(IUnknown*** aCellAccessibles, |
|
163 long* aNRowHeaderCells) |
|
164 { |
|
165 A11Y_TRYBLOCK_BEGIN |
|
166 |
|
167 if (!aCellAccessibles || !aNRowHeaderCells) |
|
168 return E_INVALIDARG; |
|
169 |
|
170 *aCellAccessibles = nullptr; |
|
171 *aNRowHeaderCells = 0; |
|
172 if (!mTableCell) |
|
173 return CO_E_OBJNOTCONNECTED; |
|
174 |
|
175 nsAutoTArray<Accessible*, 10> cells; |
|
176 mTableCell->RowHeaderCells(&cells); |
|
177 |
|
178 *aNRowHeaderCells = cells.Length(); |
|
179 *aCellAccessibles = |
|
180 static_cast<IUnknown**>(::CoTaskMemAlloc(sizeof(IUnknown*) * |
|
181 cells.Length())); |
|
182 if (!*aCellAccessibles) |
|
183 return E_OUTOFMEMORY; |
|
184 |
|
185 for (uint32_t i = 0; i < cells.Length(); i++) { |
|
186 AccessibleWrap* cell = static_cast<AccessibleWrap*>(cells[i]); |
|
187 (*aCellAccessibles)[i] = static_cast<IAccessible*>(cell); |
|
188 (*aCellAccessibles)[i]->AddRef(); |
|
189 } |
|
190 |
|
191 return S_OK; |
|
192 |
|
193 A11Y_TRYBLOCK_END |
|
194 } |
|
195 |
|
196 STDMETHODIMP |
|
197 ia2AccessibleTableCell::get_rowIndex(long* aRowIdx) |
|
198 { |
|
199 A11Y_TRYBLOCK_BEGIN |
|
200 |
|
201 if (!aRowIdx) |
|
202 return E_INVALIDARG; |
|
203 |
|
204 *aRowIdx = -1; |
|
205 if (!mTableCell) |
|
206 return CO_E_OBJNOTCONNECTED; |
|
207 |
|
208 *aRowIdx = mTableCell->RowIdx(); |
|
209 return S_OK; |
|
210 |
|
211 A11Y_TRYBLOCK_END |
|
212 } |
|
213 |
|
214 STDMETHODIMP |
|
215 ia2AccessibleTableCell::get_rowColumnExtents(long* aRowIdx, long* aColIdx, |
|
216 long* aRowExtents, |
|
217 long* aColExtents, |
|
218 boolean* aIsSelected) |
|
219 { |
|
220 A11Y_TRYBLOCK_BEGIN |
|
221 |
|
222 if (!aRowIdx || !aColIdx || !aRowExtents || !aColExtents || !aIsSelected) |
|
223 return E_INVALIDARG; |
|
224 |
|
225 *aRowIdx = *aColIdx = *aRowExtents = *aColExtents = 0; |
|
226 *aIsSelected = false; |
|
227 if (!mTableCell) |
|
228 return CO_E_OBJNOTCONNECTED; |
|
229 |
|
230 *aRowIdx = mTableCell->RowIdx(); |
|
231 *aColIdx = mTableCell->ColIdx(); |
|
232 *aRowExtents = mTableCell->RowExtent(); |
|
233 *aColExtents = mTableCell->ColExtent(); |
|
234 *aIsSelected = mTableCell->Selected(); |
|
235 |
|
236 return S_OK; |
|
237 |
|
238 A11Y_TRYBLOCK_END |
|
239 } |
|
240 |
|
241 STDMETHODIMP |
|
242 ia2AccessibleTableCell::get_isSelected(boolean* aIsSelected) |
|
243 { |
|
244 A11Y_TRYBLOCK_BEGIN |
|
245 |
|
246 if (!aIsSelected) |
|
247 return E_INVALIDARG; |
|
248 |
|
249 *aIsSelected = false; |
|
250 if (!mTableCell) |
|
251 return CO_E_OBJNOTCONNECTED; |
|
252 |
|
253 *aIsSelected = mTableCell->Selected(); |
|
254 return S_OK; |
|
255 |
|
256 A11Y_TRYBLOCK_END |
|
257 } |