2 * Copyright (C) 2011 Igalia S.L.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "AccessibilityCallbacks.h"
32 #if HAVE(ACCESSIBILITY)
34 #include "AccessibilityController.h"
35 #include "DumpRenderTree.h"
37 #include <wtf/gobject/GOwnPtr.h>
40 #include "WebCoreSupport/DumpRenderTreeSupportGtk.h"
41 #include <webkit/webkit.h>
45 #include "DumpRenderTreeChrome.h"
46 #include "WebCoreSupport/DumpRenderTreeSupportEfl.h"
49 static guint stateChangeListenerId = 0;
50 static guint focusEventListenerId = 0;
51 static guint activeDescendantChangedListenerId = 0;
52 static guint childrenChangedListenerId = 0;
53 static guint propertyChangedListenerId = 0;
54 static guint visibleDataChangedListenerId = 0;
56 static void printAccessibilityEvent(AtkObject* accessible, const gchar* signalName, const gchar* signalValue)
58 // Do not handle state-change:defunct signals, as the AtkObject
59 // associated to them will not be valid at this point already.
60 if (!signalName || !g_strcmp0(signalName, "state-change:defunct"))
63 if (!accessible || !ATK_IS_OBJECT(accessible))
66 const gchar* objectName = atk_object_get_name(accessible);
67 AtkRole objectRole = atk_object_get_role(accessible);
69 // Try to always provide a name to be logged for the object.
70 if (!objectName || *objectName == '\0')
71 objectName = "(No name)";
73 GOwnPtr<gchar> signalNameAndValue(signalValue ? g_strdup_printf("%s = %s", signalName, signalValue) : g_strdup(signalName));
74 printf("Accessibility object emitted \"%s\" / Name: \"%s\" / Role: %d\n", signalNameAndValue.get(), objectName, objectRole);
77 static gboolean axObjectEventListener(GSignalInvocationHint *signalHint, guint numParamValues, const GValue *paramValues, gpointer data)
79 // At least we should receive the instance emitting the signal.
80 if (numParamValues < 1)
83 AtkObject* accessible = ATK_OBJECT(g_value_get_object(¶mValues[0]));
84 if (!accessible || !ATK_IS_OBJECT(accessible))
87 GSignalQuery signalQuery;
88 GOwnPtr<gchar> signalName;
89 GOwnPtr<gchar> signalValue;
91 g_signal_query(signalHint->signal_id, &signalQuery);
93 if (!g_strcmp0(signalQuery.signal_name, "state-change")) {
94 signalName.set(g_strdup_printf("state-change:%s", g_value_get_string(¶mValues[1])));
95 signalValue.set(g_strdup_printf("%d", g_value_get_boolean(¶mValues[2])));
96 } else if (!g_strcmp0(signalQuery.signal_name, "focus-event")) {
97 signalName.set(g_strdup("focus-event"));
98 signalValue.set(g_strdup_printf("%d", g_value_get_boolean(¶mValues[1])));
99 } else if (!g_strcmp0(signalQuery.signal_name, "children-changed")) {
100 signalName.set(g_strdup("children-changed"));
101 signalValue.set(g_strdup_printf("%d", g_value_get_uint(¶mValues[1])));
102 } else if (!g_strcmp0(signalQuery.signal_name, "property-change"))
103 signalName.set(g_strdup_printf("property-change:%s", g_quark_to_string(signalHint->detail)));
105 signalName.set(g_strdup(signalQuery.signal_name));
107 printAccessibilityEvent(accessible, signalName.get(), signalValue.get());
112 void connectAccessibilityCallbacks()
114 // Ensure no callbacks are connected before.
115 disconnectAccessibilityCallbacks();
117 // Ensure that accessibility is initialized for the WebView by querying for
118 // the root accessible object, which will create the full hierarchy.
120 DumpRenderTreeSupportGtk::getRootAccessibleElement(mainFrame);
122 DumpRenderTreeSupportEfl::rootAccessibleElement(browser->mainFrame());
125 // Add global listeners for AtkObject's signals.
126 stateChangeListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:state-change");
127 focusEventListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:focus-event");
128 activeDescendantChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:active-descendant-changed");
129 childrenChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:children-changed");
130 propertyChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:property-change");
131 visibleDataChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:visible-data-changed");
133 // Ensure the Atk interface types are registered, otherwise
134 // the AtkDocument signal handlers below won't get registered.
135 GObject* dummyAxObject = G_OBJECT(g_object_new(ATK_TYPE_OBJECT, 0));
136 AtkObject* dummyNoOpAxObject = atk_no_op_object_new(dummyAxObject);
137 g_object_unref(G_OBJECT(dummyNoOpAxObject));
138 g_object_unref(dummyAxObject);
141 void disconnectAccessibilityCallbacks()
143 // AtkObject signals.
144 if (stateChangeListenerId) {
145 atk_remove_global_event_listener(stateChangeListenerId);
146 stateChangeListenerId = 0;
148 if (focusEventListenerId) {
149 atk_remove_global_event_listener(focusEventListenerId);
150 focusEventListenerId = 0;
152 if (activeDescendantChangedListenerId) {
153 atk_remove_global_event_listener(activeDescendantChangedListenerId);
154 activeDescendantChangedListenerId = 0;
156 if (childrenChangedListenerId) {
157 atk_remove_global_event_listener(childrenChangedListenerId);
158 childrenChangedListenerId = 0;
160 if (propertyChangedListenerId) {
161 atk_remove_global_event_listener(propertyChangedListenerId);
162 propertyChangedListenerId = 0;
164 if (visibleDataChangedListenerId) {
165 atk_remove_global_event_listener(visibleDataChangedListenerId);
166 visibleDataChangedListenerId = 0;