1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * John Gaunt (jgaunt@netscape.com)
24 : * Aaron Leventhal (aaronl@netscape.com)
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : // NOTE: alphabetically ordered
41 :
42 : #include "Role.h"
43 :
44 : #include "nsFormControlAccessible.h"
45 : #include "nsIDOMHTMLFormElement.h"
46 : #include "nsIDOMHTMLInputElement.h"
47 : #include "nsIDOMXULElement.h"
48 : #include "nsIDOMXULControlElement.h"
49 :
50 : using namespace mozilla::a11y;
51 :
52 : ////////////////////////////////////////////////////////////////////////////////
53 : // ProgressMeterAccessible
54 : ////////////////////////////////////////////////////////////////////////////////
55 :
56 : template class ProgressMeterAccessible<1>;
57 : template class ProgressMeterAccessible<100>;
58 :
59 : ////////////////////////////////////////////////////////////////////////////////
60 : // nsISupports
61 :
62 : template<int Max>
63 0 : NS_IMPL_ADDREF_INHERITED(ProgressMeterAccessible<Max>, nsFormControlAccessible)
64 :
65 : template<int Max>
66 0 : NS_IMPL_RELEASE_INHERITED(ProgressMeterAccessible<Max>, nsFormControlAccessible)
67 :
68 : template<int Max>
69 0 : NS_IMPL_QUERY_INTERFACE_INHERITED1(ProgressMeterAccessible<Max>,
70 : nsFormControlAccessible,
71 : nsIAccessibleValue)
72 :
73 : ////////////////////////////////////////////////////////////////////////////////
74 : // nsAccessible
75 :
76 : template<int Max>
77 : role
78 : ProgressMeterAccessible<Max>::NativeRole()
79 : {
80 0 : return roles::PROGRESSBAR;
81 : }
82 :
83 : ////////////////////////////////////////////////////////////////////////////////
84 : // ProgressMeterAccessible<Max>: Widgets
85 :
86 : template<int Max>
87 : bool
88 : ProgressMeterAccessible<Max>::IsWidget() const
89 : {
90 0 : return true;
91 : }
92 :
93 : ////////////////////////////////////////////////////////////////////////////////
94 : // nsIAccessibleValue
95 :
96 : template<int Max>
97 : NS_IMETHODIMP
98 : ProgressMeterAccessible<Max>::GetValue(nsAString& aValue)
99 : {
100 0 : nsresult rv = nsFormControlAccessible::GetValue(aValue);
101 0 : NS_ENSURE_SUCCESS(rv, rv);
102 :
103 0 : if (!aValue.IsEmpty())
104 0 : return NS_OK;
105 :
106 0 : double maxValue = 0;
107 0 : rv = GetMaximumValue(&maxValue);
108 0 : NS_ENSURE_SUCCESS(rv, rv);
109 :
110 0 : double curValue = 0;
111 0 : rv = GetCurrentValue(&curValue);
112 0 : NS_ENSURE_SUCCESS(rv, rv);
113 :
114 : // Treat the current value bigger than maximum as 100%.
115 : double percentValue = (curValue < maxValue) ?
116 0 : (curValue / maxValue) * 100 : 100;
117 :
118 0 : nsAutoString value;
119 0 : value.AppendFloat(percentValue); // AppendFloat isn't available on nsAString
120 0 : value.AppendLiteral("%");
121 0 : aValue = value;
122 0 : return NS_OK;
123 : }
124 :
125 : template<int Max>
126 : NS_IMETHODIMP
127 : ProgressMeterAccessible<Max>::GetMaximumValue(double* aMaximumValue)
128 : {
129 0 : nsresult rv = nsFormControlAccessible::GetMaximumValue(aMaximumValue);
130 0 : if (rv != NS_OK_NO_ARIA_VALUE)
131 0 : return rv;
132 :
133 0 : nsAutoString value;
134 0 : if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::max, value)) {
135 0 : PRInt32 result = NS_OK;
136 0 : *aMaximumValue = value.ToDouble(&result);
137 0 : return result;
138 : }
139 :
140 0 : *aMaximumValue = Max;
141 0 : return NS_OK;
142 : }
143 :
144 : template<int Max>
145 : NS_IMETHODIMP
146 : ProgressMeterAccessible<Max>::GetMinimumValue(double* aMinimumValue)
147 : {
148 0 : nsresult rv = nsFormControlAccessible::GetMinimumValue(aMinimumValue);
149 0 : if (rv != NS_OK_NO_ARIA_VALUE)
150 0 : return rv;
151 :
152 0 : *aMinimumValue = 0;
153 0 : return NS_OK;
154 : }
155 :
156 : template<int Max>
157 : NS_IMETHODIMP
158 : ProgressMeterAccessible<Max>::GetMinimumIncrement(double* aMinimumIncrement)
159 : {
160 0 : nsresult rv = nsFormControlAccessible::GetMinimumIncrement(aMinimumIncrement);
161 0 : if (rv != NS_OK_NO_ARIA_VALUE)
162 0 : return rv;
163 :
164 0 : *aMinimumIncrement = 0;
165 0 : return NS_OK;
166 : }
167 :
168 : template<int Max>
169 : NS_IMETHODIMP
170 : ProgressMeterAccessible<Max>::GetCurrentValue(double* aCurrentValue)
171 : {
172 0 : nsresult rv = nsFormControlAccessible::GetCurrentValue(aCurrentValue);
173 0 : if (rv != NS_OK_NO_ARIA_VALUE)
174 0 : return rv;
175 :
176 0 : nsAutoString attrValue;
177 0 : mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue);
178 :
179 : // Return zero value if there is no attribute or its value is empty.
180 0 : if (attrValue.IsEmpty())
181 0 : return NS_OK;
182 :
183 0 : PRInt32 error = NS_OK;
184 0 : double value = attrValue.ToDouble(&error);
185 0 : if (NS_FAILED(error))
186 0 : return NS_OK; // Zero value because of wrong markup.
187 :
188 0 : *aCurrentValue = value;
189 0 : return NS_OK;
190 : }
191 :
192 : template<int Max>
193 : NS_IMETHODIMP
194 : ProgressMeterAccessible<Max>::SetCurrentValue(double aValue)
195 : {
196 0 : return NS_ERROR_FAILURE; // Progress meters are readonly.
197 : }
198 :
199 : ////////////////////////////////////////////////////////////////////////////////
200 : // nsRadioButtonAccessible
201 : ////////////////////////////////////////////////////////////////////////////////
202 :
203 0 : nsRadioButtonAccessible::
204 : nsRadioButtonAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
205 0 : nsFormControlAccessible(aContent, aDoc)
206 : {
207 0 : }
208 :
209 : PRUint8
210 0 : nsRadioButtonAccessible::ActionCount()
211 : {
212 0 : return 1;
213 : }
214 :
215 0 : NS_IMETHODIMP nsRadioButtonAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
216 : {
217 0 : if (aIndex == eAction_Click) {
218 0 : aName.AssignLiteral("select");
219 0 : return NS_OK;
220 : }
221 0 : return NS_ERROR_INVALID_ARG;
222 : }
223 :
224 : NS_IMETHODIMP
225 0 : nsRadioButtonAccessible::DoAction(PRUint8 aIndex)
226 : {
227 0 : if (aIndex != eAction_Click)
228 0 : return NS_ERROR_INVALID_ARG;
229 :
230 0 : DoCommand();
231 0 : return NS_OK;
232 : }
233 :
234 : role
235 0 : nsRadioButtonAccessible::NativeRole()
236 : {
237 0 : return roles::RADIOBUTTON;
238 : }
239 :
240 : ////////////////////////////////////////////////////////////////////////////////
241 : // nsRadioButtonAccessible: Widgets
242 :
243 : bool
244 0 : nsRadioButtonAccessible::IsWidget() const
245 : {
246 0 : return true;
247 : }
|