summaryrefslogtreecommitdiffstats
path: root/accessible/generic/ARIAGridAccessible.cpp
blob: 6cfbe74b293a48cd52ab83c440b5294561ac3b45 (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
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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 "ARIAGridAccessible.h"

#include <stdint.h>
#include "LocalAccessible-inl.h"
#include "AccAttributes.h"
#include "AccIterator.h"
#include "mozilla/a11y/TableAccessible.h"
#include "mozilla/a11y/TableCellAccessible.h"
#include "nsAccessibilityService.h"
#include "nsAccUtils.h"
#include "nsGkAtoms.h"
#include "Role.h"
#include "States.h"

using namespace mozilla;
using namespace mozilla::a11y;

////////////////////////////////////////////////////////////////////////////////
// ARIAGridCellAccessible
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Constructor

ARIAGridCellAccessible::ARIAGridCellAccessible(nsIContent* aContent,
                                               DocAccessible* aDoc)
    : HyperTextAccessibleWrap(aContent, aDoc) {
  mGenericTypes |= eTableCell;
}

////////////////////////////////////////////////////////////////////////////////
// LocalAccessible

void ARIAGridCellAccessible::ApplyARIAState(uint64_t* aState) const {
  HyperTextAccessibleWrap::ApplyARIAState(aState);

  // Return if the gridcell has aria-selected="true".
  if (*aState & states::SELECTED) return;

  // Check aria-selected="true" on the row.
  LocalAccessible* row = LocalParent();
  if (!row || row->Role() != roles::ROW) return;

  nsIContent* rowContent = row->GetContent();
  if (nsAccUtils::HasDefinedARIAToken(rowContent, nsGkAtoms::aria_selected) &&
      !nsAccUtils::ARIAAttrValueIs(rowContent->AsElement(),
                                   nsGkAtoms::aria_selected, nsGkAtoms::_false,
                                   eCaseMatters)) {
    *aState |= states::SELECTABLE | states::SELECTED;
  }
}

already_AddRefed<AccAttributes> ARIAGridCellAccessible::NativeAttributes() {
  RefPtr<AccAttributes> attributes =
      HyperTextAccessibleWrap::NativeAttributes();

  // We only need to expose table-cell-index to clients. If we're in the content
  // process, we don't need this, so building a CachedTableAccessible is very
  // wasteful. This will be exposed by RemoteAccessible in the parent process
  // instead.
  if (!IPCAccessibilityActive()) {
    if (const TableCellAccessible* cell = AsTableCell()) {
      TableAccessible* table = cell->Table();
      const uint32_t row = cell->RowIdx();
      const uint32_t col = cell->ColIdx();
      const int32_t cellIdx = table->CellIndexAt(row, col);
      if (cellIdx != -1) {
        attributes->SetAttribute(nsGkAtoms::tableCellIndex, cellIdx);
      }
    }
  }

  return attributes.forget();
}