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 "mozilla/a11y/TableAccessible.h"
10 #include "mozilla/a11y/TableCellAccessible.h"
11 #include "nsAccessibilityService.h"
13 #include "RemoteAccessible.h"
16 #include "mozilla/Likely.h"
18 using namespace mozilla
;
19 using namespace mozilla::a11y
;
22 static gint
GetColumnSpanCB(AtkTableCell
* aCell
) {
23 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aCell
));
27 return static_cast<gint
>(acc
->AsTableCell()->ColExtent());
30 static gint
GetRowSpanCB(AtkTableCell
* aCell
) {
31 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aCell
));
35 return static_cast<gint
>(acc
->AsTableCell()->RowExtent());
38 static gboolean
GetPositionCB(AtkTableCell
* aCell
, gint
* aRow
, gint
* aCol
) {
39 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aCell
));
43 TableCellAccessible
* cell
= acc
->AsTableCell();
47 *aRow
= static_cast<gint
>(cell
->RowIdx());
48 *aCol
= static_cast<gint
>(cell
->ColIdx());
52 static gboolean
GetColumnRowSpanCB(AtkTableCell
* aCell
, gint
* aCol
, gint
* aRow
,
53 gint
* aColExtent
, gint
* aRowExtent
) {
54 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aCell
));
58 TableCellAccessible
* cellAcc
= acc
->AsTableCell();
62 *aCol
= static_cast<gint
>(cellAcc
->ColIdx());
63 *aRow
= static_cast<gint
>(cellAcc
->RowIdx());
64 *aColExtent
= static_cast<gint
>(cellAcc
->ColExtent());
65 *aRowExtent
= static_cast<gint
>(cellAcc
->ColExtent());
69 static AtkObject
* GetTableCB(AtkTableCell
* aTableCell
) {
70 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aTableCell
));
74 TableCellAccessible
* cell
= acc
->AsTableCell();
78 TableAccessible
* table
= cell
->Table();
82 Accessible
* tableAcc
= table
->AsAccessible();
83 return tableAcc
? GetWrapperFor(tableAcc
) : nullptr;
86 static GPtrArray
* GetColumnHeaderCellsCB(AtkTableCell
* aCell
) {
87 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aCell
));
91 TableCellAccessible
* cell
= acc
->AsTableCell();
95 AutoTArray
<Accessible
*, 10> headers
;
96 cell
->ColHeaderCells(&headers
);
97 if (headers
.IsEmpty()) {
101 GPtrArray
* atkHeaders
= g_ptr_array_sized_new(headers
.Length());
102 for (Accessible
* header
: headers
) {
103 AtkObject
* atkHeader
= GetWrapperFor(header
);
104 g_object_ref(atkHeader
);
105 g_ptr_array_add(atkHeaders
, atkHeader
);
111 static GPtrArray
* GetRowHeaderCellsCB(AtkTableCell
* aCell
) {
112 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aCell
));
116 TableCellAccessible
* cell
= acc
->AsTableCell();
120 AutoTArray
<Accessible
*, 10> headers
;
121 cell
->RowHeaderCells(&headers
);
122 if (headers
.IsEmpty()) {
126 GPtrArray
* atkHeaders
= g_ptr_array_sized_new(headers
.Length());
127 for (Accessible
* header
: headers
) {
128 AtkObject
* atkHeader
= GetWrapperFor(header
);
129 g_object_ref(atkHeader
);
130 g_ptr_array_add(atkHeaders
, atkHeader
);
137 void tableCellInterfaceInitCB(AtkTableCellIface
* aIface
) {
138 NS_ASSERTION(aIface
, "no interface!");
139 if (MOZ_UNLIKELY(!aIface
)) return;
141 aIface
->get_column_span
= GetColumnSpanCB
;
142 aIface
->get_column_header_cells
= GetColumnHeaderCellsCB
;
143 aIface
->get_position
= GetPositionCB
;
144 aIface
->get_row_span
= GetRowSpanCB
;
145 aIface
->get_row_header_cells
= GetRowHeaderCellsCB
;
146 aIface
->get_row_column_span
= GetColumnRowSpanCB
;
147 aIface
->get_table
= GetTableCB
;