Title: [286056] trunk
Revision
286056
Author
[email protected]
Date
2021-11-19 06:30:34 -0800 (Fri, 19 Nov 2021)

Log Message

[GTK][a11y] Add implementation of action interface when building with ATSPI
https://bugs.webkit.org/show_bug.cgi?id=232749

Reviewed by Adrian Perez de Castro.

Source/WebCore:

* SourcesGTK.txt:
* accessibility/atspi/AccessibilityObjectActionAtspi.cpp: Added.
(WebCore::AccessibilityObjectAtspi::actionName const):
(WebCore::AccessibilityObjectAtspi::localizedActionName const):
(WebCore::AccessibilityObjectAtspi::actionKeyBinding const):
(WebCore::AccessibilityObjectAtspi::doAction const):
* accessibility/atspi/AccessibilityObjectAtspi.cpp:
(WebCore::AccessibilityObjectAtspi::interfacesForObject):
(WebCore::AccessibilityObjectAtspi::path):
(WebCore::AccessibilityObjectAtspi::buildInterfaces const):
* accessibility/atspi/AccessibilityObjectAtspi.h:

Tools:

Add a unit test for the action interface and WTR implementation.

* TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp:
(testActionBasic):
(beforeAll):
* WebKitTestRunner/InjectedBundle/atspi/AccessibilityUIElementAtspi.cpp:
(WTR::AccessibilityUIElement::isPressActionSupported):
(WTR::AccessibilityUIElement::press):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (286055 => 286056)


--- trunk/Source/WebCore/ChangeLog	2021-11-19 13:35:55 UTC (rev 286055)
+++ trunk/Source/WebCore/ChangeLog	2021-11-19 14:30:34 UTC (rev 286056)
@@ -1,5 +1,24 @@
 2021-11-19  Carlos Garcia Campos  <[email protected]>
 
+        [GTK][a11y] Add implementation of action interface when building with ATSPI
+        https://bugs.webkit.org/show_bug.cgi?id=232749
+
+        Reviewed by Adrian Perez de Castro.
+
+        * SourcesGTK.txt:
+        * accessibility/atspi/AccessibilityObjectActionAtspi.cpp: Added.
+        (WebCore::AccessibilityObjectAtspi::actionName const):
+        (WebCore::AccessibilityObjectAtspi::localizedActionName const):
+        (WebCore::AccessibilityObjectAtspi::actionKeyBinding const):
+        (WebCore::AccessibilityObjectAtspi::doAction const):
+        * accessibility/atspi/AccessibilityObjectAtspi.cpp:
+        (WebCore::AccessibilityObjectAtspi::interfacesForObject):
+        (WebCore::AccessibilityObjectAtspi::path):
+        (WebCore::AccessibilityObjectAtspi::buildInterfaces const):
+        * accessibility/atspi/AccessibilityObjectAtspi.h:
+
+2021-11-19  Carlos Garcia Campos  <[email protected]>
+
         [GTK][a11y] Add implementation of hypertext interface when building with ATSPI
         https://bugs.webkit.org/show_bug.cgi?id=232708
 

Modified: trunk/Source/WebCore/SourcesGTK.txt (286055 => 286056)


--- trunk/Source/WebCore/SourcesGTK.txt	2021-11-19 13:35:55 UTC (rev 286055)
+++ trunk/Source/WebCore/SourcesGTK.txt	2021-11-19 14:30:34 UTC (rev 286056)
@@ -41,6 +41,7 @@
 
 accessibility/atspi/AccessibilityAtspi.cpp
 accessibility/atspi/AccessibilityObjectAtspi.cpp
+accessibility/atspi/AccessibilityObjectActionAtspi.cpp
 accessibility/atspi/AccessibilityObjectComponentAtspi.cpp
 accessibility/atspi/AccessibilityObjectHyperlinkAtspi.cpp
 accessibility/atspi/AccessibilityObjectHypertextAtspi.cpp

Added: trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectActionAtspi.cpp (0 => 286056)


--- trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectActionAtspi.cpp	                        (rev 0)
+++ trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectActionAtspi.cpp	2021-11-19 14:30:34 UTC (rev 286056)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2021 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "AccessibilityObjectAtspi.h"
+
+#if ENABLE(ACCESSIBILITY) && USE(ATSPI)
+
+#include "AccessibilityRootAtspi.h"
+#include <gio/gio.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+GDBusInterfaceVTable AccessibilityObjectAtspi::s_actionFunctions = {
+    // method_call
+    [](GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar* methodName, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer userData) {
+        RELEASE_ASSERT(!isMainThread());
+        auto atspiObject = Ref { *static_cast<AccessibilityObjectAtspi*>(userData) };
+        atspiObject->updateBackingStore();
+
+        if (!g_strcmp0(methodName, "GetDescription"))
+            g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", ""));
+        else if (!g_strcmp0(methodName, "GetName")) {
+            int index;
+            g_variant_get(parameters, "(i)", &index);
+            g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", !index ? atspiObject->actionName().utf8().data() : ""));
+        } else if (!g_strcmp0(methodName, "GetLocalizedName")) {
+            int index;
+            g_variant_get(parameters, "(i)", &index);
+            g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", !index ? atspiObject->localizedActionName().utf8().data() : ""));
+        } else if (!g_strcmp0(methodName, "GetKeyBinding")) {
+            int index;
+            g_variant_get(parameters, "(i)", &index);
+            g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", !index ? atspiObject->actionKeyBinding().utf8().data() : ""));
+        } else if (!g_strcmp0(methodName, "DoAction")) {
+            int index;
+            g_variant_get(parameters, "(i)", &index);
+            g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", !index ? atspiObject->doAction() : FALSE));
+        }
+    },
+    // get_property
+    [](GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar* propertyName, GError** error, gpointer userData) -> GVariant* {
+        RELEASE_ASSERT(!isMainThread());
+        auto atspiObject = Ref { *static_cast<AccessibilityObjectAtspi*>(userData) };
+        atspiObject->updateBackingStore();
+
+        if (!g_strcmp0(propertyName, "NActions"))
+            return g_variant_new_int32(1);
+
+        g_set_error(error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Unknown property '%s'", propertyName);
+        return nullptr;
+    },
+    // set_property,
+    nullptr,
+    // padding
+    nullptr
+};
+
+String AccessibilityObjectAtspi::actionName() const
+{
+    AXCoreObject* axObject = isMainThread() ? m_coreObject : m_axObject;
+    return axObject ? axObject->actionVerb() : String();
+}
+
+String AccessibilityObjectAtspi::localizedActionName() const
+{
+    return m_axObject ? m_axObject->localizedActionVerb() : String();
+}
+
+String AccessibilityObjectAtspi::actionKeyBinding() const
+{
+    return m_axObject ? m_axObject->accessKey() : String();
+}
+
+bool AccessibilityObjectAtspi::doAction() const
+{
+    return Accessibility::retrieveValueFromMainThread<bool>([this]() -> bool {
+        if (m_coreObject)
+            m_coreObject->updateBackingStore();
+
+        if (!m_coreObject)
+            return false;
+
+        return m_coreObject->performDefaultAction();
+    });
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(ACCESSIBILITY) && USE(ATSPI)

Modified: trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectAtspi.cpp (286055 => 286056)


--- trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectAtspi.cpp	2021-11-19 13:35:55 UTC (rev 286055)
+++ trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectAtspi.cpp	2021-11-19 14:30:34 UTC (rev 286056)
@@ -60,7 +60,7 @@
 
 OptionSet<AccessibilityObjectAtspi::Interface> AccessibilityObjectAtspi::interfacesForObject(AXCoreObject& coreObject)
 {
-    OptionSet<Interface> interfaces = { Interface::Accessible, Interface::Component };
+    OptionSet<Interface> interfaces = { Interface::Accessible, Interface::Component, Interface::Action };
 
     RenderObject* renderer = coreObject.isAccessibilityRenderObject() ? coreObject.renderer() : nullptr;
     if (coreObject.roleValue() == AccessibilityRole::StaticText || coreObject.roleValue() == AccessibilityRole::ColorWell)
@@ -483,6 +483,8 @@
             interfaces.append({ const_cast<GDBusInterfaceInfo*>(&webkit_hyperlink_interface), &s_hyperlinkFunctions });
         if (m_interfaces.contains(Interface::Hypertext))
             interfaces.append({ const_cast<GDBusInterfaceInfo*>(&webkit_hypertext_interface), &s_hypertextFunctions });
+        if (m_interfaces.contains(Interface::Action))
+            interfaces.append({ const_cast<GDBusInterfaceInfo*>(&webkit_action_interface), &s_actionFunctions });
         m_path = atspiRoot->atspi().registerObject(*this, WTFMove(interfaces));
     }
 
@@ -1115,6 +1117,8 @@
         g_variant_builder_add(builder, "s", webkit_hyperlink_interface.name);
     if (m_interfaces.contains(Interface::Hypertext))
         g_variant_builder_add(builder, "s", webkit_hypertext_interface.name);
+    if (m_interfaces.contains(Interface::Action))
+        g_variant_builder_add(builder, "s", webkit_action_interface.name);
 }
 
 void AccessibilityObjectAtspi::serialize(GVariantBuilder* builder) const

