Source code

Revision control

Other Tools

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/. *
6
*/
7
8
#ifndef MOZILLA_A11Y_ProxyAccessibleWrap_h
9
#define MOZILLA_A11Y_ProxyAccessibleWrap_h
10
11
#include "AccessibleWrap.h"
12
#include "DocAccessibleParent.h"
13
14
namespace mozilla {
15
namespace a11y {
16
17
/**
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.
23
*/
24
class ProxyAccessibleWrap : public AccessibleWrap {
25
public:
26
explicit ProxyAccessibleWrap(ProxyAccessible* aProxy);
27
28
virtual void Shutdown() override;
29
30
// Accessible
31
32
virtual already_AddRefed<nsIPersistentProperties> Attributes() override;
33
34
virtual uint32_t ChildCount() const override;
35
36
virtual Accessible* GetChildAt(uint32_t aIndex) const override;
37
38
virtual ENameValueFlag Name(nsString& aName) const override;
39
40
virtual void Value(nsString& aValue) const override;
41
42
virtual uint64_t State() override;
43
44
virtual nsIntRect Bounds() const override;
45
46
MOZ_CAN_RUN_SCRIPT
47
virtual void ScrollTo(uint32_t aHow) const override;
48
49
virtual uint8_t ActionCount() const override;
50
51
virtual bool DoAction(uint8_t aIndex) const override;
52
53
// AccessibleWrap
54
55
virtual void SetTextContents(const nsAString& aText) override;
56
57
virtual void GetTextContents(nsAString& aText) override;
58
59
virtual bool GetSelectionBounds(int32_t* aStartOffset,
60
int32_t* aEndOffset) override;
61
62
virtual void WrapperDOMNodeID(nsString& aDOMNodeID) override;
63
64
private:
65
virtual role WrapperRole() override;
66
67
virtual AccessibleWrap* WrapperParent() override;
68
69
virtual bool WrapperRangeInfo(double* aCurVal, double* aMinVal,
70
double* aMaxVal, double* aStep) override;
71
};
72
73
class DocProxyAccessibleWrap : public ProxyAccessibleWrap {
74
public:
75
explicit DocProxyAccessibleWrap(DocAccessibleParent* aProxy)
76
: ProxyAccessibleWrap(aProxy) {
77
mGenericTypes |= eDocument;
78
79
if (auto parent = ParentDocument()) {
80
mID = AcquireID();
81
parent->AddID(mID, this);
82
} else {
83
// top level
84
mID = kNoID;
85
}
86
}
87
88
virtual void Shutdown() override {
89
if (mID) {
90
auto parent = ParentDocument();
91
if (parent) {
92
MOZ_ASSERT(mID != kNoID, "A non root accessible always has a parent");
93
parent->RemoveID(mID);
94
ReleaseID(mID);
95
}
96
}
97
mID = 0;
98
mBits.proxy = nullptr;
99
mStateFlags |= eIsDefunct;
100
}
101
102
DocProxyAccessibleWrap* ParentDocument() {
103
DocAccessibleParent* proxy = static_cast<DocAccessibleParent*>(Proxy());
104
MOZ_ASSERT(proxy);
105
if (DocAccessibleParent* parent = proxy->ParentDoc()) {
106
return reinterpret_cast<DocProxyAccessibleWrap*>(parent->GetWrapper());
107
}
108
109
return nullptr;
110
}
111
112
DocProxyAccessibleWrap* GetChildDocumentAt(uint32_t aIndex) {
113
auto doc = Proxy()->AsDoc();
114
if (doc && doc->ChildDocCount() > aIndex) {
115
return reinterpret_cast<DocProxyAccessibleWrap*>(
116
doc->ChildDocAt(aIndex)->GetWrapper());
117
}
118
119
return nullptr;
120
}
121
122
void AddID(uint32_t aID, AccessibleWrap* aAcc) {
123
mIDToAccessibleMap.Put(aID, aAcc);
124
}
125
void RemoveID(uint32_t aID) { mIDToAccessibleMap.Remove(aID); }
126
AccessibleWrap* GetAccessibleByID(uint32_t aID) const {
127
return mIDToAccessibleMap.Get(aID);
128
}
129
130
private:
131
/*
132
* This provides a mapping from 32 bit id to accessible objects.
133
*/
134
nsDataHashtable<nsUint32HashKey, AccessibleWrap*> mIDToAccessibleMap;
135
};
136
} // namespace a11y
137
} // namespace mozilla
138
139
#endif