Accessible-inl.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #ifndef mozilla_a11y_Accessible_inl_h_
  6. #define mozilla_a11y_Accessible_inl_h_
  7. #include "DocAccessible.h"
  8. #include "ARIAMap.h"
  9. #include "nsCoreUtils.h"
  10. #ifdef A11Y_LOG
  11. #include "Logging.h"
  12. #endif
  13. namespace mozilla {
  14. namespace a11y {
  15. inline mozilla::a11y::role
  16. Accessible::Role()
  17. {
  18. const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
  19. if (!roleMapEntry || roleMapEntry->roleRule != kUseMapRole)
  20. return ARIATransformRole(NativeRole());
  21. return ARIATransformRole(roleMapEntry->role);
  22. }
  23. inline bool
  24. Accessible::HasARIARole() const
  25. {
  26. return mRoleMapEntryIndex != aria::NO_ROLE_MAP_ENTRY_INDEX;
  27. }
  28. inline bool
  29. Accessible::IsARIARole(nsIAtom* aARIARole) const
  30. {
  31. const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
  32. return roleMapEntry && roleMapEntry->Is(aARIARole);
  33. }
  34. inline bool
  35. Accessible::HasStrongARIARole() const
  36. {
  37. const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
  38. return roleMapEntry && roleMapEntry->roleRule == kUseMapRole;
  39. }
  40. inline const nsRoleMapEntry*
  41. Accessible::ARIARoleMap() const
  42. {
  43. return aria::GetRoleMapFromIndex(mRoleMapEntryIndex);
  44. }
  45. inline mozilla::a11y::role
  46. Accessible::ARIARole()
  47. {
  48. const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
  49. if (!roleMapEntry || roleMapEntry->roleRule != kUseMapRole)
  50. return mozilla::a11y::roles::NOTHING;
  51. return ARIATransformRole(roleMapEntry->role);
  52. }
  53. inline void
  54. Accessible::SetRoleMapEntry(const nsRoleMapEntry* aRoleMapEntry)
  55. {
  56. mRoleMapEntryIndex = aria::GetIndexFromRoleMap(aRoleMapEntry);
  57. }
  58. inline bool
  59. Accessible::IsSearchbox() const
  60. {
  61. const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
  62. return (roleMapEntry && roleMapEntry->Is(nsGkAtoms::searchbox)) ||
  63. (mContent->IsHTMLElement(nsGkAtoms::input) &&
  64. mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
  65. nsGkAtoms::textInputType, eCaseMatters));
  66. }
  67. inline bool
  68. Accessible::HasGenericType(AccGenericType aType) const
  69. {
  70. const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
  71. return (mGenericTypes & aType) ||
  72. (roleMapEntry && roleMapEntry->IsOfType(aType));
  73. }
  74. inline bool
  75. Accessible::HasNumericValue() const
  76. {
  77. if (mStateFlags & eHasNumericValue)
  78. return true;
  79. const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
  80. return roleMapEntry && roleMapEntry->valueRule != eNoValue;
  81. }
  82. inline void
  83. Accessible::ScrollTo(uint32_t aHow) const
  84. {
  85. if (mContent)
  86. nsCoreUtils::ScrollTo(mDoc->PresShell(), mContent, aHow);
  87. }
  88. inline bool
  89. Accessible::InsertAfter(Accessible* aNewChild, Accessible* aRefChild)
  90. {
  91. MOZ_ASSERT(aNewChild, "No new child to insert");
  92. if (aRefChild && aRefChild->Parent() != this) {
  93. #ifdef A11Y_LOG
  94. logging::TreeInfo("broken accessible tree", 0,
  95. "parent", this, "prev sibling parent",
  96. aRefChild->Parent(), "child", aNewChild, nullptr);
  97. if (logging::IsEnabled(logging::eVerbose)) {
  98. logging::Tree("TREE", "Document tree", mDoc);
  99. logging::DOMTree("TREE", "DOM document tree", mDoc);
  100. }
  101. #endif
  102. MOZ_ASSERT_UNREACHABLE("Broken accessible tree");
  103. mDoc->UnbindFromDocument(aNewChild);
  104. return false;
  105. }
  106. return InsertChildAt(aRefChild ? aRefChild->IndexInParent() + 1 : 0,
  107. aNewChild);
  108. }
  109. } // namespace a11y
  110. } // namespace mozilla
  111. #endif