2011-04-27 17:42:27 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-05-28 02:37:24 +04:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "InterfaceInitFuncs.h"
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-12-21 07:16:44 +04:00
|
|
|
#include "Accessible-inl.h"
|
2012-05-31 12:04:41 +04:00
|
|
|
#include "HyperTextAccessible.h"
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "nsMai.h"
|
|
|
|
#include "nsMaiHyperlink.h"
|
2015-03-25 17:05:18 +03:00
|
|
|
#include "ProxyAccessible.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-11-18 06:01:44 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
extern "C" {
|
2003-05-06 06:23:50 +04:00
|
|
|
|
|
|
|
static AtkHyperlink* getLinkCB(AtkHypertext* aText, gint aLinkIndex) {
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-04-22 01:30:35 +03:00
|
|
|
AtkObject* atkHyperLink = nullptr;
|
2015-03-25 17:05:18 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* hyperText = accWrap->AsHyperText();
|
|
|
|
NS_ENSURE_TRUE(hyperText, nullptr);
|
|
|
|
|
|
|
|
Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
|
2015-04-21 23:30:14 +03:00
|
|
|
if (!hyperLink || !hyperLink->IsLink()) {
|
2015-03-25 17:05:18 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-22 01:30:35 +03:00
|
|
|
atkHyperLink = AccessibleWrap::GetAtkObject(hyperLink);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
2015-03-25 17:05:18 +03:00
|
|
|
ProxyAccessible* proxyLink = proxy->LinkAt(aLinkIndex);
|
2015-04-22 01:30:35 +03:00
|
|
|
if (!proxyLink) return nullptr;
|
|
|
|
|
|
|
|
atkHyperLink = GetWrapperFor(proxyLink);
|
2015-03-25 17:05:18 +03:00
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-04-22 01:30:35 +03:00
|
|
|
NS_ENSURE_TRUE(IS_MAI_OBJECT(atkHyperLink), nullptr);
|
|
|
|
return MAI_ATK_OBJECT(atkHyperLink)->GetAtkHyperlink();
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint getLinkCountCB(AtkHypertext* aText) {
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-25 17:05:18 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* hyperText = accWrap->AsHyperText();
|
|
|
|
NS_ENSURE_TRUE(hyperText, -1);
|
|
|
|
return hyperText->LinkCount();
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-25 17:05:18 +03:00
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
return proxy->LinkCount();
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-25 17:05:18 +03:00
|
|
|
return -1;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint getLinkIndexCB(AtkHypertext* aText, gint aCharIndex) {
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-25 17:05:18 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* hyperText = accWrap->AsHyperText();
|
|
|
|
NS_ENSURE_TRUE(hyperText, -1);
|
|
|
|
|
|
|
|
return hyperText->LinkIndexAtOffset(aCharIndex);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-25 17:05:18 +03:00
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
return proxy->LinkIndexAtOffset(aCharIndex);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-25 17:05:18 +03:00
|
|
|
return -1;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
2012-03-20 08:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void hypertextInterfaceInitCB(AtkHypertextIface* aIface) {
|
|
|
|
NS_ASSERTION(aIface, "no interface!");
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(!aIface)) return;
|
2012-03-20 08:02:50 +04:00
|
|
|
|
|
|
|
aIface->get_link = getLinkCB;
|
|
|
|
aIface->get_n_links = getLinkCountCB;
|
|
|
|
aIface->get_link_index = getLinkIndexCB;
|
|
|
|
}
|