BaseAccessibles.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #ifndef mozilla_a11y_BaseAccessibles_h__
  6. #define mozilla_a11y_BaseAccessibles_h__
  7. #include "AccessibleWrap.h"
  8. #include "HyperTextAccessibleWrap.h"
  9. class nsIContent;
  10. /**
  11. * This file contains a number of classes that are used as base
  12. * classes for the different accessibility implementations of
  13. * the HTML and XUL widget sets. --jgaunt
  14. */
  15. namespace mozilla {
  16. namespace a11y {
  17. /**
  18. * Leaf version of DOM Accessible -- has no children
  19. */
  20. class LeafAccessible : public AccessibleWrap
  21. {
  22. public:
  23. LeafAccessible(nsIContent* aContent, DocAccessible* aDoc);
  24. // nsISupports
  25. NS_DECL_ISUPPORTS_INHERITED
  26. // Accessible
  27. virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY,
  28. EWhichChildAtPoint aWhichChild) override;
  29. virtual bool InsertChildAt(uint32_t aIndex, Accessible* aChild) override final;
  30. virtual bool RemoveChild(Accessible* aChild) override final;
  31. virtual bool IsAcceptableChild(nsIContent* aEl) const override;
  32. protected:
  33. virtual ~LeafAccessible() {}
  34. };
  35. /**
  36. * Used for text or image accessible nodes contained by link accessibles or
  37. * accessibles for nodes with registered click event handler. It knows how to
  38. * report the state of the host link (traveled or not) and can activate (click)
  39. * the host accessible programmatically.
  40. */
  41. class LinkableAccessible : public AccessibleWrap
  42. {
  43. public:
  44. enum { eAction_Jump = 0 };
  45. LinkableAccessible(nsIContent* aContent, DocAccessible* aDoc) :
  46. AccessibleWrap(aContent, aDoc)
  47. {
  48. }
  49. NS_DECL_ISUPPORTS_INHERITED
  50. // Accessible
  51. virtual void Value(nsString& aValue) override;
  52. virtual uint64_t NativeLinkState() const override;
  53. virtual void TakeFocus() override;
  54. // ActionAccessible
  55. virtual uint8_t ActionCount() override;
  56. virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;
  57. virtual bool DoAction(uint8_t index) override;
  58. virtual KeyBinding AccessKey() const override;
  59. // ActionAccessible helpers
  60. Accessible* ActionWalk(bool* aIsLink = nullptr,
  61. bool* aIsOnclick = nullptr,
  62. bool* aIsLabelWithControl = nullptr);
  63. // HyperLinkAccessible
  64. virtual already_AddRefed<nsIURI> AnchorURIAt(uint32_t aAnchorIndex) override;
  65. protected:
  66. virtual ~LinkableAccessible() {}
  67. };
  68. /**
  69. * A simple accessible that gets its enumerated role.
  70. */
  71. template<a11y::role R>
  72. class EnumRoleAccessible : public AccessibleWrap
  73. {
  74. public:
  75. EnumRoleAccessible(nsIContent* aContent, DocAccessible* aDoc) :
  76. AccessibleWrap(aContent, aDoc) { }
  77. NS_IMETHOD QueryInterface(REFNSIID aIID, void** aPtr) override
  78. { return Accessible::QueryInterface(aIID, aPtr); }
  79. // Accessible
  80. virtual a11y::role NativeRole() override { return R; }
  81. protected:
  82. virtual ~EnumRoleAccessible() { }
  83. };
  84. /**
  85. * A wrapper accessible around native accessible to connect it with
  86. * crossplatform accessible tree.
  87. */
  88. class DummyAccessible : public AccessibleWrap
  89. {
  90. public:
  91. explicit DummyAccessible(DocAccessible* aDocument = nullptr) :
  92. AccessibleWrap(nullptr, aDocument) { }
  93. virtual uint64_t NativeState() override final;
  94. virtual uint64_t NativeInteractiveState() const override final;
  95. virtual uint64_t NativeLinkState() const override final;
  96. virtual bool NativelyUnavailable() const override final;
  97. virtual void ApplyARIAState(uint64_t* aState) const override final;
  98. protected:
  99. virtual ~DummyAccessible() { }
  100. };
  101. } // namespace a11y
  102. } // namespace mozilla
  103. #endif