nsMaiInterfaceTableCell.cpp (4131B)
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 "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" 15 16 #include "mozilla/Likely.h" 17 18 using namespace mozilla; 19 using namespace mozilla::a11y; 20 21 extern "C" { 22 static gint GetColumnSpanCB(AtkTableCell* aCell) { 23 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell)); 24 if (!acc) { 25 return 0; 26 } 27 return static_cast<gint>(acc->AsTableCell()->ColExtent()); 28 } 29 30 static gint GetRowSpanCB(AtkTableCell* aCell) { 31 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell)); 32 if (!acc) { 33 return 0; 34 } 35 return static_cast<gint>(acc->AsTableCell()->RowExtent()); 36 } 37 38 static gboolean GetPositionCB(AtkTableCell* aCell, gint* aRow, gint* aCol) { 39 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell)); 40 if (!acc) { 41 return false; 42 } 43 TableCellAccessible* cell = acc->AsTableCell(); 44 if (!cell) { 45 return false; 46 } 47 *aRow = static_cast<gint>(cell->RowIdx()); 48 *aCol = static_cast<gint>(cell->ColIdx()); 49 return true; 50 } 51 52 static gboolean GetRowColumnSpanCB(AtkTableCell* aCell, gint* aRow, gint* aCol, 53 gint* aRowExtent, gint* aColExtent) { 54 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell)); 55 if (!acc) { 56 return false; 57 } 58 TableCellAccessible* cellAcc = acc->AsTableCell(); 59 if (!cellAcc) { 60 return false; 61 } 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->RowExtent()); 66 return true; 67 } 68 69 static AtkObject* GetTableCB(AtkTableCell* aTableCell) { 70 Accessible* acc = GetInternalObj(ATK_OBJECT(aTableCell)); 71 if (!acc) { 72 return nullptr; 73 } 74 TableCellAccessible* cell = acc->AsTableCell(); 75 if (!cell) { 76 return nullptr; 77 } 78 TableAccessible* table = cell->Table(); 79 if (!table) { 80 return nullptr; 81 } 82 Accessible* tableAcc = table->AsAccessible(); 83 return tableAcc ? GetWrapperFor(tableAcc) : nullptr; 84 } 85 86 static GPtrArray* GetColumnHeaderCellsCB(AtkTableCell* aCell) { 87 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell)); 88 if (!acc) { 89 return nullptr; 90 } 91 TableCellAccessible* cell = acc->AsTableCell(); 92 if (!cell) { 93 return nullptr; 94 } 95 AutoTArray<Accessible*, 10> headers; 96 cell->ColHeaderCells(&headers); 97 if (headers.IsEmpty()) { 98 return nullptr; 99 } 100 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); 106 } 107 108 return atkHeaders; 109 } 110 111 static GPtrArray* GetRowHeaderCellsCB(AtkTableCell* aCell) { 112 Accessible* acc = GetInternalObj(ATK_OBJECT(aCell)); 113 if (!acc) { 114 return nullptr; 115 } 116 TableCellAccessible* cell = acc->AsTableCell(); 117 if (!cell) { 118 return nullptr; 119 } 120 AutoTArray<Accessible*, 10> headers; 121 cell->RowHeaderCells(&headers); 122 if (headers.IsEmpty()) { 123 return nullptr; 124 } 125 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); 131 } 132 133 return atkHeaders; 134 } 135 } 136 137 void tableCellInterfaceInitCB(AtkTableCellIface* aIface) { 138 NS_ASSERTION(aIface, "no interface!"); 139 if (MOZ_UNLIKELY(!aIface)) return; 140 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 = GetRowColumnSpanCB; 147 aIface->get_table = GetTableCB; 148 }