xpcAccessibleDocument.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_xpcAccessibleDocument_h_
  6. #define mozilla_a11y_xpcAccessibleDocument_h_
  7. #include "nsIAccessibleDocument.h"
  8. #include "DocAccessible.h"
  9. #include "nsAccessibilityService.h"
  10. #include "xpcAccessibleApplication.h"
  11. #include "xpcAccessibleHyperText.h"
  12. namespace mozilla {
  13. namespace a11y {
  14. /**
  15. * XPCOM wrapper around DocAccessible class.
  16. */
  17. class xpcAccessibleDocument : public xpcAccessibleHyperText,
  18. public nsIAccessibleDocument
  19. {
  20. public:
  21. explicit xpcAccessibleDocument(DocAccessible* aIntl) :
  22. xpcAccessibleHyperText(aIntl), mCache(kDefaultCacheLength), mRemote(false) { }
  23. xpcAccessibleDocument(ProxyAccessible* aProxy, uint32_t aInterfaces) :
  24. xpcAccessibleHyperText(aProxy, aInterfaces), mCache(kDefaultCacheLength),
  25. mRemote(true) {}
  26. NS_DECL_ISUPPORTS_INHERITED
  27. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(xpcAccessibleDocument,
  28. xpcAccessibleGeneric)
  29. // nsIAccessibleDocument
  30. NS_IMETHOD GetURL(nsAString& aURL) final override;
  31. NS_IMETHOD GetTitle(nsAString& aTitle) final override;
  32. NS_IMETHOD GetMimeType(nsAString& aType) final override;
  33. NS_IMETHOD GetDocType(nsAString& aType) final override;
  34. NS_IMETHOD GetDOMDocument(nsIDOMDocument** aDOMDocument) final override;
  35. NS_IMETHOD GetWindow(mozIDOMWindowProxy** aDOMWindow) final override;
  36. NS_IMETHOD GetParentDocument(nsIAccessibleDocument** aDocument)
  37. final override;
  38. NS_IMETHOD GetChildDocumentCount(uint32_t* aCount) final override;
  39. NS_IMETHOD GetChildDocumentAt(uint32_t aIndex,
  40. nsIAccessibleDocument** aDocument)
  41. final override;
  42. NS_IMETHOD GetVirtualCursor(nsIAccessiblePivot** aVirtualCursor)
  43. final override;
  44. /**
  45. * Return XPCOM wrapper for the internal accessible.
  46. */
  47. xpcAccessibleGeneric* GetAccessible(Accessible* aAccessible);
  48. xpcAccessibleGeneric* GetXPCAccessible(ProxyAccessible* aProxy);
  49. virtual void Shutdown() override;
  50. protected:
  51. virtual ~xpcAccessibleDocument() {}
  52. private:
  53. DocAccessible* Intl()
  54. {
  55. if (Accessible* acc = mIntl.AsAccessible()) {
  56. return acc->AsDoc();
  57. }
  58. return nullptr;
  59. }
  60. void NotifyOfShutdown(Accessible* aAccessible)
  61. {
  62. MOZ_ASSERT(!mRemote);
  63. xpcAccessibleGeneric* xpcAcc = mCache.GetWeak(aAccessible);
  64. if (xpcAcc)
  65. xpcAcc->Shutdown();
  66. mCache.Remove(aAccessible);
  67. }
  68. void NotifyOfShutdown(ProxyAccessible* aProxy)
  69. {
  70. MOZ_ASSERT(mRemote);
  71. xpcAccessibleGeneric* acc = mCache.GetWeak(aProxy);
  72. if (acc) {
  73. acc->Shutdown();
  74. }
  75. mCache.Remove(aProxy);
  76. }
  77. friend class DocManager;
  78. friend class DocAccessible;
  79. friend class ProxyAccessible;
  80. friend class ProxyAccessibleBase<ProxyAccessible>;
  81. xpcAccessibleDocument(const xpcAccessibleDocument&) = delete;
  82. xpcAccessibleDocument& operator =(const xpcAccessibleDocument&) = delete;
  83. nsRefPtrHashtable<nsPtrHashKey<const void>, xpcAccessibleGeneric> mCache;
  84. bool mRemote;
  85. };
  86. inline xpcAccessibleGeneric*
  87. ToXPC(Accessible* aAccessible)
  88. {
  89. if (!aAccessible)
  90. return nullptr;
  91. if (aAccessible->IsApplication())
  92. return XPCApplicationAcc();
  93. xpcAccessibleDocument* xpcDoc =
  94. GetAccService()->GetXPCDocument(aAccessible->Document());
  95. return xpcDoc ? xpcDoc->GetAccessible(aAccessible) : nullptr;
  96. }
  97. xpcAccessibleGeneric* ToXPC(AccessibleOrProxy aAcc);
  98. inline xpcAccessibleHyperText*
  99. ToXPCText(HyperTextAccessible* aAccessible)
  100. {
  101. if (!aAccessible)
  102. return nullptr;
  103. xpcAccessibleDocument* xpcDoc =
  104. GetAccService()->GetXPCDocument(aAccessible->Document());
  105. return static_cast<xpcAccessibleHyperText*>(xpcDoc->GetAccessible(aAccessible));
  106. }
  107. inline xpcAccessibleDocument*
  108. ToXPCDocument(DocAccessible* aAccessible)
  109. {
  110. return GetAccService()->GetXPCDocument(aAccessible);
  111. }
  112. inline xpcAccessibleDocument*
  113. ToXPCDocument(DocAccessibleParent* aAccessible)
  114. {
  115. return GetAccService()->GetXPCDocument(aAccessible);
  116. }
  117. } // namespace a11y
  118. } // namespace mozilla
  119. #endif