Commit 8dea0ad0 authored by dmazzoni@google.com's avatar dmazzoni@google.com

AX: Layout tests would be easier to write if AccessibilityController could find an element by id

https://bugs.webkit.org/show_bug.cgi?id=97301

Reviewed by Chris Fleizach.

Source/WebCore:

Add a method to get the DOM "id" attribute from an accessible object, only for layout tests.

Makes existing test more cross-platform:
Tests: accessibility/aria-hidden-with-elements.html

* accessibility/mac/WebAccessibilityObjectWrapper.mm:
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]):

Tools:

Adds a new accessibleElementById method to AccessibilityController, to make it
easier to write cross-platform layout tests.

Implemented for Chromium and for Mac (DRT and WKTR).

* DumpRenderTree/AccessibilityController.cpp:
(getAccessibleElementByIdCallback):
(AccessibilityController::getJSClass):
* DumpRenderTree/AccessibilityController.h:
(AccessibilityController):
* DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
* DumpRenderTree/chromium/TestRunner/AccessibilityControllerChromium.cpp:
(AccessibilityController::AccessibilityController):
(AccessibilityController::findAccessibleElementByIdRecursive):
(AccessibilityController::getAccessibleElementById):
(AccessibilityController::accessibleElementByIdGetterCallback):
* DumpRenderTree/chromium/TestRunner/AccessibilityControllerChromium.h:
(AccessibilityController):
* DumpRenderTree/gtk/AccessibilityControllerGtk.cpp:
(AccessibilityController::accessibleElementById):
* DumpRenderTree/mac/AccessibilityCommonMac.h: added
* DumpRenderTree/mac/AccessibilityCommonMac.mm: added
(+[NSString stringWithJSStringRef:]):
(-[NSString createJSStringRef]):
* DumpRenderTree/mac/AccessibilityControllerMac.mm:
(findAccessibleObjectById):
(AccessibilityController::accessibleElementById):
* DumpRenderTree/mac/AccessibilityUIElementMac.mm:
* DumpRenderTree/win/AccessibilityControllerWin.cpp:
(AccessibilityController::accessibleElementById):
* WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
(WTR::AccessibilityController::accessibleElementById):
* WebKitTestRunner/InjectedBundle/AccessibilityController.h:
(AccessibilityController):
* WebKitTestRunner/InjectedBundle/Bindings/AccessibilityController.idl:
* WebKitTestRunner/InjectedBundle/mac/AccessibilityCommonMac.h: added
* WebKitTestRunner/InjectedBundle/mac/AccessibilityCommonMac.mm: added
(+[NSString stringWithJSStringRef:]):
(-[NSString createJSStringRef]):
* WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm:
(WTR::findAccessibleObjectById):
(WTR):
(WTR::AccessibilityController::accessibleElementById):
* WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
* WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:

LayoutTests:

Modifies an existing test to use the new accessibleElementById
method of AccessibilityController, enabling the test to pass on
both Mac and Chromium.

