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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. *
8 #ifndef MOZILLA_A11Y_ProxyAccessibleWrap_h
9 #define MOZILLA_A11Y_ProxyAccessibleWrap_h
11 #include "AccessibleWrap.h"
12 #include "DocAccessibleParent.h"
18 * A wrapper for Accessible proxies. The public methods here should be overriden
19 * from AccessibleWrap or its super classes.
20 * This gives us an abstraction layer so SessionAccessibility doesn't have
21 * to distinguish between a local or remote accessibles.
22 * NOTE: This shouldn't be regarded as a full Accessible implementation.
24 class ProxyAccessibleWrap
: public AccessibleWrap
{
26 explicit ProxyAccessibleWrap(ProxyAccessible
* aProxy
);
28 virtual void Shutdown() override
;
32 virtual already_AddRefed
<nsIPersistentProperties
> Attributes() override
;
34 virtual uint32_t ChildCount() const override
;
36 virtual Accessible
* GetChildAt(uint32_t aIndex
) const override
;
38 virtual ENameValueFlag
Name(nsString
& aName
) const override
;
40 virtual void Value(nsString
& aValue
) const override
;
42 virtual uint64_t State() override
;
44 virtual nsIntRect
Bounds() const override
;
46 virtual void ScrollTo(uint32_t aHow
) const override
;
48 virtual uint8_t ActionCount() const override
;
50 virtual bool DoAction(uint8_t aIndex
) const override
;
54 virtual void SetTextContents(const nsAString
& aText
) override
;
56 virtual void GetTextContents(nsAString
& aText
) override
;
58 virtual bool GetSelectionBounds(int32_t* aStartOffset
,
59 int32_t* aEndOffset
) override
;
61 virtual void WrapperDOMNodeID(nsString
& aDOMNodeID
) override
;
64 virtual role
WrapperRole() override
;
66 virtual AccessibleWrap
* WrapperParent() override
;
68 virtual bool WrapperRangeInfo(double* aCurVal
, double* aMinVal
,
69 double* aMaxVal
, double* aStep
) override
;
72 class DocProxyAccessibleWrap
: public ProxyAccessibleWrap
{
74 explicit DocProxyAccessibleWrap(DocAccessibleParent
* aProxy
)
75 : ProxyAccessibleWrap(aProxy
) {
76 mGenericTypes
|= eDocument
;
78 if (auto parent
= ParentDocument()) {
80 parent
->AddID(mID
, this);
87 virtual void Shutdown() override
{
89 auto parent
= ParentDocument();
91 MOZ_ASSERT(mID
!= kNoID
, "A non root accessible always has a parent");
92 parent
->RemoveID(mID
);
97 mBits
.proxy
= nullptr;
98 mStateFlags
|= eIsDefunct
;
101 DocProxyAccessibleWrap
* ParentDocument() {
102 DocAccessibleParent
* proxy
= static_cast<DocAccessibleParent
*>(Proxy());
104 if (DocAccessibleParent
* parent
= proxy
->ParentDoc()) {
105 return reinterpret_cast<DocProxyAccessibleWrap
*>(parent
->GetWrapper());
111 DocProxyAccessibleWrap
* GetChildDocumentAt(uint32_t aIndex
) {
112 auto doc
= Proxy()->AsDoc();
113 if (doc
&& doc
->ChildDocCount() > aIndex
) {
114 return reinterpret_cast<DocProxyAccessibleWrap
*>(
115 doc
->ChildDocAt(aIndex
)->GetWrapper());
121 void AddID(uint32_t aID
, AccessibleWrap
* aAcc
) {
122 mIDToAccessibleMap
.Put(aID
, aAcc
);
124 void RemoveID(uint32_t aID
) { mIDToAccessibleMap
.Remove(aID
); }
125 AccessibleWrap
* GetAccessibleByID(uint32_t aID
) const {
126 return mIDToAccessibleMap
.Get(aID
);
131 * This provides a mapping from 32 bit id to accessible objects.
133 nsDataHashtable
<nsUint32HashKey
, AccessibleWrap
*> mIDToAccessibleMap
;
136 } // namespace mozilla