Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/accessible/atk/nsMaiInterfaceSelection.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 "AccessibleWrap.h"
11
#include "nsMai.h"
12
#include "ProxyAccessible.h"
13
#include "mozilla/Likely.h"
14
15
#include <atk/atk.h>
16
17
using namespace mozilla::a11y;
18
19
extern "C" {
20
21
static gboolean
22
addSelectionCB(AtkSelection *aSelection, gint i)
23
0
{
24
0
  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
25
0
  if (accWrap && accWrap->IsSelect()) {
26
0
    return accWrap->AddItemToSelection(i);
27
0
  }
28
0
29
0
  if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
30
0
    return proxy->AddItemToSelection(i);
31
0
  }
32
0
33
0
  return FALSE;
34
0
}
35
36
static gboolean
37
clearSelectionCB(AtkSelection *aSelection)
38
0
{
39
0
  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
40
0
  if (accWrap && accWrap->IsSelect()) {
41
0
    return accWrap->UnselectAll();
42
0
  }
43
0
44
0
  if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
45
0
    return proxy->UnselectAll();
46
0
  }
47
0
48
0
  return FALSE;
49
0
}
50
51
static AtkObject*
52
refSelectionCB(AtkSelection *aSelection, gint i)
53
0
{
54
0
  AtkObject* atkObj = nullptr;
55
0
  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
56
0
  if (accWrap && accWrap->IsSelect()) {
57
0
    Accessible* selectedItem = accWrap->GetSelectedItem(i);
58
0
    if (!selectedItem) {
59
0
      return nullptr;
60
0
    }
61
0
62
0
    atkObj = AccessibleWrap::GetAtkObject(selectedItem);
63
0
  } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
64
0
    ProxyAccessible* selectedItem = proxy->GetSelectedItem(i);
65
0
    if (selectedItem) {
66
0
      atkObj = GetWrapperFor(selectedItem);
67
0
    }
68
0
  }
69
0
70
0
  if (atkObj) {
71
0
    g_object_ref(atkObj);
72
0
  }
73
0
74
0
  return atkObj;
75
0
}
76
77
static gint
78
getSelectionCountCB(AtkSelection *aSelection)
79
0
{
80
0
  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
81
0
  if (accWrap && accWrap->IsSelect()) {
82
0
    return accWrap->SelectedItemCount();
83
0
  }
84
0
85
0
  if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
86
0
    return proxy->SelectedItemCount();
87
0
  }
88
0
89
0
  return -1;
90
0
}
91
92
static gboolean
93
isChildSelectedCB(AtkSelection *aSelection, gint i)
94
0
{
95
0
  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
96
0
  if (accWrap && accWrap->IsSelect()) {
97
0
    return accWrap->IsItemSelected(i);
98
0
  }
99
0
100
0
  if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
101
0
    return proxy->IsItemSelected(i);
102
0
  }
103
0
104
0
  return FALSE;
105
0
}
106
107
static gboolean
108
removeSelectionCB(AtkSelection *aSelection, gint i)
109
0
{
110
0
  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
111
0
  if (accWrap && accWrap->IsSelect()) {
112
0
    return accWrap->RemoveItemFromSelection(i);
113
0
  }
114
0
115
0
  if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
116
0
    return proxy->RemoveItemFromSelection(i);
117
0
  }
118
0
119
0
  return FALSE;
120
0
}
121
122
static gboolean
123
selectAllSelectionCB(AtkSelection *aSelection)
124
0
{
125
0
  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
126
0
  if (accWrap && accWrap->IsSelect()) {
127
0
    return accWrap->SelectAll();
128
0
  }
129
0
130
0
  if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
131
0
    return proxy->SelectAll();
132
0
  }
133
0
134
0
  return FALSE;
135
0
}
136
}
137
138
void
139
selectionInterfaceInitCB(AtkSelectionIface* aIface)
140
0
{
141
0
  NS_ASSERTION(aIface, "Invalid aIface");
142
0
  if (MOZ_UNLIKELY(!aIface))
143
0
    return;
144
0
145
0
  aIface->add_selection = addSelectionCB;
146
0
  aIface->clear_selection = clearSelectionCB;
147
0
  aIface->ref_selection = refSelectionCB;
148
0
  aIface->get_selection_count = getSelectionCountCB;
149
0
  aIface->is_child_selected = isChildSelectedCB;
150
0
  aIface->remove_selection = removeSelectionCB;
151
0
  aIface->select_all_selection = selectAllSelectionCB;
152
0
}