[ATK] Missing WTR AccessibilityUIElement::addNotificationListener implementation
[WebKit-https.git] / Tools / WebKitTestRunner / InjectedBundle / atk / AccessibilityControllerAtk.cpp
index 3b58c0da0338b45665ea957b4c6bf9d8f0a24044..c1875154edc2a6178f461217080fa35b18d30807 100644 (file)
 
 namespace WTR {
 
-static void printAccessibilityEvent(AtkObject* accessible, const gchar* signalName, const gchar* signalValue)
-{
-    // Do not handle state-change:defunct signals, as the AtkObject
-    // associated to them will not be valid at this point already.
-    if (!signalName || !g_strcmp0(signalName, "state-change:defunct"))
-        return;
-
-    if (!accessible || !ATK_IS_OBJECT(accessible))
-        return;
-
-    const gchar* objectName = atk_object_get_name(accessible);
-    AtkRole objectRole = atk_object_get_role(accessible);
-
-    // Try to always provide a name to be logged for the object.
-    if (!objectName || *objectName == '\0')
-        objectName = "(No name)";
-
-    GOwnPtr<gchar> signalNameAndValue(signalValue ? g_strdup_printf("%s = %s", signalName, signalValue) : g_strdup(signalName));
-    GOwnPtr<gchar> accessibilityEventString(g_strdup_printf("Accessibility object emitted \"%s\" / Name: \"%s\" / Role: %d\n", signalNameAndValue.get(), objectName, objectRole));
-    InjectedBundle::shared().outputText(String::fromUTF8(accessibilityEventString.get()));
-}
-
-static gboolean axObjectEventListener(GSignalInvocationHint *signalHint, guint numParamValues, const GValue *paramValues, gpointer data)
-{
-    // At least we should receive the instance emitting the signal.
-    if (numParamValues < 1)
-        return TRUE;
-
-    AtkObject* accessible = ATK_OBJECT(g_value_get_object(&paramValues[0]));
-    if (!accessible || !ATK_IS_OBJECT(accessible))
-        return TRUE;
-
-    GSignalQuery signalQuery;
-    GOwnPtr<gchar> signalName;
-    GOwnPtr<gchar> signalValue;
-
-    g_signal_query(signalHint->signal_id, &signalQuery);
-
-    if (!g_strcmp0(signalQuery.signal_name, "state-change")) {
-        signalName.set(g_strdup_printf("state-change:%s", g_value_get_string(&paramValues[1])));
-        signalValue.set(g_strdup_printf("%d", g_value_get_boolean(&paramValues[2])));
-    } else if (!g_strcmp0(signalQuery.signal_name, "focus-event")) {
-        signalName.set(g_strdup("focus-event"));
-        signalValue.set(g_strdup_printf("%d", g_value_get_boolean(&paramValues[1])));
-    } else if (!g_strcmp0(signalQuery.signal_name, "children-changed")) {
-        signalName.set(g_strdup("children-changed"));
-        signalValue.set(g_strdup_printf("%d", g_value_get_uint(&paramValues[1])));
-    } else if (!g_strcmp0(signalQuery.signal_name, "property-change"))
-        signalName.set(g_strdup_printf("property-change:%s", g_quark_to_string(signalHint->detail)));
-    else
-        signalName.set(g_strdup(signalQuery.signal_name));
-
-    printAccessibilityEvent(accessible, signalName.get(), signalValue.get());
-
-    return TRUE;
-}
-
 void AccessibilityController::logAccessibilityEvents()
 {
     // Ensure no callbacks are connected before.
@@ -105,13 +48,9 @@ void AccessibilityController::logAccessibilityEvents()
     // the root accessible object, which will create the full hierarchy.
     rootElement();
 
-    // Add global listeners for AtkObject's signals.
-    m_stateChangeListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:state-change");
-    m_focusEventListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:focus-event");
-    m_activeDescendantChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:active-descendant-changed");
-    m_childrenChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:children-changed");
-    m_propertyChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:property-change");
-    m_visibleDataChangedListenerId = atk_add_global_event_listener(axObjectEventListener, "ATK:AtkObject:visible-data-changed");
+    if (!m_globalNotificationHandler)
+        m_globalNotificationHandler = AccessibilityNotificationHandler::create();
+    m_globalNotificationHandler->logAccessibilityEvents();
 
     // Ensure the Atk interface types are registered, otherwise
     // the AtkDocument signal handlers below won't get registered.
@@ -123,31 +62,7 @@ void AccessibilityController::logAccessibilityEvents()
 
 void AccessibilityController::resetToConsistentState()
 {
-    // AtkObject signals.
-    if (m_stateChangeListenerId) {
-        atk_remove_global_event_listener(m_stateChangeListenerId);
-        m_stateChangeListenerId = 0;
-    }
-    if (m_focusEventListenerId) {
-        atk_remove_global_event_listener(m_focusEventListenerId);
-        m_focusEventListenerId = 0;
-    }
-    if (m_activeDescendantChangedListenerId) {
-        atk_remove_global_event_listener(m_activeDescendantChangedListenerId);
-        m_activeDescendantChangedListenerId = 0;
-    }
-    if (m_childrenChangedListenerId) {
-        atk_remove_global_event_listener(m_childrenChangedListenerId);
-        m_childrenChangedListenerId = 0;
-    }
-    if (m_propertyChangedListenerId) {
-        atk_remove_global_event_listener(m_propertyChangedListenerId);
-        m_propertyChangedListenerId = 0;
-    }
-    if (m_visibleDataChangedListenerId) {
-        atk_remove_global_event_listener(m_visibleDataChangedListenerId);
-        m_visibleDataChangedListenerId = 0;
-    }
+    m_globalNotificationHandler = 0;
 }
 
 static AtkObject* childElementById(AtkObject* parent, const char* id)