1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "ARIAGridAccessible.h"
9 #include "LocalAccessible-inl.h"
10 #include "AccAttributes.h"
11 #include "mozilla/a11y/TableAccessible.h"
12 #include "mozilla/a11y/TableCellAccessible.h"
13 #include "nsAccessibilityService.h"
14 #include "nsAccUtils.h"
15 #include "nsGkAtoms.h"
16 #include "mozilla/a11y/Role.h"
19 using namespace mozilla
;
20 using namespace mozilla::a11y
;
22 ////////////////////////////////////////////////////////////////////////////////
23 // ARIAGridCellAccessible
24 ////////////////////////////////////////////////////////////////////////////////
26 ////////////////////////////////////////////////////////////////////////////////
29 ARIAGridCellAccessible::ARIAGridCellAccessible(nsIContent
* aContent
,
31 : HyperTextAccessible(aContent
, aDoc
) {
32 mGenericTypes
|= eTableCell
;
35 ////////////////////////////////////////////////////////////////////////////////
38 void ARIAGridCellAccessible::ApplyARIAState(uint64_t* aState
) const {
39 HyperTextAccessible::ApplyARIAState(aState
);
41 // Return if the gridcell has aria-selected="true".
42 if (*aState
& states::SELECTED
) return;
44 // Check aria-selected="true" on the row.
45 LocalAccessible
* row
= LocalParent();
46 if (!row
|| row
->Role() != roles::ROW
) return;
48 nsIContent
* rowContent
= row
->GetContent();
49 if (nsAccUtils::HasDefinedARIAToken(rowContent
, nsGkAtoms::aria_selected
) &&
50 !nsAccUtils::ARIAAttrValueIs(rowContent
->AsElement(),
51 nsGkAtoms::aria_selected
, nsGkAtoms::_false
,
53 *aState
|= states::SELECTABLE
| states::SELECTED
;
57 already_AddRefed
<AccAttributes
> ARIAGridCellAccessible::NativeAttributes() {
58 RefPtr
<AccAttributes
> attributes
= HyperTextAccessible::NativeAttributes();
60 // We only need to expose table-cell-index to clients. If we're in the content
61 // process, we don't need this, so building a CachedTableAccessible is very
62 // wasteful. This will be exposed by RemoteAccessible in the parent process
64 if (!IPCAccessibilityActive()) {
65 if (const TableCellAccessible
* cell
= AsTableCell()) {
66 TableAccessible
* table
= cell
->Table();
67 const uint32_t row
= cell
->RowIdx();
68 const uint32_t col
= cell
->ColIdx();
69 const int32_t cellIdx
= table
->CellIndexAt(row
, col
);
71 attributes
->SetAttribute(nsGkAtoms::tableCellIndex
, cellIdx
);
76 return attributes
.forget();