mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 06:43:32 +00:00
Bug 1903713: Avoid static nsTHashSet constructor via instance method, r=Jamie
This revision avoids static construction of the nsTHashSet by hiding the set behind an instance method. Differential Revision: https://phabricator.services.mozilla.com/D214664
This commit is contained in:
parent
42e07930fa
commit
9162c8ef57
@ -37,7 +37,10 @@ static bool sInAriaRelationTraversal = false;
|
||||
* alternative for an accessible. Per the Name From Content section of the Acc
|
||||
* Name spec, "[e]ach node in the subtree is consulted only once."
|
||||
*/
|
||||
static nsTHashSet<const Accessible*> sReferencedAccs;
|
||||
static nsTHashSet<const Accessible*>& GetReferencedAccs() {
|
||||
static nsTHashSet<const Accessible*> sReferencedAccs;
|
||||
return sReferencedAccs;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsTextEquivUtils. Public.
|
||||
@ -46,15 +49,15 @@ nsresult nsTextEquivUtils::GetNameFromSubtree(
|
||||
const LocalAccessible* aAccessible, nsAString& aName) {
|
||||
aName.Truncate();
|
||||
|
||||
if (sReferencedAccs.Contains(aAccessible)) {
|
||||
if (GetReferencedAccs().Contains(aAccessible)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Remember the initiating accessible so we know when we've returned to it.
|
||||
if (sReferencedAccs.IsEmpty()) {
|
||||
if (GetReferencedAccs().IsEmpty()) {
|
||||
sInitiatorAcc = aAccessible;
|
||||
}
|
||||
sReferencedAccs.Insert(aAccessible);
|
||||
GetReferencedAccs().Insert(aAccessible);
|
||||
|
||||
if (GetRoleRule(aAccessible->Role()) == eNameFromSubtreeRule) {
|
||||
// XXX: is it necessary to care the accessible is not a document?
|
||||
@ -70,7 +73,7 @@ nsresult nsTextEquivUtils::GetNameFromSubtree(
|
||||
// returned to the initiator acc), clear out the referenced accessibles and
|
||||
// reset the initiator acc.
|
||||
if (aAccessible == sInitiatorAcc) {
|
||||
sReferencedAccs.Clear();
|
||||
GetReferencedAccs().Clear();
|
||||
sInitiatorAcc = nullptr;
|
||||
}
|
||||
|
||||
@ -86,7 +89,7 @@ nsresult nsTextEquivUtils::GetTextEquivFromIDRefs(
|
||||
const bool isAriaTraversal = aIDRefsAttr == nsGkAtoms::aria_labelledby ||
|
||||
aIDRefsAttr == nsGkAtoms::aria_describedby;
|
||||
if ((sInAriaRelationTraversal && isAriaTraversal) ||
|
||||
sReferencedAccs.Contains(aAccessible)) {
|
||||
GetReferencedAccs().Contains(aAccessible)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -126,21 +129,21 @@ nsresult nsTextEquivUtils::AppendTextEquivFromContent(
|
||||
// Prevent recursion which can cause infinite loops.
|
||||
LocalAccessible* accessible =
|
||||
aInitiatorAcc->Document()->GetAccessible(aContent);
|
||||
if (sReferencedAccs.Contains(aInitiatorAcc) ||
|
||||
sReferencedAccs.Contains(accessible)) {
|
||||
if (GetReferencedAccs().Contains(aInitiatorAcc) ||
|
||||
GetReferencedAccs().Contains(accessible)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Remember the initiating accessible so we know when we've returned to it.
|
||||
if (sReferencedAccs.IsEmpty()) {
|
||||
if (GetReferencedAccs().IsEmpty()) {
|
||||
sInitiatorAcc = aInitiatorAcc;
|
||||
}
|
||||
sReferencedAccs.Insert(aInitiatorAcc);
|
||||
GetReferencedAccs().Insert(aInitiatorAcc);
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (accessible) {
|
||||
rv = AppendFromAccessible(accessible, aString);
|
||||
sReferencedAccs.Insert(accessible);
|
||||
GetReferencedAccs().Insert(accessible);
|
||||
} else {
|
||||
// The given content is invisible or otherwise inaccessible, so use the DOM
|
||||
// subtree.
|
||||
@ -151,7 +154,7 @@ nsresult nsTextEquivUtils::AppendTextEquivFromContent(
|
||||
// returned to the initiator acc), clear out the referenced accessibles and
|
||||
// reset the initiator acc.
|
||||
if (aInitiatorAcc == sInitiatorAcc) {
|
||||
sReferencedAccs.Clear();
|
||||
GetReferencedAccs().Clear();
|
||||
sInitiatorAcc = nullptr;
|
||||
}
|
||||
return rv;
|
||||
@ -212,7 +215,7 @@ nsresult nsTextEquivUtils::AppendFromAccessibleChildren(
|
||||
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
|
||||
Accessible* child = aAccessible->ChildAt(childIdx);
|
||||
// If we've already consulted this child, don't consult it again.
|
||||
if (sReferencedAccs.Contains(child)) {
|
||||
if (GetReferencedAccs().Contains(child)) {
|
||||
continue;
|
||||
}
|
||||
rv = AppendFromAccessible(child, aString);
|
||||
|
Loading…
Reference in New Issue
Block a user