Bug 1755817 - Move LandmarkRole to Accessible. r=Jamie

Current mochitests should prove the soundness of this. The only thing
preventing this from becoming a non-virtual method is the reliance
on TagName which is only available when cached is enabled. When it
is disabled we need to fallback on the sync IPDL call.

Differential Revision: https://phabricator.services.mozilla.com/D138964
This commit is contained in:
Eitan Isaacson 2022-02-18 18:21:01 +00:00
Родитель cedb598cc3
Коммит 4fb238b0ec
13 изменённых файлов: 64 добавлений и 78 удалений

Просмотреть файл

@ -321,3 +321,56 @@ const Accessible* Accessible::ActionAncestor() const {
return nullptr;
}
nsAtom* Accessible::LandmarkRole() const {
nsAtom* tagName = TagName();
if (!tagName) {
// Either no associated content, or no cache.
return nullptr;
}
if (tagName == nsGkAtoms::nav) {
return nsGkAtoms::navigation;
}
if (tagName == nsGkAtoms::aside) {
return nsGkAtoms::complementary;
}
if (tagName == nsGkAtoms::main) {
return nsGkAtoms::main;
}
if (tagName == nsGkAtoms::header) {
if (Role() == roles::LANDMARK) {
return nsGkAtoms::banner;
}
}
if (tagName == nsGkAtoms::footer) {
if (Role() == roles::LANDMARK) {
return nsGkAtoms::contentinfo;
}
}
if (tagName == nsGkAtoms::section) {
nsAutoString name;
Name(name);
if (!name.IsEmpty()) {
return nsGkAtoms::region;
}
}
if (tagName == nsGkAtoms::form) {
nsAutoString name;
Name(name);
if (!name.IsEmpty()) {
return nsGkAtoms::form;
}
}
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
return roleMapEntry && roleMapEntry->IsOfType(eLandmark)
? roleMapEntry->roleAtom
: nullptr;
}

Просмотреть файл

