Bug 1882909: Remove unnecessary uses of const_cast from accessibility module, r=morgan

This revision removes all removable instances of const_cast from the
accessibility module. Name() was previously non-const, but is now const. Same
for ActionWalk().

Differential Revision: https://phabricator.services.mozilla.com/D203207
This commit is contained in:
Nathan LaPre 2024-03-04 18:46:01 +00:00
parent 05452e1329
commit 13906c252f
3 changed files with 4 additions and 9 deletions

View File

@ -120,8 +120,7 @@ const LocalAccessible* LinkableAccessible::ActionWalk(bool* aIsLink,
}
KeyBinding LinkableAccessible::AccessKey() const {
if (const LocalAccessible* actionAcc =
const_cast<LinkableAccessible*>(this)->ActionWalk()) {
if (const LocalAccessible* actionAcc = ActionWalk()) {
return actionAcc->AccessKey();
}

View File

@ -225,7 +225,5 @@ role HTMLHeaderOrFooterAccessible::NativeRole() const {
////////////////////////////////////////////////////////////////////////////////
role HTMLSectionAccessible::NativeRole() const {
nsAutoString name;
const_cast<HTMLSectionAccessible*>(this)->Name(name);
return name.IsEmpty() ? roles::SECTION : roles::REGION;
return NameIsEmpty() ? roles::SECTION : roles::REGION;
}

View File

@ -35,9 +35,7 @@ using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
role HTMLFormAccessible::NativeRole() const {
nsAutoString name;
const_cast<HTMLFormAccessible*>(this)->Name(name);
return name.IsEmpty() ? roles::FORM : roles::FORM_LANDMARK;
return NameIsEmpty() ? roles::FORM : roles::FORM_LANDMARK;
}
void HTMLFormAccessible::DOMAttributeChanged(int32_t aNameSpaceID,
@ -293,7 +291,7 @@ already_AddRefed<AccAttributes> HTMLTextFieldAccessible::NativeAttributes() {
nsString placeholderText;
if (mContent->AsElement()->GetAttr(nsGkAtoms::placeholder, placeholderText)) {
nsAutoString name;
const_cast<HTMLTextFieldAccessible*>(this)->Name(name);
Name(name);
if (!name.Equals(placeholderText)) {
attributes->SetAttribute(nsGkAtoms::placeholder,
std::move(placeholderText));