tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ia2AccessibleTableCell.cpp (5424B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:expandtab:shiftwidth=2:tabstop=2:
      3 */
      4 /* This Source Code Form is subject to the terms of the Mozilla Public
      5 * License, v. 2.0. If a copy of the MPL was not distributed with this
      6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      7 
      8 #include "ia2AccessibleTableCell.h"
      9 
     10 #include "AccessibleTable2_i.c"
     11 #include "AccessibleTableCell_i.c"
     12 
     13 #include "IUnknownImpl.h"
     14 #include "mozilla/a11y/Accessible.h"
     15 #include "mozilla/a11y/TableAccessible.h"
     16 #include "mozilla/a11y/TableCellAccessible.h"
     17 #include "nsCOMPtr.h"
     18 #include "nsString.h"
     19 
     20 using namespace mozilla::a11y;
     21 
     22 TableCellAccessible* ia2AccessibleTableCell::CellAcc() {
     23  Accessible* acc = Acc();
     24  return acc ? acc->AsTableCell() : nullptr;
     25 }
     26 
     27 // IUnknown
     28 IMPL_IUNKNOWN_QUERY_HEAD(ia2AccessibleTableCell)
     29 IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleTableCell)
     30 IMPL_IUNKNOWN_QUERY_IFACE(IGridItemProvider)
     31 IMPL_IUNKNOWN_QUERY_IFACE(ITableItemProvider)
     32 IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(ia2AccessibleHypertext)
     33 
     34 ////////////////////////////////////////////////////////////////////////////////
     35 // IAccessibleTableCell
     36 
     37 STDMETHODIMP
     38 ia2AccessibleTableCell::get_table(IUnknown** aTable) {
     39  if (!aTable) return E_INVALIDARG;
     40 
     41  *aTable = nullptr;
     42  TableCellAccessible* tableCell = CellAcc();
     43  if (!tableCell) return CO_E_OBJNOTCONNECTED;
     44 
     45  TableAccessible* table = tableCell->Table();
     46  if (!table) return E_FAIL;
     47 
     48  Accessible* tableAcc = table->AsAccessible();
     49  RefPtr<IAccessible> result = MsaaAccessible::GetFrom(tableAcc);
     50  result.forget(aTable);
     51  return S_OK;
     52 }
     53 
     54 STDMETHODIMP
     55 ia2AccessibleTableCell::get_columnExtent(long* aSpan) {
     56  if (!aSpan) return E_INVALIDARG;
     57 
     58  *aSpan = 0;
     59  TableCellAccessible* tableCell = CellAcc();
     60  if (!tableCell) return CO_E_OBJNOTCONNECTED;
     61 
     62  *aSpan = tableCell->ColExtent();
     63 
     64  return S_OK;
     65 }
     66 
     67 STDMETHODIMP
     68 ia2AccessibleTableCell::get_columnHeaderCells(IUnknown*** aCellAccessibles,
     69                                              long* aNColumnHeaderCells) {
     70  if (!aCellAccessibles || !aNColumnHeaderCells) return E_INVALIDARG;
     71 
     72  *aCellAccessibles = nullptr;
     73  *aNColumnHeaderCells = 0;
     74  TableCellAccessible* tableCell = CellAcc();
     75  if (!tableCell) return CO_E_OBJNOTCONNECTED;
     76 
     77  AutoTArray<Accessible*, 10> cells;
     78  tableCell->ColHeaderCells(&cells);
     79 
     80  *aNColumnHeaderCells = cells.Length();
     81  *aCellAccessibles = static_cast<IUnknown**>(
     82      ::CoTaskMemAlloc(sizeof(IUnknown*) * cells.Length()));
     83 
     84  if (!*aCellAccessibles) return E_OUTOFMEMORY;
     85 
     86  for (uint32_t i = 0; i < cells.Length(); i++) {
     87    RefPtr<IAccessible> iaCell = MsaaAccessible::GetFrom(cells[i]);
     88    iaCell.forget(&(*aCellAccessibles)[i]);
     89  }
     90 
     91  return S_OK;
     92 }
     93 
     94 STDMETHODIMP
     95 ia2AccessibleTableCell::get_columnIndex(long* aColIdx) {
     96  if (!aColIdx) return E_INVALIDARG;
     97 
     98  *aColIdx = -1;
     99  TableCellAccessible* tableCell = CellAcc();
    100  if (!tableCell) return CO_E_OBJNOTCONNECTED;
    101 
    102  *aColIdx = tableCell->ColIdx();
    103  return S_OK;
    104 }
    105 
    106 STDMETHODIMP
    107 ia2AccessibleTableCell::get_rowExtent(long* aSpan) {
    108  if (!aSpan) return E_INVALIDARG;
    109 
    110  *aSpan = 0;
    111  TableCellAccessible* tableCell = CellAcc();
    112  if (!tableCell) return CO_E_OBJNOTCONNECTED;
    113 
    114  *aSpan = tableCell->RowExtent();
    115  return S_OK;
    116 }
    117 
    118 STDMETHODIMP
    119 ia2AccessibleTableCell::get_rowHeaderCells(IUnknown*** aCellAccessibles,
    120                                           long* aNRowHeaderCells) {
    121  if (!aCellAccessibles || !aNRowHeaderCells) return E_INVALIDARG;
    122 
    123  *aCellAccessibles = nullptr;
    124  *aNRowHeaderCells = 0;
    125  TableCellAccessible* tableCell = CellAcc();
    126  if (!tableCell) return CO_E_OBJNOTCONNECTED;
    127 
    128  AutoTArray<Accessible*, 10> cells;
    129  tableCell->RowHeaderCells(&cells);
    130 
    131  *aNRowHeaderCells = cells.Length();
    132  *aCellAccessibles = static_cast<IUnknown**>(
    133      ::CoTaskMemAlloc(sizeof(IUnknown*) * cells.Length()));
    134  if (!*aCellAccessibles) return E_OUTOFMEMORY;
    135 
    136  for (uint32_t i = 0; i < cells.Length(); i++) {
    137    RefPtr<IAccessible> iaCell = MsaaAccessible::GetFrom(cells[i]);
    138    iaCell.forget(&(*aCellAccessibles)[i]);
    139  }
    140 
    141  return S_OK;
    142 }
    143 
    144 STDMETHODIMP
    145 ia2AccessibleTableCell::get_rowIndex(long* aRowIdx) {
    146  if (!aRowIdx) return E_INVALIDARG;
    147 
    148  *aRowIdx = -1;
    149  TableCellAccessible* tableCell = CellAcc();
    150  if (!tableCell) return CO_E_OBJNOTCONNECTED;
    151 
    152  *aRowIdx = tableCell->RowIdx();
    153  return S_OK;
    154 }
    155 
    156 STDMETHODIMP
    157 ia2AccessibleTableCell::get_rowColumnExtents(long* aRowIdx, long* aColIdx,
    158                                             long* aRowExtents,
    159                                             long* aColExtents,
    160                                             boolean* aIsSelected) {
    161  if (!aRowIdx || !aColIdx || !aRowExtents || !aColExtents || !aIsSelected)
    162    return E_INVALIDARG;
    163 
    164  *aRowIdx = *aColIdx = *aRowExtents = *aColExtents = 0;
    165  *aIsSelected = false;
    166  TableCellAccessible* tableCell = CellAcc();
    167  if (!tableCell) return CO_E_OBJNOTCONNECTED;
    168 
    169  *aRowIdx = tableCell->RowIdx();
    170  *aColIdx = tableCell->ColIdx();
    171  *aRowExtents = tableCell->RowExtent();
    172  *aColExtents = tableCell->ColExtent();
    173  *aIsSelected = tableCell->Selected();
    174 
    175  return S_OK;
    176 }
    177 
    178 STDMETHODIMP
    179 ia2AccessibleTableCell::get_isSelected(boolean* aIsSelected) {
    180  if (!aIsSelected) return E_INVALIDARG;
    181 
    182  *aIsSelected = false;
    183  TableCellAccessible* tableCell = CellAcc();
    184  if (!tableCell) return CO_E_OBJNOTCONNECTED;
    185 
    186  *aIsSelected = tableCell->Selected();
    187  return S_OK;
    188 }