Bug 1146615 - IPC Proxy for HyperText, r=tbsaunde

This commit is contained in:
Olli Pettay 2015-03-25 16:05:18 +02:00
parent 8a5cab8850
commit d5a340e46b
6 changed files with 168 additions and 27 deletions

View File

@ -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)
return nullptr;
if (accWrap) {
HyperTextAccessible* hyperText = accWrap->AsHyperText();
NS_ENSURE_TRUE(hyperText, nullptr);
Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
if (!hyperLink)
if (!hyperLink) {
return nullptr;
}
AtkObject* hyperLinkAtkObj = AccessibleWrap::GetAtkObject(hyperLink);
AccessibleWrap* accChild = GetAccessibleWrap(hyperLinkAtkObj);
NS_ENSURE_TRUE(accChild, nullptr);
MaiHyperlink *maiHyperlink = accChild->GetMaiHyperlink();
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;
}
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();
}
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
return proxy->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);
return hyperText->LinkIndexAtOffset(aCharIndex);
}
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
return proxy->LinkIndexAtOffset(aCharIndex);
}
return -1;
}
}

View File

@ -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<uint64_t>(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;
}
}
}

View File

@ -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;

View File

@ -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);
};
}

View File

@ -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;
}
}
}

View File

@ -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.
*/