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/. */
7 #include "InterfaceInitFuncs.h"
9 #include "LocalAccessible-inl.h"
10 #include "AccessibleWrap.h"
11 #include "nsAccUtils.h"
12 #include "TableAccessible.h"
13 #include "TableCellAccessible.h"
15 #include "RemoteAccessible.h"
16 #include "nsArrayUtils.h"
18 #include "mozilla/Likely.h"
20 using namespace mozilla::a11y
;
23 static gint
GetColumnSpanCB(AtkTableCell
* aCell
) {
24 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aCell
));
26 return accWrap
->AsTableCell()->ColExtent();
29 if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aCell
))) {
30 return proxy
->ColExtent();
36 static gboolean
GetRowSpanCB(AtkTableCell
* aCell
) {
37 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aCell
));
39 return accWrap
->AsTableCell()->RowExtent();
42 if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aCell
))) {
43 return proxy
->RowExtent();
49 static gboolean
GetPositionCB(AtkTableCell
* aCell
, gint
* aRow
, gint
* aCol
) {
50 if (AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aCell
))) {
51 TableCellAccessible
* cell
= accWrap
->AsTableCell();
55 *aRow
= cell
->RowIdx();
56 *aCol
= cell
->ColIdx();
60 if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aCell
))) {
61 uint32_t rowIdx
= 0, colIdx
= 0;
62 proxy
->GetPosition(&rowIdx
, &colIdx
);
71 static gboolean
GetColumnRowSpanCB(AtkTableCell
* aCell
, gint
* aCol
, gint
* aRow
,
72 gint
* aColExtent
, gint
* aRowExtent
) {
73 if (AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aCell
))) {
74 TableCellAccessible
* cellAcc
= accWrap
->AsTableCell();
78 *aCol
= cellAcc
->ColIdx();
79 *aRow
= cellAcc
->RowIdx();
80 *aColExtent
= cellAcc
->ColExtent();
81 *aRowExtent
= cellAcc
->ColExtent();
85 if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aCell
))) {
86 uint32_t colIdx
= 0, rowIdx
= 0, colExtent
= 0, rowExtent
= 0;
87 proxy
->GetColRowExtents(&colIdx
, &rowIdx
, &colExtent
, &rowExtent
);
90 *aColExtent
= colExtent
;
91 *aRowExtent
= rowExtent
;
98 static AtkObject
* GetTableCB(AtkTableCell
* aTableCell
) {
99 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aTableCell
));
101 TableAccessible
* table
= accWrap
->AsTableCell()->Table();
106 LocalAccessible
* tableAcc
= table
->AsAccessible();
107 return tableAcc
? AccessibleWrap::GetAtkObject(tableAcc
) : nullptr;
110 if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aTableCell
))) {
111 RemoteAccessible
* table
= proxy
->TableOfACell();
112 return table
? GetWrapperFor(table
) : nullptr;
118 static GPtrArray
* GetColumnHeaderCellsCB(AtkTableCell
* aCell
) {
119 if (AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aCell
))) {
120 AutoTArray
<LocalAccessible
*, 10> headers
;
121 accWrap
->AsTableCell()->ColHeaderCells(&headers
);
122 if (headers
.IsEmpty()) {
126 GPtrArray
* atkHeaders
= g_ptr_array_sized_new(headers
.Length());
127 for (LocalAccessible
* header
: headers
) {
128 AtkObject
* atkHeader
= AccessibleWrap::GetAtkObject(header
);
129 g_object_ref(atkHeader
);
130 g_ptr_array_add(atkHeaders
, atkHeader
);
136 if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aCell
))) {
137 AutoTArray
<RemoteAccessible
*, 10> headers
;
138 proxy
->ColHeaderCells(&headers
);
139 if (headers
.IsEmpty()) {
143 GPtrArray
* atkHeaders
= g_ptr_array_sized_new(headers
.Length());
144 for (RemoteAccessible
* header
: headers
) {
145 AtkObject
* atkHeader
= GetWrapperFor(header
);
146 g_object_ref(atkHeader
);
147 g_ptr_array_add(atkHeaders
, atkHeader
);
156 static GPtrArray
* GetRowHeaderCellsCB(AtkTableCell
* aCell
) {
157 if (AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aCell
))) {
158 AutoTArray
<LocalAccessible
*, 10> headers
;
159 accWrap
->AsTableCell()->RowHeaderCells(&headers
);
160 if (headers
.IsEmpty()) {
164 GPtrArray
* atkHeaders
= g_ptr_array_sized_new(headers
.Length());
165 for (LocalAccessible
* header
: headers
) {
166 AtkObject
* atkHeader
= AccessibleWrap::GetAtkObject(header
);
167 g_object_ref(atkHeader
);
168 g_ptr_array_add(atkHeaders
, atkHeader
);
174 if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aCell
))) {
175 AutoTArray
<RemoteAccessible
*, 10> headers
;
176 proxy
->RowHeaderCells(&headers
);
177 if (headers
.IsEmpty()) {
181 GPtrArray
* atkHeaders
= g_ptr_array_sized_new(headers
.Length());
182 for (RemoteAccessible
* header
: headers
) {
183 AtkObject
* atkHeader
= GetWrapperFor(header
);
184 g_object_ref(atkHeader
);
185 g_ptr_array_add(atkHeaders
, atkHeader
);
195 void tableCellInterfaceInitCB(AtkTableCellIface
* aIface
) {
196 NS_ASSERTION(aIface
, "no interface!");
197 if (MOZ_UNLIKELY(!aIface
)) return;
199 aIface
->get_column_span
= GetColumnSpanCB
;
200 aIface
->get_column_header_cells
= GetColumnHeaderCellsCB
;
201 aIface
->get_position
= GetPositionCB
;
202 aIface
->get_row_span
= GetRowSpanCB
;
203 aIface
->get_row_header_cells
= GetRowHeaderCellsCB
;
204 aIface
->get_row_column_span
= GetColumnRowSpanCB
;
205 aIface
->get_table
= GetTableCB
;