Line data Source code
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 "ProxyAccessible.h"
14 : #include "mozilla/Likely.h"
15 :
16 :
17 : using namespace mozilla::a11y;
18 :
19 : extern "C" {
20 :
21 : static AtkHyperlink*
22 0 : getLinkCB(AtkHypertext *aText, gint aLinkIndex)
23 : {
24 0 : AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
25 0 : AtkObject* atkHyperLink = nullptr;
26 0 : if (accWrap) {
27 0 : HyperTextAccessible* hyperText = accWrap->AsHyperText();
28 0 : NS_ENSURE_TRUE(hyperText, nullptr);
29 :
30 0 : Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
31 0 : if (!hyperLink || !hyperLink->IsLink()) {
32 0 : return nullptr;
33 : }
34 :
35 0 : atkHyperLink = AccessibleWrap::GetAtkObject(hyperLink);
36 0 : } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
37 0 : ProxyAccessible* proxyLink = proxy->LinkAt(aLinkIndex);
38 0 : if (!proxyLink)
39 0 : return nullptr;
40 :
41 0 : atkHyperLink = GetWrapperFor(proxyLink);
42 : }
43 :
44 0 : NS_ENSURE_TRUE(IS_MAI_OBJECT(atkHyperLink), nullptr);
45 0 : return MAI_ATK_OBJECT(atkHyperLink)->GetAtkHyperlink();
46 : }
47 :
48 : static gint
49 0 : getLinkCountCB(AtkHypertext *aText)
50 : {
51 0 : AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
52 0 : if (accWrap) {
53 0 : HyperTextAccessible* hyperText = accWrap->AsHyperText();
54 0 : NS_ENSURE_TRUE(hyperText, -1);
55 0 : return hyperText->LinkCount();
56 : }
57 :
58 0 : if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
59 0 : return proxy->LinkCount();
60 : }
61 :
62 0 : return -1;
63 : }
64 :
65 : static gint
66 0 : getLinkIndexCB(AtkHypertext *aText, gint aCharIndex)
67 : {
68 0 : AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
69 0 : if (accWrap) {
70 0 : HyperTextAccessible* hyperText = accWrap->AsHyperText();
71 0 : NS_ENSURE_TRUE(hyperText, -1);
72 :
73 0 : return hyperText->LinkIndexAtOffset(aCharIndex);
74 : }
75 :
76 0 : if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
77 0 : return proxy->LinkIndexAtOffset(aCharIndex);
78 : }
79 :
80 0 : return -1;
81 : }
82 : }
83 :
84 : void
85 0 : hypertextInterfaceInitCB(AtkHypertextIface* aIface)
86 : {
87 0 : NS_ASSERTION(aIface, "no interface!");
88 0 : if (MOZ_UNLIKELY(!aIface))
89 0 : return;
90 :
91 0 : aIface->get_link = getLinkCB;
92 0 : aIface->get_n_links = getLinkCountCB;
93 0 : aIface->get_link_index = getLinkIndexCB;
94 : }
|