Bug 1694865 part 19: Make EnumVariant, GeckoCustom and sdn*Accessible classes aggregate MsaaAccessible/MsaaDocAccessible instead of AccessibleWrap/DocAccessibleWrap. r=morgan

These objects need to aggregate the primary COM object (MsaaAccessible).
Once the IUnknown implementation moves out of AccessibleWrap, it won't be possible to aggregate *AccessibleWrap any more.

Differential Revision: https://phabricator.services.mozilla.com/D112949
This commit is contained in:
James Teh 2021-05-01 22:29:25 +00:00
Родитель c38fab2acd
Коммит 463cee1200
11 изменённых файлов: 82 добавлений и 72 удалений

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

@ -15,7 +15,7 @@ using namespace mozilla::a11y;
IMPL_IUNKNOWN_QUERY_HEAD(ChildrenEnumVariant)
IMPL_IUNKNOWN_QUERY_IFACE(IEnumVARIANT)
IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mAnchorAcc)
IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mAnchorMsaa)
STDMETHODIMP
ChildrenEnumVariant::Next(ULONG aCount, VARIANT FAR* aItems,
@ -24,7 +24,8 @@ ChildrenEnumVariant::Next(ULONG aCount, VARIANT FAR* aItems,
*aCountFetched = 0;
if (mAnchorAcc->IsDefunct() || mAnchorAcc->LocalChildAt(mCurIndex) != mCurAcc)
AccessibleWrap* anchor = mAnchorMsaa->LocalAcc();
if (!anchor || anchor->LocalChildAt(mCurIndex) != mCurAcc)
return CO_E_OBJNOTCONNECTED;
ULONG countFetched = 0;
@ -34,7 +35,7 @@ ChildrenEnumVariant::Next(ULONG aCount, VARIANT FAR* aItems,
IDispatch* accNative = MsaaAccessible::NativeAccessible(mCurAcc);
++mCurIndex;
mCurAcc = mAnchorAcc->LocalChildAt(mCurIndex);
mCurAcc = anchor->LocalChildAt(mCurIndex);
// Don't output the accessible and count it as having been fetched unless
// it is non-null
@ -55,21 +56,23 @@ ChildrenEnumVariant::Next(ULONG aCount, VARIANT FAR* aItems,
STDMETHODIMP
ChildrenEnumVariant::Skip(ULONG aCount) {
if (mAnchorAcc->IsDefunct() || mAnchorAcc->LocalChildAt(mCurIndex) != mCurAcc)
AccessibleWrap* anchor = mAnchorMsaa->LocalAcc();
if (!anchor || anchor->LocalChildAt(mCurIndex) != mCurAcc)
return CO_E_OBJNOTCONNECTED;
mCurIndex += aCount;
mCurAcc = mAnchorAcc->LocalChildAt(mCurIndex);
mCurAcc = anchor->LocalChildAt(mCurIndex);
return mCurAcc ? S_OK : S_FALSE;
}
STDMETHODIMP
ChildrenEnumVariant::Reset() {
if (mAnchorAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED;
AccessibleWrap* anchor = mAnchorMsaa->LocalAcc();
if (!anchor) return CO_E_OBJNOTCONNECTED;
mCurIndex = 0;
mCurAcc = mAnchorAcc->LocalChildAt(0);
mCurAcc = anchor->LocalChildAt(0);
return S_OK;
}

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

@ -7,8 +7,8 @@
#ifndef mozilla_a11y_EnumVariant_h__
#define mozilla_a11y_EnumVariant_h__
#include "AccessibleWrap.h"
#include "IUnknownImpl.h"
#include "MsaaAccessible.h"
namespace mozilla {
namespace a11y {
@ -18,9 +18,9 @@ namespace a11y {
*/
class ChildrenEnumVariant final : public IEnumVARIANT {
public:
explicit ChildrenEnumVariant(AccessibleWrap* aAnchor)
: mAnchorAcc(aAnchor),
mCurAcc(mAnchorAcc->LocalChildAt(0)),
explicit ChildrenEnumVariant(MsaaAccessible* aAnchor)
: mAnchorMsaa(aAnchor),
mCurAcc(mAnchorMsaa->LocalAcc()->LocalChildAt(0)),
mCurIndex(0) {}
// IUnknown
@ -45,13 +45,13 @@ class ChildrenEnumVariant final : public IEnumVARIANT {
ChildrenEnumVariant& operator=(const ChildrenEnumVariant&) = delete;
ChildrenEnumVariant(const ChildrenEnumVariant& aEnumVariant)
: mAnchorAcc(aEnumVariant.mAnchorAcc),
: mAnchorMsaa(aEnumVariant.mAnchorMsaa),
mCurAcc(aEnumVariant.mCurAcc),
mCurIndex(aEnumVariant.mCurIndex) {}
virtual ~ChildrenEnumVariant() {}
protected:
RefPtr<AccessibleWrap> mAnchorAcc;
RefPtr<MsaaAccessible> mAnchorMsaa;
LocalAccessible* mCurAcc;
uint32_t mCurIndex;
};

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

@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AccessibleWrap.h"
#include "GeckoCustom.h"
using namespace mozilla;
@ -11,18 +12,18 @@ using namespace mozilla::a11y;
IMPL_IUNKNOWN_QUERY_HEAD(GeckoCustom)
IMPL_IUNKNOWN_QUERY_IFACE(IGeckoCustom)
IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mAcc)
IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mMsaa)
HRESULT
GeckoCustom::get_anchorCount(long* aCount) {
*aCount = mAcc->AnchorCount();
*aCount = mMsaa->LocalAcc()->AnchorCount();
return S_OK;
}
HRESULT
GeckoCustom::get_boundsInCSSPixels(int32_t* aX, int32_t* aY, int32_t* aWidth,
int32_t* aHeight) {
nsIntRect bounds = mAcc->BoundsInCSSPixels();
nsIntRect bounds = mMsaa->LocalAcc()->BoundsInCSSPixels();
if (!bounds.IsEmpty()) {
*aWidth = bounds.Width();
*aHeight = bounds.Height();
@ -37,7 +38,7 @@ GeckoCustom::get_boundsInCSSPixels(int32_t* aX, int32_t* aY, int32_t* aWidth,
HRESULT
GeckoCustom::get_DOMNodeID(BSTR* aID) {
nsIContent* content = mAcc->GetContent();
nsIContent* content = mMsaa->LocalAcc()->GetContent();
if (!content) {
return S_OK;
}
@ -53,18 +54,19 @@ GeckoCustom::get_DOMNodeID(BSTR* aID) {
STDMETHODIMP
GeckoCustom::get_ID(uint64_t* aID) {
*aID = mAcc->IsDoc() ? 0 : reinterpret_cast<uintptr_t>(mAcc.get());
AccessibleWrap* acc = mMsaa->LocalAcc();
*aID = acc->IsDoc() ? 0 : reinterpret_cast<uintptr_t>(acc);
return S_OK;
}
STDMETHODIMP
GeckoCustom::get_minimumIncrement(double* aIncrement) {
*aIncrement = mAcc->Step();
*aIncrement = mMsaa->LocalAcc()->Step();
return S_OK;
}
STDMETHODIMP
GeckoCustom::get_mozState(uint64_t* aState) {
*aState = mAcc->State();
*aState = mMsaa->LocalAcc()->State();
return S_OK;
}

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

@ -7,9 +7,9 @@
#ifndef mozilla_a11y_GeckoCustom_h_
#define mozilla_a11y_GeckoCustom_h_
#include "AccessibleWrap.h"
#include "IUnknownImpl.h"
#include "IGeckoCustom.h"
#include "MsaaAccessible.h"
namespace mozilla {
namespace a11y {
@ -20,7 +20,7 @@ namespace a11y {
*/
class GeckoCustom final : public IGeckoCustom {
public:
explicit GeckoCustom(AccessibleWrap* aAcc) : mAcc(aAcc) {}
explicit GeckoCustom(MsaaAccessible* aMsaa) : mMsaa(aMsaa) {}
// IUnknown
DECL_IUNKNOWN
@ -43,7 +43,7 @@ class GeckoCustom final : public IGeckoCustom {
~GeckoCustom() {}
protected:
RefPtr<AccessibleWrap> mAcc;
RefPtr<MsaaAccessible> mMsaa;
};
} // namespace a11y

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

@ -19,9 +19,9 @@ inline DocAccessible* sdnAccessible::GetDocument() const {
return GetExistingDocAccessible(mNode->OwnerDoc());
}
inline AccessibleWrap* sdnAccessible::GetAccessible() {
if (mWrap) {
return mWrap;
inline MsaaAccessible* sdnAccessible::GetMsaa() {
if (mMsaa) {
return mMsaa;
}
DocAccessible* document = GetDocument();
@ -31,9 +31,10 @@ inline AccessibleWrap* sdnAccessible::GetAccessible() {
// Once we have an accessible, we should hold a reference to it so that we
// may preserve object identity.
mWrap = static_cast<AccessibleWrap*>(
AccessibleWrap* wrap = static_cast<AccessibleWrap*>(
document->GetAccessibleEvenIfNotInMap(mNode));
return mWrap;
wrap->GetNativeInterface(getter_AddRefs(mMsaa));
return mMsaa;
}
} // namespace a11y

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

@ -52,7 +52,7 @@ sdnAccessible::QueryInterface(REFIID aREFIID, void** aInstancePtr) {
return S_OK;
}
AccessibleWrap* accessible = GetAccessible();
MsaaAccessible* accessible = GetMsaa();
if (accessible) return accessible->QueryInterface(aREFIID, aInstancePtr);
// IUnknown* is the canonical one if and only if this accessible doesn't have
@ -105,9 +105,9 @@ sdnAccessible::get_nodeInfo(BSTR __RPC_FAR* aNodeName,
// application can compare this to the childID we return for events such as
// focus events, to correlate back to data nodes in their internal object
// model.
AccessibleWrap* accessible = GetAccessible();
MsaaAccessible* accessible = GetMsaa();
if (accessible) {
*aUniqueID = MsaaAccessible::GetChildIDFor(accessible);
*aUniqueID = MsaaAccessible::GetChildIDFor(accessible->LocalAcc());
} else {
if (mUniqueId.isNothing()) {
MsaaAccessible::AssignChildIDTo(WrapNotNull(this));

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

@ -10,6 +10,7 @@
#include "ISimpleDOM.h"
#include "AccessibleWrap.h"
#include "IUnknownImpl.h"
#include "MsaaAccessible.h"
#include "mozilla/Attributes.h"
#include "mozilla/Maybe.h"
@ -24,8 +25,8 @@ class sdnAccessible final : public ISimpleDOMNode {
if (!mNode) MOZ_CRASH();
}
explicit sdnAccessible(NotNull<AccessibleWrap*> aAccWrap)
: mNode(aAccWrap->GetNode()), mWrap(aAccWrap) {}
explicit sdnAccessible(NotNull<MsaaAccessible*> aMsaa)
: mNode(aMsaa->LocalAcc()->GetNode()), mMsaa(aMsaa) {}
~sdnAccessible();
@ -40,9 +41,9 @@ class sdnAccessible final : public ISimpleDOMNode {
DocAccessible* GetDocument() const;
/*
* Return associated accessible if any.
* Return associated MsaaAccessible if any.
*/
AccessibleWrap* GetAccessible();
MsaaAccessible* GetMsaa();
void SetUniqueID(uint32_t aNewUniqueId) { mUniqueId = Some(aNewUniqueId); }
@ -122,7 +123,7 @@ class sdnAccessible final : public ISimpleDOMNode {
private:
nsCOMPtr<nsINode> mNode;
RefPtr<AccessibleWrap> mWrap;
RefPtr<MsaaAccessible> mMsaa;
Maybe<uint32_t> mUniqueId;
};

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

@ -20,17 +20,18 @@ using namespace mozilla::a11y;
IMPL_IUNKNOWN_QUERY_HEAD(sdnDocAccessible)
IMPL_IUNKNOWN_QUERY_IFACE(ISimpleDOMDocument)
IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mAccessible)
IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mMsaa)
STDMETHODIMP
sdnDocAccessible::get_URL(BSTR __RPC_FAR* aURL) {
if (!aURL) return E_INVALIDARG;
*aURL = nullptr;
if (mAccessible->IsDefunct()) return CO_E_OBJNOTCONNECTED;
DocAccessible* acc = mMsaa->DocAcc();
if (!acc) return CO_E_OBJNOTCONNECTED;
nsAutoString URL;
mAccessible->URL(URL);
acc->URL(URL);
if (URL.IsEmpty()) return S_FALSE;
*aURL = ::SysAllocStringLen(URL.get(), URL.Length());
@ -42,10 +43,11 @@ sdnDocAccessible::get_title(BSTR __RPC_FAR* aTitle) {
if (!aTitle) return E_INVALIDARG;
*aTitle = nullptr;
if (mAccessible->IsDefunct()) return CO_E_OBJNOTCONNECTED;
DocAccessible* acc = mMsaa->DocAcc();
if (!acc) return CO_E_OBJNOTCONNECTED;
nsAutoString title;
mAccessible->Title(title);
acc->Title(title);
*aTitle = ::SysAllocStringLen(title.get(), title.Length());
return *aTitle ? S_OK : E_OUTOFMEMORY;
}
@ -55,10 +57,11 @@ sdnDocAccessible::get_mimeType(BSTR __RPC_FAR* aMimeType) {
if (!aMimeType) return E_INVALIDARG;
*aMimeType = nullptr;
if (mAccessible->IsDefunct()) return CO_E_OBJNOTCONNECTED;
DocAccessible* acc = mMsaa->DocAcc();
if (!acc) return CO_E_OBJNOTCONNECTED;
nsAutoString mimeType;
mAccessible->MimeType(mimeType);
acc->MimeType(mimeType);
if (mimeType.IsEmpty()) return S_FALSE;
*aMimeType = ::SysAllocStringLen(mimeType.get(), mimeType.Length());
@ -70,10 +73,11 @@ sdnDocAccessible::get_docType(BSTR __RPC_FAR* aDocType) {
if (!aDocType) return E_INVALIDARG;
*aDocType = nullptr;
if (mAccessible->IsDefunct()) return CO_E_OBJNOTCONNECTED;
DocAccessible* acc = mMsaa->DocAcc();
if (!acc) return CO_E_OBJNOTCONNECTED;
nsAutoString docType;
mAccessible->DocType(docType);
acc->DocType(docType);
if (docType.IsEmpty()) return S_FALSE;
*aDocType = ::SysAllocStringLen(docType.get(), docType.Length());
@ -86,7 +90,7 @@ sdnDocAccessible::get_nameSpaceURIForID(short aNameSpaceID,
if (!aNameSpaceURI) return E_INVALIDARG;
*aNameSpaceURI = nullptr;
if (mAccessible->IsDefunct()) return CO_E_OBJNOTCONNECTED;
if (!mMsaa->DocAcc()) return CO_E_OBJNOTCONNECTED;
if (aNameSpaceID < 0) return E_INVALIDARG; // -1 is kNameSpaceID_Unknown
@ -109,5 +113,5 @@ sdnDocAccessible::put_alternateViewMediaTypes(
if (!aCommaSeparatedMediaTypes) return E_INVALIDARG;
*aCommaSeparatedMediaTypes = nullptr;
return mAccessible->IsDefunct() ? CO_E_OBJNOTCONNECTED : E_NOTIMPL;
return !mMsaa->DocAcc() ? CO_E_OBJNOTCONNECTED : E_NOTIMPL;
}

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

@ -10,15 +10,14 @@
#include "ISimpleDOM.h"
#include "IUnknownImpl.h"
#include "DocAccessibleWrap.h"
#include "MsaaDocAccessible.h"
namespace mozilla {
namespace a11y {
class sdnDocAccessible final : public ISimpleDOMDocument {
public:
explicit sdnDocAccessible(DocAccessibleWrap* aAccessible)
: mAccessible(aAccessible){};
explicit sdnDocAccessible(MsaaDocAccessible* aMsaa) : mMsaa(aMsaa){};
~sdnDocAccessible(){};
DECL_IUNKNOWN
@ -44,7 +43,7 @@ class sdnDocAccessible final : public ISimpleDOMDocument {
/* [in] */ BSTR __RPC_FAR* commaSeparatedMediaTypes);
protected:
RefPtr<DocAccessibleWrap> mAccessible;
RefPtr<MsaaDocAccessible> mMsaa;
};
} // namespace a11y

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

@ -28,18 +28,19 @@ using namespace mozilla::a11y;
IMPL_IUNKNOWN_QUERY_HEAD(sdnTextAccessible)
IMPL_IUNKNOWN_QUERY_IFACE(ISimpleDOMText)
IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mAccessible)
IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mMsaa)
STDMETHODIMP
sdnTextAccessible::get_domText(BSTR __RPC_FAR* aText) {
if (!aText) return E_INVALIDARG;
*aText = nullptr;
if (mAccessible->IsDefunct()) return CO_E_OBJNOTCONNECTED;
AccessibleWrap* acc = mMsaa->LocalAcc();
if (!acc) return CO_E_OBJNOTCONNECTED;
nsAutoString nodeValue;
mAccessible->GetContent()->GetNodeValue(nodeValue);
acc->GetContent()->GetNodeValue(nodeValue);
if (nodeValue.IsEmpty()) return S_FALSE;
*aText = ::SysAllocStringLen(nodeValue.get(), nodeValue.Length());
@ -55,7 +56,7 @@ sdnTextAccessible::get_clippedSubstringBounds(
&width, &height);
if (FAILED(rv)) return rv;
DocAccessible* document = mAccessible->Document();
DocAccessible* document = mMsaa->LocalAcc()->Document();
NS_ASSERTION(
document,
"There must always be a doc accessible, but there isn't. Crash!");
@ -80,9 +81,10 @@ sdnTextAccessible::get_unclippedSubstringBounds(
if (!aX || !aY || !aWidth || !aHeight) return E_INVALIDARG;
*aX = *aY = *aWidth = *aHeight = 0;
if (mAccessible->IsDefunct()) return CO_E_OBJNOTCONNECTED;
AccessibleWrap* acc = mMsaa->LocalAcc();
if (!acc) return CO_E_OBJNOTCONNECTED;
nsIFrame* frame = mAccessible->GetFrame();
nsIFrame* frame = acc->GetFrame();
NS_ENSURE_TRUE(frame, E_FAIL);
nsPoint startPoint, endPoint;
@ -103,7 +105,7 @@ sdnTextAccessible::get_unclippedSubstringBounds(
sum.UnionRect(sum, rect);
}
nsPresContext* presContext = mAccessible->Document()->PresContext();
nsPresContext* presContext = acc->Document()->PresContext();
*aX = presContext->AppUnitsToDevPixels(sum.X());
*aY = presContext->AppUnitsToDevPixels(sum.Y());
*aWidth = presContext->AppUnitsToDevPixels(sum.Width());
@ -115,18 +117,16 @@ sdnTextAccessible::get_unclippedSubstringBounds(
STDMETHODIMP
sdnTextAccessible::scrollToSubstring(unsigned int aStartIndex,
unsigned int aEndIndex) {
if (mAccessible->IsDefunct()) return CO_E_OBJNOTCONNECTED;
AccessibleWrap* acc = mMsaa->LocalAcc();
if (!acc) return CO_E_OBJNOTCONNECTED;
RefPtr<nsRange> range = nsRange::Create(mAccessible->GetContent());
if (NS_FAILED(range->SetStart(mAccessible->GetContent(), aStartIndex)))
return E_FAIL;
RefPtr<nsRange> range = nsRange::Create(acc->GetContent());
if (NS_FAILED(range->SetStart(acc->GetContent(), aStartIndex))) return E_FAIL;
if (NS_FAILED(range->SetEnd(mAccessible->GetContent(), aEndIndex)))
return E_FAIL;
if (NS_FAILED(range->SetEnd(acc->GetContent(), aEndIndex))) return E_FAIL;
nsresult rv = nsCoreUtils::ScrollSubstringTo(
mAccessible->GetFrame(), range,
nsIAccessibleScrollType::SCROLL_TYPE_ANYWHERE);
acc->GetFrame(), range, nsIAccessibleScrollType::SCROLL_TYPE_ANYWHERE);
return GetHRESULT(rv);
}
@ -135,9 +135,10 @@ sdnTextAccessible::get_fontFamily(BSTR __RPC_FAR* aFontFamily) {
if (!aFontFamily) return E_INVALIDARG;
*aFontFamily = nullptr;
if (mAccessible->IsDefunct()) return CO_E_OBJNOTCONNECTED;
AccessibleWrap* acc = mMsaa->LocalAcc();
if (!acc) return CO_E_OBJNOTCONNECTED;
nsIFrame* frame = mAccessible->GetFrame();
nsIFrame* frame = acc->GetFrame();
if (!frame) return E_FAIL;
RefPtr<nsFontMetrics> fm = nsLayoutUtils::GetFontMetricsForFrame(frame, 1.0f);

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

@ -10,7 +10,7 @@
#include "ISimpleDOM.h"
#include "IUnknownImpl.h"
#include "AccessibleWrap.h"
#include "MsaaAccessible.h"
class nsIFrame;
struct nsPoint;
@ -20,8 +20,7 @@ namespace a11y {
class sdnTextAccessible final : public ISimpleDOMText {
public:
explicit sdnTextAccessible(AccessibleWrap* aAccessible)
: mAccessible(aAccessible){};
explicit sdnTextAccessible(MsaaAccessible* aMsaa) : mMsaa(aMsaa){};
~sdnTextAccessible() {}
DECL_IUNKNOWN
@ -61,7 +60,7 @@ class sdnTextAccessible final : public ISimpleDOMText {
nsIFrame* GetPointFromOffset(nsIFrame* aContainingFrame, int32_t aOffset,
bool aPreferNext, nsPoint& aOutPoint);
RefPtr<AccessibleWrap> mAccessible;
RefPtr<MsaaAccessible> mMsaa;
};
} // namespace a11y