summaryrefslogtreecommitdiffstats
path: root/accessible/windows/ia2/ia2AccessibleTableCell.cpp
blob: c8e98d6a2f52fc3914b84091658e2befc459d1ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:expandtab:shiftwidth=2:tabstop=2:
 */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "ia2AccessibleTableCell.h"

#include "AccessibleTable2_i.c"
#include "AccessibleTableCell_i.c"

#include "IUnknownImpl.h"
#include "mozilla/a11y/Accessible.h"
#include "mozilla/a11y/TableAccessible.h"
#include "mozilla/a11y/TableCellAccessible.h"
#include "nsCOMPtr.h"
#include "nsString.h"

using namespace mozilla::a11y;

TableCellAccessible* ia2AccessibleTableCell::CellAcc() {
  Accessible* acc = Acc();
  return acc ? acc->AsTableCell() : nullptr;
}

// IUnknown
IMPL_IUNKNOWN_QUERY_HEAD(ia2AccessibleTableCell)
IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleTableCell)
IMPL_IUNKNOWN_QUERY_IFACE(IGridItemProvider)
IMPL_IUNKNOWN_QUERY_IFACE(ITableItemProvider)
IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(ia2AccessibleHypertext)

////////////////////////////////////////////////////////////////////////////////
// IAccessibleTableCell

STDMETHODIMP
ia2AccessibleTableCell::get_table(IUnknown** aTable) {
  if (!aTable) return E_INVALIDARG;

  *aTable = nullptr;
  TableCellAccessible* tableCell = CellAcc();
  if (!tableCell) return CO_E_OBJNOTCONNECTED;

  TableAccessible* table = tableCell->Table();
  if (!table) return E_FAIL;

  Accessible* tableAcc = table->AsAccessible();
  RefPtr<IAccessible> result = MsaaAccessible::GetFrom(tableAcc);
  result.forget(aTable);
  return S_OK;
}

STDMETHODIMP
ia2AccessibleTableCell::get_columnExtent(long* aSpan) {
  if (!aSpan) return E_INVALIDARG;

  *aSpan = 0;
  TableCellAccessible* tableCell = CellAcc();
  if (!tableCell) return CO_E_OBJNOTCONNECTED;

  *aSpan = tableCell->ColExtent();

  return S_OK;
}

STDMETHODIMP
ia2AccessibleTableCell::get_columnHeaderCells(IUnknown*** aCellAccessibles,
                                              long* aNColumnHeaderCells) {
  if (!aCellAccessibles || !aNColumnHeaderCells) return E_INVALIDARG;

  *aCellAccessibles = nullptr;
  *aNColumnHeaderCells = 0;
  TableCellAccessible* tableCell = CellAcc();
  if (!tableCell) return CO_E_OBJNOTCONNECTED;

  AutoTArray<Accessible*, 10> cells;
  tableCell->ColHeaderCells(&cells);

  *aNColumnHeaderCells = cells.Length();
  *aCellAccessibles = static_cast<IUnknown**>(
      ::CoTaskMemAlloc(sizeof(IUnknown*) * cells.Length()));

  if (!*aCellAccessibles) return E_OUTOFMEMORY;

  for (uint32_t i = 0; i < cells.Length(); i++) {
    RefPtr<IAccessible> iaCell = MsaaAccessible::GetFrom(cells[i]);
    iaCell.forget(&(*aCellAccessibles)[i]);
  }

  return S_OK;
}

STDMETHODIMP
ia2AccessibleTableCell::get_columnIndex(long* aColIdx) {
  if (!aColIdx) return E_INVALIDARG;

  *aColIdx = -1;
  TableCellAccessible* tableCell = CellAcc();
  if (!tableCell) return CO_E_OBJNOTCONNECTED;

  *aColIdx = tableCell->ColIdx();
  return S_OK;
}

STDMETHODIMP
ia2AccessibleTableCell::get_rowExtent(long* aSpan) {
  if (!aSpan) return E_INVALIDARG;

  *aSpan = 0;
  TableCellAccessible* tableCell = CellAcc();
  if (!tableCell) return CO_E_OBJNOTCONNECTED;

  *aSpan = tableCell->RowExtent();
  return S_OK;
}

STDMETHODIMP
ia2AccessibleTableCell::get_rowHeaderCells(IUnknown*** aCellAccessibles,
                                           long* aNRowHeaderCells) {
  if (!aCellAccessibles || !aNRowHeaderCells) return E_INVALIDARG;

  *aCellAccessibles = nullptr;
  *aNRowHeaderCells = 0;
  TableCellAccessible* tableCell = CellAcc();
  if (!tableCell) return CO_E_OBJNOTCONNECTED;

  AutoTArray<Accessible*, 10> cells;
  tableCell->RowHeaderCells(&cells);

  *aNRowHeaderCells = cells.Length();
  *aCellAccessibles = static_cast<IUnknown**>(
      ::CoTaskMemAlloc(sizeof(IUnknown*) * cells.Length()));
  if (!*aCellAccessibles) return E_OUTOFMEMORY;

  for (uint32_t i = 0; i < cells.Length(); i++) {
    RefPtr<IAccessible> iaCell = MsaaAccessible::GetFrom(cells[i]);
    iaCell.forget(&(*aCellAccessibles)[i]);
  }

  return S_OK;
}

STDMETHODIMP
ia2AccessibleTableCell::get_rowIndex(long* aRowIdx) {
  if (!aRowIdx) return E_INVALIDARG;

  *aRowIdx = -1;
  TableCellAccessible* tableCell = CellAcc();
  if (!tableCell) return CO_E_OBJNOTCONNECTED;

  *aRowIdx = tableCell->RowIdx();
  return S_OK;
}

STDMETHODIMP
ia2AccessibleTableCell::get_rowColumnExtents(long* aRowIdx, long* aColIdx,
                                             long* aRowExtents,
                                             long* aColExtents,
                                             boolean* aIsSelected) {
  if (!aRowIdx || !aColIdx || !aRowExtents || !aColExtents || !aIsSelected)
    return E_INVALIDARG;

  *aRowIdx = *aColIdx = *aRowExtents = *aColExtents = 0;
  *aIsSelected = false;
  TableCellAccessible* tableCell = CellAcc();
  if (!tableCell) return CO_E_OBJNOTCONNECTED;

  *aRowIdx = tableCell->RowIdx();
  *aColIdx = tableCell->ColIdx();
  *aRowExtents = tableCell->RowExtent();
  *aColExtents = tableCell->ColExtent();
  *aIsSelected = tableCell->Selected();

  return S_OK;
}

STDMETHODIMP
ia2AccessibleTableCell::get_isSelected(boolean* aIsSelected) {
  if (!aIsSelected) return E_INVALIDARG;

  *aIsSelected = false;
  TableCellAccessible* tableCell = CellAcc();
  if (!tableCell) return CO_E_OBJNOTCONNECTED;

  *aIsSelected = tableCell->Selected();
  return S_OK;
}