Bug 1754360: Move EndOffset to base Accessible. r=eeejay

Similar to StartOffset:

1. There was a Windows non-cached RemoteAccessible implementation, but it was never actually called, so I removed it.
2. The sync IPDL RemoteAccessible implementation previously provided a boolean indicating success.
    I removed this because the LocalAccessible implementation doesn't have this and it doesn't seem like remote is special in this respect.

Differential Revision: https://phabricator.services.mozilla.com/D138243
This commit is contained in:
James Teh 2022-02-11 02:37:13 +00:00
parent 3934c7d529
commit f5a04369df
13 changed files with 29 additions and 50 deletions

View File

@ -184,13 +184,7 @@ gint getEndIndexCB(AtkHyperlink* aLink) {
MaiHyperlink* maiLink = GetMaiHyperlink(aLink);
if (!maiLink) return false;
if (LocalAccessible* hyperlink = maiLink->GetAccHyperlink()) {
return static_cast<gint>(hyperlink->EndOffset());
}
bool valid = false;
uint32_t endIdx = maiLink->Proxy()->EndOffset(&valid);
return valid ? static_cast<gint>(endIdx) : -1;
return static_cast<gint>(maiLink->Acc()->EndOffset());
}
gint getStartIndexCB(AtkHyperlink* aLink) {

View File

@ -82,6 +82,14 @@ uint32_t Accessible::StartOffset() {
return hyperText ? hyperText->GetChildOffset(this) : 0;
}
uint32_t Accessible::EndOffset() {
MOZ_ASSERT(IsLink(), "EndOffset is called on not hyper link!");
Accessible* parent = Parent();
HyperTextAccessibleBase* hyperText =
parent ? parent->AsHyperTextBase() : nullptr;
return hyperText ? (hyperText->GetChildOffset(this) + 1) : 0;
}
GroupPos Accessible::GroupPosition() {
GroupPos groupPos;

View File

@ -187,6 +187,12 @@ class Accessible {
*/
virtual uint32_t StartOffset();
/**
* Return the end offset of the link within the parent
* HyperTextAccessibleBase.
*/
virtual uint32_t EndOffset();
/**
* Return object attributes for the accessible.
*/

View File

@ -2732,13 +2732,6 @@ bool LocalAccessible::IsLink() const {
return mParent && mParent->IsHyperText() && !IsText();
}
uint32_t LocalAccessible::EndOffset() {
MOZ_ASSERT(IsLink(), "EndOffset is called on not hyper link!");
HyperTextAccessible* hyperText = mParent ? mParent->AsHyperText() : nullptr;
return hyperText ? (hyperText->GetChildOffset(this) + 1) : 0;
}
uint32_t LocalAccessible::AnchorCount() {
MOZ_ASSERT(IsLink(), "AnchorCount is called on not hyper link!");
return 1;

View File

@ -531,11 +531,6 @@ class LocalAccessible : public nsISupports, public Accessible {
*/
virtual bool IsLink() const override;
/**
* Return the end offset of the link within the parent accessible.
*/
virtual uint32_t EndOffset();
/**
* Return true if the link is valid (e. g. points to a valid URL).
*/

View File

@ -139,8 +139,6 @@ LayoutDeviceIntPoint ImagePosition(uint32_t aCoordType);
LayoutDeviceIntSize ImageSize();
uint32_t EndOffset(bool* aOk);
bool IsLinkValid();
uint32_t AnchorCount(bool* aOk);

View File

@ -399,9 +399,13 @@ uint32_t RemoteAccessible::StartOffset() {
return retVal;
}
uint32_t RemoteAccessible::EndOffset(bool* aOk) {
uint32_t RemoteAccessible::EndOffset() {
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
return RemoteAccessibleBase<RemoteAccessible>::EndOffset();
}
bool ok;
uint32_t retVal = 0;
Unused << mDoc->SendEndOffset(mID, &retVal, aOk);
Unused << mDoc->SendEndOffset(mID, &retVal, &ok);
return retVal;
}

View File

@ -42,6 +42,7 @@ class RemoteAccessible : public RemoteAccessibleBase<RemoteAccessible> {
virtual already_AddRefed<AccAttributes> DefaultTextAttributes() override;
virtual uint32_t StartOffset() override;
virtual uint32_t EndOffset() override;
virtual int32_t LinkIndexAtOffset(uint32_t aOffset) override;

View File

@ -730,18 +730,6 @@ void RemoteAccessible::ScrollSubstringToPoint(int32_t aStartOffset,
static_cast<long>(aX), static_cast<long>(aY));
}
uint32_t RemoteAccessible::EndOffset(bool* aOk) {
RefPtr<IAccessibleHyperlink> acc = QueryInterface<IAccessibleHyperlink>(this);
if (!acc) {
*aOk = false;
return 0;
}
long endOffset;
*aOk = SUCCEEDED(acc->get_endIndex(&endOffset));
return static_cast<uint32_t>(endOffset);
}
bool RemoteAccessible::IsLinkValid() {
RefPtr<IAccessibleHyperlink> acc = QueryInterface<IAccessibleHyperlink>(this);
if (!acc) {

View File

@ -166,10 +166,7 @@ bool GeckoTextMarker::operator<(const GeckoTextMarker& aPoint) const {
// We compare its end offset in aPoint.mContainer with aPoint.mOffset.
Accessible* child = parents1.ElementAt(pos1 - 1);
MOZ_ASSERT(child->Parent() == aPoint.mContainer);
bool unused;
uint32_t endOffset = child->IsRemote()
? child->AsRemote()->EndOffset(&unused)
: child->AsLocal()->EndOffset();
uint32_t endOffset = child->EndOffset();
return endOffset < static_cast<uint32_t>(aPoint.mOffset);
}

View File

@ -172,6 +172,7 @@ addAccessibleTask(
is(getAccessibleDOMNodeID(link), "link", "LinkAt 0 is the link");
is(container.getLinkIndex(link), 0, "getLinkIndex for link is 0");
is(link.startIndex, 1, "link's startIndex is 1");
is(link.endIndex, 2, "link's endIndex is 2");
is(container.getLinkIndexAtOffset(1), 0, "getLinkIndexAtOffset(1) is 0");
is(container.getLinkIndexAtOffset(0), -1, "getLinkIndexAtOffset(0) is -1");
},

View File

@ -137,7 +137,7 @@ ia2AccessibleHyperlink::get_endIndex(long* aIndex) {
*aIndex = 0;
LocalAccessible* thisObj = LocalAcc();
Accessible* thisObj = Acc();
if (!thisObj) {
return CO_E_OBJNOTCONNECTED;
}

View File

@ -38,20 +38,14 @@ xpcAccessibleHyperLink::GetEndIndex(int32_t* aEndIndex) {
if (!Intl()) return NS_ERROR_FAILURE;
if (Intl()->IsLocal()) {
*aEndIndex = Intl()->AsLocal()->EndOffset();
} else {
#if defined(XP_WIN)
if (Intl()->IsRemote() &&
!StaticPrefs::accessibility_cache_enabled_AtStartup()) {
return NS_ERROR_NOT_IMPLEMENTED;
#else
bool isIndexValid = false;
uint32_t endOffset = Intl()->AsRemote()->EndOffset(&isIndexValid);
if (!isIndexValid) return NS_ERROR_FAILURE;
*aEndIndex = endOffset;
#endif
}
#endif
*aEndIndex = static_cast<int32_t>(Intl()->EndOffset());
return NS_OK;
}