Skip to content

Commit 8ce32ca

Browse files
committed
Bring back ATK support to WebKitTestRunner
1 parent 9b75a97 commit 8ce32ca

8 files changed

Lines changed: 2886 additions & 6 deletions

Tools/TestRunnerShared/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
set(TestRunnerShared_LIBRARY_TYPE OBJECT)
2+
set(TestRunnerShared_DEPENDENCIES TestRunnerSharedBindings)
3+
14
WEBKIT_FRAMEWORK_DECLARE(TestRunnerShared)
25

36
set(DumpRenderTree_BINDINGS_DIR ${TOOLS_DIR}/DumpRenderTree/Bindings)
@@ -55,8 +58,5 @@ GENERATE_BINDINGS(TestRunnerSharedBindings
5558
DESTINATION ${TestRunnerShared_DERIVED_SOURCES_DIR}
5659
GENERATOR DumpRenderTree)
5760

58-
set(TestRunnerShared_LIBRARY_TYPE OBJECT)
59-
set(TestRunnerShared_DEPENDENCIES TestRunnerSharedBindings)
60-
6161
WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS()
6262
WEBKIT_FRAMEWORK(TestRunnerShared)

Tools/WebKitTestRunner/InjectedBundle/AccessibilityController.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#include <wtf/RunLoop.h>
3939
#include <wtf/Threading.h>
4040

