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 : * Novell, Inc.
20 : * Portions created by the Initial Developer are Copyright (C) 2010
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Brad Taylor <brad@getcoded.net> (original author)
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 <atk/atk.h>
41 : #include "AtkSocketAccessible.h"
42 : #include "nsMai.h"
43 : #include "nsMaiInterfaceComponent.h"
44 :
45 : void (*AtkSocketAccessible::g_atk_socket_embed) (AtkSocket*, gchar*) = NULL;
46 : GType AtkSocketAccessible::g_atk_socket_type = G_TYPE_INVALID;
47 : const char* AtkSocketAccessible::sATKSocketEmbedSymbol = "atk_socket_embed";
48 : const char* AtkSocketAccessible::sATKSocketGetTypeSymbol = "atk_socket_get_type";
49 :
50 : bool AtkSocketAccessible::gCanEmbed = FALSE;
51 :
52 : /* MaiAtkSocket */
53 :
54 : #define MAI_TYPE_ATK_SOCKET (mai_atk_socket_get_type ())
55 : #define MAI_ATK_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
56 : MAI_TYPE_ATK_SOCKET, MaiAtkSocket))
57 : #define MAI_IS_ATK_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
58 : MAI_TYPE_ATK_SOCKET))
59 : #define MAI_ATK_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
60 : MAI_TYPE_ATK_SOCKET,\
61 : MaiAtkSocketClass))
62 : #define MAI_IS_ATK_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
63 : MAI_TYPE_ATK_SOCKET))
64 : #define MAI_ATK_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
65 : MAI_TYPE_ATK_SOCKET,\
66 : MaiAtkSocketClass))
67 :
68 : typedef struct _MaiAtkSocket MaiAtkSocket;
69 : typedef struct _MaiAtkSocketClass MaiAtkSocketClass;
70 :
71 : struct _MaiAtkSocket
72 : {
73 : AtkSocket parent;
74 :
75 : nsAccessibleWrap* accWrap;
76 : };
77 :
78 : struct _MaiAtkSocketClass
79 : {
80 : AtkSocketClass parent_class;
81 : };
82 :
83 : G_BEGIN_DECLS
84 :
85 : GType mai_atk_socket_get_type(void);
86 : AtkObject* mai_atk_socket_new(nsAccessibleWrap* aAccWrap);
87 :
88 : void mai_atk_component_iface_init(AtkComponentIface* aIface);
89 : AtkObject* mai_atk_socket_ref_accessible_at_point(AtkComponent *aComponent,
90 : gint aAccX,
91 : gint aAccY,
92 : AtkCoordType aCoordType);
93 : void mai_atk_socket_get_extents(AtkComponent* aComponent,
94 : gint* aAccX,
95 : gint* aAccY,
96 : gint* aAccWidth,
97 : gint* aAccHeight,
98 : AtkCoordType aCoordType);
99 :
100 : G_END_DECLS
101 :
102 0 : G_DEFINE_TYPE_EXTENDED(MaiAtkSocket, mai_atk_socket,
103 : AtkSocketAccessible::g_atk_socket_type, 0,
104 : G_IMPLEMENT_INTERFACE(ATK_TYPE_COMPONENT,
105 0 : mai_atk_component_iface_init))
106 :
107 : void
108 0 : mai_atk_socket_class_init(MaiAtkSocketClass* aAcc)
109 : {
110 0 : }
111 :
112 : void
113 0 : mai_atk_socket_init(MaiAtkSocket* aAcc)
114 : {
115 0 : }
116 :
117 : AtkObject*
118 0 : mai_atk_socket_new(nsAccessibleWrap* aAccWrap)
119 : {
120 0 : NS_ENSURE_TRUE(aAccWrap, NULL);
121 :
122 0 : MaiAtkSocket* acc = nsnull;
123 0 : acc = static_cast<MaiAtkSocket*>(g_object_new(MAI_TYPE_ATK_SOCKET, NULL));
124 0 : NS_ENSURE_TRUE(acc, NULL);
125 :
126 0 : acc->accWrap = aAccWrap;
127 0 : return ATK_OBJECT(acc);
128 : }
129 :
130 : void
131 0 : mai_atk_component_iface_init(AtkComponentIface* aIface)
132 : {
133 0 : NS_ASSERTION(aIface, "Invalid Interface");
134 :
135 0 : aIface->ref_accessible_at_point = mai_atk_socket_ref_accessible_at_point;
136 0 : aIface->get_extents = mai_atk_socket_get_extents;
137 0 : }
138 :
139 : AtkObject*
140 0 : mai_atk_socket_ref_accessible_at_point(AtkComponent* aComponent,
141 : gint aX, gint aY,
142 : AtkCoordType aCoordType)
143 : {
144 0 : NS_ENSURE_TRUE(MAI_IS_ATK_SOCKET(aComponent), nsnull);
145 :
146 0 : return refAccessibleAtPointHelper(MAI_ATK_SOCKET(aComponent)->accWrap,
147 0 : aX, aY, aCoordType);
148 : }
149 :
150 : void
151 0 : mai_atk_socket_get_extents(AtkComponent* aComponent,
152 : gint* aX, gint* aY, gint* aWidth, gint* aHeight,
153 : AtkCoordType aCoordType)
154 : {
155 0 : *aX = *aY = *aWidth = *aHeight = 0;
156 :
157 0 : if (!MAI_IS_ATK_SOCKET(aComponent))
158 0 : return;
159 :
160 0 : getExtentsHelper(MAI_ATK_SOCKET(aComponent)->accWrap,
161 0 : aX, aY, aWidth, aHeight, aCoordType);
162 : }
163 :
164 0 : AtkSocketAccessible::AtkSocketAccessible(nsIContent* aContent,
165 : nsDocAccessible* aDoc,
166 : const nsCString& aPlugId) :
167 0 : nsAccessibleWrap(aContent, aDoc)
168 : {
169 0 : mAtkObject = mai_atk_socket_new(this);
170 0 : if (!mAtkObject)
171 0 : return;
172 :
173 : // Embeds the children of an AtkPlug, specified by plugId, as the children of
174 : // this socket.
175 : // Using G_TYPE macros instead of ATK_SOCKET macros to avoid undefined
176 : // symbols.
177 0 : if (gCanEmbed && G_TYPE_CHECK_INSTANCE_TYPE(mAtkObject, g_atk_socket_type) &&
178 0 : !aPlugId.IsVoid()) {
179 : AtkSocket* accSocket =
180 0 : G_TYPE_CHECK_INSTANCE_CAST(mAtkObject, g_atk_socket_type, AtkSocket);
181 0 : g_atk_socket_embed(accSocket, (gchar*)aPlugId.get());
182 : }
183 : }
184 :
185 : NS_IMETHODIMP
186 0 : AtkSocketAccessible::GetNativeInterface(void** aOutAccessible)
187 : {
188 0 : *aOutAccessible = mAtkObject;
189 0 : return NS_OK;
190 : }
191 :
192 : void
193 0 : AtkSocketAccessible::Shutdown()
194 : {
195 0 : if (mAtkObject) {
196 0 : if (MAI_IS_ATK_SOCKET(mAtkObject))
197 0 : MAI_ATK_SOCKET(mAtkObject)->accWrap = nsnull;
198 0 : g_object_unref(mAtkObject);
199 0 : mAtkObject = nsnull;
200 : }
201 0 : nsAccessibleWrap::Shutdown();
202 0 : }
|