Skip to content

Commit

Permalink
Bug 1726124: [Part 1] Generalise nsAccUtils::TableFor for table parts…
Browse files Browse the repository at this point in the history
… r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D155276
  • Loading branch information
MReschenberg committed Aug 29, 2022
1 parent 2a9c6ae commit 77f810c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 45 deletions.
15 changes: 2 additions & 13 deletions accessible/base/CachedTableAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,8 @@ void CachedTableAccessible::Invalidate(Accessible* aAcc) {
if (!sCachedTables) {
return;
}
Accessible* table = nullptr;
if (aAcc->IsTable()) {
table = aAcc;
} else if (aAcc->IsTableCell()) {
for (table = aAcc->Parent(); table; table = table->Parent()) {
if (table->IsTable()) {
break;
}
}
} else {
MOZ_ASSERT_UNREACHABLE("Should only be called on a table or a cell");
}
if (table) {

if (Accessible* table = nsAccUtils::TableFor(aAcc)) {
// Destroy the instance (if any). We'll create a new one the next time it
// is requested.
sCachedTables->Remove(table);
Expand Down
32 changes: 12 additions & 20 deletions accessible/base/nsAccUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,19 @@ bool nsAccUtils::IsDOMAttrTrue(const LocalAccessible* aAccessible,
eCaseMatters);
}

Accessible* nsAccUtils::TableFor(Accessible* aRow) {
if (aRow) {
Accessible* table = aRow->Parent();
if (table) {
roles::Role tableRole = table->Role();
const nsRoleMapEntry* roleMapEntry = table->ARIARoleMap();
if (tableRole == roles::GROUPING || // if there's a rowgroup.
(table->IsGenericHyperText() && !roleMapEntry &&
!table->IsTable())) { // or there is a wrapping text container
table = table->Parent();
if (table) tableRole = table->Role();
}

return (tableRole == roles::TABLE || tableRole == roles::TREE_TABLE ||
tableRole == roles::MATHML_TABLE)
? table
: nullptr;
}
Accessible* nsAccUtils::TableFor(Accessible* aAcc) {
if (!aAcc ||
(!aAcc->IsTable() && !aAcc->IsTableRow() && !aAcc->IsTableCell())) {
return nullptr;
}

return nullptr;
Accessible* table = aAcc;
for (; table && !table->IsTable(); table = table->Parent()) {
}
// We don't assert (table && table->IsTable()) here because
// it's possible for this tree walk to yield no table at all
// ex. because a table part has been moved in the tree
// using aria-owns.
return table;
}

LocalAccessible* nsAccUtils::TableFor(LocalAccessible* aRow) {
Expand Down
5 changes: 3 additions & 2 deletions accessible/base/nsAccessibilityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,10 @@ void nsAccessibilityService::ContentRemoved(PresShell* aPresShell,
void nsAccessibilityService::TableLayoutGuessMaybeChanged(
PresShell* aPresShell, nsIContent* aContent) {
if (DocAccessible* document = GetDocAccessible(aPresShell)) {
if (LocalAccessible* accessible = document->GetAccessible(aContent)) {
if (LocalAccessible* acc = document->GetAccessible(aContent)) {
LocalAccessible* table = nsAccUtils::TableFor(acc);
document->FireDelayedEvent(
nsIAccessibleEvent::EVENT_TABLE_STYLING_CHANGED, accessible);
nsIAccessibleEvent::EVENT_TABLE_STYLING_CHANGED, table);
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions accessible/generic/DocAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,17 +1320,9 @@ bool DocAccessible::PruneOrInsertSubtree(nsIContent* aRoot) {
// status may have changed. We need to invalidate the associated
// cache, which listens for the following event.
if (acc->IsTable() || acc->IsTableRow() || acc->IsTableCell()) {
LocalAccessible* table = nsAccUtils::TableFor(acc);
FireDelayedEvent(nsIAccessibleEvent::EVENT_TABLE_STYLING_CHANGED, acc);
LocalAccessible* table;
if (acc->IsTable()) {
table = acc;
} else {
for (table = acc->LocalParent(); table; table = table->LocalParent()) {
if (table->IsTable()) {
break;
}
}
}

if (table && table->IsTable()) {
QueueCacheUpdate(acc, CacheDomain::Table);
}
Expand Down

0 comments on commit 77f810c

Please sign in to comment.