41+
#if USE(ATK)
42+
#include "AccessibilityNotificationHandlerAtk.h"
43+
#endif
44+
4145
namespace WTR {
4246

4347
#if USE(ATSPI)
@@ -96,6 +100,8 @@ class AccessibilityController : public JSWrappable {
96100

97101
#if PLATFORM(COCOA)
98102
RetainPtr<id> m_globalNotificationHandler;
103+
#elif USE(ATK)
104+
RefPtr<AccessibilityNotificationHandler> m_globalNotificationHandler;
99105
#elif USE(ATSPI)
100106
std::unique_ptr<AccessibilityNotificationHandler> m_globalNotificationHandler;
101107
#endif

Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ OBJC_CLASS NSArray;
4343
OBJC_CLASS NSString;
4444
#include <wtf/RetainPtr.h>
4545
using PlatformUIElement = id;
46+
#elif ENABLE(ACCESSIBILITY) && USE(ATK)
47+
#include "AccessibilityNotificationHandlerAtk.h"
48+
#include <atk/atk.h>
49+
#include <wtf/glib/GRefPtr.h>
50+
typedef GRefPtr<AtkObject> PlatformUIElement;
4651
#elif USE(ATSPI)
4752
namespace WebCore {
4853
class AccessibilityObjectAtspi;
@@ -248,15 +253,15 @@ class AccessibilityUIElement : public JSWrappable {
248253
RefPtr<AccessibilityUIElement> ariaOwnsElementAtIndex(unsigned);
249254
RefPtr<AccessibilityUIElement> ariaFlowToElementAtIndex(unsigned);
250255
RefPtr<AccessibilityUIElement> ariaControlsElementAtIndex(unsigned);
251-
#if PLATFORM(COCOA) || USE(ATSPI)
256+
#if PLATFORM(COCOA) || USE(ATSPI) || USE(ATK)
252257
RefPtr<AccessibilityUIElement> ariaDetailsElementAtIndex(unsigned);
253258
RefPtr<AccessibilityUIElement> ariaErrorMessageElementAtIndex(unsigned);
254259
#else
255260
RefPtr<AccessibilityUIElement> ariaDetailsElementAtIndex(unsigned) { return nullptr; }
256261
RefPtr<AccessibilityUIElement> ariaErrorMessageElementAtIndex(unsigned) { return nullptr; }
257262
#endif
258263

259-
#if USE(ATSPI)
264+
#if USE(ATSPI) || USE(ATK)
260265
RefPtr<AccessibilityUIElement> ariaLabelledByElementAtIndex(unsigned);
261266
RefPtr<AccessibilityUIElement> ariaDescribedByElementAtIndex(unsigned);
262267
RefPtr<AccessibilityUIElement> ariaOwnsReferencingElementAtIndex(unsigned);
@@ -442,7 +447,9 @@ class AccessibilityUIElement : public JSWrappable {
442447
void getChildren(Vector<RefPtr<AccessibilityUIElement> >&);
443448
void getChildrenWithRange(Vector<RefPtr<AccessibilityUIElement> >&, unsigned location, unsigned length);
444449

445-
#if USE(ATSPI)
450+
#if USE(ATK)
451+
RefPtr<AccessibilityNotificationHandler> m_notificationHandler;
452+
#elif USE(ATSPI)
446453
static RefPtr<AccessibilityController> s_controller;
447454
RefPtr<WebCore::AccessibilityObjectAtspi> m_element;
448455
std::unique_ptr<AccessibilityNotificationHandler> m_notificationHandler;
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright (C) 2012 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 are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
#include "config.h"
29+
#include "AccessibilityController.h"
30+
31+
#if ENABLE(ACCESSIBILITY) && USE(ATK)
32+
33+
#include "AccessibilityUIElement.h"
34+
#include "InjectedBundle.h"
35+
#include "InjectedBundlePage.h"
36+
37+
#include <WebKit/WKBundlePagePrivate.h>
38+
#include <atk/atk.h>
39+
#include <cstdio>
40+
#include <wtf/glib/GUniquePtr.h>
41+
#include <wtf/text/StringBuilder.h>
42+
43+
namespace WTR {
44+
45+
void AccessibilityController::resetToConsistentState()
46+
{
47+
m_globalNotificationHandler = nullptr;
48+
}
49+
50+
static AtkObject* childElementById(AtkObject* parent, const char* id)
51+
{
52+
if (!ATK_IS_OBJECT(parent))
53+
return nullptr;
54+
55+
bool parentFound = false;
56+
AtkAttributeSet* attributeSet = atk_object_get_attributes(parent);
57+
for (AtkAttributeSet* attributes = attributeSet; attributes; attributes = attributes->next) {
58+
AtkAttribute* attribute = static_cast<AtkAttribute*>(attributes->data);
59+
if (!strcmp(attribute->name, "html-id")) {
60+
if (!strcmp(attribute->value, id))
61+
parentFound = true;
62+
break;
63+
}
64+
}
65+
atk_attribute_set_free(attributeSet);
66+
67+
if (parentFound)
68+
return parent;
69+
70+
int childCount = atk_object_get_n_accessible_children(parent);
71+
for (int i = 0; i < childCount; i++) {
72+
AtkObject* result = childElementById(atk_object_ref_accessible_child(parent, i), id);
73+
if (ATK_IS_OBJECT(result))
74+
return result;
75+
}
76+
77+
return nullptr;
78+
}
79+
80+
RefPtr<AccessibilityUIElement> AccessibilityController::accessibleElementById(JSStringRef id)
81+
{
82+
AtkObject* root = ATK_OBJECT(WKAccessibilityRootObject(InjectedBundle::singleton().page()->page()));
83+
if (!root)
84+
return nullptr;
85+
86+
size_t bufferSize = JSStringGetMaximumUTF8CStringSize(id);
87+
GUniquePtr<gchar> idBuffer(static_cast<gchar*>(g_malloc(bufferSize)));
88+
JSStringGetUTF8CString(id, idBuffer.get(), bufferSize);
89+
90+
AtkObject* result = childElementById(root, idBuffer.get());
91+
if (ATK_IS_OBJECT(result))
92+
return AccessibilityUIElement::create(result);
93+
94+
return nullptr;
95+
}
96+
97+
JSRetainPtr<JSStringRef> AccessibilityController::platformName()
98+
{
99+
JSRetainPtr<JSStringRef> platformName(Adopt, JSStringCreateWithUTF8CString("atk"));
100+
return platformName;
101+
}
102+
103+
void AccessibilityController::injectAccessibilityPreference(JSStringRef domain, JSStringRef key, JSStringRef value)
104+
{
105+
}
106+
107+
Ref<AccessibilityUIElement> AccessibilityController::rootElement()
108+
{
109+
WKBundlePageRef page = InjectedBundle::singleton().page()->page();
110+
void* root = WKAccessibilityRootObject(page);
111+
112+
return AccessibilityUIElement::create(static_cast<AtkObject*>(root));
113+
}
114+
115+
RefPtr<AccessibilityUIElement> AccessibilityController::focusedElement()
116+
{
117+
WKBundlePageRef page = InjectedBundle::singleton().page()->page();
118+
void* root = WKAccessibilityFocusedObject(page);
119+
120+
if (!ATK_IS_OBJECT(root))
121+
return nullptr;
122+
123+
return AccessibilityUIElement::create(static_cast<AtkObject*>(root));
124+
}
125+
126+
bool AccessibilityController::addNotificationListener(JSValueRef functionCallback)
127+
{
128+
if (!functionCallback)
129+
return false;
130+
131+
// Only one global notification listener.
132+
if (!m_globalNotificationHandler)
133+
m_globalNotificationHandler = AccessibilityNotificationHandler::create();
134+
m_globalNotificationHandler->setNotificationFunctionCallback(functionCallback);
135+
136+
return true;
137+
}
138+
139+
bool AccessibilityController::removeNotificationListener()
140+
{
141+
// Programmers should not be trying to remove a listener that's already removed.
142+
ASSERT(m_globalNotificationHandler);
143+
144+
m_globalNotificationHandler = nullptr;
145+
return false;
146+
}
147+
148+
} // namespace WTR
149+
150+
#endif // ENABLE(ACCESSIBILITY) && USE(ATK)

0 commit comments

Comments
 (0)