Bug 1568151 - Replace `target.getInspector()` by `target.getFront("inspector")`....
[gecko.git] / accessible / base / MarkupMap.h
blobd84aee481bd0b55ee8957a6b0715610121dbac15
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
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/. */
8 MARKUPMAP(
9 a,
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());
21 roles::LINK)
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)
33 MARKUPMAP(
34 button,
35 [](Element* aElement, Accessible* aContext) -> Accessible* {
36 return new HTMLButtonAccessible(aElement, aContext->Document());
40 MARKUPMAP(
41 caption,
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());
51 return nullptr;
55 MARKUPMAP(dd, New_HTMLDtOrDd<HyperTextAccessibleWrap>, roles::DEFINITION)
57 MARKUPMAP(del, New_HyperText, roles::CONTENT_DELETION)
59 MARKUPMAP(details, New_HyperText, roles::DETAILS)
61 MARKUPMAP(
62 div,
63 [](Element* aElement, Accessible* aContext) -> Accessible* {
64 // Never create an accessible if we're part of an anonymous
65 // subtree.
66 if (aElement->IsInAnonymousSubtree()) {
67 return nullptr;
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")) {
80 return nullptr;
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();
87 if (prevSibling) {
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();
95 if (firstChild) {
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());
120 return nullptr;
122 roles::SECTION)
124 MARKUPMAP(
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)
133 MARKUPMAP(
134 figcaption,
135 [](Element* aElement, Accessible* aContext) -> Accessible* {
136 return new HTMLFigcaptionAccessible(aElement, aContext->Document());
138 roles::CAPTION)
140 MARKUPMAP(
141 figure,
142 [](Element* aElement, Accessible* aContext) -> Accessible* {
143 return new HTMLFigureAccessible(aElement, aContext->Document());
145 roles::FIGURE, Attr(xmlroles, figure))
147 MARKUPMAP(
148 fieldset,
149 [](Element* aElement, Accessible* aContext) -> Accessible* {
150 return new HTMLGroupboxAccessible(aElement, aContext->Document());
154 MARKUPMAP(
155 form,
156 [](Element* aElement, Accessible* aContext) -> Accessible* {
157 return new HTMLFormAccessible(aElement, aContext->Document());
161 MARKUPMAP(
162 footer,
163 [](Element* aElement, Accessible* aContext) -> Accessible* {
164 return new HTMLHeaderOrFooterAccessible(aElement, aContext->Document());
168 MARKUPMAP(
169 header,
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)
187 MARKUPMAP(
189 [](Element* aElement, Accessible* aContext) -> Accessible* {
190 return new HTMLHRAccessible(aElement, aContext->Document());
194 MARKUPMAP(
195 input,
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());
221 return nullptr;
225 MARKUPMAP(ins, New_HyperText, roles::CONTENT_INSERTION)
227 MARKUPMAP(
228 label,
229 [](Element* aElement, Accessible* aContext) -> Accessible* {
230 return new HTMLLabelAccessible(aElement, aContext->Document());
232 roles::LABEL)
234 MARKUPMAP(
235 legend,
236 [](Element* aElement, Accessible* aContext) -> Accessible* {
237 return new HTMLLegendAccessible(aElement, aContext->Document());
239 roles::LABEL)
241 MARKUPMAP(
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
247 // list items.
248 if (aContext->IsList() &&
249 aContext->GetContent() == aElement->GetParent()) {
250 return new HTMLLIAccessible(aElement, aContext->Document());
253 return nullptr;
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)
314 MARKUPMAP(
315 mtable_,
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_))
322 MARKUPMAP(
323 mlabeledtr_,
324 [](Element* aElement, Accessible* aContext) -> Accessible* {
325 return new HTMLTableRowAccessible(aElement, aContext->Document());
327 roles::MATHML_LABELED_ROW)
329 MARKUPMAP(
330 mtr_,
331 [](Element* aElement, Accessible* aContext) -> Accessible* {
332 return new HTMLTableRowAccessible(aElement, aContext->Document());
334 roles::MATHML_TABLE_ROW)
336 MARKUPMAP(
337 mtd_,
338 [](Element* aElement, Accessible* aContext) -> Accessible* {
339 return new HTMLTableCellAccessible(aElement, aContext->Document());
341 roles::MATHML_CELL)
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)
372 MARKUPMAP(
374 [](Element* aElement, Accessible* aContext) -> Accessible* {
375 return new HTMLListAccessible(aElement, aContext->Document());
377 roles::LIST)
379 MARKUPMAP(
380 option,
381 [](Element* aElement, Accessible* aContext) -> Accessible* {
382 return new HTMLSelectOptionAccessible(aElement, aContext->Document());
386 MARKUPMAP(
387 optgroup,
388 [](Element* aElement, Accessible* aContext) -> Accessible* {
389 return new HTMLSelectOptGroupAccessible(aElement, aContext->Document());
393 MARKUPMAP(
394 output,
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)
402 MARKUPMAP(
403 progress,
404 [](Element* aElement, Accessible* aContext) -> Accessible* {
405 return new HTMLProgressAccessible(aElement, aContext->Document());
409 MARKUPMAP(q, New_HyperText, 0)
411 MARKUPMAP(
412 section,
413 [](Element* aElement, Accessible* aContext) -> Accessible* {
414 return new HTMLSectionAccessible(aElement, aContext->Document());
418 MARKUPMAP(
419 summary,
420 [](Element* aElement, Accessible* aContext) -> Accessible* {
421 return new HTMLSummaryAccessible(aElement, aContext->Document());
423 roles::SUMMARY)
425 MARKUPMAP(
426 table,
427 [](Element* aElement, Accessible* aContext) -> Accessible* {
428 if (aElement->GetPrimaryFrame() &&
429 aElement->GetPrimaryFrame()->AccessibleType() != eHTMLTableType) {
430 return new ARIAGridAccessibleWrap(aElement, aContext->Document());
432 return nullptr;
436 MARKUPMAP(time, New_HyperText, 0, Attr(xmlroles, time),
437 AttrFromDOM(datetime, datetime))
439 MARKUPMAP(
440 tbody,
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()) {
445 return nullptr;
447 return new HyperTextAccessibleWrap(aElement, aContext->Document());
449 roles::GROUPING)
451 MARKUPMAP(
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());
472 return nullptr;
476 MARKUPMAP(
477 tfoot,
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()) {
482 return nullptr;
484 return new HyperTextAccessibleWrap(aElement, aContext->Document());
486 roles::GROUPING)
488 MARKUPMAP(
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());
499 return nullptr;
503 MARKUPMAP(
504 thead,
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()) {
509 return nullptr;
511 return new HyperTextAccessibleWrap(aElement, aContext->Document());
513 roles::GROUPING)
515 MARKUPMAP(
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();
527 if (table) {
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());
542 return nullptr;
546 MARKUPMAP(
548 [](Element* aElement, Accessible* aContext) -> Accessible* {
549 return new HTMLListAccessible(aElement, aContext->Document());
551 roles::LIST)