/work/obj-fuzz/dist/include/mozilla/dom/AccessibleNode.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ |
2 | | /* vim: set ts=2 et sw=2 tw=40: */ |
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/. */ |
6 | | |
7 | | #ifndef A11Y_AOM_ACCESSIBLENODE_H |
8 | | #define A11Y_AOM_ACCESSIBLENODE_H |
9 | | |
10 | | #include "nsDataHashtable.h" |
11 | | #include "nsRefPtrHashtable.h" |
12 | | #include "nsWrapperCache.h" |
13 | | #include "mozilla/ErrorResult.h" |
14 | | #include "mozilla/dom/BindingDeclarations.h" |
15 | | #include "mozilla/dom/Nullable.h" |
16 | | |
17 | | class nsINode; |
18 | | |
19 | | namespace mozilla { |
20 | | |
21 | | namespace a11y { |
22 | | class Accessible; |
23 | | } |
24 | | |
25 | | namespace dom { |
26 | | |
27 | | class DOMStringList; |
28 | | struct ParentObject; |
29 | | |
30 | | #define ANODE_ENUM(name) \ |
31 | | e##name, |
32 | | |
33 | | #define ANODE_FUNC(typeName, type, name) \ |
34 | | dom::Nullable<type> Get##name() \ |
35 | 0 | { \ |
36 | 0 | return GetProperty(AOM##typeName##Property::e##name); \ |
37 | 0 | } \ Unexecuted instantiation: mozilla::dom::AccessibleNode::GetAtomic() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetBusy() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetDisabled() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetExpanded() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetHidden() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetModal() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetMultiline() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetMultiselectable() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetReadOnly() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetRequired() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetSelected() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetColIndex() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetColSpan() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetLevel() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetPosInSet() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetRowIndex() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetRowSpan() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetColCount() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetRowCount() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetSetSize() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetValueMax() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetValueMin() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetValueNow() |
38 | | \ |
39 | | void Set##name(const dom::Nullable<type>& a##name) \ |
40 | 0 | { \ |
41 | 0 | SetProperty(AOM##typeName##Property::e##name, a##name); \ |
42 | 0 | } \ Unexecuted instantiation: mozilla::dom::AccessibleNode::SetAtomic(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetBusy(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetDisabled(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetExpanded(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetHidden(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetModal(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetMultiline(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetMultiselectable(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetReadOnly(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetRequired(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetSelected(mozilla::dom::Nullable<bool> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetColIndex(mozilla::dom::Nullable<unsigned int> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetColSpan(mozilla::dom::Nullable<unsigned int> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetLevel(mozilla::dom::Nullable<unsigned int> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetPosInSet(mozilla::dom::Nullable<unsigned int> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetRowIndex(mozilla::dom::Nullable<unsigned int> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetRowSpan(mozilla::dom::Nullable<unsigned int> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetColCount(mozilla::dom::Nullable<int> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetRowCount(mozilla::dom::Nullable<int> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetSetSize(mozilla::dom::Nullable<int> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetValueMax(mozilla::dom::Nullable<double> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetValueMin(mozilla::dom::Nullable<double> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetValueNow(mozilla::dom::Nullable<double> const&) |
43 | | |
44 | | #define ANODE_STRING_FUNC(name) \ |
45 | | void Get##name(nsAString& a##name) \ |
46 | 0 | { \ |
47 | 0 | return GetProperty(AOMStringProperty::e##name, a##name); \ |
48 | 0 | } \ Unexecuted instantiation: mozilla::dom::AccessibleNode::GetAutocomplete(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetChecked(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetCurrent(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetHasPopUp(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetInvalid(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetKeyShortcuts(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetLabel(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetLive(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetOrientation(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetPlaceholder(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetPressed(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetRelevant(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetRole(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetRoleDescription(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetSort(nsTSubstring<char16_t>&) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetValueText(nsTSubstring<char16_t>&) |
49 | | \ |
50 | | void Set##name(const nsAString& a##name) \ |
51 | 0 | { \ |
52 | 0 | SetProperty(AOMStringProperty::e##name, a##name); \ |
53 | 0 | } \ Unexecuted instantiation: mozilla::dom::AccessibleNode::SetAutocomplete(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetChecked(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetCurrent(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetHasPopUp(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetInvalid(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetKeyShortcuts(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetLabel(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetLive(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetOrientation(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetPlaceholder(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetPressed(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetRelevant(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetRole(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetRoleDescription(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetSort(nsTSubstring<char16_t> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetValueText(nsTSubstring<char16_t> const&) |
54 | | |
55 | | #define ANODE_RELATION_FUNC(name) \ |
56 | | already_AddRefed<AccessibleNode> Get##name() \ |
57 | 0 | { \ |
58 | 0 | return GetProperty(AOMRelationProperty::e##name); \ |
59 | 0 | } \ Unexecuted instantiation: mozilla::dom::AccessibleNode::GetActiveDescendant() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetDetails() Unexecuted instantiation: mozilla::dom::AccessibleNode::GetErrorMessage() |
60 | | \ |
61 | | void Set##name(AccessibleNode* a##name) \ |
62 | 0 | { \ |
63 | 0 | SetProperty(AOMRelationProperty::e##name, a##name); \ |
64 | 0 | } \ Unexecuted instantiation: mozilla::dom::AccessibleNode::SetActiveDescendant(mozilla::dom::AccessibleNode*) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetDetails(mozilla::dom::AccessibleNode*) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetErrorMessage(mozilla::dom::AccessibleNode*) |
65 | | |
66 | | #define ANODE_PROPS(typeName, type, ...) \ |
67 | | enum class AOM##typeName##Property { \ |
68 | | MOZ_FOR_EACH(ANODE_ENUM, (), (__VA_ARGS__)) \ |
69 | | }; \ |
70 | | MOZ_FOR_EACH(ANODE_FUNC, (typeName, type,), (__VA_ARGS__)) \ |
71 | | |
72 | | #define ANODE_STRING_PROPS(...) \ |
73 | | enum class AOMStringProperty { \ |
74 | | MOZ_FOR_EACH(ANODE_ENUM, (), (__VA_ARGS__)) \ |
75 | | }; \ |
76 | | MOZ_FOR_EACH(ANODE_STRING_FUNC, (), (__VA_ARGS__)) \ |
77 | | |
78 | | #define ANODE_RELATION_PROPS(...) \ |
79 | | enum class AOMRelationProperty { \ |
80 | | MOZ_FOR_EACH(ANODE_ENUM, (), (__VA_ARGS__)) \ |
81 | | }; \ |
82 | | MOZ_FOR_EACH(ANODE_RELATION_FUNC, (), (__VA_ARGS__)) \ |
83 | | |
84 | | #define ANODE_ACCESSOR_MUTATOR(typeName, type, defVal) \ |
85 | | nsDataHashtable<nsUint32HashKey, type> m##typeName##Properties; \ |
86 | | \ |
87 | | dom::Nullable<type> GetProperty(AOM##typeName##Property aProperty) \ |
88 | 0 | { \ |
89 | 0 | type value = defVal; \ |
90 | 0 | if (m##typeName##Properties.Get(static_cast<int>(aProperty), &value)) { \ |
91 | 0 | return dom::Nullable<type>(value); \ |
92 | 0 | } \ |
93 | 0 | return dom::Nullable<type>(); \ |
94 | 0 | } \ Unexecuted instantiation: mozilla::dom::AccessibleNode::GetProperty(mozilla::dom::AccessibleNode::AOMDoubleProperty) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetProperty(mozilla::dom::AccessibleNode::AOMIntProperty) Unexecuted instantiation: mozilla::dom::AccessibleNode::GetProperty(mozilla::dom::AccessibleNode::AOMUIntProperty) |
95 | | \ |
96 | | void SetProperty(AOM##typeName##Property aProperty, \ |
97 | | const dom::Nullable<type>& aValue) \ |
98 | 0 | { \ |
99 | 0 | if (aValue.IsNull()) { \ |
100 | 0 | m##typeName##Properties.Remove(static_cast<int>(aProperty)); \ |
101 | 0 | } else { \ |
102 | 0 | m##typeName##Properties.Put(static_cast<int>(aProperty), aValue.Value()); \ |
103 | 0 | } \ |
104 | 0 | } \ Unexecuted instantiation: mozilla::dom::AccessibleNode::SetProperty(mozilla::dom::AccessibleNode::AOMDoubleProperty, mozilla::dom::Nullable<double> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetProperty(mozilla::dom::AccessibleNode::AOMIntProperty, mozilla::dom::Nullable<int> const&) Unexecuted instantiation: mozilla::dom::AccessibleNode::SetProperty(mozilla::dom::AccessibleNode::AOMUIntProperty, mozilla::dom::Nullable<unsigned int> const&) |
105 | | |
106 | | class AccessibleNode : public nsISupports, |
107 | | public nsWrapperCache |
108 | | { |
109 | | public: |
110 | | explicit AccessibleNode(nsINode* aNode); |
111 | | |
112 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS; |
113 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AccessibleNode); |
114 | | |
115 | | JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final; |
116 | | dom::ParentObject GetParentObject() const; |
117 | | |
118 | | void GetComputedRole(nsAString& aRole); |
119 | | void GetStates(nsTArray<nsString>& aStates); |
120 | | void GetAttributes(nsTArray<nsString>& aAttributes); |
121 | | nsINode* GetDOMNode(); |
122 | | |
123 | | bool Is(const Sequence<nsString>& aFlavors); |
124 | | bool Has(const Sequence<nsString>& aAttributes); |
125 | | void Get(JSContext* cx, const nsAString& aAttribute, |
126 | | JS::MutableHandle<JS::Value> aValue, |
127 | | ErrorResult& aRv); |
128 | | |
129 | | static bool IsAOMEnabled(JSContext*, JSObject*); |
130 | | |
131 | | ANODE_STRING_PROPS( |
132 | | Autocomplete, |
133 | | Checked, |
134 | | Current, |
135 | | HasPopUp, |
136 | | Invalid, |
137 | | KeyShortcuts, |
138 | | Label, |
139 | | Live, |
140 | | Orientation, |
141 | | Placeholder, |
142 | | Pressed, |
143 | | Relevant, |
144 | | Role, |
145 | | RoleDescription, |
146 | | Sort, |
147 | | ValueText |
148 | | ) |
149 | | |
150 | | ANODE_PROPS(Boolean, bool, |
151 | | Atomic, |
152 | | Busy, |
153 | | Disabled, |
154 | | Expanded, |
155 | | Hidden, |
156 | | Modal, |
157 | | Multiline, |
158 | | Multiselectable, |
159 | | ReadOnly, |
160 | | Required, |
161 | | Selected |
162 | | ) |
163 | | |
164 | | ANODE_PROPS(UInt, uint32_t, |
165 | | ColIndex, |
166 | | ColSpan, |
167 | | Level, |
168 | | PosInSet, |
169 | | RowIndex, |
170 | | RowSpan |
171 | | ) |
172 | | |
173 | | ANODE_PROPS(Int, int32_t, |
174 | | ColCount, |
175 | | RowCount, |
176 | | SetSize |
177 | | ) |
178 | | |
179 | | ANODE_PROPS(Double, double, |
180 | | ValueMax, |
181 | | ValueMin, |
182 | | ValueNow |
183 | | ) |
184 | | |
185 | | ANODE_RELATION_PROPS( |
186 | | ActiveDescendant, |
187 | | Details, |
188 | | ErrorMessage |
189 | | ) |
190 | | |
191 | | protected: |
192 | | AccessibleNode(const AccessibleNode& aCopy) = delete; |
193 | | AccessibleNode& operator=(const AccessibleNode& aCopy) = delete; |
194 | | virtual ~AccessibleNode(); |
195 | | |
196 | 0 | void GetProperty(AOMStringProperty aProperty, nsAString& aRetval) { |
197 | 0 | nsString data; |
198 | 0 | if (!mStringProperties.Get(static_cast<int>(aProperty), &data)) { |
199 | 0 | SetDOMStringToNull(data); |
200 | 0 | } |
201 | 0 | aRetval = data; |
202 | 0 | } |
203 | | |
204 | 0 | void SetProperty(AOMStringProperty aProperty, const nsAString& aValue) { |
205 | 0 | if (DOMStringIsNull(aValue)) { |
206 | 0 | mStringProperties.Remove(static_cast<int>(aProperty)); |
207 | 0 | } else { |
208 | 0 | nsString value(aValue); |
209 | 0 | mStringProperties.Put(static_cast<int>(aProperty), value); |
210 | 0 | } |
211 | 0 | } |
212 | | |
213 | | dom::Nullable<bool> GetProperty(AOMBooleanProperty aProperty) |
214 | 0 | { |
215 | 0 | int num = static_cast<int>(aProperty); |
216 | 0 | if (mBooleanProperties & (1U << (2 * num))) { |
217 | 0 | bool data = static_cast<bool>(mBooleanProperties & (1U << (2 * num + 1))); |
218 | 0 | return dom::Nullable<bool>(data); |
219 | 0 | } |
220 | 0 | return dom::Nullable<bool>(); |
221 | 0 | } |
222 | | |
223 | | void SetProperty(AOMBooleanProperty aProperty, |
224 | | const dom::Nullable<bool>& aValue) |
225 | 0 | { |
226 | 0 | int num = static_cast<int>(aProperty); |
227 | 0 | if (aValue.IsNull()) { |
228 | 0 | mBooleanProperties &= ~(1U << (2 * num)); |
229 | 0 | } else { |
230 | 0 | mBooleanProperties |= (1U << (2 * num)); |
231 | 0 | mBooleanProperties = (aValue.Value() ? mBooleanProperties | (1U << (2 * num + 1)) |
232 | 0 | : mBooleanProperties & ~(1U << (2 * num + 1))); |
233 | 0 | } |
234 | 0 | } |
235 | | |
236 | | ANODE_ACCESSOR_MUTATOR(Double, double, 0.0) |
237 | | ANODE_ACCESSOR_MUTATOR(Int, int32_t, 0) |
238 | | ANODE_ACCESSOR_MUTATOR(UInt, uint32_t, 0) |
239 | | |
240 | | already_AddRefed<AccessibleNode> GetProperty(AOMRelationProperty aProperty) |
241 | 0 | { |
242 | 0 | return mRelationProperties.Get(static_cast<int>(aProperty)); |
243 | 0 | } |
244 | | |
245 | | void SetProperty(AOMRelationProperty aProperty, |
246 | | AccessibleNode* aValue) |
247 | 0 | { |
248 | 0 | if (!aValue) { |
249 | 0 | mRelationProperties.Remove(static_cast<int>(aProperty)); |
250 | 0 | } else { |
251 | 0 | mRelationProperties.Put(static_cast<int>(aProperty), aValue); |
252 | 0 | } |
253 | 0 | } |
254 | | |
255 | | // The 2k'th bit indicates whether the k'th boolean property is used(1) or not(0) |
256 | | // and 2k+1'th bit contains the property's value(1:true, 0:false) |
257 | | uint32_t mBooleanProperties; |
258 | | nsRefPtrHashtable<nsUint32HashKey, AccessibleNode> mRelationProperties; |
259 | | nsDataHashtable<nsUint32HashKey, nsString> mStringProperties; |
260 | | |
261 | | RefPtr<a11y::Accessible> mIntl; |
262 | | RefPtr<nsINode> mDOMNode; |
263 | | RefPtr<dom::DOMStringList> mStates; |
264 | | }; |
265 | | |
266 | | } // dom |
267 | | } // mozilla |
268 | | |
269 | | |
270 | | #endif // A11Y_JSAPI_ACCESSIBLENODE |