summaryrefslogtreecommitdiffstats
path: root/accessible/generic/TableAccessible.h
blob: e2cd51de70aaf232073a2f8d0d4021702b42cc1e (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
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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/. */

#ifndef TABLE_ACCESSIBLE_H
#define TABLE_ACCESSIBLE_H

#include "LocalAccessible.h"
#include "mozilla/a11y/TableAccessibleBase.h"
#include "mozilla/a11y/TableCellAccessibleBase.h"
#include "nsPointerHashKeys.h"
#include "nsRefPtrHashtable.h"

namespace mozilla {
namespace a11y {

/**
 * Base class for LocalAccessible table implementations.
 */
class TableAccessible : public TableAccessibleBase {
 public:
  virtual LocalAccessible* Caption() const override { return nullptr; }

  virtual LocalAccessible* CellAt(uint32_t aRowIdx, uint32_t aColIdx) override {
    return nullptr;
  }

  virtual int32_t CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx) override {
    return ColCount() * aRowIdx + aColIdx;
  }

  virtual int32_t ColIndexAt(uint32_t aCellIdx) override;
  virtual int32_t RowIndexAt(uint32_t aCellIdx) override;
  virtual void RowAndColIndicesAt(uint32_t aCellIdx, int32_t* aRowIdx,
                                  int32_t* aColIdx) override;
  virtual bool IsProbablyLayoutTable() override;
  virtual LocalAccessible* AsAccessible() override = 0;

  using HeaderCache =
      nsRefPtrHashtable<nsPtrHashKey<const TableCellAccessibleBase>,
                        LocalAccessible>;

  /**
   * Get the header cache, which maps a TableCellAccessible to its previous
   * header.
   * Although this data is only used in TableCellAccessible, it is stored on
   * TableAccessible so the cache can be easily invalidated when the table
   * is mutated.
   */
  HeaderCache& GetHeaderCache() { return mHeaderCache; }

 protected:
  /**
   * Return row accessible at the given row index.
   */
  LocalAccessible* RowAt(int32_t aRow);

  /**
   * Return cell accessible at the given column index in the row.
   */
  LocalAccessible* CellInRowAt(LocalAccessible* aRow, int32_t aColumn);

 private:
  HeaderCache mHeaderCache;
};

}  // namespace a11y
}  // namespace mozilla

#endif