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/. */
6 // NOTE: alphabetically ordered
8 #include "FormControlAccessible.h"
10 #include "mozilla/dom/HTMLInputElement.h"
11 #include "mozilla/a11y/Role.h"
13 using namespace mozilla::a11y
;
15 ////////////////////////////////////////////////////////////////////////////////
17 ////////////////////////////////////////////////////////////////////////////////
19 role
CheckboxAccessible::NativeRole() const { return roles::CHECKBUTTON
; }
21 void CheckboxAccessible::ActionNameAt(uint8_t aIndex
, nsAString
& aName
) {
22 if (aIndex
== eAction_Click
) {
23 uint64_t state
= NativeState();
24 if (state
& states::CHECKED
) {
25 aName
.AssignLiteral("uncheck");
26 } else if (state
& states::MIXED
) {
27 aName
.AssignLiteral("cycle");
29 aName
.AssignLiteral("check");
34 bool CheckboxAccessible::HasPrimaryAction() const { return true; }
36 uint64_t CheckboxAccessible::NativeState() const {
37 uint64_t state
= LeafAccessible::NativeState();
39 state
|= states::CHECKABLE
;
40 dom::HTMLInputElement
* input
= dom::HTMLInputElement::FromNode(mContent
);
41 if (input
) { // HTML:input@type="checkbox"
42 if (input
->Indeterminate()) {
43 return state
| states::MIXED
;
46 if (input
->Checked()) {
47 return state
| states::CHECKED
;
50 } else if (mContent
->AsElement()->AttrValueIs(
51 kNameSpaceID_None
, nsGkAtoms::checked
, nsGkAtoms::_true
,
52 eCaseMatters
)) { // XUL checkbox
53 return state
| states::CHECKED
;
59 ////////////////////////////////////////////////////////////////////////////////
60 // CheckboxAccessible: Widgets
62 bool CheckboxAccessible::IsWidget() const { return true; }
64 ////////////////////////////////////////////////////////////////////////////////
65 // RadioButtonAccessible
66 ////////////////////////////////////////////////////////////////////////////////
68 RadioButtonAccessible::RadioButtonAccessible(nsIContent
* aContent
,
70 : LeafAccessible(aContent
, aDoc
) {}
72 bool RadioButtonAccessible::HasPrimaryAction() const { return true; }
74 void RadioButtonAccessible::ActionNameAt(uint8_t aIndex
, nsAString
& aName
) {
75 if (aIndex
== eAction_Click
) aName
.AssignLiteral("select");
78 role
RadioButtonAccessible::NativeRole() const { return roles::RADIOBUTTON
; }
80 ////////////////////////////////////////////////////////////////////////////////
81 // RadioButtonAccessible: Widgets
83 bool RadioButtonAccessible::IsWidget() const { return true; }