Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/accessible/atk/nsMaiInterfaceComponent.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 "nsAccUtils.h"
12
#include "nsCoreUtils.h"
13
#include "nsMai.h"
14
#include "mozilla/Likely.h"
15
#include "mozilla/a11y/ProxyAccessible.h"
16
17
using namespace mozilla::a11y;
18
19
extern "C" {
20
21
static AtkObject*
22
refAccessibleAtPointCB(AtkComponent* aComponent, gint aAccX, gint aAccY,
23
                       AtkCoordType aCoordType)
24
0
{
25
0
  return refAccessibleAtPointHelper(ATK_OBJECT(aComponent),
26
0
                                    aAccX, aAccY, aCoordType);
27
0
}
28
29
static void
30
getExtentsCB(AtkComponent* aComponent, gint* aX, gint* aY,
31
             gint* aWidth, gint* aHeight, AtkCoordType aCoordType)
32
0
{
33
0
  getExtentsHelper(ATK_OBJECT(aComponent),
34
0
                   aX, aY, aWidth, aHeight, aCoordType);
35
0
}
36
37
static gboolean
38
grabFocusCB(AtkComponent* aComponent)
39
0
{
40
0
  AtkObject* atkObject = ATK_OBJECT(aComponent);
41
0
  AccessibleWrap* accWrap = GetAccessibleWrap(atkObject);
42
0
  if (accWrap) {
43
0
    accWrap->TakeFocus();
44
0
    return TRUE;
45
0
  }
46
0
47
0
  ProxyAccessible* proxy = GetProxy(atkObject);
48
0
  if (proxy) {
49
0
    proxy->TakeFocus();
50
0
    return TRUE;
51
0
  }
52
0
53
0
  return FALSE;
54
0
}
55
56
// ScrollType is compatible
57
static gboolean
58
scrollToCB(AtkComponent* aComponent, AtkScrollType type)
59
0
{
60
0
  AtkObject* atkObject = ATK_OBJECT(aComponent);
61
0
  AccessibleWrap* accWrap = GetAccessibleWrap(atkObject);
62
0
  if (accWrap) {
63
0
    accWrap->ScrollTo(type);
64
0
    return TRUE;
65
0
  }
66
0
67
0
  ProxyAccessible* proxy = GetProxy(atkObject);
68
0
  if (proxy) {
69
0
    proxy->ScrollTo(type);
70
0
    return TRUE;
71
0
  }
72
0
73
0
  return FALSE;
74
0
}
75
76
// CoordType is compatible
77
static gboolean
78
scrollToPointCB(AtkComponent* aComponent, AtkCoordType coords, gint x, gint y)
79
0
{
80
0
  AtkObject* atkObject = ATK_OBJECT(aComponent);
81
0
  AccessibleWrap* accWrap = GetAccessibleWrap(atkObject);
82
0
  if (accWrap) {
83
0
    accWrap->ScrollToPoint(coords, x, y);
84
0
    return TRUE;
85
0
  }
86
0
87
0
  ProxyAccessible* proxy = GetProxy(atkObject);
88
0
  if (proxy) {
89
0
    proxy->ScrollToPoint(coords, x, y);
90
0
    return TRUE;
91
0
  }
92
0
93
0
  return FALSE;
94
0
}
95
}
96
97
AtkObject*
98
refAccessibleAtPointHelper(AtkObject* aAtkObj, gint aX, gint aY,
99
                           AtkCoordType aCoordType)
100
0
{
101
0
  AccessibleWrap* accWrap = GetAccessibleWrap(aAtkObj);
102
0
  if (accWrap) {
103
0
    if (accWrap->IsDefunct() || nsAccUtils::MustPrune(accWrap)) {
104
0
      return nullptr;
105
0
    }
106
0
107
0
    // Accessible::ChildAtPoint(x,y) is in screen pixels.
108
0
    if (aCoordType == ATK_XY_WINDOW) {
109
0
      nsIntPoint winCoords =
110
0
        nsCoreUtils::GetScreenCoordsForWindow(accWrap->GetNode());
111
0
      aX += winCoords.x;
112
0
      aY += winCoords.y;
113
0
    }
114
0
115
0
    Accessible* accAtPoint = accWrap->ChildAtPoint(aX, aY,
116
0
                                                   Accessible::eDirectChild);
117
0
    if (!accAtPoint) {
118
0
      return nullptr;
119
0
    }
120
0
121
0
    AtkObject* atkObj = AccessibleWrap::GetAtkObject(accAtPoint);
122
0
    if (atkObj) {
123
0
      g_object_ref(atkObj);
124
0
    }
125
0
126
0
    return atkObj;
127
0
  }
128
0
129
0
  if (ProxyAccessible* proxy = GetProxy(aAtkObj)) {
130
0
    ProxyAccessible* result =
131
0
      proxy->AccessibleAtPoint(aX, aY, aCoordType == ATK_XY_WINDOW);
132
0
    AtkObject* atkObj = result ? GetWrapperFor(result) : nullptr;
133
0
    if (atkObj) {
134
0
      g_object_ref(atkObj);
135
0
    }
136
0
    return atkObj;
137
0
  }
138
0
139
0
  return nullptr;
140
0
}
141
142
void
143
getExtentsHelper(AtkObject* aAtkObj,
144
                 gint* aX, gint* aY, gint* aWidth, gint* aHeight,
145
                 AtkCoordType aCoordType)
146
0
{
147
0
  AccessibleWrap* accWrap = GetAccessibleWrap(aAtkObj);
148
0
  *aX = *aY = *aWidth = *aHeight = 0;
149
0
150
0
  if (accWrap) {
151
0
    if (accWrap->IsDefunct()) {
152
0
      return;
153
0
    }
154
0
155
0
    nsIntRect screenRect = accWrap->Bounds();
156
0
    if (screenRect.IsEmpty())
157
0
      return;
158
0
159
0
    if (aCoordType == ATK_XY_WINDOW) {
160
0
      nsIntPoint winCoords =
161
0
        nsCoreUtils::GetScreenCoordsForWindow(accWrap->GetNode());
162
0
      screenRect.x -= winCoords.x;
163
0
      screenRect.y -= winCoords.y;
164
0
    }
165
0
166
0
    *aX = screenRect.x;
167
0
    *aY = screenRect.y;
168
0
    *aWidth = screenRect.width;
169
0
    *aHeight = screenRect.height;
170
0
    return;
171
0
  }
172
0
173
0
  if (ProxyAccessible* proxy = GetProxy(aAtkObj)) {
174
0
    proxy->Extents(aCoordType == ATK_XY_WINDOW, aX, aY, aWidth, aHeight);
175
0
  }
176
0
}
177
178
void
179
componentInterfaceInitCB(AtkComponentIface* aIface)
180
0
{
181
0
  NS_ASSERTION(aIface, "Invalid Interface");
182
0
  if(MOZ_UNLIKELY(!aIface))
183
0
    return;
184
0
185
0
  /*
186
0
   * Use default implementation in atk for contains, get_position,
187
0
   * and get_size
188
0
   */
189
0
  aIface->ref_accessible_at_point = refAccessibleAtPointCB;
190
0
  aIface->get_extents = getExtentsCB;
191
0
  aIface->grab_focus = grabFocusCB;
192
0
  if (IsAtkVersionAtLeast(2, 30)) {
193
0
    aIface->scroll_to = scrollToCB;
194
0
    aIface->scroll_to_point = scrollToPointCB;
195
0
  }
196
0
}