Line data Source code
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 "AccessibleWrap.h"
10 : #include "nsAccUtils.h"
11 : #include "nsCoreUtils.h"
12 : #include "nsMai.h"
13 : #include "mozilla/Likely.h"
14 : #include "mozilla/a11y/ProxyAccessible.h"
15 :
16 : using namespace mozilla::a11y;
17 :
18 : extern "C" {
19 :
20 : static AtkObject*
21 0 : refAccessibleAtPointCB(AtkComponent* aComponent, gint aAccX, gint aAccY,
22 : AtkCoordType aCoordType)
23 : {
24 0 : return refAccessibleAtPointHelper(ATK_OBJECT(aComponent),
25 0 : aAccX, aAccY, aCoordType);
26 : }
27 :
28 : static void
29 0 : getExtentsCB(AtkComponent* aComponent, gint* aX, gint* aY,
30 : gint* aWidth, gint* aHeight, AtkCoordType aCoordType)
31 : {
32 0 : getExtentsHelper(ATK_OBJECT(aComponent),
33 0 : aX, aY, aWidth, aHeight, aCoordType);
34 0 : }
35 :
36 : static gboolean
37 0 : grabFocusCB(AtkComponent* aComponent)
38 : {
39 0 : AtkObject* atkObject = ATK_OBJECT(aComponent);
40 0 : AccessibleWrap* accWrap = GetAccessibleWrap(atkObject);
41 0 : if (accWrap) {
42 0 : accWrap->TakeFocus();
43 0 : return TRUE;
44 : }
45 :
46 0 : ProxyAccessible* proxy = GetProxy(atkObject);
47 0 : if (proxy) {
48 0 : proxy->TakeFocus();
49 0 : return TRUE;
50 : }
51 :
52 0 : return FALSE;
53 : }
54 : }
55 :
56 : AtkObject*
57 0 : refAccessibleAtPointHelper(AtkObject* aAtkObj, gint aX, gint aY,
58 : AtkCoordType aCoordType)
59 : {
60 0 : AccessibleWrap* accWrap = GetAccessibleWrap(aAtkObj);
61 0 : if (accWrap) {
62 0 : if (accWrap->IsDefunct() || nsAccUtils::MustPrune(accWrap)) {
63 0 : return nullptr;
64 : }
65 :
66 : // Accessible::ChildAtPoint(x,y) is in screen pixels.
67 0 : if (aCoordType == ATK_XY_WINDOW) {
68 : nsIntPoint winCoords =
69 0 : nsCoreUtils::GetScreenCoordsForWindow(accWrap->GetNode());
70 0 : aX += winCoords.x;
71 0 : aY += winCoords.y;
72 : }
73 :
74 0 : Accessible* accAtPoint = accWrap->ChildAtPoint(aX, aY,
75 0 : Accessible::eDirectChild);
76 0 : if (!accAtPoint) {
77 0 : return nullptr;
78 : }
79 :
80 0 : AtkObject* atkObj = AccessibleWrap::GetAtkObject(accAtPoint);
81 0 : if (atkObj) {
82 0 : g_object_ref(atkObj);
83 : }
84 :
85 0 : return atkObj;
86 : }
87 :
88 0 : if (ProxyAccessible* proxy = GetProxy(aAtkObj)) {
89 : ProxyAccessible* result =
90 0 : proxy->AccessibleAtPoint(aX, aY, aCoordType == ATK_XY_WINDOW);
91 0 : AtkObject* atkObj = result ? GetWrapperFor(result) : nullptr;
92 0 : if (atkObj) {
93 0 : g_object_ref(atkObj);
94 : }
95 0 : return atkObj;
96 : }
97 :
98 0 : return nullptr;
99 : }
100 :
101 : void
102 0 : getExtentsHelper(AtkObject* aAtkObj,
103 : gint* aX, gint* aY, gint* aWidth, gint* aHeight,
104 : AtkCoordType aCoordType)
105 : {
106 0 : AccessibleWrap* accWrap = GetAccessibleWrap(aAtkObj);
107 0 : *aX = *aY = *aWidth = *aHeight = 0;
108 :
109 0 : if (accWrap) {
110 0 : if (accWrap->IsDefunct()) {
111 0 : return;
112 : }
113 :
114 0 : nsIntRect screenRect = accWrap->Bounds();
115 0 : if (screenRect.IsEmpty())
116 0 : return;
117 :
118 0 : if (aCoordType == ATK_XY_WINDOW) {
119 : nsIntPoint winCoords =
120 0 : nsCoreUtils::GetScreenCoordsForWindow(accWrap->GetNode());
121 0 : screenRect.x -= winCoords.x;
122 0 : screenRect.y -= winCoords.y;
123 : }
124 :
125 0 : *aX = screenRect.x;
126 0 : *aY = screenRect.y;
127 0 : *aWidth = screenRect.width;
128 0 : *aHeight = screenRect.height;
129 0 : return;
130 : }
131 :
132 0 : if (ProxyAccessible* proxy = GetProxy(aAtkObj)) {
133 0 : proxy->Extents(aCoordType == ATK_XY_WINDOW, aX, aY, aWidth, aHeight);
134 : }
135 : }
136 :
137 : void
138 0 : componentInterfaceInitCB(AtkComponentIface* aIface)
139 : {
140 0 : NS_ASSERTION(aIface, "Invalid Interface");
141 0 : if(MOZ_UNLIKELY(!aIface))
142 0 : return;
143 :
144 : /*
145 : * Use default implementation in atk for contains, get_position,
146 : * and get_size
147 : */
148 0 : aIface->ref_accessible_at_point = refAccessibleAtPointCB;
149 0 : aIface->get_extents = getExtentsCB;
150 0 : aIface->grab_focus = grabFocusCB;
151 : }
|