* accessibility/aria-hidden-with-elements.html:
* platform/chromium/TestExpectations:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@129308 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3d96f0b0
2012-09-22 Dominic Mazzoni <dmazzoni@google.com>
AX: Layout tests would be easier to write if AccessibilityController could find an element by id
https://bugs.webkit.org/show_bug.cgi?id=97301
Reviewed by Chris Fleizach.
Modifies an existing test to use the new accessibleElementById
method of AccessibilityController, enabling the test to pass on
both Mac and Chromium.
* accessibility/aria-hidden-with-elements.html:
* platform/chromium/TestExpectations:
2012-09-22 Csaba Osztrogonác <ossy@webkit.org>
[Qt] Unreviewed weekend gardening, unskip now passing tests.
......@@ -5,6 +5,8 @@
</head>
<body id="body">
<div id="container" aria-label="container">
<table border=1 summary="test" aria-hidden="true">
<tr><td>cell</td><td>cell</td><td>cell</td></tr>
<tr><td>cell</td><td>cell</td><td>cell</td></tr>
......@@ -19,13 +21,17 @@
<li>test
</ul>
<div aria-label="wrapper">
<select size=10 aria-hidden="true">
<option>option
<option>option
</select>
</div>
<h1>heading</h1>
</div>
<p id="description"></p>
<div id="console"></div>
......@@ -34,14 +40,14 @@
description("This tests that aria-hidden works as expected on elements that are subclasses of AccessibilityRenderObject");
if (window.accessibilityController) {
var root = accessibilityController.rootElement;
var container = accessibilityController.accessibleElementById("container");
// first child is an AXGroup that has no children
var child = root.childAtIndex(0).childAtIndex(0);
var child = container.childAtIndex(0);
shouldBe("child.childrenCount", "0");
// The second child we ask for from the web area should be the heading, and we should have skipped over everything else.
child = root.childAtIndex(0).childAtIndex(1);
child = container.childAtIndex(1);
shouldBe("child.role", "'AXRole: AXHeading'");
}
......
......@@ -1344,7 +1344,6 @@ crbug.com/10322 accessibility/aria-combobox.html [ Skip ]
crbug.com/10322 accessibility/aria-controls-with-tabs.html [ Skip ]
crbug.com/10322 accessibility/aria-fallback-roles.html [ Skip ]
crbug.com/10322 accessibility/aria-hidden-update.html [ Skip ]
crbug.com/10322 accessibility/aria-hidden-with-elements.html [ Skip ]
crbug.com/10322 accessibility/aria-invalid.html [ Skip ]
crbug.com/10322 accessibility/aria-labelledby-overrides-label.html [ Skip ]
crbug.com/10322 accessibility/aria-link-supports-press.html [ Skip ]
......
2012-09-22 Dominic Mazzoni <dmazzoni@google.com>
AX: Layout tests would be easier to write if AccessibilityController could find an element by id
https://bugs.webkit.org/show_bug.cgi?id=97301
Reviewed by Chris Fleizach.
Add a method to get the DOM "id" attribute from an accessible object, only for layout tests.
Makes existing test more cross-platform:
Tests: accessibility/aria-hidden-with-elements.html
* accessibility/mac/WebAccessibilityObjectWrapper.mm:
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]):
2012-09-22 Thierry Reding <thierry.reding@avionic-design.de>
[GTK] Build is broken with GLib Unicode backend
......@@ -2430,6 +2430,10 @@ static NSString* roleValueToNSString(AccessibilityRole value)
return @"normal";
}
}
// Used by DRT to find an accessible node by its element id.
if ([attributeName isEqualToString:@"AXDRTElementIdAttribute"])
return m_object->getAttribute(idAttr);
return nil;
}
......
2012-09-22 Dominic Mazzoni <dmazzoni@google.com>
AX: Layout tests would be easier to write if AccessibilityController could find an element by id
https://bugs.webkit.org/show_bug.cgi?id=97301
Reviewed by Chris Fleizach.
Adds a new accessibleElementById method to AccessibilityController, to make it
easier to write cross-platform layout tests.
Implemented for Chromium and for Mac (DRT and WKTR).
* DumpRenderTree/AccessibilityController.cpp:
(getAccessibleElementByIdCallback):
(AccessibilityController::getJSClass):
* DumpRenderTree/AccessibilityController.h:
(AccessibilityController):
* DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
* DumpRenderTree/chromium/TestRunner/AccessibilityControllerChromium.cpp:
(AccessibilityController::AccessibilityController):
(AccessibilityController::findAccessibleElementByIdRecursive):
(AccessibilityController::getAccessibleElementById):
(AccessibilityController::accessibleElementByIdGetterCallback):
* DumpRenderTree/chromium/TestRunner/AccessibilityControllerChromium.h:
(AccessibilityController):
* DumpRenderTree/gtk/AccessibilityControllerGtk.cpp:
(AccessibilityController::accessibleElementById):
* DumpRenderTree/mac/AccessibilityCommonMac.h: added
* DumpRenderTree/mac/AccessibilityCommonMac.mm: added
(+[NSString stringWithJSStringRef:]):
(-[NSString createJSStringRef]):
* DumpRenderTree/mac/AccessibilityControllerMac.mm:
(findAccessibleObjectById):
(AccessibilityController::accessibleElementById):
* DumpRenderTree/mac/AccessibilityUIElementMac.mm:
* DumpRenderTree/win/AccessibilityControllerWin.cpp:
(AccessibilityController::accessibleElementById):
* WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:
(WTR::AccessibilityController::accessibleElementById):
* WebKitTestRunner/InjectedBundle/AccessibilityController.h:
(AccessibilityController):
* WebKitTestRunner/InjectedBundle/Bindings/AccessibilityController.idl:
* WebKitTestRunner/InjectedBundle/mac/AccessibilityCommonMac.h: added
* WebKitTestRunner/InjectedBundle/mac/AccessibilityCommonMac.mm: added
(+[NSString stringWithJSStringRef:]):
(-[NSString createJSStringRef]):
* WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm:
(WTR::findAccessibleObjectById):
(WTR):
(WTR::AccessibilityController::accessibleElementById):
* WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
* WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
2012-09-22 Zan Dobersek <zandobersek@gmail.com>
Unexpected reftest passes are only reported when pixel testing is enabled
......@@ -97,6 +97,18 @@ static JSValueRef getElementAtPointCallback(JSContextRef context, JSObjectRef fu
return AccessibilityUIElement::makeJSAccessibilityUIElement(context, controller->elementAtPoint(x, y));
}
static JSValueRef getAccessibleElementByIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSStringRef idAttribute = 0;
if (argumentCount == 1)
idAttribute = JSValueToStringCopy(context, arguments[0], exception);
AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject));
JSValueRef result = AccessibilityUIElement::makeJSAccessibilityUIElement(context, controller->accessibleElementById(idAttribute));
if (idAttribute)
JSStringRelease(idAttribute);
return result;
}
static JSValueRef addNotificationListenerCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount != 1)
......@@ -123,6 +135,7 @@ JSClassRef AccessibilityController::getJSClass()
{ "logScrollingStartEvents", logScrollingStartEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "logAccessibilityEvents", logAccessibilityEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "elementAtPoint", getElementAtPointCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "accessibleElementById", getAccessibleElementByIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "addNotificationListener", addNotificationListenerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "removeNotificationListener", removeNotificationListenerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ 0, 0, 0 }
......
......@@ -46,6 +46,7 @@ public:
AccessibilityUIElement rootElement();
AccessibilityUIElement focusedElement();
AccessibilityUIElement elementAtPoint(int x, int y);
AccessibilityUIElement accessibleElementById(JSStringRef id);
void setLogFocusEvents(bool);
void setLogValueChangeEvents(bool);
......
......@@ -116,6 +116,8 @@
BC0E24E00E2D9451001B6BC2 /* AccessibilityUIElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC0E24DE0E2D9451001B6BC2 /* AccessibilityUIElement.h */; };
BC0E24E10E2D9451001B6BC2 /* AccessibilityUIElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC0E24DF0E2D9451001B6BC2 /* AccessibilityUIElement.cpp */; };
BC0E26150E2DA4C6001B6BC2 /* AccessibilityUIElementMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC0E26140E2DA4C6001B6BC2 /* AccessibilityUIElementMac.mm */; };
BC0E24E00E2D9451001B6BC3 /* AccessibilityCommonMac.h in Headers */ = {isa = PBXBuildFile; fileRef = BC0E24DE0E2D9451001B6BC3 /* AccessibilityCommonMac.h */; };
BC0E26150E2DA4C6001B6BC3 /* AccessibilityCommonMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC0E26140E2DA4C6001B6BC3 /* AccessibilityCommonMac.mm */; };
BC47412A0D038A4C0072B006 /* JavaScriptThreading.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4741290D038A4C0072B006 /* JavaScriptThreading.h */; };
BC4741410D038A570072B006 /* JavaScriptThreadingPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC4741400D038A570072B006 /* JavaScriptThreadingPthreads.cpp */; };
BC9D90240C97472E0099A4A3 /* WorkQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC9D90210C97472D0099A4A3 /* WorkQueue.cpp */; };
......@@ -323,8 +325,10 @@
BC0131D80C9772010087317D /* TestRunner.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = TestRunner.cpp; sourceTree = "<group>"; };
BC0131D90C9772010087317D /* TestRunner.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = TestRunner.h; sourceTree = "<group>"; };
BC0E24DE0E2D9451001B6BC2 /* AccessibilityUIElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilityUIElement.h; sourceTree = "<group>"; };
BC0E24DE0E2D9451001B6BC3 /* AccessibilityCommonMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mac/AccessibilityCommonMac.h; sourceTree = "<group>"; };
BC0E24DF0E2D9451001B6BC2 /* AccessibilityUIElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityUIElement.cpp; sourceTree = "<group>"; };
BC0E26140E2DA4C6001B6BC2 /* AccessibilityUIElementMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityUIElementMac.mm; path = mac/AccessibilityUIElementMac.mm; sourceTree = "<group>"; };
BC0E26140E2DA4C6001B6BC3 /* AccessibilityCommonMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AccessibilityCommonMac.mm; path = mac/AccessibilityCommonMac.mm; sourceTree = "<group>"; };
BC4741290D038A4C0072B006 /* JavaScriptThreading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptThreading.h; sourceTree = "<group>"; };
BC4741400D038A570072B006 /* JavaScriptThreadingPthreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JavaScriptThreadingPthreads.cpp; path = pthreads/JavaScriptThreadingPthreads.cpp; sourceTree = "<group>"; };
BC646A4B136905DE00B35DED /* CompilerVersion.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = CompilerVersion.xcconfig; path = mac/Configurations/CompilerVersion.xcconfig; sourceTree = "<group>"; };
......@@ -503,6 +507,8 @@
BC0E24DF0E2D9451001B6BC2 /* AccessibilityUIElement.cpp */,
BC0E24DE0E2D9451001B6BC2 /* AccessibilityUIElement.h */,
BC0E26140E2DA4C6001B6BC2 /* AccessibilityUIElementMac.mm */,
BC0E26140E2DA4C6001B6BC3 /* AccessibilityCommonMac.h */,
BC0E26140E2DA4C6001B6BC3 /* AccessibilityCommonMac.mm */,
BCA18B360C9B021900114369 /* AppleScriptController.h */,
BCA18B370C9B021900114369 /* AppleScriptController.m */,
BCA18B6B0C9B08DB00114369 /* EventSendingController.h */,
......@@ -948,6 +954,7 @@
BCD08B710E1059D200A7D0C1 /* AccessibilityControllerMac.mm in Sources */,
BC0E24E10E2D9451001B6BC2 /* AccessibilityUIElement.cpp in Sources */,
BC0E26150E2DA4C6001B6BC2 /* AccessibilityUIElementMac.mm in Sources */,
BC0E26150E2DA4C6001B6BC3 /* AccessibilityCommonMac.mm in Sources */,
BCA18B390C9B021900114369 /* AppleScriptController.m in Sources */,
A8B91BFD0CF522B4008F91FF /* CheckedMalloc.cpp in Sources */,
53CBB832134E42F3001CE6A4 /* CyclicRedundancyCheck.cpp in Sources */,
......
......@@ -32,9 +32,11 @@
#include "AccessibilityControllerChromium.h"
#include "WebAccessibilityObject.h"
#include "WebElement.h"
#include "WebFrame.h"
#include "WebNode.h"
#include "WebView.h"
#include "platform/WebString.h"
#include "platform/WebCString.h"
using namespace WebKit;
......@@ -49,6 +51,8 @@ AccessibilityController::AccessibilityController()
bindProperty("focusedElement", &AccessibilityController::focusedElementGetterCallback);
bindProperty("rootElement", &AccessibilityController::rootElementGetterCallback);
bindMethod("accessibleElementById", &AccessibilityController::accessibleElementByIdGetterCallback);
bindFallbackMethod(&AccessibilityController::fallbackCallback);
}
......@@ -86,6 +90,36 @@ AccessibilityUIElement* AccessibilityController::getRootElement()
return m_elements.createRoot(m_rootElement);
}
AccessibilityUIElement* AccessibilityController::findAccessibleElementByIdRecursive(const WebAccessibilityObject& obj, const WebString& id)
{
if (obj.isNull() || obj.isDetached())
return 0;
WebNode node = obj.node();
if (!node.isNull() && node.isElementNode()) {
WebElement element = node.to<WebElement>();
element.getAttribute("id");
if (element.getAttribute("id") == id)
return m_elements.getOrCreate(obj);
}
unsigned childCount = obj.childCount();
for (unsigned i = 0; i < childCount; i++) {
if (AccessibilityUIElement* result = findAccessibleElementByIdRecursive(obj.childAt(i), id))
return result;
}
return 0;
}
AccessibilityUIElement* AccessibilityController::getAccessibleElementById(const std::string& id)
{
if (m_rootElement.isNull())
m_rootElement = m_webView->accessibilityObject();
return findAccessibleElementByIdRecursive(m_rootElement, WebString::fromUTF8(id.c_str()));
}
bool AccessibilityController::shouldLogAccessibilityEvents()
{
return m_logAccessibilityEvents;
......@@ -141,6 +175,21 @@ void AccessibilityController::rootElementGetterCallback(CppVariant* result)
result->set(*(getRootElement()->getAsCppVariant()));
}
void AccessibilityController::accessibleElementByIdGetterCallback(const CppArgumentList& arguments, CppVariant* result)
{
result->setNull();
if (arguments.size() < 1 || !arguments[0].isString())
return;
std::string id = arguments[0].toString();
AccessibilityUIElement* foundElement = getAccessibleElementById(id);
if (!foundElement)
return;
result->set(*(foundElement->getAsCppVariant()));
}
void AccessibilityController::fallbackCallback(const CppArgumentList&, CppVariant* result)
{
printf("CONSOLE MESSAGE: JavaScript ERROR: unknown method called on "
......
......@@ -51,6 +51,7 @@ public:
void setFocusedElement(const WebKit::WebAccessibilityObject&);
AccessibilityUIElement* getFocusedElement();
AccessibilityUIElement* getRootElement();
AccessibilityUIElement* getAccessibleElementById(const std::string& id);
bool shouldLogAccessibilityEvents();
......@@ -70,6 +71,9 @@ private:
void focusedElementGetterCallback(CppVariant*);
void rootElementGetterCallback(CppVariant*);
void accessibleElementByIdGetterCallback(const CppArgumentList&, CppVariant*);
AccessibilityUIElement* findAccessibleElementByIdRecursive(const WebKit::WebAccessibilityObject&, const WebKit::WebString& id);
WebKit::WebAccessibilityObject m_focusedElement;
WebKit::WebAccessibilityObject m_rootElement;
......
......@@ -70,6 +70,12 @@ AccessibilityUIElement AccessibilityController::rootElement()
return AccessibilityUIElement(accessible);
}
AccessibilityUIElement AccessibilityController::accessibleElementById(JSStringRef id)
{
// FIXME: implement
return 0;
}
void AccessibilityController::setLogFocusEvents(bool)
{
}
......
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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.
*/
#ifndef AccessibilityCommonMac_h
#define AccessibilityCommonMac_h
#import <JavaScriptCore/JSStringRef.h>
// If an unsupported attribute is passed in, it will raise an accessibility exception. These are usually caught by the Accessibility Runtime to inform
// the AX client app of the error. However, DRT is the AX client app, so it must catch these exceptions.
#define BEGIN_AX_OBJC_EXCEPTIONS @try {
#define END_AX_OBJC_EXCEPTIONS } @catch(NSException *e) { if (![[e name] isEqualToString:NSAccessibilityException]) @throw; }
@interface NSString (JSStringRefAdditions)
+ (NSString *)stringWithJSStringRef:(JSStringRef)jsStringRef;
- (JSStringRef)createJSStringRef;
@end
#endif // AccessibilityCommonMac_h
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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.
*/
#import "config.h"
#import "AccessibilityCommonMac.h"
#import <JavaScriptCore/JSStringRefCF.h>
@implementation NSString (JSStringRefAdditions)
+ (NSString *)stringWithJSStringRef:(JSStringRef)jsStringRef
{
if (!jsStringRef)
return nil;
CFStringRef cfString = JSStringCopyCFString(kCFAllocatorDefault, jsStringRef);
return [(NSString *)cfString autorelease];
}
- (JSStringRef)createJSStringRef
{
return JSStringCreateWithCFString((CFStringRef)self);
}
@end
......@@ -27,10 +27,13 @@
#import "DumpRenderTree.h"
#import "AccessibilityController.h"
#import "AccessibilityCommonMac.h"
#import "AccessibilityNotificationHandler.h"
#import "AccessibilityUIElement.h"
#import <AppKit/NSColor.h>
#import <Foundation/Foundation.h>
#import <JavaScriptCore/JSStringRef.h>
#import <JavaScriptCore/JSStringRefCF.h>
#import <WebKit/WebFrame.h>
#import <WebKit/WebFramePrivate.h>
#import <WebKit/WebHTMLView.h>
......@@ -68,6 +71,36 @@ AccessibilityUIElement AccessibilityController::rootElement()
return AccessibilityUIElement(accessibilityObject);
}
static id findAccessibleObjectById(id obj, NSString *idAttribute)
{
BEGIN_AX_OBJC_EXCEPTIONS
id objIdAttribute = [obj accessibilityAttributeValue:@"AXDRTElementIdAttribute"];
if ([objIdAttribute isKindOfClass:[NSString class]] && [objIdAttribute isEqualToString:idAttribute])
return obj;
END_AX_OBJC_EXCEPTIONS
NSArray *children = [obj accessibilityAttributeValue:NSAccessibilityChildrenAttribute];
NSUInteger childrenCount = [children count];
for (NSUInteger i = 0; i < childrenCount; ++i) {
id result = findAccessibleObjectById([children objectAtIndex:i], idAttribute);
if (result)
return result;
}
return 0;
}
AccessibilityUIElement AccessibilityController::accessibleElementById(JSStringRef idAttributeRef)
{
NSString *idAttribute = [NSString stringWithJSStringRef:idAttributeRef];
id root = [[mainFrame accessibilityRoot] accessibilityAttributeValue:NSAccessibilityParentAttribute];
id result = findAccessibleObjectById(root, idAttribute);
if (result)
return AccessibilityUIElement(result);
return 0;
}
void AccessibilityController::setLogFocusEvents(bool)
{
}
......
......@@ -25,6 +25,7 @@
#import "config.h"
#import "DumpRenderTree.h"
#import "AccessibilityCommonMac.h"
#import "AccessibilityNotificationHandler.h"
#import "AccessibilityUIElement.h"
......@@ -51,12 +52,6 @@
#define NSAccessibilityDropEffectsAttribute @"AXDropEffects"
#endif
// If an unsupported attribute is passed in, it will raise an accessibility exception. These are usually caught by the Accessibility Runtime to inform
// the AX client app of the error. However, DRT is the AX client app, so it must catch these exceptions.
#define BEGIN_AX_OBJC_EXCEPTIONS @try {
#define END_AX_OBJC_EXCEPTIONS } @catch(NSException *e) { if (![[e name] isEqualToString:NSAccessibilityException]) @throw; }
typedef void (*AXPostedNotificationCallback)(id element, NSString* notification, void* context);
@interface NSObject (WebKitAccessibilityAdditions)
......@@ -65,29 +60,6 @@ typedef void (*AXPostedNotificationCallback)(id element, NSString* notification,
- (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute;
@end
@interface NSString (JSStringRefAdditions)
+ (NSString *)stringWithJSStringRef:(JSStringRef)jsStringRef;
- (JSStringRef)createJSStringRef;
@end
@implementation NSString (JSStringRefAdditions)
+ (NSString *)stringWithJSStringRef:(JSStringRef)jsStringRef
{
if (!jsStringRef)
return NULL;
CFStringRef cfString = JSStringCopyCFString(kCFAllocatorDefault, jsStringRef);
return [(NSString *)cfString autorelease];
}
- (JSStringRef)createJSStringRef
{
return JSStringCreateWithCFString((CFStringRef)self);
}
@end
AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
: m_element(element)
, m_notificationHandler(0)
......
......@@ -67,6 +67,12 @@ AccessibilityUIElement AccessibilityController::elementAtPoint(int x, int y)
return 0;
}
AccessibilityUIElement AccessibilityController::accessibleElementById(JSStringRef id)
{
// FIXME: implement
return 0;
}
AccessibilityUIElement AccessibilityController::focusedElement()
{
COMPtr<IAccessible> rootAccessible = rootElement().platformUIElement();
......
......@@ -106,6 +106,7 @@ PassRefPtr<AccessibilityUIElement> AccessibilityController::elementAtPoint(int x
#if !PLATFORM(MAC)
bool AccessibilityController::addNotificationListener(JSValueRef) { return false; }
bool AccessibilityController::removeNotificationListener() { return false; }
PassRefPtr<AccessibilityUIElement> AccessibilityController::accessibleElementById(JSStringRef attribute) { return 0; }
#endif
#if !PLATFORM(GTK)
......
......@@ -48,6 +48,7 @@ public:
PassRefPtr<AccessibilityUIElement> rootElement();
PassRefPtr<AccessibilityUIElement> focusedElement();
PassRefPtr<AccessibilityUIElement> elementAtPoint(int x, int y);
PassRefPtr<AccessibilityUIElement> accessibleElementById(JSStringRef idAttribute);
bool addNotificationListener(JSValueRef functionCallback);
bool removeNotificationListener();
......
......@@ -29,6 +29,7 @@ module WTR {
readonly attribute AccessibilityUIElement rootElement;
readonly attribute AccessibilityUIElement focusedElement;
AccessibilityUIElement elementAtPoint(in int x, in int y);
AccessibilityUIElement accessibleElementById(in DOMString id);
boolean addNotificationListener(in object functionCallback);
boolean removeNotificationListener();
......
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT