|
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 |
|
15 using namespace mozilla::a11y; |
|
16 |
|
17 extern "C" { |
|
18 |
|
19 static AtkObject* |
|
20 refAccessibleAtPointCB(AtkComponent* aComponent, gint aAccX, gint aAccY, |
|
21 AtkCoordType aCoordType) |
|
22 { |
|
23 return refAccessibleAtPointHelper(GetAccessibleWrap(ATK_OBJECT(aComponent)), |
|
24 aAccX, aAccY, aCoordType); |
|
25 } |
|
26 |
|
27 static void |
|
28 getExtentsCB(AtkComponent* aComponent, gint* aX, gint* aY, |
|
29 gint* aWidth, gint* aHeight, AtkCoordType aCoordType) |
|
30 { |
|
31 getExtentsHelper(GetAccessibleWrap(ATK_OBJECT(aComponent)), |
|
32 aX, aY, aWidth, aHeight, aCoordType); |
|
33 } |
|
34 |
|
35 static gboolean |
|
36 grabFocusCB(AtkComponent* aComponent) |
|
37 { |
|
38 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent)); |
|
39 if (!accWrap) |
|
40 return FALSE; |
|
41 |
|
42 nsresult rv = accWrap->TakeFocus(); |
|
43 return (NS_FAILED(rv)) ? FALSE : TRUE; |
|
44 } |
|
45 } |
|
46 |
|
47 AtkObject* |
|
48 refAccessibleAtPointHelper(AccessibleWrap* aAccWrap, gint aX, gint aY, |
|
49 AtkCoordType aCoordType) |
|
50 { |
|
51 if (!aAccWrap || aAccWrap->IsDefunct() || nsAccUtils::MustPrune(aAccWrap)) |
|
52 return nullptr; |
|
53 |
|
54 // Accessible::ChildAtPoint(x,y) is in screen pixels. |
|
55 if (aCoordType == ATK_XY_WINDOW) { |
|
56 nsIntPoint winCoords = |
|
57 nsCoreUtils::GetScreenCoordsForWindow(aAccWrap->GetNode()); |
|
58 aX += winCoords.x; |
|
59 aY += winCoords.y; |
|
60 } |
|
61 |
|
62 Accessible* accAtPoint = aAccWrap->ChildAtPoint(aX, aY, |
|
63 Accessible::eDirectChild); |
|
64 if (!accAtPoint) |
|
65 return nullptr; |
|
66 |
|
67 AtkObject* atkObj = AccessibleWrap::GetAtkObject(accAtPoint); |
|
68 if (atkObj) |
|
69 g_object_ref(atkObj); |
|
70 return atkObj; |
|
71 } |
|
72 |
|
73 void |
|
74 getExtentsHelper(AccessibleWrap* aAccWrap, |
|
75 gint* aX, gint* aY, gint* aWidth, gint* aHeight, |
|
76 AtkCoordType aCoordType) |
|
77 { |
|
78 *aX = *aY = *aWidth = *aHeight = 0; |
|
79 |
|
80 if (!aAccWrap || aAccWrap->IsDefunct()) |
|
81 return; |
|
82 |
|
83 int32_t x = 0, y = 0, width = 0, height = 0; |
|
84 // Returned in screen coordinates |
|
85 nsresult rv = aAccWrap->GetBounds(&x, &y, &width, &height); |
|
86 if (NS_FAILED(rv)) |
|
87 return; |
|
88 |
|
89 if (aCoordType == ATK_XY_WINDOW) { |
|
90 nsIntPoint winCoords = |
|
91 nsCoreUtils::GetScreenCoordsForWindow(aAccWrap->GetNode()); |
|
92 x -= winCoords.x; |
|
93 y -= winCoords.y; |
|
94 } |
|
95 |
|
96 *aX = x; |
|
97 *aY = y; |
|
98 *aWidth = width; |
|
99 *aHeight = height; |
|
100 } |
|
101 |
|
102 void |
|
103 componentInterfaceInitCB(AtkComponentIface* aIface) |
|
104 { |
|
105 NS_ASSERTION(aIface, "Invalid Interface"); |
|
106 if(MOZ_UNLIKELY(!aIface)) |
|
107 return; |
|
108 |
|
109 /* |
|
110 * Use default implementation in atk for contains, get_position, |
|
111 * and get_size |
|
112 */ |
|
113 aIface->ref_accessible_at_point = refAccessibleAtPointCB; |
|
114 aIface->get_extents = getExtentsCB; |
|
115 aIface->grab_focus = grabFocusCB; |
|
116 } |