From 2e6e9c03f26c428fbfa7e1a7c1438cc9c1bef79c Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Wed, 25 Mar 2015 16:05:18 +0200 Subject: [PATCH] Bug 1146615 - IPC Proxy for HyperText, r=tbsaunde --- accessible/atk/nsMaiInterfaceHypertext.cpp | 72 ++++++++++++++-------- accessible/ipc/DocAccessibleChild.cpp | 57 ++++++++++++++++- accessible/ipc/DocAccessibleChild.h | 16 +++++ accessible/ipc/PDocAccessible.ipdl | 6 ++ accessible/ipc/ProxyAccessible.cpp | 36 +++++++++++ accessible/ipc/ProxyAccessible.h | 8 +++ 6 files changed, 168 insertions(+), 27 deletions(-) diff --git a/accessible/atk/nsMaiInterfaceHypertext.cpp b/accessible/atk/nsMaiInterfaceHypertext.cpp index 7baa58cf1fb..bf9bd67d027 100644 --- a/accessible/atk/nsMaiInterfaceHypertext.cpp +++ b/accessible/atk/nsMaiInterfaceHypertext.cpp @@ -10,8 +10,10 @@ #include "HyperTextAccessible.h" #include "nsMai.h" #include "nsMaiHyperlink.h" +#include "ProxyAccessible.h" #include "mozilla/Likely.h" + using namespace mozilla::a11y; extern "C" { @@ -20,49 +22,69 @@ static AtkHyperlink* getLinkCB(AtkHypertext *aText, gint aLinkIndex) { AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); - if (!accWrap) + if (accWrap) { + HyperTextAccessible* hyperText = accWrap->AsHyperText(); + NS_ENSURE_TRUE(hyperText, nullptr); + + Accessible* hyperLink = hyperText->LinkAt(aLinkIndex); + if (!hyperLink) { + return nullptr; + } + + AtkObject* hyperLinkAtkObj = AccessibleWrap::GetAtkObject(hyperLink); + AccessibleWrap* accChild = GetAccessibleWrap(hyperLinkAtkObj); + NS_ENSURE_TRUE(accChild, nullptr); + + MaiHyperlink* maiHyperlink = accChild->GetMaiHyperlink(); + NS_ENSURE_TRUE(maiHyperlink, nullptr); + return maiHyperlink->GetAtkHyperlink(); + } + + if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) { + ProxyAccessible* proxyLink = proxy->LinkAt(aLinkIndex); + if (proxyLink) { + NS_WARNING("IMPLEMENT ME! See bug 1146518."); + // We should somehow get from ProxyAccessible* to AtkHyperlink*. + } return nullptr; + } - HyperTextAccessible* hyperText = accWrap->AsHyperText(); - NS_ENSURE_TRUE(hyperText, nullptr); - - Accessible* hyperLink = hyperText->LinkAt(aLinkIndex); - if (!hyperLink) - return nullptr; - - AtkObject* hyperLinkAtkObj = AccessibleWrap::GetAtkObject(hyperLink); - AccessibleWrap* accChild = GetAccessibleWrap(hyperLinkAtkObj); - NS_ENSURE_TRUE(accChild, nullptr); - - MaiHyperlink *maiHyperlink = accChild->GetMaiHyperlink(); - NS_ENSURE_TRUE(maiHyperlink, nullptr); - return maiHyperlink->GetAtkHyperlink(); + return nullptr; } static gint getLinkCountCB(AtkHypertext *aText) { AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); - if (!accWrap) - return -1; + if (accWrap) { + HyperTextAccessible* hyperText = accWrap->AsHyperText(); + NS_ENSURE_TRUE(hyperText, -1); + return hyperText->LinkCount(); + } - HyperTextAccessible* hyperText = accWrap->AsHyperText(); - NS_ENSURE_TRUE(hyperText, -1); + if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) { + return proxy->LinkCount(); + } - return hyperText->LinkCount(); + return -1; } static gint getLinkIndexCB(AtkHypertext *aText, gint aCharIndex) { AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); - if (!accWrap) - return -1; + if (accWrap) { + HyperTextAccessible* hyperText = accWrap->AsHyperText(); + NS_ENSURE_TRUE(hyperText, -1); - HyperTextAccessible* hyperText = accWrap->AsHyperText(); - NS_ENSURE_TRUE(hyperText, -1); + return hyperText->LinkIndexAtOffset(aCharIndex); + } - return hyperText->LinkIndexAtOffset(aCharIndex); + if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) { + return proxy->LinkIndexAtOffset(aCharIndex); + } + + return -1; } } diff --git a/accessible/ipc/DocAccessibleChild.cpp b/accessible/ipc/DocAccessibleChild.cpp index 32ef7c66d45..56ebbcb37de 100644 --- a/accessible/ipc/DocAccessibleChild.cpp +++ b/accessible/ipc/DocAccessibleChild.cpp @@ -63,8 +63,7 @@ HyperTextAccessible* DocAccessibleChild::IdToHyperTextAccessible(const uint64_t& aID) const { Accessible* acc = IdToAccessible(aID); - MOZ_ASSERT(!acc || acc->IsHyperText()); - return acc ? acc->AsHyperText() : nullptr; + return acc && acc->IsHyperText() ? acc->AsHyperText() : nullptr; } ImageAccessible* @@ -729,5 +728,59 @@ DocAccessibleChild::RecvAnchorAt(const uint64_t& aID, return true; } +bool +DocAccessibleChild::RecvLinkCount(const uint64_t& aID, + uint32_t* aCount) +{ + HyperTextAccessible* acc = IdToHyperTextAccessible(aID); + *aCount = acc ? acc->LinkCount() : 0; + return true; +} + +bool +DocAccessibleChild::RecvLinkAt(const uint64_t& aID, + const uint32_t& aIndex, + uint64_t* aIDOfLink, + bool* aOk) +{ + *aIDOfLink = 0; + *aOk = false; + HyperTextAccessible* acc = IdToHyperTextAccessible(aID); + if (acc) { + Accessible* link = acc->LinkAt(aIndex); + if (link) { + *aIDOfLink = reinterpret_cast(link->UniqueID()); + *aOk = true; + } + } + + return true; +} + +bool +DocAccessibleChild::RecvLinkIndexOf(const uint64_t& aID, + const uint64_t& aLinkID, + int32_t* aIndex) +{ + HyperTextAccessible* acc = IdToHyperTextAccessible(aID); + Accessible* link = IdToAccessible(aLinkID); + *aIndex = -1; + if (acc && link) { + *aIndex = acc->LinkIndexOf(link); + } + + return true; +} + +bool +DocAccessibleChild::RecvLinkIndexAtOffset(const uint64_t& aID, + const uint32_t& aOffset, + int32_t* aIndex) +{ + HyperTextAccessible* acc = IdToHyperTextAccessible(aID); + *aIndex = acc ? acc->LinkIndexAtOffset(aOffset) : -1; + return true; +} + } } diff --git a/accessible/ipc/DocAccessibleChild.h b/accessible/ipc/DocAccessibleChild.h index 665b1385a28..441813263f6 100644 --- a/accessible/ipc/DocAccessibleChild.h +++ b/accessible/ipc/DocAccessibleChild.h @@ -208,6 +208,22 @@ public: uint64_t* aIDOfAnchor, bool* aOk) override; + virtual bool RecvLinkCount(const uint64_t& aID, + uint32_t* aCount) override; + + virtual bool RecvLinkAt(const uint64_t& aID, + const uint32_t& aIndex, + uint64_t* aIDOfLink, + bool* aOk) override; + + virtual bool RecvLinkIndexOf(const uint64_t& aID, + const uint64_t& aLinkID, + int32_t* aIndex) override; + + virtual bool RecvLinkIndexAtOffset(const uint64_t& aID, + const uint32_t& aOffset, + int32_t* aIndex) override; + private: Accessible* IdToAccessible(const uint64_t& aID) const; diff --git a/accessible/ipc/PDocAccessible.ipdl b/accessible/ipc/PDocAccessible.ipdl index 9e26f8e8ea5..22d5d029ee9 100644 --- a/accessible/ipc/PDocAccessible.ipdl +++ b/accessible/ipc/PDocAccessible.ipdl @@ -139,6 +139,12 @@ child: prio(high) sync AnchorCount(uint64_t aID) returns(uint32_t aRetVal, bool aOk); prio(high) sync AnchorURIAt(uint64_t aID, uint32_t aIndex) returns(nsCString aURI, bool aOk); prio(high) sync AnchorAt(uint64_t aID, uint32_t aIndex) returns(uint64_t aIDOfAnchor, bool aOk); + + prio(high) sync LinkCount(uint64_t aID) returns(uint32_t aCount); + prio(high) sync LinkAt(uint64_t aID, uint32_t aIndex) returns(uint64_t aIDOfLink, bool aOk); + prio(high) sync LinkIndexOf(uint64_t aID, uint64_t aLinkID) returns(int32_t aIndex); + prio(high) sync LinkIndexAtOffset(uint64_t aID, uint32_t aOffset) returns(int32_t aIndex); + }; } diff --git a/accessible/ipc/ProxyAccessible.cpp b/accessible/ipc/ProxyAccessible.cpp index 46ec4a801aa..45e5d0d0a6f 100644 --- a/accessible/ipc/ProxyAccessible.cpp +++ b/accessible/ipc/ProxyAccessible.cpp @@ -426,5 +426,41 @@ ProxyAccessible::AnchorAt(uint32_t aIndex) return ok ? mDoc->GetAccessible(id) : nullptr; } +uint32_t +ProxyAccessible::LinkCount() +{ + uint32_t retVal = 0; + unused << mDoc->SendLinkCount(mID, &retVal); + return retVal; +} + +ProxyAccessible* +ProxyAccessible::LinkAt(const uint32_t& aIndex) +{ + uint64_t linkID = 0; + bool ok = false; + unused << mDoc->SendLinkAt(mID, aIndex, &linkID, &ok); + return ok ? mDoc->GetAccessible(linkID) : nullptr; +} + +int32_t +ProxyAccessible::LinkIndexOf(ProxyAccessible* aLink) +{ + int32_t retVal = -1; + if (aLink) { + unused << mDoc->SendLinkIndexOf(mID, aLink->ID(), &retVal); + } + + return retVal; +} + +int32_t +ProxyAccessible::LinkIndexAtOffset(uint32_t aOffset) +{ + int32_t retVal = -1; + unused << mDoc->SendLinkIndexAtOffset(mID, aOffset, &retVal); + return retVal; +} + } } diff --git a/accessible/ipc/ProxyAccessible.h b/accessible/ipc/ProxyAccessible.h index 50ef1c80462..089c074944b 100644 --- a/accessible/ipc/ProxyAccessible.h +++ b/accessible/ipc/ProxyAccessible.h @@ -193,6 +193,14 @@ public: ProxyAccessible* AnchorAt(uint32_t aIndex); + uint32_t LinkCount(); + + ProxyAccessible* LinkAt(const uint32_t& aIndex); + + int32_t LinkIndexOf(ProxyAccessible* aLink); + + int32_t LinkIndexAtOffset(uint32_t aOffset); + /** * Allow the platform to store a pointers worth of data on us. */