/src/mozilla-central/accessible/generic/FormControlAccessible.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | // NOTE: alphabetically ordered |
7 | | |
8 | | #include "FormControlAccessible.h" |
9 | | |
10 | | #include "mozilla/dom/HTMLInputElement.h" |
11 | | #include "mozilla/FloatingPoint.h" |
12 | | #include "Role.h" |
13 | | |
14 | | using namespace mozilla::a11y; |
15 | | |
16 | | //////////////////////////////////////////////////////////////////////////////// |
17 | | // ProgressMeterAccessible |
18 | | //////////////////////////////////////////////////////////////////////////////// |
19 | | |
20 | | template class mozilla::a11y::ProgressMeterAccessible<1>; |
21 | | template class mozilla::a11y::ProgressMeterAccessible<100>; |
22 | | |
23 | | //////////////////////////////////////////////////////////////////////////////// |
24 | | // Accessible |
25 | | |
26 | | template<int Max> |
27 | | role |
28 | | ProgressMeterAccessible<Max>::NativeRole() const |
29 | 0 | { |
30 | 0 | return roles::PROGRESSBAR; |
31 | 0 | } Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<1>::NativeRole() const Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<100>::NativeRole() const |
32 | | |
33 | | template<int Max> |
34 | | uint64_t |
35 | | ProgressMeterAccessible<Max>::NativeState() const |
36 | 0 | { |
37 | 0 | uint64_t state = LeafAccessible::NativeState(); |
38 | 0 |
|
39 | 0 | // An undetermined progressbar (i.e. without a value) has a mixed state. |
40 | 0 | nsAutoString attrValue; |
41 | 0 | mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue); |
42 | 0 |
|
43 | 0 | if (attrValue.IsEmpty()) |
44 | 0 | state |= states::MIXED; |
45 | 0 |
|
46 | 0 | return state; |
47 | 0 | } Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<1>::NativeState() const Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<100>::NativeState() const |
48 | | |
49 | | //////////////////////////////////////////////////////////////////////////////// |
50 | | // ProgressMeterAccessible<Max>: Widgets |
51 | | |
52 | | template<int Max> |
53 | | bool |
54 | | ProgressMeterAccessible<Max>::IsWidget() const |
55 | 0 | { |
56 | 0 | return true; |
57 | 0 | } Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<1>::IsWidget() const Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<100>::IsWidget() const |
58 | | |
59 | | //////////////////////////////////////////////////////////////////////////////// |
60 | | // ProgressMeterAccessible<Max>: Value |
61 | | |
62 | | template<int Max> |
63 | | void |
64 | | ProgressMeterAccessible<Max>::Value(nsString& aValue) const |
65 | 0 | { |
66 | 0 | LeafAccessible::Value(aValue); |
67 | 0 | if (!aValue.IsEmpty()) |
68 | 0 | return; |
69 | 0 | |
70 | 0 | double maxValue = MaxValue(); |
71 | 0 | if (IsNaN(maxValue) || maxValue == 0) |
72 | 0 | return; |
73 | 0 | |
74 | 0 | double curValue = CurValue(); |
75 | 0 | if (IsNaN(curValue)) |
76 | 0 | return; |
77 | 0 | |
78 | 0 | // Treat the current value bigger than maximum as 100%. |
79 | 0 | double percentValue = (curValue < maxValue) ? |
80 | 0 | (curValue / maxValue) * 100 : 100; |
81 | 0 |
|
82 | 0 | aValue.AppendFloat(percentValue); |
83 | 0 | aValue.Append('%'); |
84 | 0 | } Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<1>::Value(nsTString<char16_t>&) const Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<100>::Value(nsTString<char16_t>&) const |
85 | | |
86 | | template<int Max> |
87 | | double |
88 | | ProgressMeterAccessible<Max>::MaxValue() const |
89 | 0 | { |
90 | 0 | double value = LeafAccessible::MaxValue(); |
91 | 0 | if (!IsNaN(value)) |
92 | 0 | return value; |
93 | 0 | |
94 | 0 | nsAutoString strValue; |
95 | 0 | if (mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::max, strValue)) { |
96 | 0 | nsresult result = NS_OK; |
97 | 0 | value = strValue.ToDouble(&result); |
98 | 0 | if (NS_SUCCEEDED(result)) |
99 | 0 | return value; |
100 | 0 | } |
101 | 0 | |
102 | 0 | return Max; |
103 | 0 | } Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<1>::MaxValue() const Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<100>::MaxValue() const |
104 | | |
105 | | template<int Max> |
106 | | double |
107 | | ProgressMeterAccessible<Max>::MinValue() const |
108 | 0 | { |
109 | 0 | double value = LeafAccessible::MinValue(); |
110 | 0 | return IsNaN(value) ? 0 : value; |
111 | 0 | } Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<1>::MinValue() const Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<100>::MinValue() const |
112 | | |
113 | | template<int Max> |
114 | | double |
115 | | ProgressMeterAccessible<Max>::Step() const |
116 | 0 | { |
117 | 0 | double value = LeafAccessible::Step(); |
118 | 0 | return IsNaN(value) ? 0 : value; |
119 | 0 | } Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<1>::Step() const Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<100>::Step() const |
120 | | |
121 | | template<int Max> |
122 | | double |
123 | | ProgressMeterAccessible<Max>::CurValue() const |
124 | 0 | { |
125 | 0 | double value = LeafAccessible::CurValue(); |
126 | 0 | if (!IsNaN(value)) |
127 | 0 | return value; |
128 | 0 | |
129 | 0 | nsAutoString attrValue; |
130 | 0 | if (!mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue)) |
131 | 0 | return UnspecifiedNaN<double>(); |
132 | 0 | |
133 | 0 | nsresult error = NS_OK; |
134 | 0 | value = attrValue.ToDouble(&error); |
135 | 0 | return NS_FAILED(error) ? UnspecifiedNaN<double>() : value; |
136 | 0 | } Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<1>::CurValue() const Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<100>::CurValue() const |
137 | | |
138 | | template<int Max> |
139 | | bool |
140 | | ProgressMeterAccessible<Max>::SetCurValue(double aValue) |
141 | 0 | { |
142 | 0 | return false; // progress meters are readonly. |
143 | 0 | } Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<1>::SetCurValue(double) Unexecuted instantiation: mozilla::a11y::ProgressMeterAccessible<100>::SetCurValue(double) |
144 | | |
145 | | |
146 | | //////////////////////////////////////////////////////////////////////////////// |
147 | | // CheckboxAccessible |
148 | | //////////////////////////////////////////////////////////////////////////////// |
149 | | |
150 | | role |
151 | | CheckboxAccessible::NativeRole() const |
152 | 0 | { |
153 | 0 | return roles::CHECKBUTTON; |
154 | 0 | } |
155 | | |
156 | | uint8_t |
157 | | CheckboxAccessible::ActionCount() const |
158 | 0 | { |
159 | 0 | return 1; |
160 | 0 | } |
161 | | |
162 | | void |
163 | | CheckboxAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) |
164 | 0 | { |
165 | 0 | if (aIndex == eAction_Click) { |
166 | 0 | uint64_t state = NativeState(); |
167 | 0 | if (state & states::CHECKED) { |
168 | 0 | aName.AssignLiteral("uncheck"); |
169 | 0 | } else if (state & states::MIXED) { |
170 | 0 | aName.AssignLiteral("cycle"); |
171 | 0 | } else { |
172 | 0 | aName.AssignLiteral("check"); |
173 | 0 | } |
174 | 0 | } |
175 | 0 | } |
176 | | |
177 | | bool |
178 | | CheckboxAccessible::DoAction(uint8_t aIndex) const |
179 | 0 | { |
180 | 0 | if (aIndex != eAction_Click) { |
181 | 0 | return false; |
182 | 0 | } |
183 | 0 | DoCommand(); |
184 | 0 | return true; |
185 | 0 | } |
186 | | |
187 | | uint64_t |
188 | | CheckboxAccessible::NativeState() const |
189 | 0 | { |
190 | 0 | uint64_t state = LeafAccessible::NativeState(); |
191 | 0 |
|
192 | 0 | state |= states::CHECKABLE; |
193 | 0 | dom::HTMLInputElement* input = dom::HTMLInputElement::FromNode(mContent); |
194 | 0 | if (input) { // HTML:input@type="checkbox" |
195 | 0 | if (input->Indeterminate()) { |
196 | 0 | return state | states::MIXED; |
197 | 0 | } |
198 | 0 | |
199 | 0 | if (input->Checked()) { |
200 | 0 | return state | states::CHECKED; |
201 | 0 | } |
202 | 0 | |
203 | 0 | } else if (mContent->AsElement()->AttrValueIs(kNameSpaceID_None, |
204 | 0 | nsGkAtoms::checked, |
205 | 0 | nsGkAtoms::_true, |
206 | 0 | eCaseMatters)) { // XUL checkbox |
207 | 0 | return state | states::CHECKED; |
208 | 0 | } |
209 | 0 | |
210 | 0 | return state; |
211 | 0 | } |
212 | | |
213 | | //////////////////////////////////////////////////////////////////////////////// |
214 | | // CheckboxAccessible: Widgets |
215 | | |
216 | | bool |
217 | | CheckboxAccessible::IsWidget() const |
218 | 0 | { |
219 | 0 | return true; |
220 | 0 | } |
221 | | |
222 | | |
223 | | //////////////////////////////////////////////////////////////////////////////// |
224 | | // RadioButtonAccessible |
225 | | //////////////////////////////////////////////////////////////////////////////// |
226 | | |
227 | | RadioButtonAccessible:: |
228 | | RadioButtonAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
229 | | LeafAccessible(aContent, aDoc) |
230 | 0 | { |
231 | 0 | } |
232 | | |
233 | | uint8_t |
234 | | RadioButtonAccessible::ActionCount() const |
235 | 0 | { |
236 | 0 | return 1; |
237 | 0 | } |
238 | | |
239 | | void |
240 | | RadioButtonAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) |
241 | 0 | { |
242 | 0 | if (aIndex == eAction_Click) |
243 | 0 | aName.AssignLiteral("select"); |
244 | 0 | } |
245 | | |
246 | | bool |
247 | | RadioButtonAccessible::DoAction(uint8_t aIndex) const |
248 | 0 | { |
249 | 0 | if (aIndex != eAction_Click) |
250 | 0 | return false; |
251 | 0 | |
252 | 0 | DoCommand(); |
253 | 0 | return true; |
254 | 0 | } |
255 | | |
256 | | role |
257 | | RadioButtonAccessible::NativeRole() const |
258 | 0 | { |
259 | 0 | return roles::RADIOBUTTON; |
260 | 0 | } |
261 | | |
262 | | //////////////////////////////////////////////////////////////////////////////// |
263 | | // RadioButtonAccessible: Widgets |
264 | | |
265 | | bool |
266 | | RadioButtonAccessible::IsWidget() const |
267 | 0 | { |
268 | 0 | return true; |
269 | 0 | } |