XULTabAccessible.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "XULTabAccessible.h"
  6. #include "nsAccUtils.h"
  7. #include "Relation.h"
  8. #include "Role.h"
  9. #include "States.h"
  10. // NOTE: alphabetically ordered
  11. #include "nsIDocument.h"
  12. #include "nsIDOMXULSelectCntrlEl.h"
  13. #include "nsIDOMXULSelectCntrlItemEl.h"
  14. #include "nsIDOMXULRelatedElement.h"
  15. using namespace mozilla::a11y;
  16. ////////////////////////////////////////////////////////////////////////////////
  17. // XULTabAccessible
  18. ////////////////////////////////////////////////////////////////////////////////
  19. XULTabAccessible::
  20. XULTabAccessible(nsIContent* aContent, DocAccessible* aDoc) :
  21. AccessibleWrap(aContent, aDoc)
  22. {
  23. }
  24. ////////////////////////////////////////////////////////////////////////////////
  25. // XULTabAccessible: Accessible
  26. uint8_t
  27. XULTabAccessible::ActionCount()
  28. {
  29. return 1;
  30. }
  31. void
  32. XULTabAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
  33. {
  34. if (aIndex == eAction_Switch)
  35. aName.AssignLiteral("switch");
  36. }
  37. bool
  38. XULTabAccessible::DoAction(uint8_t index)
  39. {
  40. if (index == eAction_Switch) {
  41. nsCOMPtr<nsIDOMXULElement> tab(do_QueryInterface(mContent));
  42. if (tab) {
  43. tab->Click();
  44. return true;
  45. }
  46. }
  47. return false;
  48. }
  49. ////////////////////////////////////////////////////////////////////////////////
  50. // XULTabAccessible: Accessible
  51. role
  52. XULTabAccessible::NativeRole()
  53. {
  54. return roles::PAGETAB;
  55. }
  56. uint64_t
  57. XULTabAccessible::NativeState()
  58. {
  59. // Possible states: focused, focusable, unavailable(disabled), offscreen.
  60. // get focus and disable status from base class
  61. uint64_t state = AccessibleWrap::NativeState();
  62. // Check whether the tab is selected and/or pinned
  63. nsCOMPtr<nsIDOMXULSelectControlItemElement> tab(do_QueryInterface(mContent));
  64. if (tab) {
  65. bool selected = false;
  66. if (NS_SUCCEEDED(tab->GetSelected(&selected)) && selected)
  67. state |= states::SELECTED;
  68. if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::pinned,
  69. nsGkAtoms::_true, eCaseMatters))
  70. state |= states::PINNED;
  71. }
  72. return state;
  73. }
  74. uint64_t
  75. XULTabAccessible::NativeInteractiveState() const
  76. {
  77. uint64_t state = Accessible::NativeInteractiveState();
  78. return (state & states::UNAVAILABLE) ? state : state | states::SELECTABLE;
  79. }
  80. Relation
  81. XULTabAccessible::RelationByType(RelationType aType)
  82. {
  83. Relation rel = AccessibleWrap::RelationByType(aType);
  84. if (aType != RelationType::LABEL_FOR)
  85. return rel;
  86. // Expose 'LABEL_FOR' relation on tab accessible for tabpanel accessible.
  87. nsCOMPtr<nsIDOMXULRelatedElement> tabsElm =
  88. do_QueryInterface(mContent->GetParent());
  89. if (!tabsElm)
  90. return rel;
  91. nsCOMPtr<nsIDOMNode> domNode(DOMNode());
  92. nsCOMPtr<nsIDOMNode> tabpanelNode;
  93. tabsElm->GetRelatedElement(domNode, getter_AddRefs(tabpanelNode));
  94. if (!tabpanelNode)
  95. return rel;
  96. nsCOMPtr<nsIContent> tabpanelContent(do_QueryInterface(tabpanelNode));
  97. rel.AppendTarget(mDoc, tabpanelContent);
  98. return rel;
  99. }
  100. ////////////////////////////////////////////////////////////////////////////////
  101. // XULTabsAccessible
  102. ////////////////////////////////////////////////////////////////////////////////
  103. XULTabsAccessible::
  104. XULTabsAccessible(nsIContent* aContent, DocAccessible* aDoc) :
  105. XULSelectControlAccessible(aContent, aDoc)
  106. {
  107. }
  108. role
  109. XULTabsAccessible::NativeRole()
  110. {
  111. return roles::PAGETABLIST;
  112. }
  113. uint8_t
  114. XULTabsAccessible::ActionCount()
  115. {
  116. return 0;
  117. }
  118. void
  119. XULTabsAccessible::Value(nsString& aValue)
  120. {
  121. aValue.Truncate();
  122. }
  123. ENameValueFlag
  124. XULTabsAccessible::NativeName(nsString& aName)
  125. {
  126. // no name
  127. return eNameOK;
  128. }
  129. ////////////////////////////////////////////////////////////////////////////////
  130. // XULTabpanelsAccessible
  131. ////////////////////////////////////////////////////////////////////////////////
  132. role
  133. XULTabpanelsAccessible::NativeRole()
  134. {
  135. return roles::PANE;
  136. }
  137. ////////////////////////////////////////////////////////////////////////////////
  138. // XULTabpanelAccessible
  139. ////////////////////////////////////////////////////////////////////////////////
  140. XULTabpanelAccessible::
  141. XULTabpanelAccessible(nsIContent* aContent, DocAccessible* aDoc) :
  142. AccessibleWrap(aContent, aDoc)
  143. {
  144. }
  145. role
  146. XULTabpanelAccessible::NativeRole()
  147. {
  148. return roles::PROPERTYPAGE;
  149. }
  150. Relation
  151. XULTabpanelAccessible::RelationByType(RelationType aType)
  152. {
  153. Relation rel = AccessibleWrap::RelationByType(aType);
  154. if (aType != RelationType::LABELLED_BY)
  155. return rel;
  156. // Expose 'LABELLED_BY' relation on tabpanel accessible for tab accessible.
  157. nsCOMPtr<nsIDOMXULRelatedElement> tabpanelsElm =
  158. do_QueryInterface(mContent->GetParent());
  159. if (!tabpanelsElm)
  160. return rel;
  161. nsCOMPtr<nsIDOMNode> domNode(DOMNode());
  162. nsCOMPtr<nsIDOMNode> tabNode;
  163. tabpanelsElm->GetRelatedElement(domNode, getter_AddRefs(tabNode));
  164. if (!tabNode)
  165. return rel;
  166. nsCOMPtr<nsIContent> tabContent(do_QueryInterface(tabNode));
  167. rel.AppendTarget(mDoc, tabContent);
  168. return rel;
  169. }