accessible/src/atk/nsMaiInterfaceHypertext.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/atk/nsMaiInterfaceHypertext.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "InterfaceInitFuncs.h"
    1.11 +
    1.12 +#include "Accessible-inl.h"
    1.13 +#include "HyperTextAccessible.h"
    1.14 +#include "nsMai.h"
    1.15 +#include "nsMaiHyperlink.h"
    1.16 +#include "mozilla/Likely.h"
    1.17 +
    1.18 +using namespace mozilla::a11y;
    1.19 +
    1.20 +extern "C" {
    1.21 +
    1.22 +static AtkHyperlink*
    1.23 +getLinkCB(AtkHypertext *aText, gint aLinkIndex)
    1.24 +{
    1.25 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    1.26 +  if (!accWrap)
    1.27 +    return nullptr;
    1.28 +
    1.29 +  HyperTextAccessible* hyperText = accWrap->AsHyperText();
    1.30 +  NS_ENSURE_TRUE(hyperText, nullptr);
    1.31 +
    1.32 +  Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
    1.33 +  if (!hyperLink)
    1.34 +    return nullptr;
    1.35 +
    1.36 +  AtkObject* hyperLinkAtkObj = AccessibleWrap::GetAtkObject(hyperLink);
    1.37 +  AccessibleWrap* accChild = GetAccessibleWrap(hyperLinkAtkObj);
    1.38 +  NS_ENSURE_TRUE(accChild, nullptr);
    1.39 +
    1.40 +  MaiHyperlink *maiHyperlink = accChild->GetMaiHyperlink();
    1.41 +  NS_ENSURE_TRUE(maiHyperlink, nullptr);
    1.42 +  return maiHyperlink->GetAtkHyperlink();
    1.43 +}
    1.44 +
    1.45 +static gint
    1.46 +getLinkCountCB(AtkHypertext *aText)
    1.47 +{
    1.48 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    1.49 +  if (!accWrap)
    1.50 +    return -1;
    1.51 +
    1.52 +  HyperTextAccessible* hyperText = accWrap->AsHyperText();
    1.53 +  NS_ENSURE_TRUE(hyperText, -1);
    1.54 +
    1.55 +  return hyperText->LinkCount();
    1.56 +}
    1.57 +
    1.58 +static gint
    1.59 +getLinkIndexCB(AtkHypertext *aText, gint aCharIndex)
    1.60 +{
    1.61 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    1.62 +  if (!accWrap)
    1.63 +    return -1;
    1.64 +
    1.65 +  HyperTextAccessible* hyperText = accWrap->AsHyperText();
    1.66 +  NS_ENSURE_TRUE(hyperText, -1);
    1.67 +
    1.68 +  return hyperText->LinkIndexAtOffset(aCharIndex);
    1.69 +}
    1.70 +}
    1.71 +
    1.72 +void
    1.73 +hypertextInterfaceInitCB(AtkHypertextIface* aIface)
    1.74 +{
    1.75 +  NS_ASSERTION(aIface, "no interface!");
    1.76 +  if (MOZ_UNLIKELY(!aIface))
    1.77 +    return;
    1.78 +
    1.79 +  aIface->get_link = getLinkCB;
    1.80 +  aIface->get_n_links = getLinkCountCB;
    1.81 +  aIface->get_link_index = getLinkIndexCB;
    1.82 +}

mercurial