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 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Sun Microsystems, Inc.
20 : * Portions created by the Initial Developer are Copyright (C) 2002
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Bolian Yin (bolian.yin@sun.com)
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "nsMaiInterfaceComponent.h"
41 :
42 : #include "nsAccessibleWrap.h"
43 : #include "nsAccUtils.h"
44 : #include "nsCoreUtils.h"
45 :
46 : void
47 0 : componentInterfaceInitCB(AtkComponentIface *aIface)
48 : {
49 0 : NS_ASSERTION(aIface, "Invalid Interface");
50 0 : if(!aIface)
51 0 : return;
52 :
53 : /*
54 : * Use default implementation in atk for contains, get_position,
55 : * and get_size
56 : */
57 0 : aIface->ref_accessible_at_point = refAccessibleAtPointCB;
58 0 : aIface->get_extents = getExtentsCB;
59 0 : aIface->grab_focus = grabFocusCB;
60 : }
61 :
62 : AtkObject*
63 0 : refAccessibleAtPointCB(AtkComponent* aComponent, gint aAccX, gint aAccY,
64 : AtkCoordType aCoordType)
65 : {
66 0 : return refAccessibleAtPointHelper(GetAccessibleWrap(ATK_OBJECT(aComponent)),
67 0 : aAccX, aAccY, aCoordType);
68 : }
69 :
70 : void
71 0 : getExtentsCB(AtkComponent* aComponent, gint* aX, gint* aY,
72 : gint* aWidth, gint* aHeight, AtkCoordType aCoordType)
73 : {
74 0 : getExtentsHelper(GetAccessibleWrap(ATK_OBJECT(aComponent)),
75 0 : aX, aY, aWidth, aHeight, aCoordType);
76 0 : }
77 :
78 : gboolean
79 0 : grabFocusCB(AtkComponent* aComponent)
80 : {
81 0 : nsAccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent));
82 0 : if (!accWrap)
83 0 : return FALSE;
84 :
85 0 : nsresult rv = accWrap->TakeFocus();
86 0 : return (NS_FAILED(rv)) ? FALSE : TRUE;
87 : }
88 :
89 : AtkObject*
90 0 : refAccessibleAtPointHelper(nsAccessibleWrap* aAccWrap, gint aX, gint aY,
91 : AtkCoordType aCoordType)
92 : {
93 0 : if (!aAccWrap || aAccWrap->IsDefunct() || nsAccUtils::MustPrune(aAccWrap))
94 0 : return nsnull;
95 :
96 : // nsAccessible::ChildAtPoint(x,y) is in screen pixels.
97 0 : if (aCoordType == ATK_XY_WINDOW) {
98 : nsIntPoint winCoords =
99 0 : nsCoreUtils::GetScreenCoordsForWindow(aAccWrap->GetNode());
100 0 : aX += winCoords.x;
101 0 : aY += winCoords.y;
102 : }
103 :
104 : nsAccessible* accAtPoint = aAccWrap->ChildAtPoint(aX, aY,
105 0 : nsAccessible::eDirectChild);
106 0 : if (!accAtPoint)
107 0 : return nsnull;
108 :
109 0 : AtkObject* atkObj = nsAccessibleWrap::GetAtkObject(accAtPoint);
110 0 : if (atkObj)
111 0 : g_object_ref(atkObj);
112 0 : return atkObj;
113 : }
114 :
115 : void
116 0 : getExtentsHelper(nsAccessibleWrap* aAccWrap,
117 : gint* aX, gint* aY, gint* aWidth, gint* aHeight,
118 : AtkCoordType aCoordType)
119 : {
120 0 : *aX = *aY = *aWidth = *aHeight = 0;
121 :
122 0 : if (!aAccWrap || aAccWrap->IsDefunct())
123 0 : return;
124 :
125 0 : PRInt32 x = 0, y = 0, width = 0, height = 0;
126 : // Returned in screen coordinates
127 0 : nsresult rv = aAccWrap->GetBounds(&x, &y, &width, &height);
128 0 : if (NS_FAILED(rv))
129 0 : return;
130 :
131 0 : if (aCoordType == ATK_XY_WINDOW) {
132 : nsIntPoint winCoords =
133 0 : nsCoreUtils::GetScreenCoordsForWindow(aAccWrap->GetNode());
134 0 : x -= winCoords.x;
135 0 : y -= winCoords.y;
136 : }
137 :
138 0 : *aX = x;
139 0 : *aY = y;
140 0 : *aWidth = width;
141 0 : *aHeight = height;
142 : }
|