Bug 496271, automation config for Tb2.0.0.22 build1, p=joduinn, r=me
[mozilla-1.9.git] / accessible / src / xforms / nsXFormsFormControlsAccessible.cpp
blob1d81bde8b78a250895ad81ad8c3f5d9d02be0fb5
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
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/
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.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Alexander Surkov <surkov.alexander@gmail.com> (original author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsXFormsFormControlsAccessible.h"
41 // nsXFormsLabelAccessible
43 nsXFormsLabelAccessible::
44 nsXFormsLabelAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
45 nsXFormsAccessible(aNode, aShell)
49 NS_IMETHODIMP
50 nsXFormsLabelAccessible::GetRole(PRUint32 *aRole)
52 NS_ENSURE_ARG_POINTER(aRole);
54 *aRole = nsIAccessibleRole::ROLE_LABEL;
55 return NS_OK;
58 NS_IMETHODIMP
59 nsXFormsLabelAccessible::GetName(nsAString& aName)
61 nsAutoString name;
62 nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, name);
63 aName = name;
64 return rv;
67 NS_IMETHODIMP
68 nsXFormsLabelAccessible::GetDescription(nsAString& aDescription)
70 nsAutoString description;
71 nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_describedby, description);
72 aDescription = description;
73 return rv;
76 // nsXFormsOutputAccessible
78 nsXFormsOutputAccessible::
79 nsXFormsOutputAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
80 nsXFormsAccessible(aNode, aShell)
84 NS_IMETHODIMP
85 nsXFormsOutputAccessible::GetRole(PRUint32 *aRole)
87 NS_ENSURE_ARG_POINTER(aRole);
89 *aRole = nsIAccessibleRole::ROLE_STATICTEXT;
90 return NS_OK;
93 // nsXFormsTriggerAccessible
95 nsXFormsTriggerAccessible::
96 nsXFormsTriggerAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
97 nsXFormsAccessible(aNode, aShell)
101 NS_IMETHODIMP
102 nsXFormsTriggerAccessible::GetRole(PRUint32 *aRole)
104 NS_ENSURE_ARG_POINTER(aRole);
106 *aRole = nsIAccessibleRole::ROLE_PUSHBUTTON;
107 return NS_OK;
110 NS_IMETHODIMP
111 nsXFormsTriggerAccessible::GetValue(nsAString& aValue)
113 aValue.Truncate();
114 return NS_OK;
117 NS_IMETHODIMP
118 nsXFormsTriggerAccessible::GetNumActions(PRUint8 *aCount)
120 NS_ENSURE_ARG_POINTER(aCount);
122 *aCount = 1;
123 return NS_OK;
126 NS_IMETHODIMP
127 nsXFormsTriggerAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
129 if (aIndex == eAction_Click) {
130 aName.AssignLiteral("press");
131 return NS_OK;
133 return NS_ERROR_INVALID_ARG;
136 NS_IMETHODIMP
137 nsXFormsTriggerAccessible::DoAction(PRUint8 aIndex)
139 if (aIndex == eAction_Click)
140 return DoCommand();
142 return NS_ERROR_INVALID_ARG;
145 // nsXFormsInputAccessible
147 nsXFormsInputAccessible::
148 nsXFormsInputAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
149 nsXFormsEditableAccessible(aNode, aShell)
153 NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsInputAccessible, nsAccessible, nsHyperTextAccessible, nsIAccessibleText, nsIAccessibleEditableText)
155 NS_IMETHODIMP
156 nsXFormsInputAccessible::GetRole(PRUint32 *aRole)
158 NS_ENSURE_ARG_POINTER(aRole);
160 *aRole = nsIAccessibleRole::ROLE_ENTRY;
161 return NS_OK;
164 NS_IMETHODIMP
165 nsXFormsInputAccessible::GetNumActions(PRUint8* aCount)
167 NS_ENSURE_ARG_POINTER(aCount);
169 *aCount = 1;
170 return NS_OK;
173 NS_IMETHODIMP
174 nsXFormsInputAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
176 if (aIndex != eAction_Click)
177 return NS_ERROR_INVALID_ARG;
179 aName.AssignLiteral("activate");
180 return NS_OK;
183 NS_IMETHODIMP
184 nsXFormsInputAccessible::DoAction(PRUint8 aIndex)
186 if (aIndex != eAction_Click)
187 return NS_ERROR_INVALID_ARG;
189 return sXFormsService->Focus(mDOMNode);
192 // nsXFormsInputBooleanAccessible
194 nsXFormsInputBooleanAccessible::
195 nsXFormsInputBooleanAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
196 nsXFormsAccessible(aNode, aShell)
200 NS_IMETHODIMP
201 nsXFormsInputBooleanAccessible::GetRole(PRUint32 *aRole)
203 NS_ENSURE_ARG_POINTER(aRole);
205 *aRole = nsIAccessibleRole::ROLE_CHECKBUTTON;
206 return NS_OK;
209 NS_IMETHODIMP
210 nsXFormsInputBooleanAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
212 nsresult rv = nsXFormsAccessible::GetState(aState, aExtraState);
213 NS_ENSURE_SUCCESS(rv, rv);
214 if (!mDOMNode)
215 return NS_OK;
217 nsAutoString value;
218 rv = sXFormsService->GetValue(mDOMNode, value);
219 NS_ENSURE_SUCCESS(rv, rv);
221 if (value.EqualsLiteral("true"))
222 *aState |= nsIAccessibleStates::STATE_CHECKED;
224 return NS_OK;
227 NS_IMETHODIMP
228 nsXFormsInputBooleanAccessible::GetNumActions(PRUint8 *aCount)
230 NS_ENSURE_ARG_POINTER(aCount);
232 *aCount = 1;
233 return NS_OK;
236 NS_IMETHODIMP
237 nsXFormsInputBooleanAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
239 if (aIndex != eAction_Click)
240 return NS_ERROR_INVALID_ARG;
242 nsAutoString value;
243 nsresult rv = sXFormsService->GetValue(mDOMNode, value);
244 NS_ENSURE_SUCCESS(rv, rv);
246 if (value.EqualsLiteral("true"))
247 aName.AssignLiteral("uncheck");
248 else
249 aName.AssignLiteral("check");
251 return NS_OK;
254 NS_IMETHODIMP
255 nsXFormsInputBooleanAccessible::DoAction(PRUint8 aIndex)
257 if (aIndex != eAction_Click)
258 return NS_ERROR_INVALID_ARG;
260 return DoCommand();
263 // nsXFormsInputDateAccessible
265 nsXFormsInputDateAccessible::
266 nsXFormsInputDateAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
267 nsXFormsContainerAccessible(aNode, aShell)
271 NS_IMETHODIMP
272 nsXFormsInputDateAccessible::GetRole(PRUint32 *aRole)
274 NS_ENSURE_ARG_POINTER(aRole);
276 *aRole = nsIAccessibleRole::ROLE_DROPLIST;
277 return NS_OK;
280 // nsXFormsSecretAccessible
282 nsXFormsSecretAccessible::
283 nsXFormsSecretAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
284 nsXFormsInputAccessible(aNode, aShell)
288 NS_IMETHODIMP
289 nsXFormsSecretAccessible::GetRole(PRUint32 *aRole)
291 NS_ENSURE_ARG_POINTER(aRole);
293 *aRole = nsIAccessibleRole::ROLE_PASSWORD_TEXT;
294 return NS_OK;
297 NS_IMETHODIMP
298 nsXFormsSecretAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
300 nsresult rv = nsXFormsInputAccessible::GetState(aState, aExtraState);
301 NS_ENSURE_SUCCESS(rv, rv);
302 if (!mDOMNode)
303 return NS_OK;
305 *aState |= nsIAccessibleStates::STATE_PROTECTED;
306 return NS_OK;
309 NS_IMETHODIMP
310 nsXFormsSecretAccessible::GetValue(nsAString& aValue)
312 return NS_ERROR_FAILURE;
316 // nsXFormsRangeAccessible
318 nsXFormsRangeAccessible::
319 nsXFormsRangeAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
320 nsXFormsAccessible(aNode, aShell)
324 NS_IMETHODIMP
325 nsXFormsRangeAccessible::GetRole(PRUint32 *aRole)
327 NS_ENSURE_ARG_POINTER(aRole);
329 *aRole = nsIAccessibleRole::ROLE_SLIDER;
330 return NS_OK;
333 NS_IMETHODIMP
334 nsXFormsRangeAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
336 nsresult rv = nsXFormsAccessible::GetState(aState, aExtraState);
337 NS_ENSURE_SUCCESS(rv, rv);
338 if (!mDOMNode)
339 return NS_OK;
341 PRUint32 isInRange = nsIXFormsUtilityService::STATE_NOT_A_RANGE;
342 rv = sXFormsService->IsInRange(mDOMNode, &isInRange);
343 NS_ENSURE_SUCCESS(rv, rv);
345 if (isInRange == nsIXFormsUtilityService::STATE_OUT_OF_RANGE)
346 *aState |= nsIAccessibleStates::STATE_INVALID;
348 return NS_OK;
351 NS_IMETHODIMP
352 nsXFormsRangeAccessible::GetMaximumValue(double *aMaximumValue)
354 NS_ENSURE_ARG_POINTER(aMaximumValue);
356 nsAutoString value;
357 nsresult rv = sXFormsService->GetRangeEnd(mDOMNode, value);
358 NS_ENSURE_SUCCESS(rv, rv);
360 PRInt32 error = NS_OK;
361 *aMaximumValue = value.ToFloat(&error);
362 return error;
365 NS_IMETHODIMP
366 nsXFormsRangeAccessible::GetMinimumValue(double *aMinimumValue)
368 NS_ENSURE_ARG_POINTER(aMinimumValue);
370 nsAutoString value;
371 nsresult rv = sXFormsService->GetRangeStart(mDOMNode, value);
372 NS_ENSURE_SUCCESS(rv, rv);
374 PRInt32 error = NS_OK;
375 *aMinimumValue = value.ToFloat(&error);
376 return error;
379 NS_IMETHODIMP
380 nsXFormsRangeAccessible::GetMinimumIncrement(double *aMinimumIncrement)
382 NS_ENSURE_ARG_POINTER(aMinimumIncrement);
384 nsAutoString value;
385 nsresult rv = sXFormsService->GetRangeStep(mDOMNode, value);
386 NS_ENSURE_SUCCESS(rv, rv);
388 PRInt32 error = NS_OK;
389 *aMinimumIncrement = value.ToFloat(&error);
390 return error;
393 NS_IMETHODIMP
394 nsXFormsRangeAccessible::GetCurrentValue(double *aCurrentValue)
396 NS_ENSURE_ARG_POINTER(aCurrentValue);
398 nsAutoString value;
399 nsresult rv = sXFormsService->GetValue(mDOMNode, value);
400 NS_ENSURE_SUCCESS(rv, rv);
402 PRInt32 error = NS_OK;
403 *aCurrentValue = value.ToFloat(&error);
404 return error;
408 // nsXFormsSelectAccessible
410 nsXFormsSelectAccessible::
411 nsXFormsSelectAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
412 nsXFormsContainerAccessible(aNode, aShell)
416 NS_IMETHODIMP
417 nsXFormsSelectAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
419 nsresult rv = nsXFormsContainerAccessible::GetState(aState, aExtraState);
420 NS_ENSURE_SUCCESS(rv, rv);
421 if (!mDOMNode)
422 return NS_OK;
424 PRUint32 isInRange = nsIXFormsUtilityService::STATE_NOT_A_RANGE;
425 rv = sXFormsService->IsInRange(mDOMNode, &isInRange);
426 NS_ENSURE_SUCCESS(rv, rv);
428 if (isInRange == nsIXFormsUtilityService::STATE_OUT_OF_RANGE)
429 *aState |= nsIAccessibleStates::STATE_INVALID;
431 return NS_OK;
436 // nsXFormsChoicesAccessible
438 nsXFormsChoicesAccessible::
439 nsXFormsChoicesAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
440 nsXFormsAccessible(aNode, aShell)
444 NS_IMETHODIMP
445 nsXFormsChoicesAccessible::GetRole(PRUint32 *aRole)
447 NS_ENSURE_ARG_POINTER(aRole);
449 *aRole = nsIAccessibleRole::ROLE_GROUPING;
450 return NS_OK;
453 NS_IMETHODIMP
454 nsXFormsChoicesAccessible::GetValue(nsAString& aValue)
456 aValue.Truncate();
457 return NS_OK;
460 void
461 nsXFormsChoicesAccessible::CacheChildren()
463 CacheSelectChildren();
467 // nsXFormsSelectFullAccessible
469 nsXFormsSelectFullAccessible::
470 nsXFormsSelectFullAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
471 nsXFormsSelectableAccessible(aNode, aShell)
475 NS_IMETHODIMP
476 nsXFormsSelectFullAccessible::GetRole(PRUint32 *aRole)
478 NS_ENSURE_ARG_POINTER(aRole);
480 *aRole = nsIAccessibleRole::ROLE_GROUPING;
481 return NS_OK;
484 void
485 nsXFormsSelectFullAccessible::CacheChildren()
487 CacheSelectChildren();
491 // nsXFormsItemCheckgroupAccessible
493 nsXFormsItemCheckgroupAccessible::
494 nsXFormsItemCheckgroupAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
495 nsXFormsSelectableItemAccessible(aNode, aShell)
499 NS_IMETHODIMP
500 nsXFormsItemCheckgroupAccessible::GetRole(PRUint32 *aRole)
502 NS_ENSURE_ARG_POINTER(aRole);
504 *aRole = nsIAccessibleRole::ROLE_CHECKBUTTON;
505 return NS_OK;
508 NS_IMETHODIMP
509 nsXFormsItemCheckgroupAccessible::GetState(PRUint32 *aState,
510 PRUint32 *aExtraState)
512 nsresult rv = nsXFormsSelectableItemAccessible::GetState(aState, aExtraState);
513 NS_ENSURE_SUCCESS(rv, rv);
514 if (!mDOMNode)
515 return NS_OK;
517 if (IsItemSelected())
518 *aState |= nsIAccessibleStates::STATE_CHECKED;
520 return NS_OK;
523 NS_IMETHODIMP
524 nsXFormsItemCheckgroupAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
526 if (aIndex != eAction_Click)
527 return NS_ERROR_INVALID_ARG;
529 if (IsItemSelected())
530 aName.AssignLiteral("uncheck");
531 else
532 aName.AssignLiteral("check");
534 return NS_OK;
538 // nsXFormsItemRadiogroupAccessible
540 nsXFormsItemRadiogroupAccessible::
541 nsXFormsItemRadiogroupAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
542 nsXFormsSelectableItemAccessible(aNode, aShell)
546 NS_IMETHODIMP
547 nsXFormsItemRadiogroupAccessible::GetRole(PRUint32 *aRole)
549 NS_ENSURE_ARG_POINTER(aRole);
551 *aRole = nsIAccessibleRole::ROLE_RADIOBUTTON;
552 return NS_OK;
555 NS_IMETHODIMP
556 nsXFormsItemRadiogroupAccessible::GetState(PRUint32 *aState,
557 PRUint32 *aExtraState)
559 nsresult rv = nsXFormsSelectableItemAccessible::GetState(aState, aExtraState);
560 NS_ENSURE_SUCCESS(rv, rv);
561 if (!mDOMNode)
562 return NS_OK;
564 if (IsItemSelected())
565 *aState |= nsIAccessibleStates::STATE_CHECKED;
567 return NS_OK;
570 NS_IMETHODIMP
571 nsXFormsItemRadiogroupAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
573 if (aIndex != eAction_Click)
574 return NS_ERROR_INVALID_ARG;
576 aName.AssignLiteral("select");
577 return NS_OK;
581 // nsXFormsSelectComboboxAccessible
583 nsXFormsSelectComboboxAccessible::
584 nsXFormsSelectComboboxAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
585 nsXFormsSelectableAccessible(aNode, aShell)
589 NS_IMETHODIMP
590 nsXFormsSelectComboboxAccessible::GetRole(PRUint32 *aRole)
592 NS_ENSURE_ARG_POINTER(aRole);
594 *aRole = nsIAccessibleRole::ROLE_COMBOBOX;
595 return NS_OK;
598 NS_IMETHODIMP
599 nsXFormsSelectComboboxAccessible::GetState(PRUint32 *aState,
600 PRUint32 *aExtraState)
602 nsresult rv = nsXFormsSelectableAccessible::GetState(aState, aExtraState);
603 NS_ENSURE_SUCCESS(rv, rv);
604 if (!mDOMNode)
605 return NS_OK;
607 PRBool isOpen = PR_FALSE;
608 rv = sXFormsService->IsDropmarkerOpen(mDOMNode, &isOpen);
609 NS_ENSURE_SUCCESS(rv, rv);
611 if (isOpen)
612 *aState = nsIAccessibleStates::STATE_EXPANDED;
613 else
614 *aState = nsIAccessibleStates::STATE_COLLAPSED;
616 *aState |= nsIAccessibleStates::STATE_HASPOPUP |
617 nsIAccessibleStates::STATE_FOCUSABLE;
618 return NS_OK;
621 NS_IMETHODIMP
622 nsXFormsSelectComboboxAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
624 NS_ENSURE_ARG_POINTER(aAllowsAnonChildren);
626 *aAllowsAnonChildren = PR_TRUE;
627 return NS_OK;
631 // nsXFormsItemComboboxAccessible
633 nsXFormsItemComboboxAccessible::
634 nsXFormsItemComboboxAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
635 nsXFormsSelectableItemAccessible(aNode, aShell)
639 NS_IMETHODIMP
640 nsXFormsItemComboboxAccessible::GetRole(PRUint32 *aRole)
642 NS_ENSURE_ARG_POINTER(aRole);
644 *aRole = nsIAccessibleRole::ROLE_LISTITEM;
645 return NS_OK;
648 NS_IMETHODIMP
649 nsXFormsItemComboboxAccessible::GetState(PRUint32 *aState,
650 PRUint32 *aExtraState)
652 nsresult rv = nsXFormsSelectableItemAccessible::GetState(aState, aExtraState);
653 NS_ENSURE_SUCCESS(rv, rv);
654 if (!mDOMNode || (*aState & nsIAccessibleStates::STATE_UNAVAILABLE))
655 return NS_OK;
657 *aState |= nsIAccessibleStates::STATE_SELECTABLE;
658 if (IsItemSelected())
659 *aState |= nsIAccessibleStates::STATE_SELECTED;
661 return NS_OK;
664 NS_IMETHODIMP
665 nsXFormsItemComboboxAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
667 if (aIndex != eAction_Click)
668 return NS_ERROR_INVALID_ARG;
670 aName.AssignLiteral("select");
671 return NS_OK;