blob: 39987a79f5aef8830abad421d58f21c02e22dfb6 [file] [log] [blame]
<
/*
* Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "third_party/blink/renderer/modules/accessibility/ax_object.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/web_scroll_into_view_params.h"
#include "third_party/blink/renderer/core/aom/accessible_node.h"
#include "third_party/blink/renderer/core/aom/accessible_node_list.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/display_lock/display_lock_utilities.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/user_gesture_indicator.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/custom/element_internals.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/forms/html_select_element.h"
#include "third_party/blink/renderer/core/html/html_dialog_element.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/input/context_menu_allowed_scope.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/layout_box_model_object.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/modules/accessibility/ax_object_cache_impl.h"
#include "third_party/blink/renderer/modules/accessibility/ax_range.h"
#include "third_party/blink/renderer/modules/accessibility/ax_sparse_attribute_setter.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/language.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/text/platform_locale.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/wtf_size_t.h"
#include "third_party/skia/include/core/SkMatrix44.h"
namespace blink {
namespace {
struct RoleHashTraits : HashTraits<ax::mojom::Role> {
static const bool kEmptyValueIsZero = true;
static ax::mojom::Role EmptyValue() { return ax::mojom::Role::kUnknown; }
};
using ARIARoleMap = HashMap<String,
ax::mojom::Role,
CaseFoldingHash,
HashTraits<String>,
RoleHashTraits>;
struct RoleEntry {
const char* aria_role;
ax::mojom::Role webcore_role;
};
// Mapping of ARIA role name to internal role name.
const RoleEntry kRoles[] = {
{"alert", ax::mojom::Role::kAlert},
{"alertdialog", ax::mojom::Role::kAlertDialog},
{"annotation-attribution", ax::mojom::Role::kAnnotationAttribution},
{"annotation-commentary", ax::mojom::Role::kAnnotationCommentary},
{"annotation-presence", ax::mojom::Role::kAnnotationPresence},
{"annotation-revision", ax::mojom::Role::kAnnotationRevision},
{"annotation-suggestion", ax::mojom::Role::kAnnotationSuggestion},
{"application", ax::mojom::Role::kApplication},
{"article", ax::mojom::Role::kArticle},
{"banner", ax::mojom::Role::kBanner},
{"blockquote", ax::mojom::Role::kBlockquote},
{"button", ax::mojom::Role::kButton},
{"caption", ax::mojom::Role::kCaption},
{"cell", ax::mojom::Role::kCell},
{"code", ax::mojom::Role::kCode},
{"checkbox", ax::mojom::Role::kCheckBox},
{"columnheader", ax::mojom::Role::kColumnHeader},
{"combobox", ax::mojom::Role::kComboBoxGrouping},
{"complementary", ax::mojom::Role::kComplementary},
{"contentinfo", ax::mojom::Role::kContentInfo},
{"definition", ax::mojom::Role::kDefinition},
{"deletion", ax::mojom::Role::kContentDeletion},
{"dialog", ax::mojom::Role::kDialog},
{"directory", ax::mojom::Role::kDirectory},
// -------------------------------------------------
// DPub Roles:
// www.w3.org/TR/dpub-aam-1.0/#mapping_role_table
{"doc-abstract", ax::mojom::Role::kDocAbstract},
{"doc-acknowledgments", ax::mojom::Role::kDocAcknowledgments},
{"doc-afterword", ax::mojom::Role::kDocAfterword},
{"doc-appendix", ax::mojom::Role::kDocAppendix},
{"doc-backlink", ax::mojom::Role::kDocBackLink},
{"doc-biblioentry", ax::mojom::Role::kDocBiblioEntry},
{"doc-bibliography", ax::mojom::Role::kDocBibliography},
{"doc-biblioref", ax::mojom::Role::kDocBiblioRef},
{"doc-chapter", ax::mojom::Role::kDocChapter},
{"doc-colophon", ax::mojom::Role::kDocColophon},
{"doc-conclusion", ax::mojom::Role::kDocConclusion},
{"doc-cover", ax::mojom::Role::kDocCover},
{"doc-credit", ax::mojom::Role::kDocCredit},
{"doc-credits", ax::mojom::Role::kDocCredits},
{"doc-dedication", ax::mojom::Role::kDocDedication},
{"doc-endnote", ax::mojom::Role::kDocEndnote},
{"doc-endnotes", ax::mojom::Role::kDocEndnotes},
{"doc-epigraph", ax::mojom::Role::kDocEpigraph},
{"doc-epilogue", ax::mojom::Role::kDocEpilogue},
{"doc-errata", ax::mojom::Role::kDocErrata},
{"doc-example", ax::mojom::Role::kDocExample},
{"doc-footnote", ax::mojom::Role::kDocFootnote},
{"doc-foreword", ax::mojom::Role::kDocForeword},
{"doc-glossary", ax::mojom::Role::kDocGlossary},
{"doc-glossref", ax::mojom::Role::kDocGlossRef},
{"doc-index", ax::mojom::Role::kDocIndex},
{"doc-introduction", ax::mojom::Role::kDocIntroduction},
{"doc-noteref", ax::mojom::Role::kDocNoteRef},
{"doc-notice", ax::mojom::Role::kDocNotice},
{"doc-pagebreak", ax::mojom::Role::kDocPageBreak},
{"doc-pagelist", ax::mojom::Role::kDocPageList},
{"doc-part", ax::mojom::Role::kDocPart},
{"doc-preface", ax::mojom::Role::kDocPreface},
{"doc-prologue", ax::mojom::Role::kDocPrologue},
{"doc-pullquote", ax::mojom::Role::kDocPullquote},
{"doc-qna", ax::mojom::Role::kDocQna},
{"doc-subtitle", ax::mojom::Role::kDocSubtitle},
{"doc-tip", ax::mojom::Role::kDocTip},
{"doc-toc", ax::mojom::Role::kDocToc},
// End DPub roles.
// -------------------------------------------------
{"document", ax::mojom::Role::kDocument},
{"emphasis", ax::mojom::Role::kEmphasis},
{"feed", ax::mojom::Role::kFeed},
{"figure", ax::mojom::Role::kFigure},
{"form", ax::mojom::Role::kForm},
{"generic", ax::mojom::Role::kGenericContainer},
// -------------------------------------------------
// ARIA Graphics module roles:
// https://rawgit.com/w3c/graphics-aam/master/
{"graphics-document", ax::mojom::Role::kGraphicsDocument},
{"graphics-object", ax::mojom::Role::kGraphicsObject},
{"graphics-symbol", ax::mojom::Role::kGraphicsSymbol},
// End ARIA Graphics module roles.
// -------------------------------------------------
{"grid", ax::mojom::Role::kGrid},
{"gridcell", ax::mojom::Role::kCell},
{"group", ax::mojom::Role::kGroup},
{"heading", ax::mojom::Role::kHeading},
{"img", ax::mojom::Role::kImage},
{"insertion", ax::mojom::Role::kContentInsertion},
{"link", ax::mojom::Role::kLink},
{"list", ax::mojom::Role::kList},
{"listbox", ax::mojom::Role::kListBox},
{"listitem", ax::mojom::Role::kListItem},
{"log", ax::mojom::Role::kLog},
{"main", ax::mojom::Role::kMain},
{"marquee", ax::mojom::Role::kMarquee},
{"math", ax::mojom::Role::kMath},
{"menu", ax::mojom::Role::kMenu},
{"menubar", ax::mojom::Role::kMenuBar},
{"menuitem", ax::mojom::Role::kMenuItem},
{"menuitemcheckbox", ax::mojom::Role::kMenuItemCheckBox},
{"menuitemradio", ax::mojom::Role::kMenuItemRadio},
{"meter", ax::mojom::Role::kMeter},
{"navigation", ax::mojom::Role::kNavigation},
{"none", ax::mojom::Role::kNone},
{"note", ax::mojom::Role::kNote},
{"option", ax::mojom::Role::kListBoxOption},
{"paragraph", ax::mojom::Role::kParagraph},
{"presentation", ax::mojom::Role::kPresentational},
{"progressbar", ax::mojom::Role::kProgressIndicator},
{"radio", ax::mojom::Role::kRadioButton},
{"radiogroup", ax::mojom::Role::kRadioGroup},
// TODO(accessibility) region should only be mapped
// if name present. See http://crbug.com/840819.
{"region", ax::mojom::Role::kRegion},
{"row", ax::mojom::Role::kRow},
{"rowheader", ax::mojom::Role::kRowHeader},
{"scrollbar", ax::mojom::Role::kScrollBar},
{"search", ax::mojom::Role::kSearch},
{"searchbox", ax::mojom::Role::kSearchBox},
{"separator", ax::mojom::Role::kSplitter},
{"slider", ax::mojom::Role::kSlider},
{"spinbutton", ax::mojom::Role::kSpinButton},
{"status", ax::mojom::Role::kStatus},
{"strong", ax::mojom::Role::kStrong},
{"switch", ax::mojom::Role::kSwitch},
{"tab", ax::mojom::Role::kTab},
{"table", ax::mojom::Role::kTable},
{"tablist", ax::mojom::Role::kTabList},
{"tabpanel", ax::mojom::Role::kTabPanel},
{"term", ax::mojom::Role::kTerm},
{"text", ax::mojom::Role::kStaticText},
{"textbox", ax::mojom::Role::kTextField},
{"time", ax::mojom::Role::kTime},
{"timer", ax::mojom::Role::kTimer},
{"toolbar", ax::mojom::Role::kToolbar},
{"tooltip", ax::mojom::Role::kTooltip},
{"tree", ax::mojom::Role::kTree},
{"treegrid", ax::mojom::Role::kTreeGrid},
{"treeitem", ax::mojom::Role::kTreeItem}};
struct InternalRoleEntry {
ax::mojom::Role webcore_role;
const char* internal_role_name;
};
const InternalRoleEntry kInternalRoles[] = {
{ax::mojom::Role::kNone, "None"},
{ax::mojom::Role::kAbbr, "Abbr"},
{ax::mojom::Role::kAlertDialog, "AlertDialog"},
{ax::mojom::Role::kAlert, "Alert"},
{ax::mojom::Role::kAnchor, "Anchor"},
{ax::mojom::Role::kAnnotationAttribution, "kAnnotationAttribution"},
{ax::mojom::Role::kAnnotationCommentary, "AnnotationCommentary"},
{ax::mojom::Role::kAnnotationPresence, "AnnotationPresence"},
{ax::mojom::Role::kAnnotationRevision, "AnnotationRevision"},
{ax::mojom::Role::kAnnotationSuggestion, "AnnotationSuggestion"},
{ax::mojom::Role::kApplication, "Application"},
{ax::mojom::Role::kArticle, "Article"},
{ax::mojom::Role::kAudio, "Audio"},
{ax::mojom::Role::kBanner, "Banner"},
{ax::mojom::Role::kBlockquote, "Blockquote"},
{ax::mojom::Role::kButton, "Button"},
{ax::mojom::Role::kCanvas, "Canvas"},
{ax::mojom::Role::kCaption, "Caption"},
{ax::mojom::Role::kCaret, "Caret"},
{ax::mojom::Role::kCell, "Cell"},
{ax::mojom::Role::kCheckBox, "CheckBox"},
{ax::mojom::Role::kClient, "Client"},
{ax::mojom::Role::kCode, "Code"},
{ax::mojom::Role::kColorWell, "ColorWell"},
{ax::mojom::Role::kColumnHeader, "ColumnHeader"},
{ax::mojom::Role::kColumn, "Column"},
{ax::mojom::Role::kComboBoxGrouping, "ComboBox"},
{ax::mojom::Role::kComboBoxMenuButton, "ComboBox"},
{ax::mojom::Role::kComplementary, "Complementary"},
{ax::mojom::Role::kContentDeletion, "ContentDeletion"},
{ax::mojom::Role::kContentInsertion, "ContentInsertion"},
{ax::mojom::Role::kContentInfo, "ContentInfo"},
{ax::mojom::Role::kDate, "Date"},
{ax::mojom::Role::kDateTime, "DateTime"},
{ax::mojom::Role::kDefinition, "Definition"},
{ax::mojom::Role::kDescriptionListDetail, "DescriptionListDetail"},
{ax::mojom::Role::kDescriptionList, "DescriptionList"},
{ax::mojom::Role::kDescriptionListTerm, "DescriptionListTerm"},
{ax::mojom::Role::kDesktop, "Desktop"},
{ax::mojom::Role::kDetails, "Details"},
{ax::mojom::Role::kDialog, "Dialog"},
{ax::mojom::Role::kDirectory, "Directory"},
{ax::mojom::Role::kDisclosureTriangle, "DisclosureTriangle"},
// --------------------------------------------------------------
// DPub Roles:
// https://www.w3.org/TR/dpub-aam-1.0/#mapping_role_table
{ax::mojom::Role::kDocAbstract, "DocAbstract"},
{ax::mojom::Role::kDocAcknowledgments, "DocAcknowledgments"},
{ax::mojom::Role::kDocAfterword, "DocAfterword"},
{ax::mojom::Role::kDocAppendix, "DocAppendix"},
{ax::mojom::Role::kDocBackLink, "DocBackLink"},
{ax::mojom::Role::kDocBiblioEntry, "DocBiblioentry"},
{ax::mojom::Role::kDocBibliography, "DocBibliography"},
{ax::mojom::Role::kDocBiblioRef, "DocBiblioref"},
{ax::mojom::Role::kDocChapter, "DocChapter"},
{ax::mojom::Role::kDocColophon, "DocColophon"},
{ax::mojom::Role::kDocConclusion, "DocConclusion"},
{ax::mojom::Role::kDocCover, "DocCover"},
{ax::mojom::Role::kDocCredit, "DocCredit"},
{ax::mojom::Role::kDocCredits, "DocCredits"},
{ax::mojom::Role::kDocDedication, "DocDedication"},
{ax::mojom::Role::kDocEndnote, "DocEndnote"},
{ax::mojom::Role::kDocEndnotes, "DocEndnotes"},
{ax::mojom::Role::kDocEpigraph, "DocEpigraph"},
{ax::mojom::Role::kDocEpilogue, "DocEpilogue"},
{ax::mojom::Role::kDocErrata, "DocErrata"},
{ax::mojom::Role::kDocExample, "DocExample"},
{ax::mojom::Role::kDocFootnote, "DocFootnote"},
{ax::mojom::Role::kDocForeword, "DocForeword"},
{ax::mojom::Role::kDocGlossary, "DocGlossary"},
{ax::mojom::Role::kDocGlossRef, "DocGlossref"},
{ax::mojom::Role::kDocIndex, "DocIndex"},
{ax::mojom::Role::kDocIntroduction, "DocIntroduction"},
{ax::mojom::Role::kDocNoteRef, "DocNoteref"},
{ax::mojom::Role::kDocNotice, "DocNotice"},
{ax::mojom::Role::kDocPageBreak, "DocPagebreak"},
{ax::mojom::Role::kDocPageList, "DocPagelist"},
{ax::mojom::Role::kDocPart, "DocPart"},
{ax::mojom::Role::kDocPreface, "DocPreface"},
{ax::mojom::Role::kDocPrologue, "DocPrologue"},
{ax::mojom::Role::kDocPullquote, "DocPullquote"},
{ax::mojom::Role::kDocQna, "DocQna"},
{ax::mojom::Role::kDocSubtitle, "DocSubtitle"},
{ax::mojom::Role::kDocTip, "DocTip"},
{ax::mojom::Role::kDocToc, "DocToc"},
// End DPub roles.
// --------------------------------------------------------------
{ax::mojom::Role::kDocument, "Document"},
{ax::mojom::Role::kEmbeddedObject, "EmbeddedObject"},
{ax::mojom::Role::kEmphasis, "Emphasis"},
{ax::mojom::Role::kFeed, "feed"},
{ax::mojom::Role::kFigcaption, "Figcaption"},
{ax::mojom::Role::kFigure, "Figure"},
{ax::mojom::Role::kFooter, "Footer"},
{ax::mojom::Role::kFooterAsNonLandmark, "FooterAsNonLandmark"},
{ax::mojom::Role::kForm, "Form"},
{ax::mojom::Role::kGenericContainer, "GenericContainer"},
// --------------------------------------------------------------
// ARIA Graphics module roles:
// https://rawgit.com/w3c/graphics-aam/master/#mapping_role_table
{ax::mojom::Role::kGraphicsDocument, "GraphicsDocument"},
{ax::mojom::Role::kGraphicsObject, "GraphicsObject"},
{ax::mojom::Role::kGraphicsSymbol, "GraphicsSymbol"},
// End ARIA Graphics module roles.
// --------------------------------------------------------------
{ax::mojom::Role::kGrid, "Grid"},
{ax::mojom::Role::kGroup, "Group"},
{ax::mojom::Role::kHeader, "Header"},
{ax::mojom::Role::kHeaderAsNonLandmark, "HeaderAsNonLandmark"},
{ax::mojom::Role::kHeading, "Heading"},
{ax::mojom::Role::kIframePresentational, "IframePresentational"},
{ax::mojom::Role::kIframe, "Iframe"},
{ax::mojom::Role::kIgnored, "Ignored"},
{ax::mojom::Role::kImageMap, "ImageMap"},
{ax::mojom::Role::kImage, "Image"},
{ax::mojom::Role::kInlineTextBox, "InlineTextBox"},
{ax::mojom::Role::kInputTime, "InputTime"},
{ax::mojom::Role::kKeyboard, "Keyboard"},
{ax::mojom::Role::kLabelText, "Label"},
{ax::mojom::Role::kLayoutTable, "LayoutTable"},
{ax::mojom::Role::kLayoutTableCell, "LayoutCellTable"},
{ax::mojom::Role::kLayoutTableColumn, "LayoutColumnTable"},
{ax::mojom::Role::kLayoutTableRow, "LayoutRowTable"},
{ax::mojom::Role::kLegend, "Legend"},
{ax::mojom::Role::kLink, "Link"},
{ax::mojom::Role::kLineBreak, "LineBreak"},
{ax::mojom::Role::kListBox, "ListBox"},
{ax::mojom::Role::kListBoxOption, "ListBoxOption"},
{ax::mojom::Role::kListGrid, "ListGrid"},
{ax::mojom::Role::kListItem, "ListItem"},
{ax::mojom::Role::kListMarker, "ListMarker"},
{ax::mojom::Role::kList, "List"},
{ax::mojom::Role::kLog, "Log"},
{ax::mojom::Role::kMain, "Main"},
{ax::mojom::Role::kMark, "Mark"},
{ax::mojom::Role::kMarquee, "Marquee"},
{ax::mojom::Role::kMath, "Math"},
{ax::mojom::Role::kMenuBar, "MenuBar"},
{ax::mojom::Role::kMenuButton, "MenuButton"},
{ax::mojom::Role::kMenuItem, "MenuItem"},
{ax::mojom::Role::kMenuItemCheckBox, "MenuItemCheckBox"},
{ax::mojom::Role::kMenuItemRadio, "MenuItemRadio"},
{ax::mojom::Role::kMenuListOption, "MenuListOption"},
{ax::mojom::Role::kMenuListPopup, "MenuListPopup"},
{ax::mojom::Role::kMenu, "Menu"},
{ax::mojom::Role::kMeter, "Meter"},
{ax::mojom::Role::kNavigation, "Navigation"},
{ax::mojom::Role::kNote, "Note"},
{ax::mojom::Role::kPane, "Pane"},
{ax::mojom::Role::kParagraph, "Paragraph"},
{ax::mojom::Role::kPopUpButton, "PopUpButton"},
{ax::mojom::Role::kPre, "Pre"},
{ax::mojom::Role::kPresentational, "Presentational"},
{ax::mojom::Role::kProgressIndicator, "ProgressIndicator"},
{ax::mojom::Role::kRadioButton, "RadioButton"},
{ax::mojom::Role::kRadioGroup, "RadioGroup"},
{ax::mojom::Role::kRegion, "Region"},
{ax::mojom::Role::kRootWebArea, "WebArea"},
{ax::mojom::Role::kRowHeader, "RowHeader"},
{ax::mojom::Role::kRow, "Row"},
{ax::mojom::Role::kRuby, "Ruby"},
{ax::mojom::Role::kRubyAnnotation, "RubyAnnotation"},
{ax::mojom::Role::kSection, "Section"},
{ax::mojom::Role::kSvgRoot, "SVGRoot"},
{ax::mojom::Role::kScrollBar, "ScrollBar"},
{ax::mojom::Role::kScrollView, "ScrollView"},
{ax::mojom::Role::kSearch, "Search"},
{ax::mojom::Role::kSearchBox, "SearchBox"},
{ax::mojom::Role::kSlider, "Slider"},
{ax::mojom::Role::kSliderThumb, "SliderThumb"},
{ax::mojom::Role::kSpinButton, "SpinButton"},
{ax::mojom::Role::kSplitter, "Splitter"},
{ax::mojom::Role::kStaticText, "StaticText"},
{ax::mojom::Role::kStatus, "Status"},
{ax::mojom::Role::kStrong, "Strong"},
{ax::mojom::Role::kSwitch, "Switch"},
{ax::mojom::Role::kTab, "Tab"},
{ax::mojom::Role::kTabList, "TabList"},
{ax::mojom::Role::kTabPanel, "TabPanel"},
{ax::mojom::Role::kTable, "Table"},
{ax::mojom::Role::kTableHeaderContainer, "TableHeaderContainer"},
{ax::mojom::Role::kTerm, "Term"},
{ax::mojom::Role::kTextField, "TextField"},
{ax::mojom::Role::kTextFieldWithComboBox, "ComboBox"},
{ax::mojom::Role::kTime, "Time"},
{ax::mojom::Role::kTimer, "Timer"},
{ax::mojom::Role::kTitleBar, "TitleBar"},
{ax::mojom::Role::kToggleButton, "ToggleButton"},
{ax::mojom::Role::kToolbar, "Toolbar"},
{ax::mojom::Role::kTreeGrid, "TreeGrid"},
{ax::mojom::Role::kTreeItem, "TreeItem"},
{ax::mojom::Role::kTree, "Tree"},
{ax::mojom::Role::kTooltip, "UserInterfaceTooltip"},
{ax::mojom::Role::kUnknown, "Unknown"},
{ax::mojom::Role::kVideo, "Video"},
{ax::mojom::Role::kWebArea, "WebArea"},
{ax::mojom::Role::kWebView, "WebView"},
{ax::mojom::Role::kWindow, "Window"}};
static_assert(base::size(kInternalRoles) ==
static_cast<size_t>(ax::mojom::Role::kMaxValue) + 1,
"Not all internal roles have an entry in internalRoles array");
// Roles which we need to map in the other direction
const RoleEntry kReverseRoles[] = {
{"banner", ax::mojom::Role::kHeader},
{"button", ax::mojom::Role::kToggleButton},
{"combobox", ax::mojom::Role::kPopUpButton},
{"contentinfo", ax::mojom::Role::kFooter},
{"menuitem", ax::mojom::Role::kMenuButton},
{"menuitem", ax::mojom::Role::kMenuListOption},
{"progressbar", ax::mojom::Role::kMeter},
{"region", ax::mojom::Role::kSection},
{"textbox", ax::mojom::Role::kTextField},
{"combobox", ax::mojom::Role::kComboBoxMenuButton},
{"combobox", ax::mojom::Role::kTextFieldWithComboBox}};
static ARIARoleMap* CreateARIARoleMap() {
ARIARoleMap* role_map = new ARIARoleMap;
for (size_t i = 0; i < base::size(kRoles); ++i)
role_map->Set(String(kRoles[i].aria_role), kRoles[i].webcore_role);
// Grids "ignore" their non-row children during computation of children.
role_map->Set(String("rowgroup"), ax::mojom::Role::kIgnored);
return role_map;
}
static Vector<AtomicString>* CreateRoleNameVector() {
Vector<AtomicString>* role_name_vector =
new Vector<AtomicString>(base::size(kInternalRoles));
for (wtf_size_t i = 0; i < base::size(kInternalRoles); i++)
(*role_name_vector)[i] = g_null_atom;
for (wtf_size_t i = 0; i < base::size(kRoles); ++i) {
(*role_name_vector)[static_cast<wtf_size_t>(kRoles[i].webcore_role)] =
AtomicString(kRoles[i].aria_role);
}
for (wtf_size_t i = 0; i < base::size(kReverseRoles); ++i) {
(*role_name_vector)[static_cast<wtf_size_t>(
kReverseRoles[i].webcore_role)] =
AtomicString(kReverseRoles[i].aria_role);
}
return role_name_vector;
}
static Vector<AtomicString>* CreateInternalRoleNameVector() {
Vector<AtomicString>* internal_role_name_vector =
new Vector<AtomicString>(base::size(kInternalRoles));
for (wtf_size_t i = 0; i < base::size(kInternalRoles); i++) {
(*internal_role_name_vector)[static_cast<wtf_size_t>(
kInternalRoles[i].webcore_role)] =
AtomicString(kInternalRoles[i].internal_role_name);
}
return internal_role_name_vector;
}
HTMLDialogElement* GetActiveDialogElement(Node* node) {
return node->GetDocument().ActiveModalDialog();
}
} // namespace
unsigned AXObject::number_of_live_ax_objects_ = 0;
AXObject::AXObject(AXObjectCacheImpl& ax_object_cache)
: id_(0),
have_children_(false),
role_(ax::mojom::Role::kUnknown),
aria_role_(ax::mojom::Role::kUnknown),
last_known_is_ignored_value_(kDefaultBehavior),
last_known_is_ignored_but_included_in_tree_value_(kDefaultBehavior),
explicit_container_id_(0),
parent_(nullptr),
last_modification_count_(-1),
cached_is_ignored_(false),
cached_is_ignored_but_included_in_tree_(false),
cached_is_inert_or_aria_hidden_(false),
cached_is_descendant_of_leaf_node_(false),
cached_is_descendant_of_disabled_node_(false),
cached_has_inherited_presentational_role_(false),
cached_is_editable_root_(false),
cached_live_region_root_(nullptr),
cached_aria_column_index_(0),
cached_aria_row_index_(0),
ax_object_cache_(&ax_object_cache) {
++number_of_live_ax_objects_;
}
AXObject::~AXObject() {
DCHECK(IsDetached());
--number_of_live_ax_objects_;
}
void AXObject::Init() {
role_ = DetermineAccessibilityRole();
}
void AXObject::Detach() {
// Clear any children and call detachFromParent on them so that
// no children are left with dangling pointers to their parent.
ClearChildren();
ax_object_cache_ = nullptr;
}
bool AXObject::IsDetached() const {
return !ax_object_cache_;
}
const AtomicString& AXObject::GetAOMPropertyOrARIAAttribute(
AOMStringProperty property) const {
Element* element = this->GetElement();
if (!element)
return g_null_atom;
return AccessibleNode::GetPropertyOrARIAAttribute(element, property);
}
Element* AXObject::GetAOMPropertyOrARIAAttribute(
AOMRelationProperty property) const {
Element* element = this->GetElement();
if (!element)
return nullptr;
return AccessibleNode::GetPropertyOrARIAAttribute(element, property);
}
bool AXObject::HasAOMProperty(AOMRelationListProperty property,
HeapVector<Member<Element>>& result) const {
Element* element = this->GetElement();
if (!element)
return false;
return AccessibleNode::GetProperty(element, property, result);
}
bool AXObject::HasAOMPropertyOrARIAAttribute(
AOMRelationListProperty property,
HeapVector<Member<Element>>& result) const {
Element* element = this->GetElement();
if (!element)
return false;
return AccessibleNode::GetPropertyOrARIAAttribute(element, property, result);
}
bool AXObject::HasAOMPropertyOrARIAAttribute(AOMBooleanProperty property,
bool& result) const {
Element* element = this->GetElement();
if (!element)
return false;
bool is_null = true;
result =
AccessibleNode::GetPropertyOrARIAAttribute(element, property, is_null);
return !is_null;
}
bool AXObject::AOMPropertyOrARIAAttributeIsTrue(
AOMBooleanProperty property) const {
bool result;
if (HasAOMPropertyOrARIAAttribute(property, result))
return result;
return false;
}
bool AXObject::AOMPropertyOrARIAAttributeIsFalse(
AOMBooleanProperty property) const {
bool result;
if (HasAOMPropertyOrARIAAttribute(property, result))
return !result;
return false;
}
bool AXObject::HasAOMPropertyOrARIAAttribute(AOMUIntProperty property,
uint32_t& result) const {
Element* element = this->GetElement();
if (!element)
return false;
bool is_null = true;
result =
AccessibleNode::GetPropertyOrARIAAttribute(element, property, is_null);
return !is_null;
}
bool AXObject::HasAOMPropertyOrARIAAttribute(AOMIntProperty property,
int32_t& result) const {
Element* element = this->GetElement();
if (!element)
return false;
bool is_null = true;
result =
AccessibleNode::GetPropertyOrARIAAttribute(element, property, is_null);
return !is_null;
}
bool AXObject::HasAOMPropertyOrARIAAttribute(AOMFloatProperty property,
float& result) const {
Element* element = this->GetElement();
if (!element)
return false;
bool is_null = true;
result =
AccessibleNode::GetPropertyOrARIAAttribute(element, property, is_null);
return !is_null;
}
bool AXObject::HasAOMPropertyOrARIAAttribute(AOMStringProperty property,
AtomicString& result) const {
Element* element = this->GetElement();
if (!element)
return false;
result = AccessibleNode::GetPropertyOrARIAAttribute(element, property);
return !result.IsNull();
}
AccessibleNode* AXObject::GetAccessibleNode() const {
Element* element = GetElement();
if (!element)
return nullptr;
return element->ExistingAccessibleNode();
}
void AXObject::GetSparseAXAttributes(
AXSparseAttributeClient& sparse_attribute_client) const {
AXSparseAttributeAOMPropertyClient property_client(*ax_object_cache_,
sparse_attribute_client);
HashSet<QualifiedName> shadowed_aria_attributes;
AccessibleNode* accessible_node = GetAccessibleNode();
// Virtual nodes for AOM are still tied to the AXTree.
if (accessible_node && IsVirtualObject())
accessible_node->GetAllAOMProperties(&property_client,
shadowed_aria_attributes);
Element* element = GetElement();
if (!element)
return;
AXSparseAttributeSetterMap& ax_sparse_attribute_setter_map =
GetSparseAttributeSetterMap();
AttributeCollection attributes = element->AttributesWithoutUpdate();
HashSet<QualifiedName> set_attributes;
for (const Attribute& attr : attributes) {
set_attributes.insert(attr.GetName());
if (shadowed_aria_attributes.Contains(attr.GetName()))
continue;
AXSparseAttributeSetter* setter =
ax_sparse_attribute_setter_map.at(attr.GetName());
if (setter)
setter->Run(*this, sparse_attribute_client, attr.Value());
}
if (!element->DidAttachInternals())
return;
const auto& internals_attributes =
element->EnsureElementInternals().GetAttributes();
for (const QualifiedName& attr : internals_attributes.Keys()) {
if (set_attributes.Contains(attr))
continue;
AXSparseAttributeSetter* setter = ax_sparse_attribute_setter_map.at(attr);
if (setter) {
setter->Run(*this, sparse_attribute_client,
internals_attributes.at(attr));
}
}
}
bool AXObject::IsARIATextControl() const {
return AriaRoleAttribute() == ax::mojom::Role::kTextField ||
AriaRoleAttribute() == ax::mojom::Role::kSearchBox ||
AriaRoleAttribute() == ax::mojom::Role::kTextFieldWithComboBox;
}
bool AXObject::IsButton() const {
ax::mojom::Role role = RoleValue();
return role == ax::mojom::Role::kButton ||
role == ax::mojom::Role::kPopUpButton ||
role == ax::mojom::Role::kToggleButton;
}
bool AXObject::IsCheckable() const {
switch (RoleValue()) {
case ax::mojom::Role::kCheckBox:
case ax::mojom::Role::kMenuItemCheckBox:
case ax::mojom::Role::kMenuItemRadio:
case ax::mojom::Role::kRadioButton:
case ax::mojom::Role::kSwitch:
case ax::mojom::Role::kToggleButton:
return true;
case ax::mojom::Role::kTreeItem:
case ax::mojom::Role::kListBoxOption:
case ax::mojom::Role::kMenuListOption:
return AriaCheckedIsPresent();
default:
return false;
}
}
// Why this is here instead of AXNodeObject:
// Because an AXMenuListOption (<option>) can
// have an ARIA role of menuitemcheckbox/menuitemradio
// yet does not inherit from AXNodeObject
ax::mojom::CheckedState AXObject::CheckedState() const {
if (!IsCheckable())
return ax::mojom::CheckedState::kNone;
// Try ARIA checked/pressed state
const ax::mojom::Role role = RoleValue();
const auto prop = role == ax::mojom::Role::kToggleButton
? AOMStringProperty::kPressed
: AOMStringProperty::kChecked;
const AtomicString& checked_attribute = GetAOMPropertyOrARIAAttribute(prop);
if (checked_attribute) {
if (EqualIgnoringASCIICase(checked_attribute, "mixed")) {
// Only checkable role that doesn't support mixed is the switch.
if (role != ax::mojom::Role::kSwitch)
return ax::mojom::CheckedState::kMixed;
}
// Anything other than "false" should be treated as "true".
return EqualIgnoringASCIICase(checked_attribute, "false")
? ax::mojom::CheckedState::kFalse
: ax::mojom::CheckedState::kTrue;
}
// Native checked state
if (role != ax::mojom::Role::kToggleButton) {
const Node* node = this->GetNode();
if (!node)
return ax::mojom::CheckedState::kNone;
// Expose native checkbox mixed state as accessibility mixed state. However,
// do not expose native radio mixed state as accessibility mixed state.
// This would confuse the JAWS screen reader, which reports a mixed radio as
// both checked and partially checked, but a native mixed native radio
// button sinply means no radio buttons have been checked in the group yet.
if (IsNativeCheckboxInMixedState(node))
return ax::mojom::CheckedState::kMixed;
if (IsHTMLInputElement(*node) &&
ToHTMLInputElement(*node).ShouldAppearChecked()) {
return ax::mojom::CheckedState::kTrue;
}
}
return ax::mojom::CheckedState::kFalse;
}
bool AXObject::IsNativeCheckboxInMixedState(const Node* node) {
if (!IsHTMLInputElement(node))
return false;
const HTMLInputElement* input = ToHTMLInputElement(node);
const auto inputType = input->type();
if (inputType != input_type_names::kCheckbox)
return false;
return input->ShouldAppearIndeterminate();
}
bool AXObject::IsLandmarkRelated() const {
switch (RoleValue()) {
case ax::mojom::Role::kApplication:
case ax::mojom::Role::kArticle:
case ax::mojom::Role::kBanner:
case ax::mojom::Role::kComplementary:
case ax::mojom::Role::kContentInfo:
case ax::mojom::Role::kDocAcknowledgments:
case ax::mojom::Role::kDocAfterword:
case ax::mojom::Role::kDocAppendix:
case ax::mojom::Role::kDocBibliography:
case ax::mojom::Role::kDocChapter:
case ax::mojom::Role::kDocConclusion:
case ax::mojom::Role::kDocCredits:
case ax::mojom::Role::kDocEndnotes:
case ax::mojom::Role::kDocEpilogue:
case ax::mojom::Role::kDocErrata:
case ax::mojom::Role::kDocForeword:
case ax::mojom::Role::kDocGlossary:
case ax::mojom::Role::kDocIntroduction:
case ax::mojom::Role::kDocPart:
case ax::mojom::Role::kDocPreface:
case ax::mojom::Role::kDocPrologue:
case ax::mojom::Role::kDocToc:
case ax::mojom::Role::kFooter:
case ax::mojom::Role::kForm:
case ax::mojom::Role::kHeader:
case ax::mojom::Role::kMain:
case ax::mojom::Role::kNavigation:
case ax::mojom::Role::kRegion:
case ax::mojom::Role::kSearch:
case ax::mojom::Role::kSection:
return true;
default:
return false;
}
}
bool AXObject::IsMenuRelated() const {
switch (RoleValue()) {
case ax::mojom::Role::kMenu:
case ax::mojom::Role::kMenuBar:
case ax::mojom::Role::kMenuButton:
case ax::mojom::Role::kMenuItem:
case ax::mojom::Role::kMenuItemCheckBox:
case ax::mojom::Role::kMenuItemRadio:
return true;
default:
return false;
}
}
bool AXObject::IsPasswordFieldAndShouldHideValue() const {
Settings* settings = GetDocument()->GetSettings();
if (!settings || settings->GetAccessibilityPasswordValuesEnabled())
return false;
return IsPasswordField();
}
bool AXObject::IsTextObject() const {
// Objects with |ax::mojom::Role::kLineBreak| are HTML <br> elements and are
// not backed by DOM text nodes. We can't mark them as text objects for that
// reason.
switch (RoleValue()) {
case ax::mojom::Role::kInlineTextBox:
case ax::mojom::Role::kStaticText:
return true;
default:
return false;
}
}
bool AXObject::IsClickable() const {
if (IsButton() || IsLink() || IsTextControl())
return true;
// TODO(dmazzoni): Ensure that ax::mojom::Role::kColorWell and
// ax::mojom::Role::kSpinButton are correctly handled here via their
// constituent parts.
switch (RoleValue()) {
case ax::mojom::Role::kCheckBox:
case ax::mojom::Role::kComboBoxMenuButton:
case ax::mojom::Role::kDisclosureTriangle:
case ax::mojom::Role::kListBox:
case ax::mojom::Role::kListBoxOption:
case ax::mojom::Role::kMenuItemCheckBox:
case ax::mojom::Role::kMenuItemRadio:
case ax::mojom::Role::kMenuItem:
case ax::mojom::Role::kMenuListOption:
case ax::mojom::Role::kRadioButton:
case ax::mojom::Role::kSwitch:
case ax::mojom::Role::kTab:
return true;
default:
return false;
}
}
bool AXObject::AccessibilityIsIgnored() const {
UpdateDistributionForFlatTreeTraversal();
UpdateCachedAttributeValuesIfNeeded();
return cached_is_ignored_;
}
bool AXObject::AccessibilityIsIgnoredButIncludedInTree() const {
UpdateDistributionForFlatTreeTraversal();
UpdateCachedAttributeValuesIfNeeded();
return cached_is_ignored_but_included_in_tree_;
}
// AccessibilityIsIncludedInTree should be true for all nodes that should be
// included in the tree, even if they are ignored
bool AXObject::AccessibilityIsIncludedInTree() const {
return !AccessibilityIsIgnored() || AccessibilityIsIgnoredButIncludedInTree();
}
void AXObject::UpdateCachedAttributeValuesIfNeeded() const {
if (IsDetached())
return;
AXObjectCacheImpl& cache = AXObjectCache();
if (cache.ModificationCount() == last_modification_count_)
return;
last_modification_count_ = cache.ModificationCount();
cached_background_color_ = ComputeBackgroundColor();
cached_is_inert_or_aria_hidden_ = ComputeIsInertOrAriaHidden();
cached_is_descendant_of_leaf_node_ = !!LeafNodeAncestor();
cached_is_descendant_of_disabled_node_ = !!DisabledAncestor();
cached_has_inherited_presentational_role_ =
!!InheritsPresentationalRoleFrom();
cached_is_ignored_ = ComputeAccessibilityIsIgnored();
cached_is_ignored_but_included_in_tree_ =
cached_is_ignored_ && ComputeAccessibilityIsIgnoredButIncludedInTree();
cached_is_editable_root_ = ComputeIsEditableRoot();
// Compute live region root, which can be from any ARIA live value, including
// "off", or from an automatic ARIA live value, e.g. from role="status".
// TODO(dmazzoni): remove this const_cast.
AtomicString aria_live;
cached_live_region_root_ =
IsLiveRegionRoot()
? const_cast<AXObject*>(this)
: (ParentObjectIfExists() ? ParentObjectIfExists()->LiveRegionRoot()
: nullptr);
cached_aria_column_index_ = ComputeAriaColumnIndex();
cached_aria_row_index_ = ComputeAriaRowIndex();
bool ignored_states_changed = false;
if (cached_is_ignored_ != LastKnownIsIgnoredValue()) {
last_known_is_ignored_value_ =
cached_is_ignored_ ? kIgnoreObject : kIncludeObject;
ignored_states_changed = true;
}
if (cached_is_ignored_but_included_in_tree_ !=
LastKnownIsIgnoredButIncludedInTreeValue()) {
last_known_is_ignored_but_included_in_tree_value_ =
cached_is_ignored_but_included_in_tree_ ? kIncludeObject
: kIgnoreObject;
ignored_states_changed = true;
}
if (ignored_states_changed) {
if (AXObject* parent = ParentObjectIfExists())
parent->ChildrenChanged();
}
if (GetLayoutObject() && GetLayoutObject()->IsText()) {
cached_local_bounding_box_rect_for_accessibility_ =
GetLayoutObject()->LocalBoundingBoxRectForAccessibility();
}
}
bool AXObject::AccessibilityIsIgnoredByDefault(
IgnoredReasons* ignored_reasons) const {
return DefaultObjectInclusion(ignored_reasons) == kIgnoreObject;
}
AXObjectInclusion AXObject::AccessibilityPlatformIncludesObject() const {
if (IsMenuListPopup() || IsMenuListOption())
return kIncludeObject;
return kDefaultBehavior;
}
AXObjectInclusion AXObject::DefaultObjectInclusion(
IgnoredReasons* ignored_reasons) const {
if (IsInertOrAriaHidden()) {
// Keep focusable elements that are aria-hidden in tree, so that they can
// still fire events such as focus and value changes.
const Element* elem = GetElement();
if (!elem || !elem->SupportsFocus() || elem->IsInert()) {
if (ignored_reasons)
ComputeIsInertOrAriaHidden(ignored_reasons);
return kIgnoreObject;
}
}
return AccessibilityPlatformIncludesObject();
}
bool AXObject::IsInertOrAriaHidden() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_is_inert_or_aria_hidden_;
}
bool AXObject::ComputeIsInertOrAriaHidden(
IgnoredReasons* ignored_reasons) const {
if (GetNode()) {
if (GetNode()->IsInert()) {
if (ignored_reasons) {
HTMLDialogElement* dialog = GetActiveDialogElement(GetNode());
if (dialog) {
AXObject* dialog_object = AXObjectCache().GetOrCreate(dialog);
if (dialog_object) {
ignored_reasons->push_back(
IgnoredReason(kAXActiveModalDialog, dialog_object));
} else {
ignored_reasons->push_back(IgnoredReason(kAXInertElement));
}
} else {
const AXObject* inert_root_el = InertRoot();
if (inert_root_el == this) {
ignored_reasons->push_back(IgnoredReason(kAXInertElement));
} else {
ignored_reasons->push_back(
IgnoredReason(kAXInertSubtree, inert_root_el));
}
}
}
return true;
}
} else {
AXObject* parent = ParentObject();
if (parent && parent->IsInertOrAriaHidden()) {
if (ignored_reasons)
parent->ComputeIsInertOrAriaHidden(ignored_reasons);
return true;
}
}
const AXObject* hidden_root = AriaHiddenRoot();
if (hidden_root) {
if (ignored_reasons) {
if (hidden_root == this) {
ignored_reasons->push_back(IgnoredReason(kAXAriaHiddenElement));
} else {
ignored_reasons->push_back(
IgnoredReason(kAXAriaHiddenSubtree, hidden_root));
}
}
return true;
}
return false;
}
bool AXObject::IsVisible() const {
return !IsInertOrAriaHidden() && !IsHiddenForTextAlternativeCalculation();
}
bool AXObject::IsDescendantOfLeafNode() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_is_descendant_of_leaf_node_;
}
AXObject* AXObject::LeafNodeAncestor() const {
if (AXObject* parent = ParentObject()) {
if (!parent->CanHaveChildren())
return parent;
return parent->LeafNodeAncestor();
}
return nullptr;
}
const AXObject* AXObject::AriaHiddenRoot() const {
for (const AXObject* object = this; object; object = object->ParentObject()) {
if (object->AOMPropertyOrARIAAttributeIsTrue(AOMBooleanProperty::kHidden))
return object;
}
return nullptr;
}
const AXObject* AXObject::InertRoot() const {
const AXObject* object = this;
if (!RuntimeEnabledFeatures::InertAttributeEnabled())
return nullptr;
while (object && !object->IsAXNodeObject())
object = object->ParentObject();
Node* node = object->GetNode();
auto* element = DynamicTo<Element>(node);
if (!element)
element = FlatTreeTraversal::ParentElement(*node);
while (element) {
if (element->FastHasAttribute(html_names::kInertAttr))
return AXObjectCache().GetOrCreate(element);
element = FlatTreeTraversal::ParentElement(*element);
}
return nullptr;
}
bool AXObject::DispatchEventToAOMEventListeners(Event& event) {
HeapVector<Member<AccessibleNode>> event_path;
for (AXObject* ancestor = this; ancestor;
ancestor = ancestor->ParentObject()) {
AccessibleNode* ancestor_accessible_node = ancestor->GetAccessibleNode();
if (!ancestor_accessible_node)
continue;
if (!ancestor_accessible_node->HasEventListeners(event.type()))
continue;
event_path.push_back(ancestor_accessible_node);
}
// Short-circuit: if there are no AccessibleNodes attached anywhere
// in the ancestry of this node, exit.
if (!event_path.size())
return false;
// Check if the user has granted permission for this domain to use
// AOM event listeners yet. This may trigger an infobar, but we shouldn't
// block, so whatever decision the user makes will apply to the next
// event received after that.
//
// Note that we only ask the user about this permission the first
// time an event is received that actually would have triggered an
// event listener. However, if the user grants this permission, it
// persists for this origin from then on.
if (!AXObjectCache().CanCallAOMEventListeners()) {
AXObjectCache().RequestAOMEventListenerPermission();
return false;
}
// Since we now know the AOM is being used in this document, get the
// AccessibleNode for the target element and create it if necessary -
// otherwise we wouldn't be able to set the event target. However note
// that if it didn't previously exist it won't be part of the event path.
AccessibleNode* target = GetAccessibleNode();
if (!target) {
if (Element* element = GetElement())
target = element->accessibleNode();
}
if (!target)
return false;
event.SetTarget(target);
// Capturing phase.
event.SetEventPhase(Event::kCapturingPhase);
for (int i = static_cast<int>(event_path.size()) - 1; i >= 0; i--) {
// Don't call capturing event listeners on the target. Note that
// the target may not necessarily be in the event path which is why
// we check here.
if (event_path[i] == target)
break;
event.SetCurrentTarget(event_path[i]);
event_path[i]->FireEventListeners(event);
if (event.PropagationStopped())
return true;
}
// Targeting phase.
event.SetEventPhase(Event::kAtTarget);
event.SetCurrentTarget(event_path[0]);
event_path[0]->FireEventListeners(event);
if (event.PropagationStopped())
return true;
// Bubbling phase.
event.SetEventPhase(Event::kBubblingPhase);
for (wtf_size_t i = 1; i < event_path.size(); i++) {
event.SetCurrentTarget(event_path[i]);
event_path[i]->FireEventListeners(event);
if (event.PropagationStopped())
return true;
}
if (event.defaultPrevented())
return true;
return false;
}
bool AXObject::IsDescendantOfDisabledNode() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_is_descendant_of_disabled_node_;
}
const AXObject* AXObject::DisabledAncestor() const {
bool disabled = false;
if (HasAOMPropertyOrARIAAttribute(AOMBooleanProperty::kDisabled, disabled)) {
if (disabled)
return this;
return nullptr;
}
if (AXObject* parent = ParentObject())
return parent->DisabledAncestor();
return nullptr;
}
bool AXObject::ComputeAccessibilityIsIgnoredButIncludedInTree() const {
if (!GetNode())
return false;
// If the node is part of the user agent shadow dom, or has the explicit
// internal Role::kIgnored, they aren't interesting for paragraph navigation
// or LabelledBy/DescribedBy relationships.
if (RoleValue() == ax::mojom::Role::kIgnored ||
GetNode()->IsInUserAgentShadowRoot()) {
return false;
}
// Always pass through Line Breaking objects, this is necessary to
// detect paragraph edges, which are defined as hard-line breaks.
if (IsLineBreakingObject())
return true;
// Allow the browser side ax tree to access "visibility: [hidden|collapse]"
// and "display: none" nodes. This is useful for APIs that return the node
// referenced by aria-labeledby and aria-describedby.
// An element must have an id attribute or it cannot be referenced by
// aria-labelledby or aria-describedby.
if (RuntimeEnabledFeatures::AccessibilityExposeDisplayNoneEnabled()) {
if (Element* element = GetElement()) {
if (element->FastHasAttribute(html_names::kIdAttr) &&
IsHiddenForTextAlternativeCalculation()) {
return true;
}
}
} else if (GetLayoutObject()) {
if (GetLayoutObject()->Style()->Visibility() != EVisibility::kVisible)
return true;
}
// Allow the browser side ax tree to access "aria-hidden" nodes.
// This is useful for APIs that return the node referenced by
// aria-labeledby and aria-describedby.
if (GetLayoutObject() && AriaHiddenRoot())
return true;
return false;
}
const AXObject* AXObject::DatetimeAncestor(int max_levels_to_check) const {
switch (RoleValue()) {
case ax::mojom::Role::kDateTime:
case ax::mojom::Role::kDate:
case ax::mojom::Role::kInputTime:
case ax::mojom::Role::kTime:
return this;
default:
break;
}
if (max_levels_to_check == 0)
return nullptr;
if (AXObject* parent = ParentObject())
return parent->DatetimeAncestor(max_levels_to_check - 1);
return nullptr;
}
bool AXObject::LastKnownIsIgnoredValue() const {
if (last_known_is_ignored_value_ == kDefaultBehavior) {
last_known_is_ignored_value_ =
AccessibilityIsIgnored() ? kIgnoreObject : kIncludeObject;
}
return last_known_is_ignored_value_ == kIgnoreObject;
}
void AXObject::SetLastKnownIsIgnoredValue(bool is_ignored) {
last_known_is_ignored_value_ = is_ignored ? kIgnoreObject : kIncludeObject;
}
bool AXObject::LastKnownIsIgnoredButIncludedInTreeValue() const {
if (last_known_is_ignored_but_included_in_tree_value_ == kDefaultBehavior) {
last_known_is_ignored_but_included_in_tree_value_ =
AccessibilityIsIgnoredButIncludedInTree() ? kIncludeObject
: kIgnoreObject;
}
return last_known_is_ignored_but_included_in_tree_value_ == kIncludeObject;
}
void AXObject::SetLastKnownIsIgnoredButIncludedInTreeValue(
bool is_ignored_but_included_in_tree) {
last_known_is_ignored_but_included_in_tree_value_ =
is_ignored_but_included_in_tree ? kIncludeObject : kIgnoreObject;
}
bool AXObject::HasInheritedPresentationalRole() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_has_inherited_presentational_role_;
}
bool AXObject::CanReceiveAccessibilityFocus() const {
const Element* elem = GetElement();
if (!elem)
return false;
// Focusable, and not forwarding the focus somewhere else
if (elem->IsFocusable() &&
!GetAOMPropertyOrARIAAttribute(AOMRelationProperty::kActiveDescendant))
return true;
// aria-activedescendant focus
return elem->FastHasAttribute(html_names::kIdAttr) && CanBeActiveDescendant();
}
bool AXObject::CanSetValueAttribute() const {
switch (RoleValue()) {
case ax::mojom::Role::kColorWell:
case ax::mojom::Role::kDate:
case ax::mojom::Role::kDateTime:
case ax::mojom::Role::kScrollBar:
case ax::mojom::Role::kSlider:
case ax::mojom::Role::kSpinButton:
case ax::mojom::Role::kSplitter:
case ax::mojom::Role::kTextField:
case ax::mojom::Role::kTextFieldWithComboBox:
case ax::mojom::Role::kTime:
case ax::mojom::Role::kSearchBox:
return Restriction() == kRestrictionNone;
default:
break;
}
return false;
}
bool AXObject::CanSetFocusAttribute() const {
Node* node = GetNode();
if (!node)
return false;
if (IsWebArea())
return true;
// Children of elements with an aria-activedescendant attribute should be
// focusable if they have a (non-presentational) ARIA role.
if (!IsPresentational() && AriaRoleAttribute() != ax::mojom::Role::kUnknown &&
CanBeActiveDescendant()) {
return true;
}
// NOTE: It would be more accurate to ask the document whether
// setFocusedNode() would do anything. For example, setFocusedNode() will do
// nothing if the current focused node will not relinquish the focus.
if (IsDisabledFormControl(node))
return false;
// Check for options here because AXListBoxOption and AXMenuListOption
// don't help when the <option> is canvas fallback, and because
// a common case for aria-owns from a textbox that points to a list
// does not change the hierarchy (textboxes don't support children)
if (RoleValue() == ax::mojom::Role::kListBoxOption ||
RoleValue() == ax::mojom::Role::kMenuListOption)
return true;
auto* element = DynamicTo<Element>(node);
return element && element->SupportsFocus();
}
// From ARIA 1.1.
// 1. The value of aria-activedescendant refers to an element that is either a
// descendant of the element with DOM focus or is a logical descendant as
// indicated by the aria-owns attribute. 2. The element with DOM focus is a
// textbox with aria-controls referring to an element that supports
// aria-activedescendant, and the value of aria-activedescendant specified for
// the textbox refers to either a descendant of the element controlled by the
// textbox or is a logical descendant of that controlled element as indicated by
// the aria-owns attribute.
bool AXObject::CanBeActiveDescendant() const {
return IsARIAControlledByTextboxWithActiveDescendant() ||
AncestorExposesActiveDescendant();
}
void AXObject::UpdateDistributionForFlatTreeTraversal() const {
Node* node = GetNode();
if (!node) {
AXObject* parent = this->ParentObject();
while (!node && parent) {
node = parent->GetNode();
parent = parent->ParentObject();
}
}
if (node)
node->UpdateDistributionForFlatTreeTraversal();
// TODO(aboxhall): Instead of this, propagate inert down through frames
Document* document = GetDocument();
while (document && document->LocalOwner()) {
document->LocalOwner()->UpdateDistributionForFlatTreeTraversal();
document = document->LocalOwner()->ownerDocument();
}
}
bool AXObject::IsARIAControlledByTextboxWithActiveDescendant() const {
// This situation should mostly arise when using an active descendant on a
// textbox inside an ARIA 1.1 combo box widget, which points to the selected
// option in a list. In such situations, the active descendant is useful only
// when the textbox is focused. Therefore, we don't currently need to keep
// track of all aria-controls relationships.
const AXObject* focused_object = AXObjectCache().FocusedObject();
if (!focused_object || !focused_object->IsTextControl())
return false;
if (!focused_object->GetAOMPropertyOrARIAAttribute(
AOMRelationProperty::kActiveDescendant)) {
return false;
}
HeapVector<Member<Element>> controlled_by_elements;
if (!focused_object->HasAOMPropertyOrARIAAttribute(
AOMRelationListProperty::kControls, controlled_by_elements)) {
return false;
}
for (const auto& controlled_by_element : controlled_by_elements) {
const AXObject* controlled_by_object =
AXObjectCache().GetOrCreate(controlled_by_element);
if (!controlled_by_object)
continue;
const AXObject* object = this;
while (object && object != controlled_by_object)
object = object->ParentObjectUnignored();
if (object)
return true;
}
return false;
}
bool AXObject::AncestorExposesActiveDescendant() const {
const AXObject* parent = ParentObjectUnignored();
if (!parent)
return false;
if (parent->GetAOMPropertyOrARIAAttribute(
AOMRelationProperty::kActiveDescendant)) {
return true;
}
return parent->AncestorExposesActiveDescendant();
}
bool AXObject::HasIndirectChildren() const {
return RoleValue() == ax::mojom::Role::kTableHeaderContainer;
}
bool AXObject::CanSetSelectedAttribute() const {
// Sub-widget elements can be selected if not disabled (native or ARIA)
return IsSubWidget() && Restriction() != kRestrictionDisabled;
}
bool AXObject::IsSubWidget() const {
switch (RoleValue()) {
case ax::mojom::Role::kCell:
case ax::mojom::Role::kColumnHeader:
case ax::mojom::Role::kRowHeader:
case ax::mojom::Role::kColumn:
case ax::mojom::Role::kRow: {
// If it has an explicit ARIA role, it's a subwidget.
//
// Reasoning:
// Static table cells are not selectable, but ARIA grid cells
// and rows definitely are according to the spec. To support
// ARIA 1.0, it's sufficient to just check if there's any
// ARIA role at all, because if so then it must be a grid-related
// role so it must be selectable.
//
// TODO: an ARIA 1.1+ role of "cell", or a role of "row" inside
// an ARIA 1.1 role of "table", should not be selectable. We may
// need to create separate role enums for grid cells vs table cells
// to implement this.
if (AriaRoleAttribute() != ax::mojom::Role::kUnknown)
return true;
// Otherwise it's only a subwidget if it's in a grid or treegrid,
// not in a table.
AXObject* parent = ParentObjectUnignored();
while (parent && !parent->IsTableLikeRole())
parent = parent->ParentObjectUnignored();
if (parent && (parent->RoleValue() == ax::mojom::Role::kGrid ||
parent->RoleValue() == ax::mojom::Role::kTreeGrid))
return true;
return false;
}
case ax::mojom::Role::kListBoxOption:
case ax::mojom::Role::kMenuListOption:
case ax::mojom::Role::kTab:
case ax::mojom::Role::kTreeItem:
return true;
default:
break;
}
return false;
}
bool AXObject::SupportsARIASetSizeAndPosInSet() const {
switch (RoleValue()) {
case ax::mojom::Role::kArticle:
case ax::mojom::Role::kListBoxOption:
case ax::mojom::Role::kListItem:
case ax::mojom::Role::kMenuItem:
case ax::mojom::Role::kMenuItemRadio:
case ax::mojom::Role::kMenuItemCheckBox:
case ax::mojom::Role::kMenuListOption:
case ax::mojom::Role::kRadioButton:
case ax::mojom::Role::kRow:
case ax::mojom::Role::kTab:
case ax::mojom::Role::kTreeItem:
return true;
default:
break;
}
return false;
}
// Simplify whitespace, but preserve a single leading and trailing whitespace
// character if it's present.
// static
String AXObject::CollapseWhitespace(const String& str) {
StringBuilder result;
if (!str.IsEmpty() && IsHTMLSpace<UChar>(str[0]))
result.Append(' ');
result.Append(str.SimplifyWhiteSpace(IsHTMLSpace<UChar>));
if (!str.IsEmpty() && IsHTMLSpace<UChar>(str[str.length() - 1]))
result.Append(' ');
return result.ToString();
}
String AXObject::ComputedName() const {
ax::mojom::NameFrom name_from;
AXObject::AXObjectVector name_objects;
return GetName(name_from, &name_objects);
}
String AXObject::GetName(ax::mojom::NameFrom& name_from,
AXObject::AXObjectVector* name_objects) const {
HeapHashSet<Member<const AXObject>> visited;
AXRelatedObjectVector related_objects;
// For purposes of computing a text alternative, if an ignored node is
// included in the tree, assume that it is the target of aria-labelledby or
// aria-describedby, since we can't tell yet whether that's the case. If it
// isn't exposed, the AT will never see the name anyways.
bool hidden_and_ignored_but_included_in_tree =
IsHiddenForTextAlternativeCalculation() &&
AccessibilityIsIgnoredButIncludedInTree();
// Initialize |name_from|, as TextAlternative() might never set it in some
// cases.
name_from = ax::mojom::NameFrom::kNone;
String text = TextAlternative(false, hidden_and_ignored_but_included_in_tree,
visited, name_from, &related_objects, nullptr);
ax::mojom::Role role = RoleValue();
if (!GetNode() ||
(!IsA<HTMLBRElement>(GetNode()) && role != ax::mojom::Role::kStaticText &&
role != ax::mojom::Role::kInlineTextBox))
text = CollapseWhitespace(text);
if (name_objects) {
name_objects->clear();
for (NameSourceRelatedObject* related_object : related_objects)
name_objects->push_back(related_object->object);
}
return text;
}
String AXObject::GetName(NameSources* name_sources) const {
AXObjectSet visited;
ax::mojom::NameFrom tmp_name_from;
AXRelatedObjectVector tmp_related_objects;
// For purposes of computing a text alternative, if an ignored node is
// included in the tree, assume that it is the target of aria-labelledby or
// aria-describedby, since we can't tell yet whether that's the case. If it
// isn't exposed, the AT will never see the name anyways.
bool hidden_and_ignored_but_included_in_tree =
IsHiddenForTextAlternativeCalculation() &&
AccessibilityIsIgnoredButIncludedInTree();
String text =
TextAlternative(false, hidden_and_ignored_but_included_in_tree, visited,
tmp_name_from, &tmp_related_objects, name_sources);
text = text.SimplifyWhiteSpace(IsHTMLSpace<UChar>);
return text;
}
String AXObject::RecursiveTextAlternative(const AXObject& ax_obj,
bool in_aria_labelled_by_traversal,
AXObjectSet& visited) {
ax::mojom::NameFrom tmp_name_from;
return RecursiveTextAlternative(ax_obj, in_aria_labelled_by_traversal,
visited, tmp_name_from);
}
String AXObject::RecursiveTextAlternative(const AXObject& ax_obj,
bool in_aria_labelled_by_traversal,
AXObjectSet& visited,
ax::mojom::NameFrom& name_from) {
if (visited.Contains(&ax_obj) && !in_aria_labelled_by_traversal)
return String();
return ax_obj.TextAlternative(true, in_aria_labelled_by_traversal, visited,
name_from, nullptr, nullptr);
}
bool AXObject::IsHiddenForTextAlternativeCalculation() const {
if (AOMPropertyOrARIAAttributeIsFalse(AOMBooleanProperty::kHidden))
return false;
if (GetLayoutObject())
return GetLayoutObject()->Style()->Visibility() != EVisibility::kVisible;
// This is an obscure corner case: if a node has no LayoutObject, that means
// it's not rendered, but we still may be exploring it as part of a text
// alternative calculation, for example if it was explicitly referenced by
// aria-labelledby. So we need to explicitly call the style resolver to check
// whether it's invisible or display:none, rather than relying on the style
// cached in the LayoutObject.
Document* document = GetDocument();
if (!document || !document->GetFrame())
return false;
if (Node* node = GetNode()) {
auto* element = DynamicTo<Element>(node);
if (element && node->isConnected()) {
const ComputedStyle* style = element->EnsureComputedStyle();
return style->Display() == EDisplay::kNone ||
style->Visibility() != EVisibility::kVisible;
}
}
return false;
}
String AXObject::AriaTextAlternative(bool recursive,
bool in_aria_labelled_by_traversal,
AXObjectSet& visited,
ax::mojom::NameFrom& name_from,
AXRelatedObjectVector* related_objects,
NameSources* name_sources,
bool* found_text_alternative) const {
String text_alternative;
bool already_visited = visited.Contains(this);
visited.insert(this);
// Step 2A from: http://www.w3.org/TR/accname-aam-1.1
// If you change this logic, update AXNodeObject::nameFromLabelElement, too.
if (!in_aria_labelled_by_traversal &&
IsHiddenForTextAlternativeCalculation()) {
*found_text_alternative = true;
return String();
}
// Step 2B from: http://www.w3.org/TR/accname-aam-1.1
// If you change this logic, update AXNodeObject::nameFromLabelElement, too.
if (!in_aria_labelled_by_traversal && !already_visited) {
name_from = ax::mojom::NameFrom::kRelatedElement;
// Check ARIA attributes.
const QualifiedName& attr =
HasAttribute(html_names::kAriaLabeledbyAttr) &&
!HasAttribute(html_names::kAriaLabelledbyAttr)
? html_names::kAriaLabeledbyAttr
: html_names::kAriaLabelledbyAttr;
if (name_sources) {
name_sources->push_back(NameSource(*found_text_alternative, attr));
name_sources->back().type = name_from;
}
const AtomicString& aria_labelledby = GetAttribute(attr);
if (!aria_labelledby.IsNull()) {
if (name_sources)
name_sources->back().attribute_value = aria_labelledby;
// Operate on a copy of |visited| so that if |nameSources| is not null,
// the set of visited objects is preserved unmodified for future
// calculations.
AXObjectSet visited_copy = visited;
Vector<String> ids;
text_alternative =
TextFromAriaLabelledby(visited_copy, related_objects, ids);
if (!ids.IsEmpty())
AXObjectCache().UpdateReverseRelations(this, ids);
if (!text_alternative.IsNull()) {
if (name_sources) {
NameSource& source = name_sources->back();
source.type = name_from;
source.related_objects = *related_objects;
source.text = text_alternative;
*found_text_alternative = true;
} else {
*found_text_alternative = true;
return text_alternative;
}
} else if (name_sources) {
name_sources->back().invalid = true;
}
}
}
// Step 2C from: http://www.w3.org/TR/accname-aam-1.1
// If you change this logic, update AXNodeObject::nameFromLabelElement, too.
name_from = ax::mojom::NameFrom::kAttribute;
if (name_sources) {
name_sources->push_back(
NameSource(*found_text_alternative, html_names::kAriaLabelAttr));
name_sources->back().type = name_from;
}
const AtomicString& aria_label =
GetAOMPropertyOrARIAAttribute(AOMStringProperty::kLabel);
if (!aria_label.IsEmpty()) {
text_alternative = aria_label;
if (name_sources) {
NameSource& source = name_sources->back();
source.text = text_alternative;
source.attribute_value = aria_label;
*found_text_alternative = true;
} else {
*found_text_alternative = true;
return text_alternative;
}
}
return text_alternative;
}
String AXObject::TextFromElements(
bool in_aria_labelledby_traversal,
AXObjectSet& visited,
HeapVector<Member<Element>>& elements,
AXRelatedObjectVector* related_objects) const {
StringBuilder accumulated_text;
bool found_valid_element = false;
AXRelatedObjectVector local_related_objects;
for (const auto& element : elements) {
AXObject* ax_element = AXObjectCache().GetOrCreate(element);
if (ax_element) {
found_valid_element = true;
String result = RecursiveTextAlternative(
*ax_element, in_aria_labelledby_traversal, visited);
visited.insert(ax_element);
local_related_objects.push_back(
MakeGarbageCollected<NameSourceRelatedObject>(ax_element, result));
if (!result.IsEmpty()) {
if (!accumulated_text.IsEmpty())
accumulated_text.Append(' ');
accumulated_text.Append(result);
}
}
}
if (!found_valid_element)
return String();
if (related_objects)
*related_objects = local_related_objects;
return accumulated_text.ToString();
}
void AXObject::TokenVectorFromAttribute(Vector<String>& tokens,
const QualifiedName& attribute) const {
Node* node = this->GetNode();
if (!node || !node->IsElementNode())
return;
String attribute_value = GetAttribute(attribute).GetString();
if (attribute_value.IsEmpty())
return;
attribute_value = attribute_value.SimplifyWhiteSpace();
attribute_value.Split(' ', tokens);
}
void AXObject::ElementsFromAttribute(HeapVector<Member<Element>>& elements,
const QualifiedName& attribute,
Vector<String>& ids) const {
TokenVectorFromAttribute(ids, attribute);
if (ids.IsEmpty())
return;
TreeScope& scope = GetNode()->GetTreeScope();
for (const auto& id : ids) {
if (Element* id_element = scope.getElementById(AtomicString(id)))
elements.push_back(id_element);
}
}
void AXObject::AriaLabelledbyElementVector(
HeapVector<Member<Element>>& elements,
Vector<String>& ids) const {
// Try both spellings, but prefer aria-labelledby, which is the official spec.
ElementsFromAttribute(elements, html_names::kAriaLabelledbyAttr, ids);
if (!ids.size())
ElementsFromAttribute(elements, html_names::kAriaLabeledbyAttr, ids);
}
String AXObject::TextFromAriaLabelledby(AXObjectSet& visited,
AXRelatedObjectVector* related_objects,
Vector<String>& ids) const {
HeapVector<Member<Element>> elements;
AriaLabelledbyElementVector(elements, ids);
return TextFromElements(true, visited, elements, related_objects);
}
String AXObject::TextFromAriaDescribedby(AXRelatedObjectVector* related_objects,
Vector<String>& ids) const {
AXObjectSet visited;
HeapVector<Member<Element>> elements;
ElementsFromAttribute(elements, html_names::kAriaDescribedbyAttr, ids);
return TextFromElements(true, visited, elements, related_objects);
}
RGBA32 AXObject::BackgroundColor() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_background_color_;
}
AccessibilityOrientation AXObject::Orientation() const {
// In ARIA 1.1, the default value for aria-orientation changed from
// horizontal to undefined.
return kAccessibilityOrientationUndefined;
}
void AXObject::Markers(Vector<DocumentMarker::MarkerType>&,
Vector<AXRange>&) const {}
void AXObject::TextCharacterOffsets(Vector<int>&) const {}
void AXObject::GetWordBoundaries(Vector<int>& word_starts,
Vector<int>& word_ends) const {}
ax::mojom::DefaultActionVerb AXObject::Action() const {
Element* action_element = ActionElement();
if (!action_element)
return ax::mojom::DefaultActionVerb::kNone;
// TODO(dmazzoni): Ensure that combo box text field is handled here.
if (IsTextControl())
return ax::mojom::DefaultActionVerb::kActivate;
if (IsCheckable()) {
return CheckedState() != ax::mojom::CheckedState::kTrue
? ax::mojom::DefaultActionVerb::kCheck
: ax::mojom::DefaultActionVerb::kUncheck;
}
switch (RoleValue()) {
case ax::mojom::Role::kButton:
case ax::mojom::Role::kDisclosureTriangle:
case ax::mojom::Role::kToggleButton:
return ax::mojom::DefaultActionVerb::kPress;
case ax::mojom::Role::kListBoxOption:
case ax::mojom::Role::kMenuItemRadio:
case ax::mojom::Role::kMenuItem:
case ax::mojom::Role::kMenuListOption:
return ax::mojom::DefaultActionVerb::kSelect;
case ax::mojom::Role::kLink:
return ax::mojom::DefaultActionVerb::kJump;
case ax::mojom::Role::kComboBoxMenuButton:
case ax::mojom::Role::kPopUpButton:
return ax::mojom::DefaultActionVerb::kOpen;
default:
if (action_element == GetNode())
return ax::mojom::DefaultActionVerb::kClick;
return ax::mojom::DefaultActionVerb::kClickAncestor;
}
}
bool AXObject::AriaPressedIsPresent() const {
AtomicString result;
return HasAOMPropertyOrARIAAttribute(AOMStringProperty::kPressed, result);
}
bool AXObject::AriaCheckedIsPresent() const {
AtomicString result;
return HasAOMPropertyOrARIAAttribute(AOMStringProperty::kChecked, result);
}
bool AXObject::SupportsARIAExpanded() const {
switch (RoleValue()) {
case ax::mojom::Role::kApplication:
case ax::mojom::Role::kButton:
case ax::mojom::Role::kCheckBox:
case ax::mojom::Role::kColumnHeader:
case ax::mojom::Role::kComboBoxGrouping:
case ax::mojom::Role::kComboBoxMenuButton:
case ax::mojom::Role::kDisclosureTriangle:
case ax::mojom::Role::kListBox:
case ax::mojom::Role::kLink:
case ax::mojom::Role::kPopUpButton:
case ax::mojom::Role::kMenuButton:
case ax::mojom::Role::kMenuItem:
case ax::mojom::Role::kMenuItemCheckBox:
case ax::mojom::Role::kMenuItemRadio:
case ax::mojom::Role::kRow:
case ax::mojom::Role::kRowHeader:
case ax::mojom::Role::kSwitch:
case ax::mojom::Role::kTab:
case ax::mojom::Role::kTextFieldWithComboBox:
case ax::mojom::Role::kTreeItem:
return true;
case ax::mojom::Role::kCell:
// TODO(Accessibility): aria-expanded is supported on grid cells but not
// on cells inside a static table. Consider creating separate internal
// roles so that we can easily distinguish these two types. See also
// IsSubWidget().
return true;
default:
return false;
}
}
bool IsGlobalARIAAttribute(const AtomicString& name) {
if (!name.StartsWith("ARIA"))
return false;
if (name.StartsWith("ARIA-ATOMIC"))
return true;
if (name.StartsWith("ARIA-BUSY"))
return true;
if (name.StartsWith("ARIA-CONTROLS"))
return true;
if (name.StartsWith("ARIA-CURRENT"))
return true;
if (name.StartsWith("ARIA-DESCRIBEDBY"))
return true;
if (name.StartsWith("ARIA-DETAILS"))
return true;
if (name.StartsWith("ARIA-DISABLED"))
return true;
if (name.StartsWith("ARIA-DROPEFFECT"))
return true;
if (name.StartsWith("ARIA-ERRORMESSAGE"))
return true;
if (name.StartsWith("ARIA-FLOWTO"))
return true;
if (name.StartsWith("ARIA-GRABBED"))
return true;
if (name.StartsWith("ARIA-HASPOPUP"))
return true;
if (name.StartsWith("ARIA-HIDDEN"))
return true;
if (name.StartsWith("ARIA-INVALID"))
return true;
if (name.StartsWith("ARIA-KEYSHORTCUTS"))
return true;
if (name.StartsWith("ARIA-LABEL"))
return true;
if (name.StartsWith("ARIA-LABELEDBY"))
return true;
if (name.StartsWith("ARIA-LABELLEDBY"))
return true;
if (name.StartsWith("ARIA-LIVE"))
return true;
if (name.StartsWith("ARIA-OWNS"))
return true;
if (name.StartsWith("ARIA-RELEVANT"))
return true;
if (name.StartsWith("ARIA-ROLEDESCRIPTION"))
return true;
return false;
}
bool AXObject::HasGlobalARIAAttribute() const {
auto* element = GetElement();
if (!element)
return false;
AttributeCollection attributes = element->AttributesWithoutUpdate();
for (const Attribute& attr : attributes) {
// Attributes cache their uppercase names.
auto name = attr.GetName().LocalNameUpper();
if (IsGlobalARIAAttribute(name))
return true;
}
if (!element->DidAttachInternals())
return false;
const auto& internals_attributes =
element->EnsureElementInternals().GetAttributes();
for (const QualifiedName& attr : internals_attributes.Keys()) {
if (IsGlobalARIAAttribute(attr.LocalNameUpper()))
return true;
}
return false;
}
bool AXObject::SupportsRangeValue() const {
return IsProgressIndicator() || IsMeter() || IsSlider() || IsScrollbar() ||
IsSpinButton() || IsMoveableSplitter();
}
int AXObject::IndexInParent() const {
DCHECK(AccessibilityIsIncludedInTree())
<< "IndexInParent is only valid when a node is included in the tree";
if (!ParentObjectIncludedInTree())
return 0;
const AXObjectVector& siblings = ParentObjectIncludedInTree()->Children();
wtf_size_t index = siblings.Find(this);
DCHECK(index != kNotFound);
return (index == kNotFound) ? 0 : static_cast<int>(index);
}
bool AXObject::IsLiveRegionRoot() const {
const AtomicString& live_region = LiveRegionStatus();
return !live_region.IsEmpty();
}
bool AXObject::IsActiveLiveRegionRoot() const {
const AtomicString& live_region = LiveRegionStatus();
return !live_region.IsEmpty() && !EqualIgnoringASCIICase(live_region, "off");
}
AXRestriction AXObject::Restriction() const {
// According to ARIA, all elements of the base markup can be disabled.
// According to CORE-AAM, any focusable descendant of aria-disabled
// ancestor is also disabled.
bool is_disabled;
if (HasAOMPropertyOrARIAAttribute(AOMBooleanProperty::kDisabled,
is_disabled)) {
// Has aria-disabled, overrides native markup determining disabled.
if (is_disabled)
return kRestrictionDisabled;
} else if (CanSetFocusAttribute() && IsDescendantOfDisabledNode()) {
// No aria-disabled, but other markup says it's disabled.
return kRestrictionDisabled;
}
// Check aria-readonly if supported by current role.
bool is_read_only;
if (SupportsARIAReadOnly() &&
HasAOMPropertyOrARIAAttribute(AOMBooleanProperty::kReadOnly,
is_read_only)) {
// ARIA overrides other readonly state markup.
return is_read_only ? kRestrictionReadOnly : kRestrictionNone;
}
// This is a node that is not readonly and not disabled.
return kRestrictionNone;
}
ax::mojom::Role AXObject::DetermineAccessibilityRole() {
aria_role_ = DetermineAriaRoleAttribute();
return aria_role_;
}
ax::mojom::Role AXObject::AriaRoleAttribute() const {
return aria_role_;
}
ax::mojom::Role AXObject::DetermineAriaRoleAttribute() const {
const AtomicString& aria_role =
GetAOMPropertyOrARIAAttribute(AOMStringProperty::kRole);
if (aria_role.IsNull() || aria_role.IsEmpty())
return ax::mojom::Role::kUnknown;
ax::mojom::Role role = AriaRoleToWebCoreRole(aria_role);
switch (role) {
case ax::mojom::Role::kAnnotationAttribution:
case ax::mojom::Role::kAnnotationCommentary:
case ax::mojom::Role::kAnnotationPresence:
case ax::mojom::Role::kAnnotationRevision:
case ax::mojom::Role::kAnnotationSuggestion:
UseCounter::Count(GetDocument(), WebFeature::kARIAAnnotationRoles);
if (!RuntimeEnabledFeatures::AccessibilityExposeARIAAnnotationsEnabled(
GetDocument())) {
role = ax::mojom::Role::kGenericContainer;
}
break;
default:
break;
}
// ARIA states if an item can get focus, it should not be presentational.
// It also states user agents should ignore the presentational role if
// the element has global ARIA states and properties.
if ((role == ax::mojom::Role::kNone ||
role == ax::mojom::Role::kPresentational) &&
(CanSetFocusAttribute() || HasGlobalARIAAttribute()))
return ax::mojom::Role::kUnknown;
if (role == ax::mojom::Role::kButton)
role = ButtonRoleType();
role = RemapAriaRoleDueToParent(role);
// Distinguish between different uses of the "combobox" role:
//
// ax::mojom::Role::kComboBoxGrouping:
// <div role="combobox"><input></div>
// ax::mojom::Role::kTextFieldWithComboBox:
// <input role="combobox">
// ax::mojom::Role::kComboBoxMenuButton:
// <div tabindex=0 role="combobox">Select</div>
if (role == ax::mojom::Role::kComboBoxGrouping) {
if (IsNativeTextControl())
role = ax::mojom::Role::kTextFieldWithComboBox;
else if (GetElement() && GetElement()->SupportsFocus())
role = ax::mojom::Role::kComboBoxMenuButton;
}
if (role != ax::mojom::Role::kUnknown)
return role;
return ax::mojom::Role::kUnknown;
}
ax::mojom::Role AXObject::RemapAriaRoleDueToParent(ax::mojom::Role role) const {
// Some objects change their role based on their parent.
// However, asking for the unignoredParent calls accessibilityIsIgnored(),
// which can trigger a loop. While inside the call stack of creating an
// element, we need to avoid accessibilityIsIgnored().
// https://bugs.webkit.org/show_bug.cgi?id=65174
if (role != ax::mojom::Role::kListBoxOption &&
role != ax::mojom::Role::kMenuItem)
return role;
for (AXObject* parent = ParentObject();
parent && !parent->AccessibilityIsIgnored();
parent = parent->ParentObject()) {
ax::mojom::Role parent_aria_role = parent->AriaRoleAttribute();
// Selects and listboxes both have options as child roles, but they map to
// different roles within WebCore.
if (role == ax::mojom::Role::kListBoxOption &&
parent_aria_role == ax::mojom::Role::kMenu)
return ax::mojom::Role::kMenuItem;
// An aria "menuitem" may map to MenuButton or MenuItem depending on its
// parent.
if (role == ax::mojom::Role::kMenuItem &&
parent_aria_role == ax::mojom::Role::kGroup)
return ax::mojom::Role::kMenuButton;
// If the parent had a different role, then we don't need to continue
// searching up the chain.
if (parent_aria_role != ax::mojom::Role::kUnknown)
break;
}
return role;
}
bool AXObject::IsEditableRoot() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_is_editable_root_;
}
AXObject* AXObject::LiveRegionRoot() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_live_region_root_;
}
bool AXObject::LiveRegionAtomic() const {
bool atomic = false;
if (HasAOMPropertyOrARIAAttribute(AOMBooleanProperty::kAtomic, atomic))
return atomic;
// ARIA roles "alert" and "status" should have an implicit aria-atomic value
// of true.
return RoleValue() == ax::mojom::Role::kAlert ||
RoleValue() == ax::mojom::Role::kStatus;
}
const AtomicString& AXObject::ContainerLiveRegionStatus() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_live_region_root_ ? cached_live_region_root_->LiveRegionStatus()
: g_null_atom;
}
const AtomicString& AXObject::ContainerLiveRegionRelevant() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_live_region_root_
? cached_live_region_root_->LiveRegionRelevant()
: g_null_atom;
}
bool AXObject::ContainerLiveRegionAtomic() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_live_region_root_ &&
cached_live_region_root_->LiveRegionAtomic();
}
bool AXObject::ContainerLiveRegionBusy() const {
UpdateCachedAttributeValuesIfNeeded();
return cached_live_region_root_ &&
cached_live_region_root_->AOMPropertyOrARIAAttributeIsTrue(
AOMBooleanProperty::kBusy);
}
AXObject* AXObject::ElementAccessibilityHitTest(const IntPoint& point) const {
// Check if there are any mock elements that need to be handled.
for (const auto& child : children_) {
if (child->IsMockObject() &&
child->GetBoundsInFrameCoordinates().Contains(point))
return child->ElementAccessibilityHitTest(point);
}
return const_cast<AXObject*>(this);
}
AXObject::AncestorsIterator AXObject::AncestorsBegin() {
AXObject* parent = ParentObjectUnignored();
if (parent)
return AXObject::AncestorsIterator(*parent);
return AncestorsEnd();
}
AXObject::AncestorsIterator AXObject::AncestorsEnd() {
return AXObject::AncestorsIterator();
}
AXObject::InOrderTraversalIterator AXObject::GetInOrderTraversalIterator() {
return InOrderTraversalIterator(*this);
}
int AXObject::ChildCount() const {
return HasIndirectChildren() ? 0 : static_cast<int>(Children().size());
}
const AXObject::AXObjectVector& AXObject::Children() const {
return const_cast<AXObject*>(this)->Children();
}
const AXObject::AXObjectVector& AXObject::Children() {
UpdateChildrenIfNecessary();
return children_;
}
AXObject* AXObject::FirstChild() const {
return ChildCount() ? *Children().begin() : nullptr;
}
AXObject* AXObject::LastChild() const {
return ChildCount() ? *(Children().end() - 1) : nullptr;
}
AXObject* AXObject::DeepestFirstChild() const {
if (!ChildCount())
return nullptr;
AXObject* deepest_child = FirstChild();
while (deepest_child->ChildCount())
deepest_child = deepest_child->FirstChild();
return deepest_child;
}
AXObject* AXObject::DeepestLastChild() const {
if (!ChildCount())
return nullptr;
AXObject* deepest_child = LastChild();
while (deepest_child->ChildCount())
deepest_child = deepest_child->LastChild();
return deepest_child;
}
bool AXObject::IsAncestorOf(const AXObject& descendant) const {
return descendant.IsDescendantOf(*this);
}
bool AXObject::IsDescendantOf(const AXObject& ancestor) const {
const AXObject* parent = ParentObject();
while (parent && parent != &ancestor)
parent = parent->ParentObject();
return !!parent;
}
AXObject* AXObject::NextSiblingIncludingIgnored() const {
if (!AccessibilityIsIncludedInTree()) {
NOTREACHED() << "We don't support iterating over objects excluded "
"from the accessibility tree";
return nullptr;
}
const AXObject* parent_in_tree = ParentObjectIncludedInTree();
if (!parent_in_tree)
return nullptr;
const int index_in_parent = IndexInParent();
if (index_in_parent < parent_in_tree->ChildCount() - 1)
return *(parent_in_tree->Children().begin() + index_in_parent + 1);
return nullptr;
}
AXObject* AXObject::PreviousSiblingIncludingIgnored() const {
if (!AccessibilityIsIncludedInTree()) {
NOTREACHED() << "We don't support iterating over objects excluded "
"from the accessibility tree";
return nullptr;
}
const AXObject* parent_in_tree = ParentObjectIncludedInTree();
if (!parent_in_tree)
return nullptr;
const int index_in_parent = IndexInParent();
if (index_in_parent > 0)
return *(parent_in_tree->Children().begin() + index_in_parent - 1);
return nullptr;
}
AXObject* AXObject::NextInPreOrderIncludingIgnored(
const AXObject* within) const {
if (!AccessibilityIsIncludedInTree()) {
NOTREACHED() << "We don't support iterating over objects excluded "
"from the accessibility tree";
return nullptr;
}
if (ChildCount())
return FirstChild();
if (within == this)
return nullptr;
const AXObject* current = this;
AXObject* next = current->NextSiblingIncludingIgnored();
for (; !next; next = current->NextSiblingIncludingIgnored()) {
current = current->ParentObjectIncludedInTree();
if (!current || within == current)
return nullptr;
}
return next;
}
AXObject* AXObject::PreviousInPreOrderIncludingIgnored(
const AXObject* within) const {
if (!AccessibilityIsIncludedInTree()) {
NOTREACHED() << "We don't support iterating over objects excluded "
"from the accessibility tree";
return nullptr;
}
if (within == this)
return nullptr;
if (AXObject* sibling = PreviousSiblingIncludingIgnored()) {
if (sibling->ChildCount())
return sibling->DeepestLastChild();
return sibling;
}
return ParentObjectIncludedInTree();
}
AXObject* AXObject::PreviousInPostOrderIncludingIgnored(
const AXObject* within) const {
if (!AccessibilityIsIncludedInTree()) {
NOTREACHED() << "We don't support iterating over objects excluded "
"from the accessibility tree";
return nullptr;
}
if (ChildCount())
return LastChild();
if (within == this)
return nullptr;
const AXObject* current = this;
AXObject* previous = current->PreviousSiblingIncludingIgnored();
for (; !previous; previous = current->PreviousSiblingIncludingIgnored()) {
current = current->ParentObjectIncludedInTree();
if (!current || within == current)
return nullptr;
}
return previous;
}
AXObject* AXObject::NextSibling() const {
if (AccessibilityIsIgnored()) {
NOTREACHED() << "We don't support finding siblings for ignored objects.";
return nullptr;
}
// Find the next sibling for the same unignored parent object,
// flattening accessibility ignored objects.
//
// For example :
// ++A
// ++++B
// ++++C IGNORED
// ++++++E
// ++++D
// Objects [B, E, D] will be siblings since C is ignored.
const AXObject* unignored_parent = ParentObjectUnignored();
const AXObject* current_obj = this;
while (current_obj) {
AXObject* sibling = current_obj->NextSiblingIncludingIgnored();
if (sibling) {
// If we found an ignored sibling, walk in next pre-order
// until an unignored object is found, flattening the ignored object.
while (sibling && sibling->AccessibilityIsIgnored()) {
sibling = sibling->NextInPreOrderIncludingIgnored(unignored_parent);
}
return sibling;
}
// If a sibling has not been found, try again with the parent object,
// until the unignored parent is reached.
current_obj = current_obj->ParentObjectIncludedInTree();
if (!current_obj || !current_obj->AccessibilityIsIgnored())
return nullptr;
}
return nullptr;
}
AXObject* AXObject::PreviousSibling() const {
if (AccessibilityIsIgnored()) {
NOTREACHED() << "We don't support finding siblings for ignored objects.";
return nullptr;
}
// Find the previous sibling for the same unignored parent object,
// flattening accessibility ignored objects.
//
// For example :
// ++A
// ++++B
// ++++C IGNORED
// ++++++E
// ++++D
// Objects [B, E, D] will be siblings since C is ignored.
const AXObject* current_obj = this;
while (current_obj) {
AXObject* sibling = current_obj->PreviousSiblingIncludingIgnored();
if (sibling) {
const AXObject* unignored_parent = ParentObjectUnignored();
// If we found an ignored sibling, walk in previous post-order
// until an unignored object is found, flattening the ignored object.
while (sibling && sibling->AccessibilityIsIgnored()) {
sibling =