AccessibilityUIElementMac.mm 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578
  1. /*
  2. * Copyright (C) 2008 Apple Inc. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #import "config.h"
  26. #import "DumpRenderTree.h"
  27. #import "AccessibilityCommonMac.h"
  28. #import "AccessibilityNotificationHandler.h"
  29. #import "AccessibilityUIElement.h"
  30. #import <Foundation/Foundation.h>
  31. #import <JavaScriptCore/JSRetainPtr.h>
  32. #import <JavaScriptCore/JSStringRef.h>
  33. #import <JavaScriptCore/JSStringRefCF.h>
  34. #import <WebKit/WebFrame.h>
  35. #import <WebKit/WebHTMLView.h>
  36. #import <WebKit/WebTypesInternal.h>
  37. #import <wtf/RetainPtr.h>
  38. #import <wtf/Vector.h>
  39. #ifndef NSAccessibilityOwnsAttribute
  40. #define NSAccessibilityOwnsAttribute @"AXOwns"
  41. #endif
  42. #ifndef NSAccessibilityGrabbedAttribute
  43. #define NSAccessibilityGrabbedAttribute @"AXGrabbed"
  44. #endif
  45. #ifndef NSAccessibilityDropEffectsAttribute
  46. #define NSAccessibilityDropEffectsAttribute @"AXDropEffects"
  47. #endif
  48. #ifndef NSAccessibilityPathAttribute
  49. #define NSAccessibilityPathAttribute @"AXPath"
  50. #endif
  51. typedef void (*AXPostedNotificationCallback)(id element, NSString* notification, void* context);
  52. @interface NSObject (WebKitAccessibilityAdditions)
  53. - (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount;
  54. - (NSUInteger)accessibilityIndexOfChild:(id)child;
  55. - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute;
  56. @end
  57. AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
  58. : m_element(element)
  59. , m_notificationHandler(0)
  60. {
  61. // FIXME: ap@webkit.org says ObjC objects need to be CFRetained/CFRelease to be GC-compliant on the mac.
  62. [m_element retain];
  63. }
  64. AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other)
  65. : m_element(other.m_element)
  66. , m_notificationHandler(0)
  67. {
  68. [m_element retain];
  69. }
  70. AccessibilityUIElement::~AccessibilityUIElement()
  71. {
  72. // The notification handler should be nil because removeNotificationListener() should have been called in the test.
  73. ASSERT(!m_notificationHandler);
  74. [m_element release];
  75. }
  76. static NSString* descriptionOfValue(id valueObject, id focusedAccessibilityObject)
  77. {
  78. if (!valueObject)
  79. return NULL;
  80. if ([valueObject isKindOfClass:[NSArray class]])
  81. return [NSString stringWithFormat:@"<array of size %lu>", static_cast<unsigned long>([(NSArray*)valueObject count])];
  82. if ([valueObject isKindOfClass:[NSNumber class]])
  83. return [(NSNumber*)valueObject stringValue];
  84. if ([valueObject isKindOfClass:[NSValue class]]) {
  85. NSString* type = [NSString stringWithCString:[valueObject objCType] encoding:NSASCIIStringEncoding];
  86. NSValue* value = (NSValue*)valueObject;
  87. if ([type rangeOfString:@"NSRect"].length > 0)
  88. return [NSString stringWithFormat:@"NSRect: %@", NSStringFromRect([value rectValue])];
  89. if ([type rangeOfString:@"NSPoint"].length > 0)
  90. return [NSString stringWithFormat:@"NSPoint: %@", NSStringFromPoint([value pointValue])];
  91. if ([type rangeOfString:@"NSSize"].length > 0)
  92. return [NSString stringWithFormat:@"NSSize: %@", NSStringFromSize([value sizeValue])];
  93. if ([type rangeOfString:@"NSRange"].length > 0)
  94. return [NSString stringWithFormat:@"NSRange: %@", NSStringFromRange([value rangeValue])];
  95. }
  96. // Strip absolute URL paths
  97. NSString* description = [valueObject description];
  98. NSRange range = [description rangeOfString:@"LayoutTests"];
  99. if (range.length)
  100. return [description substringFromIndex:range.location];
  101. // Strip pointer locations
  102. if ([description rangeOfString:@"0x"].length) {
  103. NSString* role = [focusedAccessibilityObject accessibilityAttributeValue:NSAccessibilityRoleAttribute];
  104. NSString* title = [focusedAccessibilityObject accessibilityAttributeValue:NSAccessibilityTitleAttribute];
  105. if ([title length])
  106. return [NSString stringWithFormat:@"<%@: '%@'>", role, title];
  107. return [NSString stringWithFormat:@"<%@>", role];
  108. }
  109. return [valueObject description];
  110. }
  111. static NSString* attributesOfElement(id accessibilityObject)
  112. {
  113. NSArray* supportedAttributes = [accessibilityObject accessibilityAttributeNames];
  114. NSMutableString* attributesString = [NSMutableString string];
  115. for (NSUInteger i = 0; i < [supportedAttributes count]; ++i) {
  116. NSString* attribute = [supportedAttributes objectAtIndex:i];
  117. // Right now, position provides useless and screen-specific information, so we do not
  118. // want to include it for the sake of universally passing tests.
  119. if ([attribute isEqualToString:@"AXPosition"])
  120. continue;
  121. // accessibilityAttributeValue: can throw an if an attribute is not returned.
  122. // For DumpRenderTree's purpose, we should ignore those exceptions
  123. BEGIN_AX_OBJC_EXCEPTIONS
  124. id valueObject = [accessibilityObject accessibilityAttributeValue:attribute];
  125. NSString* value = descriptionOfValue(valueObject, accessibilityObject);
  126. [attributesString appendFormat:@"%@: %@\n", attribute, value];
  127. END_AX_OBJC_EXCEPTIONS
  128. }
  129. return attributesString;
  130. }
  131. static JSStringRef concatenateAttributeAndValue(NSString* attribute, NSString* value)
  132. {
  133. Vector<UniChar> buffer([attribute length]);
  134. [attribute getCharacters:buffer.data()];
  135. buffer.append(':');
  136. buffer.append(' ');
  137. Vector<UniChar> valueBuffer([value length]);
  138. [value getCharacters:valueBuffer.data()];
  139. buffer.appendVector(valueBuffer);
  140. return JSStringCreateWithCharacters(buffer.data(), buffer.size());
  141. }
  142. static void convertNSArrayToVector(NSArray* array, Vector<AccessibilityUIElement>& elementVector)
  143. {
  144. NSUInteger count = [array count];
  145. for (NSUInteger i = 0; i < count; ++i)
  146. elementVector.append(AccessibilityUIElement([array objectAtIndex:i]));
  147. }
  148. static JSStringRef descriptionOfElements(Vector<AccessibilityUIElement>& elementVector)
  149. {
  150. NSMutableString* allElementString = [NSMutableString string];
  151. size_t size = elementVector.size();
  152. for (size_t i = 0; i < size; ++i) {
  153. NSString* attributes = attributesOfElement(elementVector[i].platformUIElement());
  154. [allElementString appendFormat:@"%@\n------------\n", attributes];
  155. }
  156. return [allElementString createJSStringRef];
  157. }
  158. void AccessibilityUIElement::getLinkedUIElements(Vector<AccessibilityUIElement>& elementVector)
  159. {
  160. BEGIN_AX_OBJC_EXCEPTIONS
  161. NSArray* linkedElements = [m_element accessibilityAttributeValue:NSAccessibilityLinkedUIElementsAttribute];
  162. convertNSArrayToVector(linkedElements, elementVector);
  163. END_AX_OBJC_EXCEPTIONS
  164. }
  165. void AccessibilityUIElement::getDocumentLinks(Vector<AccessibilityUIElement>& elementVector)
  166. {
  167. BEGIN_AX_OBJC_EXCEPTIONS
  168. NSArray* linkElements = [m_element accessibilityAttributeValue:@"AXLinkUIElements"];
  169. convertNSArrayToVector(linkElements, elementVector);
  170. END_AX_OBJC_EXCEPTIONS
  171. }
  172. void AccessibilityUIElement::getChildren(Vector<AccessibilityUIElement>& elementVector)
  173. {
  174. BEGIN_AX_OBJC_EXCEPTIONS
  175. NSArray* children = [m_element accessibilityAttributeValue:NSAccessibilityChildrenAttribute];
  176. convertNSArrayToVector(children, elementVector);
  177. END_AX_OBJC_EXCEPTIONS
  178. }
  179. void AccessibilityUIElement::getChildrenWithRange(Vector<AccessibilityUIElement>& elementVector, unsigned location, unsigned length)
  180. {
  181. BEGIN_AX_OBJC_EXCEPTIONS
  182. NSArray* children = [m_element accessibilityArrayAttributeValues:NSAccessibilityChildrenAttribute index:location maxCount:length];
  183. convertNSArrayToVector(children, elementVector);
  184. END_AX_OBJC_EXCEPTIONS
  185. }
  186. int AccessibilityUIElement::childrenCount()
  187. {
  188. Vector<AccessibilityUIElement> children;
  189. getChildren(children);
  190. return children.size();
  191. }
  192. AccessibilityUIElement AccessibilityUIElement::elementAtPoint(int x, int y)
  193. {
  194. id element = [m_element accessibilityHitTest:NSMakePoint(x, y)];
  195. if (!element)
  196. return nil;
  197. return AccessibilityUIElement(element);
  198. }
  199. unsigned AccessibilityUIElement::indexOfChild(AccessibilityUIElement* element)
  200. {
  201. return [m_element accessibilityIndexOfChild:element->platformUIElement()];
  202. }
  203. AccessibilityUIElement AccessibilityUIElement::getChildAtIndex(unsigned index)
  204. {
  205. Vector<AccessibilityUIElement> children;
  206. getChildrenWithRange(children, index, 1);
  207. if (children.size() == 1)
  208. return children[0];
  209. return 0;
  210. }
  211. AccessibilityUIElement AccessibilityUIElement::linkedUIElementAtIndex(unsigned index)
  212. {
  213. BEGIN_AX_OBJC_EXCEPTIONS
  214. NSArray* objects = [m_element accessibilityAttributeValue:NSAccessibilityLinkedUIElementsAttribute];
  215. if (index < [objects count])
  216. return [objects objectAtIndex:index];
  217. END_AX_OBJC_EXCEPTIONS
  218. return 0;
  219. }
  220. AccessibilityUIElement AccessibilityUIElement::ariaOwnsElementAtIndex(unsigned index)
  221. {
  222. BEGIN_AX_OBJC_EXCEPTIONS
  223. NSArray* objects = [m_element accessibilityAttributeValue:NSAccessibilityOwnsAttribute];
  224. if (index < [objects count])
  225. return [objects objectAtIndex:index];
  226. END_AX_OBJC_EXCEPTIONS
  227. return 0;
  228. }
  229. AccessibilityUIElement AccessibilityUIElement::ariaFlowToElementAtIndex(unsigned index)
  230. {
  231. BEGIN_AX_OBJC_EXCEPTIONS
  232. NSArray* objects = [m_element accessibilityAttributeValue:NSAccessibilityLinkedUIElementsAttribute];
  233. if (index < [objects count])
  234. return [objects objectAtIndex:index];
  235. END_AX_OBJC_EXCEPTIONS
  236. return 0;
  237. }
  238. AccessibilityUIElement AccessibilityUIElement::disclosedRowAtIndex(unsigned index)
  239. {
  240. BEGIN_AX_OBJC_EXCEPTIONS
  241. NSArray* rows = [m_element accessibilityAttributeValue:NSAccessibilityDisclosedRowsAttribute];
  242. if (index < [rows count])
  243. return [rows objectAtIndex:index];
  244. END_AX_OBJC_EXCEPTIONS
  245. return 0;
  246. }
  247. AccessibilityUIElement AccessibilityUIElement::selectedChildAtIndex(unsigned index) const
  248. {
  249. BEGIN_AX_OBJC_EXCEPTIONS
  250. NSArray* array = [m_element accessibilityAttributeValue:NSAccessibilitySelectedChildrenAttribute];
  251. if (index < [array count])
  252. return [array objectAtIndex:index];
  253. END_AX_OBJC_EXCEPTIONS
  254. return 0;
  255. }
  256. unsigned AccessibilityUIElement::selectedChildrenCount() const
  257. {
  258. BEGIN_AX_OBJC_EXCEPTIONS
  259. return [m_element accessibilityArrayAttributeCount:NSAccessibilitySelectedChildrenAttribute];
  260. END_AX_OBJC_EXCEPTIONS
  261. return 0;
  262. }
  263. AccessibilityUIElement AccessibilityUIElement::selectedRowAtIndex(unsigned index)
  264. {
  265. BEGIN_AX_OBJC_EXCEPTIONS
  266. NSArray* rows = [m_element accessibilityAttributeValue:NSAccessibilitySelectedRowsAttribute];
  267. if (index < [rows count])
  268. return [rows objectAtIndex:index];
  269. END_AX_OBJC_EXCEPTIONS
  270. return 0;
  271. }
  272. AccessibilityUIElement AccessibilityUIElement::rowAtIndex(unsigned index)
  273. {
  274. BEGIN_AX_OBJC_EXCEPTIONS
  275. NSArray* rows = [m_element accessibilityAttributeValue:NSAccessibilityRowsAttribute];
  276. if (index < [rows count])
  277. return [rows objectAtIndex:index];
  278. END_AX_OBJC_EXCEPTIONS
  279. return 0;
  280. }
  281. AccessibilityUIElement AccessibilityUIElement::titleUIElement()
  282. {
  283. BEGIN_AX_OBJC_EXCEPTIONS
  284. id accessibilityObject = [m_element accessibilityAttributeValue:NSAccessibilityTitleUIElementAttribute];
  285. if (accessibilityObject)
  286. return AccessibilityUIElement(accessibilityObject);
  287. END_AX_OBJC_EXCEPTIONS
  288. return 0;
  289. }
  290. AccessibilityUIElement AccessibilityUIElement::parentElement()
  291. {
  292. BEGIN_AX_OBJC_EXCEPTIONS
  293. id accessibilityObject = [m_element accessibilityAttributeValue:NSAccessibilityParentAttribute];
  294. if (accessibilityObject)
  295. return AccessibilityUIElement(accessibilityObject);
  296. END_AX_OBJC_EXCEPTIONS
  297. return 0;
  298. }
  299. AccessibilityUIElement AccessibilityUIElement::disclosedByRow()
  300. {
  301. BEGIN_AX_OBJC_EXCEPTIONS
  302. id accessibilityObject = [m_element accessibilityAttributeValue:NSAccessibilityDisclosedByRowAttribute];
  303. if (accessibilityObject)
  304. return AccessibilityUIElement(accessibilityObject);
  305. END_AX_OBJC_EXCEPTIONS
  306. return 0;
  307. }
  308. JSStringRef AccessibilityUIElement::attributesOfLinkedUIElements()
  309. {
  310. Vector<AccessibilityUIElement> linkedElements;
  311. getLinkedUIElements(linkedElements);
  312. return descriptionOfElements(linkedElements);
  313. }
  314. JSStringRef AccessibilityUIElement::attributesOfDocumentLinks()
  315. {
  316. Vector<AccessibilityUIElement> linkElements;
  317. getDocumentLinks(linkElements);
  318. return descriptionOfElements(linkElements);
  319. }
  320. JSStringRef AccessibilityUIElement::attributesOfChildren()
  321. {
  322. Vector<AccessibilityUIElement> children;
  323. getChildren(children);
  324. return descriptionOfElements(children);
  325. }
  326. JSStringRef AccessibilityUIElement::allAttributes()
  327. {
  328. NSString* attributes = attributesOfElement(m_element);
  329. return [attributes createJSStringRef];
  330. }
  331. JSStringRef AccessibilityUIElement::stringAttributeValue(JSStringRef attribute)
  332. {
  333. BEGIN_AX_OBJC_EXCEPTIONS
  334. id value = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
  335. if ([value isKindOfClass:[NSString class]])
  336. return [value createJSStringRef];
  337. END_AX_OBJC_EXCEPTIONS
  338. return 0;
  339. }
  340. AccessibilityUIElement AccessibilityUIElement::uiElementAttributeValue(JSStringRef attribute) const
  341. {
  342. BEGIN_AX_OBJC_EXCEPTIONS
  343. id uiElement = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
  344. return AccessibilityUIElement(uiElement);
  345. END_AX_OBJC_EXCEPTIONS
  346. return 0;
  347. }
  348. double AccessibilityUIElement::numberAttributeValue(JSStringRef attribute)
  349. {
  350. BEGIN_AX_OBJC_EXCEPTIONS
  351. id value = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
  352. if ([value isKindOfClass:[NSNumber class]])
  353. return [value doubleValue];
  354. END_AX_OBJC_EXCEPTIONS
  355. return 0;
  356. }
  357. bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute)
  358. {
  359. BEGIN_AX_OBJC_EXCEPTIONS
  360. id value = [m_element accessibilityAttributeValue:[NSString stringWithJSStringRef:attribute]];
  361. if ([value isKindOfClass:[NSNumber class]])
  362. return [value boolValue];
  363. END_AX_OBJC_EXCEPTIONS
  364. return false;
  365. }
  366. bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute)
  367. {
  368. BEGIN_AX_OBJC_EXCEPTIONS
  369. return [m_element accessibilityIsAttributeSettable:[NSString stringWithJSStringRef:attribute]];
  370. END_AX_OBJC_EXCEPTIONS
  371. return false;
  372. }
  373. bool AccessibilityUIElement::isAttributeSupported(JSStringRef attribute)
  374. {
  375. BEGIN_AX_OBJC_EXCEPTIONS
  376. return [[m_element accessibilityAttributeNames] containsObject:[NSString stringWithJSStringRef:attribute]];
  377. END_AX_OBJC_EXCEPTIONS
  378. return false;
  379. }
  380. JSStringRef AccessibilityUIElement::parameterizedAttributeNames()
  381. {
  382. NSArray* supportedParameterizedAttributes = [m_element accessibilityParameterizedAttributeNames];
  383. NSMutableString* attributesString = [NSMutableString string];
  384. for (NSUInteger i = 0; i < [supportedParameterizedAttributes count]; ++i) {
  385. [attributesString appendFormat:@"%@\n", [supportedParameterizedAttributes objectAtIndex:i]];
  386. }
  387. return [attributesString createJSStringRef];
  388. }
  389. JSStringRef AccessibilityUIElement::role()
  390. {
  391. BEGIN_AX_OBJC_EXCEPTIONS
  392. NSString *role = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityRoleAttribute], m_element);
  393. return concatenateAttributeAndValue(@"AXRole", role);
  394. END_AX_OBJC_EXCEPTIONS
  395. return 0;
  396. }
  397. JSStringRef AccessibilityUIElement::subrole()
  398. {
  399. BEGIN_AX_OBJC_EXCEPTIONS
  400. NSString* role = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilitySubroleAttribute], m_element);
  401. return concatenateAttributeAndValue(@"AXSubrole", role);
  402. END_AX_OBJC_EXCEPTIONS
  403. return 0;
  404. }
  405. JSStringRef AccessibilityUIElement::roleDescription()
  406. {
  407. BEGIN_AX_OBJC_EXCEPTIONS
  408. NSString* role = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityRoleDescriptionAttribute], m_element);
  409. return concatenateAttributeAndValue(@"AXRoleDescription", role);
  410. END_AX_OBJC_EXCEPTIONS
  411. return 0;
  412. }
  413. JSStringRef AccessibilityUIElement::title()
  414. {
  415. BEGIN_AX_OBJC_EXCEPTIONS
  416. NSString* title = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityTitleAttribute], m_element);
  417. return concatenateAttributeAndValue(@"AXTitle", title);
  418. END_AX_OBJC_EXCEPTIONS
  419. return 0;
  420. }
  421. JSStringRef AccessibilityUIElement::description()
  422. {
  423. BEGIN_AX_OBJC_EXCEPTIONS
  424. id description = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityDescriptionAttribute], m_element);
  425. return concatenateAttributeAndValue(@"AXDescription", description);
  426. END_AX_OBJC_EXCEPTIONS
  427. return 0;
  428. }
  429. JSStringRef AccessibilityUIElement::orientation() const
  430. {
  431. BEGIN_AX_OBJC_EXCEPTIONS
  432. id description = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityOrientationAttribute], m_element);
  433. return concatenateAttributeAndValue(@"AXOrientation", description);
  434. END_AX_OBJC_EXCEPTIONS
  435. return 0;
  436. }
  437. JSStringRef AccessibilityUIElement::stringValue()
  438. {
  439. BEGIN_AX_OBJC_EXCEPTIONS
  440. id description = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityValueAttribute], m_element);
  441. return concatenateAttributeAndValue(@"AXValue", description);
  442. END_AX_OBJC_EXCEPTIONS
  443. return 0;
  444. }
  445. JSStringRef AccessibilityUIElement::language()
  446. {
  447. BEGIN_AX_OBJC_EXCEPTIONS
  448. id description = descriptionOfValue([m_element accessibilityAttributeValue:@"AXLanguage"], m_element);
  449. return concatenateAttributeAndValue(@"AXLanguage", description);
  450. END_AX_OBJC_EXCEPTIONS
  451. return 0;
  452. }
  453. JSStringRef AccessibilityUIElement::helpText() const
  454. {
  455. BEGIN_AX_OBJC_EXCEPTIONS
  456. id description = descriptionOfValue([m_element accessibilityAttributeValue:NSAccessibilityHelpAttribute], m_element);
  457. return concatenateAttributeAndValue(@"AXHelp", description);
  458. END_AX_OBJC_EXCEPTIONS
  459. return 0;
  460. }
  461. double AccessibilityUIElement::x()
  462. {
  463. BEGIN_AX_OBJC_EXCEPTIONS
  464. NSValue* positionValue = [m_element accessibilityAttributeValue:NSAccessibilityPositionAttribute];
  465. return static_cast<double>([positionValue pointValue].x);
  466. END_AX_OBJC_EXCEPTIONS
  467. return 0.0f;
  468. }
  469. double AccessibilityUIElement::y()
  470. {
  471. BEGIN_AX_OBJC_EXCEPTIONS
  472. NSValue* positionValue = [m_element accessibilityAttributeValue:NSAccessibilityPositionAttribute];
  473. return static_cast<double>([positionValue pointValue].y);
  474. END_AX_OBJC_EXCEPTIONS
  475. return 0.0f;
  476. }
  477. double AccessibilityUIElement::width()
  478. {
  479. BEGIN_AX_OBJC_EXCEPTIONS
  480. NSValue* sizeValue = [m_element accessibilityAttributeValue:NSAccessibilitySizeAttribute];
  481. return static_cast<double>([sizeValue sizeValue].width);
  482. END_AX_OBJC_EXCEPTIONS
  483. return 0.0f;
  484. }
  485. double AccessibilityUIElement::height()
  486. {
  487. BEGIN_AX_OBJC_EXCEPTIONS
  488. NSValue* sizeValue = [m_element accessibilityAttributeValue:NSAccessibilitySizeAttribute];
  489. return static_cast<double>([sizeValue sizeValue].height);
  490. END_AX_OBJC_EXCEPTIONS
  491. return 0.0f;
  492. }
  493. double AccessibilityUIElement::clickPointX()
  494. {
  495. BEGIN_AX_OBJC_EXCEPTIONS
  496. NSValue* positionValue = [m_element accessibilityAttributeValue:@"AXClickPoint"];
  497. return static_cast<double>([positionValue pointValue].x);
  498. END_AX_OBJC_EXCEPTIONS
  499. return 0.0f;
  500. }
  501. double AccessibilityUIElement::clickPointY()
  502. {
  503. BEGIN_AX_OBJC_EXCEPTIONS
  504. NSValue* positionValue = [m_element accessibilityAttributeValue:@"AXClickPoint"];
  505. return static_cast<double>([positionValue pointValue].y);
  506. END_AX_OBJC_EXCEPTIONS
  507. return 0.0f;
  508. }
  509. double AccessibilityUIElement::intValue() const
  510. {
  511. BEGIN_AX_OBJC_EXCEPTIONS
  512. id value = [m_element accessibilityAttributeValue:NSAccessibilityValueAttribute];
  513. if ([value isKindOfClass:[NSNumber class]])
  514. return [(NSNumber*)value doubleValue];
  515. END_AX_OBJC_EXCEPTIONS
  516. return 0.0f;
  517. }
  518. double AccessibilityUIElement::minValue()
  519. {
  520. BEGIN_AX_OBJC_EXCEPTIONS
  521. id value = [m_element accessibilityAttributeValue:NSAccessibilityMinValueAttribute];
  522. if ([value isKindOfClass:[NSNumber class]])
  523. return [(NSNumber*)value doubleValue];
  524. END_AX_OBJC_EXCEPTIONS
  525. return 0.0f;
  526. }
  527. double AccessibilityUIElement::maxValue()
  528. {
  529. BEGIN_AX_OBJC_EXCEPTIONS
  530. id value = [m_element accessibilityAttributeValue:NSAccessibilityMaxValueAttribute];
  531. if ([value isKindOfClass:[NSNumber class]])
  532. return [(NSNumber*)value doubleValue];
  533. END_AX_OBJC_EXCEPTIONS
  534. return 0.0;
  535. }
  536. JSStringRef AccessibilityUIElement::valueDescription()
  537. {
  538. BEGIN_AX_OBJC_EXCEPTIONS
  539. NSString* valueDescription = [m_element accessibilityAttributeValue:NSAccessibilityValueDescriptionAttribute];
  540. if ([valueDescription isKindOfClass:[NSString class]])
  541. return [valueDescription createJSStringRef];
  542. END_AX_OBJC_EXCEPTIONS
  543. return 0;
  544. }
  545. int AccessibilityUIElement::insertionPointLineNumber()
  546. {
  547. BEGIN_AX_OBJC_EXCEPTIONS
  548. id value = [m_element accessibilityAttributeValue:NSAccessibilityInsertionPointLineNumberAttribute];
  549. if ([value isKindOfClass:[NSNumber class]])
  550. return [(NSNumber *)value intValue];
  551. END_AX_OBJC_EXCEPTIONS
  552. return -1;
  553. }
  554. bool AccessibilityUIElement::isPressActionSupported()
  555. {
  556. BEGIN_AX_OBJC_EXCEPTIONS
  557. NSArray* actions = [m_element accessibilityActionNames];
  558. return [actions containsObject:NSAccessibilityPressAction];
  559. END_AX_OBJC_EXCEPTIONS
  560. return false;
  561. }
  562. bool AccessibilityUIElement::isIncrementActionSupported()
  563. {
  564. BEGIN_AX_OBJC_EXCEPTIONS
  565. NSArray* actions = [m_element accessibilityActionNames];
  566. return [actions containsObject:NSAccessibilityIncrementAction];
  567. END_AX_OBJC_EXCEPTIONS
  568. return false;
  569. }
  570. bool AccessibilityUIElement::isDecrementActionSupported()
  571. {
  572. BEGIN_AX_OBJC_EXCEPTIONS
  573. NSArray* actions = [m_element accessibilityActionNames];
  574. return [actions containsObject:NSAccessibilityDecrementAction];
  575. END_AX_OBJC_EXCEPTIONS
  576. return false;
  577. }
  578. bool AccessibilityUIElement::isEnabled()
  579. {
  580. BEGIN_AX_OBJC_EXCEPTIONS
  581. id value = [m_element accessibilityAttributeValue:NSAccessibilityEnabledAttribute];
  582. if ([value isKindOfClass:[NSNumber class]])
  583. return [value boolValue];
  584. END_AX_OBJC_EXCEPTIONS
  585. return false;
  586. }
  587. bool AccessibilityUIElement::isRequired() const
  588. {
  589. BEGIN_AX_OBJC_EXCEPTIONS
  590. id value = [m_element accessibilityAttributeValue:@"AXRequired"];
  591. if ([value isKindOfClass:[NSNumber class]])
  592. return [value boolValue];
  593. END_AX_OBJC_EXCEPTIONS
  594. return false;
  595. }
  596. bool AccessibilityUIElement::isFocused() const
  597. {
  598. // FIXME: implement
  599. return false;
  600. }
  601. bool AccessibilityUIElement::isSelected() const
  602. {
  603. BEGIN_AX_OBJC_EXCEPTIONS
  604. id value = [m_element accessibilityAttributeValue:NSAccessibilitySelectedAttribute];
  605. if ([value isKindOfClass:[NSNumber class]])
  606. return [value boolValue];
  607. END_AX_OBJC_EXCEPTIONS
  608. return false;
  609. }
  610. bool AccessibilityUIElement::isExpanded() const
  611. {
  612. BEGIN_AX_OBJC_EXCEPTIONS
  613. id value = [m_element accessibilityAttributeValue:NSAccessibilityExpandedAttribute];
  614. if ([value isKindOfClass:[NSNumber class]])
  615. return [value boolValue];
  616. END_AX_OBJC_EXCEPTIONS
  617. return false;
  618. }
  619. bool AccessibilityUIElement::isChecked() const
  620. {
  621. // On the Mac, intValue()==1 if a a checkable control is checked.
  622. return intValue() == 1;
  623. }
  624. int AccessibilityUIElement::hierarchicalLevel() const
  625. {
  626. BEGIN_AX_OBJC_EXCEPTIONS
  627. id value = [m_element accessibilityAttributeValue:NSAccessibilityDisclosureLevelAttribute];
  628. if ([value isKindOfClass:[NSNumber class]])
  629. return [value intValue];
  630. END_AX_OBJC_EXCEPTIONS
  631. return 0;
  632. }
  633. JSStringRef AccessibilityUIElement::speak()
  634. {
  635. BEGIN_AX_OBJC_EXCEPTIONS
  636. id value = [m_element accessibilityAttributeValue:@"AXDRTSpeechAttribute"];
  637. if ([value isKindOfClass:[NSString class]])
  638. return [value createJSStringRef];
  639. END_AX_OBJC_EXCEPTIONS
  640. return 0;
  641. }
  642. bool AccessibilityUIElement::ariaIsGrabbed() const
  643. {
  644. BEGIN_AX_OBJC_EXCEPTIONS
  645. id value = [m_element accessibilityAttributeValue:NSAccessibilityGrabbedAttribute];
  646. if ([value isKindOfClass:[NSNumber class]])
  647. return [value boolValue];
  648. END_AX_OBJC_EXCEPTIONS
  649. return false;
  650. }
  651. JSStringRef AccessibilityUIElement::ariaDropEffects() const
  652. {
  653. BEGIN_AX_OBJC_EXCEPTIONS
  654. id value = [m_element accessibilityAttributeValue:NSAccessibilityDropEffectsAttribute];
  655. if (![value isKindOfClass:[NSArray class]])
  656. return 0;
  657. NSMutableString* dropEffects = [NSMutableString string];
  658. NSInteger length = [value count];
  659. for (NSInteger k = 0; k < length; ++k) {
  660. [dropEffects appendString:[value objectAtIndex:k]];
  661. if (k < length - 1)
  662. [dropEffects appendString:@","];
  663. }
  664. return [dropEffects createJSStringRef];
  665. END_AX_OBJC_EXCEPTIONS
  666. return 0;
  667. }
  668. // parameterized attributes
  669. int AccessibilityUIElement::lineForIndex(int index)
  670. {
  671. BEGIN_AX_OBJC_EXCEPTIONS
  672. id value = [m_element accessibilityAttributeValue:NSAccessibilityLineForIndexParameterizedAttribute forParameter:[NSNumber numberWithInt:index]];
  673. if ([value isKindOfClass:[NSNumber class]])
  674. return [(NSNumber *)value intValue];
  675. END_AX_OBJC_EXCEPTIONS
  676. return -1;
  677. }
  678. JSStringRef AccessibilityUIElement::rangeForLine(int line)
  679. {
  680. BEGIN_AX_OBJC_EXCEPTIONS
  681. id value = [m_element accessibilityAttributeValue:NSAccessibilityRangeForLineParameterizedAttribute forParameter:[NSNumber numberWithInt:line]];
  682. if ([value isKindOfClass:[NSValue class]])
  683. return [NSStringFromRange([value rangeValue]) createJSStringRef];
  684. END_AX_OBJC_EXCEPTIONS
  685. return 0;
  686. }
  687. JSStringRef AccessibilityUIElement::rangeForPosition(int x, int y)
  688. {
  689. BEGIN_AX_OBJC_EXCEPTIONS
  690. id value = [m_element accessibilityAttributeValue:NSAccessibilityRangeForPositionParameterizedAttribute forParameter:[NSValue valueWithPoint:NSMakePoint(x, y)]];
  691. if ([value isKindOfClass:[NSValue class]])
  692. return [NSStringFromRange([value rangeValue]) createJSStringRef];
  693. END_AX_OBJC_EXCEPTIONS
  694. return 0;
  695. }
  696. JSStringRef AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
  697. {
  698. NSRange range = NSMakeRange(location, length);
  699. BEGIN_AX_OBJC_EXCEPTIONS
  700. id value = [m_element accessibilityAttributeValue:NSAccessibilityBoundsForRangeParameterizedAttribute forParameter:[NSValue valueWithRange:range]];
  701. NSRect rect = NSMakeRect(0,0,0,0);
  702. if ([value isKindOfClass:[NSValue class]])
  703. rect = [value rectValue];
  704. // don't return position information because it is platform dependent
  705. NSMutableString* boundsDescription = [NSMutableString stringWithFormat:@"{{%f, %f}, {%f, %f}}",-1.0f,-1.0f,rect.size.width,rect.size.height];
  706. return [boundsDescription createJSStringRef];
  707. END_AX_OBJC_EXCEPTIONS
  708. return 0;
  709. }
  710. JSStringRef AccessibilityUIElement::stringForRange(unsigned location, unsigned length)
  711. {
  712. NSRange range = NSMakeRange(location, length);
  713. BEGIN_AX_OBJC_EXCEPTIONS
  714. id string = [m_element accessibilityAttributeValue:NSAccessibilityStringForRangeParameterizedAttribute forParameter:[NSValue valueWithRange:range]];
  715. if (![string isKindOfClass:[NSString class]])
  716. return 0;
  717. return [string createJSStringRef];
  718. END_AX_OBJC_EXCEPTIONS
  719. return 0;
  720. }
  721. JSStringRef AccessibilityUIElement::attributedStringForRange(unsigned location, unsigned length)
  722. {
  723. NSRange range = NSMakeRange(location, length);
  724. BEGIN_AX_OBJC_EXCEPTIONS
  725. NSAttributedString* string = [m_element accessibilityAttributeValue:NSAccessibilityAttributedStringForRangeParameterizedAttribute forParameter:[NSValue valueWithRange:range]];
  726. if (![string isKindOfClass:[NSAttributedString class]])
  727. return 0;
  728. NSString* stringWithAttrs = [string description];
  729. return [stringWithAttrs createJSStringRef];
  730. END_AX_OBJC_EXCEPTIONS
  731. return 0;
  732. }
  733. bool AccessibilityUIElement::attributedStringRangeIsMisspelled(unsigned location, unsigned length)
  734. {
  735. NSRange range = NSMakeRange(location, length);
  736. BEGIN_AX_OBJC_EXCEPTIONS
  737. NSAttributedString* string = [m_element accessibilityAttributeValue:NSAccessibilityAttributedStringForRangeParameterizedAttribute forParameter:[NSValue valueWithRange:range]];
  738. if (![string isKindOfClass:[NSAttributedString class]])
  739. return false;
  740. NSDictionary* attrs = [string attributesAtIndex:0 effectiveRange:nil];
  741. BOOL misspelled = [[attrs objectForKey:NSAccessibilityMisspelledTextAttribute] boolValue];
  742. #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
  743. if (misspelled)
  744. misspelled = [[attrs objectForKey:NSAccessibilityMarkedMisspelledTextAttribute] boolValue];
  745. #endif
  746. return misspelled;
  747. END_AX_OBJC_EXCEPTIONS
  748. return false;
  749. }
  750. AccessibilityUIElement AccessibilityUIElement::uiElementForSearchPredicate(JSContextRef context, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly)
  751. {
  752. BEGIN_AX_OBJC_EXCEPTIONS
  753. NSMutableDictionary* parameter = [NSMutableDictionary dictionary];
  754. [parameter setObject:(isDirectionNext) ? @"AXDirectionNext" : @"AXDirectionPrevious" forKey:@"AXDirection"];
  755. if (visibleOnly)
  756. [parameter setObject:[NSNumber numberWithBool:YES] forKey:@"AXVisibleOnly"];
  757. [parameter setObject:[NSNumber numberWithInt:1] forKey:@"AXResultsLimit"];
  758. if (startElement && startElement->platformUIElement())
  759. [parameter setObject:(id)startElement->platformUIElement() forKey:@"AXStartElement"];
  760. if (searchKey) {
  761. if (JSValueIsString(context, searchKey)) {
  762. NSString *searchKeyParameter = nil;
  763. JSStringRef singleSearchKey = JSValueToStringCopy(context, searchKey, 0);
  764. if (singleSearchKey) {
  765. searchKeyParameter = [NSString stringWithJSStringRef:singleSearchKey];
  766. JSStringRelease(singleSearchKey);
  767. if (searchKeyParameter)
  768. [parameter setObject:searchKeyParameter forKey:@"AXSearchKey"];
  769. }
  770. }
  771. else if (JSValueIsObject(context, searchKey)) {
  772. NSMutableArray *searchKeyParameter = nil;
  773. JSObjectRef array = const_cast<JSObjectRef>(searchKey);
  774. unsigned arrayLength = 0;
  775. JSRetainPtr<JSStringRef> arrayLengthString(Adopt, JSStringCreateWithUTF8CString("length"));
  776. JSValueRef arrayLengthValue = JSObjectGetProperty(context, array, arrayLengthString.get(), 0);
  777. if (arrayLengthValue && JSValueIsNumber(context, arrayLengthValue))
  778. arrayLength = static_cast<unsigned>(JSValueToNumber(context, arrayLengthValue, 0));
  779. for (unsigned i = 0; i < arrayLength; ++i) {
  780. JSValueRef exception = 0;
  781. JSValueRef value = JSObjectGetPropertyAtIndex(context, array, i, &exception);
  782. if (exception)
  783. break;
  784. JSStringRef singleSearchKey = JSValueToStringCopy(context, value, &exception);
  785. if (exception)
  786. break;
  787. if (singleSearchKey) {
  788. if (!searchKeyParameter)
  789. searchKeyParameter = [NSMutableArray array];
  790. [searchKeyParameter addObject:[NSString stringWithJSStringRef:singleSearchKey]];
  791. JSStringRelease(singleSearchKey);
  792. }
  793. }
  794. if (searchKeyParameter)
  795. [parameter setObject:searchKeyParameter forKey:@"AXSearchKey"];
  796. }
  797. }
  798. if (searchText && JSStringGetLength(searchText))
  799. [parameter setObject:[NSString stringWithJSStringRef:searchText] forKey:@"AXSearchText"];
  800. id uiElement = [[m_element accessibilityAttributeValue:@"AXUIElementsForSearchPredicate" forParameter:parameter] lastObject];
  801. return AccessibilityUIElement(uiElement);
  802. END_AX_OBJC_EXCEPTIONS
  803. return 0;
  804. }
  805. JSStringRef AccessibilityUIElement::attributesOfColumnHeaders()
  806. {
  807. // not yet defined in AppKit... odd
  808. BEGIN_AX_OBJC_EXCEPTIONS
  809. NSArray* columnHeadersArray = [m_element accessibilityAttributeValue:@"AXColumnHeaderUIElements"];
  810. Vector<AccessibilityUIElement> columnHeadersVector;
  811. convertNSArrayToVector(columnHeadersArray, columnHeadersVector);
  812. return descriptionOfElements(columnHeadersVector);
  813. END_AX_OBJC_EXCEPTIONS
  814. return 0;
  815. }
  816. JSStringRef AccessibilityUIElement::attributesOfRowHeaders()
  817. {
  818. BEGIN_AX_OBJC_EXCEPTIONS
  819. NSArray* rowHeadersArray = [m_element accessibilityAttributeValue:@"AXRowHeaderUIElements"];
  820. Vector<AccessibilityUIElement> rowHeadersVector;
  821. convertNSArrayToVector(rowHeadersArray, rowHeadersVector);
  822. return descriptionOfElements(rowHeadersVector);
  823. END_AX_OBJC_EXCEPTIONS
  824. return 0;
  825. }
  826. JSStringRef AccessibilityUIElement::attributesOfColumns()
  827. {
  828. BEGIN_AX_OBJC_EXCEPTIONS
  829. NSArray* columnsArray = [m_element accessibilityAttributeValue:NSAccessibilityColumnsAttribute];
  830. Vector<AccessibilityUIElement> columnsVector;
  831. convertNSArrayToVector(columnsArray, columnsVector);
  832. return descriptionOfElements(columnsVector);
  833. END_AX_OBJC_EXCEPTIONS
  834. return 0;
  835. }
  836. JSStringRef AccessibilityUIElement::attributesOfRows()
  837. {
  838. BEGIN_AX_OBJC_EXCEPTIONS
  839. NSArray* rowsArray = [m_element accessibilityAttributeValue:NSAccessibilityRowsAttribute];
  840. Vector<AccessibilityUIElement> rowsVector;
  841. convertNSArrayToVector(rowsArray, rowsVector);
  842. return descriptionOfElements(rowsVector);
  843. END_AX_OBJC_EXCEPTIONS
  844. return 0;
  845. }
  846. JSStringRef AccessibilityUIElement::attributesOfVisibleCells()
  847. {
  848. BEGIN_AX_OBJC_EXCEPTIONS
  849. NSArray* cellsArray = [m_element accessibilityAttributeValue:@"AXVisibleCells"];
  850. Vector<AccessibilityUIElement> cellsVector;
  851. convertNSArrayToVector(cellsArray, cellsVector);
  852. return descriptionOfElements(cellsVector);
  853. END_AX_OBJC_EXCEPTIONS
  854. return 0;
  855. }
  856. JSStringRef AccessibilityUIElement::attributesOfHeader()
  857. {
  858. BEGIN_AX_OBJC_EXCEPTIONS
  859. id headerObject = [m_element accessibilityAttributeValue:NSAccessibilityHeaderAttribute];
  860. if (!headerObject)
  861. return [@"" createJSStringRef];
  862. Vector<AccessibilityUIElement> headerVector;
  863. headerVector.append(headerObject);
  864. return descriptionOfElements(headerVector);
  865. END_AX_OBJC_EXCEPTIONS
  866. return 0;
  867. }
  868. int AccessibilityUIElement::rowCount()
  869. {
  870. BEGIN_AX_OBJC_EXCEPTIONS
  871. return [m_element accessibilityArrayAttributeCount:NSAccessibilityRowsAttribute];
  872. END_AX_OBJC_EXCEPTIONS
  873. return 0;
  874. }
  875. int AccessibilityUIElement::columnCount()
  876. {
  877. BEGIN_AX_OBJC_EXCEPTIONS
  878. return [m_element accessibilityArrayAttributeCount:NSAccessibilityColumnsAttribute];
  879. END_AX_OBJC_EXCEPTIONS
  880. return 0;
  881. }
  882. int AccessibilityUIElement::indexInTable()
  883. {
  884. BEGIN_AX_OBJC_EXCEPTIONS
  885. NSNumber* indexNumber = [m_element accessibilityAttributeValue:NSAccessibilityIndexAttribute];
  886. if (indexNumber)
  887. return [indexNumber intValue];
  888. END_AX_OBJC_EXCEPTIONS
  889. return -1;
  890. }
  891. JSStringRef AccessibilityUIElement::rowIndexRange()
  892. {
  893. NSRange range = NSMakeRange(0, 0);
  894. BEGIN_AX_OBJC_EXCEPTIONS
  895. NSValue* indexRange = [m_element accessibilityAttributeValue:@"AXRowIndexRange"];
  896. if (indexRange)
  897. range = [indexRange rangeValue];
  898. NSMutableString* rangeDescription = [NSMutableString stringWithFormat:@"{%lu, %lu}", static_cast<unsigned long>(range.location), static_cast<unsigned long>(range.length)];
  899. return [rangeDescription createJSStringRef];
  900. END_AX_OBJC_EXCEPTIONS
  901. return 0;
  902. }
  903. JSStringRef AccessibilityUIElement::columnIndexRange()
  904. {
  905. NSRange range = NSMakeRange(0, 0);
  906. BEGIN_AX_OBJC_EXCEPTIONS
  907. NSNumber* indexRange = [m_element accessibilityAttributeValue:@"AXColumnIndexRange"];
  908. if (indexRange)
  909. range = [indexRange rangeValue];
  910. NSMutableString* rangeDescription = [NSMutableString stringWithFormat:@"{%lu, %lu}",static_cast<unsigned long>(range.location), static_cast<unsigned long>(range.length)];
  911. return [rangeDescription createJSStringRef];
  912. END_AX_OBJC_EXCEPTIONS
  913. return 0;
  914. }
  915. AccessibilityUIElement AccessibilityUIElement::cellForColumnAndRow(unsigned col, unsigned row)
  916. {
  917. NSArray *colRowArray = [NSArray arrayWithObjects:[NSNumber numberWithUnsignedInt:col], [NSNumber numberWithUnsignedInt:row], nil];
  918. BEGIN_AX_OBJC_EXCEPTIONS
  919. return [m_element accessibilityAttributeValue:@"AXCellForColumnAndRow" forParameter:colRowArray];
  920. END_AX_OBJC_EXCEPTIONS
  921. return 0;
  922. }
  923. AccessibilityUIElement AccessibilityUIElement::horizontalScrollbar() const
  924. {
  925. BEGIN_AX_OBJC_EXCEPTIONS
  926. return AccessibilityUIElement([m_element accessibilityAttributeValue:NSAccessibilityHorizontalScrollBarAttribute]);
  927. END_AX_OBJC_EXCEPTIONS
  928. return 0;
  929. }
  930. AccessibilityUIElement AccessibilityUIElement::verticalScrollbar() const
  931. {
  932. BEGIN_AX_OBJC_EXCEPTIONS
  933. return AccessibilityUIElement([m_element accessibilityAttributeValue:NSAccessibilityVerticalScrollBarAttribute]);
  934. END_AX_OBJC_EXCEPTIONS
  935. return 0;
  936. }
  937. JSStringRef AccessibilityUIElement::pathDescription() const
  938. {
  939. BEGIN_AX_OBJC_EXCEPTIONS
  940. NSMutableString *result = [NSMutableString stringWithString:@"\nStart Path\n"];
  941. NSBezierPath *bezierPath = [m_element accessibilityAttributeValue:NSAccessibilityPathAttribute];
  942. NSUInteger elementCount = [bezierPath elementCount];
  943. for (NSUInteger i = 0; i < elementCount; i++) {
  944. switch ([bezierPath elementAtIndex:i]) {
  945. case NSMoveToBezierPathElement:
  946. [result appendString:@"\tMove to point\n"];
  947. break;
  948. case NSLineToBezierPathElement:
  949. [result appendString:@"\tLine to\n"];
  950. break;
  951. case NSCurveToBezierPathElement:
  952. [result appendString:@"\tCurve to\n"];
  953. break;
  954. case NSClosePathBezierPathElement:
  955. [result appendString:@"\tClose\n"];
  956. break;
  957. }
  958. }
  959. return [result createJSStringRef];
  960. END_AX_OBJC_EXCEPTIONS
  961. return 0;
  962. }
  963. JSStringRef AccessibilityUIElement::selectedTextRange()
  964. {
  965. NSRange range = NSMakeRange(NSNotFound, 0);
  966. BEGIN_AX_OBJC_EXCEPTIONS
  967. NSValue *indexRange = [m_element accessibilityAttributeValue:NSAccessibilitySelectedTextRangeAttribute];
  968. if (indexRange)
  969. range = [indexRange rangeValue];
  970. NSMutableString *rangeDescription = [NSMutableString stringWithFormat:@"{%lu, %lu}", static_cast<unsigned long>(range.location), static_cast<unsigned long>(range.length)];
  971. return [rangeDescription createJSStringRef];
  972. END_AX_OBJC_EXCEPTIONS
  973. return 0;
  974. }
  975. void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length)
  976. {
  977. NSRange textRange = NSMakeRange(location, length);
  978. NSValue *textRangeValue = [NSValue valueWithRange:textRange];
  979. BEGIN_AX_OBJC_EXCEPTIONS
  980. [m_element accessibilitySetValue:textRangeValue forAttribute:NSAccessibilitySelectedTextRangeAttribute];
  981. END_AX_OBJC_EXCEPTIONS
  982. }
  983. void AccessibilityUIElement::increment()
  984. {
  985. BEGIN_AX_OBJC_EXCEPTIONS
  986. [m_element accessibilityPerformAction:NSAccessibilityIncrementAction];
  987. END_AX_OBJC_EXCEPTIONS
  988. }
  989. void AccessibilityUIElement::decrement()
  990. {
  991. BEGIN_AX_OBJC_EXCEPTIONS
  992. [m_element accessibilityPerformAction:NSAccessibilityDecrementAction];
  993. END_AX_OBJC_EXCEPTIONS
  994. }
  995. void AccessibilityUIElement::showMenu()
  996. {
  997. BEGIN_AX_OBJC_EXCEPTIONS
  998. [m_element accessibilityPerformAction:NSAccessibilityShowMenuAction];
  999. END_AX_OBJC_EXCEPTIONS
  1000. }
  1001. void AccessibilityUIElement::press()
  1002. {
  1003. BEGIN_AX_OBJC_EXCEPTIONS
  1004. [m_element accessibilityPerformAction:NSAccessibilityPressAction];
  1005. END_AX_OBJC_EXCEPTIONS
  1006. }
  1007. void AccessibilityUIElement::setSelectedChild(AccessibilityUIElement* element) const
  1008. {
  1009. BEGIN_AX_OBJC_EXCEPTIONS
  1010. NSArray* array = [NSArray arrayWithObject:element->platformUIElement()];
  1011. [m_element accessibilitySetValue:array forAttribute:NSAccessibilitySelectedChildrenAttribute];
  1012. END_AX_OBJC_EXCEPTIONS
  1013. }
  1014. JSStringRef AccessibilityUIElement::accessibilityValue() const
  1015. {
  1016. // FIXME: implement
  1017. return JSStringCreateWithCharacters(0, 0);
  1018. }
  1019. JSStringRef AccessibilityUIElement::documentEncoding()
  1020. {
  1021. return JSStringCreateWithCharacters(0, 0);
  1022. }
  1023. JSStringRef AccessibilityUIElement::documentURI()
  1024. {
  1025. return JSStringCreateWithCharacters(0, 0);
  1026. }
  1027. JSStringRef AccessibilityUIElement::url()
  1028. {
  1029. BEGIN_AX_OBJC_EXCEPTIONS
  1030. NSURL *url = [m_element accessibilityAttributeValue:NSAccessibilityURLAttribute];
  1031. return [[url absoluteString] createJSStringRef];
  1032. END_AX_OBJC_EXCEPTIONS
  1033. return nil;
  1034. }
  1035. bool AccessibilityUIElement::addNotificationListener(JSObjectRef functionCallback)
  1036. {
  1037. if (!functionCallback)
  1038. return false;
  1039. // Mac programmers should not be adding more than one notification listener per element.
  1040. // Other platforms may be different.
  1041. if (m_notificationHandler)
  1042. return false;
  1043. m_notificationHandler = [[AccessibilityNotificationHandler alloc] init];
  1044. [m_notificationHandler setPlatformElement:platformUIElement()];
  1045. [m_notificationHandler setCallback:functionCallback];
  1046. [m_notificationHandler startObserving];
  1047. return true;
  1048. }
  1049. void AccessibilityUIElement::removeNotificationListener()
  1050. {
  1051. // Mac programmers should not be trying to remove a listener that's already removed.
  1052. ASSERT(m_notificationHandler);
  1053. [m_notificationHandler release];
  1054. m_notificationHandler = nil;
  1055. }
  1056. bool AccessibilityUIElement::isFocusable() const
  1057. {
  1058. bool result = false;
  1059. BEGIN_AX_OBJC_EXCEPTIONS
  1060. result = [m_element accessibilityIsAttributeSettable:NSAccessibilityFocusedAttribute];
  1061. END_AX_OBJC_EXCEPTIONS
  1062. return result;
  1063. }
  1064. bool AccessibilityUIElement::isSelectable() const
  1065. {
  1066. // FIXME: implement
  1067. return false;
  1068. }
  1069. bool AccessibilityUIElement::isMultiSelectable() const
  1070. {
  1071. // FIXME: implement
  1072. return false;
  1073. }
  1074. bool AccessibilityUIElement::isSelectedOptionActive() const
  1075. {
  1076. // FIXME: implement
  1077. return false;
  1078. }
  1079. bool AccessibilityUIElement::isVisible() const
  1080. {
  1081. // FIXME: implement
  1082. return false;
  1083. }
  1084. bool AccessibilityUIElement::isOffScreen() const
  1085. {
  1086. // FIXME: implement
  1087. return false;
  1088. }
  1089. bool AccessibilityUIElement::isCollapsed() const
  1090. {
  1091. // FIXME: implement
  1092. return false;
  1093. }
  1094. bool AccessibilityUIElement::isIgnored() const
  1095. {
  1096. BOOL result = NO;
  1097. BEGIN_AX_OBJC_EXCEPTIONS
  1098. result = [m_element accessibilityIsIgnored];
  1099. END_AX_OBJC_EXCEPTIONS
  1100. return result;
  1101. }
  1102. bool AccessibilityUIElement::hasPopup() const
  1103. {
  1104. BEGIN_AX_OBJC_EXCEPTIONS
  1105. id value = [m_element accessibilityAttributeValue:@"AXHasPopup"];
  1106. if ([value isKindOfClass:[NSNumber class]])
  1107. return [value boolValue];
  1108. END_AX_OBJC_EXCEPTIONS
  1109. return false;
  1110. }
  1111. void AccessibilityUIElement::takeFocus()
  1112. {
  1113. // FIXME: implement
  1114. }
  1115. void AccessibilityUIElement::takeSelection()
  1116. {
  1117. // FIXME: implement
  1118. }
  1119. void AccessibilityUIElement::addSelection()
  1120. {
  1121. // FIXME: implement
  1122. }
  1123. void AccessibilityUIElement::removeSelection()
  1124. {
  1125. // FIXME: implement
  1126. }
  1127. #if SUPPORTS_AX_TEXTMARKERS
  1128. // Text markers
  1129. AccessibilityTextMarkerRange AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
  1130. {
  1131. BEGIN_AX_OBJC_EXCEPTIONS
  1132. id textMarkerRange = [m_element accessibilityAttributeValue:@"AXTextMarkerRangeForUIElement" forParameter:element->platformUIElement()];
  1133. return AccessibilityTextMarkerRange(textMarkerRange);
  1134. END_AX_OBJC_EXCEPTIONS
  1135. return 0;
  1136. }
  1137. int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange* range)
  1138. {
  1139. BEGIN_AX_OBJC_EXCEPTIONS
  1140. NSNumber* lengthValue = [m_element accessibilityAttributeValue:@"AXLengthForTextMarkerRange" forParameter:(id)range->platformTextMarkerRange()];
  1141. return [lengthValue intValue];
  1142. END_AX_OBJC_EXCEPTIONS
  1143. return 0;
  1144. }
  1145. bool AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute(JSStringRef attribute, AccessibilityTextMarkerRange* range)
  1146. {
  1147. BEGIN_AX_OBJC_EXCEPTIONS
  1148. NSAttributedString* string = [m_element accessibilityAttributeValue:@"AXAttributedStringForTextMarkerRange" forParameter:(id)range->platformTextMarkerRange()];
  1149. if (![string isKindOfClass:[NSAttributedString class]])
  1150. return false;
  1151. NSDictionary* attrs = [string attributesAtIndex:0 effectiveRange:nil];
  1152. if ([attrs objectForKey:[NSString stringWithJSStringRef:attribute]])
  1153. return true;
  1154. END_AX_OBJC_EXCEPTIONS
  1155. return false;
  1156. }
  1157. int AccessibilityUIElement::indexForTextMarker(AccessibilityTextMarker* marker)
  1158. {
  1159. BEGIN_AX_OBJC_EXCEPTIONS
  1160. NSNumber* indexNumber = [m_element accessibilityAttributeValue:@"AXIndexForTextMarker" forParameter:(id)marker->platformTextMarker()];
  1161. return [indexNumber intValue];
  1162. END_AX_OBJC_EXCEPTIONS
  1163. return -1;
  1164. }
  1165. AccessibilityTextMarker AccessibilityUIElement::textMarkerForIndex(int textIndex)
  1166. {
  1167. BEGIN_AX_OBJC_EXCEPTIONS
  1168. id textMarker = [m_element accessibilityAttributeValue:@"AXTextMarkerForIndex" forParameter:[NSNumber numberWithInteger:textIndex]];
  1169. return AccessibilityTextMarker(textMarker);
  1170. END_AX_OBJC_EXCEPTIONS
  1171. return 0;
  1172. }
  1173. bool AccessibilityUIElement::isTextMarkerValid(AccessibilityTextMarker* textMarker)
  1174. {
  1175. BEGIN_AX_OBJC_EXCEPTIONS
  1176. NSNumber* validNumber = [m_element accessibilityAttributeValue:@"AXTextMarkerIsValid" forParameter:(id)textMarker->platformTextMarker()];
  1177. return [validNumber boolValue];
  1178. END_AX_OBJC_EXCEPTIONS
  1179. return false;
  1180. }
  1181. AccessibilityTextMarker AccessibilityUIElement::previousTextMarker(AccessibilityTextMarker* textMarker)
  1182. {
  1183. BEGIN_AX_OBJC_EXCEPTIONS
  1184. id previousMarker = [m_element accessibilityAttributeValue:@"AXPreviousTextMarkerForTextMarker" forParameter:(id)textMarker->platformTextMarker()];
  1185. return AccessibilityTextMarker(previousMarker);
  1186. END_AX_OBJC_EXCEPTIONS
  1187. return 0;
  1188. }
  1189. AccessibilityTextMarker AccessibilityUIElement::nextTextMarker(AccessibilityTextMarker* textMarker)
  1190. {
  1191. BEGIN_AX_OBJC_EXCEPTIONS
  1192. id nextMarker = [m_element accessibilityAttributeValue:@"AXNextTextMarkerForTextMarker" forParameter:(id)textMarker->platformTextMarker()];
  1193. return AccessibilityTextMarker(nextMarker);
  1194. END_AX_OBJC_EXCEPTIONS
  1195. return 0;
  1196. }
  1197. JSStringRef AccessibilityUIElement::stringForTextMarkerRange(AccessibilityTextMarkerRange* markerRange)
  1198. {
  1199. BEGIN_AX_OBJC_EXCEPTIONS
  1200. id textString = [m_element accessibilityAttributeValue:@"AXStringForTextMarkerRange" forParameter:(id)markerRange->platformTextMarkerRange()];
  1201. return [textString createJSStringRef];
  1202. END_AX_OBJC_EXCEPTIONS
  1203. return 0;
  1204. }
  1205. AccessibilityTextMarkerRange AccessibilityUIElement::textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker)
  1206. {
  1207. BEGIN_AX_OBJC_EXCEPTIONS
  1208. NSArray* textMarkers = [NSArray arrayWithObjects:(id)startMarker->platformTextMarker(), (id)endMarker->platformTextMarker(), nil];
  1209. id textMarkerRange = [m_element accessibilityAttributeValue:@"AXTextMarkerRangeForUnorderedTextMarkers" forParameter:textMarkers];
  1210. return AccessibilityTextMarkerRange(textMarkerRange);
  1211. END_AX_OBJC_EXCEPTIONS
  1212. return 0;
  1213. }
  1214. AccessibilityTextMarker AccessibilityUIElement::startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
  1215. {
  1216. BEGIN_AX_OBJC_EXCEPTIONS
  1217. id textMarker = [m_element accessibilityAttributeValue:@"AXStartTextMarkerForTextMarkerRange" forParameter:(id)range->platformTextMarkerRange()];
  1218. return AccessibilityTextMarker(textMarker);
  1219. END_AX_OBJC_EXCEPTIONS
  1220. return 0;
  1221. }
  1222. AccessibilityTextMarker AccessibilityUIElement::endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
  1223. {
  1224. BEGIN_AX_OBJC_EXCEPTIONS
  1225. id textMarker = [m_element accessibilityAttributeValue:@"AXEndTextMarkerForTextMarkerRange" forParameter:(id)range->platformTextMarkerRange()];
  1226. return AccessibilityTextMarker(textMarker);
  1227. END_AX_OBJC_EXCEPTIONS
  1228. return 0;
  1229. }
  1230. AccessibilityTextMarker AccessibilityUIElement::textMarkerForPoint(int x, int y)
  1231. {
  1232. BEGIN_AX_OBJC_EXCEPTIONS
  1233. id textMarker = [m_element accessibilityAttributeValue:@"AXTextMarkerForPosition" forParameter:[NSValue valueWithPoint:NSMakePoint(x, y)]];
  1234. return AccessibilityTextMarker(textMarker);
  1235. END_AX_OBJC_EXCEPTIONS
  1236. return 0;
  1237. }
  1238. AccessibilityUIElement AccessibilityUIElement::accessibilityElementForTextMarker(AccessibilityTextMarker* marker)
  1239. {
  1240. BEGIN_AX_OBJC_EXCEPTIONS
  1241. id uiElement = [m_element accessibilityAttributeValue:@"AXUIElementForTextMarker" forParameter:(id)marker->platformTextMarker()];
  1242. return AccessibilityUIElement(uiElement);
  1243. END_AX_OBJC_EXCEPTIONS
  1244. return 0;
  1245. }
  1246. #endif // SUPPORTS_AX_TEXTMARKERS
  1247. JSStringRef AccessibilityUIElement::supportedActions()
  1248. {
  1249. BEGIN_AX_OBJC_EXCEPTIONS
  1250. NSArray *names = [m_element accessibilityActionNames];
  1251. return [[names componentsJoinedByString:@","] createJSStringRef];
  1252. END_AX_OBJC_EXCEPTIONS
  1253. return 0;
  1254. }
  1255. static NSString *convertMathMultiscriptPairsToString(NSArray *pairs)
  1256. {
  1257. __block NSMutableString *result = [NSMutableString string];
  1258. [pairs enumerateObjectsUsingBlock:^(id pair, NSUInteger index, BOOL *stop) {
  1259. for (NSString *key in pair)
  1260. [result appendFormat:@"\t%lu. %@ = %@\n", (unsigned long)index, key, [[pair objectForKey:key] accessibilityAttributeValue:NSAccessibilitySubroleAttribute]];
  1261. }];
  1262. return result;
  1263. }
  1264. JSStringRef AccessibilityUIElement::mathPostscriptsDescription() const
  1265. {
  1266. BEGIN_AX_OBJC_EXCEPTIONS
  1267. NSArray *pairs = [m_element accessibilityAttributeValue:@"AXMathPostscripts"];
  1268. return [convertMathMultiscriptPairsToString(pairs) createJSStringRef];
  1269. END_AX_OBJC_EXCEPTIONS
  1270. return 0;
  1271. }
  1272. JSStringRef AccessibilityUIElement::mathPrescriptsDescription() const
  1273. {
  1274. BEGIN_AX_OBJC_EXCEPTIONS
  1275. NSArray *pairs = [m_element accessibilityAttributeValue:@"AXMathPrescripts"];
  1276. return [convertMathMultiscriptPairsToString(pairs) createJSStringRef];
  1277. END_AX_OBJC_EXCEPTIONS
  1278. return 0;
  1279. }
  1280. void AccessibilityUIElement::scrollToMakeVisible()
  1281. {
  1282. BEGIN_AX_OBJC_EXCEPTIONS
  1283. [m_element accessibilityPerformAction:@"AXScrollToVisible"];
  1284. END_AX_OBJC_EXCEPTIONS
  1285. }
  1286. void AccessibilityUIElement::scrollToMakeVisibleWithSubFocus(int x, int y, int width, int height)
  1287. {
  1288. // FIXME: implement
  1289. }
  1290. void AccessibilityUIElement::scrollToGlobalPoint(int x, int y)
  1291. {
  1292. // FIXME: implement
  1293. }