Modified: trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectAtspi.h (286055 => 286056)


--- trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectAtspi.h	2021-11-19 13:35:55 UTC (rev 286055)
+++ trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectAtspi.h	2021-11-19 14:30:34 UTC (rev 286056)
@@ -48,7 +48,8 @@
         Text = 1 << 2,
         Value = 1 << 3,
         Hyperlink = 1 << 4,
-        Hypertext = 1 << 5
+        Hypertext = 1 << 5,
+        Action = 1 << 6
     };
     const OptionSet<Interface>& interfaces() const { return m_interfaces; }
 
@@ -122,6 +123,9 @@
 
     WEBCORE_EXPORT URL url() const;
 
+    WEBCORE_EXPORT String actionName() const;
+    WEBCORE_EXPORT bool doAction() const;
+
 private:
     explicit AccessibilityObjectAtspi(AXCoreObject*);
 
@@ -161,6 +165,9 @@
     AccessibilityObjectAtspi* hyperlink(unsigned) const;
     std::optional<unsigned> hyperlinkIndex(unsigned) const;
 
+    String localizedActionName() const;
+    String actionKeyBinding() const;
+
     static OptionSet<Interface> interfacesForObject(AXCoreObject&);
 
     static GDBusInterfaceVTable s_accessibleFunctions;
@@ -169,6 +176,7 @@
     static GDBusInterfaceVTable s_valueFunctions;
     static GDBusInterfaceVTable s_hyperlinkFunctions;
     static GDBusInterfaceVTable s_hypertextFunctions;
+    static GDBusInterfaceVTable s_actionFunctions;
 
     AXCoreObject* m_axObject { nullptr };
     AXCoreObject* m_coreObject { nullptr };

Modified: trunk/Tools/ChangeLog (286055 => 286056)


--- trunk/Tools/ChangeLog	2021-11-19 13:35:55 UTC (rev 286055)
+++ trunk/Tools/ChangeLog	2021-11-19 14:30:34 UTC (rev 286056)
@@ -1,5 +1,21 @@
 2021-11-19  Carlos Garcia Campos  <[email protected]>
 
+        [GTK][a11y] Add implementation of action interface when building with ATSPI
+        https://bugs.webkit.org/show_bug.cgi?id=232749
+
+        Reviewed by Adrian Perez de Castro.
+
+        Add a unit test for the action interface and WTR implementation.
+
+        * TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp:
+        (testActionBasic):
+        (beforeAll):
+        * WebKitTestRunner/InjectedBundle/atspi/AccessibilityUIElementAtspi.cpp:
+        (WTR::AccessibilityUIElement::isPressActionSupported):
+        (WTR::AccessibilityUIElement::press):
+
+2021-11-19  Carlos Garcia Campos  <[email protected]>
+
         [GTK][a11y] Add implementation of hypertext interface when building with ATSPI
         https://bugs.webkit.org/show_bug.cgi?id=232708
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp (286055 => 286056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp	2021-11-19 13:35:55 UTC (rev 286055)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp	2021-11-19 14:30:34 UTC (rev 286056)
@@ -1884,6 +1884,61 @@
 #endif
 }
 
