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
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
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
)
50 nsXFormsLabelAccessible::GetRole(PRUint32
*aRole
)
52 NS_ENSURE_ARG_POINTER(aRole
);
54 *aRole
= nsIAccessibleRole::ROLE_LABEL
;
59 nsXFormsLabelAccessible::GetName(nsAString
& aName
)
62 nsresult rv
= GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby
, name
);
68 nsXFormsLabelAccessible::GetDescription(nsAString
& aDescription
)
70 nsAutoString description
;
71 nsresult rv
= GetTextFromRelationID(nsAccessibilityAtoms::aria_describedby
, description
);
72 aDescription
= description
;
76 // nsXFormsOutputAccessible
78 nsXFormsOutputAccessible::
79 nsXFormsOutputAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
80 nsXFormsAccessible(aNode
, aShell
)
85 nsXFormsOutputAccessible::GetRole(PRUint32
*aRole
)
87 NS_ENSURE_ARG_POINTER(aRole
);
89 *aRole
= nsIAccessibleRole::ROLE_STATICTEXT
;
93 // nsXFormsTriggerAccessible
95 nsXFormsTriggerAccessible::
96 nsXFormsTriggerAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
97 nsXFormsAccessible(aNode
, aShell
)
102 nsXFormsTriggerAccessible::GetRole(PRUint32
*aRole
)
104 NS_ENSURE_ARG_POINTER(aRole
);
106 *aRole
= nsIAccessibleRole::ROLE_PUSHBUTTON
;
111 nsXFormsTriggerAccessible::GetValue(nsAString
& aValue
)
118 nsXFormsTriggerAccessible::GetNumActions(PRUint8
*aCount
)
120 NS_ENSURE_ARG_POINTER(aCount
);
127 nsXFormsTriggerAccessible::GetActionName(PRUint8 aIndex
, nsAString
& aName
)
129 if (aIndex
== eAction_Click
) {
130 aName
.AssignLiteral("press");
133 return NS_ERROR_INVALID_ARG
;
137 nsXFormsTriggerAccessible::DoAction(PRUint8 aIndex
)
139 if (aIndex
== eAction_Click
)
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
)
156 nsXFormsInputAccessible::GetRole(PRUint32
*aRole
)
158 NS_ENSURE_ARG_POINTER(aRole
);
160 *aRole
= nsIAccessibleRole::ROLE_ENTRY
;
165 nsXFormsInputAccessible::GetNumActions(PRUint8
* aCount
)
167 NS_ENSURE_ARG_POINTER(aCount
);
174 nsXFormsInputAccessible::GetActionName(PRUint8 aIndex
, nsAString
& aName
)
176 if (aIndex
!= eAction_Click
)
177 return NS_ERROR_INVALID_ARG
;
179 aName
.AssignLiteral("activate");
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
)
201 nsXFormsInputBooleanAccessible::GetRole(PRUint32
*aRole
)
203 NS_ENSURE_ARG_POINTER(aRole
);
205 *aRole
= nsIAccessibleRole::ROLE_CHECKBUTTON
;
210 nsXFormsInputBooleanAccessible::GetState(PRUint32
*aState
, PRUint32
*aExtraState
)
212 nsresult rv
= nsXFormsAccessible::GetState(aState
, aExtraState
);
213 NS_ENSURE_SUCCESS(rv
, rv
);
218 rv
= sXFormsService
->GetValue(mDOMNode
, value
);
219 NS_ENSURE_SUCCESS(rv
, rv
);
221 if (value
.EqualsLiteral("true"))
222 *aState
|= nsIAccessibleStates::STATE_CHECKED
;
228 nsXFormsInputBooleanAccessible::GetNumActions(PRUint8
*aCount
)
230 NS_ENSURE_ARG_POINTER(aCount
);
237 nsXFormsInputBooleanAccessible::GetActionName(PRUint8 aIndex
, nsAString
& aName
)
239 if (aIndex
!= eAction_Click
)
240 return NS_ERROR_INVALID_ARG
;
243 nsresult rv
= sXFormsService
->GetValue(mDOMNode
, value
);
244 NS_ENSURE_SUCCESS(rv
, rv
);
246 if (value
.EqualsLiteral("true"))
247 aName
.AssignLiteral("uncheck");
249 aName
.AssignLiteral("check");
255 nsXFormsInputBooleanAccessible::DoAction(PRUint8 aIndex
)
257 if (aIndex
!= eAction_Click
)
258 return NS_ERROR_INVALID_ARG
;
263 // nsXFormsInputDateAccessible
265 nsXFormsInputDateAccessible::
266 nsXFormsInputDateAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
267 nsXFormsContainerAccessible(aNode
, aShell
)
272 nsXFormsInputDateAccessible::GetRole(PRUint32
*aRole
)
274 NS_ENSURE_ARG_POINTER(aRole
);
276 *aRole
= nsIAccessibleRole::ROLE_DROPLIST
;
280 // nsXFormsSecretAccessible
282 nsXFormsSecretAccessible::
283 nsXFormsSecretAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
284 nsXFormsInputAccessible(aNode
, aShell
)
289 nsXFormsSecretAccessible::GetRole(PRUint32
*aRole
)
291 NS_ENSURE_ARG_POINTER(aRole
);
293 *aRole
= nsIAccessibleRole::ROLE_PASSWORD_TEXT
;
298 nsXFormsSecretAccessible::GetState(PRUint32
*aState
, PRUint32
*aExtraState
)
300 nsresult rv
= nsXFormsInputAccessible::GetState(aState
, aExtraState
);
301 NS_ENSURE_SUCCESS(rv
, rv
);
305 *aState
|= nsIAccessibleStates::STATE_PROTECTED
;
310 nsXFormsSecretAccessible::GetValue(nsAString
& aValue
)
312 return NS_ERROR_FAILURE
;
316 // nsXFormsRangeAccessible
318 nsXFormsRangeAccessible::
319 nsXFormsRangeAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
320 nsXFormsAccessible(aNode
, aShell
)
325 nsXFormsRangeAccessible::GetRole(PRUint32
*aRole
)
327 NS_ENSURE_ARG_POINTER(aRole
);
329 *aRole
= nsIAccessibleRole::ROLE_SLIDER
;
334 nsXFormsRangeAccessible::GetState(PRUint32
*aState
, PRUint32
*aExtraState
)
336 nsresult rv
= nsXFormsAccessible::GetState(aState
, aExtraState
);
337 NS_ENSURE_SUCCESS(rv
, rv
);
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
;
352 nsXFormsRangeAccessible::GetMaximumValue(double *aMaximumValue
)
354 NS_ENSURE_ARG_POINTER(aMaximumValue
);
357 nsresult rv
= sXFormsService
->GetRangeEnd(mDOMNode
, value
);
358 NS_ENSURE_SUCCESS(rv
, rv
);
360 PRInt32 error
= NS_OK
;
361 *aMaximumValue
= value
.ToFloat(&error
);
366 nsXFormsRangeAccessible::GetMinimumValue(double *aMinimumValue
)
368 NS_ENSURE_ARG_POINTER(aMinimumValue
);
371 nsresult rv
= sXFormsService
->GetRangeStart(mDOMNode
, value
);
372 NS_ENSURE_SUCCESS(rv
, rv
);
374 PRInt32 error
= NS_OK
;
375 *aMinimumValue
= value
.ToFloat(&error
);
380 nsXFormsRangeAccessible::GetMinimumIncrement(double *aMinimumIncrement
)
382 NS_ENSURE_ARG_POINTER(aMinimumIncrement
);
385 nsresult rv
= sXFormsService
->GetRangeStep(mDOMNode
, value
);
386 NS_ENSURE_SUCCESS(rv
, rv
);
388 PRInt32 error
= NS_OK
;
389 *aMinimumIncrement
= value
.ToFloat(&error
);
394 nsXFormsRangeAccessible::GetCurrentValue(double *aCurrentValue
)
396 NS_ENSURE_ARG_POINTER(aCurrentValue
);
399 nsresult rv
= sXFormsService
->GetValue(mDOMNode
, value
);
400 NS_ENSURE_SUCCESS(rv
, rv
);
402 PRInt32 error
= NS_OK
;
403 *aCurrentValue
= value
.ToFloat(&error
);
408 // nsXFormsSelectAccessible
410 nsXFormsSelectAccessible::
411 nsXFormsSelectAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
412 nsXFormsContainerAccessible(aNode
, aShell
)
417 nsXFormsSelectAccessible::GetState(PRUint32
*aState
, PRUint32
*aExtraState
)
419 nsresult rv
= nsXFormsContainerAccessible::GetState(aState
, aExtraState
);
420 NS_ENSURE_SUCCESS(rv
, rv
);
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
;
436 // nsXFormsChoicesAccessible
438 nsXFormsChoicesAccessible::
439 nsXFormsChoicesAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
440 nsXFormsAccessible(aNode
, aShell
)
445 nsXFormsChoicesAccessible::GetRole(PRUint32
*aRole
)
447 NS_ENSURE_ARG_POINTER(aRole
);
449 *aRole
= nsIAccessibleRole::ROLE_GROUPING
;
454 nsXFormsChoicesAccessible::GetValue(nsAString
& aValue
)
461 nsXFormsChoicesAccessible::CacheChildren()
463 CacheSelectChildren();
467 // nsXFormsSelectFullAccessible
469 nsXFormsSelectFullAccessible::
470 nsXFormsSelectFullAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
471 nsXFormsSelectableAccessible(aNode
, aShell
)
476 nsXFormsSelectFullAccessible::GetRole(PRUint32
*aRole
)
478 NS_ENSURE_ARG_POINTER(aRole
);
480 *aRole
= nsIAccessibleRole::ROLE_GROUPING
;
485 nsXFormsSelectFullAccessible::CacheChildren()
487 CacheSelectChildren();
491 // nsXFormsItemCheckgroupAccessible
493 nsXFormsItemCheckgroupAccessible::
494 nsXFormsItemCheckgroupAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
495 nsXFormsSelectableItemAccessible(aNode
, aShell
)
500 nsXFormsItemCheckgroupAccessible::GetRole(PRUint32
*aRole
)
502 NS_ENSURE_ARG_POINTER(aRole
);
504 *aRole
= nsIAccessibleRole::ROLE_CHECKBUTTON
;
509 nsXFormsItemCheckgroupAccessible::GetState(PRUint32
*aState
,
510 PRUint32
*aExtraState
)
512 nsresult rv
= nsXFormsSelectableItemAccessible::GetState(aState
, aExtraState
);
513 NS_ENSURE_SUCCESS(rv
, rv
);
517 if (IsItemSelected())
518 *aState
|= nsIAccessibleStates::STATE_CHECKED
;
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");
532 aName
.AssignLiteral("check");
538 // nsXFormsItemRadiogroupAccessible
540 nsXFormsItemRadiogroupAccessible::
541 nsXFormsItemRadiogroupAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
542 nsXFormsSelectableItemAccessible(aNode
, aShell
)
547 nsXFormsItemRadiogroupAccessible::GetRole(PRUint32
*aRole
)
549 NS_ENSURE_ARG_POINTER(aRole
);
551 *aRole
= nsIAccessibleRole::ROLE_RADIOBUTTON
;
556 nsXFormsItemRadiogroupAccessible::GetState(PRUint32
*aState
,
557 PRUint32
*aExtraState
)
559 nsresult rv
= nsXFormsSelectableItemAccessible::GetState(aState
, aExtraState
);
560 NS_ENSURE_SUCCESS(rv
, rv
);
564 if (IsItemSelected())
565 *aState
|= nsIAccessibleStates::STATE_CHECKED
;
571 nsXFormsItemRadiogroupAccessible::GetActionName(PRUint8 aIndex
, nsAString
& aName
)
573 if (aIndex
!= eAction_Click
)
574 return NS_ERROR_INVALID_ARG
;
576 aName
.AssignLiteral("select");
581 // nsXFormsSelectComboboxAccessible
583 nsXFormsSelectComboboxAccessible::
584 nsXFormsSelectComboboxAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
585 nsXFormsSelectableAccessible(aNode
, aShell
)
590 nsXFormsSelectComboboxAccessible::GetRole(PRUint32
*aRole
)
592 NS_ENSURE_ARG_POINTER(aRole
);
594 *aRole
= nsIAccessibleRole::ROLE_COMBOBOX
;
599 nsXFormsSelectComboboxAccessible::GetState(PRUint32
*aState
,
600 PRUint32
*aExtraState
)
602 nsresult rv
= nsXFormsSelectableAccessible::GetState(aState
, aExtraState
);
603 NS_ENSURE_SUCCESS(rv
, rv
);
607 PRBool isOpen
= PR_FALSE
;
608 rv
= sXFormsService
->IsDropmarkerOpen(mDOMNode
, &isOpen
);
609 NS_ENSURE_SUCCESS(rv
, rv
);
612 *aState
= nsIAccessibleStates::STATE_EXPANDED
;
614 *aState
= nsIAccessibleStates::STATE_COLLAPSED
;
616 *aState
|= nsIAccessibleStates::STATE_HASPOPUP
|
617 nsIAccessibleStates::STATE_FOCUSABLE
;
622 nsXFormsSelectComboboxAccessible::GetAllowsAnonChildAccessibles(PRBool
*aAllowsAnonChildren
)
624 NS_ENSURE_ARG_POINTER(aAllowsAnonChildren
);
626 *aAllowsAnonChildren
= PR_TRUE
;
631 // nsXFormsItemComboboxAccessible
633 nsXFormsItemComboboxAccessible::
634 nsXFormsItemComboboxAccessible(nsIDOMNode
*aNode
, nsIWeakReference
*aShell
):
635 nsXFormsSelectableItemAccessible(aNode
, aShell
)
640 nsXFormsItemComboboxAccessible::GetRole(PRUint32
*aRole
)
642 NS_ENSURE_ARG_POINTER(aRole
);
644 *aRole
= nsIAccessibleRole::ROLE_LISTITEM
;
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
))
657 *aState
|= nsIAccessibleStates::STATE_SELECTABLE
;
658 if (IsItemSelected())
659 *aState
|= nsIAccessibleStates::STATE_SELECTED
;
665 nsXFormsItemComboboxAccessible::GetActionName(PRUint8 aIndex
, nsAString
& aName
)
667 if (aIndex
!= eAction_Click
)
668 return NS_ERROR_INVALID_ARG
;
670 aName
.AssignLiteral("select");