1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "InterfaceInitFuncs.h"
9 #include "LocalAccessible-inl.h"
10 #include "HyperTextAccessible.h"
12 #include "nsMaiHyperlink.h"
13 #include "RemoteAccessible.h"
14 #include "mozilla/Likely.h"
16 using namespace mozilla::a11y
;
20 static AtkHyperlink
* getLinkCB(AtkHypertext
* aText
, gint aLinkIndex
) {
21 if (Accessible
* acc
= GetInternalObj(ATK_OBJECT(aText
))) {
22 if (HyperTextAccessibleBase
* hyperText
= acc
->AsHyperTextBase()) {
23 Accessible
* linkAcc
= hyperText
->LinkAt(aLinkIndex
);
24 AtkObject
* atkHyperLink
= GetWrapperFor(linkAcc
);
25 NS_ENSURE_TRUE(IS_MAI_OBJECT(atkHyperLink
), nullptr);
26 return MAI_ATK_OBJECT(atkHyperLink
)->GetAtkHyperlink();
33 static gint
getLinkCountCB(AtkHypertext
* aText
) {
34 if (Accessible
* acc
= GetInternalObj(ATK_OBJECT(aText
))) {
35 if (HyperTextAccessibleBase
* hyperText
= acc
->AsHyperTextBase()) {
36 return static_cast<gint
>(hyperText
->LinkCount());
42 static gint
getLinkIndexCB(AtkHypertext
* aText
, gint aCharIndex
) {
43 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aText
));
47 HyperTextAccessibleBase
* hyperText
= acc
->AsHyperTextBase();
51 return hyperText
->LinkIndexAtOffset(aCharIndex
);
56 void hypertextInterfaceInitCB(AtkHypertextIface
* aIface
) {
57 NS_ASSERTION(aIface
, "no interface!");
58 if (MOZ_UNLIKELY(!aIface
)) return;
60 aIface
->get_link
= getLinkCB
;
61 aIface
->get_n_links
= getLinkCountCB
;
62 aIface
->get_link_index
= getLinkIndexCB
;