Diff
Modified: trunk/Tools/ChangeLog (287104 => 287105)
--- trunk/Tools/ChangeLog 2021-12-15 21:26:53 UTC (rev 287104)
+++ trunk/Tools/ChangeLog 2021-12-15 21:32:07 UTC (rev 287105)
@@ -1,3 +1,35 @@
+2021-12-15 Don Olmstead <don.olmst...@sony.com>
+
+ Split ATK specific code in WPEViewBackends
+ https://bugs.webkit.org/show_bug.cgi?id=234310
+
+ Reviewed by Adrian Perez de Castro.
+
+ Move ATK specific code in WPEViewBackends into the atk directory. This splits
+ ViewBackend's implementation into two files with ATK specific code migrated to
+ atk/ViewBackendAtk.cpp. The code in WebKitAccessibleApplication is all ATK specific so
+ its completely moved into the atk directory.
+
+ * wpe/backends/CMakeLists.txt:
+ * wpe/backends/PlatformWPE.cmake:
+ * wpe/backends/ViewBackend.cpp:
+ (WPEToolingBackends::ViewBackend::initializeAccessibility):
+ (WPEToolingBackends::ViewBackend::updateAccessibilityState):
+ (WPEToolingBackends::addKeyEventListener): Deleted.
+ (WPEToolingBackends::removeKeyEventListener): Deleted.
+ (WPEToolingBackends::notifyAccessibilityKeyEventListeners): Deleted.
+ (WPEToolingBackends::ViewBackend::setAccessibleChild): Deleted.
+ * wpe/backends/ViewBackend.h:
+ * wpe/backends/atk/ViewBackendAtk.cpp: Copied from Tools/wpe/backends/ViewBackend.cpp.
+ (WPEToolingBackends::addKeyEventListener):
+ (WPEToolingBackends::removeKeyEventListener):
+ (WPEToolingBackends::ViewBackend::notifyAccessibilityKeyEventListeners):
+ (WPEToolingBackends::ViewBackend::initializeAccessibility):
+ (WPEToolingBackends::ViewBackend::updateAccessibilityState):
+ (WPEToolingBackends::ViewBackend::setAccessibleChild):
+ * wpe/backends/atk/WebKitAccessibleApplication.cpp: Renamed from Tools/wpe/backends/WebKitAccessibleApplication.cpp.
+ * wpe/backends/atk/WebKitAccessibleApplication.h: Renamed from Tools/wpe/backends/WebKitAccessibleApplication.h.
+
2021-12-15 Alex Christensen <achristen...@webkit.org>
Avoid unnecessary allocation and UTF-8 conversion when calling DFABytecodeInterpreter::interpret
Modified: trunk/Tools/wpe/backends/CMakeLists.txt (287104 => 287105)
--- trunk/Tools/wpe/backends/CMakeLists.txt 2021-12-15 21:26:53 UTC (rev 287104)
+++ trunk/Tools/wpe/backends/CMakeLists.txt 2021-12-15 21:32:07 UTC (rev 287105)
@@ -13,7 +13,6 @@
set(WPEToolingBackends_SOURCES
HeadlessViewBackend.cpp
ViewBackend.cpp
- WebKitAccessibleApplication.cpp
WindowViewBackend.cpp
)
Modified: trunk/Tools/wpe/backends/PlatformWPE.cmake (287104 => 287105)
--- trunk/Tools/wpe/backends/PlatformWPE.cmake 2021-12-15 21:26:53 UTC (rev 287104)
+++ trunk/Tools/wpe/backends/PlatformWPE.cmake 2021-12-15 21:32:07 UTC (rev 287105)
@@ -9,8 +9,14 @@
list(APPEND WPEToolingBackends_SOURCES
${WPEToolingBackends_DERIVED_SOURCES_DIR}/xdg-shell-unstable-v6-protocol.c
+ atk/ViewBackendAtk.cpp
+ atk/WebKitAccessibleApplication.cpp
)
+list(APPEND WPEToolingBackends_PRIVATE_INCLUDE_DIRECTORIES
+ ${TOOLS_DIR}/wpe/backends/atk
+)
+
list(APPEND WPEToolingBackends_SYSTEM_INCLUDE_DIRECTORIES
${ATK_INCLUDE_DIRS}
${GLIB_INCLUDE_DIRS}
Modified: trunk/Tools/wpe/backends/ViewBackend.cpp (287104 => 287105)
--- trunk/Tools/wpe/backends/ViewBackend.cpp 2021-12-15 21:26:53 UTC (rev 287104)
+++ trunk/Tools/wpe/backends/ViewBackend.cpp 2021-12-15 21:32:07 UTC (rev 287105)
@@ -25,110 +25,8 @@
#include "ViewBackend.h"
-#include <epoxy/egl.h>
-#include <glib.h>
-#include <wpe/fdo-egl.h>
-
-#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
-#include "WebKitAccessibleApplication.h"
-#include <atk-bridge.h>
-#include <atk/atk.h>
-#endif
-
namespace WPEToolingBackends {
-#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
-static GHashTable* keyEventListeners;
-
-struct KeyEventListener {
- AtkKeySnoopFunc function;
- gpointer userData;
-};
-
-static unsigned addKeyEventListener(AtkKeySnoopFunc function, gpointer userData)
-{
- if (!keyEventListeners) {
- keyEventListeners = g_hash_table_new_full(g_direct_hash, g_direct_equal, nullptr, [](gpointer data) {
- delete static_cast<KeyEventListener*>(data);
- });
- }
-
- static unsigned key = 0;
- key++;
- g_hash_table_insert(keyEventListeners, GUINT_TO_POINTER(key), new KeyEventListener { function, userData });
-
- return key;
-}
-
-static void removeKeyEventListener(unsigned key)
-{
- if (!keyEventListeners)
- return;
-
- g_hash_table_remove(keyEventListeners, GUINT_TO_POINTER(key));
-}
-
-static void notifyAccessibilityKeyEventListeners(struct wpe_input_keyboard_event* event)
-{
- if (!keyEventListeners)
- return;
-
- AtkKeyEventStruct atkEvent;
- atkEvent.type = event->pressed ? ATK_KEY_EVENT_PRESS : ATK_KEY_EVENT_RELEASE;
- atkEvent.state = event->modifiers;
- atkEvent.keyval = event->key_code;
- atkEvent.keycode = event->hardware_key_code;
- atkEvent.timestamp = event->time;
-
- atkEvent.string = nullptr;
- switch (atkEvent.keyval) {
- case WPE_KEY_ISO_Enter:
- case WPE_KEY_KP_Enter:
- case WPE_KEY_Return:
- atkEvent.string = g_strdup("\r");
- atkEvent.length = 1;
- break;
- case WPE_KEY_BackSpace:
- atkEvent.string = g_strdup("\x8");
- atkEvent.length = 1;
- break;
- case WPE_KEY_Tab:
- atkEvent.string = g_strdup("\t");
- atkEvent.length = 1;
- break;
- default:
- break;
- }
-
- if (!atkEvent.string) {
- auto unicodeCharacter = wpe_key_code_to_unicode(atkEvent.keyval);
- if (unicodeCharacter) {
- char buffer[7];
- int length = g_unichar_to_utf8(unicodeCharacter, buffer);
- buffer[length] = '\0';
- size_t bytesWritten;
- atkEvent.string = g_locale_from_utf8(buffer, length, nullptr, &bytesWritten, nullptr);
- atkEvent.length = bytesWritten;
- }
- }
-
- if (!atkEvent.string) {
- atkEvent.length = 0;
- atkEvent.string = g_strdup("");
- }
-
- GHashTableIter iter;
- gpointer value;
- g_hash_table_iter_init(&iter, keyEventListeners);
- while (g_hash_table_iter_next(&iter, nullptr, &value)) {
- auto* listener = static_cast<KeyEventListener*>(value);
- listener->function(&atkEvent, listener->userData);
- }
-
- g_free(atkEvent.string);
-}
-#endif
-
ViewBackend::ViewBackend(uint32_t width, uint32_t height)
: m_width(width)
, m_height(height)
@@ -138,60 +36,15 @@
ViewBackend::~ViewBackend() = default;
-
+#if !(defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY)
void ViewBackend::initializeAccessibility()
{
-#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
- auto* atkUtilClass = ATK_UTIL_CLASS(g_type_class_ref(ATK_TYPE_UTIL));
- atkUtilClass->add_key_event_listener = [](AtkKeySnoopFunc listener, gpointer userData) -> guint {
- return addKeyEventListener(listener, userData);
- };
-
- atkUtilClass->remove_key_event_listener = [](guint key) {
- removeKeyEventListener(key);
- };
-
- atkUtilClass->get_root = []() -> AtkObject* {
- static AtkObject* accessible = nullptr;
- if (!accessible)
- accessible = ATK_OBJECT(webkitAccessibleApplicationNew());
- return accessible;
- };
-
- atkUtilClass->get_toolkit_name = []() -> const gchar* {
- return "WPEWebKit";
- };
-
- atkUtilClass->get_toolkit_version = []() -> const gchar* {
- return "";
- };
-
- atk_bridge_adaptor_init(nullptr, nullptr);
-#endif
}
void ViewBackend::updateAccessibilityState(uint32_t previousFlags)
{
-#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
- auto* accessible = atk_get_root();
- if (!WEBKIT_IS_ACCESSIBLE_APPLICATION(accessible))
- return;
-
- uint32_t flags = wpe_view_backend_get_activity_state(backend());
- uint32_t changedFlags = previousFlags ^ flags;
- if (changedFlags & wpe_view_activity_state_in_window)
- atk_object_notify_state_change(accessible, ATK_STATE_ACTIVE, flags & wpe_view_activity_state_in_window);
- if (changedFlags & wpe_view_activity_state_visible)
- atk_object_notify_state_change(accessible, ATK_STATE_VISIBLE, flags & wpe_view_activity_state_visible);
- if (changedFlags & wpe_view_activity_state_focused) {
- atk_object_notify_state_change(accessible, ATK_STATE_FOCUSED, flags & wpe_view_activity_state_focused);
- if ((flags & wpe_view_activity_state_in_window) && (flags & wpe_view_activity_state_focused))
- g_signal_emit_by_name(accessible, "activate");
- else
- g_signal_emit_by_name(accessible, "deactivate");
- }
-#endif
}
+#endif // !HAVE(ACCESSIBILITY)
void ViewBackend::setInputClient(std::unique_ptr<InputClient>&& client)
{
@@ -198,17 +51,6 @@
m_inputClient = std::move(client);
}
-#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
-void ViewBackend::setAccessibleChild(AtkObject* child)
-{
- auto* accessible = atk_get_root();
- if (!WEBKIT_IS_ACCESSIBLE_APPLICATION(accessible))
- return;
-
- webkitAccessibleApplicationSetChild(WEBKIT_ACCESSIBLE_APPLICATION(accessible), child);
-}
-#endif
-
void ViewBackend::addActivityState(uint32_t flags)
{
uint32_t previousFlags = wpe_view_backend_get_activity_state(backend());
Modified: trunk/Tools/wpe/backends/ViewBackend.h (287104 => 287105)
--- trunk/Tools/wpe/backends/ViewBackend.h 2021-12-15 21:26:53 UTC (rev 287104)
+++ trunk/Tools/wpe/backends/ViewBackend.h 2021-12-15 21:32:07 UTC (rev 287105)
@@ -28,10 +28,13 @@
#include <memory>
#include <wpe/fdo.h>
+#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
+typedef struct _AtkObject AtkObject;
+#endif
+
typedef void* EGLConfig;
typedef void* EGLContext;
typedef void* EGLDisplay;
-typedef struct _AtkObject AtkObject;
struct wpe_fdo_egl_exported_image;
#if WPE_FDO_CHECK_VERSION(1, 5, 0)
@@ -73,6 +76,9 @@
void initializeAccessibility();
void updateAccessibilityState(uint32_t);
+#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
+ static void notifyAccessibilityKeyEventListeners(struct wpe_input_keyboard_event* event);
+#endif
void dispatchInputPointerEvent(struct wpe_input_pointer_event*);
void dispatchInputAxisEvent(struct wpe_input_axis_event*);
Deleted: trunk/Tools/wpe/backends/WebKitAccessibleApplication.cpp (287104 => 287105)
--- trunk/Tools/wpe/backends/WebKitAccessibleApplication.cpp 2021-12-15 21:26:53 UTC (rev 287104)
+++ trunk/Tools/wpe/backends/WebKitAccessibleApplication.cpp 2021-12-15 21:32:07 UTC (rev 287105)
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2019 Igalia S.L.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "WebKitAccessibleApplication.h"
-
-#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
-
-struct _WebKitAccessibleApplicationPrivate {
- AtkObject* child;
-};
-
-static void webkitAccessibleApplicationWindowInterfaceInit(AtkWindowIface*)
-{
-}
-
-G_DEFINE_TYPE_WITH_CODE(WebKitAccessibleApplication, webkit_accessible_application, ATK_TYPE_OBJECT,
- G_ADD_PRIVATE(WebKitAccessibleApplication)
- G_IMPLEMENT_INTERFACE(ATK_TYPE_WINDOW, webkitAccessibleApplicationWindowInterfaceInit))
-
-static void webkitAccessibleApplicationFinalize(GObject* object)
-{
- auto* accessible = WEBKIT_ACCESSIBLE_APPLICATION(object);
- webkitAccessibleApplicationSetChild(accessible, nullptr);
-
- G_OBJECT_CLASS(webkit_accessible_application_parent_class)->finalize(object);
-}
-
-static void webkitAccessibleApplicationInitialize(AtkObject* atkObject, gpointer data)
-{
- ATK_OBJECT_CLASS(webkit_accessible_application_parent_class)->initialize(atkObject, data);
- atkObject->role = ATK_ROLE_APPLICATION;
- atkObject->accessible_parent = nullptr;
-}
-
-static gint webkitAccessibleApplicationGetNChildren(AtkObject* atkObject)
-{
- auto* accessible = WEBKIT_ACCESSIBLE_APPLICATION(atkObject);
- return accessible->priv->child ? 1 : 0;
-}
-
-static AtkObject* webkitAccessibleApplicationRefChild(AtkObject* atkObject, int i)
-{
- if (i)
- return nullptr;
-
- auto* accessible = WEBKIT_ACCESSIBLE_APPLICATION(atkObject);
- return accessible->priv->child ? ATK_OBJECT(g_object_ref(accessible->priv->child)) : nullptr;
-}
-
-static const char* webkitAccessibleApplicationGetName(AtkObject*)
-{
- return g_get_prgname();
-}
-
-static void webkit_accessible_application_class_init(WebKitAccessibleApplicationClass* klass)
-{
- GObjectClass* gobjectClass = G_OBJECT_CLASS(klass);
- gobjectClass->finalize = webkitAccessibleApplicationFinalize;
-
- AtkObjectClass* atkObjectClass = ATK_OBJECT_CLASS(klass);
- atkObjectClass->initialize = webkitAccessibleApplicationInitialize;
- atkObjectClass->get_n_children = webkitAccessibleApplicationGetNChildren;
- atkObjectClass->ref_child = webkitAccessibleApplicationRefChild;
- atkObjectClass->get_name = webkitAccessibleApplicationGetName;
- atkObjectClass->get_parent = nullptr;
-}
-
-static void webkit_accessible_application_init(WebKitAccessibleApplication* accessible)
-{
- accessible->priv = static_cast<WebKitAccessibleApplicationPrivate*>(webkit_accessible_application_get_instance_private(accessible));
-}
-
-WebKitAccessibleApplication* webkitAccessibleApplicationNew()
-{
- auto* accessible = ATK_OBJECT(g_object_new(WEBKIT_TYPE_ACCESSIBLE_APPLICATION, nullptr));
- atk_object_initialize(accessible, nullptr);
- return WEBKIT_ACCESSIBLE_APPLICATION(accessible);
-}
-
-void webkitAccessibleApplicationSetChild(WebKitAccessibleApplication* accessible, AtkObject* child)
-{
- g_return_if_fail(WEBKIT_IS_ACCESSIBLE_APPLICATION(accessible));
-
- if (accessible->priv->child == child)
- return;
-
- if (accessible->priv->child) {
- g_signal_emit_by_name(accessible, "children-changed::remove", 0, accessible->priv->child);
- atk_object_set_parent(accessible->priv->child, nullptr);
- }
-
- accessible->priv->child = child;
-
- if (accessible->priv->child) {
- atk_object_set_parent(child, ATK_OBJECT(accessible));
- g_signal_emit_by_name(accessible, "children-changed::add", 0, child);
- }
-}
-
-#endif // HAVE(ACCESSIBILITY)
Deleted: trunk/Tools/wpe/backends/WebKitAccessibleApplication.h (287104 => 287105)
--- trunk/Tools/wpe/backends/WebKitAccessibleApplication.h 2021-12-15 21:26:53 UTC (rev 287104)
+++ trunk/Tools/wpe/backends/WebKitAccessibleApplication.h 2021-12-15 21:32:07 UTC (rev 287105)
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2019 Igalia S.L.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
-
-#include <atk/atk.h>
-
-G_BEGIN_DECLS
-
-#define WEBKIT_TYPE_ACCESSIBLE_APPLICATION (webkit_accessible_application_get_type())
-#define WEBKIT_ACCESSIBLE_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_ACCESSIBLE_APPLICATION, WebKitAccessibleApplication))
-#define WEBKIT_IS_ACCESSIBLE_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_ACCESSIBLE_APPLICATION))
-#define WEBKIT_ACCESSIBLE_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_ACCESSIBLE_APPLICATION, WebKitAccessibleApplicationClass))
-#define WEBKIT_IS_ACCESSIBLE_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_ACCESSIBLE_APPLICATION))
-#define WEBKIT_ACCESSIBLE_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_ACCESSIBLE_APPLICATION, WebKitAccessibleApplicationClass))
-
-typedef struct _WebKitAccessibleApplication WebKitAccessibleApplication;
-typedef struct _WebKitAccessibleApplicationClass WebKitAccessibleApplicationClass;
-typedef struct _WebKitAccessibleApplicationPrivate WebKitAccessibleApplicationPrivate;
-
-struct _WebKitAccessibleApplication {
- AtkObject parent;
-
- WebKitAccessibleApplicationPrivate *priv;
-};
-
-struct _WebKitAccessibleApplicationClass {
- AtkObjectClass parent;
-};
-
-GType webkit_accessible_application_get_type(void);
-
-WebKitAccessibleApplication* webkitAccessibleApplicationNew(void);
-void webkitAccessibleApplicationSetChild(WebKitAccessibleApplication*, AtkObject*);
-
-G_END_DECLS
-
-#endif // HAVE(ACCESSIBILITY)
Copied: trunk/Tools/wpe/backends/atk/ViewBackendAtk.cpp (from rev 287104, trunk/Tools/wpe/backends/ViewBackend.cpp) (0 => 287105)
--- trunk/Tools/wpe/backends/atk/ViewBackendAtk.cpp (rev 0)
+++ trunk/Tools/wpe/backends/atk/ViewBackendAtk.cpp 2021-12-15 21:32:07 UTC (rev 287105)
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "ViewBackend.h"
+
+#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
+
+#include "WebKitAccessibleApplication.h"
+#include <atk-bridge.h>
+#include <atk/atk.h>
+#include <glib.h>
+
+namespace WPEToolingBackends {
+
+static GHashTable* keyEventListeners;
+
+struct KeyEventListener {
+ AtkKeySnoopFunc function;
+ gpointer userData;
+};
+
+static unsigned addKeyEventListener(AtkKeySnoopFunc function, gpointer userData)
+{
+ if (!keyEventListeners) {
+ keyEventListeners = g_hash_table_new_full(g_direct_hash, g_direct_equal, nullptr, [](gpointer data) {
+ delete static_cast<KeyEventListener*>(data);
+ });
+ }
+
+ static unsigned key = 0;
+ key++;
+ g_hash_table_insert(keyEventListeners, GUINT_TO_POINTER(key), new KeyEventListener { function, userData });
+
+ return key;
+}
+
+static void removeKeyEventListener(unsigned key)
+{
+ if (!keyEventListeners)
+ return;
+
+ g_hash_table_remove(keyEventListeners, GUINT_TO_POINTER(key));
+}
+
+void ViewBackend::notifyAccessibilityKeyEventListeners(struct wpe_input_keyboard_event* event)
+{
+ if (!keyEventListeners)
+ return;
+
+ AtkKeyEventStruct atkEvent;
+ atkEvent.type = event->pressed ? ATK_KEY_EVENT_PRESS : ATK_KEY_EVENT_RELEASE;
+ atkEvent.state = event->modifiers;
+ atkEvent.keyval = event->key_code;
+ atkEvent.keycode = event->hardware_key_code;
+ atkEvent.timestamp = event->time;
+
+ atkEvent.string = nullptr;
+ switch (atkEvent.keyval) {
+ case WPE_KEY_ISO_Enter:
+ case WPE_KEY_KP_Enter:
+ case WPE_KEY_Return:
+ atkEvent.string = g_strdup("\r");
+ atkEvent.length = 1;
+ break;
+ case WPE_KEY_BackSpace:
+ atkEvent.string = g_strdup("\x8");
+ atkEvent.length = 1;
+ break;
+ case WPE_KEY_Tab:
+ atkEvent.string = g_strdup("\t");
+ atkEvent.length = 1;
+ break;
+ default:
+ break;
+ }
+
+ if (!atkEvent.string) {
+ auto unicodeCharacter = wpe_key_code_to_unicode(atkEvent.keyval);
+ if (unicodeCharacter) {
+ char buffer[7];
+ int length = g_unichar_to_utf8(unicodeCharacter, buffer);
+ buffer[length] = '\0';
+ size_t bytesWritten;
+ atkEvent.string = g_locale_from_utf8(buffer, length, nullptr, &bytesWritten, nullptr);
+ atkEvent.length = bytesWritten;
+ }
+ }
+
+ if (!atkEvent.string) {
+ atkEvent.length = 0;
+ atkEvent.string = g_strdup("");
+ }
+
+ GHashTableIter iter;
+ gpointer value;
+ g_hash_table_iter_init(&iter, keyEventListeners);
+ while (g_hash_table_iter_next(&iter, nullptr, &value)) {
+ auto* listener = static_cast<KeyEventListener*>(value);
+ listener->function(&atkEvent, listener->userData);
+ }
+
+ g_free(atkEvent.string);
+}
+
+void ViewBackend::initializeAccessibility()
+{
+ auto* atkUtilClass = ATK_UTIL_CLASS(g_type_class_ref(ATK_TYPE_UTIL));
+ atkUtilClass->add_key_event_listener = [](AtkKeySnoopFunc listener, gpointer userData) -> guint {
+ return addKeyEventListener(listener, userData);
+ };
+
+ atkUtilClass->remove_key_event_listener = [](guint key) {
+ removeKeyEventListener(key);
+ };
+
+ atkUtilClass->get_root = []() -> AtkObject* {
+ static AtkObject* accessible = nullptr;
+ if (!accessible)
+ accessible = ATK_OBJECT(webkitAccessibleApplicationNew());
+ return accessible;
+ };
+
+ atkUtilClass->get_toolkit_name = []() -> const gchar* {
+ return "WPEWebKit";
+ };
+
+ atkUtilClass->get_toolkit_version = []() -> const gchar* {
+ return "";
+ };
+
+ atk_bridge_adaptor_init(nullptr, nullptr);
+}
+
+void ViewBackend::updateAccessibilityState(uint32_t previousFlags)
+{
+ auto* accessible = atk_get_root();
+ if (!WEBKIT_IS_ACCESSIBLE_APPLICATION(accessible))
+ return;
+
+ uint32_t flags = wpe_view_backend_get_activity_state(backend());
+ uint32_t changedFlags = previousFlags ^ flags;
+ if (changedFlags & wpe_view_activity_state_in_window)
+ atk_object_notify_state_change(accessible, ATK_STATE_ACTIVE, flags & wpe_view_activity_state_in_window);
+ if (changedFlags & wpe_view_activity_state_visible)
+ atk_object_notify_state_change(accessible, ATK_STATE_VISIBLE, flags & wpe_view_activity_state_visible);
+ if (changedFlags & wpe_view_activity_state_focused) {
+ atk_object_notify_state_change(accessible, ATK_STATE_FOCUSED, flags & wpe_view_activity_state_focused);
+ if ((flags & wpe_view_activity_state_in_window) && (flags & wpe_view_activity_state_focused))
+ g_signal_emit_by_name(accessible, "activate");
+ else
+ g_signal_emit_by_name(accessible, "deactivate");
+ }
+}
+
+void ViewBackend::setAccessibleChild(AtkObject* child)
+{
+ auto* accessible = atk_get_root();
+ if (!WEBKIT_IS_ACCESSIBLE_APPLICATION(accessible))
+ return;
+
+ webkitAccessibleApplicationSetChild(WEBKIT_ACCESSIBLE_APPLICATION(accessible), child);
+}
+
+} // namespace WPEToolingBackends
+
+#endif // HAVE(ACCESSIBILITY)
Copied: trunk/Tools/wpe/backends/atk/WebKitAccessibleApplication.cpp (from rev 287104, trunk/Tools/wpe/backends/WebKitAccessibleApplication.cpp) (0 => 287105)
--- trunk/Tools/wpe/backends/atk/WebKitAccessibleApplication.cpp (rev 0)
+++ trunk/Tools/wpe/backends/atk/WebKitAccessibleApplication.cpp 2021-12-15 21:32:07 UTC (rev 287105)
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2019 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "WebKitAccessibleApplication.h"
+
+#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
+
+struct _WebKitAccessibleApplicationPrivate {
+ AtkObject* child;
+};
+
+static void webkitAccessibleApplicationWindowInterfaceInit(AtkWindowIface*)
+{
+}
+
+G_DEFINE_TYPE_WITH_CODE(WebKitAccessibleApplication, webkit_accessible_application, ATK_TYPE_OBJECT,
+ G_ADD_PRIVATE(WebKitAccessibleApplication)
+ G_IMPLEMENT_INTERFACE(ATK_TYPE_WINDOW, webkitAccessibleApplicationWindowInterfaceInit))
+
+static void webkitAccessibleApplicationFinalize(GObject* object)
+{
+ auto* accessible = WEBKIT_ACCESSIBLE_APPLICATION(object);
+ webkitAccessibleApplicationSetChild(accessible, nullptr);
+
+ G_OBJECT_CLASS(webkit_accessible_application_parent_class)->finalize(object);
+}
+
+static void webkitAccessibleApplicationInitialize(AtkObject* atkObject, gpointer data)
+{
+ ATK_OBJECT_CLASS(webkit_accessible_application_parent_class)->initialize(atkObject, data);
+ atkObject->role = ATK_ROLE_APPLICATION;
+ atkObject->accessible_parent = nullptr;
+}
+
+static gint webkitAccessibleApplicationGetNChildren(AtkObject* atkObject)
+{
+ auto* accessible = WEBKIT_ACCESSIBLE_APPLICATION(atkObject);
+ return accessible->priv->child ? 1 : 0;
+}
+
+static AtkObject* webkitAccessibleApplicationRefChild(AtkObject* atkObject, int i)
+{
+ if (i)
+ return nullptr;
+
+ auto* accessible = WEBKIT_ACCESSIBLE_APPLICATION(atkObject);
+ return accessible->priv->child ? ATK_OBJECT(g_object_ref(accessible->priv->child)) : nullptr;
+}
+
+static const char* webkitAccessibleApplicationGetName(AtkObject*)
+{
+ return g_get_prgname();
+}
+
+static void webkit_accessible_application_class_init(WebKitAccessibleApplicationClass* klass)
+{
+ GObjectClass* gobjectClass = G_OBJECT_CLASS(klass);
+ gobjectClass->finalize = webkitAccessibleApplicationFinalize;
+
+ AtkObjectClass* atkObjectClass = ATK_OBJECT_CLASS(klass);
+ atkObjectClass->initialize = webkitAccessibleApplicationInitialize;
+ atkObjectClass->get_n_children = webkitAccessibleApplicationGetNChildren;
+ atkObjectClass->ref_child = webkitAccessibleApplicationRefChild;
+ atkObjectClass->get_name = webkitAccessibleApplicationGetName;
+ atkObjectClass->get_parent = nullptr;
+}
+
+static void webkit_accessible_application_init(WebKitAccessibleApplication* accessible)
+{
+ accessible->priv = static_cast<WebKitAccessibleApplicationPrivate*>(webkit_accessible_application_get_instance_private(accessible));
+}
+
+WebKitAccessibleApplication* webkitAccessibleApplicationNew()
+{
+ auto* accessible = ATK_OBJECT(g_object_new(WEBKIT_TYPE_ACCESSIBLE_APPLICATION, nullptr));
+ atk_object_initialize(accessible, nullptr);
+ return WEBKIT_ACCESSIBLE_APPLICATION(accessible);
+}
+
+void webkitAccessibleApplicationSetChild(WebKitAccessibleApplication* accessible, AtkObject* child)
+{
+ g_return_if_fail(WEBKIT_IS_ACCESSIBLE_APPLICATION(accessible));
+
+ if (accessible->priv->child == child)
+ return;
+
+ if (accessible->priv->child) {
+ g_signal_emit_by_name(accessible, "children-changed::remove", 0, accessible->priv->child);
+ atk_object_set_parent(accessible->priv->child, nullptr);
+ }
+
+ accessible->priv->child = child;
+
+ if (accessible->priv->child) {
+ atk_object_set_parent(child, ATK_OBJECT(accessible));
+ g_signal_emit_by_name(accessible, "children-changed::add", 0, child);
+ }
+}
+
+#endif // HAVE(ACCESSIBILITY)
Copied: trunk/Tools/wpe/backends/atk/WebKitAccessibleApplication.h (from rev 287104, trunk/Tools/wpe/backends/WebKitAccessibleApplication.h) (0 => 287105)
--- trunk/Tools/wpe/backends/atk/WebKitAccessibleApplication.h (rev 0)
+++ trunk/Tools/wpe/backends/atk/WebKitAccessibleApplication.h 2021-12-15 21:32:07 UTC (rev 287105)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2019 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if defined(HAVE_ACCESSIBILITY) && HAVE_ACCESSIBILITY
+
+#include <atk/atk.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_ACCESSIBLE_APPLICATION (webkit_accessible_application_get_type())
+#define WEBKIT_ACCESSIBLE_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_ACCESSIBLE_APPLICATION, WebKitAccessibleApplication))
+#define WEBKIT_IS_ACCESSIBLE_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_ACCESSIBLE_APPLICATION))
+#define WEBKIT_ACCESSIBLE_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_ACCESSIBLE_APPLICATION, WebKitAccessibleApplicationClass))
+#define WEBKIT_IS_ACCESSIBLE_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_ACCESSIBLE_APPLICATION))
+#define WEBKIT_ACCESSIBLE_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_ACCESSIBLE_APPLICATION, WebKitAccessibleApplicationClass))
+
+typedef struct _WebKitAccessibleApplication WebKitAccessibleApplication;
+typedef struct _WebKitAccessibleApplicationClass WebKitAccessibleApplicationClass;
+typedef struct _WebKitAccessibleApplicationPrivate WebKitAccessibleApplicationPrivate;
+
+struct _WebKitAccessibleApplication {
+ AtkObject parent;
+
+ WebKitAccessibleApplicationPrivate *priv;
+};
+
+struct _WebKitAccessibleApplicationClass {
+ AtkObjectClass parent;
+};
+
+GType webkit_accessible_application_get_type(void);
+
+WebKitAccessibleApplication* webkitAccessibleApplicationNew(void);
+void webkitAccessibleApplicationSetChild(WebKitAccessibleApplication*, AtkObject*);
+
+G_END_DECLS
+
+#endif // HAVE(ACCESSIBILITY)