bug 1146518 - make atk hyper link impl support proxies r=surkov

This commit is contained in:
Trevor Saunders 2015-04-22 18:31:19 -04:00
Родитель ecbbd51e94
Коммит 1266c7fcf4
2 изменённых файлов: 74 добавлений и 33 удалений

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

@ -6,6 +6,7 @@
#include "nsIURI.h" #include "nsIURI.h"
#include "nsMaiHyperlink.h" #include "nsMaiHyperlink.h"
#include "mozilla/a11y/ProxyAccessible.h"
using namespace mozilla::a11y; using namespace mozilla::a11y;
@ -61,8 +62,17 @@ static gint getAnchorCountCB(AtkHyperlink *aLink);
G_END_DECLS G_END_DECLS
static gpointer parent_class = nullptr; static gpointer parent_class = nullptr;
static Accessible*
get_accessible_hyperlink(AtkHyperlink *aHyperlink); static MaiHyperlink*
GetMaiHyperlink(AtkHyperlink *aHyperlink)
{
NS_ENSURE_TRUE(MAI_IS_ATK_HYPERLINK(aHyperlink), nullptr);
MaiHyperlink * maiHyperlink =
MAI_ATK_HYPERLINK(aHyperlink)->maiHyperlink;
NS_ENSURE_TRUE(maiHyperlink != nullptr, nullptr);
NS_ENSURE_TRUE(maiHyperlink->GetAtkHyperlink() == aHyperlink, nullptr);
return maiHyperlink;
}
GType GType
mai_atk_hyperlink_get_type(void) mai_atk_hyperlink_get_type(void)
@ -150,79 +160,102 @@ finalizeCB(GObject *aObj)
gchar * gchar *
getUriCB(AtkHyperlink *aLink, gint aLinkIndex) getUriCB(AtkHyperlink *aLink, gint aLinkIndex)
{ {
Accessible* hyperlink = get_accessible_hyperlink(aLink); MaiHyperlink* maiLink = GetMaiHyperlink(aLink);
NS_ENSURE_TRUE(hyperlink, nullptr); if (!maiLink)
return nullptr;
nsAutoCString cautoStr;
if (Accessible* hyperlink = maiLink->GetAccHyperlink()) {
nsCOMPtr<nsIURI> uri = hyperlink->AnchorURIAt(aLinkIndex); nsCOMPtr<nsIURI> uri = hyperlink->AnchorURIAt(aLinkIndex);
if (!uri) if (!uri)
return nullptr; return nullptr;
nsAutoCString cautoStr;
nsresult rv = uri->GetSpec(cautoStr); nsresult rv = uri->GetSpec(cautoStr);
NS_ENSURE_SUCCESS(rv, nullptr); NS_ENSURE_SUCCESS(rv, nullptr);
return g_strdup(cautoStr.get()); return g_strdup(cautoStr.get());
}
bool valid;
maiLink->Proxy()->AnchorURIAt(aLinkIndex, cautoStr, &valid);
if (!valid)
return nullptr;
return g_strdup(cautoStr.get());
} }
AtkObject * AtkObject *
getObjectCB(AtkHyperlink *aLink, gint aLinkIndex) getObjectCB(AtkHyperlink *aLink, gint aLinkIndex)
{ {
Accessible* hyperlink = get_accessible_hyperlink(aLink); MaiHyperlink* maiLink = GetMaiHyperlink(aLink);
NS_ENSURE_TRUE(hyperlink, nullptr); if (!maiLink)
return nullptr;
Accessible* anchor = hyperlink->AnchorAt(aLinkIndex); if (Accessible* hyperlink = maiLink->GetAccHyperlink()) {
NS_ENSURE_TRUE(anchor, nullptr); Accessible* anchor = hyperlink->AnchorAt(aLinkIndex);
NS_ENSURE_TRUE(anchor, nullptr);
AtkObject* atkObj = AccessibleWrap::GetAtkObject(anchor); return AccessibleWrap::GetAtkObject(anchor);
//no need to add ref it, because it is "get" not "ref" }
return atkObj;
ProxyAccessible* anchor = maiLink->Proxy()->AnchorAt(aLinkIndex);
return anchor ? GetWrapperFor(anchor) : nullptr;
} }
gint gint
getEndIndexCB(AtkHyperlink *aLink) getEndIndexCB(AtkHyperlink *aLink)
{ {
Accessible* hyperlink = get_accessible_hyperlink(aLink); MaiHyperlink* maiLink = GetMaiHyperlink(aLink);
NS_ENSURE_TRUE(hyperlink, -1); if (!maiLink)
return false;
if (Accessible* hyperlink = maiLink->GetAccHyperlink())
return static_cast<gint>(hyperlink->EndOffset()); return static_cast<gint>(hyperlink->EndOffset());
bool valid = false;
uint32_t endIdx = maiLink->Proxy()->EndOffset(&valid);
return valid ? static_cast<gint>(endIdx) : -1;
} }
gint gint
getStartIndexCB(AtkHyperlink *aLink) getStartIndexCB(AtkHyperlink *aLink)
{ {
Accessible* hyperlink = get_accessible_hyperlink(aLink); MaiHyperlink* maiLink = GetMaiHyperlink(aLink);
NS_ENSURE_TRUE(hyperlink, -1); if (maiLink)
return -1;
if (Accessible* hyperlink = maiLink->GetAccHyperlink())
return static_cast<gint>(hyperlink->StartOffset()); return static_cast<gint>(hyperlink->StartOffset());
bool valid = false;
uint32_t startIdx = maiLink->Proxy()->StartOffset(&valid);
return valid ? static_cast<gint>(startIdx) : -1;
} }
gboolean gboolean
isValidCB(AtkHyperlink *aLink) isValidCB(AtkHyperlink *aLink)
{ {
Accessible* hyperlink = get_accessible_hyperlink(aLink); MaiHyperlink* maiLink = GetMaiHyperlink(aLink);
NS_ENSURE_TRUE(hyperlink, FALSE); if (!maiLink)
return false;
if (Accessible* hyperlink = maiLink->GetAccHyperlink())
return static_cast<gboolean>(hyperlink->IsLinkValid()); return static_cast<gboolean>(hyperlink->IsLinkValid());
return static_cast<gboolean>(maiLink->Proxy()->IsLinkValid());
} }
gint gint
getAnchorCountCB(AtkHyperlink *aLink) getAnchorCountCB(AtkHyperlink *aLink)
{ {
Accessible* hyperlink = get_accessible_hyperlink(aLink); MaiHyperlink* maiLink = GetMaiHyperlink(aLink);
NS_ENSURE_TRUE(hyperlink, -1); if (!maiLink)
return -1;
if (Accessible* hyperlink = maiLink->GetAccHyperlink())
return static_cast<gint>(hyperlink->AnchorCount()); return static_cast<gint>(hyperlink->AnchorCount());
}
// Check if aHyperlink is a valid MaiHyperlink, and return the bool valid = false;
// HyperLinkAccessible related. uint32_t anchorCount = maiLink->Proxy()->AnchorCount(&valid);
Accessible* return valid ? static_cast<gint>(anchorCount) : -1;
get_accessible_hyperlink(AtkHyperlink *aHyperlink)
{
NS_ENSURE_TRUE(MAI_IS_ATK_HYPERLINK(aHyperlink), nullptr);
MaiHyperlink * maiHyperlink =
MAI_ATK_HYPERLINK(aHyperlink)->maiHyperlink;
NS_ENSURE_TRUE(maiHyperlink != nullptr, nullptr);
NS_ENSURE_TRUE(maiHyperlink->GetAtkHyperlink() == aHyperlink, nullptr);
return maiHyperlink->GetAccHyperlink();
} }

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

@ -38,6 +38,14 @@ public:
return link; return link;
} }
ProxyAccessible* Proxy() const
{
if (!(mHyperlink & IS_PROXY))
return nullptr;
return reinterpret_cast<ProxyAccessible*>(mHyperlink & ~IS_PROXY);
}
protected: protected:
uintptr_t mHyperlink; uintptr_t mHyperlink;
AtkHyperlink* mMaiAtkHyperlink; AtkHyperlink* mMaiAtkHyperlink;