Bug 1714390 - P6: Make more attribute keys static atoms. r=Jamie

Keys should be static atoms whenever possible.

Differential Revision: https://phabricator.services.mozilla.com/D116787
This commit is contained in:
Eitan Isaacson 2021-06-10 23:07:07 +00:00
parent 4fc2c36ea8
commit 349592fb91
12 changed files with 28 additions and 36 deletions

View File

@ -811,8 +811,8 @@ mozilla::java::GeckoBundle::LocalRef AccessibleWrap::ToBundle(
GECKOBUNDLE_PUT(nodeInfo, "collectionItemInfo", collectionItemInfo);
}
RefPtr<nsAtom> attrAtom = NS_Atomize("child-item-count"_ns);
Maybe<int32_t> rowCount = aAttributes->GetAttribute<int32_t>(attrAtom);
Maybe<int32_t> rowCount =
aAttributes->GetAttribute<int32_t>(nsGkAtoms::child_item_count);
if (rowCount) {
GECKOBUNDLE_START(collectionInfo);
GECKOBUNDLE_PUT(collectionInfo, "rowCount",
@ -820,8 +820,7 @@ mozilla::java::GeckoBundle::LocalRef AccessibleWrap::ToBundle(
GECKOBUNDLE_PUT(collectionInfo, "columnCount",
java::sdk::Integer::ValueOf(1));
attrAtom = NS_Atomize("hierarchical"_ns);
if (aAttributes->HasAttribute(attrAtom)) {
if (aAttributes->HasAttribute(nsGkAtoms::tree)) {
GECKOBUNDLE_PUT(collectionInfo, "isHierarchical",
java::sdk::Boolean::TRUE());
}

View File

@ -66,20 +66,6 @@ class AccAttributes {
}
}
// XXX: This will be removed in a later patch in the stack. This is
// just a stop-gap before we transtion to atom-only keys.
template <typename T>
void SetAttribute(const nsAString& aAttrName, const T& aAttrValue) {
RefPtr<nsAtom> attrAtom = NS_Atomize(aAttrName);
if constexpr (std::is_base_of_v<nsAtom, std::remove_pointer_t<T>>) {
mData.InsertOrUpdate(attrAtom, AsVariant(RefPtr<nsAtom>(aAttrValue)));
} else if constexpr (std::is_base_of_v<detail::nsStringRepr, T>) {
mData.InsertOrUpdate(attrAtom, AsVariant(nsString(aAttrValue)));
} else {
mData.InsertOrUpdate(attrAtom, AsVariant(aAttrValue));
}
}
template <typename T>
Maybe<T> GetAttribute(nsAtom* aAttrName) {
if (auto value = mData.Lookup(aAttrName)) {

View File

@ -40,7 +40,7 @@ already_AddRefed<AccAttributes> ARIAGridAccessible::NativeAttributes() {
RefPtr<AccAttributes> attributes = AccessibleWrap::NativeAttributes();
if (IsProbablyLayoutTable()) {
attributes->SetAttribute(u"layout-guess"_ns, true);
attributes->SetAttribute(nsGkAtoms::layout_guess, true);
}
return attributes.forget();
@ -608,7 +608,8 @@ already_AddRefed<AccAttributes> ARIAGridCellAccessible::NativeAttributes() {
rowIdx * colCount + colIdx);
#ifdef DEBUG
attributes->SetAttribute(u"cppclass"_ns, u"ARIAGridCellAccessible"_ns);
RefPtr<nsAtom> cppClass = NS_Atomize(u"cppclass"_ns);
attributes->SetAttribute(cppClass, u"ARIAGridCellAccessible"_ns);
#endif
return attributes.forget();

View File

@ -1411,7 +1411,7 @@ already_AddRefed<AccAttributes> HyperTextAccessible::NativeAttributes() {
// instead.
nsIFrame* frame = GetFrame();
if (frame && frame->IsBlockFrame()) {
attributes->SetAttribute(u"formatting"_ns, nsGkAtoms::block);
attributes->SetAttribute(nsGkAtoms::formatting, nsGkAtoms::block);
}
if (FocusMgr()->IsFocused(this)) {

View File

@ -1019,7 +1019,7 @@ already_AddRefed<AccAttributes> LocalAccessible::NativeAttributes() {
if (HasNumericValue()) {
nsAutoString valuetext;
Value(valuetext);
attributes->SetAttribute(u"valuetext"_ns, valuetext);
attributes->SetAttribute(nsGkAtoms::aria_valuetext, valuetext);
}
// Expose checkable object attribute if the accessible has checkable state
@ -1030,7 +1030,7 @@ already_AddRefed<AccAttributes> LocalAccessible::NativeAttributes() {
// Expose 'explicit-name' attribute.
nsAutoString name;
if (Name(name) != eNameFromSubtree && !name.IsVoid()) {
attributes->SetAttribute(u"explicit-name"_ns, true);
attributes->SetAttribute(nsGkAtoms::explicit_name, true);
}
// Group attributes (level/setsize/posinset)
@ -1041,12 +1041,12 @@ already_AddRefed<AccAttributes> LocalAccessible::NativeAttributes() {
bool hierarchical = false;
uint32_t itemCount = AccGroupInfo::TotalItemCount(this, &hierarchical);
if (itemCount) {
attributes->SetAttribute(u"child-item-count"_ns,
attributes->SetAttribute(nsGkAtoms::child_item_count,
static_cast<int32_t>(itemCount));
}
if (hierarchical) {
attributes->SetAttribute(u"hierarchical"_ns, true);
attributes->SetAttribute(nsGkAtoms::tree, true);
}
// If the accessible doesn't have own content (such as list item bullet or

View File

@ -118,7 +118,8 @@ already_AddRefed<AccAttributes> HTMLTableCellAccessible::NativeAttributes() {
}
#ifdef DEBUG
attributes->SetAttribute(u"cppclass"_ns, u"HTMLTableCellAccessible"_ns);
RefPtr<nsAtom> cppClass = NS_Atomize(u"cppclass"_ns);
attributes->SetAttribute(cppClass, u"HTMLTableCellAccessible"_ns);
#endif
return attributes.forget();
@ -398,7 +399,7 @@ already_AddRefed<AccAttributes> HTMLTableAccessible::NativeAttributes() {
}
if (IsProbablyLayoutTable()) {
attributes->SetAttribute(u"layout-guess"_ns, true);
attributes->SetAttribute(nsGkAtoms::layout_guess, true);
}
return attributes.forget();

View File

@ -58,8 +58,8 @@ using namespace mozilla::a11y;
// Per the MathML 3 spec, the latter happens iff the linethickness
// attribute is of the form [zero-float][optional-unit]. In that case we
// set line thickness to zero and in the other cases we set it to one.
RefPtr<nsAtom> attrName = NS_Atomize("thickness"_ns);
if (NSString* thickness = utils::GetAccAttr(self, attrName)) {
if (NSString* thickness =
utils::GetAccAttr(self, nsGkAtoms::linethickness_)) {
NSNumberFormatter* formatter =
[[[NSNumberFormatter alloc] init] autorelease];
NSNumber* value = [formatter numberFromString:thickness];

View File

@ -138,9 +138,9 @@ function testGroupParentAttrs(aAccOrElmOrID, aChildItemCount, aIsHierarchical) {
);
if (aIsHierarchical) {
testAttrs(aAccOrElmOrID, { hierarchical: "true" }, true);
testAttrs(aAccOrElmOrID, { tree: "true" }, true);
} else {
testAbsentAttrs(aAccOrElmOrID, { hierarchical: "true" });
testAbsentAttrs(aAccOrElmOrID, { tree: "true" });
}
}

View File

@ -212,8 +212,8 @@
testGroupAttrs("h5", 0, 0, 5);
testGroupAttrs("h6", 0, 0, 6);
testGroupAttrs("ariaHeadingNoLevel", 0, 0, 2);
// No child item counts or "hierarchical" flag for parent of headings
testAbsentAttrs("headings", {"child-item-count": "", "hierarchical": ""});
// No child item counts or "tree" flag for parent of headings
testAbsentAttrs("headings", {"child-item-count": "", "tree": ""});
// ////////////////////////////////////////////////////////////////////////
// ARIA combobox

View File

@ -26,7 +26,8 @@ already_AddRefed<AccAttributes> ApplicationAccessibleWrap::NativeAttributes() {
if (gfxInfo) {
bool isD2DEnabled = false;
gfxInfo->GetD2DEnabled(&isD2DEnabled);
attributes->SetAttribute(u"D2D"_ns, isD2DEnabled);
RefPtr<nsAtom> attrName = NS_Atomize(u"D2D"_ns);
attributes->SetAttribute(attrName, isD2DEnabled);
}
return attributes.forget();

View File

@ -378,8 +378,8 @@ xpcAccessible::GetAttributes(nsIPersistentProperties** aAttributes) {
proxy->Attributes(&attrs);
uint32_t attrCount = attrs.Length();
for (uint32_t i = 0; i < attrCount; i++) {
attributes->SetAttribute(NS_ConvertUTF8toUTF16(attrs[i].Name()),
attrs[i].Value());
RefPtr<nsAtom> nameAttr = NS_Atomize(attrs[i].Name());
attributes->SetAttribute(nameAttr, attrs[i].Value());
}
}

View File

@ -224,6 +224,7 @@ STATIC_ATOMS = [
Atom("child", "child"),
Atom("children", "children"),
Atom("childList", "childList"),
Atom("child_item_count", "child-item-count"),
Atom("choose", "choose"),
Atom("chromemargin", "chromemargin"),
Atom("exposeToUntrustedContent", "exposeToUntrustedContent"),
@ -422,6 +423,7 @@ STATIC_ATOMS = [
Atom("events", "events"),
Atom("excludeResultPrefixes", "exclude-result-prefixes"),
Atom("exportparts", "exportparts"),
Atom("explicit_name", "explicit-name"),
Atom("extends", "extends"),
Atom("extensionElementPrefixes", "extension-element-prefixes"),
Atom("face", "face"),
@ -583,6 +585,7 @@ STATIC_ATOMS = [
Atom("last", "last"),
Atom("layer", "layer"),
Atom("LayerActivity", "LayerActivity"),
Atom("layout_guess", "layout-guess"),
Atom("leading", "leading"),
Atom("leaf", "leaf"),
Atom("left", "left"),
@ -1398,6 +1401,7 @@ STATIC_ATOMS = [
Atom("font_stretch", "font-stretch"),
Atom("font_style", "font-style"),
Atom("font_variant", "font-variant"),
Atom("formatting", "formatting"),
Atom("foreignObject", "foreignObject"),
Atom("fractalNoise", "fractalNoise"),
Atom("fr", "fr"),