michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "InterfaceInitFuncs.h" michael@0: michael@0: #include "Accessible-inl.h" michael@0: #include "HyperTextAccessible.h" michael@0: #include "nsMai.h" michael@0: #include "nsMaiHyperlink.h" michael@0: #include "mozilla/Likely.h" michael@0: michael@0: using namespace mozilla::a11y; michael@0: michael@0: extern "C" { michael@0: michael@0: static AtkHyperlink* michael@0: getLinkCB(AtkHypertext *aText, gint aLinkIndex) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); michael@0: if (!accWrap) michael@0: return nullptr; michael@0: michael@0: HyperTextAccessible* hyperText = accWrap->AsHyperText(); michael@0: NS_ENSURE_TRUE(hyperText, nullptr); michael@0: michael@0: Accessible* hyperLink = hyperText->LinkAt(aLinkIndex); michael@0: if (!hyperLink) michael@0: return nullptr; michael@0: michael@0: AtkObject* hyperLinkAtkObj = AccessibleWrap::GetAtkObject(hyperLink); michael@0: AccessibleWrap* accChild = GetAccessibleWrap(hyperLinkAtkObj); michael@0: NS_ENSURE_TRUE(accChild, nullptr); michael@0: michael@0: MaiHyperlink *maiHyperlink = accChild->GetMaiHyperlink(); michael@0: NS_ENSURE_TRUE(maiHyperlink, nullptr); michael@0: return maiHyperlink->GetAtkHyperlink(); michael@0: } michael@0: michael@0: static gint michael@0: getLinkCountCB(AtkHypertext *aText) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); michael@0: if (!accWrap) michael@0: return -1; michael@0: michael@0: HyperTextAccessible* hyperText = accWrap->AsHyperText(); michael@0: NS_ENSURE_TRUE(hyperText, -1); michael@0: michael@0: return hyperText->LinkCount(); michael@0: } michael@0: michael@0: static gint michael@0: getLinkIndexCB(AtkHypertext *aText, gint aCharIndex) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); michael@0: if (!accWrap) michael@0: return -1; michael@0: michael@0: HyperTextAccessible* hyperText = accWrap->AsHyperText(); michael@0: NS_ENSURE_TRUE(hyperText, -1); michael@0: michael@0: return hyperText->LinkIndexAtOffset(aCharIndex); michael@0: } michael@0: } michael@0: michael@0: void michael@0: hypertextInterfaceInitCB(AtkHypertextIface* aIface) michael@0: { michael@0: NS_ASSERTION(aIface, "no interface!"); michael@0: if (MOZ_UNLIKELY(!aIface)) michael@0: return; michael@0: michael@0: aIface->get_link = getLinkCB; michael@0: aIface->get_n_links = getLinkCountCB; michael@0: aIface->get_link_index = getLinkIndexCB; michael@0: }