Disabled touch adjust feature in case of SDK version.
[framework/web/webkit-efl.git] / Tools / DumpRenderTree / gtk / AccessibilityCallbacks.cpp
1 /*
2  * Copyright (C) 2011 Igalia S.L.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
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.
16  *
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.
27  */
28
29 #include "config.h"
30 #include "AccessibilityCallbacks.h"
31
32 #include "AccessibilityController.h"
33 #include "DumpRenderTree.h"
34 #include "WebCoreSupport/DumpRenderTreeSupportGtk.h"
35 #include <gtk/gtk.h>
36 #include <webkit/webkit.h>
37 #include <wtf/gobject/GOwnPtr.h>
38
39 static guint stateChangeListenerId = 0;
40 static guint focusEventListenerId = 0;
41 static guint activeDescendantChangedListenerId = 0;
42 static guint childrenChangedListenerId = 0;
43 static guint propertyChangedListenerId = 0;
44 static guint visibleDataChangedListenerId = 0;
45
46 static void printAccessibilityEvent(AtkObject* accessible, const gchar* signalName, const gchar* signalValue)
47 {
48     // Do not handle state-change:defunct signals, as the AtkObject
49     // associated to them will not be valid at this point already.
50     if (!signalName || !g_strcmp0(signalName, "state-change:defunct"))
51         return;
52
53     if (!accessible || !ATK_IS_OBJECT(accessible))
54         return;
55
56     const gchar* objectName = atk_object_get_name(accessible);
57     AtkRole objectRole = atk_object_get_role(accessible);
58
59     // Try to always provide a name to be logged for the object.
60     if (!objectName || *objectName == '\0')
61         objectName = "(No name)";
62
63     GOwnPtr<gchar> signalNameAndValue(signalValue ? g_strdup_printf("%s = %s", signalName, signalValue) : g_strdup(signalName));
64     printf("Accessibility object emitted \"%s\" / Name: \"%s\" / Role: %d\n",
65            signalNameAndValue.get(), objectName, objectRole);
66 }
67
68 static gboolean axObjectEventListener(GSignalInvocationHint *signalHint,
69                                       guint numParamValues,
70                                       const GValue *paramValues,
71                                       gpointer data)
72 {
73     // At least we should receive the instance emitting the signal.
74     if (numParamValues < 1)
75         return TRUE;
76
77     AtkObject* accessible = ATK_OBJECT(g_value_get_object(&paramValues[0]));
78     if (!accessible || !ATK_IS_OBJECT(accessible))
79         return TRUE;
80
81     GSignalQuery signal_query;
82     GOwnPtr<gchar> signalName;
83     GOwnPtr<gchar> signalValue;
84
85     g_signal_query(signalHint->signal_id, &signal_query);
86
87     if (!g_strcmp0(signal_query.signal_name, "state-change")) {
88         signalName.set(g_strdup_printf("state-change:%s", g_value_get_string(&paramValues[1])));
89         signalValue.set(g_strdup_printf("%d", g_value_get_boolean(&paramValues[2])));
90     } else if (!g_strcmp0(signal_query.signal_name, "focus-event")) {
91         signalName.set(g_strdup("focus-event"));
92         signalValue.set(g_strdup_printf("%d", g_value_get_boolean(&paramValues[1])));
93     } else if (!g_strcmp0(signal_query.signal_name, "children-changed")) {
94         signalName.set(g_strdup("children-changed"));
95         signalValue.set(g_strdup_printf("%d", g_value_get_uint(&paramValues[1])));
96     } else if (!g_strcmp0(signal_query.signal_name, "property-change")) {
97         signalName.set(g_strdup_printf("property-change:%s", g_quark_to_string(signalHint->detail)));
98     } else
99         signalName.set(g_strdup(signal_query.signal_name));
100
101     printAccessibilityEvent(accessible, signalName.get(), signalValue.get());
102
103     return TRUE;
104 }
105
106 void connectAccessibilityCallbacks()
107 {
108     // Ensure no callbacks are connected before.
109     disconnectAccessibilityCallbacks();
110
111     // Ensure that accessibility is initialized for the WebView by querying for
112     // the root accessible object, which will create the full hierarchy.
113     DumpRenderTreeSupportGtk::getRootAccessibleElement(mainFrame);
114
115     // Add global listeners for AtkObject's signals.
116     stateChangeListenerId = atk_add_global_event_listener(axObjectEventListener, "Gtk:AtkObject:state-change");
117     focusEventListenerId = atk_add_global_event_listener(axObjectEventListener, "Gtk:AtkObject:focus-event");
118     activeDescendantChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "Gtk:AtkObject:active-descendant-changed");
119     childrenChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "Gtk:AtkObject:children-changed");
120     propertyChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "Gtk:AtkObject:property-change");
121     visibleDataChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "Gtk:AtkObject:visible-data-changed");
122
123     // Ensure the Atk interface types are registered, otherwise
124     // the AtkDocument signal handlers below won't get registered.
125     GObject* dummyAxObject = G_OBJECT(g_object_new(ATK_TYPE_OBJECT, 0));
126     AtkObject* dummyNoOpAxObject = atk_no_op_object_new(dummyAxObject);
127     g_object_unref(G_OBJECT(dummyNoOpAxObject));
128     g_object_unref(dummyAxObject);
129 }
130
131 void disconnectAccessibilityCallbacks()
132 {
133     // AtkObject signals.
134     if (stateChangeListenerId) {
135         atk_remove_global_event_listener(stateChangeListenerId);
136         stateChangeListenerId = 0;
137     }
138     if (focusEventListenerId) {
139         atk_remove_global_event_listener(focusEventListenerId);
140         focusEventListenerId = 0;
141     }
142     if (activeDescendantChangedListenerId) {
143         atk_remove_global_event_listener(activeDescendantChangedListenerId);
144         activeDescendantChangedListenerId = 0;
145     }
146     if (childrenChangedListenerId) {
147         atk_remove_global_event_listener(childrenChangedListenerId);
148         childrenChangedListenerId = 0;
149     }
150     if (propertyChangedListenerId) {
151         atk_remove_global_event_listener(propertyChangedListenerId);
152         propertyChangedListenerId = 0;
153     }
154     if (visibleDataChangedListenerId) {
155         atk_remove_global_event_listener(visibleDataChangedListenerId);
156         visibleDataChangedListenerId = 0;
157     }
158 }
159