⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 287071 in webkit


Ignore:
Timestamp:
Dec 15, 2021, 6:15:06 AM (5 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK][a11y] Add support for loading events when building with ATSPI
https://bugs.webkit.org/show_bug.cgi?id=234344

Reviewed by Joanmarie Diggs.

Source/WebCore:

Emit document:load-complete, document:reload, document:load-stopped and object:state-changed:busy.

  • accessibility/atspi/AXObjectCacheAtspi.cpp:

(WebCore::AXObjectCache::frameLoadingEventPlatformNotification):

  • accessibility/atspi/AccessibilityAtspi.cpp:

(WebCore::AccessibilityAtspi::loadEvent):

  • accessibility/atspi/AccessibilityAtspi.h:
  • accessibility/atspi/AccessibilityObjectAtspi.cpp:

(WebCore::AccessibilityObjectAtspi::loadEvent):

  • accessibility/atspi/AccessibilityObjectAtspi.h:

Tools:

Add a test case to check loading events.

  • TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp:

(AccessibilityTest::shouldProcessEvent): Helper to make the filters conditions easier to read.
(AccessibilityTest::startEventMonitor): Make it possible to use the monitor without filtering events.
(testDocumentLoadEvents):
(beforeAll):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r287070 r287071  
     12021-12-15  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][a11y] Add support for loading events when building with ATSPI
     4        https://bugs.webkit.org/show_bug.cgi?id=234344
     5
     6        Reviewed by Joanmarie Diggs.
     7
     8        Emit document:load-complete, document:reload, document:load-stopped and object:state-changed:busy.
     9
     10        * accessibility/atspi/AXObjectCacheAtspi.cpp:
     11        (WebCore::AXObjectCache::frameLoadingEventPlatformNotification):
     12        * accessibility/atspi/AccessibilityAtspi.cpp:
     13        (WebCore::AccessibilityAtspi::loadEvent):
     14        * accessibility/atspi/AccessibilityAtspi.h:
     15        * accessibility/atspi/AccessibilityObjectAtspi.cpp:
     16        (WebCore::AccessibilityObjectAtspi::loadEvent):
     17        * accessibility/atspi/AccessibilityObjectAtspi.h:
     18
    1192021-12-15  Carlos Garcia Campos  <cgarcia@igalia.com>
    220
  • trunk/Source/WebCore/accessibility/atspi/AXObjectCacheAtspi.cpp

    r287020 r287071  
    306306}
    307307
    308 void AXObjectCache::frameLoadingEventPlatformNotification(AccessibilityObject* object, AXLoadingEvent loadingEvent)
    309 {
     308void AXObjectCache::frameLoadingEventPlatformNotification(AccessibilityObject* coreObject, AXLoadingEvent loadingEvent)
     309{
     310    RELEASE_ASSERT(isMainThread());
     311    if (!coreObject)
     312        return;
     313
     314    if (coreObject->roleValue() != AccessibilityRole::WebArea)
     315        return;
     316
     317    auto* wrapper = coreObject->wrapper();
     318    if (!wrapper)
     319        return;
     320
     321    switch (loadingEvent) {
     322    case AXObjectCache::AXLoadingStarted:
     323        wrapper->stateChanged("busy", true);
     324        break;
     325    case AXObjectCache::AXLoadingReloaded:
     326        wrapper->stateChanged("busy", true);
     327        wrapper->loadEvent("Reload");
     328        break;
     329    case AXObjectCache::AXLoadingFailed:
     330        wrapper->stateChanged("busy", false);
     331        wrapper->loadEvent("LoadStopped");
     332        break;
     333    case AXObjectCache::AXLoadingFinished:
     334        wrapper->stateChanged("busy", false);
     335        wrapper->loadEvent("LoadComplete");
     336        break;
     337    }
    310338}
    311339
  • trunk/Source/WebCore/accessibility/atspi/AccessibilityAtspi.cpp

    r287070 r287071  
    461461
    462462        g_dbus_connection_emit_signal(m_connection.get(), nullptr, atspiObject->path().utf8().data(), "org.a11y.atspi.Event.Object", "SelectionChanged",
     463            g_variant_new("(siiva{sv})", "", 0, 0, g_variant_new_string(""), nullptr), nullptr);
     464    });
     465}
     466
     467void AccessibilityAtspi::loadEvent(AccessibilityObjectAtspi& atspiObject, CString&& event)
     468{
     469    RELEASE_ASSERT(isMainThread());
     470    m_queue->dispatch([this, atspiObject = Ref { atspiObject }, event = WTFMove(event)] {
     471        if (!m_connection)
     472            return;
     473
     474        if (!shouldEmitSignal("Document", event.data()))
     475            return;
     476
     477        g_dbus_connection_emit_signal(m_connection.get(), nullptr, atspiObject->path().utf8().data(), "org.a11y.atspi.Event.Document", event.data(),
    463478            g_variant_new("(siiva{sv})", "", 0, 0, g_variant_new_string(""), nullptr), nullptr);
    464479    });
  • trunk/Source/WebCore/accessibility/atspi/AccessibilityAtspi.h

    r287070 r287071  
    7373    void selectionChanged(AccessibilityObjectAtspi&);
    7474
     75    void loadEvent(AccessibilityObjectAtspi&, CString&&);
     76
    7577    static const char* localizedRoleName(AccessibilityRole);
    7678
  • trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectAtspi.cpp

    r287070 r287071  
    12381238}
    12391239
     1240void AccessibilityObjectAtspi::loadEvent(const char* event)
     1241{
     1242    RELEASE_ASSERT(isMainThread());
     1243    m_root.atspi().loadEvent(*this, event);
     1244}
     1245
    12401246unsigned AccessibilityObjectAtspi::role() const
    12411247{
  • trunk/Source/WebCore/accessibility/atspi/AccessibilityObjectAtspi.h

    r287020 r287071  
    136136
    137137    WEBCORE_EXPORT String documentAttribute(const String&) const;
     138    void loadEvent(const char*);
    138139
    139140    WEBCORE_EXPORT unsigned selectionCount() const;
  • trunk/Tools/ChangeLog

    r287070 r287071  
     12021-12-15  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][a11y] Add support for loading events when building with ATSPI
     4        https://bugs.webkit.org/show_bug.cgi?id=234344
     5
     6        Reviewed by Joanmarie Diggs.
     7
     8        Add a test case to check loading events.
     9
     10        * TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp:
     11        (AccessibilityTest::shouldProcessEvent): Helper to make the filters conditions easier to read.
     12        (AccessibilityTest::startEventMonitor): Make it possible to use the monitor without filtering events.
     13        (testDocumentLoadEvents):
     14        (beforeAll):
     15
    1162021-12-15  Carlos Garcia Campos  <cgarcia@igalia.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestWebKitAccessibility.cpp

    r287070 r287071  
    115115    }
    116116
    117     void startEventMonitor(AtspiAccessible* source, Vector<CString>&& events)
     117    bool shouldProcessEvent(AtspiEvent* event)
     118    {
     119        // source = std::nullopt -> no filter.
     120        if (!m_eventMonitor.source)
     121            return true;
     122
     123        // source = nullptr -> filter by application.
     124        if (!m_eventMonitor.source.value())
     125            return accessibleApplicationIsTestProgram(event->source);
     126
     127        // source != nullptr -> filter by accessible.
     128        return m_eventMonitor.source.value() == event->source;
     129    }
     130
     131    void startEventMonitor(std::optional<AtspiAccessible*> source, Vector<CString>&& events)
    118132    {
    119133        m_eventMonitor.source = source;
     
    121135        m_eventMonitor.listener = adoptGRef(atspi_event_listener_new([](AtspiEvent* event, gpointer userData) {
    122136            auto* test = static_cast<AccessibilityTest*>(userData);
    123             if ((test->m_eventMonitor.source && event->source == test->m_eventMonitor.source)
    124                 || (!test->m_eventMonitor.source && accessibleApplicationIsTestProgram(event->source))) {
     137            if (test->shouldProcessEvent(event))
    125138                test->m_eventMonitor.events.append(static_cast<AtspiEvent*>(g_boxed_copy(ATSPI_TYPE_EVENT, event)));
    126             }
    127139        }, this, nullptr));
    128140
     
    176188        Vector<CString> eventTypes;
    177189        Vector<UniqueAtspiEvent> events;
    178         AtspiAccessible* source { nullptr };
     190        std::optional<AtspiAccessible*> source;
    179191    } m_eventMonitor;
    180192};
     
    21172129    g_assert_cmpstr(value.get(), ==, "Document attributes");
    21182130#endif
     2131}
     2132
     2133static void testDocumentLoadEvents(AccessibilityTest* test, gconstpointer)
     2134{
     2135    test->showInWindow();
     2136    test->loadURI("about:blank");
     2137    test->waitUntilLoadFinished();
     2138    test->startEventMonitor(std::nullopt, { "document:", "object:state-changed:busy" });
     2139    test->loadHtml(
     2140        "<html>"
     2141        "  <body>"
     2142        "    <p>Loading events test</p>"
     2143        "  </body>"
     2144        "</html>",
     2145        nullptr);
     2146    test->waitUntilLoadFinished();
     2147    auto events = test->stopEventMonitor(3);
     2148    g_assert_cmpuint(events.size(), ==, 3);
     2149    g_assert_cmpstr(events[0]->type, ==, "object:state-changed:busy");
     2150    g_assert_cmpuint(events[0]->detail1, ==, 1);
     2151    g_assert_cmpstr(events[1]->type, ==, "object:state-changed:busy");
     2152    g_assert_cmpuint(events[1]->detail1, ==, 0);
     2153    g_assert_false(events[0]->source == events[1]->source);
     2154    g_assert_true(ATSPI_IS_ACCESSIBLE(events[0]->source));
     2155    g_assert_cmpint(atspi_accessible_get_role(events[0]->source, nullptr), ==, ATSPI_ROLE_DOCUMENT_WEB);
     2156    g_assert_cmpstr(events[2]->type, ==, "document:load-complete");
     2157    g_assert_true(events[1]->source == events[2]->source);
     2158    g_assert_true(ATSPI_IS_ACCESSIBLE(events[1]->source));
     2159    g_assert_cmpint(atspi_accessible_get_role(events[1]->source, nullptr), ==, ATSPI_ROLE_DOCUMENT_WEB);
     2160    events = { };
     2161
     2162    test->startEventMonitor(std::nullopt, { "document:", "object:state-changed:busy" });
     2163    webkit_web_view_reload(test->m_webView);
     2164    test->waitUntilLoadFinished();
     2165    events = test->stopEventMonitor(4);
     2166    g_assert_cmpuint(events.size(), ==, 4);
     2167    g_assert_cmpstr(events[0]->type, ==, "object:state-changed:busy");
     2168    g_assert_cmpuint(events[0]->detail1, ==, 1);
     2169    g_assert_cmpstr(events[1]->type, ==, "document:reload");
     2170    g_assert_true(events[0]->source == events[1]->source);
     2171    g_assert_true(ATSPI_IS_ACCESSIBLE(events[0]->source));
     2172    g_assert_cmpint(atspi_accessible_get_role(events[0]->source, nullptr), ==, ATSPI_ROLE_DOCUMENT_WEB);
     2173    g_assert_cmpstr(events[2]->type, ==, "object:state-changed:busy");
     2174    g_assert_cmpuint(events[2]->detail1, ==, 0);
     2175    g_assert_false(events[1]->source == events[2]->source);
     2176    g_assert_cmpstr(events[3]->type, ==, "document:load-complete");
     2177    g_assert_true(events[2]->source == events[3]->source);
     2178    g_assert_true(ATSPI_IS_ACCESSIBLE(events[2]->source));
     2179    g_assert_cmpint(atspi_accessible_get_role(events[2]->source, nullptr), ==, ATSPI_ROLE_DOCUMENT_WEB);
     2180    events = { };
    21192181}
    21202182
     
    28202882    AccessibilityTest::add("WebKitAccessibility", "action/basic", testActionBasic);
    28212883    AccessibilityTest::add("WebKitAccessibility", "document/basic", testDocumentBasic);
     2884    AccessibilityTest::add("WebKitAccessibility", "document/load-events", testDocumentLoadEvents);
    28222885    AccessibilityTest::add("WebKitAccessibility", "image/basic", testImageBasic);
    28232886    AccessibilityTest::add("WebKitAccessibility", "selection/listbox", testSelectionListBox);
Note: See TracChangeset for help on using the changeset viewer.