Bug 1854550 - pt 10. Allow LOG() with zero extra arguments r=glandium
[gecko.git] / accessible / atk / nsMaiInterfaceTableCell.cpp
blob06a684a87de5a3fccd74af4d34130cbd6ca815e3
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"
12 #include "nsMai.h"
13 #include "RemoteAccessible.h"
14 #include "nsTArray.h"
16 #include "mozilla/Likely.h"
18 using namespace mozilla;
19 using namespace mozilla::a11y;
21 extern "C" {
22 static gint GetColumnSpanCB(AtkTableCell* aCell) {
23 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell));
24 if (!acc) {
25 return 0;
27 return static_cast<gint>(acc->AsTableCell()->ColExtent());
30 static gint GetRowSpanCB(AtkTableCell* aCell) {
31 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell));
32 if (!acc) {
33 return 0;
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));
40 if (!acc) {
41 return false;
43 TableCellAccessible* cell = acc->AsTableCell();
44 if (!cell) {
45 return false;
47 *aRow = static_cast<gint>(cell->RowIdx());
48 *aCol = static_cast<gint>(cell->ColIdx());
49 return true;
52 static gboolean GetColumnRowSpanCB(AtkTableCell* aCell, gint* aCol, gint* aRow,
53 gint* aColExtent, gint* aRowExtent) {
54 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell));
55 if (!acc) {
56 return false;
58 TableCellAccessible* cellAcc = acc->AsTableCell();
59 if (!cellAcc) {
60 return false;
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());
66 return true;
69 static AtkObject* GetTableCB(AtkTableCell* aTableCell) {
70 Accessible* acc = GetInternalObj(ATK_OBJECT(aTableCell));
71 if (!acc) {
72 return nullptr;
74 TableCellAccessible* cell = acc->AsTableCell();
75 if (!cell) {
76 return nullptr;
78 TableAccessible* table = cell->Table();
79 if (!table) {
80 return nullptr;
82 Accessible* tableAcc = table->AsAccessible();
83 return tableAcc ? GetWrapperFor(tableAcc) : nullptr;
86 static GPtrArray* GetColumnHeaderCellsCB(AtkTableCell* aCell) {
87 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell));
88 if (!acc) {
89 return nullptr;
91 TableCellAccessible* cell = acc->AsTableCell();
92 if (!cell) {
93 return nullptr;
95 AutoTArray<Accessible*, 10> headers;
96 cell->ColHeaderCells(&headers);
97 if (headers.IsEmpty()) {
98 return nullptr;
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);
108 return atkHeaders;
111 static GPtrArray* GetRowHeaderCellsCB(AtkTableCell* aCell) {
112 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell));
113 if (!acc) {
114 return nullptr;
116 TableCellAccessible* cell = acc->AsTableCell();
117 if (!cell) {
118 return nullptr;
120 AutoTArray<Accessible*, 10> headers;
121 cell->RowHeaderCells(&headers);
122 if (headers.IsEmpty()) {
123 return nullptr;
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);
133 return atkHeaders;
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;