Line data Source code
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 : #include "HTMLElementAccessibles.h"
7 :
8 : #include "DocAccessible.h"
9 : #include "nsAccUtils.h"
10 : #include "nsIPersistentProperties2.h"
11 : #include "nsTextEquivUtils.h"
12 : #include "Relation.h"
13 : #include "Role.h"
14 : #include "States.h"
15 :
16 : #include "mozilla/dom/HTMLLabelElement.h"
17 : #include "mozilla/dom/HTMLDetailsElement.h"
18 : #include "mozilla/dom/HTMLSummaryElement.h"
19 :
20 : using namespace mozilla::a11y;
21 :
22 : ////////////////////////////////////////////////////////////////////////////////
23 : // HTMLHRAccessible
24 : ////////////////////////////////////////////////////////////////////////////////
25 :
26 : role
27 0 : HTMLHRAccessible::NativeRole()
28 : {
29 0 : return roles::SEPARATOR;
30 : }
31 :
32 : ////////////////////////////////////////////////////////////////////////////////
33 : // HTMLBRAccessible
34 : ////////////////////////////////////////////////////////////////////////////////
35 :
36 : role
37 0 : HTMLBRAccessible::NativeRole()
38 : {
39 0 : return roles::WHITESPACE;
40 : }
41 :
42 : uint64_t
43 0 : HTMLBRAccessible::NativeState()
44 : {
45 0 : return states::READONLY;
46 : }
47 :
48 : ENameValueFlag
49 0 : HTMLBRAccessible::NativeName(nsString& aName)
50 : {
51 0 : aName = static_cast<char16_t>('\n'); // Newline char
52 0 : return eNameOK;
53 : }
54 :
55 : ////////////////////////////////////////////////////////////////////////////////
56 : // HTMLLabelAccessible
57 : ////////////////////////////////////////////////////////////////////////////////
58 :
59 0 : NS_IMPL_ISUPPORTS_INHERITED0(HTMLLabelAccessible, HyperTextAccessible)
60 :
61 : ENameValueFlag
62 0 : HTMLLabelAccessible::NativeName(nsString& aName)
63 : {
64 0 : nsTextEquivUtils::GetNameFromSubtree(this, aName);
65 0 : return aName.IsEmpty() ? eNameOK : eNameFromSubtree;
66 : }
67 :
68 : Relation
69 0 : HTMLLabelAccessible::RelationByType(RelationType aType)
70 : {
71 0 : Relation rel = AccessibleWrap::RelationByType(aType);
72 0 : if (aType == RelationType::LABEL_FOR) {
73 0 : dom::HTMLLabelElement* label = dom::HTMLLabelElement::FromContent(mContent);
74 0 : rel.AppendTarget(mDoc, label->GetControl());
75 : }
76 :
77 0 : return rel;
78 : }
79 :
80 : uint8_t
81 0 : HTMLLabelAccessible::ActionCount()
82 : {
83 0 : return nsCoreUtils::IsLabelWithControl(mContent) ? 1 : 0;
84 : }
85 :
86 : void
87 0 : HTMLLabelAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
88 : {
89 0 : if (aIndex == 0) {
90 0 : if (nsCoreUtils::IsLabelWithControl(mContent))
91 0 : aName.AssignLiteral("click");
92 : }
93 0 : }
94 :
95 : bool
96 0 : HTMLLabelAccessible::DoAction(uint8_t aIndex)
97 : {
98 0 : if (aIndex != 0)
99 0 : return false;
100 :
101 0 : DoCommand();
102 0 : return true;
103 : }
104 :
105 :
106 : ////////////////////////////////////////////////////////////////////////////////
107 : // nsHTMLOuputAccessible
108 : ////////////////////////////////////////////////////////////////////////////////
109 :
110 0 : NS_IMPL_ISUPPORTS_INHERITED0(HTMLOutputAccessible, HyperTextAccessible)
111 :
112 : Relation
113 0 : HTMLOutputAccessible::RelationByType(RelationType aType)
114 : {
115 0 : Relation rel = AccessibleWrap::RelationByType(aType);
116 0 : if (aType == RelationType::CONTROLLED_BY)
117 0 : rel.AppendIter(new IDRefsIterator(mDoc, mContent, nsGkAtoms::_for));
118 :
119 0 : return rel;
120 : }
121 :
122 : ////////////////////////////////////////////////////////////////////////////////
123 : // HTMLSummaryAccessible
124 : ////////////////////////////////////////////////////////////////////////////////
125 :
126 0 : HTMLSummaryAccessible::
127 0 : HTMLSummaryAccessible(nsIContent* aContent, DocAccessible* aDoc) :
128 0 : HyperTextAccessibleWrap(aContent, aDoc)
129 : {
130 0 : mGenericTypes |= eButton;
131 0 : }
132 :
133 : uint8_t
134 0 : HTMLSummaryAccessible::ActionCount()
135 : {
136 0 : return 1;
137 : }
138 :
139 : void
140 0 : HTMLSummaryAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
141 : {
142 0 : if (aIndex != eAction_Click) {
143 0 : return;
144 : }
145 :
146 0 : dom::HTMLSummaryElement* summary = dom::HTMLSummaryElement::FromContent(mContent);
147 0 : if (!summary) {
148 0 : return;
149 : }
150 :
151 0 : dom::HTMLDetailsElement* details = summary->GetDetails();
152 0 : if (!details) {
153 0 : return;
154 : }
155 :
156 0 : if (details->Open()) {
157 0 : aName.AssignLiteral("collapse");
158 : } else {
159 0 : aName.AssignLiteral("expand");
160 : }
161 : }
162 :
163 : bool
164 0 : HTMLSummaryAccessible::DoAction(uint8_t aIndex)
165 : {
166 0 : if (aIndex != eAction_Click)
167 0 : return false;
168 :
169 0 : DoCommand();
170 0 : return true;
171 : }
172 :
173 : uint64_t
174 0 : HTMLSummaryAccessible::NativeState()
175 : {
176 0 : uint64_t state = HyperTextAccessibleWrap::NativeState();
177 :
178 0 : dom::HTMLSummaryElement* summary = dom::HTMLSummaryElement::FromContent(mContent);
179 0 : if (!summary) {
180 0 : return state;
181 : }
182 :
183 0 : dom::HTMLDetailsElement* details = summary->GetDetails();
184 0 : if (!details) {
185 0 : return state;
186 : }
187 :
188 0 : if (details->Open()) {
189 0 : state |= states::EXPANDED;
190 : } else {
191 0 : state |= states::COLLAPSED;
192 : }
193 :
194 0 : return state;
195 : }
196 :
197 : ////////////////////////////////////////////////////////////////////////////////
198 : // HTMLSummaryAccessible: Widgets
199 :
200 : bool
201 0 : HTMLSummaryAccessible::IsWidget() const
202 : {
203 0 : return true;
204 : }
|