XULColorPickerAccessible.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 "XULColorPickerAccessible.h"
  6. #include "Accessible-inl.h"
  7. #include "nsAccUtils.h"
  8. #include "nsCoreUtils.h"
  9. #include "DocAccessible.h"
  10. #include "Role.h"
  11. #include "States.h"
  12. #include "nsIDOMElement.h"
  13. #include "nsMenuPopupFrame.h"
  14. using namespace mozilla::a11y;
  15. ////////////////////////////////////////////////////////////////////////////////
  16. // XULColorPickerTileAccessible
  17. ////////////////////////////////////////////////////////////////////////////////
  18. XULColorPickerTileAccessible::
  19. XULColorPickerTileAccessible(nsIContent* aContent, DocAccessible* aDoc) :
  20. AccessibleWrap(aContent, aDoc)
  21. {
  22. }
  23. ////////////////////////////////////////////////////////////////////////////////
  24. // XULColorPickerTileAccessible: Accessible
  25. void
  26. XULColorPickerTileAccessible::Value(nsString& aValue)
  27. {
  28. aValue.Truncate();
  29. mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::color, aValue);
  30. }
  31. role
  32. XULColorPickerTileAccessible::NativeRole()
  33. {
  34. return roles::PUSHBUTTON;
  35. }
  36. uint64_t
  37. XULColorPickerTileAccessible::NativeState()
  38. {
  39. uint64_t state = AccessibleWrap::NativeState();
  40. if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::selected))
  41. state |= states::SELECTED;
  42. return state;
  43. }
  44. uint64_t
  45. XULColorPickerTileAccessible::NativeInteractiveState() const
  46. {
  47. return NativelyUnavailable() ?
  48. states::UNAVAILABLE : states::FOCUSABLE | states::SELECTABLE;
  49. }
  50. ////////////////////////////////////////////////////////////////////////////////
  51. // XULColorPickerTileAccessible: Widgets
  52. Accessible*
  53. XULColorPickerTileAccessible::ContainerWidget() const
  54. {
  55. Accessible* parent = Parent();
  56. if (parent) {
  57. Accessible* grandParent = parent->Parent();
  58. if (grandParent && grandParent->IsMenuButton())
  59. return grandParent;
  60. }
  61. return nullptr;
  62. }
  63. ////////////////////////////////////////////////////////////////////////////////
  64. // XULColorPickerAccessible
  65. ////////////////////////////////////////////////////////////////////////////////
  66. XULColorPickerAccessible::
  67. XULColorPickerAccessible(nsIContent* aContent, DocAccessible* aDoc) :
  68. XULColorPickerTileAccessible(aContent, aDoc)
  69. {
  70. mGenericTypes |= eMenuButton;
  71. }
  72. ////////////////////////////////////////////////////////////////////////////////
  73. // XULColorPickerAccessible: Accessible
  74. uint64_t
  75. XULColorPickerAccessible::NativeState()
  76. {
  77. uint64_t state = AccessibleWrap::NativeState();
  78. return state | states::HASPOPUP;
  79. }
  80. role
  81. XULColorPickerAccessible::NativeRole()
  82. {
  83. return roles::BUTTONDROPDOWNGRID;
  84. }
  85. ////////////////////////////////////////////////////////////////////////////////
  86. // XULColorPickerAccessible: Widgets
  87. bool
  88. XULColorPickerAccessible::IsWidget() const
  89. {
  90. return true;
  91. }
  92. bool
  93. XULColorPickerAccessible::IsActiveWidget() const
  94. {
  95. return FocusMgr()->HasDOMFocus(mContent);
  96. }
  97. bool
  98. XULColorPickerAccessible::AreItemsOperable() const
  99. {
  100. Accessible* menuPopup = mChildren.SafeElementAt(0, nullptr);
  101. if (menuPopup) {
  102. nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(menuPopup->GetFrame());
  103. return menuPopupFrame && menuPopupFrame->IsOpen();
  104. }
  105. return false;
  106. }
  107. ////////////////////////////////////////////////////////////////////////////////
  108. // XULColorPickerAccessible: Accessible
  109. bool
  110. XULColorPickerAccessible::IsAcceptableChild(nsIContent* aEl) const
  111. {
  112. nsAutoString role;
  113. nsCoreUtils::XBLBindingRole(aEl, role);
  114. return role.EqualsLiteral("xul:panel") &&
  115. aEl->AttrValueIs(kNameSpaceID_None, nsGkAtoms::noautofocus,
  116. nsGkAtoms::_true, eCaseMatters);
  117. }