@ -229,6 +229,11 @@ class Accessible {
*/
virtual nsAtom* TagName() const = 0;
/**
* Return a landmark role if applied.
*/
virtual nsAtom* LandmarkRole() const;
//////////////////////////////////////////////////////////////////////////////
// ActionAccessible

Просмотреть файл

@ -1427,26 +1427,6 @@ already_AddRefed<AccAttributes> HyperTextAccessible::NativeAttributes() {
return attributes.forget();
}
nsAtom* HyperTextAccessible::LandmarkRole() const {
if (!HasOwnContent()) return nullptr;
// For the html landmark elements we expose them like we do ARIA landmarks to
// make AT navigation schemes "just work".
if (mContent->IsHTMLElement(nsGkAtoms::nav)) {
return nsGkAtoms::navigation;
}
if (mContent->IsHTMLElement(nsGkAtoms::aside)) {
return nsGkAtoms::complementary;
}
if (mContent->IsHTMLElement(nsGkAtoms::main)) {
return nsGkAtoms::main;
}
return AccessibleWrap::LandmarkRole();
}
int32_t HyperTextAccessible::OffsetAtPoint(int32_t aX, int32_t aY,
uint32_t aCoordType) {
nsIFrame* hyperFrame = GetFrame();

Просмотреть файл

@ -50,7 +50,6 @@ class HyperTextAccessible : public AccessibleWrap,
NS_INLINE_DECL_REFCOUNTING_INHERITED(HyperTextAccessible, AccessibleWrap)
// LocalAccessible
virtual nsAtom* LandmarkRole() const override;
virtual already_AddRefed<AccAttributes> NativeAttributes() override;
virtual mozilla::a11y::role NativeRole() const override;
virtual uint64_t NativeState() const override;

Просмотреть файл

@ -1804,13 +1804,6 @@ role LocalAccessible::ARIATransformRole(role aRole) const {
return aRole;
}
nsAtom* LocalAccessible::LandmarkRole() const {
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
return roleMapEntry && roleMapEntry->IsOfType(eLandmark)
? roleMapEntry->roleAtom
: nullptr;
}
role LocalAccessible::NativeRole() const { return roles::NOTHING; }
uint8_t LocalAccessible::ActionCount() const {

Просмотреть файл

@ -172,11 +172,6 @@ class LocalAccessible : public nsISupports, public Accessible {
*/
mozilla::a11y::role ARIARole();
/**
* Return a landmark role if applied.
*/
virtual nsAtom* LandmarkRole() const;
/**
* Returns enumerated accessible role from native markup (see constants in
* Role.h). Doesn't take into account ARIA roles.

Просмотреть файл

@ -208,23 +208,6 @@ role HTMLHeaderOrFooterAccessible::NativeRole() const {
return roles::SECTION;
}
nsAtom* HTMLHeaderOrFooterAccessible::LandmarkRole() const {
if (!HasOwnContent()) return nullptr;
a11y::role r = const_cast<HTMLHeaderOrFooterAccessible*>(this)->Role();
if (r == roles::LANDMARK) {
if (mContent->IsHTMLElement(nsGkAtoms::header)) {
return nsGkAtoms::banner;
}
if (mContent->IsHTMLElement(nsGkAtoms::footer)) {
return nsGkAtoms::contentinfo;
}
}
return HyperTextAccessibleWrap::LandmarkRole();
}
////////////////////////////////////////////////////////////////////////////////
// HTMLSectionAccessible
////////////////////////////////////////////////////////////////////////////////
@ -235,14 +218,3 @@ role HTMLSectionAccessible::NativeRole() const {
return name.IsEmpty() ? roles::SECTION : roles::REGION;
}
nsAtom* HTMLSectionAccessible::LandmarkRole() const {
if (!HasOwnContent()) {
return nullptr;
}
// Only return xml-roles "region" if the section has an accessible name.
nsAutoString name;
const_cast<HTMLSectionAccessible*>(this)->Name(name);
return name.IsEmpty() ? HyperTextAccessibleWrap::LandmarkRole()
: nsGkAtoms::region;
}

Просмотреть файл

@ -125,7 +125,6 @@ class HTMLHeaderOrFooterAccessible : public HyperTextAccessibleWrap {
HyperTextAccessibleWrap)
// LocalAccessible
virtual nsAtom* LandmarkRole() const override;
virtual a11y::role NativeRole() const override;
protected:
@ -144,7 +143,6 @@ class HTMLSectionAccessible : public HyperTextAccessibleWrap {
HyperTextAccessibleWrap)
// LocalAccessible
virtual nsAtom* LandmarkRole() const override;
virtual a11y::role NativeRole() const override;
protected:

Просмотреть файл

@ -42,18 +42,6 @@ role HTMLFormAccessible::NativeRole() const {
return name.IsEmpty() ? roles::FORM : roles::FORM_LANDMARK;
}
nsAtom* HTMLFormAccessible::LandmarkRole() const {
if (!HasOwnContent()) {
return nullptr;
}
// Only return xml-roles "form" if the form has an accessible name.
nsAutoString name;
const_cast<HTMLFormAccessible*>(this)->Name(name);
return name.IsEmpty() ? HyperTextAccessibleWrap::LandmarkRole()
: nsGkAtoms::form;
}
void HTMLFormAccessible::DOMAttributeChanged(int32_t aNameSpaceID,
nsAtom* aAttribute,
int32_t aModType,

Просмотреть файл

@ -244,7 +244,6 @@ class HTMLFormAccessible : public HyperTextAccessibleWrap {
HyperTextAccessibleWrap)
// LocalAccessible
virtual nsAtom* LandmarkRole() const override;
virtual a11y::role NativeRole() const override;
protected:

Просмотреть файл

@ -61,8 +61,6 @@ void Relations(nsTArray<RelationType>* aTypes,
bool IsSearchbox() const;
nsAtom* LandmarkRole() const;
nsStaticAtom* ARIARoleAtom() const;
virtual mozilla::a11y::GroupPos GroupPosition() override;

Просмотреть файл

@ -129,6 +129,10 @@ bool RemoteAccessible::IsSearchbox() const {
}
nsAtom* RemoteAccessible::LandmarkRole() const {
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
return RemoteAccessibleBase<RemoteAccessible>::LandmarkRole();
}
nsString landmark;
Unused << mDoc->SendLandmarkRole(mID, &landmark);
return NS_GetStaticAtom(landmark);

Просмотреть файл

@ -59,6 +59,8 @@ class RemoteAccessible : public RemoteAccessibleBase<RemoteAccessible> {
virtual bool SelectAll() override;
virtual bool UnselectAll() override;
virtual nsAtom* LandmarkRole() const override;
protected:
explicit RemoteAccessible(DocAccessibleParent* aThisAsDoc)
: RemoteAccessibleBase(aThisAsDoc) {