2022-04-01 09:49:57 +00:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#include "CachedTableAccessible.h"
|
|
|
|
|
2022-04-01 09:49:59 +00:00
|
|
|
#include "AccIterator.h"
|
Bug 1832261: Remove most of HTMLTable*Accessible. r=nlapre
We now use CachedTableAccessible for HTML tables, so much of the code in the HTMLTable*Accessible classes was unused.
However, we still depend on these classes for some data needed to build the cached table.
1. HTMLTableAccessible and HTMLTableCellAccessible no longer derive from TableAccessible and TableCellAccessible, respectively. Instead, callers which need specific access to HTML table data use the HTMLTable*Accessible class directly.
2. All table specific methods have been removed except those that provide data required to build a CachedTableAccessible. The remaining methods are those for querying the row/column span (which depends on layout) and getting the caption (which depends on DOM).
3. HTMLTable*Accessible are now used for all <table>, <td>, <th> and <tr> elements and MathML equivalents. ARIA*Accessible are never used for these elements. This improves consistency, simplifies the code and means that behavior specific to these HTML elements is handled in these classes, rather than in the ARIA classes as well.
4. The table and row roles are now specified in HTMLMarkupMap and MathMLMarkupMap, rather than overriding NativeRole. Cell roles are still handled in a NativeRole override; see the code comments for details.
5. IsProbablyLayoutTable has been moved from TableAccessible to HTMLTableAccessible, as it is only relevant for HTML tables, not for ARIA tables.
6. HTMLTableHeaderCellAccessible::NativeRole has been rewritten such that it no longer depends on querying table coordinates, as that would now require building a CachedTableAccessible, which would be very wasteful here. This replaces TableCellAccessible::HeaderCellRole, which has been removed.
Differential Revision: https://phabricator.services.mozilla.com/D179799
2023-06-08 09:50:28 +00:00
|
|
|
#include "HTMLTableAccessible.h"
|
2022-04-01 09:49:57 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
2022-04-01 09:49:59 +00:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2022-04-01 09:49:57 +00:00
|
|
|
#include "nsAccUtils.h"
|
|
|
|
#include "nsIAccessiblePivot.h"
|
|
|
|
#include "Pivot.h"
|
2022-04-01 09:49:58 +00:00
|
|
|
#include "RemoteAccessible.h"
|
2022-04-01 09:49:57 +00:00
|
|
|
|
|
|
|
namespace mozilla::a11y {
|
|
|
|
|
|
|
|
// Used to search for table descendants relevant to table structure.
|
|
|
|
class TablePartRule : public PivotRule {
|
|
|
|
public:
|
|
|
|
virtual uint16_t Match(Accessible* aAcc) override {
|
|
|
|
role accRole = aAcc->Role();
|
|
|
|
if (accRole == roles::CAPTION || aAcc->IsTableCell()) {
|
|
|
|
return nsIAccessibleTraversalRule::FILTER_MATCH |
|
|
|
|
nsIAccessibleTraversalRule::FILTER_IGNORE_SUBTREE;
|
|
|
|
}
|
|
|
|
if (aAcc->IsTableRow()) {
|
|
|
|
return nsIAccessibleTraversalRule::FILTER_MATCH;
|
|
|
|
}
|
|
|
|
if (aAcc->IsTable() ||
|
|
|
|
// Generic containers.
|
|
|
|
accRole == roles::TEXT || accRole == roles::TEXT_CONTAINER ||
|
|
|
|
accRole == roles::SECTION ||
|
|
|
|
// Row groups.
|
2024-04-10 17:22:12 +00:00
|
|
|
accRole == roles::ROWGROUP) {
|
2022-04-01 09:49:57 +00:00
|
|
|
// Walk inside these, but don't match them.
|
|
|
|
return nsIAccessibleTraversalRule::FILTER_IGNORE;
|
|
|
|
}
|
|
|
|
return nsIAccessibleTraversalRule::FILTER_IGNORE |
|
|
|
|
nsIAccessibleTraversalRule::FILTER_IGNORE_SUBTREE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The Accessible* keys should only be used for lookup. They should not be
|
|
|
|
// dereferenced.
|
|
|
|
using CachedTablesMap = nsTHashMap<Accessible*, CachedTableAccessible>;
|
|
|
|
// We use a global map rather than a map in each document for three reasons:
|
|
|
|
// 1. We don't have a common base class for local and remote documents.
|
|
|
|
// 2. It avoids wasting memory in a document that doesn't have any tables.
|
|
|
|
// 3. It allows the cache management to be encapsulated here in
|
|
|
|
// CachedTableAccessible.
|
|
|
|
static StaticAutoPtr<CachedTablesMap> sCachedTables;
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
CachedTableAccessible* CachedTableAccessible::GetFrom(Accessible* aAcc) {
|
2022-06-04 02:22:47 +00:00
|
|
|
MOZ_ASSERT(aAcc->IsTable());
|
2022-04-01 09:49:57 +00:00
|
|
|
if (!sCachedTables) {
|
|
|
|
sCachedTables = new CachedTablesMap();
|
|
|
|
ClearOnShutdown(&sCachedTables);
|
|
|
|
}
|
|
|
|
return &sCachedTables->LookupOrInsertWith(
|
|
|
|
aAcc, [&] { return CachedTableAccessible(aAcc); });
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void CachedTableAccessible::Invalidate(Accessible* aAcc) {
|
|
|
|
if (!sCachedTables) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-30 23:12:18 +00:00
|
|
|
|
|
|
|
if (Accessible* table = nsAccUtils::TableFor(aAcc)) {
|
2022-04-01 09:49:57 +00:00
|
|
|
// Destroy the instance (if any). We'll create a new one the next time it
|
|
|
|
// is requested.
|
|
|
|
sCachedTables->Remove(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CachedTableAccessible::CachedTableAccessible(Accessible* aAcc) : mAcc(aAcc) {
|
|
|
|
MOZ_ASSERT(mAcc);
|
|
|
|
// Build the cache. The cache can only be built once per instance. When it's
|
|
|
|
// invalidated, we just throw away the instance and create a new one when
|
|
|
|
// the cache is next needed.
|
|
|
|
int32_t rowIdx = -1;
|
|
|
|
uint32_t colIdx = 0;
|
|
|
|
// Maps a column index to the cell index of its previous implicit column
|
|
|
|
// header.
|
|
|
|
nsTHashMap<uint32_t, uint32_t> prevColHeaders;
|
|
|
|
Pivot pivot(mAcc);
|
|
|
|
TablePartRule rule;
|
|
|
|
for (Accessible* part = pivot.Next(mAcc, rule); part;
|
|
|
|
part = pivot.Next(part, rule)) {
|
|
|
|
role partRole = part->Role();
|
|
|
|
if (partRole == roles::CAPTION) {
|
|
|
|
// If there are multiple captions, use the first.
|
|
|
|
if (!mCaptionAccID) {
|
|
|
|
mCaptionAccID = part->ID();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (part->IsTableRow()) {
|
|
|
|
++rowIdx;
|
|
|
|
colIdx = 0;
|
|
|
|
// This might be an empty row, so ensure a row here, as our row count is
|
|
|
|
// based on the length of mRowColToCellIdx.
|
|
|
|
EnsureRow(rowIdx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(part->IsTableCell());
|
|
|
|
if (rowIdx == -1) {
|
|
|
|
// We haven't created a row yet, so this cell must be outside a row.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Check for a cell spanning multiple rows which already occupies this
|
|
|
|
// position. Keep incrementing until we find a vacant position.
|
|
|
|
for (;;) {
|
|
|
|
EnsureRowCol(rowIdx, colIdx);
|
|
|
|
if (mRowColToCellIdx[rowIdx][colIdx] == kNoCellIdx) {
|
|
|
|
// This position is not occupied.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// This position is occupied.
|
|
|
|
++colIdx;
|
|
|
|
}
|
|
|
|
// Create the cell.
|
|
|
|
uint32_t cellIdx = mCells.Length();
|
|
|
|
auto prevColHeader = prevColHeaders.MaybeGet(colIdx);
|
|
|
|
auto cell = mCells.AppendElement(
|
|
|
|
CachedTableCellAccessible(part->ID(), part, rowIdx, colIdx,
|
|
|
|
prevColHeader ? *prevColHeader : kNoCellIdx));
|
|
|
|
mAccToCellIdx.InsertOrUpdate(part, cellIdx);
|
|
|
|
// Update our row/col map.
|
|
|
|
// This cell might span multiple rows and/or columns. In that case, we need
|
|
|
|
// to occupy multiple coordinates in the row/col map.
|
|
|
|
uint32_t lastRowForCell =
|
|
|
|
static_cast<uint32_t>(rowIdx) + cell->RowExtent() - 1;
|
|
|
|
MOZ_ASSERT(lastRowForCell >= static_cast<uint32_t>(rowIdx));
|
|
|
|
uint32_t lastColForCell = colIdx + cell->ColExtent() - 1;
|
|
|
|
MOZ_ASSERT(lastColForCell >= colIdx);
|
|
|
|
for (uint32_t spannedRow = static_cast<uint32_t>(rowIdx);
|
|
|
|
spannedRow <= lastRowForCell; ++spannedRow) {
|
|
|
|
for (uint32_t spannedCol = colIdx; spannedCol <= lastColForCell;
|
|
|
|
++spannedCol) {
|
|
|
|
EnsureRowCol(spannedRow, spannedCol);
|
|
|
|
auto& rowCol = mRowColToCellIdx[spannedRow][spannedCol];
|
|
|
|
// If a cell already occupies this position, it overlaps with this one;
|
|
|
|
// e.g. r1..2c2 and r2c1..2. In that case, we want to prefer the first
|
|
|
|
// cell.
|
|
|
|
if (rowCol == kNoCellIdx) {
|
|
|
|
rowCol = cellIdx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (partRole == roles::COLUMNHEADER) {
|
|
|
|
for (uint32_t spannedCol = colIdx; spannedCol <= lastColForCell;
|
|
|
|
++spannedCol) {
|
|
|
|
prevColHeaders.InsertOrUpdate(spannedCol, cellIdx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Increment for the next cell.
|
|
|
|
colIdx = lastColForCell + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CachedTableAccessible::EnsureRow(uint32_t aRowIdx) {
|
2022-06-04 02:22:47 +00:00
|
|
|
if (mRowColToCellIdx.Length() <= aRowIdx) {
|
|
|
|
mRowColToCellIdx.AppendElements(aRowIdx - mRowColToCellIdx.Length() + 1);
|
2022-04-01 09:49:57 +00:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(mRowColToCellIdx.Length() > aRowIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CachedTableAccessible::EnsureRowCol(uint32_t aRowIdx, uint32_t aColIdx) {
|
|
|
|
EnsureRow(aRowIdx);
|
|
|
|
auto& row = mRowColToCellIdx[aRowIdx];
|
2022-06-04 02:22:47 +00:00
|
|
|
if (mColCount <= aColIdx) {
|
|
|
|
mColCount = aColIdx + 1;
|
|
|
|
}
|
|
|
|
row.SetCapacity(mColCount);
|
2022-04-01 09:49:57 +00:00
|
|
|
for (uint32_t newCol = row.Length(); newCol <= aColIdx; ++newCol) {
|
|
|
|
// An entry doesn't yet exist for this column in this row.
|
|
|
|
row.AppendElement(kNoCellIdx);
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(row.Length() > aColIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
Accessible* CachedTableAccessible::Caption() const {
|
|
|
|
if (mCaptionAccID) {
|
|
|
|
Accessible* caption = nsAccUtils::GetAccessibleByID(
|
|
|
|
nsAccUtils::DocumentFor(mAcc), mCaptionAccID);
|
|
|
|
MOZ_ASSERT(caption, "Dead caption Accessible!");
|
2022-07-14 00:45:26 +00:00
|
|
|
MOZ_ASSERT(caption->Role() == roles::CAPTION, "Caption has wrong role");
|
2022-04-01 09:49:57 +00:00
|
|
|
return caption;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CachedTableAccessible::Summary(nsString& aSummary) {
|
|
|
|
if (Caption()) {
|
|
|
|
// If there's a caption, we map caption to Name and summary to Description.
|
|
|
|
mAcc->Description(aSummary);
|
|
|
|
} else {
|
|
|
|
// If there's no caption, we map summary to Name.
|
|
|
|
mAcc->Name(aSummary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Accessible* CachedTableAccessible::CellAt(uint32_t aRowIdx, uint32_t aColIdx) {
|
|
|
|
int32_t cellIdx = CellIndexAt(aRowIdx, aColIdx);
|
|
|
|
if (cellIdx == -1) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mCells[cellIdx].Acc(mAcc);
|
|
|
|
}
|
|
|
|
|
2022-04-01 09:49:59 +00:00
|
|
|
bool CachedTableAccessible::IsProbablyLayoutTable() {
|
|
|
|
if (RemoteAccessible* remoteAcc = mAcc->AsRemote()) {
|
|
|
|
return remoteAcc->TableIsProbablyForLayout();
|
|
|
|
}
|
Bug 1832261: Remove most of HTMLTable*Accessible. r=nlapre
We now use CachedTableAccessible for HTML tables, so much of the code in the HTMLTable*Accessible classes was unused.
However, we still depend on these classes for some data needed to build the cached table.
1. HTMLTableAccessible and HTMLTableCellAccessible no longer derive from TableAccessible and TableCellAccessible, respectively. Instead, callers which need specific access to HTML table data use the HTMLTable*Accessible class directly.
2. All table specific methods have been removed except those that provide data required to build a CachedTableAccessible. The remaining methods are those for querying the row/column span (which depends on layout) and getting the caption (which depends on DOM).
3. HTMLTable*Accessible are now used for all <table>, <td>, <th> and <tr> elements and MathML equivalents. ARIA*Accessible are never used for these elements. This improves consistency, simplifies the code and means that behavior specific to these HTML elements is handled in these classes, rather than in the ARIA classes as well.
4. The table and row roles are now specified in HTMLMarkupMap and MathMLMarkupMap, rather than overriding NativeRole. Cell roles are still handled in a NativeRole override; see the code comments for details.
5. IsProbablyLayoutTable has been moved from TableAccessible to HTMLTableAccessible, as it is only relevant for HTML tables, not for ARIA tables.
6. HTMLTableHeaderCellAccessible::NativeRole has been rewritten such that it no longer depends on querying table coordinates, as that would now require building a CachedTableAccessible, which would be very wasteful here. This replaces TableCellAccessible::HeaderCellRole, which has been removed.
Differential Revision: https://phabricator.services.mozilla.com/D179799
2023-06-08 09:50:28 +00:00
|
|
|
if (auto* localTable = HTMLTableAccessible::GetFrom(mAcc->AsLocal())) {
|
|
|
|
return localTable->IsProbablyLayoutTable();
|
|
|
|
}
|
|
|
|
return false;
|
2022-04-01 09:49:59 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 09:49:57 +00:00
|
|
|
/* static */
|
|
|
|
CachedTableCellAccessible* CachedTableCellAccessible::GetFrom(
|
|
|
|
Accessible* aAcc) {
|
|
|
|
MOZ_ASSERT(aAcc->IsTableCell());
|
|
|
|
for (Accessible* parent = aAcc; parent; parent = parent->Parent()) {
|
2023-10-25 23:30:25 +00:00
|
|
|
if (parent->IsDoc()) {
|
|
|
|
break; // Never cross document boundaries.
|
|
|
|
}
|
|
|
|
TableAccessible* table = parent->AsTable();
|
|
|
|
if (!table) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (LocalAccessible* local = parent->AsLocal()) {
|
|
|
|
nsIContent* content = local->GetContent();
|
|
|
|
if (content && content->IsXULElement()) {
|
|
|
|
// XUL tables don't use CachedTableAccessible.
|
|
|
|
break;
|
2022-04-01 09:49:57 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-25 23:30:25 +00:00
|
|
|
// Non-XUL tables only use CachedTableAccessible.
|
|
|
|
auto* cachedTable = static_cast<CachedTableAccessible*>(table);
|
|
|
|
if (auto cellIdx = cachedTable->mAccToCellIdx.Lookup(aAcc)) {
|
|
|
|
return &cachedTable->mCells[*cellIdx];
|
|
|
|
}
|
2023-11-06 04:17:45 +00:00
|
|
|
// We found a table, but it doesn't know about this cell. This can happen
|
|
|
|
// if a cell is outside of a row due to authoring error. We must not search
|
|
|
|
// ancestor tables, since this cell's data is not valid there and vice
|
|
|
|
// versa.
|
|
|
|
break;
|
2022-04-01 09:49:57 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Accessible* CachedTableCellAccessible::Acc(Accessible* aTableAcc) const {
|
|
|
|
Accessible* acc =
|
|
|
|
nsAccUtils::GetAccessibleByID(nsAccUtils::DocumentFor(aTableAcc), mAccID);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(acc == mAcc, "Cell's cached mAcc is dead!");
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
2023-06-08 09:50:28 +00:00
|
|
|
TableAccessible* CachedTableCellAccessible::Table() const {
|
2022-04-01 09:49:57 +00:00
|
|
|
for (const Accessible* acc = mAcc; acc; acc = acc->Parent()) {
|
|
|
|
// Since the caller has this cell, the table is already created, so it's
|
|
|
|
// okay to ignore the const restriction here.
|
2023-06-08 09:50:28 +00:00
|
|
|
if (TableAccessible* table = const_cast<Accessible*>(acc)->AsTable()) {
|
2022-04-01 09:49:57 +00:00
|
|
|
return table;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CachedTableCellAccessible::ColExtent() const {
|
2022-04-01 09:49:58 +00:00
|
|
|
if (RemoteAccessible* remoteAcc = mAcc->AsRemote()) {
|
2024-09-09 23:02:20 +00:00
|
|
|
if (RequestDomainsIfInactive(CacheDomain::Table)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-04-01 09:49:58 +00:00
|
|
|
if (remoteAcc->mCachedFields) {
|
|
|
|
if (auto colSpan = remoteAcc->mCachedFields->GetAttribute<int32_t>(
|
Bug 1743749 part 2: Replace usage of atoms as cache keys with the new CacheKey aliases. r=nlapre
This was done with the following Python script:
```
import re
cacheConsts = open("accessible/base/CacheConstants.h", "rt").read()
aliases = {
alias: atom
for atom, alias in
re.findall(
r'static constexpr nsStaticAtom\*\s+(.*?)\s+=\s+(nsGkAtoms::.*?);',
cacheConsts
)
}
RE_ATOM = re.compile(r'(fields->SetAttribute|(?:mCachedFields|aFields)->(?:GetAttribute|GetAttributeRefPtr|GetMutableAttribute|HasAttribute|Remove|SetAttribute)(?:<.+>)?)(\(\s*)(nsGkAtoms::[a-zA-Z_]+)')
def repl(m):
# Group 3 is the atom.
alias = aliases.get(m.group(3))
if not alias:
# No alias for this atom. Return input unaltered.
return m.group(0)
alias = "CacheKey::" + alias
# Groups 1 and 2 should be returned unaltered. Group 3 (the atom) is replaced
# with the alias.
return m.group(1) + m.group(2) + alias
for fn in (
# Found with: git grep -l 'ields->'
"accessible/base/CachedTableAccessible.cpp",
"accessible/base/nsAccessibilityService.cpp",
"accessible/base/TextLeafRange.cpp",
"accessible/generic/LocalAccessible.cpp",
"accessible/ipc/DocAccessibleParent.cpp",
"accessible/ipc/RemoteAccessible.cpp",
"accessible/ipc/RemoteAccessible.h",
"accessible/windows/sdn/sdnAccessible.cpp",
):
input = open(fn, "rt").read()
output = RE_ATOM.sub(repl, input)
open(fn, "wt").write(output)
```
Differential Revision: https://phabricator.services.mozilla.com/D184791
2023-07-31 23:09:56 +00:00
|
|
|
CacheKey::ColSpan)) {
|
2022-06-04 02:22:46 +00:00
|
|
|
MOZ_ASSERT(*colSpan > 0);
|
2022-04-01 09:49:58 +00:00
|
|
|
return *colSpan;
|
|
|
|
}
|
|
|
|
}
|
Bug 1832261: Remove most of HTMLTable*Accessible. r=nlapre
We now use CachedTableAccessible for HTML tables, so much of the code in the HTMLTable*Accessible classes was unused.
However, we still depend on these classes for some data needed to build the cached table.
1. HTMLTableAccessible and HTMLTableCellAccessible no longer derive from TableAccessible and TableCellAccessible, respectively. Instead, callers which need specific access to HTML table data use the HTMLTable*Accessible class directly.
2. All table specific methods have been removed except those that provide data required to build a CachedTableAccessible. The remaining methods are those for querying the row/column span (which depends on layout) and getting the caption (which depends on DOM).
3. HTMLTable*Accessible are now used for all <table>, <td>, <th> and <tr> elements and MathML equivalents. ARIA*Accessible are never used for these elements. This improves consistency, simplifies the code and means that behavior specific to these HTML elements is handled in these classes, rather than in the ARIA classes as well.
4. The table and row roles are now specified in HTMLMarkupMap and MathMLMarkupMap, rather than overriding NativeRole. Cell roles are still handled in a NativeRole override; see the code comments for details.
5. IsProbablyLayoutTable has been moved from TableAccessible to HTMLTableAccessible, as it is only relevant for HTML tables, not for ARIA tables.
6. HTMLTableHeaderCellAccessible::NativeRole has been rewritten such that it no longer depends on querying table coordinates, as that would now require building a CachedTableAccessible, which would be very wasteful here. This replaces TableCellAccessible::HeaderCellRole, which has been removed.
Differential Revision: https://phabricator.services.mozilla.com/D179799
2023-06-08 09:50:28 +00:00
|
|
|
} else if (auto* cell = HTMLTableCellAccessible::GetFrom(mAcc->AsLocal())) {
|
2022-04-01 09:49:58 +00:00
|
|
|
// For HTML table cells, we must use the HTMLTableCellAccessible
|
|
|
|
// GetColExtent method rather than using the DOM attributes directly.
|
|
|
|
// This is because of things like rowspan="0" which depend on knowing
|
|
|
|
// about thead, tbody, etc., which is info we don't have in the a11y tree.
|
2022-06-04 02:22:46 +00:00
|
|
|
uint32_t colExtent = cell->ColExtent();
|
|
|
|
MOZ_ASSERT(colExtent > 0);
|
|
|
|
if (colExtent > 0) {
|
|
|
|
return colExtent;
|
|
|
|
}
|
2022-04-01 09:49:58 +00:00
|
|
|
}
|
2022-04-01 09:49:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CachedTableCellAccessible::RowExtent() const {
|
2022-04-01 09:49:58 +00:00
|
|
|
if (RemoteAccessible* remoteAcc = mAcc->AsRemote()) {
|
2024-09-09 23:02:20 +00:00
|
|
|
if (RequestDomainsIfInactive(CacheDomain::Table)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-04-01 09:49:58 +00:00
|
|
|
if (remoteAcc->mCachedFields) {
|
|
|
|
if (auto rowSpan = remoteAcc->mCachedFields->GetAttribute<int32_t>(
|
Bug 1743749 part 2: Replace usage of atoms as cache keys with the new CacheKey aliases. r=nlapre
This was done with the following Python script:
```
import re
cacheConsts = open("accessible/base/CacheConstants.h", "rt").read()
aliases = {
alias: atom
for atom, alias in
re.findall(
r'static constexpr nsStaticAtom\*\s+(.*?)\s+=\s+(nsGkAtoms::.*?);',
cacheConsts
)
}
RE_ATOM = re.compile(r'(fields->SetAttribute|(?:mCachedFields|aFields)->(?:GetAttribute|GetAttributeRefPtr|GetMutableAttribute|HasAttribute|Remove|SetAttribute)(?:<.+>)?)(\(\s*)(nsGkAtoms::[a-zA-Z_]+)')
def repl(m):
# Group 3 is the atom.
alias = aliases.get(m.group(3))
if not alias:
# No alias for this atom. Return input unaltered.
return m.group(0)
alias = "CacheKey::" + alias
# Groups 1 and 2 should be returned unaltered. Group 3 (the atom) is replaced
# with the alias.
return m.group(1) + m.group(2) + alias
for fn in (
# Found with: git grep -l 'ields->'
"accessible/base/CachedTableAccessible.cpp",
"accessible/base/nsAccessibilityService.cpp",
"accessible/base/TextLeafRange.cpp",
"accessible/generic/LocalAccessible.cpp",
"accessible/ipc/DocAccessibleParent.cpp",
"accessible/ipc/RemoteAccessible.cpp",
"accessible/ipc/RemoteAccessible.h",
"accessible/windows/sdn/sdnAccessible.cpp",
):
input = open(fn, "rt").read()
output = RE_ATOM.sub(repl, input)
open(fn, "wt").write(output)
```
Differential Revision: https://phabricator.services.mozilla.com/D184791
2023-07-31 23:09:56 +00:00
|
|
|
CacheKey::RowSpan)) {
|
2022-06-04 02:22:46 +00:00
|
|
|
MOZ_ASSERT(*rowSpan > 0);
|
2022-04-01 09:49:58 +00:00
|
|
|
return *rowSpan;
|
|
|
|
}
|
|
|
|
}
|
Bug 1832261: Remove most of HTMLTable*Accessible. r=nlapre
We now use CachedTableAccessible for HTML tables, so much of the code in the HTMLTable*Accessible classes was unused.
However, we still depend on these classes for some data needed to build the cached table.
1. HTMLTableAccessible and HTMLTableCellAccessible no longer derive from TableAccessible and TableCellAccessible, respectively. Instead, callers which need specific access to HTML table data use the HTMLTable*Accessible class directly.
2. All table specific methods have been removed except those that provide data required to build a CachedTableAccessible. The remaining methods are those for querying the row/column span (which depends on layout) and getting the caption (which depends on DOM).
3. HTMLTable*Accessible are now used for all <table>, <td>, <th> and <tr> elements and MathML equivalents. ARIA*Accessible are never used for these elements. This improves consistency, simplifies the code and means that behavior specific to these HTML elements is handled in these classes, rather than in the ARIA classes as well.
4. The table and row roles are now specified in HTMLMarkupMap and MathMLMarkupMap, rather than overriding NativeRole. Cell roles are still handled in a NativeRole override; see the code comments for details.
5. IsProbablyLayoutTable has been moved from TableAccessible to HTMLTableAccessible, as it is only relevant for HTML tables, not for ARIA tables.
6. HTMLTableHeaderCellAccessible::NativeRole has been rewritten such that it no longer depends on querying table coordinates, as that would now require building a CachedTableAccessible, which would be very wasteful here. This replaces TableCellAccessible::HeaderCellRole, which has been removed.
Differential Revision: https://phabricator.services.mozilla.com/D179799
2023-06-08 09:50:28 +00:00
|
|
|
} else if (auto* cell = HTMLTableCellAccessible::GetFrom(mAcc->AsLocal())) {
|
2022-04-01 09:49:58 +00:00
|
|
|
// For HTML table cells, we must use the HTMLTableCellAccessible
|
|
|
|
// GetRowExtent method rather than using the DOM attributes directly.
|
|
|
|
// This is because of things like rowspan="0" which depend on knowing
|
|
|
|
// about thead, tbody, etc., which is info we don't have in the a11y tree.
|
2022-06-04 02:22:46 +00:00
|
|
|
uint32_t rowExtent = cell->RowExtent();
|
|
|
|
MOZ_ASSERT(rowExtent > 0);
|
|
|
|
if (rowExtent > 0) {
|
|
|
|
return rowExtent;
|
|
|
|
}
|
2022-04-01 09:49:58 +00:00
|
|
|
}
|
2022-04-01 09:49:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-04-01 09:49:59 +00:00
|
|
|
UniquePtr<AccIterable> CachedTableCellAccessible::GetExplicitHeadersIterator() {
|
|
|
|
if (RemoteAccessible* remoteAcc = mAcc->AsRemote()) {
|
2024-09-09 23:02:20 +00:00
|
|
|
if (RequestDomainsIfInactive(CacheDomain::Table)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-04-01 09:49:59 +00:00
|
|
|
if (remoteAcc->mCachedFields) {
|
|
|
|
if (auto headers =
|
|
|
|
remoteAcc->mCachedFields->GetAttribute<nsTArray<uint64_t>>(
|
Bug 1743749 part 2: Replace usage of atoms as cache keys with the new CacheKey aliases. r=nlapre
This was done with the following Python script:
```
import re
cacheConsts = open("accessible/base/CacheConstants.h", "rt").read()
aliases = {
alias: atom
for atom, alias in
re.findall(
r'static constexpr nsStaticAtom\*\s+(.*?)\s+=\s+(nsGkAtoms::.*?);',
cacheConsts
)
}
RE_ATOM = re.compile(r'(fields->SetAttribute|(?:mCachedFields|aFields)->(?:GetAttribute|GetAttributeRefPtr|GetMutableAttribute|HasAttribute|Remove|SetAttribute)(?:<.+>)?)(\(\s*)(nsGkAtoms::[a-zA-Z_]+)')
def repl(m):
# Group 3 is the atom.
alias = aliases.get(m.group(3))
if not alias:
# No alias for this atom. Return input unaltered.
return m.group(0)
alias = "CacheKey::" + alias
# Groups 1 and 2 should be returned unaltered. Group 3 (the atom) is replaced
# with the alias.
return m.group(1) + m.group(2) + alias
for fn in (
# Found with: git grep -l 'ields->'
"accessible/base/CachedTableAccessible.cpp",
"accessible/base/nsAccessibilityService.cpp",
"accessible/base/TextLeafRange.cpp",
"accessible/generic/LocalAccessible.cpp",
"accessible/ipc/DocAccessibleParent.cpp",
"accessible/ipc/RemoteAccessible.cpp",
"accessible/ipc/RemoteAccessible.h",
"accessible/windows/sdn/sdnAccessible.cpp",
):
input = open(fn, "rt").read()
output = RE_ATOM.sub(repl, input)
open(fn, "wt").write(output)
```
Differential Revision: https://phabricator.services.mozilla.com/D184791
2023-07-31 23:09:56 +00:00
|
|
|
CacheKey::CellHeaders)) {
|
2022-08-03 23:58:51 +00:00
|
|
|
return MakeUnique<RemoteAccIterator>(*headers, remoteAcc->Document());
|
2022-04-01 09:49:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (LocalAccessible* localAcc = mAcc->AsLocal()) {
|
2024-09-15 22:39:53 +00:00
|
|
|
return MakeUnique<AssociatedElementsIterator>(
|
2022-04-01 09:49:59 +00:00
|
|
|
localAcc->Document(), localAcc->GetContent(), nsGkAtoms::headers);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-04-01 09:49:57 +00:00
|
|
|
void CachedTableCellAccessible::ColHeaderCells(nsTArray<Accessible*>* aCells) {
|
|
|
|
auto* table = static_cast<CachedTableAccessible*>(Table());
|
|
|
|
if (!table) {
|
|
|
|
return;
|
|
|
|
}
|
2024-09-09 23:02:20 +00:00
|
|
|
if (mAcc->IsRemote() && RequestDomainsIfInactive(CacheDomain::Table)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-01 09:49:59 +00:00
|
|
|
if (auto iter = GetExplicitHeadersIterator()) {
|
|
|
|
while (Accessible* header = iter->Next()) {
|
|
|
|
role headerRole = header->Role();
|
|
|
|
if (headerRole == roles::COLUMNHEADER) {
|
|
|
|
aCells->AppendElement(header);
|
|
|
|
} else if (headerRole != roles::ROWHEADER) {
|
|
|
|
// Treat this cell as a column header only if it's in the same column.
|
|
|
|
if (auto cellIdx = table->mAccToCellIdx.Lookup(header)) {
|
|
|
|
CachedTableCellAccessible& cell = table->mCells[*cellIdx];
|
|
|
|
if (cell.ColIdx() == ColIdx()) {
|
|
|
|
aCells->AppendElement(header);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!aCells->IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-04-01 09:49:57 +00:00
|
|
|
Accessible* doc = nsAccUtils::DocumentFor(table->AsAccessible());
|
|
|
|
// Each cell stores its previous implicit column header, effectively forming a
|
|
|
|
// linked list. We traverse that to get all the headers.
|
|
|
|
CachedTableCellAccessible* cell = this;
|
|
|
|
for (;;) {
|
|
|
|
if (cell->mPrevColHeaderCellIdx == kNoCellIdx) {
|
|
|
|
break; // No more headers.
|
|
|
|
}
|
|
|
|
cell = &table->mCells[cell->mPrevColHeaderCellIdx];
|
|
|
|
Accessible* cellAcc = nsAccUtils::GetAccessibleByID(doc, cell->mAccID);
|
|
|
|
aCells->AppendElement(cellAcc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CachedTableCellAccessible::RowHeaderCells(nsTArray<Accessible*>* aCells) {
|
2022-04-01 09:49:59 +00:00
|
|
|
auto* table = static_cast<CachedTableAccessible*>(Table());
|
2022-04-01 09:49:57 +00:00
|
|
|
if (!table) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-01 09:49:59 +00:00
|
|
|
if (auto iter = GetExplicitHeadersIterator()) {
|
|
|
|
while (Accessible* header = iter->Next()) {
|
|
|
|
role headerRole = header->Role();
|
|
|
|
if (headerRole == roles::ROWHEADER) {
|
|
|
|
aCells->AppendElement(header);
|
|
|
|
} else if (headerRole != roles::COLUMNHEADER) {
|
|
|
|
// Treat this cell as a row header only if it's in the same row.
|
|
|
|
if (auto cellIdx = table->mAccToCellIdx.Lookup(header)) {
|
|
|
|
CachedTableCellAccessible& cell = table->mCells[*cellIdx];
|
|
|
|
if (cell.RowIdx() == RowIdx()) {
|
|
|
|
aCells->AppendElement(header);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!aCells->IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-07-14 00:44:56 +00:00
|
|
|
Accessible* doc = nsAccUtils::DocumentFor(table->AsAccessible());
|
2022-04-01 09:49:57 +00:00
|
|
|
// We don't cache implicit row headers because there are usually not that many
|
|
|
|
// cells per row. Get all the row headers on the row before this cell.
|
|
|
|
uint32_t row = RowIdx();
|
|
|
|
uint32_t thisCol = ColIdx();
|
|
|
|
for (uint32_t col = thisCol - 1; col < thisCol; --col) {
|
2022-07-14 00:44:56 +00:00
|
|
|
int32_t cellIdx = table->CellIndexAt(row, col);
|
|
|
|
if (cellIdx == -1) {
|
2022-04-01 09:49:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-07-14 00:44:56 +00:00
|
|
|
CachedTableCellAccessible& cell = table->mCells[cellIdx];
|
|
|
|
Accessible* cellAcc = nsAccUtils::GetAccessibleByID(doc, cell.mAccID);
|
|
|
|
MOZ_ASSERT(cellAcc);
|
2022-04-01 09:49:57 +00:00
|
|
|
// cell might span multiple columns. We don't want to visit it multiple
|
|
|
|
// times, so ensure col is set to cell's starting column.
|
2022-07-14 00:44:56 +00:00
|
|
|
col = cell.ColIdx();
|
2022-04-01 09:49:57 +00:00
|
|
|
if (cellAcc->Role() != roles::ROWHEADER) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
aCells->AppendElement(cellAcc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CachedTableCellAccessible::Selected() {
|
|
|
|
return mAcc->State() & states::SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla::a11y
|