1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
11 // Only some roles truly enjoy life as HTMLLinkAccessibles, for
12 // details see closed bug 494807.
13 const nsRoleMapEntry
* roleMapEntry
= aria::GetRoleMap(aElement
);
14 if (roleMapEntry
&& roleMapEntry
->role
!= roles::NOTHING
&&
15 roleMapEntry
->role
!= roles::LINK
) {
16 return new HyperTextAccessibleWrap(aElement
, aContext
->Document());
19 return new HTMLLinkAccessible(aElement
, aContext
->Document());
23 MARKUPMAP(abbr
, New_HyperText
, 0)
25 MARKUPMAP(acronym
, New_HyperText
, 0)
27 MARKUPMAP(article
, New_HyperText
, roles::ARTICLE
, Attr(xmlroles
, article
))
29 MARKUPMAP(aside
, New_HyperText
, roles::LANDMARK
)
31 MARKUPMAP(blockquote
, New_HyperText
, roles::BLOCKQUOTE
)
35 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
36 return new HTMLButtonAccessible(aElement
, aContext
->Document());
42 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
43 if (aContext
->IsTable()) {
44 dom::HTMLTableElement
* tableEl
=
45 dom::HTMLTableElement::FromNode(aContext
->GetContent());
46 if (tableEl
&& tableEl
== aElement
->GetParent() &&
47 tableEl
->GetCaption() == aElement
) {
48 return new HTMLCaptionAccessible(aElement
, aContext
->Document());
55 MARKUPMAP(dd
, New_HTMLDtOrDd
<HyperTextAccessibleWrap
>, roles::DEFINITION
)
57 MARKUPMAP(del
, New_HyperText
, roles::CONTENT_DELETION
)
59 MARKUPMAP(details
, New_HyperText
, roles::DETAILS
)
63 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
64 // Never create an accessible if we're part of an anonymous
66 if (aElement
->IsInAnonymousSubtree()) {
69 // Always create an accessible if the div has an id.
70 if (aElement
->HasAttr(kNameSpaceID_None
, nsGkAtoms::id
)) {
71 return new HyperTextAccessibleWrap(aElement
, aContext
->Document());
73 // Never create an accessible if the div is not display:block; or
74 // display:inline-block;
75 nsAutoString displayValue
;
76 StyleInfo
styleInfo(aElement
);
77 styleInfo
.Display(displayValue
);
78 if (displayValue
!= NS_LITERAL_STRING("block") &&
79 displayValue
!= NS_LITERAL_STRING("inline-block")) {
82 // Check for various conditions to determine if this is a block
83 // break and needs to be rendered.
84 // If its previous sibling is an inline element, we probably want
85 // to break, so render.
86 nsIContent
* prevSibling
= aElement
->GetPreviousSibling();
88 nsIFrame
* prevSiblingFrame
= prevSibling
->GetPrimaryFrame();
89 if (prevSiblingFrame
&& prevSiblingFrame
->IsInlineFrame()) {
90 return new HyperTextAccessibleWrap(aElement
, aContext
->Document());
93 // Now, check the children.
94 nsIContent
* firstChild
= aElement
->GetFirstChild();
96 // Render it if it is a text node.
97 if (firstChild
->IsText()) {
98 return new HyperTextAccessibleWrap(aElement
, aContext
->Document());
100 // Check to see if first child has an inline frame.
101 nsIFrame
* firstChildFrame
= firstChild
->GetPrimaryFrame();
102 if (firstChildFrame
&& (firstChildFrame
->IsInlineFrame() ||
103 firstChildFrame
->IsBrFrame())) {
104 return new HyperTextAccessibleWrap(aElement
, aContext
->Document());
106 nsIContent
* lastChild
= aElement
->GetLastChild();
107 if (lastChild
&& lastChild
!= firstChild
) {
108 // Render it if it is a text node.
109 if (lastChild
->IsText()) {
110 return new HyperTextAccessibleWrap(aElement
, aContext
->Document());
112 // Check to see if last child has an inline frame.
113 nsIFrame
* lastChildFrame
= lastChild
->GetPrimaryFrame();
114 if (lastChildFrame
&& (lastChildFrame
->IsInlineFrame() ||
115 lastChildFrame
->IsBrFrame())) {
116 return new HyperTextAccessibleWrap(aElement
, aContext
->Document());
126 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
127 return new HTMLListAccessible(aElement
, aContext
->Document());
129 roles::DEFINITION_LIST
)
131 MARKUPMAP(dt
, New_HTMLDtOrDd
<HTMLLIAccessible
>, roles::TERM
)
135 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
136 return new HTMLFigcaptionAccessible(aElement
, aContext
->Document());
142 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
143 return new HTMLFigureAccessible(aElement
, aContext
->Document());
145 roles::FIGURE
, Attr(xmlroles
, figure
))
149 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
150 return new HTMLGroupboxAccessible(aElement
, aContext
->Document());
156 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
157 return new HTMLFormAccessible(aElement
, aContext
->Document());
163 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
164 return new HTMLHeaderOrFooterAccessible(aElement
, aContext
->Document());
170 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
171 return new HTMLHeaderOrFooterAccessible(aElement
, aContext
->Document());
175 MARKUPMAP(h1
, New_HyperText
, roles::HEADING
)
177 MARKUPMAP(h2
, New_HyperText
, roles::HEADING
)
179 MARKUPMAP(h3
, New_HyperText
, roles::HEADING
)
181 MARKUPMAP(h4
, New_HyperText
, roles::HEADING
)
183 MARKUPMAP(h5
, New_HyperText
, roles::HEADING
)
185 MARKUPMAP(h6
, New_HyperText
, roles::HEADING
)
189 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
190 return new HTMLHRAccessible(aElement
, aContext
->Document());
196 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
197 // TODO(emilio): This would be faster if it used
198 // HTMLInputElement's already-parsed representation.
199 if (aElement
->AttrValueIs(kNameSpaceID_None
, nsGkAtoms::type
,
200 nsGkAtoms::checkbox
, eIgnoreCase
)) {
201 return new CheckboxAccessible(aElement
, aContext
->Document());
203 if (aElement
->AttrValueIs(kNameSpaceID_None
, nsGkAtoms::type
,
204 nsGkAtoms::image
, eIgnoreCase
)) {
205 return new HTMLButtonAccessible(aElement
, aContext
->Document());
207 if (aElement
->AttrValueIs(kNameSpaceID_None
, nsGkAtoms::type
,
208 nsGkAtoms::radio
, eIgnoreCase
)) {
209 return new HTMLRadioButtonAccessible(aElement
, aContext
->Document());
211 if (aElement
->AttrValueIs(kNameSpaceID_None
, nsGkAtoms::type
,
212 nsGkAtoms::time
, eIgnoreCase
)) {
213 return new EnumRoleAccessible
<roles::GROUPING
>(aElement
,
214 aContext
->Document());
216 if (aElement
->AttrValueIs(kNameSpaceID_None
, nsGkAtoms::type
,
217 nsGkAtoms::date
, eIgnoreCase
)) {
218 return new EnumRoleAccessible
<roles::DATE_EDITOR
>(aElement
,
219 aContext
->Document());
225 MARKUPMAP(ins
, New_HyperText
, roles::CONTENT_INSERTION
)
229 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
230 return new HTMLLabelAccessible(aElement
, aContext
->Document());
236 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
237 return new HTMLLegendAccessible(aElement
, aContext
->Document());
243 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
244 // If list item is a child of accessible list then create an
245 // accessible for it unconditionally by tag name. nsBlockFrame
246 // creates the list item accessible for other elements styled as
248 if (aContext
->IsList() &&
249 aContext
->GetContent() == aElement
->GetParent()) {
250 return new HTMLLIAccessible(aElement
, aContext
->Document());
257 MARKUPMAP(main
, New_HyperText
, roles::LANDMARK
)
259 MARKUPMAP(map
, nullptr, roles::TEXT_CONTAINER
)
261 MARKUPMAP(math
, New_HyperText
, roles::MATHML_MATH
)
263 MARKUPMAP(mi_
, New_HyperText
, roles::MATHML_IDENTIFIER
)
265 MARKUPMAP(mn_
, New_HyperText
, roles::MATHML_NUMBER
)
267 MARKUPMAP(mo_
, New_HyperText
, roles::MATHML_OPERATOR
,
268 AttrFromDOM(accent_
, accent_
), AttrFromDOM(fence_
, fence_
),
269 AttrFromDOM(separator_
, separator_
), AttrFromDOM(largeop_
, largeop_
))
271 MARKUPMAP(mtext_
, New_HyperText
, roles::MATHML_TEXT
)
273 MARKUPMAP(ms_
, New_HyperText
, roles::MATHML_STRING_LITERAL
)
275 MARKUPMAP(mglyph_
, New_HyperText
, roles::MATHML_GLYPH
)
277 MARKUPMAP(mrow_
, New_HyperText
, roles::MATHML_ROW
)
279 MARKUPMAP(mfrac_
, New_HyperText
, roles::MATHML_FRACTION
,
280 AttrFromDOM(bevelled_
, bevelled_
),
281 AttrFromDOM(linethickness_
, linethickness_
))
283 MARKUPMAP(msqrt_
, New_HyperText
, roles::MATHML_SQUARE_ROOT
)
285 MARKUPMAP(mroot_
, New_HyperText
, roles::MATHML_ROOT
)
287 MARKUPMAP(mfenced_
, New_HyperText
, roles::MATHML_FENCED
,
288 AttrFromDOM(close
, close
), AttrFromDOM(open
, open
),
289 AttrFromDOM(separators_
, separators_
))
291 MARKUPMAP(menclose_
, New_HyperText
, roles::MATHML_ENCLOSED
,
292 AttrFromDOM(notation_
, notation_
))
294 MARKUPMAP(mstyle_
, New_HyperText
, roles::MATHML_STYLE
)
296 MARKUPMAP(msub_
, New_HyperText
, roles::MATHML_SUB
)
298 MARKUPMAP(msup_
, New_HyperText
, roles::MATHML_SUP
)
300 MARKUPMAP(msubsup_
, New_HyperText
, roles::MATHML_SUB_SUP
)
302 MARKUPMAP(munder_
, New_HyperText
, roles::MATHML_UNDER
,
303 AttrFromDOM(accentunder_
, accentunder_
), AttrFromDOM(align
, align
))
305 MARKUPMAP(mover_
, New_HyperText
, roles::MATHML_OVER
,
306 AttrFromDOM(accent_
, accent_
), AttrFromDOM(align
, align
))
308 MARKUPMAP(munderover_
, New_HyperText
, roles::MATHML_UNDER_OVER
,
309 AttrFromDOM(accent_
, accent_
),
310 AttrFromDOM(accentunder_
, accentunder_
), AttrFromDOM(align
, align
))
312 MARKUPMAP(mmultiscripts_
, New_HyperText
, roles::MATHML_MULTISCRIPTS
)
316 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
317 return new HTMLTableAccessible(aElement
, aContext
->Document());
319 roles::MATHML_TABLE
, AttrFromDOM(align
, align
),
320 AttrFromDOM(columnlines_
, columnlines_
), AttrFromDOM(rowlines_
, rowlines_
))
324 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
325 return new HTMLTableRowAccessible(aElement
, aContext
->Document());
327 roles::MATHML_LABELED_ROW
)
331 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
332 return new HTMLTableRowAccessible(aElement
, aContext
->Document());
334 roles::MATHML_TABLE_ROW
)
338 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
339 return new HTMLTableCellAccessible(aElement
, aContext
->Document());
343 MARKUPMAP(maction_
, New_HyperText
, roles::MATHML_ACTION
,
344 AttrFromDOM(actiontype_
, actiontype_
),
345 AttrFromDOM(selection_
, selection_
))
347 MARKUPMAP(merror_
, New_HyperText
, roles::MATHML_ERROR
)
349 MARKUPMAP(mstack_
, New_HyperText
, roles::MATHML_STACK
,
350 AttrFromDOM(align
, align
), AttrFromDOM(position
, position
))
352 MARKUPMAP(mlongdiv_
, New_HyperText
, roles::MATHML_LONG_DIVISION
,
353 AttrFromDOM(longdivstyle_
, longdivstyle_
))
355 MARKUPMAP(msgroup_
, New_HyperText
, roles::MATHML_STACK_GROUP
,
356 AttrFromDOM(position
, position
), AttrFromDOM(shift_
, shift_
))
358 MARKUPMAP(msrow_
, New_HyperText
, roles::MATHML_STACK_ROW
,
359 AttrFromDOM(position
, position
))
361 MARKUPMAP(mscarries_
, New_HyperText
, roles::MATHML_STACK_CARRIES
,
362 AttrFromDOM(location_
, location_
), AttrFromDOM(position
, position
))
364 MARKUPMAP(mscarry_
, New_HyperText
, roles::MATHML_STACK_CARRY
,
365 AttrFromDOM(crossout_
, crossout_
))
367 MARKUPMAP(msline_
, New_HyperText
, roles::MATHML_STACK_LINE
,
368 AttrFromDOM(position
, position
))
370 MARKUPMAP(nav
, New_HyperText
, roles::LANDMARK
)
374 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
375 return new HTMLListAccessible(aElement
, aContext
->Document());
381 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
382 return new HTMLSelectOptionAccessible(aElement
, aContext
->Document());
388 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
389 return new HTMLSelectOptGroupAccessible(aElement
, aContext
->Document());
395 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
396 return new HTMLOutputAccessible(aElement
, aContext
->Document());
398 roles::SECTION
, Attr(live
, polite
))
400 MARKUPMAP(p
, nullptr, roles::PARAGRAPH
)
404 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
405 return new HTMLProgressAccessible(aElement
, aContext
->Document());
409 MARKUPMAP(q
, New_HyperText
, 0)
413 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
414 return new HTMLSectionAccessible(aElement
, aContext
->Document());
420 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
421 return new HTMLSummaryAccessible(aElement
, aContext
->Document());
427 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
428 if (aElement
->GetPrimaryFrame() &&
429 aElement
->GetPrimaryFrame()->AccessibleType() != eHTMLTableType
) {
430 return new ARIAGridAccessibleWrap(aElement
, aContext
->Document());
436 MARKUPMAP(time
, New_HyperText
, 0, Attr(xmlroles
, time
),
437 AttrFromDOM(datetime
, datetime
))
441 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
442 // Expose this as a grouping if its frame type is non-standard.
443 if (aElement
->GetPrimaryFrame() &&
444 aElement
->GetPrimaryFrame()->IsTableRowGroupFrame()) {
447 return new HyperTextAccessibleWrap(aElement
, aContext
->Document());
453 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
454 if (aContext
->IsTableRow() &&
455 aContext
->GetContent() == aElement
->GetParent()) {
456 // If HTML:td element is part of its HTML:table, which has CSS
457 // display style other than 'table', then create a generic table
458 // cell accessible, because there's no underlying table layout and
459 // thus native HTML table cell class doesn't work. The same is
460 // true if the cell itself has CSS display:block;.
461 if (!aContext
->IsHTMLTableRow() ||
462 (aElement
->GetPrimaryFrame() &&
463 aElement
->GetPrimaryFrame()->AccessibleType() !=
464 eHTMLTableCellType
)) {
465 return new ARIAGridCellAccessibleWrap(aElement
, aContext
->Document());
467 if (aElement
->HasAttr(kNameSpaceID_None
, nsGkAtoms::scope
)) {
468 return new HTMLTableHeaderCellAccessibleWrap(aElement
,
469 aContext
->Document());
478 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
479 // Expose this as a grouping if its frame type is non-standard.
480 if (aElement
->GetPrimaryFrame() &&
481 aElement
->GetPrimaryFrame()->IsTableRowGroupFrame()) {
484 return new HyperTextAccessibleWrap(aElement
, aContext
->Document());
490 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
491 if (aContext
->IsTableRow() &&
492 aContext
->GetContent() == aElement
->GetParent()) {
493 if (!aContext
->IsHTMLTableRow()) {
494 return new ARIAGridCellAccessibleWrap(aElement
, aContext
->Document());
496 return new HTMLTableHeaderCellAccessibleWrap(aElement
,
497 aContext
->Document());
505 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
506 // Expose this as a grouping if its frame type is non-standard.
507 if (aElement
->GetPrimaryFrame() &&
508 aElement
->GetPrimaryFrame()->IsTableRowGroupFrame()) {
511 return new HyperTextAccessibleWrap(aElement
, aContext
->Document());
517 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
518 // If HTML:tr element is part of its HTML:table, which has CSS
519 // display style other than 'table', then create a generic table row
520 // accessible, because there's no underlying table layout and thus
521 // native HTML table row class doesn't work. Refer to
522 // CreateAccessibleByFrameType dual logic.
523 Accessible
* table
= aContext
->IsTable() ? aContext
: nullptr;
524 if (!table
&& aContext
->Parent() && aContext
->Parent()->IsTable()) {
525 table
= aContext
->Parent();
528 nsIContent
* parentContent
= aElement
->GetParent();
529 nsIFrame
* parentFrame
= parentContent
->GetPrimaryFrame();
530 if (parentFrame
&& !parentFrame
->IsTableWrapperFrame()) {
531 parentContent
= parentContent
->GetParent();
532 parentFrame
= parentContent
->GetPrimaryFrame();
533 if (table
->GetContent() == parentContent
&&
534 ((parentFrame
&& !parentFrame
->IsTableWrapperFrame()) ||
535 (aElement
->GetPrimaryFrame() &&
536 aElement
->GetPrimaryFrame()->AccessibleType() !=
537 eHTMLTableRowType
))) {
538 return new ARIARowAccessible(aElement
, aContext
->Document());
548 [](Element
* aElement
, Accessible
* aContext
) -> Accessible
* {
549 return new HTMLListAccessible(aElement
, aContext
->Document());