xpcAccessible.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "Accessible-inl.h"
  6. #include "mozilla/a11y/DocAccessibleParent.h"
  7. #include "nsAccUtils.h"
  8. #include "nsIAccessibleRelation.h"
  9. #include "nsIAccessibleRole.h"
  10. #include "nsAccessibleRelation.h"
  11. #include "Relation.h"
  12. #include "Role.h"
  13. #include "RootAccessible.h"
  14. #include "xpcAccessibleDocument.h"
  15. #include "nsIMutableArray.h"
  16. #include "nsIPersistentProperties2.h"
  17. using namespace mozilla::a11y;
  18. NS_IMETHODIMP
  19. xpcAccessible::GetParent(nsIAccessible** aParent)
  20. {
  21. NS_ENSURE_ARG_POINTER(aParent);
  22. *aParent = nullptr;
  23. if (IntlGeneric().IsNull())
  24. return NS_ERROR_FAILURE;
  25. AccessibleOrProxy parent = IntlGeneric().Parent();
  26. NS_IF_ADDREF(*aParent = ToXPC(parent));
  27. return NS_OK;
  28. }
  29. NS_IMETHODIMP
  30. xpcAccessible::GetNextSibling(nsIAccessible** aNextSibling)
  31. {
  32. NS_ENSURE_ARG_POINTER(aNextSibling);
  33. *aNextSibling = nullptr;
  34. if (IntlGeneric().IsNull())
  35. return NS_ERROR_FAILURE;
  36. if (IntlGeneric().IsAccessible()) {
  37. nsresult rv = NS_OK;
  38. NS_IF_ADDREF(*aNextSibling = ToXPC(Intl()->GetSiblingAtOffset(1, &rv)));
  39. return rv;
  40. }
  41. ProxyAccessible* proxy = IntlGeneric().AsProxy();
  42. NS_ENSURE_STATE(proxy);
  43. NS_IF_ADDREF(*aNextSibling = ToXPC(proxy->NextSibling()));
  44. return *aNextSibling ? NS_OK : NS_ERROR_FAILURE;
  45. }
  46. NS_IMETHODIMP
  47. xpcAccessible::GetPreviousSibling(nsIAccessible** aPreviousSibling)
  48. {
  49. NS_ENSURE_ARG_POINTER(aPreviousSibling);
  50. *aPreviousSibling = nullptr;
  51. if (IntlGeneric().IsNull())
  52. return NS_ERROR_FAILURE;
  53. if (IntlGeneric().IsAccessible()) {
  54. nsresult rv = NS_OK;
  55. NS_IF_ADDREF(*aPreviousSibling = ToXPC(Intl()->GetSiblingAtOffset(-1, &rv)));
  56. return rv;
  57. }
  58. ProxyAccessible* proxy = IntlGeneric().AsProxy();
  59. NS_ENSURE_STATE(proxy);
  60. NS_IF_ADDREF(*aPreviousSibling = ToXPC(proxy->PrevSibling()));
  61. return *aPreviousSibling ? NS_OK : NS_ERROR_FAILURE;
  62. }
  63. NS_IMETHODIMP
  64. xpcAccessible::GetFirstChild(nsIAccessible** aFirstChild)
  65. {
  66. NS_ENSURE_ARG_POINTER(aFirstChild);
  67. *aFirstChild = nullptr;
  68. if (IntlGeneric().IsNull())
  69. return NS_ERROR_FAILURE;
  70. NS_IF_ADDREF(*aFirstChild = ToXPC(IntlGeneric().FirstChild()));
  71. return NS_OK;
  72. }
  73. NS_IMETHODIMP
  74. xpcAccessible::GetLastChild(nsIAccessible** aLastChild)
  75. {
  76. NS_ENSURE_ARG_POINTER(aLastChild);
  77. *aLastChild = nullptr;
  78. if (IntlGeneric().IsNull())
  79. return NS_ERROR_FAILURE;
  80. NS_IF_ADDREF(*aLastChild = ToXPC(IntlGeneric().LastChild()));
  81. return NS_OK;
  82. }
  83. NS_IMETHODIMP
  84. xpcAccessible::GetChildCount(int32_t* aChildCount)
  85. {
  86. NS_ENSURE_ARG_POINTER(aChildCount);
  87. if (IntlGeneric().IsNull())
  88. return NS_ERROR_FAILURE;
  89. *aChildCount = IntlGeneric().ChildCount();
  90. return NS_OK;
  91. }
  92. NS_IMETHODIMP
  93. xpcAccessible::GetChildAt(int32_t aChildIndex, nsIAccessible** aChild)
  94. {
  95. NS_ENSURE_ARG_POINTER(aChild);
  96. *aChild = nullptr;
  97. if (IntlGeneric().IsNull())
  98. return NS_ERROR_FAILURE;
  99. // If child index is negative, then return last child.
  100. // XXX: do we really need this?
  101. if (aChildIndex < 0)
  102. aChildIndex = IntlGeneric().ChildCount() - 1;
  103. AccessibleOrProxy child = IntlGeneric().ChildAt(aChildIndex);
  104. if (child.IsNull())
  105. return NS_ERROR_INVALID_ARG;
  106. NS_ADDREF(*aChild = ToXPC(child));
  107. return NS_OK;
  108. }
  109. NS_IMETHODIMP
  110. xpcAccessible::GetChildren(nsIArray** aChildren)
  111. {
  112. NS_ENSURE_ARG_POINTER(aChildren);
  113. *aChildren = nullptr;
  114. if (IntlGeneric().IsNull())
  115. return NS_ERROR_FAILURE;
  116. nsresult rv = NS_OK;
  117. nsCOMPtr<nsIMutableArray> children =
  118. do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
  119. NS_ENSURE_SUCCESS(rv, rv);
  120. uint32_t childCount = IntlGeneric().ChildCount();
  121. for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
  122. AccessibleOrProxy child = IntlGeneric().ChildAt(childIdx);
  123. children->AppendElement(static_cast<nsIAccessible*>(ToXPC(child)), false);
  124. }
  125. children.forget(aChildren);
  126. return NS_OK;
  127. }
  128. NS_IMETHODIMP
  129. xpcAccessible::GetIndexInParent(int32_t* aIndexInParent)
  130. {
  131. NS_ENSURE_ARG_POINTER(aIndexInParent);
  132. *aIndexInParent = -1;
  133. if (IntlGeneric().IsNull())
  134. return NS_ERROR_FAILURE;
  135. if (IntlGeneric().IsAccessible()) {
  136. *aIndexInParent = Intl()->IndexInParent();
  137. } else if (IntlGeneric().IsProxy()) {
  138. *aIndexInParent = IntlGeneric().AsProxy()->IndexInParent();
  139. }
  140. return *aIndexInParent != -1 ? NS_OK : NS_ERROR_FAILURE;
  141. }
  142. NS_IMETHODIMP
  143. xpcAccessible::GetDOMNode(nsIDOMNode** aDOMNode)
  144. {
  145. NS_ENSURE_ARG_POINTER(aDOMNode);
  146. *aDOMNode = nullptr;
  147. if (!Intl())
  148. return NS_ERROR_FAILURE;
  149. nsINode* node = Intl()->GetNode();
  150. if (node)
  151. CallQueryInterface(node, aDOMNode);
  152. return NS_OK;
  153. }
  154. NS_IMETHODIMP
  155. xpcAccessible::GetId(nsAString& aID)
  156. {
  157. #if defined(XP_WIN)
  158. return NS_ERROR_NOT_IMPLEMENTED;
  159. #else
  160. ProxyAccessible* proxy = IntlGeneric().AsProxy();
  161. if (!proxy) {
  162. return NS_ERROR_FAILURE;
  163. }
  164. nsString id;
  165. proxy->DOMNodeID(id);
  166. aID.Assign(id);
  167. return NS_OK;
  168. #endif
  169. }
  170. NS_IMETHODIMP
  171. xpcAccessible::GetDocument(nsIAccessibleDocument** aDocument)
  172. {
  173. NS_ENSURE_ARG_POINTER(aDocument);
  174. *aDocument = nullptr;
  175. if (!Intl())
  176. return NS_ERROR_FAILURE;
  177. NS_IF_ADDREF(*aDocument = ToXPCDocument(Intl()->Document()));
  178. return NS_OK;
  179. }
  180. NS_IMETHODIMP
  181. xpcAccessible::GetRootDocument(nsIAccessibleDocument** aRootDocument)
  182. {
  183. NS_ENSURE_ARG_POINTER(aRootDocument);
  184. *aRootDocument = nullptr;
  185. if (!Intl())
  186. return NS_ERROR_FAILURE;
  187. NS_IF_ADDREF(*aRootDocument = ToXPCDocument(Intl()->RootAccessible()));
  188. return NS_OK;
  189. }
  190. NS_IMETHODIMP
  191. xpcAccessible::GetRole(uint32_t* aRole)
  192. {
  193. NS_ENSURE_ARG_POINTER(aRole);
  194. *aRole = nsIAccessibleRole::ROLE_NOTHING;
  195. if (IntlGeneric().IsNull())
  196. return NS_ERROR_FAILURE;
  197. *aRole = IntlGeneric().Role();
  198. return NS_OK;
  199. }
  200. NS_IMETHODIMP
  201. xpcAccessible::GetState(uint32_t* aState, uint32_t* aExtraState)
  202. {
  203. NS_ENSURE_ARG_POINTER(aState);
  204. if (IntlGeneric().IsNull())
  205. nsAccUtils::To32States(states::DEFUNCT, aState, aExtraState);
  206. else if (Intl())
  207. nsAccUtils::To32States(Intl()->State(), aState, aExtraState);
  208. else
  209. nsAccUtils::To32States(IntlGeneric().AsProxy()->State(), aState,
  210. aExtraState);
  211. return NS_OK;
  212. }
  213. NS_IMETHODIMP
  214. xpcAccessible::GetName(nsAString& aName)
  215. {
  216. aName.Truncate();
  217. if (IntlGeneric().IsNull())
  218. return NS_ERROR_FAILURE;
  219. nsAutoString name;
  220. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  221. proxy->Name(name);
  222. } else {
  223. Intl()->Name(name);
  224. }
  225. aName.Assign(name);
  226. return NS_OK;
  227. }
  228. NS_IMETHODIMP
  229. xpcAccessible::GetDescription(nsAString& aDescription)
  230. {
  231. if (IntlGeneric().IsNull())
  232. return NS_ERROR_FAILURE;
  233. nsAutoString desc;
  234. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  235. proxy->Description(desc);
  236. } else {
  237. Intl()->Description(desc);
  238. }
  239. aDescription.Assign(desc);
  240. return NS_OK;
  241. }
  242. NS_IMETHODIMP
  243. xpcAccessible::GetLanguage(nsAString& aLanguage)
  244. {
  245. if (IntlGeneric().IsNull())
  246. return NS_ERROR_FAILURE;
  247. nsAutoString lang;
  248. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  249. proxy->Language(lang);
  250. } else {
  251. Intl()->Language(lang);
  252. }
  253. aLanguage.Assign(lang);
  254. return NS_OK;
  255. }
  256. NS_IMETHODIMP
  257. xpcAccessible::GetValue(nsAString& aValue)
  258. {
  259. if (IntlGeneric().IsNull())
  260. return NS_ERROR_FAILURE;
  261. nsAutoString value;
  262. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  263. proxy->Value(value);
  264. } else {
  265. Intl()->Value(value);
  266. }
  267. aValue.Assign(value);
  268. return NS_OK;
  269. }
  270. NS_IMETHODIMP
  271. xpcAccessible::GetHelp(nsAString& aHelp)
  272. {
  273. if (IntlGeneric().IsNull())
  274. return NS_ERROR_FAILURE;
  275. nsAutoString help;
  276. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  277. #if defined(XP_WIN)
  278. return NS_ERROR_NOT_IMPLEMENTED;
  279. #else
  280. proxy->Help(help);
  281. #endif
  282. } else {
  283. Intl()->Help(help);
  284. }
  285. aHelp.Assign(help);
  286. return NS_OK;
  287. }
  288. NS_IMETHODIMP
  289. xpcAccessible::GetAccessKey(nsAString& aAccessKey)
  290. {
  291. aAccessKey.Truncate();
  292. if (IntlGeneric().IsNull())
  293. return NS_ERROR_FAILURE;
  294. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  295. #if defined(XP_WIN)
  296. return NS_ERROR_NOT_IMPLEMENTED;
  297. #else
  298. proxy->AccessKey().ToString(aAccessKey);
  299. #endif
  300. } else {
  301. Intl()->AccessKey().ToString(aAccessKey);
  302. }
  303. return NS_OK;
  304. }
  305. NS_IMETHODIMP
  306. xpcAccessible::GetKeyboardShortcut(nsAString& aKeyBinding)
  307. {
  308. aKeyBinding.Truncate();
  309. if (IntlGeneric().IsNull())
  310. return NS_ERROR_FAILURE;
  311. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  312. #if defined(XP_WIN)
  313. return NS_ERROR_NOT_IMPLEMENTED;
  314. #else
  315. proxy->KeyboardShortcut().ToString(aKeyBinding);
  316. #endif
  317. } else {
  318. Intl()->KeyboardShortcut().ToString(aKeyBinding);
  319. }
  320. return NS_OK;
  321. }
  322. NS_IMETHODIMP
  323. xpcAccessible::GetAttributes(nsIPersistentProperties** aAttributes)
  324. {
  325. NS_ENSURE_ARG_POINTER(aAttributes);
  326. *aAttributes = nullptr;
  327. if (IntlGeneric().IsNull()) {
  328. return NS_ERROR_FAILURE;
  329. }
  330. if (Accessible* acc = Intl()) {
  331. nsCOMPtr<nsIPersistentProperties> attributes = acc->Attributes();
  332. attributes.swap(*aAttributes);
  333. return NS_OK;
  334. }
  335. ProxyAccessible* proxy = IntlGeneric().AsProxy();
  336. AutoTArray<Attribute, 10> attrs;
  337. proxy->Attributes(&attrs);
  338. nsCOMPtr<nsIPersistentProperties> props =
  339. do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
  340. uint32_t attrCount = attrs.Length();
  341. nsAutoString unused;
  342. for (uint32_t i = 0; i < attrCount; i++) {
  343. props->SetStringProperty(attrs[i].Name(), attrs[i].Value(), unused);
  344. }
  345. props.forget(aAttributes);
  346. return NS_OK;
  347. }
  348. NS_IMETHODIMP
  349. xpcAccessible::GetBounds(int32_t* aX, int32_t* aY,
  350. int32_t* aWidth, int32_t* aHeight)
  351. {
  352. NS_ENSURE_ARG_POINTER(aX);
  353. *aX = 0;
  354. NS_ENSURE_ARG_POINTER(aY);
  355. *aY = 0;
  356. NS_ENSURE_ARG_POINTER(aWidth);
  357. *aWidth = 0;
  358. NS_ENSURE_ARG_POINTER(aHeight);
  359. *aHeight = 0;
  360. if (IntlGeneric().IsNull())
  361. return NS_ERROR_FAILURE;
  362. nsIntRect rect;
  363. if (Accessible* acc = IntlGeneric().AsAccessible()) {
  364. rect = acc->Bounds();
  365. } else {
  366. rect = IntlGeneric().AsProxy()->Bounds();
  367. }
  368. *aX = rect.x;
  369. *aY = rect.y;
  370. *aWidth = rect.width;
  371. *aHeight = rect.height;
  372. return NS_OK;
  373. }
  374. NS_IMETHODIMP
  375. xpcAccessible::GroupPosition(int32_t* aGroupLevel,
  376. int32_t* aSimilarItemsInGroup,
  377. int32_t* aPositionInGroup)
  378. {
  379. NS_ENSURE_ARG_POINTER(aGroupLevel);
  380. *aGroupLevel = 0;
  381. NS_ENSURE_ARG_POINTER(aSimilarItemsInGroup);
  382. *aSimilarItemsInGroup = 0;
  383. NS_ENSURE_ARG_POINTER(aPositionInGroup);
  384. *aPositionInGroup = 0;
  385. if (!Intl())
  386. return NS_ERROR_FAILURE;
  387. GroupPos groupPos = Intl()->GroupPosition();
  388. *aGroupLevel = groupPos.level;
  389. *aSimilarItemsInGroup = groupPos.setSize;
  390. *aPositionInGroup = groupPos.posInSet;
  391. return NS_OK;
  392. }
  393. NS_IMETHODIMP
  394. xpcAccessible::GetRelationByType(uint32_t aType,
  395. nsIAccessibleRelation** aRelation)
  396. {
  397. NS_ENSURE_ARG_POINTER(aRelation);
  398. *aRelation = nullptr;
  399. NS_ENSURE_ARG(aType <= static_cast<uint32_t>(RelationType::LAST));
  400. if (IntlGeneric().IsNull())
  401. return NS_ERROR_FAILURE;
  402. if (IntlGeneric().IsAccessible()) {
  403. Relation rel = Intl()->RelationByType(static_cast<RelationType>(aType));
  404. NS_ADDREF(*aRelation = new nsAccessibleRelation(aType, &rel));
  405. return NS_OK;
  406. }
  407. #if defined(XP_WIN)
  408. return NS_ERROR_NOT_IMPLEMENTED;
  409. #else
  410. ProxyAccessible* proxy = IntlGeneric().AsProxy();
  411. nsTArray<ProxyAccessible*> targets =
  412. proxy->RelationByType(static_cast<RelationType>(aType));
  413. NS_ADDREF(*aRelation = new nsAccessibleRelation(aType, &targets));
  414. return NS_OK;
  415. #endif
  416. }
  417. NS_IMETHODIMP
  418. xpcAccessible::GetRelations(nsIArray** aRelations)
  419. {
  420. NS_ENSURE_ARG_POINTER(aRelations);
  421. *aRelations = nullptr;
  422. if (IntlGeneric().IsNull())
  423. return NS_ERROR_FAILURE;
  424. nsCOMPtr<nsIMutableArray> relations = do_CreateInstance(NS_ARRAY_CONTRACTID);
  425. NS_ENSURE_TRUE(relations, NS_ERROR_OUT_OF_MEMORY);
  426. static const uint32_t relationTypes[] = {
  427. nsIAccessibleRelation::RELATION_LABELLED_BY,
  428. nsIAccessibleRelation::RELATION_LABEL_FOR,
  429. nsIAccessibleRelation::RELATION_DESCRIBED_BY,
  430. nsIAccessibleRelation::RELATION_DESCRIPTION_FOR,
  431. nsIAccessibleRelation::RELATION_NODE_CHILD_OF,
  432. nsIAccessibleRelation::RELATION_NODE_PARENT_OF,
  433. nsIAccessibleRelation::RELATION_CONTROLLED_BY,
  434. nsIAccessibleRelation::RELATION_CONTROLLER_FOR,
  435. nsIAccessibleRelation::RELATION_FLOWS_TO,
  436. nsIAccessibleRelation::RELATION_FLOWS_FROM,
  437. nsIAccessibleRelation::RELATION_MEMBER_OF,
  438. nsIAccessibleRelation::RELATION_SUBWINDOW_OF,
  439. nsIAccessibleRelation::RELATION_EMBEDS,
  440. nsIAccessibleRelation::RELATION_EMBEDDED_BY,
  441. nsIAccessibleRelation::RELATION_POPUP_FOR,
  442. nsIAccessibleRelation::RELATION_PARENT_WINDOW_OF,
  443. nsIAccessibleRelation::RELATION_DEFAULT_BUTTON,
  444. nsIAccessibleRelation::RELATION_CONTAINING_DOCUMENT,
  445. nsIAccessibleRelation::RELATION_CONTAINING_TAB_PANE,
  446. nsIAccessibleRelation::RELATION_CONTAINING_APPLICATION
  447. };
  448. for (uint32_t idx = 0; idx < ArrayLength(relationTypes); idx++) {
  449. nsCOMPtr<nsIAccessibleRelation> relation;
  450. nsresult rv = GetRelationByType(relationTypes[idx], getter_AddRefs(relation));
  451. if (NS_SUCCEEDED(rv) && relation) {
  452. uint32_t targets = 0;
  453. relation->GetTargetsCount(&targets);
  454. if (targets)
  455. relations->AppendElement(relation, false);
  456. }
  457. }
  458. NS_ADDREF(*aRelations = relations);
  459. return NS_OK;
  460. }
  461. NS_IMETHODIMP
  462. xpcAccessible::GetFocusedChild(nsIAccessible** aChild)
  463. {
  464. NS_ENSURE_ARG_POINTER(aChild);
  465. *aChild = nullptr;
  466. if (IntlGeneric().IsNull())
  467. return NS_ERROR_FAILURE;
  468. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  469. #if defined(XP_WIN)
  470. return NS_ERROR_NOT_IMPLEMENTED;
  471. #else
  472. NS_IF_ADDREF(*aChild = ToXPC(proxy->FocusedChild()));
  473. #endif
  474. } else {
  475. NS_IF_ADDREF(*aChild = ToXPC(Intl()->FocusedChild()));
  476. }
  477. return NS_OK;
  478. }
  479. NS_IMETHODIMP
  480. xpcAccessible::GetChildAtPoint(int32_t aX, int32_t aY,
  481. nsIAccessible** aAccessible)
  482. {
  483. NS_ENSURE_ARG_POINTER(aAccessible);
  484. *aAccessible = nullptr;
  485. if (IntlGeneric().IsNull())
  486. return NS_ERROR_FAILURE;
  487. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  488. #if defined(XP_WIN)
  489. return NS_ERROR_NOT_IMPLEMENTED;
  490. #else
  491. NS_IF_ADDREF(*aAccessible =
  492. ToXPC(proxy->ChildAtPoint(aX, aY, Accessible::eDirectChild)));
  493. #endif
  494. } else {
  495. NS_IF_ADDREF(*aAccessible =
  496. ToXPC(Intl()->ChildAtPoint(aX, aY, Accessible::eDirectChild)));
  497. }
  498. return NS_OK;
  499. }
  500. NS_IMETHODIMP
  501. xpcAccessible::GetDeepestChildAtPoint(int32_t aX, int32_t aY,
  502. nsIAccessible** aAccessible)
  503. {
  504. NS_ENSURE_ARG_POINTER(aAccessible);
  505. *aAccessible = nullptr;
  506. if (IntlGeneric().IsNull())
  507. return NS_ERROR_FAILURE;
  508. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  509. #if defined(XP_WIN)
  510. return NS_ERROR_NOT_IMPLEMENTED;
  511. #else
  512. NS_IF_ADDREF(*aAccessible =
  513. ToXPC(proxy->ChildAtPoint(aX, aY, Accessible::eDeepestChild)));
  514. #endif
  515. } else {
  516. NS_IF_ADDREF(*aAccessible =
  517. ToXPC(Intl()->ChildAtPoint(aX, aY, Accessible::eDeepestChild)));
  518. }
  519. return NS_OK;
  520. }
  521. NS_IMETHODIMP
  522. xpcAccessible::SetSelected(bool aSelect)
  523. {
  524. if (IntlGeneric().IsNull())
  525. return NS_ERROR_FAILURE;
  526. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  527. #if defined(XP_WIN)
  528. return NS_ERROR_NOT_IMPLEMENTED;
  529. #else
  530. proxy->SetSelected(aSelect);
  531. #endif
  532. } else {
  533. Intl()->SetSelected(aSelect);
  534. }
  535. return NS_OK;
  536. }
  537. NS_IMETHODIMP
  538. xpcAccessible::TakeSelection()
  539. {
  540. if (IntlGeneric().IsNull())
  541. return NS_ERROR_FAILURE;
  542. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  543. #if defined(XP_WIN)
  544. return NS_ERROR_NOT_IMPLEMENTED;
  545. #else
  546. proxy->TakeSelection();
  547. #endif
  548. } else {
  549. Intl()->TakeSelection();
  550. }
  551. return NS_OK;
  552. }
  553. NS_IMETHODIMP
  554. xpcAccessible::TakeFocus()
  555. {
  556. if (IntlGeneric().IsNull())
  557. return NS_ERROR_FAILURE;
  558. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  559. #if defined(XP_WIN)
  560. return NS_ERROR_NOT_IMPLEMENTED;
  561. #else
  562. proxy->TakeFocus();
  563. #endif
  564. } else {
  565. Intl()->TakeFocus();
  566. }
  567. return NS_OK;
  568. }
  569. NS_IMETHODIMP
  570. xpcAccessible::GetActionCount(uint8_t* aActionCount)
  571. {
  572. NS_ENSURE_ARG_POINTER(aActionCount);
  573. *aActionCount = 0;
  574. if (IntlGeneric().IsNull())
  575. return NS_ERROR_FAILURE;
  576. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  577. #if defined(XP_WIN)
  578. return NS_ERROR_NOT_IMPLEMENTED;
  579. #else
  580. *aActionCount = proxy->ActionCount();
  581. #endif
  582. } else {
  583. *aActionCount = Intl()->ActionCount();
  584. }
  585. return NS_OK;
  586. }
  587. NS_IMETHODIMP
  588. xpcAccessible::GetActionName(uint8_t aIndex, nsAString& aName)
  589. {
  590. if (IntlGeneric().IsNull())
  591. return NS_ERROR_FAILURE;
  592. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  593. #if defined(XP_WIN)
  594. return NS_ERROR_NOT_IMPLEMENTED;
  595. #else
  596. nsString name;
  597. proxy->ActionNameAt(aIndex, name);
  598. aName.Assign(name);
  599. #endif
  600. } else {
  601. if (aIndex >= Intl()->ActionCount())
  602. return NS_ERROR_INVALID_ARG;
  603. Intl()->ActionNameAt(aIndex, aName);
  604. }
  605. return NS_OK;
  606. }
  607. NS_IMETHODIMP
  608. xpcAccessible::GetActionDescription(uint8_t aIndex, nsAString& aDescription)
  609. {
  610. if (IntlGeneric().IsNull())
  611. return NS_ERROR_FAILURE;
  612. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  613. #if defined(XP_WIN)
  614. return NS_ERROR_NOT_IMPLEMENTED;
  615. #else
  616. nsString description;
  617. proxy->ActionDescriptionAt(aIndex, description);
  618. aDescription.Assign(description);
  619. #endif
  620. } else {
  621. if (aIndex >= Intl()->ActionCount())
  622. return NS_ERROR_INVALID_ARG;
  623. Intl()->ActionDescriptionAt(aIndex, aDescription);
  624. }
  625. return NS_OK;
  626. }
  627. NS_IMETHODIMP
  628. xpcAccessible::DoAction(uint8_t aIndex)
  629. {
  630. if (IntlGeneric().IsNull())
  631. return NS_ERROR_FAILURE;
  632. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  633. #if defined(XP_WIN)
  634. return NS_ERROR_NOT_IMPLEMENTED;
  635. #else
  636. return proxy->DoAction(aIndex) ? NS_OK : NS_ERROR_INVALID_ARG;
  637. #endif
  638. } else {
  639. return Intl()->DoAction(aIndex) ?
  640. NS_OK : NS_ERROR_INVALID_ARG;
  641. }
  642. }
  643. NS_IMETHODIMP
  644. xpcAccessible::ScrollTo(uint32_t aHow)
  645. {
  646. if (IntlGeneric().IsNull())
  647. return NS_ERROR_FAILURE;
  648. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  649. #if defined(XP_WIN)
  650. return NS_ERROR_NOT_IMPLEMENTED;
  651. #else
  652. proxy->ScrollTo(aHow);
  653. #endif
  654. } else {
  655. Intl()->ScrollTo(aHow);
  656. }
  657. return NS_OK;
  658. }
  659. NS_IMETHODIMP
  660. xpcAccessible::ScrollToPoint(uint32_t aCoordinateType, int32_t aX, int32_t aY)
  661. {
  662. if (IntlGeneric().IsNull())
  663. return NS_ERROR_FAILURE;
  664. if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
  665. #if defined(XP_WIN)
  666. return NS_ERROR_NOT_IMPLEMENTED;
  667. #else
  668. proxy->ScrollToPoint(aCoordinateType, aX, aY);
  669. #endif
  670. } else {
  671. Intl()->ScrollToPoint(aCoordinateType, aX, aY);
  672. }
  673. return NS_OK;
  674. }