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 // CheckboxAccessible
18 ////////////////////////////////////////////////////////////////////////////////
19 
NativeRole() const20 role CheckboxAccessible::NativeRole() const { return roles::CHECKBUTTON; }
21 
ActionNameAt(uint8_t aIndex,nsAString & aName)22 void CheckboxAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) {
23   if (aIndex == eAction_Click) {
24     uint64_t state = NativeState();
25     if (state & states::CHECKED) {
26       aName.AssignLiteral("uncheck");
27     } else if (state & states::MIXED) {
28       aName.AssignLiteral("cycle");
29     } else {
30       aName.AssignLiteral("check");
31     }
32   }
33 }
34 
HasPrimaryAction() const35 bool CheckboxAccessible::HasPrimaryAction() const { return true; }
36 
NativeState() const37 uint64_t CheckboxAccessible::NativeState() const {
38   uint64_t state = LeafAccessible::NativeState();
39 
40   state |= states::CHECKABLE;
41   dom::HTMLInputElement* input = dom::HTMLInputElement::FromNode(mContent);
42   if (input) {  // HTML:input@type="checkbox"
43     if (input->Indeterminate()) {
44       return state | states::MIXED;
45     }
46 
47     if (input->Checked()) {
48       return state | states::CHECKED;
49     }
50 
51   } else if (mContent->AsElement()->AttrValueIs(
52                  kNameSpaceID_None, nsGkAtoms::checked, nsGkAtoms::_true,
53                  eCaseMatters)) {  // XUL checkbox
54     return state | states::CHECKED;
55   }
56 
57   return state;
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 // CheckboxAccessible: Widgets
62 
IsWidget() const63 bool CheckboxAccessible::IsWidget() const { return true; }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 // RadioButtonAccessible
67 ////////////////////////////////////////////////////////////////////////////////
68 
RadioButtonAccessible(nsIContent * aContent,DocAccessible * aDoc)69 RadioButtonAccessible::RadioButtonAccessible(nsIContent* aContent,
70                                              DocAccessible* aDoc)
71     : LeafAccessible(aContent, aDoc) {}
72 
HasPrimaryAction() const73 bool RadioButtonAccessible::HasPrimaryAction() const { return true; }
74 
ActionNameAt(uint8_t aIndex,nsAString & aName)75 void RadioButtonAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) {
76   if (aIndex == eAction_Click) aName.AssignLiteral("select");
77 }
78 
NativeRole() const79 role RadioButtonAccessible::NativeRole() const { return roles::RADIOBUTTON; }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 // RadioButtonAccessible: Widgets
83 
IsWidget() const84 bool RadioButtonAccessible::IsWidget() const { return true; }
85