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 Pivot(int32_t aGranularity, bool aForward,
63
bool aInclusive) override;
64
65
virtual void NavigateText(int32_t aGranularity, int32_t aStartOffset,
66
int32_t aEndOffset, bool aForward,
67
bool aSelect) override;
68
69
virtual void SetSelection(int32_t aStart, int32_t aEnd) override;
70
71
virtual void Cut() override;
72
73
virtual void Copy() override;
74
75
virtual void Paste() override;
76
77
virtual void ExploreByTouch(float aX, float aY) override;
78
79
virtual void WrapperDOMNodeID(nsString& aDOMNodeID) override;
80
81
private:
82
virtual role WrapperRole() override;
83
84
virtual AccessibleWrap* WrapperParent() override;
85
86
virtual bool WrapperRangeInfo(double* aCurVal, double* aMinVal,
87
double* aMaxVal, double* aStep) override;
88
};
89
90
class DocProxyAccessibleWrap : public ProxyAccessibleWrap {
91
public:
92
explicit DocProxyAccessibleWrap(DocAccessibleParent* aProxy)
93
: ProxyAccessibleWrap(aProxy) {
94
mGenericTypes |= eDocument;
95
96
if (auto parent = ParentDocument()) {
97
mID = AcquireID();
98
parent->AddID(mID, this);
99
} else {
100
// top level
101
mID = kNoID;
102
}
103
}
104
105
virtual void Shutdown() override {
106
if (mID) {
107
auto parent = ParentDocument();
108
if (parent) {
109
MOZ_ASSERT(mID != kNoID, "A non root accessible always has a parent");
110
parent->RemoveID(mID);
111
ReleaseID(mID);
112
}
113
}
114
mID = 0;
115
mBits.proxy = nullptr;
116
mStateFlags |= eIsDefunct;
117
}
118
119
DocProxyAccessibleWrap* ParentDocument() {
120
DocAccessibleParent* proxy = static_cast<DocAccessibleParent*>(Proxy());
121
MOZ_ASSERT(proxy);
122
if (DocAccessibleParent* parent = proxy->ParentDoc()) {
123
return reinterpret_cast<DocProxyAccessibleWrap*>(parent->GetWrapper());
124
}
125
126
return nullptr;
127
}
128
129
DocProxyAccessibleWrap* GetChildDocumentAt(uint32_t aIndex) {
130
auto doc = Proxy()->AsDoc();
131
if (doc && doc->ChildDocCount() > aIndex) {
132
return reinterpret_cast<DocProxyAccessibleWrap*>(
133
doc->ChildDocAt(aIndex)->GetWrapper());
134
}
135
136
return nullptr;
137
}
138
139
void AddID(uint32_t aID, AccessibleWrap* aAcc) {
140
mIDToAccessibleMap.Put(aID, aAcc);
141
}
142
void RemoveID(uint32_t aID) { mIDToAccessibleMap.Remove(aID); }
143
AccessibleWrap* GetAccessibleByID(uint32_t aID) const {
144
return mIDToAccessibleMap.Get(aID);
145
}
146
147
private:
148
/*
149
* This provides a mapping from 32 bit id to accessible objects.
150
*/
151
nsDataHashtable<nsUint32HashKey, AccessibleWrap*> mIDToAccessibleMap;
152
};
153
} // namespace a11y
154
} // namespace mozilla
155
156
#endif