AccessibilityUIElementAtk.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  1. /*
  2. * Copyright (C) 2011 Apple Inc. All Rights Reserved.
  3. * Copyright (C) 2012 Igalia S.L.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  15. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "config.h"
  27. #include "AccessibilityUIElement.h"
  28. #if HAVE(ACCESSIBILITY)
  29. #include "InjectedBundle.h"
  30. #include "InjectedBundlePage.h"
  31. #include "NotImplemented.h"
  32. #include <JavaScriptCore/JSStringRef.h>
  33. #include <atk/atk.h>
  34. #include <wtf/Assertions.h>
  35. #include <wtf/gobject/GOwnPtr.h>
  36. #include <wtf/gobject/GRefPtr.h>
  37. #include <wtf/text/CString.h>
  38. #include <wtf/text/WTFString.h>
  39. #include <wtf/unicode/CharacterNames.h>
  40. namespace WTR {
  41. static String coreAttributeToAtkAttribute(JSStringRef attribute)
  42. {
  43. size_t bufferSize = JSStringGetMaximumUTF8CStringSize(attribute);
  44. GOwnPtr<gchar> buffer(static_cast<gchar*>(g_malloc(bufferSize)));
  45. JSStringGetUTF8CString(attribute, buffer.get(), bufferSize);
  46. String attributeString = String::fromUTF8(buffer.get());
  47. return attributeString == "AXPlaceholderValue" ? "placeholder-text" : String();
  48. }
  49. static void attributesClear(AtkAttributeSet* attributesSet)
  50. {
  51. for (GSList* attributes = attributesSet; attributes; attributes = attributes->next) {
  52. AtkAttribute* atkAttribute = static_cast<AtkAttribute*>(attributes->data);
  53. g_free(atkAttribute->name);
  54. g_free(atkAttribute->value);
  55. g_free(atkAttribute);
  56. }
  57. }
  58. static gchar* attributeSetToString(AtkAttributeSet* attributeSet)
  59. {
  60. GOwnPtr<GSList> atkAttributes(attributeSet);
  61. GString* str = g_string_new(0);
  62. for (GSList* attributes = atkAttributes.get(); attributes; attributes = attributes->next) {
  63. AtkAttribute* attribute = static_cast<AtkAttribute*>(attributes->data);
  64. GOwnPtr<gchar> attributeData(g_strconcat(attribute->name, ":", attribute->value, NULL));
  65. g_string_append(str, attributeData.get());
  66. if (attributes->next)
  67. g_string_append(str, ", ");
  68. }
  69. attributesClear(atkAttributes.get());
  70. return g_string_free(str, FALSE);
  71. }
  72. static bool checkElementState(PlatformUIElement element, AtkStateType stateType)
  73. {
  74. if (!ATK_IS_OBJECT(element.get()))
  75. return false;
  76. GRefPtr<AtkStateSet> stateSet = adoptGRef(atk_object_ref_state_set(ATK_OBJECT(element.get())));
  77. return atk_state_set_contains_state(stateSet.get(), stateType);
  78. }
  79. static JSStringRef indexRangeInTable(PlatformUIElement element, bool isRowRange)
  80. {
  81. GOwnPtr<gchar> rangeString(g_strdup("{0, 0}"));
  82. if (!element || !ATK_IS_OBJECT(element.get()))
  83. return JSStringCreateWithUTF8CString(rangeString.get());
  84. AtkObject* axTable = atk_object_get_parent(ATK_OBJECT(element.get()));
  85. if (!axTable || !ATK_IS_TABLE(axTable))
  86. return JSStringCreateWithUTF8CString(rangeString.get());
  87. // Look for the cell in the table.
  88. gint indexInParent = atk_object_get_index_in_parent(ATK_OBJECT(element.get()));
  89. if (indexInParent == -1)
  90. return JSStringCreateWithUTF8CString(rangeString.get());
  91. int row = -1;
  92. int column = -1;
  93. row = atk_table_get_row_at_index(ATK_TABLE(axTable), indexInParent);
  94. column = atk_table_get_column_at_index(ATK_TABLE(axTable), indexInParent);
  95. // Get the actual values, if row and columns are valid values.
  96. if (row != -1 && column != -1) {
  97. int base = 0;
  98. int length = 0;
  99. if (isRowRange) {
  100. base = row;
  101. length = atk_table_get_row_extent_at(ATK_TABLE(axTable), row, column);
  102. } else {
  103. base = column;
  104. length = atk_table_get_column_extent_at(ATK_TABLE(axTable), row, column);
  105. }
  106. rangeString.set(g_strdup_printf("{%d, %d}", base, length));
  107. }
  108. return JSStringCreateWithUTF8CString(rangeString.get());
  109. }
  110. static void alterCurrentValue(PlatformUIElement element, int factor)
  111. {
  112. if (!element || !ATK_IS_VALUE(element.get()))
  113. return;
  114. GValue currentValue = G_VALUE_INIT;
  115. atk_value_get_current_value(ATK_VALUE(element.get()), &currentValue);
  116. GValue increment = G_VALUE_INIT;
  117. atk_value_get_minimum_increment(ATK_VALUE(element.get()), &increment);
  118. GValue newValue = G_VALUE_INIT;
  119. g_value_init(&newValue, G_TYPE_DOUBLE);
  120. g_value_set_float(&newValue, g_value_get_float(&currentValue) + factor * g_value_get_float(&increment));
  121. atk_value_set_current_value(ATK_VALUE(element.get()), &newValue);
  122. g_value_unset(&newValue);
  123. g_value_unset(&increment);
  124. g_value_unset(&currentValue);
  125. }
  126. static gchar* replaceCharactersForResults(gchar* str)
  127. {
  128. WTF::String uString = WTF::String::fromUTF8(str);
  129. // The object replacement character is passed along to ATs so we need to be
  130. // able to test for their presence and do so without causing test failures.
  131. uString.replace(objectReplacementCharacter, "<obj>");
  132. // The presence of newline characters in accessible text of a single object
  133. // is appropriate, but it makes test results (especially the accessible tree)
  134. // harder to read.
  135. uString.replace("\n", "<\\n>");
  136. return g_strdup(uString.utf8().data());
  137. }
  138. static const gchar* roleToString(AtkRole role)
  139. {
  140. switch (role) {
  141. case ATK_ROLE_ALERT:
  142. return "AXRole: AXAlert";
  143. case ATK_ROLE_CANVAS:
  144. return "AXRole: AXCanvas";
  145. case ATK_ROLE_CHECK_BOX:
  146. return "AXRole: AXCheckBox";
  147. case ATK_ROLE_COLUMN_HEADER:
  148. return "AXRole: AXColumnHeader";
  149. case ATK_ROLE_COMBO_BOX:
  150. return "AXRole: AXComboBox";
  151. case ATK_ROLE_DOCUMENT_FRAME:
  152. return "AXRole: AXWebArea";
  153. case ATK_ROLE_ENTRY:
  154. return "AXRole: AXTextField";
  155. case ATK_ROLE_FOOTER:
  156. return "AXRole: AXFooter";
  157. case ATK_ROLE_FORM:
  158. return "AXRole: AXForm";
  159. case ATK_ROLE_GROUPING:
  160. return "AXRole: AXGroup";
  161. case ATK_ROLE_HEADING:
  162. return "AXRole: AXHeading";
  163. case ATK_ROLE_IMAGE:
  164. return "AXRole: AXImage";
  165. case ATK_ROLE_IMAGE_MAP:
  166. return "AXRole: AXImageMap";
  167. case ATK_ROLE_LABEL:
  168. return "AXRole: AXLabel";
  169. case ATK_ROLE_LINK:
  170. return "AXRole: AXLink";
  171. case ATK_ROLE_LIST:
  172. return "AXRole: AXList";
  173. case ATK_ROLE_LIST_BOX:
  174. return "AXRole: AXListBox";
  175. case ATK_ROLE_LIST_ITEM:
  176. return "AXRole: AXListItem";
  177. case ATK_ROLE_MENU:
  178. return "AXRole: AXMenu";
  179. case ATK_ROLE_MENU_BAR:
  180. return "AXRole: AXMenuBar";
  181. case ATK_ROLE_MENU_ITEM:
  182. return "AXRole: AXMenuItem";
  183. case ATK_ROLE_PAGE_TAB:
  184. return "AXRole: AXTab";
  185. case ATK_ROLE_PAGE_TAB_LIST:
  186. return "AXRole: AXTabGroup";
  187. case ATK_ROLE_PANEL:
  188. return "AXRole: AXGroup";
  189. case ATK_ROLE_PARAGRAPH:
  190. return "AXRole: AXParagraph";
  191. case ATK_ROLE_PASSWORD_TEXT:
  192. return "AXRole: AXPasswordField";
  193. case ATK_ROLE_PUSH_BUTTON:
  194. return "AXRole: AXButton";
  195. case ATK_ROLE_RADIO_BUTTON:
  196. return "AXRole: AXRadioButton";
  197. case ATK_ROLE_ROW_HEADER:
  198. return "AXRole: AXRowHeader";
  199. case ATK_ROLE_RULER:
  200. return "AXRole: AXRuler";
  201. case ATK_ROLE_SCROLL_BAR:
  202. return "AXRole: AXScrollBar";
  203. case ATK_ROLE_SCROLL_PANE:
  204. return "AXRole: AXScrollArea";
  205. case ATK_ROLE_SECTION:
  206. return "AXRole: AXDiv";
  207. case ATK_ROLE_SEPARATOR:
  208. return "AXRole: AXHorizontalRule";
  209. case ATK_ROLE_SLIDER:
  210. return "AXRole: AXSlider";
  211. case ATK_ROLE_SPIN_BUTTON:
  212. return "AXRole: AXSpinButton";
  213. case ATK_ROLE_TABLE:
  214. return "AXRole: AXTable";
  215. case ATK_ROLE_TABLE_CELL:
  216. return "AXRole: AXCell";
  217. case ATK_ROLE_TABLE_COLUMN_HEADER:
  218. return "AXRole: AXColumnHeader";
  219. case ATK_ROLE_TABLE_ROW:
  220. return "AXRole: AXRow";
  221. case ATK_ROLE_TABLE_ROW_HEADER:
  222. return "AXRole: AXRowHeader";
  223. case ATK_ROLE_TOGGLE_BUTTON:
  224. return "AXRole: AXToggleButton";
  225. case ATK_ROLE_TOOL_BAR:
  226. return "AXRole: AXToolbar";
  227. case ATK_ROLE_TOOL_TIP:
  228. return "AXRole: AXUserInterfaceTooltip";
  229. case ATK_ROLE_TREE:
  230. return "AXRole: AXTree";
  231. case ATK_ROLE_TREE_TABLE:
  232. return "AXRole: AXTreeGrid";
  233. case ATK_ROLE_TREE_ITEM:
  234. return "AXRole: AXTreeItem";
  235. case ATK_ROLE_WINDOW:
  236. return "AXRole: AXWindow";
  237. case ATK_ROLE_UNKNOWN:
  238. return "AXRole: AXUnknown";
  239. default:
  240. // We want to distinguish ATK_ROLE_UNKNOWN from a known AtkRole which
  241. // our DRT isn't properly handling.
  242. return "AXRole: FIXME not identified";
  243. }
  244. }
  245. AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
  246. : m_element(element)
  247. {
  248. }
  249. AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other)
  250. : JSWrappable()
  251. , m_element(other.m_element)
  252. {
  253. }
  254. AccessibilityUIElement::~AccessibilityUIElement()
  255. {
  256. }
  257. bool AccessibilityUIElement::isEqual(AccessibilityUIElement* otherElement)
  258. {
  259. return m_element == otherElement->platformUIElement();
  260. }
  261. void AccessibilityUIElement::getChildren(Vector<RefPtr<AccessibilityUIElement> >& children)
  262. {
  263. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  264. return;
  265. int count = childrenCount();
  266. for (int i = 0; i < count; i++) {
  267. GRefPtr<AtkObject> child = adoptGRef(atk_object_ref_accessible_child(ATK_OBJECT(m_element.get()), i));
  268. children.append(AccessibilityUIElement::create(child.get()));
  269. }
  270. }
  271. void AccessibilityUIElement::getChildrenWithRange(Vector<RefPtr<AccessibilityUIElement> >& children, unsigned location, unsigned length)
  272. {
  273. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  274. return;
  275. unsigned end = location + length;
  276. for (unsigned i = location; i < end; i++) {
  277. GRefPtr<AtkObject> child = adoptGRef(atk_object_ref_accessible_child(ATK_OBJECT(m_element.get()), i));
  278. children.append(AccessibilityUIElement::create(child.get()));
  279. }
  280. }
  281. int AccessibilityUIElement::childrenCount()
  282. {
  283. if (!m_element)
  284. return 0;
  285. return atk_object_get_n_accessible_children(ATK_OBJECT(m_element.get()));
  286. }
  287. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::elementAtPoint(int x, int y)
  288. {
  289. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  290. return 0;
  291. GRefPtr<AtkObject> objectAtPoint = adoptGRef(atk_component_ref_accessible_at_point(ATK_COMPONENT(m_element.get()), x, y, ATK_XY_WINDOW));
  292. return objectAtPoint ? AccessibilityUIElement::create(objectAtPoint.get()) : 0;
  293. }
  294. unsigned AccessibilityUIElement::indexOfChild(AccessibilityUIElement* element)
  295. {
  296. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  297. return 0;
  298. Vector<RefPtr<AccessibilityUIElement> > children;
  299. getChildren(children);
  300. unsigned count = children.size();
  301. for (unsigned i = 0; i < count; i++)
  302. if (children[i]->isEqual(element))
  303. return i;
  304. return 0;
  305. }
  306. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::childAtIndex(unsigned index)
  307. {
  308. Vector<RefPtr<AccessibilityUIElement> > children;
  309. getChildrenWithRange(children, index, 1);
  310. if (children.size() == 1)
  311. return children[0];
  312. return 0;
  313. }
  314. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::linkedUIElementAtIndex(unsigned index)
  315. {
  316. // FIXME: implement
  317. return 0;
  318. }
  319. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::ariaOwnsElementAtIndex(unsigned index)
  320. {
  321. // FIXME: implement
  322. return 0;
  323. }
  324. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::ariaFlowToElementAtIndex(unsigned index)
  325. {
  326. // FIXME: implement
  327. return 0;
  328. }
  329. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::disclosedRowAtIndex(unsigned index)
  330. {
  331. // FIXME: implement
  332. return 0;
  333. }
  334. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::rowAtIndex(unsigned index)
  335. {
  336. // FIXME: implement
  337. return 0;
  338. }
  339. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::selectedChildAtIndex(unsigned index) const
  340. {
  341. // FIXME: implement
  342. return 0;
  343. }
  344. unsigned AccessibilityUIElement::selectedChildrenCount() const
  345. {
  346. // FIXME: implement
  347. return 0;
  348. }
  349. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::selectedRowAtIndex(unsigned index)
  350. {
  351. // FIXME: implement
  352. return 0;
  353. }
  354. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::titleUIElement()
  355. {
  356. if (!m_element)
  357. return 0;
  358. AtkRelationSet* set = atk_object_ref_relation_set(ATK_OBJECT(m_element.get()));
  359. if (!set)
  360. return 0;
  361. AtkObject* target = 0;
  362. int count = atk_relation_set_get_n_relations(set);
  363. for (int i = 0; i < count; i++) {
  364. AtkRelation* relation = atk_relation_set_get_relation(set, i);
  365. if (atk_relation_get_relation_type(relation) == ATK_RELATION_LABELLED_BY) {
  366. GPtrArray* targetList = atk_relation_get_target(relation);
  367. if (targetList->len)
  368. target = static_cast<AtkObject*>(g_ptr_array_index(targetList, 0));
  369. }
  370. }
  371. g_object_unref(set);
  372. return target ? AccessibilityUIElement::create(target) : 0;
  373. }
  374. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::parentElement()
  375. {
  376. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  377. return 0;
  378. AtkObject* parent = atk_object_get_parent(ATK_OBJECT(m_element.get()));
  379. return parent ? AccessibilityUIElement::create(parent) : 0;
  380. }
  381. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::disclosedByRow()
  382. {
  383. // FIXME: implement
  384. return 0;
  385. }
  386. JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfLinkedUIElements()
  387. {
  388. // FIXME: implement
  389. return JSStringCreateWithCharacters(0, 0);
  390. }
  391. JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfDocumentLinks()
  392. {
  393. // FIXME: implement
  394. return JSStringCreateWithCharacters(0, 0);
  395. }
  396. JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfChildren()
  397. {
  398. // FIXME: implement
  399. return JSStringCreateWithCharacters(0, 0);
  400. }
  401. JSRetainPtr<JSStringRef> AccessibilityUIElement::allAttributes()
  402. {
  403. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  404. return JSStringCreateWithCharacters(0, 0);
  405. GOwnPtr<gchar> attributeData(attributeSetToString(atk_object_get_attributes(ATK_OBJECT(m_element.get()))));
  406. return JSStringCreateWithUTF8CString(attributeData.get());
  407. }
  408. JSRetainPtr<JSStringRef> AccessibilityUIElement::stringAttributeValue(JSStringRef attribute)
  409. {
  410. if (!m_element)
  411. return JSStringCreateWithCharacters(0, 0);
  412. String atkAttributeName = coreAttributeToAtkAttribute(attribute);
  413. if (atkAttributeName.isNull())
  414. return JSStringCreateWithCharacters(0, 0);
  415. GOwnPtr<gchar> attributeValue;
  416. GOwnPtr<GSList> objectAttributes(atk_object_get_attributes(ATK_OBJECT(m_element.get())));
  417. for (GSList* attributes = objectAttributes.get(); attributes; attributes = attributes->next) {
  418. AtkAttribute* atkAttribute = static_cast<AtkAttribute*>(attributes->data);
  419. if (!strcmp(atkAttribute->name, atkAttributeName.utf8().data())) {
  420. attributeValue.set(g_strdup(atkAttribute->value));
  421. break;
  422. }
  423. }
  424. attributesClear(objectAttributes.get());
  425. return JSStringCreateWithUTF8CString(attributeValue.get());
  426. }
  427. double AccessibilityUIElement::numberAttributeValue(JSStringRef attribute)
  428. {
  429. // FIXME: implement
  430. return 0.0f;
  431. }
  432. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::uiElementAttributeValue(JSStringRef attribute) const
  433. {
  434. // FIXME: implement
  435. return 0;
  436. }
  437. bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute)
  438. {
  439. // FIXME: implement
  440. return false;
  441. }
  442. bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute)
  443. {
  444. // FIXME: implement
  445. return false;
  446. }
  447. bool AccessibilityUIElement::isAttributeSupported(JSStringRef attribute)
  448. {
  449. // FIXME: implement
  450. return false;
  451. }
  452. JSRetainPtr<JSStringRef> AccessibilityUIElement::parameterizedAttributeNames()
  453. {
  454. // FIXME: implement
  455. return JSStringCreateWithCharacters(0, 0);
  456. }
  457. JSRetainPtr<JSStringRef> AccessibilityUIElement::role()
  458. {
  459. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  460. return JSStringCreateWithCharacters(0, 0);
  461. AtkRole role = atk_object_get_role(ATK_OBJECT(m_element.get()));
  462. if (!role)
  463. return JSStringCreateWithCharacters(0, 0);
  464. GOwnPtr<gchar> axRole(g_strdup(roleToString(role)));
  465. return JSStringCreateWithUTF8CString(axRole.get());
  466. }
  467. JSRetainPtr<JSStringRef> AccessibilityUIElement::subrole()
  468. {
  469. // FIXME: implement
  470. return JSStringCreateWithCharacters(0, 0);
  471. }
  472. JSRetainPtr<JSStringRef> AccessibilityUIElement::roleDescription()
  473. {
  474. // FIXME: implement
  475. return JSStringCreateWithCharacters(0, 0);
  476. }
  477. JSRetainPtr<JSStringRef> AccessibilityUIElement::title()
  478. {
  479. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  480. return JSStringCreateWithCharacters(0, 0);
  481. const gchar* name = atk_object_get_name(ATK_OBJECT(m_element.get()));
  482. GOwnPtr<gchar> axTitle(g_strdup_printf("AXTitle: %s", name ? name : ""));
  483. return JSStringCreateWithUTF8CString(axTitle.get());
  484. }
  485. JSRetainPtr<JSStringRef> AccessibilityUIElement::description()
  486. {
  487. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  488. return JSStringCreateWithCharacters(0, 0);
  489. const gchar* description = atk_object_get_description(ATK_OBJECT(m_element.get()));
  490. if (!description)
  491. return JSStringCreateWithCharacters(0, 0);
  492. GOwnPtr<gchar> axDesc(g_strdup_printf("AXDescription: %s", description));
  493. return JSStringCreateWithUTF8CString(axDesc.get());
  494. }
  495. JSRetainPtr<JSStringRef> AccessibilityUIElement::orientation() const
  496. {
  497. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  498. return JSStringCreateWithCharacters(0, 0);
  499. const gchar* axOrientation = 0;
  500. if (checkElementState(m_element.get(), ATK_STATE_HORIZONTAL))
  501. axOrientation = "AXOrientation: AXHorizontalOrientation";
  502. else if (checkElementState(m_element.get(), ATK_STATE_VERTICAL))
  503. axOrientation = "AXOrientation: AXVerticalOrientation";
  504. if (!axOrientation)
  505. return JSStringCreateWithCharacters(0, 0);
  506. return JSStringCreateWithUTF8CString(axOrientation);
  507. }
  508. JSRetainPtr<JSStringRef> AccessibilityUIElement::stringValue()
  509. {
  510. if (!m_element || !ATK_IS_TEXT(m_element.get()))
  511. return JSStringCreateWithCharacters(0, 0);
  512. GOwnPtr<gchar> text(atk_text_get_text(ATK_TEXT(m_element.get()), 0, -1));
  513. GOwnPtr<gchar> textWithReplacedCharacters(replaceCharactersForResults(text.get()));
  514. GOwnPtr<gchar> axValue(g_strdup_printf("AXValue: %s", textWithReplacedCharacters.get()));
  515. return JSStringCreateWithUTF8CString(axValue.get());
  516. }
  517. JSRetainPtr<JSStringRef> AccessibilityUIElement::language()
  518. {
  519. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  520. return JSStringCreateWithCharacters(0, 0);
  521. const gchar* locale = atk_object_get_object_locale(ATK_OBJECT(m_element.get()));
  522. if (!locale)
  523. return JSStringCreateWithCharacters(0, 0);
  524. return JSStringCreateWithUTF8CString(g_strdup_printf("AXLanguage: %s", locale));
  525. }
  526. JSRetainPtr<JSStringRef> AccessibilityUIElement::helpText() const
  527. {
  528. // FIXME: implement
  529. // We need a way to call WebCore::AccessibilityObject::helpText()
  530. // from here, probably a new helper class in WebProcess/WebCoreSupport.
  531. return JSStringCreateWithCharacters(0, 0);
  532. }
  533. double AccessibilityUIElement::x()
  534. {
  535. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  536. return 0.0f;
  537. int x, y;
  538. atk_component_get_position(ATK_COMPONENT(m_element.get()), &x, &y, ATK_XY_SCREEN);
  539. return x;
  540. }
  541. double AccessibilityUIElement::y()
  542. {
  543. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  544. return 0.0f;
  545. int x, y;
  546. atk_component_get_position(ATK_COMPONENT(m_element.get()), &x, &y, ATK_XY_SCREEN);
  547. return y;
  548. }
  549. double AccessibilityUIElement::width()
  550. {
  551. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  552. return 0.0f;
  553. int width, height;
  554. atk_component_get_size(ATK_COMPONENT(m_element.get()), &width, &height);
  555. return width;
  556. }
  557. double AccessibilityUIElement::height()
  558. {
  559. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  560. return 0.0f;
  561. int width, height;
  562. atk_component_get_size(ATK_COMPONENT(m_element.get()), &width, &height);
  563. return height;
  564. }
  565. double AccessibilityUIElement::clickPointX()
  566. {
  567. // FIXME: implement
  568. return 0.0f;
  569. }
  570. double AccessibilityUIElement::clickPointY()
  571. {
  572. // FIXME: implement
  573. return 0.0f;
  574. }
  575. double AccessibilityUIElement::intValue() const
  576. {
  577. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  578. return 0.0f;
  579. GValue value = G_VALUE_INIT;
  580. atk_value_get_current_value(ATK_VALUE(m_element.get()), &value);
  581. if (!G_VALUE_HOLDS_FLOAT(&value))
  582. return 0.0f;
  583. return g_value_get_float(&value);
  584. }
  585. double AccessibilityUIElement::minValue()
  586. {
  587. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  588. return 0.0f;
  589. GValue value = G_VALUE_INIT;
  590. atk_value_get_minimum_value(ATK_VALUE(m_element.get()), &value);
  591. if (!G_VALUE_HOLDS_FLOAT(&value))
  592. return 0.0f;
  593. return g_value_get_float(&value);
  594. }
  595. double AccessibilityUIElement::maxValue()
  596. {
  597. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  598. return 0.0f;
  599. GValue value = G_VALUE_INIT;
  600. atk_value_get_maximum_value(ATK_VALUE(m_element.get()), &value);
  601. if (!G_VALUE_HOLDS_FLOAT(&value))
  602. return 0.0f;
  603. return g_value_get_float(&value);
  604. }
  605. JSRetainPtr<JSStringRef> AccessibilityUIElement::valueDescription()
  606. {
  607. // FIXME: implement
  608. return JSStringCreateWithCharacters(0, 0);
  609. }
  610. int AccessibilityUIElement::insertionPointLineNumber()
  611. {
  612. // FIXME: implement
  613. return -1;
  614. }
  615. bool AccessibilityUIElement::isPressActionSupported()
  616. {
  617. // FIXME: implement
  618. return false;
  619. }
  620. bool AccessibilityUIElement::isIncrementActionSupported()
  621. {
  622. // FIXME: implement
  623. return false;
  624. }
  625. bool AccessibilityUIElement::isDecrementActionSupported()
  626. {
  627. // FIXME: implement
  628. return false;
  629. }
  630. bool AccessibilityUIElement::isEnabled()
  631. {
  632. return checkElementState(m_element.get(), ATK_STATE_ENABLED);
  633. }
  634. bool AccessibilityUIElement::isRequired() const
  635. {
  636. // FIXME: implement
  637. return false;
  638. }
  639. bool AccessibilityUIElement::isFocused() const
  640. {
  641. return checkElementState(m_element.get(), ATK_STATE_FOCUSED);
  642. }
  643. bool AccessibilityUIElement::isSelected() const
  644. {
  645. return checkElementState(m_element.get(), ATK_STATE_SELECTED);
  646. }
  647. bool AccessibilityUIElement::isExpanded() const
  648. {
  649. return checkElementState(m_element.get(), ATK_STATE_EXPANDED);
  650. }
  651. bool AccessibilityUIElement::isChecked() const
  652. {
  653. return checkElementState(m_element.get(), ATK_STATE_CHECKED);
  654. }
  655. int AccessibilityUIElement::hierarchicalLevel() const
  656. {
  657. // FIXME: implement
  658. return 0;
  659. }
  660. JSRetainPtr<JSStringRef> AccessibilityUIElement::speak()
  661. {
  662. // FIXME: implement
  663. return JSStringCreateWithCharacters(0, 0);
  664. }
  665. bool AccessibilityUIElement::ariaIsGrabbed() const
  666. {
  667. // FIXME: implement
  668. return false;
  669. }
  670. JSRetainPtr<JSStringRef> AccessibilityUIElement::ariaDropEffects() const
  671. {
  672. // FIXME: implement
  673. return JSStringCreateWithCharacters(0, 0);
  674. }
  675. // parameterized attributes
  676. int AccessibilityUIElement::lineForIndex(int index)
  677. {
  678. // FIXME: implement
  679. return 0;
  680. }
  681. JSRetainPtr<JSStringRef> AccessibilityUIElement::rangeForLine(int line)
  682. {
  683. // FIXME: implement
  684. return JSStringCreateWithCharacters(0, 0);
  685. }
  686. JSRetainPtr<JSStringRef> AccessibilityUIElement::rangeForPosition(int x, int y)
  687. {
  688. // FIXME: implement
  689. return JSStringCreateWithCharacters(0, 0);
  690. }
  691. JSRetainPtr<JSStringRef> AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
  692. {
  693. // FIXME: implement
  694. return JSStringCreateWithCharacters(0, 0);
  695. }
  696. JSRetainPtr<JSStringRef> AccessibilityUIElement::stringForRange(unsigned location, unsigned length)
  697. {
  698. // FIXME: implement
  699. return JSStringCreateWithCharacters(0, 0);
  700. }
  701. JSRetainPtr<JSStringRef> AccessibilityUIElement::attributedStringForRange(unsigned location, unsigned length)
  702. {
  703. // FIXME: implement
  704. return JSStringCreateWithCharacters(0, 0);
  705. }
  706. bool AccessibilityUIElement::attributedStringRangeIsMisspelled(unsigned location, unsigned length)
  707. {
  708. // FIXME: implement
  709. return false;
  710. }
  711. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::uiElementForSearchPredicate(JSContextRef context, AccessibilityUIElement* startElement, bool isDirectionNext, JSValueRef searchKey, JSStringRef searchText, bool visibleOnly)
  712. {
  713. // FIXME: implement
  714. return 0;
  715. }
  716. JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumnHeaders()
  717. {
  718. // FIXME: implement
  719. return JSStringCreateWithCharacters(0, 0);
  720. }
  721. JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRowHeaders()
  722. {
  723. // FIXME: implement
  724. return JSStringCreateWithCharacters(0, 0);
  725. }
  726. JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfColumns()
  727. {
  728. // FIXME: implement
  729. return JSStringCreateWithCharacters(0, 0);
  730. }
  731. JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfRows()
  732. {
  733. // FIXME: implement
  734. return JSStringCreateWithCharacters(0, 0);
  735. }
  736. JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfVisibleCells()
  737. {
  738. // FIXME: implement
  739. return JSStringCreateWithCharacters(0, 0);
  740. }
  741. JSRetainPtr<JSStringRef> AccessibilityUIElement::attributesOfHeader()
  742. {
  743. // FIXME: implement
  744. return JSStringCreateWithCharacters(0, 0);
  745. }
  746. int AccessibilityUIElement::rowCount()
  747. {
  748. if (!m_element || !ATK_IS_TABLE(m_element.get()))
  749. return 0;
  750. return atk_table_get_n_rows(ATK_TABLE(m_element.get()));
  751. }
  752. int AccessibilityUIElement::columnCount()
  753. {
  754. if (!m_element || !ATK_IS_TABLE(m_element.get()))
  755. return 0;
  756. return atk_table_get_n_columns(ATK_TABLE(m_element.get()));
  757. }
  758. int AccessibilityUIElement::indexInTable()
  759. {
  760. // FIXME: implement
  761. return -1;
  762. }
  763. JSRetainPtr<JSStringRef> AccessibilityUIElement::rowIndexRange()
  764. {
  765. // Range in table for rows.
  766. return indexRangeInTable(m_element.get(), true);
  767. }
  768. JSRetainPtr<JSStringRef> AccessibilityUIElement::columnIndexRange()
  769. {
  770. // Range in table for columns.
  771. return indexRangeInTable(m_element.get(), false);
  772. }
  773. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::cellForColumnAndRow(unsigned col, unsigned row)
  774. {
  775. if (!m_element || !ATK_IS_TABLE(m_element.get()))
  776. return 0;
  777. // Adopt the AtkObject representing the cell because
  778. // at_table_ref_at() transfers full ownership.
  779. GRefPtr<AtkObject> foundCell = adoptGRef(atk_table_ref_at(ATK_TABLE(m_element.get()), row, col));
  780. return foundCell ? AccessibilityUIElement::create(foundCell.get()) : 0;
  781. }
  782. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::horizontalScrollbar() const
  783. {
  784. // FIXME: implement
  785. return 0;
  786. }
  787. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::verticalScrollbar() const
  788. {
  789. // FIXME: implement
  790. return 0;
  791. }
  792. JSRetainPtr<JSStringRef> AccessibilityUIElement::selectedTextRange()
  793. {
  794. // FIXME: implement
  795. return JSStringCreateWithCharacters(0, 0);
  796. }
  797. void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length)
  798. {
  799. // FIXME: implement
  800. }
  801. void AccessibilityUIElement::increment()
  802. {
  803. alterCurrentValue(m_element.get(), 1);
  804. }
  805. void AccessibilityUIElement::decrement()
  806. {
  807. alterCurrentValue(m_element.get(), -1);
  808. }
  809. void AccessibilityUIElement::showMenu()
  810. {
  811. // FIXME: implement
  812. }
  813. void AccessibilityUIElement::press()
  814. {
  815. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  816. return;
  817. if (!ATK_IS_ACTION(m_element.get()))
  818. return;
  819. // Only one action per object is supported so far.
  820. atk_action_do_action(ATK_ACTION(m_element.get()), 0);
  821. }
  822. void AccessibilityUIElement::setSelectedChild(AccessibilityUIElement* element) const
  823. {
  824. // FIXME: implement
  825. }
  826. JSRetainPtr<JSStringRef> AccessibilityUIElement::accessibilityValue() const
  827. {
  828. // FIXME: implement
  829. return JSStringCreateWithCharacters(0, 0);
  830. }
  831. JSRetainPtr<JSStringRef> AccessibilityUIElement::documentEncoding()
  832. {
  833. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  834. return JSStringCreateWithCharacters(0, 0);
  835. AtkRole role = atk_object_get_role(ATK_OBJECT(m_element.get()));
  836. if (role != ATK_ROLE_DOCUMENT_FRAME)
  837. return JSStringCreateWithCharacters(0, 0);
  838. return JSStringCreateWithUTF8CString(atk_document_get_attribute_value(ATK_DOCUMENT(m_element.get()), "Encoding"));
  839. }
  840. JSRetainPtr<JSStringRef> AccessibilityUIElement::documentURI()
  841. {
  842. if (!m_element || !ATK_IS_OBJECT(m_element.get()))
  843. return JSStringCreateWithCharacters(0, 0);
  844. AtkRole role = atk_object_get_role(ATK_OBJECT(m_element.get()));
  845. if (role != ATK_ROLE_DOCUMENT_FRAME)
  846. return JSStringCreateWithCharacters(0, 0);
  847. return JSStringCreateWithUTF8CString(atk_document_get_attribute_value(ATK_DOCUMENT(m_element.get()), "URI"));
  848. }
  849. JSRetainPtr<JSStringRef> AccessibilityUIElement::url()
  850. {
  851. // FIXME: implement
  852. return JSStringCreateWithCharacters(0, 0);
  853. }
  854. bool AccessibilityUIElement::addNotificationListener(JSValueRef functionCallback)
  855. {
  856. // FIXME: implement
  857. return true;
  858. }
  859. bool AccessibilityUIElement::removeNotificationListener()
  860. {
  861. // FIXME: implement
  862. return true;
  863. }
  864. bool AccessibilityUIElement::isFocusable() const
  865. {
  866. return checkElementState(m_element.get(), ATK_STATE_FOCUSABLE);
  867. }
  868. bool AccessibilityUIElement::isSelectable() const
  869. {
  870. return checkElementState(m_element.get(), ATK_STATE_SELECTABLE);
  871. }
  872. bool AccessibilityUIElement::isMultiSelectable() const
  873. {
  874. return checkElementState(m_element.get(), ATK_STATE_MULTISELECTABLE);
  875. }
  876. bool AccessibilityUIElement::isVisible() const
  877. {
  878. return checkElementState(m_element.get(), ATK_STATE_VISIBLE);
  879. }
  880. bool AccessibilityUIElement::isOffScreen() const
  881. {
  882. // FIXME: implement
  883. return false;
  884. }
  885. bool AccessibilityUIElement::isCollapsed() const
  886. {
  887. // FIXME: implement
  888. return false;
  889. }
  890. bool AccessibilityUIElement::isIgnored() const
  891. {
  892. // FIXME: implement
  893. return false;
  894. }
  895. bool AccessibilityUIElement::hasPopup() const
  896. {
  897. // FIXME: implement
  898. return false;
  899. }
  900. void AccessibilityUIElement::takeFocus()
  901. {
  902. // FIXME: implement
  903. }
  904. void AccessibilityUIElement::takeSelection()
  905. {
  906. // FIXME: implement
  907. }
  908. void AccessibilityUIElement::addSelection()
  909. {
  910. // FIXME: implement
  911. }
  912. void AccessibilityUIElement::removeSelection()
  913. {
  914. // FIXME: implement
  915. }
  916. // Text markers
  917. PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForElement(AccessibilityUIElement* element)
  918. {
  919. // FIXME: implement
  920. return 0;
  921. }
  922. int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange* range)
  923. {
  924. // FIXME: implement
  925. return 0;
  926. }
  927. PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::previousTextMarker(AccessibilityTextMarker* textMarker)
  928. {
  929. // FIXME: implement
  930. return 0;
  931. }
  932. PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::nextTextMarker(AccessibilityTextMarker* textMarker)
  933. {
  934. // FIXME: implement
  935. return 0;
  936. }
  937. JSRetainPtr<JSStringRef> AccessibilityUIElement::stringForTextMarkerRange(AccessibilityTextMarkerRange* markerRange)
  938. {
  939. // FIXME: implement
  940. return JSStringCreateWithCharacters(0, 0);
  941. }
  942. PassRefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::textMarkerRangeForMarkers(AccessibilityTextMarker* startMarker, AccessibilityTextMarker* endMarker)
  943. {
  944. // FIXME: implement
  945. return 0;
  946. }
  947. PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::startTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
  948. {
  949. // FIXME: implement
  950. return 0;
  951. }
  952. PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::endTextMarkerForTextMarkerRange(AccessibilityTextMarkerRange* range)
  953. {
  954. // FIXME: implement
  955. return 0;
  956. }
  957. PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::textMarkerForPoint(int x, int y)
  958. {
  959. // FIXME: implement
  960. return 0;
  961. }
  962. PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::accessibilityElementForTextMarker(AccessibilityTextMarker* marker)
  963. {
  964. // FIXME: implement
  965. return 0;
  966. }
  967. bool AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute(JSStringRef attribute, AccessibilityTextMarkerRange* range)
  968. {
  969. // FIXME: implement
  970. return false;
  971. }
  972. int AccessibilityUIElement::indexForTextMarker(AccessibilityTextMarker* marker)
  973. {
  974. // FIXME: implement
  975. return -1;
  976. }
  977. bool AccessibilityUIElement::isTextMarkerValid(AccessibilityTextMarker* textMarker)
  978. {
  979. // FIXME: implement
  980. return false;
  981. }
  982. PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::textMarkerForIndex(int textIndex)
  983. {
  984. // FIXME: implement
  985. return 0;
  986. }
  987. void AccessibilityUIElement::scrollToMakeVisible()
  988. {
  989. // FIXME: implement
  990. }
  991. JSRetainPtr<JSStringRef> AccessibilityUIElement::supportedActions() const
  992. {
  993. // FIXME: implement
  994. return 0;
  995. }
  996. JSRetainPtr<JSStringRef> AccessibilityUIElement::pathDescription() const
  997. {
  998. notImplemented();
  999. return 0;
  1000. }
  1001. JSRetainPtr<JSStringRef> AccessibilityUIElement::mathPostscriptsDescription() const
  1002. {
  1003. notImplemented();
  1004. return 0;
  1005. }
  1006. JSRetainPtr<JSStringRef> AccessibilityUIElement::mathPrescriptsDescription() const
  1007. {
  1008. notImplemented();
  1009. return 0;
  1010. }
  1011. } // namespace WTR
  1012. #endif