Bumping manifests a=b2g-bump
[gecko.git] / accessible / atk / nsMaiInterfaceHypertext.cpp
blob7baa58cf1fb4d991ad60914e430573b67556d9ee
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"
11 #include "nsMai.h"
12 #include "nsMaiHyperlink.h"
13 #include "mozilla/Likely.h"
15 using namespace mozilla::a11y;
17 extern "C" {
19 static AtkHyperlink*
20 getLinkCB(AtkHypertext *aText, gint aLinkIndex)
22 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
23 if (!accWrap)
24 return nullptr;
26 HyperTextAccessible* hyperText = accWrap->AsHyperText();
27 NS_ENSURE_TRUE(hyperText, nullptr);
29 Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
30 if (!hyperLink)
31 return nullptr;
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();
42 static gint
43 getLinkCountCB(AtkHypertext *aText)
45 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
46 if (!accWrap)
47 return -1;
49 HyperTextAccessible* hyperText = accWrap->AsHyperText();
50 NS_ENSURE_TRUE(hyperText, -1);
52 return hyperText->LinkCount();
55 static gint
56 getLinkIndexCB(AtkHypertext *aText, gint aCharIndex)
58 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
59 if (!accWrap)
60 return -1;
62 HyperTextAccessible* hyperText = accWrap->AsHyperText();
63 NS_ENSURE_TRUE(hyperText, -1);
65 return hyperText->LinkIndexAtOffset(aCharIndex);
69 void
70 hypertextInterfaceInitCB(AtkHypertextIface* aIface)
72 NS_ASSERTION(aIface, "no interface!");
73 if (MOZ_UNLIKELY(!aIface))
74 return;
76 aIface->get_link = getLinkCB;
77 aIface->get_n_links = getLinkCountCB;
78 aIface->get_link_index = getLinkIndexCB;