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 "Accessible-inl.h"
10 #include "HyperTextAccessible.h"
12 #include "nsMaiHyperlink.h"
13 #include "mozilla/Likely.h"
15 using namespace mozilla::a11y
;
20 getLinkCB(AtkHypertext
*aText
, gint aLinkIndex
)
22 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aText
));
26 HyperTextAccessible
* hyperText
= accWrap
->AsHyperText();
27 NS_ENSURE_TRUE(hyperText
, nullptr);
29 Accessible
* hyperLink
= hyperText
->LinkAt(aLinkIndex
);
33 AtkObject
* hyperLinkAtkObj
= AccessibleWrap::GetAtkObject(hyperLink
);
34 AccessibleWrap
* accChild
= GetAccessibleWrap(hyperLinkAtkObj
);
35 NS_ENSURE_TRUE(accChild
, nullptr);
37 MaiHyperlink
*maiHyperlink
= accChild
->GetMaiHyperlink();
38 NS_ENSURE_TRUE(maiHyperlink
, nullptr);
39 return maiHyperlink
->GetAtkHyperlink();
43 getLinkCountCB(AtkHypertext
*aText
)
45 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aText
));
49 HyperTextAccessible
* hyperText
= accWrap
->AsHyperText();
50 NS_ENSURE_TRUE(hyperText
, -1);
52 return hyperText
->LinkCount();
56 getLinkIndexCB(AtkHypertext
*aText
, gint aCharIndex
)
58 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aText
));
62 HyperTextAccessible
* hyperText
= accWrap
->AsHyperText();
63 NS_ENSURE_TRUE(hyperText
, -1);
65 return hyperText
->LinkIndexAtOffset(aCharIndex
);
70 hypertextInterfaceInitCB(AtkHypertextIface
* aIface
)
72 NS_ASSERTION(aIface
, "no interface!");
73 if (MOZ_UNLIKELY(!aIface
))
76 aIface
->get_link
= getLinkCB
;
77 aIface
->get_n_links
= getLinkCountCB
;
78 aIface
->get_link_index
= getLinkIndexCB
;