Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/accessible/atk/nsMaiInterfaceHypertext.cpp
Line
Count
Source (jump to first uncovered line)
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
getLinkCB(AtkHypertext *aText, gint aLinkIndex)
23
0
{
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
0
30
0
    Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
31
0
    if (!hyperLink || !hyperLink->IsLink()) {
32
0
      return nullptr;
33
0
    }
34
0
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
0
41
0
    atkHyperLink = GetWrapperFor(proxyLink);
42
0
  }
43
0
44
0
    NS_ENSURE_TRUE(IS_MAI_OBJECT(atkHyperLink), nullptr);
45
0
    return MAI_ATK_OBJECT(atkHyperLink)->GetAtkHyperlink();
46
0
}
47
48
static gint
49
getLinkCountCB(AtkHypertext *aText)
50
0
{
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
0
  }
57
0
58
0
  if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
59
0
    return proxy->LinkCount();
60
0
  }
61
0
62
0
  return -1;
63
0
}
64
65
static gint
66
getLinkIndexCB(AtkHypertext *aText, gint aCharIndex)
67
0
{
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
0
73
0
    return hyperText->LinkIndexAtOffset(aCharIndex);
74
0
  }
75
0
76
0
  if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
77
0
    return proxy->LinkIndexAtOffset(aCharIndex);
78
0
  }
79
0
80
0
  return -1;
81
0
}
82
}
83
84
void
85
hypertextInterfaceInitCB(AtkHypertextIface* aIface)
86
0
{
87
0
  NS_ASSERTION(aIface, "no interface!");
88
0
  if (MOZ_UNLIKELY(!aIface))
89
0
    return;
90
0
91
0
  aIface->get_link = getLinkCB;
92
0
  aIface->get_n_links = getLinkCountCB;
93
0
  aIface->get_link_index = getLinkIndexCB;
94
0
}