/src/mozilla-central/accessible/atk/nsMaiInterfaceTableCell.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "InterfaceInitFuncs.h" |
8 | | |
9 | | #include "Accessible-inl.h" |
10 | | #include "AccessibleWrap.h" |
11 | | #include "nsAccUtils.h" |
12 | | #include "TableAccessible.h" |
13 | | #include "TableCellAccessible.h" |
14 | | #include "nsMai.h" |
15 | | #include "ProxyAccessible.h" |
16 | | #include "nsArrayUtils.h" |
17 | | |
18 | | #include "mozilla/Likely.h" |
19 | | |
20 | | using namespace mozilla::a11y; |
21 | | |
22 | | extern "C" { |
23 | | static gint |
24 | | GetColumnSpanCB(AtkTableCell* aCell) |
25 | 0 | { |
26 | 0 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aCell)); |
27 | 0 | if (accWrap) { |
28 | 0 | return accWrap->AsTableCell()->ColExtent(); |
29 | 0 | } |
30 | 0 | |
31 | 0 | if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) { |
32 | 0 | return proxy->ColExtent(); |
33 | 0 | } |
34 | 0 | |
35 | 0 | return 0; |
36 | 0 | } |
37 | | |
38 | | static gboolean |
39 | | GetRowSpanCB(AtkTableCell* aCell) |
40 | 0 | { |
41 | 0 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aCell)); |
42 | 0 | if (accWrap) { |
43 | 0 | return accWrap->AsTableCell()->RowExtent(); |
44 | 0 | } |
45 | 0 | |
46 | 0 | if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) { |
47 | 0 | return proxy->RowExtent(); |
48 | 0 | } |
49 | 0 | |
50 | 0 | return 0; |
51 | 0 | } |
52 | | |
53 | | static gboolean |
54 | | GetPositionCB(AtkTableCell* aCell, gint* aRow, gint* aCol) |
55 | 0 | { |
56 | 0 | if (AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aCell))) { |
57 | 0 | TableCellAccessible* cell = accWrap->AsTableCell(); |
58 | 0 | if (!cell) { |
59 | 0 | return false; |
60 | 0 | } |
61 | 0 | *aRow = cell->RowIdx(); |
62 | 0 | *aCol = cell->ColIdx(); |
63 | 0 | return true; |
64 | 0 | } |
65 | 0 | |
66 | 0 | if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) { |
67 | 0 | uint32_t rowIdx = 0, colIdx = 0; |
68 | 0 | proxy->GetPosition(&rowIdx, &colIdx); |
69 | 0 | *aCol = colIdx; |
70 | 0 | *aRow = rowIdx; |
71 | 0 | return true; |
72 | 0 | } |
73 | 0 | |
74 | 0 | return false; |
75 | 0 | } |
76 | | |
77 | | static gboolean |
78 | | GetColumnRowSpanCB(AtkTableCell* aCell, gint* aCol, gint* aRow, |
79 | 0 | gint* aColExtent, gint* aRowExtent) { |
80 | 0 | if (AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aCell))) { |
81 | 0 | TableCellAccessible* cellAcc = accWrap->AsTableCell(); |
82 | 0 | if (!cellAcc) { |
83 | 0 | return false; |
84 | 0 | } |
85 | 0 | *aCol = cellAcc->ColIdx(); |
86 | 0 | *aRow = cellAcc->RowIdx(); |
87 | 0 | *aColExtent = cellAcc->ColExtent(); |
88 | 0 | *aRowExtent = cellAcc->ColExtent(); |
89 | 0 | return true; |
90 | 0 | } |
91 | 0 | |
92 | 0 | if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) { |
93 | 0 | uint32_t colIdx = 0, rowIdx = 0, colExtent = 0, rowExtent = 0; |
94 | 0 | proxy->GetColRowExtents(&colIdx, &rowIdx, &colExtent, &rowExtent); |
95 | 0 | *aCol = colIdx; |
96 | 0 | *aRow = rowIdx; |
97 | 0 | *aColExtent = colExtent; |
98 | 0 | *aRowExtent = rowExtent; |
99 | 0 | return true; |
100 | 0 | } |
101 | 0 | |
102 | 0 | return false; |
103 | 0 | } |
104 | | |
105 | | static AtkObject* |
106 | | GetTableCB(AtkTableCell* aTableCell) |
107 | 0 | { |
108 | 0 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTableCell)); |
109 | 0 | if (accWrap) { |
110 | 0 | TableAccessible* table = accWrap->AsTableCell()->Table(); |
111 | 0 | if (!table) { |
112 | 0 | return nullptr; |
113 | 0 | } |
114 | 0 | |
115 | 0 | Accessible* tableAcc = table->AsAccessible(); |
116 | 0 | return tableAcc ? AccessibleWrap::GetAtkObject(tableAcc) : nullptr; |
117 | 0 | } |
118 | 0 |
|
119 | 0 | if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aTableCell))) { |
120 | 0 | ProxyAccessible* table = proxy->TableOfACell(); |
121 | 0 | return table ? GetWrapperFor(table) : nullptr; |
122 | 0 | } |
123 | 0 |
|
124 | 0 | return nullptr; |
125 | 0 | } |
126 | | |
127 | | static GPtrArray* |
128 | | GetColumnHeaderCellsCB(AtkTableCell* aCell) |
129 | 0 | { |
130 | 0 | if (AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aCell))) { |
131 | 0 | AutoTArray<Accessible*, 10> headers; |
132 | 0 | accWrap->AsTableCell()->ColHeaderCells(&headers); |
133 | 0 | if (headers.IsEmpty()) { |
134 | 0 | return nullptr; |
135 | 0 | } |
136 | 0 | |
137 | 0 | GPtrArray* atkHeaders = g_ptr_array_sized_new(headers.Length()); |
138 | 0 | for (Accessible* header: headers) { |
139 | 0 | AtkObject* atkHeader = AccessibleWrap::GetAtkObject(header); |
140 | 0 | g_object_ref(atkHeader); |
141 | 0 | g_ptr_array_add(atkHeaders, atkHeader); |
142 | 0 | } |
143 | 0 |
|
144 | 0 | return atkHeaders; |
145 | 0 | } |
146 | 0 |
|
147 | 0 | if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) { |
148 | 0 | AutoTArray<ProxyAccessible*, 10> headers; |
149 | 0 | proxy->ColHeaderCells(&headers); |
150 | 0 | if (headers.IsEmpty()) { |
151 | 0 | return nullptr; |
152 | 0 | } |
153 | 0 | |
154 | 0 | GPtrArray* atkHeaders = g_ptr_array_sized_new(headers.Length()); |
155 | 0 | for (ProxyAccessible* header: headers) { |
156 | 0 | AtkObject* atkHeader = GetWrapperFor(header); |
157 | 0 | g_object_ref(atkHeader); |
158 | 0 | g_ptr_array_add(atkHeaders, atkHeader); |
159 | 0 | } |
160 | 0 |
|
161 | 0 | return atkHeaders; |
162 | 0 | } |
163 | 0 |
|
164 | 0 | return nullptr; |
165 | 0 | } |
166 | | |
167 | | static GPtrArray* |
168 | | GetRowHeaderCellsCB(AtkTableCell* aCell) |
169 | 0 | { |
170 | 0 | if (AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aCell))) { |
171 | 0 | AutoTArray<Accessible*, 10> headers; |
172 | 0 | accWrap->AsTableCell()->RowHeaderCells(&headers); |
173 | 0 | if (headers.IsEmpty()) { |
174 | 0 | return nullptr; |
175 | 0 | } |
176 | 0 | |
177 | 0 | GPtrArray* atkHeaders = g_ptr_array_sized_new(headers.Length()); |
178 | 0 | for (Accessible* header: headers) { |
179 | 0 | AtkObject* atkHeader = AccessibleWrap::GetAtkObject(header); |
180 | 0 | g_object_ref(atkHeader); |
181 | 0 | g_ptr_array_add(atkHeaders, atkHeader); |
182 | 0 | } |
183 | 0 |
|
184 | 0 | return atkHeaders; |
185 | 0 | } |
186 | 0 |
|
187 | 0 | if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) { |
188 | 0 | AutoTArray<ProxyAccessible*, 10> headers; |
189 | 0 | proxy->RowHeaderCells(&headers); |
190 | 0 | if (headers.IsEmpty()) { |
191 | 0 | return nullptr; |
192 | 0 | } |
193 | 0 | |
194 | 0 | GPtrArray* atkHeaders = g_ptr_array_sized_new(headers.Length()); |
195 | 0 | for (ProxyAccessible* header: headers) { |
196 | 0 | AtkObject* atkHeader = GetWrapperFor(header); |
197 | 0 | g_object_ref(atkHeader); |
198 | 0 | g_ptr_array_add(atkHeaders, atkHeader); |
199 | 0 | } |
200 | 0 |
|
201 | 0 | return atkHeaders; |
202 | 0 | } |
203 | 0 |
|
204 | 0 | return nullptr; |
205 | 0 | } |
206 | | } |
207 | | |
208 | | void |
209 | | tableCellInterfaceInitCB(AtkTableCellIface* aIface) |
210 | 0 | { |
211 | 0 | NS_ASSERTION(aIface, "no interface!"); |
212 | 0 | if (MOZ_UNLIKELY(!aIface)) |
213 | 0 | return; |
214 | 0 | |
215 | 0 | aIface->get_column_span = GetColumnSpanCB; |
216 | 0 | aIface->get_column_header_cells = GetColumnHeaderCellsCB; |
217 | 0 | aIface->get_position = GetPositionCB; |
218 | 0 | aIface->get_row_span = GetRowSpanCB; |
219 | 0 | aIface->get_row_header_cells = GetRowHeaderCellsCB; |
220 | 0 | aIface->get_row_column_span = GetColumnRowSpanCB; |
221 | 0 | aIface->get_table = GetTableCB; |
222 | 0 | } |