+static void testActionBasic(AccessibilityTest* test, gconstpointer)
+{
+    test->showInWindow(800, 600);
+    test->loadHtml(
+        "<html>"
+        "  <body>"
+        "    <p>This is <button accessKey='p'>button</button> and <a href=''>link</a> in a paragraph</p>"
+        "  </body>"
+        "</html>",
+        nullptr);
+    test->waitUntilLoadFinished();
+
+    auto testApp = test->findTestApplication();
+    g_assert_true(ATSPI_IS_ACCESSIBLE(testApp.get()));
+
+    auto documentWeb = test->findDocumentWeb(testApp.get());
+    g_assert_true(ATSPI_IS_ACCESSIBLE(documentWeb.get()));
+    g_assert_cmpint(atspi_accessible_get_child_count(documentWeb.get(), nullptr), ==, 1);
+
+    auto p = adoptGRef(atspi_accessible_get_child_at_index(documentWeb.get(), 0, nullptr));
+    g_assert_true(ATSPI_IS_ACTION(p.get()));
+    // Paragraph implements action interface, but it does nothing.
+    g_assert_cmpint(atspi_action_get_n_actions(ATSPI_ACTION(p.get()), nullptr), ==, 1);
+    GUniquePtr<char> name(atspi_action_get_action_name(ATSPI_ACTION(p.get()), 0, nullptr));
+    g_assert_cmpstr(name.get(), ==, "");
+    GUniquePtr<char> localizedName(atspi_action_get_localized_name(ATSPI_ACTION(p.get()), 0, nullptr));
+    g_assert_cmpstr(localizedName.get(), ==, "");
+    GUniquePtr<char> keyBinding(atspi_action_get_key_binding(ATSPI_ACTION(p.get()), 0, nullptr));
+    g_assert_cmpstr(keyBinding.get(), ==, "");
+
+    auto button = adoptGRef(atspi_accessible_get_child_at_index(p.get(), 0, nullptr));
+    g_assert_true(ATSPI_IS_ACTION(button.get()));
+    g_assert_cmpint(atspi_action_get_n_actions(ATSPI_ACTION(button.get()), nullptr), ==, 1);
+    name.reset(atspi_action_get_action_name(ATSPI_ACTION(button.get()), 0, nullptr));
+    g_assert_cmpstr(name.get(), ==, "press");
+#if USE(ATSPI)
+    localizedName.reset(atspi_action_get_localized_name(ATSPI_ACTION(button.get()), 0, nullptr));
+    g_assert_cmpstr(localizedName.get(), ==, "press");
+#endif
+    keyBinding.reset(atspi_action_get_key_binding(ATSPI_ACTION(button.get()), 0, nullptr));
+    g_assert_cmpstr(keyBinding.get(), ==, "p");
+
+    auto a = adoptGRef(atspi_accessible_get_child_at_index(p.get(), 1, nullptr));
+    g_assert_true(ATSPI_IS_ACTION(a.get()));
+    g_assert_cmpint(atspi_action_get_n_actions(ATSPI_ACTION(a.get()), nullptr), ==, 1);
+    name.reset(atspi_action_get_action_name(ATSPI_ACTION(a.get()), 0, nullptr));
+    g_assert_cmpstr(name.get(), ==, "jump");
+#if USE(ATSPI)
+    localizedName.reset(atspi_action_get_localized_name(ATSPI_ACTION(a.get()), 0, nullptr));
+    g_assert_cmpstr(localizedName.get(), ==, "jump");
+#endif
+    keyBinding.reset(atspi_action_get_key_binding(ATSPI_ACTION(a.get()), 0, nullptr));
+    g_assert_cmpstr(keyBinding.get(), ==, "");
+}
+
 void beforeAll()
 {
     AccessibilityTest::add("WebKitAccessibility", "accessible/basic-hierarchy", testAccessibleBasicHierarchy);
@@ -1907,6 +1962,7 @@
     AccessibilityTest::add("WebKitAccessibility", "value/basic", testValueBasic);
     AccessibilityTest::add("WebKitAccessibility", "hyperlink/basic", testHyperlinkBasic);
     AccessibilityTest::add("WebKitAccessibility", "hypertext/basic", testHypertextBasic);
+    AccessibilityTest::add("WebKitAccessibility", "action/basic", testActionBasic);
 }
 
 void afterAll()

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/atspi/AccessibilityUIElementAtspi.cpp (286055 => 286056)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/atspi/AccessibilityUIElementAtspi.cpp	2021-11-19 13:35:55 UTC (rev 286055)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/atspi/AccessibilityUIElementAtspi.cpp	2021-11-19 14:30:34 UTC (rev 286056)
@@ -794,7 +794,9 @@
 
 bool AccessibilityUIElement::isPressActionSupported()
 {
-    return false;
+    m_element->updateBackingStore();
+    auto name = m_element->actionName();
+    return name == "press" || name == "jump";
 }
 
 bool AccessibilityUIElement::isIncrementActionSupported()
@@ -1094,6 +1096,7 @@
 
 void AccessibilityUIElement::press()
 {
+    m_element->doAction();
 }
 
 void AccessibilityUIElement::setSelectedChild(AccessibilityUIElement* element) const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to