1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573 |
- /*
- * Copyright (C) 2011 Apple 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:
- * 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. ``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
- * 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 "AccessibilityNotificationHandler.h"
- #import "AccessibilityUIElement.h"
- #import "InjectedBundle.h"
- #import "InjectedBundlePage.h"
- #import <AppKit/NSAccessibility.h>
- #import <Foundation/Foundation.h>
- #import <JavaScriptCore/JSRetainPtr.h>
- #import <JavaScriptCore/JSStringRef.h>
- #import <JavaScriptCore/JSStringRefCF.h>
- #import <JavaScriptCore/JSObjectRef.h>
- #import <WebKit2/WKBundleFrame.h>
- #import <wtf/RetainPtr.h>
- #import <wtf/Vector.h>
- #ifndef NSAccessibilityOwnsAttribute
- #define NSAccessibilityOwnsAttribute @"AXOwns"
- #endif
- #ifndef NSAccessibilityGrabbedAttribute
- #define NSAccessibilityGrabbedAttribute @"AXGrabbed"
- #endif
- #ifndef NSAccessibilityDropEffectsAttribute
- #define NSAccessibilityDropEffectsAttribute @"AXDropEffects"
- #endif
- #ifndef NSAccessibilityPathAttribute
- #define NSAccessibilityPathAttribute @"AXPath"
- #endif
- typedef void (*AXPostedNotificationCallback)(id element, NSString* notification, void* context);
- @interface NSObject (WebKitAccessibilityAdditions)
- - (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount;
- - (NSUInteger)accessibilityIndexOfChild:(id)child;
- - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute;
- @end
- namespace WTR {
- AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
- : m_element(element)
- , m_notificationHandler(0)
- {
- // FIXME: ap@webkit.org says ObjC objects need to be CFRetained/CFRelease to be GC-compliant on the mac.
- [m_element retain];
- }
- AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other)
- : JSWrappable()
- , m_element(other.m_element)
- , m_notificationHandler(0)
- {
- [m_element retain];
- }
- AccessibilityUIElement::~AccessibilityUIElement()
- {
- // The notification handler should be nil because removeNotificationListener() should have been called in the test.
- ASSERT(!m_notificationHandler);
- [m_element release];
- }
- bool AccessibilityUIElement::isEqual(AccessibilityUIElement* otherElement)
- {
- if (!otherElement)
- return false;
- return platformUIElement() == otherElement->platformUIElement();
- }
-
- static NSString* descriptionOfValue(id valueObject, id focusedAccessibilityObject)
- {
- if (!valueObject)
- return NULL;
- if ([valueObject isKindOfClass:[NSArray class]])
- return [NSString stringWithFormat:@"<array of size %lu>", static_cast<unsigned long>([(NSArray*)valueObject count])];
- if ([valueObject isKindOfClass:[NSNumber class]])
- return [(NSNumber*)valueObject stringValue];
- if ([valueObject isKindOfClass:[NSValue class]]) {
- NSString* type = [NSString stringWithCString:[valueObject objCType] encoding:NSASCIIStringEncoding];
- NSValue* value = (NSValue*)valueObject;
- if ([type rangeOfString:@"NSRect"].length > 0)
- return [NSString stringWithFormat:@"NSRect: %@", NSStringFromRect([value rectValue])];
- if ([type rangeOfString:@"NSPoint"].length > 0)
- return [NSString stringWithFormat:@"NSPoint: %@", NSStringFromPoint([value pointValue])];
- if ([type rangeOfString:@"NSSize"].length > 0)
- return [NSString stringWithFormat:@"NSSize: %@", NSStringFromSize([value sizeValue])];
- if ([type rangeOfString:@"NSRange"].length > 0)
- return [NSString stringWithFormat:@"NSRange: %@", NSStringFromRange([value rangeValue])];
- }
- // Strip absolute URL paths
- NSString* description = [valueObject description];
- NSRange range = [description rangeOfString:@"LayoutTests"];
- if (range.length)
- return [description substringFromIndex:range.location];
- // Strip pointer locations
- if ([description rangeOfString:@"0x"].length) {
- NSString* role = [focusedAccessibilityObject accessibilityAttributeValue:NSAccessibilityRoleAttribute];
- NSString* title = [focusedAccessibilityObject accessibilityAttributeValue:NSAccessibilityTitleAttribute];
- if ([title length])
- return [NSString stringWithFormat:@"<%@: '%@'>", role, title];
- return [NSString stringWithFormat:@"<%@>", role];
- }
-
- return [valueObject description];
- }
- static NSString* attributesOfElement(id accessibilityObject)
- {
- NSArray* supportedAttributes = [accessibilityObject accessibilityAttributeNames];
- NSMutableString* attributesString = [NSMutableString string];
- for (NSUInteger i = 0; i < [supportedAttributes count]; ++i) {
- NSString* attribute = [supportedAttributes objectAtIndex:i];
-
- // Right now, position provides useless and screen-specific information, so we do not
- // want to include it for the sake of universally passing tests.
- if ([attribute isEqualToString:@"AXPosition"])
- continue;
-
- // accessibilityAttributeValue: can throw an if an attribute is not returned.
- // For DumpRenderTree's purpose, we should ignore those exceptions
- BEGIN_AX_OBJC_EXCEPTIONS
- id valueObject = [accessibilityObject accessibilityAttributeValue:attribute];
- NSString* value = descriptionOfValue(valueObject, accessibilityObject);
- [attributesString appendFormat:@"%@: %@\n", attribute, value];
- END_AX_OBJC_EXCEPTIONS
- }
-
- return attributesString;
- }
- static JSStringRef concatenateAttributeAndValue(NSString* attribute, NSString* value)
- {
- Vector<UniChar> buffer([attribute length]);
- [attribute getCharacters:buffer.data()];
- buffer.append(':');
- buffer.append(' ');
- Vector<UniChar> valueBuffer([value length]);
- [value getCharacters:valueBuffer.data()];
- buffer.appendVector(valueBuffer);
- return JSStringCreateWithCharacters(buffer.data(), buffer.size());
- }
- static void convertNSArrayToVector(NSArray* array, Vector<RefPtr<AccessibilityUIElement> >& elementVector)
- {
- NSUInteger count = [array count];
- for (NSUInteger i = 0; i < count; ++i)
- elementVector.append(AccessibilityUIElement::create([array objectAtIndex:i]));
- }
- static JSStringRef descriptionOfElements(Vector<RefPtr<AccessibilityUIElement> >& elementVector)
- {
- NSMutableString* allElementString = [NSMutableString string];
- size_t size = elementVector.size();
- for (size_t i = 0; i < size; ++i) {
- RefPtr<AccessibilityUIElement> uiElement = elementVector[i];
- NSString* attributes = attributesOfElement(uiElement->platformUIElement());
- [allElementString appendFormat:@"%@\n------------\n", attributes];
- }
-
- return [allElementString createJSStringRef];
- }
- void AccessibilityUIElement::getLinkedUIElements(Vector<RefPtr<AccessibilityUIElement> >& elementVector)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* linkedElements = [m_element accessibilityAttributeValue:NSAccessibilityLinkedUIElementsAttribute];
- convertNSArrayToVector(linkedElements, elementVector);
- END_AX_OBJC_EXCEPTIONS
- }
- void AccessibilityUIElement::getDocumentLinks(Vector<RefPtr<AccessibilityUIElement> >& elementVector)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* linkElements = [m_element accessibilityAttributeValue:@"AXLinkUIElements"];
- convertNSArrayToVector(linkElements, elementVector);
- END_AX_OBJC_EXCEPTIONS
- }
- void AccessibilityUIElement::getChildren(Vector<RefPtr<AccessibilityUIElement> >& elementVector)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* children = [m_element accessibilityAttributeValue:NSAccessibilityChildrenAttribute];
- convertNSArrayToVector(children, elementVector);
- END_AX_OBJC_EXCEPTIONS
- }
- void AccessibilityUIElement::getChildrenWithRange(Vector<RefPtr<AccessibilityUIElement> >& elementVector, unsigned location, unsigned length)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* children = [m_element accessibilityArrayAttributeValues:NSAccessibilityChildrenAttribute index:location maxCount:length];
- convertNSArrayToVector(children, elementVector);
- END_AX_OBJC_EXCEPTIONS
- }
- int AccessibilityUIElement::childrenCount()
- {
- Vector<RefPtr<AccessibilityUIElement> > children;
- getChildren(children);
-
- return children.size();
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::elementAtPoint(int x, int y)
- {
- id element = [m_element accessibilityHitTest:NSMakePoint(x, y)];
- if (!element)
- return nil;
-
- return AccessibilityUIElement::create(element);
- }
- unsigned AccessibilityUIElement::indexOfChild(AccessibilityUIElement* element)
- {
- return [m_element accessibilityIndexOfChild:element->platformUIElement()];
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::childAtIndex(unsigned index)
- {
- Vector<RefPtr<AccessibilityUIElement> > children;
- getChildrenWithRange(children, index, 1);
- if (children.size() == 1)
- return children[0];
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::linkedUIElementAtIndex(unsigned index)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* objects = [m_element accessibilityAttributeValue:NSAccessibilityLinkedUIElementsAttribute];
- if (index < [objects count])
- return AccessibilityUIElement::create([objects objectAtIndex:index]);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::ariaOwnsElementAtIndex(unsigned index)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* objects = [m_element accessibilityAttributeValue:NSAccessibilityOwnsAttribute];
- if (index < [objects count])
- return AccessibilityUIElement::create([objects objectAtIndex:index]);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::ariaFlowToElementAtIndex(unsigned index)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* objects = [m_element accessibilityAttributeValue:NSAccessibilityLinkedUIElementsAttribute];
- if (index < [objects count])
- return AccessibilityUIElement::create([objects objectAtIndex:index]);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::disclosedRowAtIndex(unsigned index)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* rows = [m_element accessibilityAttributeValue:NSAccessibilityDisclosedRowsAttribute];
- if (index < [rows count])
- return AccessibilityUIElement::create([rows objectAtIndex:index]);
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
-
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::rowAtIndex(unsigned index)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* rows = [m_element accessibilityAttributeValue:NSAccessibilityRowsAttribute];
- if (index < [rows count])
- return AccessibilityUIElement::create([rows objectAtIndex:index]);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::selectedChildAtIndex(unsigned index) const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* array = [m_element accessibilityAttributeValue:NSAccessibilitySelectedChildrenAttribute];
- if (index < [array count])
- return AccessibilityUIElement::create([array objectAtIndex:index]);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- unsigned AccessibilityUIElement::selectedChildrenCount() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- return [m_element accessibilityArrayAttributeCount:NSAccessibilitySelectedChildrenAttribute];
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::selectedRowAtIndex(unsigned index)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* rows = [m_element accessibilityAttributeValue:NSAccessibilitySelectedRowsAttribute];
- if (index < [rows count])
- return AccessibilityUIElement::create([rows objectAtIndex:index]);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::titleUIElement()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id accessibilityObject = [m_element accessibilityAttributeValue:NSAccessibilityTitleUIElementAttribute];
- if (accessibilityObject)
- return AccessibilityUIElement::create(accessibilityObject);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::parentElement()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id accessibilityObject = [m_element accessibilityAttributeValue:NSAccessibilityParentAttribute];
- if (accessibilityObject)
- return AccessibilityUIElement::create(accessibilityObject);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::disclosedByRow()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id accessibilityObject = [m_element accessibilityAttributeValue:NSAccessibilityDisclosedByRowAttribute];
- if (accessibilityObject)
- return AccessibilityUIElement::create(accessibilityObject);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfLinkedUIElements()
- {
- Vector<RefPtr<AccessibilityUIElement> > linkedElements;
- getLinkedUIElements(linkedElements);
- return descriptionOfElements(linkedElements);
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfDocumentLinks()
- {
- Vector<RefPtr<AccessibilityUIElement> > linkElements;
- getDocumentLinks(linkElements);
- return descriptionOfElements(linkElements);
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfChildren()
- {
- Vector<RefPtr<AccessibilityUIElement> > children;
- getChildren(children);
- return descriptionOfElements(children);
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::allAttributes()
- {
- NSString* attributes = attributesOfElement(m_element);
- return [attributes createJSStringRef];
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::stringAttributeValue(JSStringRef attribute)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- double AccessibilityUIElement::numberAttributeValue(JSStringRef attribute)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
- if ([value isKindOfClass:[NSNumber class]])
- return [value doubleValue];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::uiElementAttributeValue(JSStringRef attribute) const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id uiElement = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
- return AccessibilityUIElement::create(uiElement);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
-
- bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- return [m_element accessibilityIsAttributeSettable:[NSString stringWithJSStringRef:attribute]];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- bool AccessibilityUIElement::isAttributeSupported(JSStringRef attribute)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- return [[m_element accessibilityAttributeNames] containsObject:[NSString stringWithJSStringRef:attribute]];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::parameterizedAttributeNames()
- {
- NSArray* supportedParameterizedAttributes = [m_element accessibilityParameterizedAttributeNames];
-
- NSMutableString* attributesString = [NSMutableString string];
- for (NSUInteger i = 0; i < [supportedParameterizedAttributes count]; ++i) {
- [attributesString appendFormat:@"%@\n", [supportedParameterizedAttributes objectAtIndex:i]];
- }
-
- return [attributesString createJSStringRef];
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::role()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSString *role = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityRoleAttribute], m_element);
- return concatenateAttributeAndValue(@"AXRole", role);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::subrole()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSString* role = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilitySubroleAttribute], m_element);
- return concatenateAttributeAndValue(@"AXSubrole", role);
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::roleDescription()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSString* role = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityRoleDescriptionAttribute], m_element);
- return concatenateAttributeAndValue(@"AXRoleDescription", role);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::title()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSString* title = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityTitleAttribute], m_element);
- return concatenateAttributeAndValue(@"AXTitle", title);
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::description()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id description = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityDescriptionAttribute], m_element);
- return concatenateAttributeAndValue(@"AXDescription", description);
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::orientation() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id description = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityOrientationAttribute], m_element);
- return concatenateAttributeAndValue(@"AXOrientation", description);
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::stringValue()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id description = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityValueAttribute], m_element);
- return concatenateAttributeAndValue(@"AXValue", description);
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::language()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id description = descriptionOfValue([m_element accessibilityAttributeValue:@"AXLanguage"], m_element);
- return concatenateAttributeAndValue(@"AXLanguage", description);
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::helpText() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id description = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityHelpAttribute], m_element);
- return concatenateAttributeAndValue(@"AXHelp", description);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- double AccessibilityUIElement::x()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSValue* positionValue = [m_element accessibilityAttributeValue:NSAccessibilityPositionAttribute];
- return static_cast<double>([positionValue pointValue].x);
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0f;
- }
- double AccessibilityUIElement::y()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSValue* positionValue = [m_element accessibilityAttributeValue:NSAccessibilityPositionAttribute];
- return static_cast<double>([positionValue pointValue].y);
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0f;
- }
- double AccessibilityUIElement::width()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSValue* sizeValue = [m_element accessibilityAttributeValue:NSAccessibilitySizeAttribute];
- return static_cast<double>([sizeValue sizeValue].width);
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0f;
- }
- double AccessibilityUIElement::height()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSValue* sizeValue = [m_element accessibilityAttributeValue:NSAccessibilitySizeAttribute];
- return static_cast<double>([sizeValue sizeValue].height);
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0f;
- }
- double AccessibilityUIElement::clickPointX()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSValue* positionValue = [m_element accessibilityAttributeValue:@"AXClickPoint"];
- return static_cast<double>([positionValue pointValue].x);
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0f;
- }
- double AccessibilityUIElement::clickPointY()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSValue* positionValue = [m_element accessibilityAttributeValue:@"AXClickPoint"];
- return static_cast<double>([positionValue pointValue].y);
- END_AX_OBJC_EXCEPTIONS
-
- return 0.0f;
- }
- double AccessibilityUIElement::intValue() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityValueAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber*)value doubleValue];
- END_AX_OBJC_EXCEPTIONS
- return 0.0f;
- }
- double AccessibilityUIElement::minValue()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityMinValueAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber*)value doubleValue];
- END_AX_OBJC_EXCEPTIONS
- return 0.0f;
- }
- double AccessibilityUIElement::maxValue()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityMaxValueAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber*)value doubleValue];
- END_AX_OBJC_EXCEPTIONS
- return 0.0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::valueDescription()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSString* valueDescription = [m_element accessibilityAttributeValue:NSAccessibilityValueDescriptionAttribute];
- if ([valueDescription isKindOfClass:[NSString class]])
- return [valueDescription createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- int AccessibilityUIElement::insertionPointLineNumber()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityInsertionPointLineNumberAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber *)value intValue];
- END_AX_OBJC_EXCEPTIONS
-
- return -1;
- }
- bool AccessibilityUIElement::isPressActionSupported()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* actions = [m_element accessibilityActionNames];
- return [actions containsObject:NSAccessibilityPressAction];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- bool AccessibilityUIElement::isIncrementActionSupported()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* actions = [m_element accessibilityActionNames];
- return [actions containsObject:NSAccessibilityIncrementAction];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- bool AccessibilityUIElement::isDecrementActionSupported()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* actions = [m_element accessibilityActionNames];
- return [actions containsObject:NSAccessibilityDecrementAction];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- bool AccessibilityUIElement::isEnabled()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityEnabledAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- bool AccessibilityUIElement::isRequired() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXRequired"];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- bool AccessibilityUIElement::isFocused() const
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::isSelected() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilitySelectedAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- bool AccessibilityUIElement::isExpanded() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityExpandedAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- bool AccessibilityUIElement::isChecked() const
- {
- // On the Mac, intValue()==1 if a a checkable control is checked.
- return intValue() == 1;
- }
- int AccessibilityUIElement::hierarchicalLevel() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityDisclosureLevelAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [value intValue];
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::speak()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXDRTSpeechAttribute"];
- if ([value isKindOfClass:[NSString class]])
- return [value createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- bool AccessibilityUIElement::ariaIsGrabbed() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityGrabbedAttribute];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
- return false;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::ariaDropEffects() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityDropEffectsAttribute];
- if (![value isKindOfClass:[NSArray class]])
- return 0;
- NSMutableString* dropEffects = [NSMutableString string];
- NSInteger length = [value count];
- for (NSInteger k = 0; k < length; ++k) {
- [dropEffects appendString:[value objectAtIndex:k]];
- if (k < length - 1)
- [dropEffects appendString:@","];
- }
-
- return [dropEffects createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- // parameterized attributes
- int AccessibilityUIElement::lineForIndex(int index)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityLineForIndexParameterizedAttribute forParameter:[NSNumber numberWithInt:index]];
- if ([value isKindOfClass:[NSNumber class]])
- return [(NSNumber *)value intValue];
- END_AX_OBJC_EXCEPTIONS
- return -1;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::rangeForLine(int line)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityRangeForLineParameterizedAttribute forParameter:[NSNumber numberWithInt:line]];
- if ([value isKindOfClass:[NSValue class]])
- return [NSStringFromRange([value rangeValue]) createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::rangeForPosition(int x, int y)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityRangeForPositionParameterizedAttribute forParameter:[NSValue valueWithPoint:NSMakePoint(x, y)]];
- if ([value isKindOfClass:[NSValue class]])
- return [NSStringFromRange([value rangeValue]) createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
- {
- NSRange range = NSMakeRange(location, length);
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:NSAccessibilityBoundsForRangeParameterizedAttribute forParameter:[NSValue valueWithRange:range]];
- NSRect rect = NSMakeRect(0,0,0,0);
- if ([value isKindOfClass:[NSValue class]])
- rect = [value rectValue];
-
- // don't return position information because it is platform dependent
- NSMutableString* boundsDescription = [NSMutableString stringWithFormat:@"{{%f, %f}, {%f, %f}}",-1.0f,-1.0f,rect.size.width,rect.size.height];
- return [boundsDescription createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::stringForRange(unsigned location, unsigned length)
- {
- NSRange range = NSMakeRange(location, length);
- BEGIN_AX_OBJC_EXCEPTIONS
- id string = [m_element accessibilityAttributeValue:NSAccessibilityStringForRangeParameterizedAttribute forParameter:[NSValue valueWithRange:range]];
- if (![string isKindOfClass:[NSString class]])
- return 0;
-
- return [string createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::attributedStringForRange(unsigned location, unsigned length)
- {
- NSRange range = NSMakeRange(location, length);
- BEGIN_AX_OBJC_EXCEPTIONS
- NSAttributedString* string = [m_element accessibilityAttributeValue:NSAccessibilityAttributedStringForRangeParameterizedAttribute forParameter:[NSValue valueWithRange:range]];
- if (![string isKindOfClass:[NSAttributedString class]])
- return 0;
-
- NSString* stringWithAttrs = [string description];
- return [stringWithAttrs createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- bool AccessibilityUIElement::attributedStringRangeIsMisspelled(unsigned location, unsigned length)
- {
- NSRange range = NSMakeRange(location, length);
- BEGIN_AX_OBJC_EXCEPTIONS
- NSAttributedString* string = [m_element accessibilityAttributeValue:NSAccessibilityAttributedStringForRangeParameterizedAttribute forParameter:[NSValue valueWithRange:range]];
- if (![string isKindOfClass:[NSAttributedString class]])
- return false;
- NSDictionary* attrs = [string attributesAtIndex:0 effectiveRange:nil];
- BOOL misspelled = [[attrs objectForKey:NSAccessibilityMisspelledTextAttribute] boolValue];
- #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
- if (misspelled)
- misspelled = [[attrs objectForKey:NSAccessibilityMarkedMisspelledTextAttribute] boolValue];
- #endif
- return misspelled;
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::uiElementForSearchPredicate(JSContextRef context, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSMutableDictionary* parameter = [NSMutableDictionary dictionary];
- [parameter setObject:(isDirectionNext) ? @"AXDirectionNext" : @"AXDirectionPrevious" forKey:@"AXDirection"];
- if (visibleOnly)
- [parameter setObject:[NSNumber numberWithBool:YES] forKey:@"AXVisibleOnly"];
- [parameter setObject:[NSNumber numberWithInt:1] forKey:@"AXResultsLimit"];
- if (startElement && startElement->platformUIElement())
- [parameter setObject:(id)startElement->platformUIElement() forKey:@"AXStartElement"];
- if (searchKey) {
- if (JSValueIsString(context, searchKey)) {
- NSString *searchKeyParameter = nil;
- JSStringRef singleSearchKey = JSValueToStringCopy(context, searchKey, 0);
- if (singleSearchKey) {
- searchKeyParameter = [NSString stringWithJSStringRef:singleSearchKey];
- JSStringRelease(singleSearchKey);
- if (searchKeyParameter)
- [parameter setObject:searchKeyParameter forKey:@"AXSearchKey"];
- }
- }
- else if (JSValueIsObject(context, searchKey)) {
- NSMutableArray *searchKeyParameter = nil;
- JSObjectRef array = const_cast<JSObjectRef>(searchKey);
- unsigned arrayLength = 0;
- JSRetainPtr<JSStringRef> arrayLengthString(Adopt, JSStringCreateWithUTF8CString("length"));
- JSValueRef arrayLengthValue = JSObjectGetProperty(context, array, arrayLengthString.get(), 0);
- if (arrayLengthValue && JSValueIsNumber(context, arrayLengthValue))
- arrayLength = static_cast<unsigned>(JSValueToNumber(context, arrayLengthValue, 0));
-
- for (unsigned i = 0; i < arrayLength; ++i) {
- JSValueRef exception = 0;
- JSValueRef value = JSObjectGetPropertyAtIndex(context, array, i, &exception);
- if (exception)
- break;
- JSStringRef singleSearchKey = JSValueToStringCopy(context, value, &exception);
- if (exception)
- break;
- if (singleSearchKey) {
- if (!searchKeyParameter)
- searchKeyParameter = [NSMutableArray array];
- [searchKeyParameter addObject:[NSString stringWithJSStringRef:singleSearchKey]];
- JSStringRelease(singleSearchKey);
- }
- }
- if (searchKeyParameter)
- [parameter setObject:searchKeyParameter forKey:@"AXSearchKey"];
- }
- }
- if (searchText && JSStringGetLength(searchText))
- [parameter setObject:[NSString stringWithJSStringRef:searchText] forKey:@"AXSearchText"];
-
- id uiElement = [[m_element accessibilityAttributeValue:@"AXUIElementsForSearchPredicate" forParameter:parameter] lastObject];
- return AccessibilityUIElement::create(uiElement);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumnHeaders()
- {
- // not yet defined in AppKit... odd
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* columnHeadersArray = [m_element accessibilityAttributeValue:@"AXColumnHeaderUIElements"];
- Vector<RefPtr<AccessibilityUIElement> > columnHeadersVector;
- convertNSArrayToVector(columnHeadersArray, columnHeadersVector);
- return descriptionOfElements(columnHeadersVector);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRowHeaders()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* rowHeadersArray = [m_element accessibilityAttributeValue:@"AXRowHeaderUIElements"];
- Vector<RefPtr<AccessibilityUIElement> > rowHeadersVector;
- convertNSArrayToVector(rowHeadersArray, rowHeadersVector);
- return descriptionOfElements(rowHeadersVector);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumns()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* columnsArray = [m_element accessibilityAttributeValue:NSAccessibilityColumnsAttribute];
- Vector<RefPtr<AccessibilityUIElement> > columnsVector;
- convertNSArrayToVector(columnsArray, columnsVector);
- return descriptionOfElements(columnsVector);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRows()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* rowsArray = [m_element accessibilityAttributeValue:NSAccessibilityRowsAttribute];
- Vector<RefPtr<AccessibilityUIElement> > rowsVector;
- convertNSArrayToVector(rowsArray, rowsVector);
- return descriptionOfElements(rowsVector);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfVisibleCells()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* cellsArray = [m_element accessibilityAttributeValue:@"AXVisibleCells"];
- Vector<RefPtr<AccessibilityUIElement> > cellsVector;
- convertNSArrayToVector(cellsArray, cellsVector);
- return descriptionOfElements(cellsVector);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfHeader()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id headerObject = [m_element accessibilityAttributeValue:NSAccessibilityHeaderAttribute];
- if (!headerObject)
- return [@"" createJSStringRef];
-
- Vector<RefPtr<AccessibilityUIElement> > headerVector;
- headerVector.append(AccessibilityUIElement::create(headerObject));
- return descriptionOfElements(headerVector);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- int AccessibilityUIElement::rowCount()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- return [m_element accessibilityArrayAttributeCount:NSAccessibilityRowsAttribute];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- int AccessibilityUIElement::columnCount()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- return [m_element accessibilityArrayAttributeCount:NSAccessibilityColumnsAttribute];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- int AccessibilityUIElement::indexInTable()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSNumber* indexNumber = [m_element accessibilityAttributeValue:NSAccessibilityIndexAttribute];
- if (indexNumber)
- return [indexNumber intValue];
- END_AX_OBJC_EXCEPTIONS
- return -1;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::rowIndexRange()
- {
- NSRange range = NSMakeRange(0, 0);
- BEGIN_AX_OBJC_EXCEPTIONS
- NSValue* indexRange = [m_element accessibilityAttributeValue:@"AXRowIndexRange"];
- if (indexRange)
- range = [indexRange rangeValue];
- NSMutableString* rangeDescription = [NSMutableString stringWithFormat:@"{%lu, %lu}", static_cast<unsigned long>(range.location), static_cast<unsigned long>(range.length)];
- return [rangeDescription createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::columnIndexRange()
- {
- NSRange range = NSMakeRange(0, 0);
- BEGIN_AX_OBJC_EXCEPTIONS
- NSNumber* indexRange = [m_element accessibilityAttributeValue:@"AXColumnIndexRange"];
- if (indexRange)
- range = [indexRange rangeValue];
- NSMutableString* rangeDescription = [NSMutableString stringWithFormat:@"{%lu, %lu}", static_cast<unsigned long>(range.location), static_cast<unsigned long>(range.length)];
- return [rangeDescription createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::cellForColumnAndRow(unsigned col, unsigned row)
- {
- NSArray *colRowArray = [NSArray arrayWithObjects:[NSNumber numberWithUnsignedInt:col], [NSNumber numberWithUnsignedInt:row], nil];
- BEGIN_AX_OBJC_EXCEPTIONS
- return AccessibilityUIElement::create([m_element accessibilityAttributeValue:@"AXCellForColumnAndRow" forParameter:colRowArray]);
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::horizontalScrollbar() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- return AccessibilityUIElement::create([m_element accessibilityAttributeValue:NSAccessibilityHorizontalScrollBarAttribute]);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::verticalScrollbar() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- return AccessibilityUIElement::create([m_element accessibilityAttributeValue:NSAccessibilityVerticalScrollBarAttribute]);
- END_AX_OBJC_EXCEPTIONS
- return 0;
- }
- void AccessibilityUIElement::scrollToMakeVisible()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- [m_element accessibilityPerformAction:@"AXScrollToVisible"];
- END_AX_OBJC_EXCEPTIONS
- }
-
- JSRetainPtr<JSStringRef> AccessibilityUIElement::selectedTextRange()
- {
- NSRange range = NSMakeRange(NSNotFound, 0);
- BEGIN_AX_OBJC_EXCEPTIONS
- NSValue *indexRange = [m_element accessibilityAttributeValue:NSAccessibilitySelectedTextRangeAttribute];
- if (indexRange)
- range = [indexRange rangeValue];
- NSMutableString* rangeDescription = [NSMutableString stringWithFormat:@"{%lu, %lu}", static_cast<unsigned long>(range.location), static_cast<unsigned long>(range.length)];
- return [rangeDescription createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length)
- {
- NSRange textRange = NSMakeRange(location, length);
- NSValue *textRangeValue = [NSValue valueWithRange:textRange];
- BEGIN_AX_OBJC_EXCEPTIONS
- [m_element accessibilitySetValue:textRangeValue forAttribute:NSAccessibilitySelectedTextRangeAttribute];
- END_AX_OBJC_EXCEPTIONS
- }
- void AccessibilityUIElement::increment()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- [m_element accessibilityPerformAction:NSAccessibilityIncrementAction];
- END_AX_OBJC_EXCEPTIONS
- }
- void AccessibilityUIElement::decrement()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- [m_element accessibilityPerformAction:NSAccessibilityDecrementAction];
- END_AX_OBJC_EXCEPTIONS
- }
- void AccessibilityUIElement::showMenu()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- [m_element accessibilityPerformAction:NSAccessibilityShowMenuAction];
- END_AX_OBJC_EXCEPTIONS
- }
- void AccessibilityUIElement::press()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- [m_element accessibilityPerformAction:NSAccessibilityPressAction];
- END_AX_OBJC_EXCEPTIONS
- }
- void AccessibilityUIElement::setSelectedChild(AccessibilityUIElement* element) const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* array = [NSArray arrayWithObject:element->platformUIElement()];
- [m_element accessibilitySetValue:array forAttribute:NSAccessibilitySelectedChildrenAttribute];
- END_AX_OBJC_EXCEPTIONS
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const
- {
- // FIXME: implement
- return JSStringCreateWithCharacters(0, 0);
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::documentEncoding()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::documentURI()
- {
- return JSStringCreateWithCharacters(0, 0);
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::url()
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSURL *url = [m_element accessibilityAttributeValue:NSAccessibilityURLAttribute];
- return [[url absoluteString] createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return nil;
- }
- bool AccessibilityUIElement::addNotificationListener(JSValueRef functionCallback)
- {
- if (!functionCallback)
- return false;
-
- // Mac programmers should not be adding more than one notification listener per element.
- // Other platforms may be different.
- if (m_notificationHandler)
- return false;
- m_notificationHandler = [[AccessibilityNotificationHandler alloc] init];
- [m_notificationHandler setPlatformElement:platformUIElement()];
- [m_notificationHandler setCallback:functionCallback];
- [m_notificationHandler startObserving];
- return true;
- }
- bool AccessibilityUIElement::removeNotificationListener()
- {
- // Mac programmers should not be trying to remove a listener that's already removed.
- ASSERT(m_notificationHandler);
- [m_notificationHandler release];
- m_notificationHandler = nil;
-
- return true;
- }
- bool AccessibilityUIElement::isFocusable() const
- {
- bool result = false;
- BEGIN_AX_OBJC_EXCEPTIONS
- result = [m_element accessibilityIsAttributeSettable:NSAccessibilityFocusedAttribute];
- END_AX_OBJC_EXCEPTIONS
-
- return result;
- }
- bool AccessibilityUIElement::isSelectable() const
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::isMultiSelectable() const
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::isVisible() const
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::isOffScreen() const
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::isCollapsed() const
- {
- // FIXME: implement
- return false;
- }
- bool AccessibilityUIElement::isIgnored() const
- {
- BOOL result = NO;
- BEGIN_AX_OBJC_EXCEPTIONS
- result = [m_element accessibilityIsIgnored];
- END_AX_OBJC_EXCEPTIONS
- return result;
- }
- bool AccessibilityUIElement::hasPopup() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id value = [m_element accessibilityAttributeValue:@"AXHasPopup"];
- if ([value isKindOfClass:[NSNumber class]])
- return [value boolValue];
- END_AX_OBJC_EXCEPTIONS
- return false;
- }
- void AccessibilityUIElement::takeFocus()
- {
- // FIXME: implement
- }
- void AccessibilityUIElement::takeSelection()
- {
- // FIXME: implement
- }
- void AccessibilityUIElement::addSelection()
- {
- // FIXME: implement
- }
- void AccessibilityUIElement::removeSelection()
- {
- // FIXME: implement
- }
- // Text markers
- PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id textMarkerRange = [m_element accessibilityAttributeValue:@"AXTextMarkerRangeForUIElement" forParameter:element->platformUIElement()];
- return AccessibilityTextMarkerRange::create(textMarkerRange);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange* range)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSNumber* lengthValue = [m_element accessibilityAttributeValue:@"AXLengthForTextMarkerRange" forParameter:(id)range->platformTextMarkerRange()];
- return [lengthValue intValue];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::previousTextMarker(AccessibilityTextMarker* textMarker)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id previousMarker = [m_element accessibilityAttributeValue:@"AXPreviousTextMarkerForTextMarker" forParameter:(id)textMarker->platformTextMarker()];
- return AccessibilityTextMarker::create(previousMarker);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::nextTextMarker(AccessibilityTextMarker* textMarker)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id nextMarker = [m_element accessibilityAttributeValue:@"AXNextTextMarkerForTextMarker" forParameter:(id)textMarker->platformTextMarker()];
- return AccessibilityTextMarker::create(nextMarker);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::stringForTextMarkerRange(AccessibilityTextMarkerRange* markerRange)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id textString = [m_element accessibilityAttributeValue:@"AXStringForTextMarkerRange" forParameter:(id)markerRange->platformTextMarkerRange()];
- return [textString createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray* textMarkers = [NSArray arrayWithObjects:(id)startMarker->platformTextMarker(), (id)endMarker->platformTextMarker(), nil];
- id textMarkerRange = [m_element accessibilityAttributeValue:@"AXTextMarkerRangeForUnorderedTextMarkers" forParameter:textMarkers];
- return AccessibilityTextMarkerRange::create(textMarkerRange);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id textMarker = [m_element accessibilityAttributeValue:@"AXStartTextMarkerForTextMarkerRange" forParameter:(id)range->platformTextMarkerRange()];
- return AccessibilityTextMarker::create(textMarker);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id textMarker = [m_element accessibilityAttributeValue:@"AXEndTextMarkerForTextMarkerRange" forParameter:(id)range->platformTextMarkerRange()];
- return AccessibilityTextMarker::create(textMarker);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::textMarkerForPoint(int x, int y)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id textMarker = [m_element accessibilityAttributeValue:@"AXTextMarkerForPosition" forParameter:[NSValue valueWithPoint:NSMakePoint(x, y)]];
- return AccessibilityTextMarker::create(textMarker);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::accessibilityElementForTextMarker(AccessibilityTextMarker* marker)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id uiElement = [m_element accessibilityAttributeValue:@"AXUIElementForTextMarker" forParameter:(id)marker->platformTextMarker()];
- return AccessibilityUIElement::create(uiElement);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
-
- bool AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute(JSStringRef attribute, AccessibilityTextMarkerRange* range)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSAttributedString* string = [m_element accessibilityAttributeValue:@"AXAttributedStringForTextMarkerRange" forParameter:(id)range->platformTextMarkerRange()];
- if (![string isKindOfClass:[NSAttributedString class]])
- return false;
-
- NSDictionary* attrs = [string attributesAtIndex:0 effectiveRange:nil];
- if ([attrs objectForKey:[NSString stringWithJSStringRef:attribute]])
- return true;
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
-
- int AccessibilityUIElement::indexForTextMarker(AccessibilityTextMarker* marker)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSNumber* indexNumber = [m_element accessibilityAttributeValue:@"AXIndexForTextMarker" forParameter:(id)marker->platformTextMarker()];
- return [indexNumber intValue];
- END_AX_OBJC_EXCEPTIONS
-
- return -1;
- }
- bool AccessibilityUIElement::isTextMarkerValid(AccessibilityTextMarker* textMarker)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSNumber* validNumber = [m_element accessibilityAttributeValue:@"AXTextMarkerIsValid" forParameter:(id)textMarker->platformTextMarker()];
- return [validNumber boolValue];
- END_AX_OBJC_EXCEPTIONS
-
- return false;
- }
- PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::textMarkerForIndex(int textIndex)
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- id textMarker = [m_element accessibilityAttributeValue:@"AXTextMarkerForIndex" forParameter:[NSNumber numberWithInteger:textIndex]];
- return AccessibilityTextMarker::create(textMarker);
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- static NSString *_convertMathMultiscriptPairsToString(NSArray *pairs)
- {
- __block NSMutableString *result = [NSMutableString string];
- [pairs enumerateObjectsUsingBlock:^(id pair, NSUInteger index, BOOL *stop) {
- for (NSString *key in pair)
- [result appendFormat:@"\t%lu. %@ = %@\n", (unsigned long)index, key, [[pair objectForKey:key] accessibilityAttributeValue:NSAccessibilitySubroleAttribute]];
- }];
-
- return result;
- }
-
- JSRetainPtr<JSStringRef> AccessibilityUIElement::mathPostscriptsDescription() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray *pairs = [m_element accessibilityAttributeValue:@"AXMathPostscripts"];
- return [_convertMathMultiscriptPairsToString(pairs) createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- JSRetainPtr<JSStringRef> AccessibilityUIElement::mathPrescriptsDescription() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray *pairs = [m_element accessibilityAttributeValue:@"AXMathPrescripts"];
- return [_convertMathMultiscriptPairsToString(pairs) createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
-
- JSRetainPtr<JSStringRef> AccessibilityUIElement::pathDescription() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSMutableString *result = [NSMutableString stringWithString:@"\nStart Path\n"];
- NSBezierPath *bezierPath = [m_element accessibilityAttributeValue:NSAccessibilityPathAttribute];
-
- NSUInteger elementCount = [bezierPath elementCount];
- NSPoint points[3];
- for (NSUInteger i = 0; i < elementCount; i++) {
- switch ([bezierPath elementAtIndex:i associatedPoints:points]) {
- case NSMoveToBezierPathElement:
- [result appendString:@"\tMove to point\n"];
- break;
-
- case NSLineToBezierPathElement:
- [result appendString:@"\tLine to\n"];
- break;
-
- case NSCurveToBezierPathElement:
- [result appendString:@"\tCurve to\n"];
- break;
-
- case NSClosePathBezierPathElement:
- [result appendString:@"\tClose\n"];
- break;
- }
- }
-
- return [result createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
-
- JSRetainPtr<JSStringRef> AccessibilityUIElement::supportedActions() const
- {
- BEGIN_AX_OBJC_EXCEPTIONS
- NSArray *names = [m_element accessibilityActionNames];
- return [[names componentsJoinedByString:@","] createJSStringRef];
- END_AX_OBJC_EXCEPTIONS
-
- return 0;
- }
- } // namespace WTR
|