|
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/. */ |
|
6 |
|
7 #include "InterfaceInitFuncs.h" |
|
8 |
|
9 #include "Accessible-inl.h" |
|
10 #include "HyperTextAccessible.h" |
|
11 #include "nsMai.h" |
|
12 #include "nsMaiHyperlink.h" |
|
13 #include "mozilla/Likely.h" |
|
14 |
|
15 using namespace mozilla::a11y; |
|
16 |
|
17 extern "C" { |
|
18 |
|
19 static AtkHyperlink* |
|
20 getLinkCB(AtkHypertext *aText, gint aLinkIndex) |
|
21 { |
|
22 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
|
23 if (!accWrap) |
|
24 return nullptr; |
|
25 |
|
26 HyperTextAccessible* hyperText = accWrap->AsHyperText(); |
|
27 NS_ENSURE_TRUE(hyperText, nullptr); |
|
28 |
|
29 Accessible* hyperLink = hyperText->LinkAt(aLinkIndex); |
|
30 if (!hyperLink) |
|
31 return nullptr; |
|
32 |
|
33 AtkObject* hyperLinkAtkObj = AccessibleWrap::GetAtkObject(hyperLink); |
|
34 AccessibleWrap* accChild = GetAccessibleWrap(hyperLinkAtkObj); |
|
35 NS_ENSURE_TRUE(accChild, nullptr); |
|
36 |
|
37 MaiHyperlink *maiHyperlink = accChild->GetMaiHyperlink(); |
|
38 NS_ENSURE_TRUE(maiHyperlink, nullptr); |
|
39 return maiHyperlink->GetAtkHyperlink(); |
|
40 } |
|
41 |
|
42 static gint |
|
43 getLinkCountCB(AtkHypertext *aText) |
|
44 { |
|
45 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
|
46 if (!accWrap) |
|
47 return -1; |
|
48 |
|
49 HyperTextAccessible* hyperText = accWrap->AsHyperText(); |
|
50 NS_ENSURE_TRUE(hyperText, -1); |
|
51 |
|
52 return hyperText->LinkCount(); |
|
53 } |
|
54 |
|
55 static gint |
|
56 getLinkIndexCB(AtkHypertext *aText, gint aCharIndex) |
|
57 { |
|
58 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
|
59 if (!accWrap) |
|
60 return -1; |
|
61 |
|
62 HyperTextAccessible* hyperText = accWrap->AsHyperText(); |
|
63 NS_ENSURE_TRUE(hyperText, -1); |
|
64 |
|
65 return hyperText->LinkIndexAtOffset(aCharIndex); |
|
66 } |
|
67 } |
|
68 |
|
69 void |
|
70 hypertextInterfaceInitCB(AtkHypertextIface* aIface) |
|
71 { |
|
72 NS_ASSERTION(aIface, "no interface!"); |
|
73 if (MOZ_UNLIKELY(!aIface)) |
|
74 return; |
|
75 |
|
76 aIface->get_link = getLinkCB; |
|
77 aIface->get_n_links = getLinkCountCB; |
|
78 aIface->get_link_index = getLinkIndexCB; |
|
79 } |