Bug 1735097 - Geolocation: use EpochTimeStamp instead of DOMTimeStamp r=saschanaz...
[gecko.git] / accessible / atk / nsMaiInterfaceTableCell.cpp
blobe1350208401ef63d7fedeea97df152646ba6abb2
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"
14 #include "nsMai.h"
15 #include "RemoteAccessible.h"
16 #include "nsArrayUtils.h"
18 #include "mozilla/Likely.h"
20 using namespace mozilla::a11y;
22 extern "C" {
23 static gint GetColumnSpanCB(AtkTableCell* aCell) {
24 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aCell));
25 if (accWrap) {
26 return accWrap->AsTableCell()->ColExtent();
29 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) {
30 return proxy->ColExtent();
33 return 0;
36 static gboolean GetRowSpanCB(AtkTableCell* aCell) {
37 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aCell));
38 if (accWrap) {
39 return accWrap->AsTableCell()->RowExtent();
42 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) {
43 return proxy->RowExtent();
46 return 0;
49 static gboolean GetPositionCB(AtkTableCell* aCell, gint* aRow, gint* aCol) {
50 if (AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aCell))) {
51 TableCellAccessible* cell = accWrap->AsTableCell();
52 if (!cell) {
53 return false;
55 *aRow = cell->RowIdx();
56 *aCol = cell->ColIdx();
57 return true;
60 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) {
61 uint32_t rowIdx = 0, colIdx = 0;
62 proxy->GetPosition(&rowIdx, &colIdx);
63 *aCol = colIdx;
64 *aRow = rowIdx;
65 return true;
68 return false;
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();
75 if (!cellAcc) {
76 return false;
78 *aCol = cellAcc->ColIdx();
79 *aRow = cellAcc->RowIdx();
80 *aColExtent = cellAcc->ColExtent();
81 *aRowExtent = cellAcc->ColExtent();
82 return true;
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);
88 *aCol = colIdx;
89 *aRow = rowIdx;
90 *aColExtent = colExtent;
91 *aRowExtent = rowExtent;
92 return true;
95 return false;
98 static AtkObject* GetTableCB(AtkTableCell* aTableCell) {
99 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTableCell));
100 if (accWrap) {
101 TableAccessible* table = accWrap->AsTableCell()->Table();
102 if (!table) {
103 return nullptr;
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;
115 return 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()) {
123 return nullptr;
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);
133 return atkHeaders;
136 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) {
137 AutoTArray<RemoteAccessible*, 10> headers;
138 proxy->ColHeaderCells(&headers);
139 if (headers.IsEmpty()) {
140 return nullptr;
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);
150 return atkHeaders;
153 return nullptr;
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()) {
161 return nullptr;
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);
171 return atkHeaders;
174 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aCell))) {
175 AutoTArray<RemoteAccessible*, 10> headers;
176 proxy->RowHeaderCells(&headers);
177 if (headers.IsEmpty()) {
178 return nullptr;
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);
188 return atkHeaders;
191 return nullptr;
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;