From 25f7ff34851a85d35e7286f3430082c4f6c39be2 Mon Sep 17 00:00:00 2001 From: James Teh Date: Tue, 7 Dec 2021 00:01:30 +0000 Subject: [PATCH] Bug 1742915 part 1: Move Attributes to base Accessible. r=morgan The RemoteAccessibleBase implementation is a stub for now, but will be expanded in the next patch. Differential Revision: https://phabricator.services.mozilla.com/D132652 --- accessible/atk/AccessibleWrap.cpp | 18 +++++------------- accessible/basetypes/Accessible.h | 6 ++++++ accessible/generic/LocalAccessible.h | 5 +---- accessible/ipc/RemoteAccessibleBase.cpp | 6 ++++++ accessible/ipc/RemoteAccessibleBase.h | 2 ++ accessible/ipc/RemoteAccessibleShared.h | 2 +- accessible/ipc/other/RemoteAccessible.cpp | 9 +++++++-- accessible/ipc/win/RemoteAccessible.cpp | 16 ++++++++++------ accessible/mac/MacUtils.mm | 9 ++------- accessible/windows/ia2/ia2Accessible.cpp | 7 ++----- accessible/xpcom/xpcAccessible.cpp | 8 +------- 11 files changed, 43 insertions(+), 45 deletions(-) diff --git a/accessible/atk/AccessibleWrap.cpp b/accessible/atk/AccessibleWrap.cpp index cab1d207a69b..4b29f183d56b 100644 --- a/accessible/atk/AccessibleWrap.cpp +++ b/accessible/atk/AccessibleWrap.cpp @@ -658,20 +658,12 @@ static AtkAttributeSet* ConvertToAtkAttributeSet(AccAttributes* aAttributes) { return objAttributeSet; } -AtkAttributeSet* GetAttributeSet(LocalAccessible* aAccessible) { - RefPtr attributes = aAccessible->Attributes(); - return ConvertToAtkAttributeSet(attributes); -} - AtkAttributeSet* getAttributesCB(AtkObject* aAtkObj) { - AccessibleWrap* accWrap = GetAccessibleWrap(aAtkObj); - if (accWrap) return GetAttributeSet(accWrap); - - RemoteAccessible* proxy = GetProxy(aAtkObj); - if (!proxy) return nullptr; - - RefPtr attributes = nullptr; - proxy->Attributes(&attributes); + Accessible* acc = GetInternalObj(aAtkObj); + if (!acc) { + return nullptr; + } + RefPtr attributes = acc->Attributes(); return ConvertToAtkAttributeSet(attributes); } diff --git a/accessible/basetypes/Accessible.h b/accessible/basetypes/Accessible.h index 4fd2fa18da6e..ff19828d73d4 100644 --- a/accessible/basetypes/Accessible.h +++ b/accessible/basetypes/Accessible.h @@ -18,6 +18,7 @@ struct nsRoleMapEntry; namespace mozilla { namespace a11y { +class AccAttributes; class HyperTextAccessibleBase; class LocalAccessible; class RemoteAccessible; @@ -163,6 +164,11 @@ class Accessible { */ virtual uint32_t StartOffset(); + /** + * Return object attributes for the accessible. + */ + virtual already_AddRefed Attributes() = 0; + // Methods that interact with content. virtual void TakeFocus() const = 0; diff --git a/accessible/generic/LocalAccessible.h b/accessible/generic/LocalAccessible.h index fe5e71f02aac..fd37269f5d99 100644 --- a/accessible/generic/LocalAccessible.h +++ b/accessible/generic/LocalAccessible.h @@ -242,10 +242,7 @@ class LocalAccessible : public nsISupports, public Accessible { */ virtual bool NativelyUnavailable() const; - /** - * Return object attributes for the accessible. - */ - virtual already_AddRefed Attributes(); + virtual already_AddRefed Attributes() override; /** * Return group position (level, position in set and set size). diff --git a/accessible/ipc/RemoteAccessibleBase.cpp b/accessible/ipc/RemoteAccessibleBase.cpp index ccc2b6e462d0..b99d252da6ce 100644 --- a/accessible/ipc/RemoteAccessibleBase.cpp +++ b/accessible/ipc/RemoteAccessibleBase.cpp @@ -467,6 +467,12 @@ uint64_t RemoteAccessibleBase::State() { return state; } +template +already_AddRefed RemoteAccessibleBase::Attributes() { + RefPtr attributes = new AccAttributes(); + return attributes.forget(); +} + template void RemoteAccessibleBase::TakeFocus() const { Unused << mDoc->SendTakeFocus(mID); diff --git a/accessible/ipc/RemoteAccessibleBase.h b/accessible/ipc/RemoteAccessibleBase.h index 2eded2c3be8f..e72c5b18fc69 100644 --- a/accessible/ipc/RemoteAccessibleBase.h +++ b/accessible/ipc/RemoteAccessibleBase.h @@ -180,6 +180,8 @@ class RemoteAccessibleBase : public Accessible, public HyperTextAccessibleBase { virtual uint64_t State() override; + virtual already_AddRefed Attributes() override; + // Methods that interact with content. virtual void TakeFocus() const override; diff --git a/accessible/ipc/RemoteAccessibleShared.h b/accessible/ipc/RemoteAccessibleShared.h index 6634be234c4f..868a9f043c00 100644 --- a/accessible/ipc/RemoteAccessibleShared.h +++ b/accessible/ipc/RemoteAccessibleShared.h @@ -46,7 +46,7 @@ void Description(nsString& aDesc) const override; /** * Get the set of attributes on the proxied accessible. */ -void Attributes(RefPtr* aAttributes) const; +virtual already_AddRefed Attributes() override; /** * Return set of targets of given relation type. diff --git a/accessible/ipc/other/RemoteAccessible.cpp b/accessible/ipc/other/RemoteAccessible.cpp index e6cc4f019c5d..19f54df06028 100644 --- a/accessible/ipc/other/RemoteAccessible.cpp +++ b/accessible/ipc/other/RemoteAccessible.cpp @@ -62,8 +62,13 @@ void RemoteAccessible::Description(nsString& aDesc) const { Unused << mDoc->SendDescription(mID, &aDesc); } -void RemoteAccessible::Attributes(RefPtr* aAttributes) const { - Unused << mDoc->SendAttributes(mID, aAttributes); +already_AddRefed RemoteAccessible::Attributes() { + if (StaticPrefs::accessibility_cache_enabled_AtStartup()) { + return RemoteAccessibleBase::Attributes(); + } + RefPtr attrs; + Unused << mDoc->SendAttributes(mID, &attrs); + return attrs.forget(); } nsTArray RemoteAccessible::RelationByType( diff --git a/accessible/ipc/win/RemoteAccessible.cpp b/accessible/ipc/win/RemoteAccessible.cpp index 4e494a9016e6..19a323914c29 100644 --- a/accessible/ipc/win/RemoteAccessible.cpp +++ b/accessible/ipc/win/RemoteAccessible.cpp @@ -353,28 +353,32 @@ static bool ConvertBSTRAttributesToAccAttributes( return true; } -void RemoteAccessible::Attributes(RefPtr* aAttrs) const { +already_AddRefed RemoteAccessible::Attributes() { + if (StaticPrefs::accessibility_cache_enabled_AtStartup()) { + return RemoteAccessibleBase::Attributes(); + } + RefPtr attrsObj = new AccAttributes(); RefPtr acc; if (!GetCOMInterface((void**)getter_AddRefs(acc))) { - return; + return attrsObj.forget(); } RefPtr acc2; if (FAILED(acc->QueryInterface(IID_IAccessible2, (void**)getter_AddRefs(acc2)))) { - return; + return attrsObj.forget(); } BSTR attrs; HRESULT hr = acc2->get_attributes(&attrs); _bstr_t attrsWrap(attrs, false); if (FAILED(hr)) { - return; + return attrsObj.forget(); } - *aAttrs = new AccAttributes(); ConvertBSTRAttributesToAccAttributes( - nsDependentString((wchar_t*)attrs, attrsWrap.length()), *aAttrs); + nsDependentString((wchar_t*)attrs, attrsWrap.length()), attrsObj); + return attrsObj.forget(); } nsTArray RemoteAccessible::RelationByType( diff --git a/accessible/mac/MacUtils.mm b/accessible/mac/MacUtils.mm index 403599468f28..de3820191271 100644 --- a/accessible/mac/MacUtils.mm +++ b/accessible/mac/MacUtils.mm @@ -62,13 +62,8 @@ NSString* LocalizedString(const nsString& aString) { NSString* GetAccAttr(mozAccessible* aNativeAccessible, nsAtom* aAttrName) { nsAutoString result; - RefPtr attributes; - if (LocalAccessible* acc = [aNativeAccessible geckoAccessible]->AsLocal()) { - attributes = acc->Attributes(); - } else if (RemoteAccessible* proxy = - [aNativeAccessible geckoAccessible]->AsRemote()) { - proxy->Attributes(&attributes); - } + Accessible* acc = [aNativeAccessible geckoAccessible]; + RefPtr attributes = acc->Attributes(); attributes->GetAttribute(aAttrName, result); diff --git a/accessible/windows/ia2/ia2Accessible.cpp b/accessible/windows/ia2/ia2Accessible.cpp index b56b1d3d39c6..e79a150e0a3d 100644 --- a/accessible/windows/ia2/ia2Accessible.cpp +++ b/accessible/windows/ia2/ia2Accessible.cpp @@ -453,12 +453,9 @@ ia2Accessible::get_attributes(BSTR* aAttributes) { if (!aAttributes) return E_INVALIDARG; *aAttributes = nullptr; - if (!Acc()) { - return CO_E_OBJNOTCONNECTED; - } - AccessibleWrap* acc = LocalAcc(); + Accessible* acc = Acc(); if (!acc) { - return E_NOTIMPL; // XXX Not supported for RemoteAccessible yet. + return CO_E_OBJNOTCONNECTED; } // The format is name:value;name:value; with \ for escaping these diff --git a/accessible/xpcom/xpcAccessible.cpp b/accessible/xpcom/xpcAccessible.cpp index 4b3521a8cb5b..db0156d37e97 100644 --- a/accessible/xpcom/xpcAccessible.cpp +++ b/accessible/xpcom/xpcAccessible.cpp @@ -359,13 +359,7 @@ xpcAccessible::GetAttributes(nsIPersistentProperties** aAttributes) { RefPtr props = new nsPersistentProperties(); - RefPtr attributes; - if (LocalAccessible* acc = Intl()) { - attributes = acc->Attributes(); - } else { - RemoteAccessible* proxy = IntlGeneric()->AsRemote(); - proxy->Attributes(&attributes); - } + RefPtr attributes = IntlGeneric()->Attributes(); nsAutoString unused; for (auto iter : *attributes) {