1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_a11y_xpcAccessibleDocument_h_
8 #define mozilla_a11y_xpcAccessibleDocument_h_
10 #include "nsIAccessibleDocument.h"
12 #include "DocAccessible.h"
13 #include "nsAccessibilityService.h"
14 #include "xpcAccessibleApplication.h"
15 #include "xpcAccessibleHyperText.h"
21 * XPCOM wrapper around DocAccessible class.
23 class xpcAccessibleDocument
: public xpcAccessibleHyperText
,
24 public nsIAccessibleDocument
{
26 explicit xpcAccessibleDocument(Accessible
* aIntl
)
27 : xpcAccessibleHyperText(aIntl
),
28 mCache(kDefaultCacheLength
),
29 mRemote(aIntl
->IsRemote()) {
30 // XXX: Once there is a base doc class that both remote and local
31 // accessibles inherit, we can add the type to the prototype and remove this
33 MOZ_ASSERT(aIntl
->IsDoc());
36 NS_DECL_ISUPPORTS_INHERITED
38 // nsIAccessibleDocument
39 NS_IMETHOD
GetURL(nsAString
& aURL
) final
;
40 NS_IMETHOD
GetTitle(nsAString
& aTitle
) final
;
41 NS_IMETHOD
GetMimeType(nsAString
& aType
) final
;
42 NS_IMETHOD
GetDocType(nsAString
& aType
) final
;
43 NS_IMETHOD
GetDOMDocument(dom::Document
** aDOMDocument
) final
;
44 NS_IMETHOD
GetWindow(mozIDOMWindowProxy
** aDOMWindow
) final
;
45 NS_IMETHOD
GetParentDocument(nsIAccessibleDocument
** aDocument
) final
;
46 NS_IMETHOD
GetChildDocumentCount(uint32_t* aCount
) final
;
47 NS_IMETHOD
GetChildDocumentAt(uint32_t aIndex
,
48 nsIAccessibleDocument
** aDocument
) final
;
49 NS_IMETHOD
GetVirtualCursor(nsIAccessiblePivot
** aVirtualCursor
) final
;
52 * Return XPCOM wrapper for the internal accessible.
54 xpcAccessibleGeneric
* GetAccessible(Accessible
* aAccessible
);
56 virtual void Shutdown() override
;
59 virtual ~xpcAccessibleDocument() {}
62 DocAccessible
* Intl() {
63 if (LocalAccessible
* acc
= mIntl
->AsLocal()) {
70 void NotifyOfShutdown(Accessible
* aAccessible
) {
71 xpcAccessibleGeneric
* xpcAcc
= mCache
.Get(aAccessible
);
76 mCache
.Remove(aAccessible
);
77 if (mCache
.Count() == 0 && mRefCnt
== 1) {
78 if (mIntl
->IsLocal()) {
79 GetAccService()->RemoveFromXPCDocumentCache(mIntl
->AsLocal()->AsDoc());
81 GetAccService()->RemoveFromRemoteXPCDocumentCache(
82 mIntl
->AsRemote()->AsDoc());
87 friend class DocManager
;
88 friend class DocAccessible
;
89 friend class RemoteAccessible
;
90 friend class RemoteAccessibleBase
<RemoteAccessible
>;
91 friend class xpcAccessibleGeneric
;
93 xpcAccessibleDocument(const xpcAccessibleDocument
&) = delete;
94 xpcAccessibleDocument
& operator=(const xpcAccessibleDocument
&) = delete;
96 nsTHashMap
<nsPtrHashKey
<const void>, xpcAccessibleGeneric
*> mCache
;
100 inline xpcAccessibleGeneric
* ToXPC(Accessible
* aAccessible
) {
101 if (!aAccessible
) return nullptr;
103 if (aAccessible
->IsApplication()) return XPCApplicationAcc();
105 xpcAccessibleDocument
* xpcDoc
=
106 aAccessible
->IsLocal()
107 ? GetAccService()->GetXPCDocument(aAccessible
->AsLocal()->Document())
108 : GetAccService()->GetXPCDocument(
109 aAccessible
->AsRemote()->Document());
110 return xpcDoc
? xpcDoc
->GetAccessible(aAccessible
) : nullptr;
113 inline xpcAccessibleHyperText
* ToXPCText(Accessible
* aAccessible
) {
114 if (!aAccessible
|| !aAccessible
->IsHyperText()) {
118 xpcAccessibleDocument
* xpcDoc
=
119 aAccessible
->IsLocal()
120 ? GetAccService()->GetXPCDocument(aAccessible
->AsLocal()->Document())
121 : nsAccessibilityService::GetXPCDocument(
122 aAccessible
->AsRemote()->Document());
123 return static_cast<xpcAccessibleHyperText
*>(
124 xpcDoc
? xpcDoc
->GetAccessible(aAccessible
) : nullptr);
127 inline xpcAccessibleDocument
* ToXPCDocument(DocAccessible
* aAccessible
) {
128 return GetAccService()->GetXPCDocument(aAccessible
);
131 inline xpcAccessibleDocument
* ToXPCDocument(DocAccessibleParent
* aAccessible
) {
132 return GetAccService()->GetXPCDocument(aAccessible
);
136 } // namespace mozilla