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