2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "AccessibilityRenderObject.h"
32 #include "AXObjectCache.h"
33 #include "AccessibilityImageMapLink.h"
34 #include "AccessibilityListBox.h"
35 #include "AccessibilitySVGRoot.h"
36 #include "AccessibilitySpinButton.h"
37 #include "AccessibilityTable.h"
38 #include "CachedImage.h"
40 #include "ElementIterator.h"
41 #include "EventNames.h"
42 #include "FloatRect.h"
44 #include "FrameLoader.h"
45 #include "FrameSelection.h"
46 #include "HTMLAreaElement.h"
47 #include "HTMLAudioElement.h"
48 #include "HTMLFormElement.h"
49 #include "HTMLFrameElementBase.h"
50 #include "HTMLImageElement.h"
51 #include "HTMLInputElement.h"
52 #include "HTMLLabelElement.h"
53 #include "HTMLMapElement.h"
54 #include "HTMLNames.h"
55 #include "HTMLOptGroupElement.h"
56 #include "HTMLOptionElement.h"
57 #include "HTMLOptionsCollection.h"
58 #include "HTMLSelectElement.h"
59 #include "HTMLTableElement.h"
60 #include "HTMLTextAreaElement.h"
61 #include "HTMLVideoElement.h"
62 #include "HitTestRequest.h"
63 #include "HitTestResult.h"
65 #include "LocalizedStrings.h"
66 #include "MathMLNames.h"
69 #include "ProgressTracker.h"
70 #include "RenderButton.h"
71 #include "RenderFieldset.h"
72 #include "RenderFileUploadControl.h"
73 #include "RenderHTMLCanvas.h"
74 #include "RenderImage.h"
75 #include "RenderInline.h"
76 #include "RenderIterator.h"
77 #include "RenderLayer.h"
78 #include "RenderLineBreak.h"
79 #include "RenderListBox.h"
80 #include "RenderListItem.h"
81 #include "RenderListMarker.h"
82 #include "RenderMathMLBlock.h"
83 #include "RenderMathMLFraction.h"
84 #include "RenderMathMLOperator.h"
85 #include "RenderMathMLRoot.h"
86 #include "RenderMenuList.h"
87 #include "RenderSVGRoot.h"
88 #include "RenderSVGShape.h"
89 #include "RenderText.h"
90 #include "RenderTextControl.h"
91 #include "RenderTextControlSingleLine.h"
92 #include "RenderTextFragment.h"
93 #include "RenderTheme.h"
94 #include "RenderView.h"
95 #include "RenderWidget.h"
96 #include "RenderedPosition.h"
97 #include "SVGDocument.h"
100 #include "SVGSVGElement.h"
102 #include "TextControlInnerElements.h"
103 #include "TextIterator.h"
104 #include "VisibleUnits.h"
105 #include "htmlediting.h"
106 #include <wtf/NeverDestroyed.h>
107 #include <wtf/StdLibExtras.h>
108 #include <wtf/text/StringBuilder.h>
109 #include <wtf/unicode/CharacterNames.h>
113 using namespace HTMLNames;
115 AccessibilityRenderObject::AccessibilityRenderObject(RenderObject* renderer)
116 : AccessibilityNodeObject(renderer->node())
117 , m_renderer(renderer)
120 m_renderer->setHasAXObject(true);
124 AccessibilityRenderObject::~AccessibilityRenderObject()
126 ASSERT(isDetached());
129 void AccessibilityRenderObject::init()
131 AccessibilityNodeObject::init();
134 Ref<AccessibilityRenderObject> AccessibilityRenderObject::create(RenderObject* renderer)
136 return adoptRef(*new AccessibilityRenderObject(renderer));
139 void AccessibilityRenderObject::detach(AccessibilityDetachmentType detachmentType, AXObjectCache* cache)
141 AccessibilityNodeObject::detach(detachmentType, cache);
143 detachRemoteSVGRoot();
147 m_renderer->setHasAXObject(false);
149 m_renderer = nullptr;
152 RenderBoxModelObject* AccessibilityRenderObject::renderBoxModelObject() const
154 if (!is<RenderBoxModelObject>(m_renderer))
156 return downcast<RenderBoxModelObject>(m_renderer);
159 void AccessibilityRenderObject::setRenderer(RenderObject* renderer)
161 m_renderer = renderer;
162 setNode(renderer->node());
165 static inline bool isInlineWithContinuation(RenderObject& object)
167 return is<RenderInline>(object) && downcast<RenderInline>(object).continuation();
170 static inline RenderObject* firstChildInContinuation(RenderInline& renderer)
172 auto continuation = renderer.continuation();
174 while (continuation) {
175 if (is<RenderBlock>(*continuation))
177 if (RenderObject* child = continuation->firstChild())
179 continuation = downcast<RenderInline>(*continuation).continuation();
185 static inline RenderObject* firstChildConsideringContinuation(RenderObject& renderer)
187 RenderObject* firstChild = renderer.firstChildSlow();
189 if (!firstChild && isInlineWithContinuation(renderer))
190 firstChild = firstChildInContinuation(downcast<RenderInline>(renderer));
196 static inline RenderObject* lastChildConsideringContinuation(RenderObject& renderer)
198 if (!is<RenderInline>(renderer) && !is<RenderBlock>(renderer))
201 RenderObject* lastChild = downcast<RenderBoxModelObject>(renderer).lastChild();
202 RenderBoxModelObject* previous;
203 for (auto* current = &downcast<RenderBoxModelObject>(renderer); current; ) {
206 if (RenderObject* newLastChild = current->lastChild())
207 lastChild = newLastChild;
209 if (is<RenderInline>(*current)) {
210 current = downcast<RenderInline>(*current).inlineElementContinuation();
211 ASSERT_UNUSED(previous, current || !downcast<RenderInline>(*previous).continuation());
213 current = downcast<RenderBlock>(*current).inlineElementContinuation();
219 AccessibilityObject* AccessibilityRenderObject::firstChild() const
224 RenderObject* firstChild = firstChildConsideringContinuation(*m_renderer);
226 // If an object can't have children, then it is using this method to help
227 // calculate some internal property (like its description).
228 // In this case, it should check the Node level for children in case they're
229 // not rendered (like a <meter> element).
230 if (!firstChild && !canHaveChildren())
231 return AccessibilityNodeObject::firstChild();
233 return axObjectCache()->getOrCreate(firstChild);
236 AccessibilityObject* AccessibilityRenderObject::lastChild() const
241 RenderObject* lastChild = lastChildConsideringContinuation(*m_renderer);
243 if (!lastChild && !canHaveChildren())
244 return AccessibilityNodeObject::lastChild();
246 return axObjectCache()->getOrCreate(lastChild);
249 static inline RenderInline* startOfContinuations(RenderObject& renderer)
251 if (renderer.isInlineElementContinuation() && is<RenderInline>(renderer.node()->renderer()))
252 return downcast<RenderInline>(renderer.node()->renderer());
254 // Blocks with a previous continuation always have a next continuation
255 if (is<RenderBlock>(renderer) && downcast<RenderBlock>(renderer).inlineElementContinuation())
256 return downcast<RenderInline>(downcast<RenderBlock>(renderer).inlineElementContinuation()->element()->renderer());
261 static inline RenderObject* endOfContinuations(RenderObject& renderer)
263 if (!is<RenderInline>(renderer) && !is<RenderBlock>(renderer))
266 auto* previous = &downcast<RenderBoxModelObject>(renderer);
267 for (auto* current = previous; current; ) {
269 if (is<RenderInline>(*current)) {
270 current = downcast<RenderInline>(*current).inlineElementContinuation();
271 ASSERT(current || !downcast<RenderInline>(*previous).continuation());
273 current = downcast<RenderBlock>(*current).inlineElementContinuation();
280 static inline RenderObject* childBeforeConsideringContinuations(RenderInline* renderer, RenderObject* child)
282 RenderObject* previous = nullptr;
283 for (RenderBoxModelObject* currentContainer = renderer; currentContainer; ) {
284 if (is<RenderInline>(*currentContainer)) {
285 auto* current = currentContainer->firstChild();
287 if (current == child)
290 current = current->nextSibling();
293 currentContainer = downcast<RenderInline>(*currentContainer).continuation();
294 } else if (is<RenderBlock>(*currentContainer)) {
295 if (currentContainer == child)
298 previous = currentContainer;
299 currentContainer = downcast<RenderBlock>(*currentContainer).inlineElementContinuation();
303 ASSERT_NOT_REACHED();
307 static inline bool firstChildIsInlineContinuation(RenderElement& renderer)
309 RenderObject* child = renderer.firstChild();
310 return child && child->isInlineElementContinuation();
313 AccessibilityObject* AccessibilityRenderObject::previousSibling() const
318 RenderObject* previousSibling = nullptr;
320 // Case 1: The node is a block and is an inline's continuation. In that case, the inline's
321 // last child is our previous sibling (or further back in the continuation chain)
322 RenderInline* startOfConts;
323 if (is<RenderBox>(*m_renderer) && (startOfConts = startOfContinuations(*m_renderer)))
324 previousSibling = childBeforeConsideringContinuations(startOfConts, m_renderer);
326 // Case 2: Anonymous block parent of the end of a continuation - skip all the way to before
327 // the parent of the start, since everything in between will be linked up via the continuation.
328 else if (m_renderer->isAnonymousBlock() && firstChildIsInlineContinuation(downcast<RenderBlock>(*m_renderer))) {
329 RenderBlock& renderBlock = downcast<RenderBlock>(*m_renderer);
330 auto* firstParent = startOfContinuations(*renderBlock.firstChild())->parent();
332 while (firstChildIsInlineContinuation(*firstParent))
333 firstParent = startOfContinuations(*firstParent->firstChild())->parent();
334 previousSibling = firstParent->previousSibling();
337 // Case 3: The node has an actual previous sibling
338 else if (RenderObject* ps = m_renderer->previousSibling())
339 previousSibling = ps;
341 // Case 4: This node has no previous siblings, but its parent is an inline,
342 // and is another node's inline continutation. Follow the continuation chain.
343 else if (is<RenderInline>(*m_renderer->parent()) && (startOfConts = startOfContinuations(*m_renderer->parent())))
344 previousSibling = childBeforeConsideringContinuations(startOfConts, m_renderer->parent()->firstChild());
346 if (!previousSibling)
349 return axObjectCache()->getOrCreate(previousSibling);
352 static inline bool lastChildHasContinuation(RenderElement& renderer)
354 RenderObject* child = renderer.lastChild();
355 return child && isInlineWithContinuation(*child);
358 AccessibilityObject* AccessibilityRenderObject::nextSibling() const
363 RenderObject* nextSibling = nullptr;
365 // Case 1: node is a block and has an inline continuation. Next sibling is the inline continuation's
367 RenderInline* inlineContinuation;
368 if (is<RenderBlock>(*m_renderer) && (inlineContinuation = downcast<RenderBlock>(*m_renderer).inlineElementContinuation()))
369 nextSibling = firstChildConsideringContinuation(*inlineContinuation);
371 // Case 2: Anonymous block parent of the start of a continuation - skip all the way to
372 // after the parent of the end, since everything in between will be linked up via the continuation.
373 else if (m_renderer->isAnonymousBlock() && lastChildHasContinuation(downcast<RenderBlock>(*m_renderer))) {
374 RenderElement* lastParent = endOfContinuations(*downcast<RenderBlock>(*m_renderer).lastChild())->parent();
376 while (lastChildHasContinuation(*lastParent))
377 lastParent = endOfContinuations(*lastParent->lastChild())->parent();
378 nextSibling = lastParent->nextSibling();
381 // Case 3: node has an actual next sibling
382 else if (RenderObject* ns = m_renderer->nextSibling())
385 // Case 4: node is an inline with a continuation. Next sibling is the next sibling of the end
386 // of the continuation chain.
387 else if (isInlineWithContinuation(*m_renderer))
388 nextSibling = endOfContinuations(*m_renderer)->nextSibling();
390 // Case 5: node has no next sibling, and its parent is an inline with a continuation.
391 else if (isInlineWithContinuation(*m_renderer->parent())) {
392 auto& continuation = *downcast<RenderInline>(*m_renderer->parent()).continuation();
394 // Case 5a: continuation is a block - in this case the block itself is the next sibling.
395 if (is<RenderBlock>(continuation))
396 nextSibling = &continuation;
397 // Case 5b: continuation is an inline - in this case the inline's first child is the next sibling
399 nextSibling = firstChildConsideringContinuation(continuation);
405 return axObjectCache()->getOrCreate(nextSibling);
408 static RenderBoxModelObject* nextContinuation(RenderObject& renderer)
410 if (is<RenderInline>(renderer) && !renderer.isReplaced())
411 return downcast<RenderInline>(renderer).continuation();
412 if (is<RenderBlock>(renderer))
413 return downcast<RenderBlock>(renderer).inlineElementContinuation();
417 RenderObject* AccessibilityRenderObject::renderParentObject() const
422 RenderElement* parent = m_renderer->parent();
424 // Case 1: node is a block and is an inline's continuation. Parent
425 // is the start of the continuation chain.
426 RenderInline* startOfConts = nullptr;
427 RenderObject* firstChild = nullptr;
428 if (is<RenderBlock>(*m_renderer) && (startOfConts = startOfContinuations(*m_renderer)))
429 parent = startOfConts;
431 // Case 2: node's parent is an inline which is some node's continuation; parent is
432 // the earliest node in the continuation chain.
433 else if (is<RenderInline>(parent) && (startOfConts = startOfContinuations(*parent)))
434 parent = startOfConts;
436 // Case 3: The first sibling is the beginning of a continuation chain. Find the origin of that continuation.
437 else if (parent && (firstChild = parent->firstChild()) && firstChild->node()) {
438 // Get the node's renderer and follow that continuation chain until the first child is found
439 RenderObject* nodeRenderFirstChild = firstChild->node()->renderer();
440 while (nodeRenderFirstChild != firstChild) {
441 for (RenderObject* contsTest = nodeRenderFirstChild; contsTest; contsTest = nextContinuation(*contsTest)) {
442 if (contsTest == firstChild) {
443 parent = nodeRenderFirstChild->parent();
447 RenderObject* parentFirstChild = parent->firstChild();
448 if (firstChild == parentFirstChild)
450 firstChild = parentFirstChild;
451 if (!firstChild->node())
453 nodeRenderFirstChild = firstChild->node()->renderer();
460 AccessibilityObject* AccessibilityRenderObject::parentObjectIfExists() const
462 AXObjectCache* cache = axObjectCache();
466 // WebArea's parent should be the scroll view containing it.
468 return cache->get(&m_renderer->view().frameView());
470 return cache->get(renderParentObject());
473 AccessibilityObject* AccessibilityRenderObject::parentObject() const
478 if (ariaRoleAttribute() == MenuBarRole)
479 return axObjectCache()->getOrCreate(m_renderer->parent());
481 // menuButton and its corresponding menu are DOM siblings, but Accessibility needs them to be parent/child
482 if (ariaRoleAttribute() == MenuRole) {
483 AccessibilityObject* parent = menuButtonForMenu();
488 AXObjectCache* cache = axObjectCache();
492 RenderObject* parentObj = renderParentObject();
494 return cache->getOrCreate(parentObj);
496 // WebArea's parent should be the scroll view containing it.
498 return cache->getOrCreate(&m_renderer->view().frameView());
503 bool AccessibilityRenderObject::isAttachment() const
505 RenderBoxModelObject* renderer = renderBoxModelObject();
508 // Widgets are the replaced elements that we represent to AX as attachments
509 bool isWidget = renderer->isWidget();
511 return isWidget && ariaRoleAttribute() == UnknownRole;
514 bool AccessibilityRenderObject::isFileUploadButton() const
516 if (m_renderer && is<HTMLInputElement>(m_renderer->node())) {
517 HTMLInputElement& input = downcast<HTMLInputElement>(*m_renderer->node());
518 return input.isFileUpload();
524 bool AccessibilityRenderObject::isReadOnly() const
529 if (HTMLElement* body = m_renderer->document().bodyOrFrameset()) {
530 if (body->hasEditableStyle())
534 return !m_renderer->document().hasEditableStyle();
537 return AccessibilityNodeObject::isReadOnly();
540 bool AccessibilityRenderObject::isOffScreen() const
543 IntRect contentRect = snappedIntRect(m_renderer->absoluteClippedOverflowRect());
544 // FIXME: unclear if we need LegacyIOSDocumentVisibleRect.
545 IntRect viewRect = m_renderer->view().frameView().visibleContentRect(ScrollableArea::LegacyIOSDocumentVisibleRect);
546 viewRect.intersect(contentRect);
547 return viewRect.isEmpty();
550 Element* AccessibilityRenderObject::anchorElement() const
555 AXObjectCache* cache = axObjectCache();
559 RenderObject* currentRenderer;
561 // Search up the render tree for a RenderObject with a DOM node. Defer to an earlier continuation, though.
562 for (currentRenderer = m_renderer; currentRenderer && !currentRenderer->node(); currentRenderer = currentRenderer->parent()) {
563 if (currentRenderer->isAnonymousBlock()) {
564 if (RenderObject* continuation = downcast<RenderBlock>(*currentRenderer).continuation())
565 return cache->getOrCreate(continuation)->anchorElement();
569 // bail if none found
570 if (!currentRenderer)
573 // search up the DOM tree for an anchor element
574 // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElement
575 for (Node* node = currentRenderer->node(); node; node = node->parentNode()) {
576 if (is<HTMLAnchorElement>(*node) || (node->renderer() && cache->getOrCreate(node->renderer())->isLink()))
577 return downcast<Element>(node);
583 String AccessibilityRenderObject::helpText() const
588 const AtomicString& ariaHelp = getAttribute(aria_helpAttr);
589 if (!ariaHelp.isEmpty())
592 String describedBy = ariaDescribedByAttribute();
593 if (!describedBy.isEmpty())
596 String description = accessibilityDescription();
597 for (RenderObject* ancestor = m_renderer; ancestor; ancestor = ancestor->parent()) {
598 if (is<HTMLElement>(ancestor->node())) {
599 HTMLElement& element = downcast<HTMLElement>(*ancestor->node());
600 const AtomicString& summary = element.getAttribute(summaryAttr);
601 if (!summary.isEmpty())
604 // The title attribute should be used as help text unless it is already being used as descriptive text.
605 const AtomicString& title = element.getAttribute(titleAttr);
606 if (!title.isEmpty() && description != title)
610 // Only take help text from an ancestor element if its a group or an unknown role. If help was
611 // added to those kinds of elements, it is likely it was meant for a child element.
612 AccessibilityObject* axObj = axObjectCache()->getOrCreate(ancestor);
614 AccessibilityRole role = axObj->roleValue();
615 if (role != GroupRole && role != UnknownRole)
623 String AccessibilityRenderObject::textUnderElement(AccessibilityTextUnderElementMode mode) const
628 if (is<RenderFileUploadControl>(*m_renderer))
629 return downcast<RenderFileUploadControl>(*m_renderer).buttonValue();
631 // Reflect when a content author has explicitly marked a line break.
632 if (m_renderer->isBR())
633 return ASCIILiteral("\n");
636 // Math operators create RenderText nodes on the fly that are not tied into the DOM in a reasonable way,
637 // so rangeOfContents does not work for them (nor does regular text selection).
638 if (is<RenderText>(*m_renderer) && m_renderer->isAnonymous() && ancestorsOfType<RenderMathMLOperator>(*m_renderer).first())
639 return downcast<RenderText>(*m_renderer).text();
640 if (is<RenderMathMLOperator>(*m_renderer) && !m_renderer->isAnonymous())
641 return downcast<RenderMathMLOperator>(*m_renderer).element().textContent();
644 // rangeOfContents does not include CSS-generated content.
645 if (m_renderer->isBeforeOrAfterContent())
646 return AccessibilityNodeObject::textUnderElement(mode);
648 // We use a text iterator for text objects AND for those cases where we are
649 // explicitly asking for the full text under a given element.
650 if (is<RenderText>(*m_renderer) || mode.childrenInclusion == AccessibilityTextUnderElementMode::TextUnderElementModeIncludeAllChildren) {
651 // If possible, use a text iterator to get the text, so that whitespace
652 // is handled consistently.
653 Document* nodeDocument = nullptr;
654 RefPtr<Range> textRange;
655 if (Node* node = m_renderer->node()) {
656 // rangeOfContents does not include CSS-generated content.
657 Node* firstChild = node->pseudoAwareFirstChild();
658 Node* lastChild = node->pseudoAwareLastChild();
659 if ((firstChild && firstChild->isPseudoElement()) || (lastChild && lastChild->isPseudoElement()))
660 return AccessibilityNodeObject::textUnderElement(mode);
662 nodeDocument = &node->document();
663 textRange = rangeOfContents(*node);
665 // For anonymous blocks, we work around not having a direct node to create a range from
666 // defining one based in the two external positions defining the boundaries of the subtree.
667 RenderObject* firstChildRenderer = m_renderer->firstChildSlow();
668 RenderObject* lastChildRenderer = m_renderer->lastChildSlow();
669 if (firstChildRenderer && lastChildRenderer) {
670 ASSERT(firstChildRenderer->node());
671 ASSERT(lastChildRenderer->node());
673 // We define the start and end positions for the range as the ones right before and after
674 // the first and the last nodes in the DOM tree that is wrapped inside the anonymous block.
675 Node* firstNodeInBlock = firstChildRenderer->node();
676 Position startPosition = positionInParentBeforeNode(firstNodeInBlock);
677 Position endPosition = positionInParentAfterNode(lastChildRenderer->node());
679 nodeDocument = &firstNodeInBlock->document();
680 textRange = Range::create(*nodeDocument, startPosition, endPosition);
684 if (nodeDocument && textRange) {
685 if (Frame* frame = nodeDocument->frame()) {
686 // catch stale WebCoreAXObject (see <rdar://problem/3960196>)
687 if (frame->document() != nodeDocument)
689 return plainText(textRange.get(), textIteratorBehaviorForTextRange());
693 // Sometimes text fragments don't have Nodes associated with them (like when
694 // CSS content is used to insert text or when a RenderCounter is used.)
695 if (is<RenderText>(*m_renderer)) {
696 RenderText& renderTextObject = downcast<RenderText>(*m_renderer);
697 if (is<RenderTextFragment>(renderTextObject)) {
698 RenderTextFragment& renderTextFragment = downcast<RenderTextFragment>(renderTextObject);
699 // The alt attribute may be set on a text fragment through CSS, which should be honored.
700 const String& altText = renderTextFragment.altText();
701 if (!altText.isEmpty())
703 return renderTextFragment.contentString();
706 return renderTextObject.text();
710 return AccessibilityNodeObject::textUnderElement(mode);
713 Node* AccessibilityRenderObject::node() const
717 if (m_renderer->isRenderView())
718 return &m_renderer->document();
719 return m_renderer->node();
722 String AccessibilityRenderObject::stringValue() const
727 if (isPasswordField())
728 return passwordFieldValue();
730 RenderBoxModelObject* cssBox = renderBoxModelObject();
732 if (ariaRoleAttribute() == StaticTextRole) {
733 String staticText = text();
734 if (!staticText.length())
735 staticText = textUnderElement();
739 if (is<RenderText>(*m_renderer))
740 return textUnderElement();
742 if (is<RenderMenuList>(cssBox)) {
743 // RenderMenuList will go straight to the text() of its selected item.
744 // This has to be overridden in the case where the selected item has an ARIA label.
745 HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*m_renderer->node());
746 int selectedIndex = selectElement.selectedIndex();
747 const Vector<HTMLElement*>& listItems = selectElement.listItems();
748 if (selectedIndex >= 0 && static_cast<size_t>(selectedIndex) < listItems.size()) {
749 const AtomicString& overriddenDescription = listItems[selectedIndex]->fastGetAttribute(aria_labelAttr);
750 if (!overriddenDescription.isNull())
751 return overriddenDescription;
753 return downcast<RenderMenuList>(*m_renderer).text();
756 if (is<RenderListMarker>(*m_renderer))
757 return downcast<RenderListMarker>(*m_renderer).text();
765 if (is<RenderFileUploadControl>(*m_renderer))
766 return downcast<RenderFileUploadControl>(*m_renderer).fileTextValue();
768 // FIXME: We might need to implement a value here for more types
769 // FIXME: It would be better not to advertise a value at all for the types for which we don't implement one;
770 // this would require subclassing or making accessibilityAttributeNames do something other than return a
771 // single static array.
775 HTMLLabelElement* AccessibilityRenderObject::labelElementContainer() const
780 // the control element should not be considered part of the label
784 // find if this has a parent that is a label
785 for (Node* parentNode = m_renderer->node(); parentNode; parentNode = parentNode->parentNode()) {
786 if (is<HTMLLabelElement>(*parentNode))
787 return downcast<HTMLLabelElement>(parentNode);
793 // The boundingBox for elements within the remote SVG element needs to be offset by its position
794 // within the parent page, otherwise they are in relative coordinates only.
795 void AccessibilityRenderObject::offsetBoundingBoxForRemoteSVGElement(LayoutRect& rect) const
797 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
798 if (parent->isAccessibilitySVGRoot()) {
799 rect.moveBy(parent->parentObject()->boundingBoxRect().location());
805 LayoutRect AccessibilityRenderObject::boundingBoxRect() const
807 RenderObject* obj = m_renderer;
812 if (obj->node()) // If we are a continuation, we want to make sure to use the primary renderer.
813 obj = obj->node()->renderer();
815 // absoluteFocusRingQuads will query the hierarchy below this element, which for large webpages can be very slow.
816 // For a web area, which will have the most elements of any element, absoluteQuads should be used.
817 // We should also use absoluteQuads for SVG elements, otherwise transforms won't be applied.
818 Vector<FloatQuad> quads;
819 bool isSVGRoot = false;
821 if (obj->isSVGRoot())
824 if (is<RenderText>(*obj))
825 quads = downcast<RenderText>(*obj).absoluteQuadsClippedToEllipsis();
826 else if (isWebArea() || isSVGRoot)
827 obj->absoluteQuads(quads);
829 obj->absoluteFocusRingQuads(quads);
831 LayoutRect result = boundingBoxForQuads(obj, quads);
833 Document* document = this->document();
834 if (document && document->isSVGDocument())
835 offsetBoundingBoxForRemoteSVGElement(result);
837 // The size of the web area should be the content size, not the clipped size.
839 result.setSize(obj->view().frameView().contentsSize());
844 LayoutRect AccessibilityRenderObject::checkboxOrRadioRect() const
849 HTMLLabelElement* label = labelForElement(downcast<Element>(m_renderer->node()));
850 if (!label || !label->renderer())
851 return boundingBoxRect();
853 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementRect();
854 labelRect.unite(boundingBoxRect());
858 LayoutRect AccessibilityRenderObject::elementRect() const
860 // a checkbox or radio button should encompass its label
861 if (isCheckboxOrRadio())
862 return checkboxOrRadioRect();
864 return boundingBoxRect();
867 bool AccessibilityRenderObject::supportsPath() const
869 return is<RenderSVGShape>(m_renderer);
872 Path AccessibilityRenderObject::elementPath() const
874 if (is<RenderSVGShape>(m_renderer) && downcast<RenderSVGShape>(*m_renderer).hasPath()) {
875 Path path = downcast<RenderSVGShape>(*m_renderer).path();
877 // The SVG path is in terms of the parent's bounding box. The path needs to be offset to frame coordinates.
878 if (auto svgRoot = ancestorsOfType<RenderSVGRoot>(*m_renderer).first()) {
879 LayoutPoint parentOffset = axObjectCache()->getOrCreate(&*svgRoot)->elementRect().location();
880 path.transform(AffineTransform().translate(parentOffset.x(), parentOffset.y()));
889 IntPoint AccessibilityRenderObject::clickPoint()
891 // Headings are usually much wider than their textual content. If the mid point is used, often it can be wrong.
892 if (isHeading() && children().size() == 1)
893 return children()[0]->clickPoint();
895 // use the default position unless this is an editable web area, in which case we use the selection bounds.
896 if (!isWebArea() || isReadOnly())
897 return AccessibilityObject::clickPoint();
899 VisibleSelection visSelection = selection();
900 VisiblePositionRange range = VisiblePositionRange(visSelection.visibleStart(), visSelection.visibleEnd());
901 IntRect bounds = boundsForVisiblePositionRange(range);
903 bounds.setLocation(m_renderer->view().frameView().screenToContents(bounds.location()));
905 return IntPoint(bounds.x() + (bounds.width() / 2), bounds.y() - (bounds.height() / 2));
908 AccessibilityObject* AccessibilityRenderObject::internalLinkElement() const
910 Element* element = anchorElement();
911 // Right now, we do not support ARIA links as internal link elements
912 if (!is<HTMLAnchorElement>(element))
914 HTMLAnchorElement& anchor = downcast<HTMLAnchorElement>(*element);
916 URL linkURL = anchor.href();
917 String fragmentIdentifier = linkURL.fragmentIdentifier();
918 if (fragmentIdentifier.isEmpty())
921 // check if URL is the same as current URL
922 URL documentURL = m_renderer->document().url();
923 if (!equalIgnoringFragmentIdentifier(documentURL, linkURL))
926 Node* linkedNode = m_renderer->document().findAnchor(fragmentIdentifier);
930 // The element we find may not be accessible, so find the first accessible object.
931 return firstAccessibleObjectFromNode(linkedNode);
934 ESpeak AccessibilityRenderObject::speakProperty() const
937 return AccessibilityObject::speakProperty();
939 return m_renderer->style().speak();
942 void AccessibilityRenderObject::addRadioButtonGroupMembers(AccessibilityChildrenVector& linkedUIElements) const
944 if (!m_renderer || roleValue() != RadioButtonRole)
947 Node* node = m_renderer->node();
948 if (!is<HTMLInputElement>(node))
951 HTMLInputElement& input = downcast<HTMLInputElement>(*node);
952 // if there's a form, then this is easy
954 for (auto& associateElement : input.form()->namedElements(input.name())) {
955 if (AccessibilityObject* object = axObjectCache()->getOrCreate(&associateElement.get()))
956 linkedUIElements.append(object);
959 RefPtr<NodeList> list = node->document().getElementsByTagName(inputTag.localName());
960 unsigned length = list->length();
961 for (unsigned i = 0; i < length; ++i) {
962 Node* item = list->item(i);
963 if (is<HTMLInputElement>(*item)) {
964 HTMLInputElement& associateElement = downcast<HTMLInputElement>(*item);
965 if (associateElement.isRadioButton() && associateElement.name() == input.name()) {
966 if (AccessibilityObject* object = axObjectCache()->getOrCreate(&associateElement))
967 linkedUIElements.append(object);
974 // linked ui elements could be all the related radio buttons in a group
975 // or an internal anchor connection
976 void AccessibilityRenderObject::linkedUIElements(AccessibilityChildrenVector& linkedUIElements) const
978 ariaFlowToElements(linkedUIElements);
981 AccessibilityObject* linkedAXElement = internalLinkElement();
983 linkedUIElements.append(linkedAXElement);
986 if (roleValue() == RadioButtonRole)
987 addRadioButtonGroupMembers(linkedUIElements);
990 bool AccessibilityRenderObject::hasTextAlternative() const
992 // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
993 // override the "label" element association.
994 return ariaAccessibilityDescription().length();
997 bool AccessibilityRenderObject::ariaHasPopup() const
999 return elementAttributeValue(aria_haspopupAttr);
1002 void AccessibilityRenderObject::ariaElementsFromAttribute(AccessibilityChildrenVector& children, const QualifiedName& attributeName) const
1004 Vector<Element*> elements;
1005 elementsFromAttribute(elements, attributeName);
1006 AXObjectCache* cache = axObjectCache();
1007 for (const auto& element : elements) {
1008 if (AccessibilityObject* axObject = cache->getOrCreate(element))
1009 children.append(axObject);
1013 bool AccessibilityRenderObject::supportsARIAFlowTo() const
1015 return !getAttribute(aria_flowtoAttr).isEmpty();
1018 void AccessibilityRenderObject::ariaFlowToElements(AccessibilityChildrenVector& flowTo) const
1020 ariaElementsFromAttribute(flowTo, aria_flowtoAttr);
1023 bool AccessibilityRenderObject::supportsARIADescribedBy() const
1025 return !getAttribute(aria_describedbyAttr).isEmpty();
1028 void AccessibilityRenderObject::ariaDescribedByElements(AccessibilityChildrenVector& ariaDescribedBy) const
1030 ariaElementsFromAttribute(ariaDescribedBy, aria_describedbyAttr);
1033 bool AccessibilityRenderObject::supportsARIAControls() const
1035 return !getAttribute(aria_controlsAttr).isEmpty();
1038 void AccessibilityRenderObject::ariaControlsElements(AccessibilityChildrenVector& ariaControls) const
1040 ariaElementsFromAttribute(ariaControls, aria_controlsAttr);
1043 bool AccessibilityRenderObject::supportsARIADropping() const
1045 const AtomicString& dropEffect = getAttribute(aria_dropeffectAttr);
1046 return !dropEffect.isEmpty();
1049 bool AccessibilityRenderObject::supportsARIADragging() const
1051 const AtomicString& grabbed = getAttribute(aria_grabbedAttr);
1052 return equalIgnoringCase(grabbed, "true") || equalIgnoringCase(grabbed, "false");
1055 bool AccessibilityRenderObject::isARIAGrabbed()
1057 return elementAttributeValue(aria_grabbedAttr);
1060 void AccessibilityRenderObject::determineARIADropEffects(Vector<String>& effects)
1062 const AtomicString& dropEffects = getAttribute(aria_dropeffectAttr);
1063 if (dropEffects.isEmpty()) {
1068 String dropEffectsString = dropEffects.string();
1069 dropEffectsString.replace('\n', ' ');
1070 dropEffectsString.split(' ', effects);
1073 bool AccessibilityRenderObject::exposesTitleUIElement() const
1078 // If this control is ignored (because it's invisible),
1079 // then the label needs to be exposed so it can be visible to accessibility.
1080 if (accessibilityIsIgnored())
1083 // When controls have their own descriptions, the title element should be ignored.
1084 if (hasTextAlternative())
1090 AccessibilityObject* AccessibilityRenderObject::titleUIElement() const
1095 // if isFieldset is true, the renderer is guaranteed to be a RenderFieldset
1097 return axObjectCache()->getOrCreate(downcast<RenderFieldset>(*m_renderer).findLegend(RenderFieldset::IncludeFloatingOrOutOfFlow));
1099 Node* node = m_renderer->node();
1100 if (!is<Element>(node))
1102 HTMLLabelElement* label = labelForElement(downcast<Element>(node));
1103 if (label && label->renderer())
1104 return axObjectCache()->getOrCreate(label);
1109 bool AccessibilityRenderObject::isAllowedChildOfTree() const
1111 // Determine if this is in a tree. If so, we apply special behavior to make it work like an AXOutline.
1112 AccessibilityObject* axObj = parentObject();
1113 bool isInTree = false;
1114 bool isTreeItemDescendant = false;
1116 if (axObj->roleValue() == TreeItemRole)
1117 isTreeItemDescendant = true;
1118 if (axObj->isTree()) {
1122 axObj = axObj->parentObject();
1125 // If the object is in a tree, only tree items should be exposed (and the children of tree items).
1127 AccessibilityRole role = roleValue();
1128 if (role != TreeItemRole && role != StaticTextRole && !isTreeItemDescendant)
1134 static AccessibilityObjectInclusion objectInclusionFromAltText(const String& altText)
1136 // Don't ignore an image that has an alt tag.
1137 if (!altText.containsOnlyWhitespace())
1138 return IncludeObject;
1140 // The informal standard is to ignore images with zero-length alt strings.
1141 if (!altText.isNull())
1142 return IgnoreObject;
1144 return DefaultBehavior;
1147 AccessibilityObjectInclusion AccessibilityRenderObject::defaultObjectInclusion() const
1149 // The following cases can apply to any element that's a subclass of AccessibilityRenderObject.
1152 return IgnoreObject;
1154 if (m_renderer->style().visibility() != VISIBLE) {
1155 // aria-hidden is meant to override visibility as the determinant in AX hierarchy inclusion.
1156 if (equalIgnoringCase(getAttribute(aria_hiddenAttr), "false"))
1157 return DefaultBehavior;
1159 return IgnoreObject;
1162 return AccessibilityObject::defaultObjectInclusion();
1165 bool AccessibilityRenderObject::computeAccessibilityIsIgnored() const
1168 ASSERT(m_initialized);
1174 // Check first if any of the common reasons cause this element to be ignored.
1175 // Then process other use cases that need to be applied to all the various roles
1176 // that AccessibilityRenderObjects take on.
1177 AccessibilityObjectInclusion decision = defaultObjectInclusion();
1178 if (decision == IncludeObject)
1180 if (decision == IgnoreObject)
1183 // If this element is within a parent that cannot have children, it should not be exposed.
1184 if (isDescendantOfBarrenParent())
1187 if (roleValue() == IgnoredRole)
1190 if (roleValue() == PresentationalRole || inheritsPresentationalRole())
1193 // An ARIA tree can only have tree items and static text as children.
1194 if (!isAllowedChildOfTree())
1197 // Allow the platform to decide if the attachment is ignored or not.
1199 return accessibilityIgnoreAttachment();
1201 // ignore popup menu items because AppKit does
1202 if (m_renderer && ancestorsOfType<RenderMenuList>(*m_renderer).first())
1205 // find out if this element is inside of a label element.
1206 // if so, it may be ignored because it's the label for a checkbox or radio button
1207 AccessibilityObject* controlObject = correspondingControlForLabelElement();
1208 if (controlObject && !controlObject->exposesTitleUIElement() && controlObject->isCheckboxOrRadio())
1211 if (m_renderer->isBR())
1214 if (is<RenderText>(*m_renderer)) {
1215 // static text beneath MenuItems and MenuButtons are just reported along with the menu item, so it's ignored on an individual level
1216 AccessibilityObject* parent = parentObjectUnignored();
1217 if (parent && (parent->isMenuItem() || parent->ariaRoleAttribute() == MenuButtonRole))
1219 auto& renderText = downcast<RenderText>(*m_renderer);
1220 if (!renderText.hasRenderedText())
1223 // static text beneath TextControls is reported along with the text control text so it's ignored.
1224 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
1225 if (parent->roleValue() == TextFieldRole)
1229 // The alt attribute may be set on a text fragment through CSS, which should be honored.
1230 if (is<RenderTextFragment>(renderText)) {
1231 AccessibilityObjectInclusion altTextInclusion = objectInclusionFromAltText(downcast<RenderTextFragment>(renderText).altText());
1232 if (altTextInclusion == IgnoreObject)
1234 if (altTextInclusion == IncludeObject)
1238 // text elements that are just empty whitespace should not be returned
1239 return renderText.text()->containsOnlyWhitespace();
1251 // all controls are accessible
1255 switch (roleValue()) {
1257 case DescriptionListTermRole:
1258 case DescriptionListDetailRole:
1260 case DocumentArticleRole:
1261 case DocumentRegionRole:
1269 if (ariaRoleAttribute() != UnknownRole)
1272 if (roleValue() == HorizontalRuleRole)
1275 // don't ignore labels, because they serve as TitleUIElements
1276 Node* node = m_renderer->node();
1277 if (is<HTMLLabelElement>(node))
1280 // Anything that is content editable should not be ignored.
1281 // However, one cannot just call node->hasEditableStyle() since that will ask if its parents
1282 // are also editable. Only the top level content editable region should be exposed.
1283 if (hasContentEditableAttributeSet())
1287 // if this element has aria attributes on it, it should not be ignored.
1288 if (supportsARIAAttributes())
1292 // First check if this is a special case within the math tree that needs to be ignored.
1293 if (isIgnoredElementWithinMathTree())
1295 // Otherwise all other math elements are in the tree.
1296 if (isMathElement())
1300 if (is<RenderBlockFlow>(*m_renderer) && m_renderer->childrenInline() && !canSetFocusAttribute())
1301 return !downcast<RenderBlockFlow>(*m_renderer).hasLines() && !mouseButtonListener();
1303 // ignore images seemingly used as spacers
1306 // If the image can take focus, it should not be ignored, lest the user not be able to interact with something important.
1307 if (canSetFocusAttribute())
1310 // First check the RenderImage's altText (which can be set through a style sheet, or come from the Element).
1311 // However, if this is not a native image, fallback to the attribute on the Element.
1312 AccessibilityObjectInclusion altTextInclusion = DefaultBehavior;
1313 bool isRenderImage = is<RenderImage>(m_renderer);
1315 altTextInclusion = objectInclusionFromAltText(downcast<RenderImage>(*m_renderer).altText());
1317 altTextInclusion = objectInclusionFromAltText(getAttribute(altAttr).string());
1319 if (altTextInclusion == IgnoreObject)
1321 if (altTextInclusion == IncludeObject)
1324 // If an image has a title attribute on it, accessibility should be lenient and allow it to appear in the hierarchy (according to WAI-ARIA).
1325 if (!getAttribute(titleAttr).isEmpty())
1328 if (isRenderImage) {
1329 // check for one-dimensional image
1330 RenderImage& image = downcast<RenderImage>(*m_renderer);
1331 if (image.height() <= 1 || image.width() <= 1)
1334 // check whether rendered image was stretched from one-dimensional file image
1335 if (image.cachedImage()) {
1336 LayoutSize imageSize = image.cachedImage()->imageSizeForRenderer(&image, image.view().zoomFactor());
1337 return imageSize.height() <= 1 || imageSize.width() <= 1;
1344 if (canvasHasFallbackContent())
1347 if (is<RenderBox>(*m_renderer)) {
1348 auto& canvasBox = downcast<RenderBox>(*m_renderer);
1349 if (canvasBox.height() <= 1 || canvasBox.width() <= 1)
1352 // Otherwise fall through; use presence of help text, title, or description to decide.
1355 if (m_renderer->isListMarker()) {
1356 AccessibilityObject* parent = parentObjectUnignored();
1357 return parent && !parent->isListItem();
1363 // Using the presence of an accessible name to decide an element's visibility is not
1364 // as definitive as previous checks, so this should remain as one of the last.
1365 if (hasAttributesRequiredForInclusion())
1368 // Don't ignore generic focusable elements like <div tabindex=0>
1369 // unless they're completely empty, with no children.
1370 if (isGenericFocusableElement() && node->firstChild())
1373 // <span> tags are inline tags and not meant to convey information if they have no other aria
1374 // information on them. If we don't ignore them, they may emit signals expected to come from
1375 // their parent. In addition, because included spans are GroupRole objects, and GroupRole
1376 // objects are often containers with meaningful information, the inclusion of a span can have
1377 // the side effect of causing the immediate parent accessible to be ignored. This is especially
1378 // problematic for platforms which have distinct roles for textual block elements.
1379 if (node && node->hasTagName(spanTag))
1382 // Other non-ignored host language elements
1383 if (node && node->hasTagName(dfnTag))
1386 // Make sure that ruby containers are not ignored.
1387 if (m_renderer->isRubyRun() || m_renderer->isRubyBlock() || m_renderer->isRubyInline())
1390 // By default, objects should be ignored so that the AX hierarchy is not
1391 // filled with unnecessary items.
1395 bool AccessibilityRenderObject::isLoaded() const
1397 return !m_renderer->document().parser();
1400 double AccessibilityRenderObject::estimatedLoadingProgress() const
1408 Page* page = m_renderer->document().page();
1412 return page->progress().estimatedProgress();
1415 int AccessibilityRenderObject::layoutCount() const
1417 if (!is<RenderView>(*m_renderer))
1419 return downcast<RenderView>(*m_renderer).frameView().layoutCount();
1422 String AccessibilityRenderObject::text() const
1424 if (isPasswordField())
1425 return passwordFieldValue();
1427 return AccessibilityNodeObject::text();
1430 int AccessibilityRenderObject::textLength() const
1432 ASSERT(isTextControl());
1434 if (isPasswordField())
1435 return passwordFieldValue().length();
1437 return text().length();
1440 PlainTextRange AccessibilityRenderObject::documentBasedSelectedTextRange() const
1442 Node* node = m_renderer->node();
1444 return PlainTextRange();
1446 VisibleSelection visibleSelection = selection();
1447 RefPtr<Range> currentSelectionRange = visibleSelection.toNormalizedRange();
1448 if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, IGNORE_EXCEPTION))
1449 return PlainTextRange();
1451 int start = indexForVisiblePosition(visibleSelection.start());
1452 int end = indexForVisiblePosition(visibleSelection.end());
1454 return PlainTextRange(start, end - start);
1457 String AccessibilityRenderObject::selectedText() const
1459 ASSERT(isTextControl());
1461 if (isPasswordField())
1462 return String(); // need to return something distinct from empty string
1464 if (isNativeTextControl()) {
1465 HTMLTextFormControlElement& textControl = downcast<RenderTextControl>(*m_renderer).textFormControlElement();
1466 return textControl.selectedText();
1469 return doAXStringForRange(documentBasedSelectedTextRange());
1472 const AtomicString& AccessibilityRenderObject::accessKey() const
1474 Node* node = m_renderer->node();
1475 if (!is<Element>(node))
1477 return downcast<Element>(*node).getAttribute(accesskeyAttr);
1480 VisibleSelection AccessibilityRenderObject::selection() const
1482 return m_renderer->frame().selection().selection();
1485 PlainTextRange AccessibilityRenderObject::selectedTextRange() const
1487 ASSERT(isTextControl());
1489 if (isPasswordField())
1490 return PlainTextRange();
1492 AccessibilityRole ariaRole = ariaRoleAttribute();
1493 if (isNativeTextControl() && ariaRole == UnknownRole) {
1494 HTMLTextFormControlElement& textControl = downcast<RenderTextControl>(*m_renderer).textFormControlElement();
1495 return PlainTextRange(textControl.selectionStart(), textControl.selectionEnd() - textControl.selectionStart());
1498 return documentBasedSelectedTextRange();
1501 static void setTextSelectionIntent(AXObjectCache* cache, AXTextStateChangeType type)
1505 AXTextStateChangeIntent intent(type, AXTextSelection { AXTextSelectionDirectionDiscontiguous, AXTextSelectionGranularityUnknown, false });
1506 cache->setTextSelectionIntent(intent);
1507 cache->setIsSynchronizingSelection(true);
1510 static void clearTextSelectionIntent(AXObjectCache* cache)
1514 cache->setTextSelectionIntent(AXTextStateChangeIntent());
1515 cache->setIsSynchronizingSelection(false);
1518 void AccessibilityRenderObject::setSelectedTextRange(const PlainTextRange& range)
1520 if (isNativeTextControl()) {
1521 setTextSelectionIntent(axObjectCache(), range.length ? AXTextStateChangeTypeSelectionExtend : AXTextStateChangeTypeSelectionMove);
1522 HTMLTextFormControlElement& textControl = downcast<RenderTextControl>(*m_renderer).textFormControlElement();
1523 textControl.setSelectionRange(range.start, range.start + range.length);
1524 clearTextSelectionIntent(axObjectCache());
1528 Node* node = m_renderer->node();
1529 VisibleSelection newSelection(Position(node, range.start, Position::PositionIsOffsetInAnchor), Position(node, range.start + range.length, Position::PositionIsOffsetInAnchor), DOWNSTREAM);
1530 setTextSelectionIntent(axObjectCache(), range.length ? AXTextStateChangeTypeSelectionExtend : AXTextStateChangeTypeSelectionMove);
1531 m_renderer->frame().selection().setSelection(newSelection, FrameSelection::defaultSetSelectionOptions());
1532 clearTextSelectionIntent(axObjectCache());
1535 URL AccessibilityRenderObject::url() const
1537 if (isLink() && is<HTMLAnchorElement>(*m_renderer->node())) {
1538 if (HTMLAnchorElement* anchor = downcast<HTMLAnchorElement>(anchorElement()))
1539 return anchor->href();
1543 return m_renderer->document().url();
1545 if (isImage() && is<HTMLImageElement>(m_renderer->node()))
1546 return downcast<HTMLImageElement>(*m_renderer->node()).src();
1549 return downcast<HTMLInputElement>(*m_renderer->node()).src();
1554 bool AccessibilityRenderObject::isUnvisited() const
1556 // FIXME: Is it a privacy violation to expose unvisited information to accessibility APIs?
1557 return m_renderer->style().isLink() && m_renderer->style().insideLink() == InsideUnvisitedLink;
1560 bool AccessibilityRenderObject::isVisited() const
1562 // FIXME: Is it a privacy violation to expose visited information to accessibility APIs?
1563 return m_renderer->style().isLink() && m_renderer->style().insideLink() == InsideVisitedLink;
1566 void AccessibilityRenderObject::setElementAttributeValue(const QualifiedName& attributeName, bool value)
1571 Node* node = m_renderer->node();
1572 if (!is<Element>(node))
1575 downcast<Element>(*node).setAttribute(attributeName, (value) ? "true" : "false");
1578 bool AccessibilityRenderObject::elementAttributeValue(const QualifiedName& attributeName) const
1583 return equalIgnoringCase(getAttribute(attributeName), "true");
1586 bool AccessibilityRenderObject::isSelected() const
1591 Node* node = m_renderer->node();
1595 const AtomicString& ariaSelected = getAttribute(aria_selectedAttr);
1596 if (equalIgnoringCase(ariaSelected, "true"))
1599 if (isTabItem() && isTabItemSelected())
1605 bool AccessibilityRenderObject::isTabItemSelected() const
1607 if (!isTabItem() || !m_renderer)
1610 Node* node = m_renderer->node();
1611 if (!node || !node->isElementNode())
1614 // The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel
1615 // that has keyboard focus inside of it, or if a tabpanel in its aria-controls list has KB
1616 // focus inside of it.
1617 AccessibilityObject* focusedElement = focusedUIElement();
1618 if (!focusedElement)
1621 Vector<Element*> elements;
1622 elementsFromAttribute(elements, aria_controlsAttr);
1624 AXObjectCache* cache = axObjectCache();
1628 for (const auto& element : elements) {
1629 AccessibilityObject* tabPanel = cache->getOrCreate(element);
1631 // A tab item should only control tab panels.
1632 if (!tabPanel || tabPanel->roleValue() != TabPanelRole)
1635 AccessibilityObject* checkFocusElement = focusedElement;
1636 // Check if the focused element is a descendant of the element controlled by the tab item.
1637 while (checkFocusElement) {
1638 if (tabPanel == checkFocusElement)
1640 checkFocusElement = checkFocusElement->parentObject();
1647 bool AccessibilityRenderObject::isFocused() const
1652 Document& document = m_renderer->document();
1654 Element* focusedElement = document.focusedElement();
1655 if (!focusedElement)
1658 // A web area is represented by the Document node in the DOM tree, which isn't focusable.
1659 // Check instead if the frame's selection controller is focused
1660 if (focusedElement == m_renderer->node()
1661 || (roleValue() == WebAreaRole && document.frame()->selection().isFocusedAndActive()))
1667 void AccessibilityRenderObject::setFocused(bool on)
1669 if (!canSetFocusAttribute())
1672 Document* document = this->document();
1673 Node* node = this->node();
1675 if (!on || !is<Element>(node)) {
1676 document->setFocusedElement(nullptr);
1680 // If this node is already the currently focused node, then calling focus() won't do anything.
1681 // That is a problem when focus is removed from the webpage to chrome, and then returns.
1682 // In these cases, we need to do what keyboard and mouse focus do, which is reset focus first.
1683 if (document->focusedElement() == node)
1684 document->setFocusedElement(nullptr);
1686 axObjectCache()->setIsSynchronizingSelection(true);
1687 downcast<Element>(*node).focus();
1688 axObjectCache()->setIsSynchronizingSelection(false);
1691 void AccessibilityRenderObject::setSelectedRows(AccessibilityChildrenVector& selectedRows)
1693 // Setting selected only makes sense in trees and tables (and tree-tables).
1694 AccessibilityRole role = roleValue();
1695 if (role != TreeRole && role != TreeGridRole && role != TableRole)
1698 bool isMulti = isMultiSelectable();
1699 unsigned count = selectedRows.size();
1700 if (count > 1 && !isMulti)
1703 for (const auto& selectedRow : selectedRows)
1704 selectedRow->setSelected(true);
1707 void AccessibilityRenderObject::setValue(const String& string)
1709 if (!m_renderer || !is<Element>(m_renderer->node()))
1711 Element& element = downcast<Element>(*m_renderer->node());
1713 if (!is<RenderBoxModelObject>(*m_renderer))
1715 RenderBoxModelObject& renderer = downcast<RenderBoxModelObject>(*m_renderer);
1717 // FIXME: Do we want to do anything here for ARIA textboxes?
1718 if (renderer.isTextField() && is<HTMLInputElement>(element))
1719 downcast<HTMLInputElement>(element).setValue(string);
1720 else if (renderer.isTextArea() && is<HTMLTextAreaElement>(element))
1721 downcast<HTMLTextAreaElement>(element).setValue(string);
1724 void AccessibilityRenderObject::ariaOwnsElements(AccessibilityChildrenVector& axObjects) const
1726 ariaElementsFromAttribute(axObjects, aria_ownsAttr);
1729 bool AccessibilityRenderObject::supportsARIAOwns() const
1733 const AtomicString& ariaOwns = getAttribute(aria_ownsAttr);
1735 return !ariaOwns.isEmpty();
1738 RenderView* AccessibilityRenderObject::topRenderer() const
1740 Document* topDoc = topDocument();
1744 return topDoc->renderView();
1747 Document* AccessibilityRenderObject::document() const
1751 return &m_renderer->document();
1754 Widget* AccessibilityRenderObject::widget() const
1756 if (!is<RenderWidget>(*m_renderer))
1758 return downcast<RenderWidget>(*m_renderer).widget();
1761 AccessibilityObject* AccessibilityRenderObject::accessibilityParentForImageMap(HTMLMapElement* map) const
1763 // find an image that is using this map
1767 HTMLImageElement* imageElement = map->imageElement();
1771 if (AXObjectCache* cache = axObjectCache())
1772 return cache->getOrCreate(imageElement);
1777 void AccessibilityRenderObject::getDocumentLinks(AccessibilityChildrenVector& result)
1779 Document& document = m_renderer->document();
1780 Ref<HTMLCollection> links = document.links();
1781 for (unsigned i = 0; Node* curr = links->item(i); i++) {
1782 RenderObject* obj = curr->renderer();
1784 RefPtr<AccessibilityObject> axobj = document.axObjectCache()->getOrCreate(obj);
1786 if (!axobj->accessibilityIsIgnored() && axobj->isLink())
1787 result.append(axobj);
1789 Node* parent = curr->parentNode();
1790 if (is<HTMLAreaElement>(*curr) && is<HTMLMapElement>(parent)) {
1791 auto& areaObject = downcast<AccessibilityImageMapLink>(*axObjectCache()->getOrCreate(ImageMapLinkRole));
1792 HTMLMapElement& map = downcast<HTMLMapElement>(*parent);
1793 areaObject.setHTMLAreaElement(downcast<HTMLAreaElement>(curr));
1794 areaObject.setHTMLMapElement(&map);
1795 areaObject.setParent(accessibilityParentForImageMap(&map));
1797 result.append(&areaObject);
1803 FrameView* AccessibilityRenderObject::documentFrameView() const
1808 // this is the RenderObject's Document's Frame's FrameView
1809 return &m_renderer->view().frameView();
1812 Widget* AccessibilityRenderObject::widgetForAttachmentView() const
1814 if (!isAttachment())
1816 return downcast<RenderWidget>(*m_renderer).widget();
1819 // This function is like a cross-platform version of - (WebCoreTextMarkerRange*)textMarkerRange. It returns
1820 // a Range that we can convert to a WebCoreTextMarkerRange in the Obj-C file
1821 VisiblePositionRange AccessibilityRenderObject::visiblePositionRange() const
1824 return VisiblePositionRange();
1826 // construct VisiblePositions for start and end
1827 Node* node = m_renderer->node();
1829 return VisiblePositionRange();
1831 VisiblePosition startPos = firstPositionInOrBeforeNode(node);
1832 VisiblePosition endPos = lastPositionInOrAfterNode(node);
1834 // the VisiblePositions are equal for nodes like buttons, so adjust for that
1835 // FIXME: Really? [button, 0] and [button, 1] are distinct (before and after the button)
1836 // I expect this code is only hit for things like empty divs? In which case I don't think
1837 // the behavior is correct here -- eseidel
1838 if (startPos == endPos) {
1839 endPos = endPos.next();
1840 if (endPos.isNull())
1844 return VisiblePositionRange(startPos, endPos);
1847 VisiblePositionRange AccessibilityRenderObject::visiblePositionRangeForLine(unsigned lineCount) const
1849 if (!lineCount || !m_renderer)
1850 return VisiblePositionRange();
1852 // iterate over the lines
1853 // FIXME: this is wrong when lineNumber is lineCount+1, because nextLinePosition takes you to the
1854 // last offset of the last line
1855 VisiblePosition visiblePos = m_renderer->view().positionForPoint(IntPoint(), nullptr);
1856 VisiblePosition savedVisiblePos;
1857 while (--lineCount) {
1858 savedVisiblePos = visiblePos;
1859 visiblePos = nextLinePosition(visiblePos, 0);
1860 if (visiblePos.isNull() || visiblePos == savedVisiblePos)
1861 return VisiblePositionRange();
1864 // make a caret selection for the marker position, then extend it to the line
1865 // NOTE: ignores results of sel.modify because it returns false when
1866 // starting at an empty line. The resulting selection in that case
1867 // will be a caret at visiblePos.
1868 FrameSelection selection;
1869 selection.setSelection(VisibleSelection(visiblePos));
1870 selection.modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary);
1872 return VisiblePositionRange(selection.selection().visibleStart(), selection.selection().visibleEnd());
1875 VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(int index) const
1878 return VisiblePosition();
1880 if (isNativeTextControl())
1881 return downcast<RenderTextControl>(*m_renderer).textFormControlElement().visiblePositionForIndex(index);
1883 if (!allowsTextRanges() && !is<RenderText>(*m_renderer))
1884 return VisiblePosition();
1886 Node* node = m_renderer->node();
1888 return VisiblePosition();
1890 return visiblePositionForIndexUsingCharacterIterator(node, index);
1893 int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
1895 if (isNativeTextControl())
1896 return downcast<RenderTextControl>(*m_renderer).textFormControlElement().indexForVisiblePosition(pos);
1898 if (!isTextControl())
1901 Node* node = m_renderer->node();
1905 Position indexPosition = pos.deepEquivalent();
1906 if (indexPosition.isNull() || highestEditableRoot(indexPosition, HasEditableAXRole) != node)
1910 // We need to consider replaced elements for GTK, as they will be
1911 // presented with the 'object replacement character' (0xFFFC).
1912 bool forSelectionPreservation = true;
1914 bool forSelectionPreservation = false;
1917 return WebCore::indexForVisiblePosition(node, pos, forSelectionPreservation);
1920 Element* AccessibilityRenderObject::rootEditableElementForPosition(const Position& position) const
1922 // Find the root editable or pseudo-editable (i.e. having an editable ARIA role) element.
1923 Element* result = nullptr;
1925 Element* rootEditableElement = position.rootEditableElement();
1927 for (Element* e = position.element(); e && e != rootEditableElement; e = e->parentElement()) {
1928 if (nodeIsTextControl(e))
1930 if (e->hasTagName(bodyTag))
1937 return rootEditableElement;
1940 bool AccessibilityRenderObject::nodeIsTextControl(const Node* node) const
1945 if (AXObjectCache* cache = axObjectCache()) {
1946 if (AccessibilityObject* axObjectForNode = cache->getOrCreate(const_cast<Node*>(node)))
1947 return axObjectForNode->isTextControl();
1953 IntRect AccessibilityRenderObject::boundsForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange) const
1955 if (visiblePositionRange.isNull())
1958 // Create a mutable VisiblePositionRange.
1959 VisiblePositionRange range(visiblePositionRange);
1960 LayoutRect rect1 = range.start.absoluteCaretBounds();
1961 LayoutRect rect2 = range.end.absoluteCaretBounds();
1963 // readjust for position at the edge of a line. This is to exclude line rect that doesn't need to be accounted in the range bounds
1964 if (rect2.y() != rect1.y()) {
1965 VisiblePosition endOfFirstLine = endOfLine(range.start);
1966 if (range.start == endOfFirstLine) {
1967 range.start.setAffinity(DOWNSTREAM);
1968 rect1 = range.start.absoluteCaretBounds();
1970 if (range.end == endOfFirstLine) {
1971 range.end.setAffinity(UPSTREAM);
1972 rect2 = range.end.absoluteCaretBounds();
1976 LayoutRect ourrect = rect1;
1977 ourrect.unite(rect2);
1979 // if the rectangle spans lines and contains multiple text chars, use the range's bounding box intead
1980 if (rect1.maxY() != rect2.maxY()) {
1981 RefPtr<Range> dataRange = makeRange(range.start, range.end);
1982 LayoutRect boundingBox = dataRange->boundingBox();
1983 String rangeString = plainText(dataRange.get());
1984 if (rangeString.length() > 1 && !boundingBox.isEmpty())
1985 ourrect = boundingBox;
1989 return m_renderer->view().frameView().contentsToScreen(snappedIntRect(ourrect));
1991 return snappedIntRect(ourrect);
1995 void AccessibilityRenderObject::setSelectedVisiblePositionRange(const VisiblePositionRange& range) const
1997 if (range.start.isNull() || range.end.isNull())
2000 // make selection and tell the document to use it. if it's zero length, then move to that position
2001 if (range.start == range.end) {
2002 setTextSelectionIntent(axObjectCache(), AXTextStateChangeTypeSelectionMove);
2003 m_renderer->frame().selection().moveTo(range.start, UserTriggered);
2004 clearTextSelectionIntent(axObjectCache());
2007 setTextSelectionIntent(axObjectCache(), AXTextStateChangeTypeSelectionExtend);
2008 VisibleSelection newSelection = VisibleSelection(range.start, range.end);
2009 m_renderer->frame().selection().setSelection(newSelection, FrameSelection::defaultSetSelectionOptions());
2010 clearTextSelectionIntent(axObjectCache());
2014 VisiblePosition AccessibilityRenderObject::visiblePositionForPoint(const IntPoint& point) const
2017 return VisiblePosition();
2019 // convert absolute point to view coordinates
2020 RenderView* renderView = topRenderer();
2022 return VisiblePosition();
2025 FrameView* frameView = &renderView->frameView();
2028 Node* innerNode = nullptr;
2030 // locate the node containing the point
2031 LayoutPoint pointResult;
2033 LayoutPoint ourpoint;
2035 ourpoint = frameView->screenToContents(point);
2039 HitTestRequest request(HitTestRequest::ReadOnly |
2040 HitTestRequest::Active);
2041 HitTestResult result(ourpoint);
2042 renderView->hitTest(request, result);
2043 innerNode = result.innerNode();
2045 return VisiblePosition();
2047 RenderObject* renderer = innerNode->renderer();
2049 return VisiblePosition();
2051 pointResult = result.localPoint();
2053 // done if hit something other than a widget
2054 if (!is<RenderWidget>(*renderer))
2057 // descend into widget (FRAME, IFRAME, OBJECT...)
2058 Widget* widget = downcast<RenderWidget>(*renderer).widget();
2059 if (!is<FrameView>(widget))
2061 Frame& frame = downcast<FrameView>(*widget).frame();
2062 renderView = frame.document()->renderView();
2064 frameView = downcast<FrameView>(widget);
2068 return innerNode->renderer()->positionForPoint(pointResult, nullptr);
2071 // NOTE: Consider providing this utility method as AX API
2072 VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(unsigned indexValue, bool lastIndexOK) const
2074 if (!isTextControl())
2075 return VisiblePosition();
2077 // lastIndexOK specifies whether the position after the last character is acceptable
2078 if (indexValue >= text().length()) {
2079 if (!lastIndexOK || indexValue > text().length())
2080 return VisiblePosition();
2082 VisiblePosition position = visiblePositionForIndex(indexValue);
2083 position.setAffinity(DOWNSTREAM);
2087 // NOTE: Consider providing this utility method as AX API
2088 int AccessibilityRenderObject::index(const VisiblePosition& position) const
2090 if (position.isNull() || !isTextControl())
2093 if (renderObjectContainsPosition(m_renderer, position.deepEquivalent()))
2094 return indexForVisiblePosition(position);
2099 void AccessibilityRenderObject::lineBreaks(Vector<int>& lineBreaks) const
2101 if (!isTextControl())
2104 VisiblePosition visiblePos = visiblePositionForIndex(0);
2105 VisiblePosition savedVisiblePos = visiblePos;
2106 visiblePos = nextLinePosition(visiblePos, 0);
2107 while (!visiblePos.isNull() && visiblePos != savedVisiblePos) {
2108 lineBreaks.append(indexForVisiblePosition(visiblePos));
2109 savedVisiblePos = visiblePos;
2110 visiblePos = nextLinePosition(visiblePos, 0);
2114 // Given a line number, the range of characters of the text associated with this accessibility
2115 // object that contains the line number.
2116 PlainTextRange AccessibilityRenderObject::doAXRangeForLine(unsigned lineNumber) const
2118 if (!isTextControl())
2119 return PlainTextRange();
2121 // iterate to the specified line
2122 VisiblePosition visiblePos = visiblePositionForIndex(0);
2123 VisiblePosition savedVisiblePos;
2124 for (unsigned lineCount = lineNumber; lineCount; lineCount -= 1) {
2125 savedVisiblePos = visiblePos;
2126 visiblePos = nextLinePosition(visiblePos, 0);
2127 if (visiblePos.isNull() || visiblePos == savedVisiblePos)
2128 return PlainTextRange();
2131 // Get the end of the line based on the starting position.
2132 VisiblePosition endPosition = endOfLine(visiblePos);
2134 int index1 = indexForVisiblePosition(visiblePos);
2135 int index2 = indexForVisiblePosition(endPosition);
2137 // add one to the end index for a line break not caused by soft line wrap (to match AppKit)
2138 if (endPosition.affinity() == DOWNSTREAM && endPosition.next().isNotNull())
2141 // return nil rather than an zero-length range (to match AppKit)
2142 if (index1 == index2)
2143 return PlainTextRange();
2145 return PlainTextRange(index1, index2 - index1);
2148 // The composed character range in the text associated with this accessibility object that
2149 // is specified by the given index value. This parameterized attribute returns the complete
2150 // range of characters (including surrogate pairs of multi-byte glyphs) at the given index.
2151 PlainTextRange AccessibilityRenderObject::doAXRangeForIndex(unsigned index) const
2153 if (!isTextControl())
2154 return PlainTextRange();
2156 String elementText = text();
2157 if (!elementText.length() || index > elementText.length() - 1)
2158 return PlainTextRange();
2160 return PlainTextRange(index, 1);
2163 // A substring of the text associated with this accessibility object that is
2164 // specified by the given character range.
2165 String AccessibilityRenderObject::doAXStringForRange(const PlainTextRange& range) const
2170 if (!isTextControl())
2173 String elementText = isPasswordField() ? passwordFieldValue() : text();
2174 return elementText.substring(range.start, range.length);
2177 // The bounding rectangle of the text associated with this accessibility object that is
2178 // specified by the given range. This is the bounding rectangle a sighted user would see
2179 // on the display screen, in pixels.
2180 IntRect AccessibilityRenderObject::doAXBoundsForRange(const PlainTextRange& range) const
2182 if (allowsTextRanges())
2183 return boundsForVisiblePositionRange(visiblePositionRangeForRange(range));
2187 AccessibilityObject* AccessibilityRenderObject::accessibilityImageMapHitTest(HTMLAreaElement* area, const IntPoint& point) const
2192 AccessibilityObject* parent = nullptr;
2193 for (Element* mapParent = area->parentElement(); mapParent; mapParent = mapParent->parentElement()) {
2194 if (is<HTMLMapElement>(*mapParent)) {
2195 parent = accessibilityParentForImageMap(downcast<HTMLMapElement>(mapParent));
2202 for (const auto& child : parent->children()) {
2203 if (child->elementRect().contains(point))
2210 AccessibilityObject* AccessibilityRenderObject::remoteSVGElementHitTest(const IntPoint& point) const
2212 AccessibilityObject* remote = remoteSVGRootElement();
2216 IntSize offset = point - roundedIntPoint(boundingBoxRect().location());
2217 return remote->accessibilityHitTest(IntPoint(offset));
2220 AccessibilityObject* AccessibilityRenderObject::elementAccessibilityHitTest(const IntPoint& point) const
2223 return remoteSVGElementHitTest(point);
2225 return AccessibilityObject::elementAccessibilityHitTest(point);
2228 AccessibilityObject* AccessibilityRenderObject::accessibilityHitTest(const IntPoint& point) const
2230 if (!m_renderer || !m_renderer->hasLayer())
2233 m_renderer->document().updateLayout();
2235 RenderLayer* layer = downcast<RenderBox>(*m_renderer).layer();
2237 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::AccessibilityHitTest);
2238 HitTestResult hitTestResult = HitTestResult(point);
2239 layer->hitTest(request, hitTestResult);
2240 if (!hitTestResult.innerNode())
2242 Node* node = hitTestResult.innerNode()->deprecatedShadowAncestorNode();
2245 if (is<HTMLAreaElement>(*node))
2246 return accessibilityImageMapHitTest(downcast<HTMLAreaElement>(node), point);
2248 if (is<HTMLOptionElement>(*node))
2249 node = downcast<HTMLOptionElement>(*node).ownerSelectElement();
2251 RenderObject* obj = node->renderer();
2255 AccessibilityObject* result = obj->document().axObjectCache()->getOrCreate(obj);
2256 result->updateChildrenIfNecessary();
2258 // Allow the element to perform any hit-testing it might need to do to reach non-render children.
2259 result = result->elementAccessibilityHitTest(point);
2261 if (result && result->accessibilityIsIgnored()) {
2262 // If this element is the label of a control, a hit test should return the control.
2263 AccessibilityObject* controlObject = result->correspondingControlForLabelElement();
2264 if (controlObject && !controlObject->exposesTitleUIElement())
2265 return controlObject;
2267 result = result->parentObjectUnignored();
2273 bool AccessibilityRenderObject::shouldNotifyActiveDescendant() const
2275 // We want to notify that the combo box has changed its active descendant,
2276 // but we do not want to change the focus, because focus should remain with the combo box.
2280 return shouldFocusActiveDescendant();
2283 bool AccessibilityRenderObject::shouldFocusActiveDescendant() const
2285 switch (ariaRoleAttribute()) {
2290 case RadioGroupRole:
2292 case PopUpButtonRole:
2293 case ProgressIndicatorRole:
2298 /* FIXME: replace these with actual roles when they are added to AccessibilityRole
2311 AccessibilityObject* AccessibilityRenderObject::activeDescendant() const
2316 const AtomicString& activeDescendantAttrStr = getAttribute(aria_activedescendantAttr);
2317 if (activeDescendantAttrStr.isNull() || activeDescendantAttrStr.isEmpty())
2320 Element* element = this->element();
2324 Element* target = element->treeScope().getElementById(activeDescendantAttrStr);
2328 if (AXObjectCache* cache = axObjectCache()) {
2329 AccessibilityObject* obj = cache->getOrCreate(target);
2330 if (obj && obj->isAccessibilityRenderObject())
2331 // an activedescendant is only useful if it has a renderer, because that's what's needed to post the notification
2338 void AccessibilityRenderObject::handleAriaExpandedChanged()
2340 // Find if a parent of this object should handle aria-expanded changes.
2341 AccessibilityObject* containerParent = this->parentObject();
2342 while (containerParent) {
2343 bool foundParent = false;
2345 switch (containerParent->roleValue()) {
2360 containerParent = containerParent->parentObject();
2363 // Post that the row count changed.
2364 AXObjectCache* cache = axObjectCache();
2368 if (containerParent)
2369 cache->postNotification(containerParent, document(), AXObjectCache::AXRowCountChanged);
2371 // Post that the specific row either collapsed or expanded.
2372 if (roleValue() == RowRole || roleValue() == TreeItemRole)
2373 cache->postNotification(this, document(), isExpanded() ? AXObjectCache::AXRowExpanded : AXObjectCache::AXRowCollapsed);
2375 cache->postNotification(this, document(), AXObjectCache::AXExpandedChanged);
2378 void AccessibilityRenderObject::handleActiveDescendantChanged()
2380 Element* element = downcast<Element>(renderer()->node());
2383 if (!renderer()->frame().selection().isFocusedAndActive() || renderer()->document().focusedElement() != element)
2386 if (activeDescendant() && shouldNotifyActiveDescendant())
2387 renderer()->document().axObjectCache()->postNotification(m_renderer, AXObjectCache::AXActiveDescendantChanged);
2390 AccessibilityObject* AccessibilityRenderObject::correspondingControlForLabelElement() const
2392 HTMLLabelElement* labelElement = labelElementContainer();
2396 HTMLElement* correspondingControl = labelElement->control();
2397 if (!correspondingControl)
2400 // Make sure the corresponding control isn't a descendant of this label that's in the middle of being destroyed.
2401 if (correspondingControl->renderer() && !correspondingControl->renderer()->parent())
2404 return axObjectCache()->getOrCreate(correspondingControl);
2407 AccessibilityObject* AccessibilityRenderObject::correspondingLabelForControlElement() const
2412 // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
2413 // override the "label" element association.
2414 if (hasTextAlternative())
2417 Node* node = m_renderer->node();
2418 if (is<HTMLElement>(node)) {
2419 if (HTMLLabelElement* label = labelForElement(downcast<HTMLElement>(node)))
2420 return axObjectCache()->getOrCreate(label);
2426 bool AccessibilityRenderObject::renderObjectIsObservable(RenderObject& renderer) const
2428 // AX clients will listen for AXValueChange on a text control.
2429 if (is<RenderTextControl>(renderer))
2432 // AX clients will listen for AXSelectedChildrenChanged on listboxes.
2433 Node* node = renderer.node();
2437 if (nodeHasRole(node, "listbox") || (is<RenderBoxModelObject>(renderer) && downcast<RenderBoxModelObject>(renderer).isListBox()))
2440 // Textboxes should send out notifications.
2441 if (nodeHasRole(node, "textbox") || (is<Element>(*node) && contentEditableAttributeIsEnabled(downcast<Element>(node))))
2447 AccessibilityObject* AccessibilityRenderObject::observableObject() const
2449 // Find the object going up the parent chain that is used in accessibility to monitor certain notifications.
2450 for (RenderObject* renderer = m_renderer; renderer && renderer->node(); renderer = renderer->parent()) {
2451 if (renderObjectIsObservable(*renderer)) {
2452 if (AXObjectCache* cache = axObjectCache())
2453 return cache->getOrCreate(renderer);
2460 bool AccessibilityRenderObject::isDescendantOfElementType(const QualifiedName& tagName) const
2462 for (auto& ancestor : ancestorsOfType<RenderElement>(*m_renderer)) {
2463 if (ancestor.element() && ancestor.element()->hasTagName(tagName))
2469 String AccessibilityRenderObject::expandedTextValue() const
2471 if (AccessibilityObject* parent = parentObject()) {
2472 if (parent->hasTagName(abbrTag) || parent->hasTagName(acronymTag))
2473 return parent->getAttribute(titleAttr);
2479 bool AccessibilityRenderObject::supportsExpandedTextValue() const
2481 if (roleValue() == StaticTextRole) {
2482 if (AccessibilityObject* parent = parentObject())
2483 return parent->hasTagName(abbrTag) || parent->hasTagName(acronymTag);
2489 AccessibilityRole AccessibilityRenderObject::determineAccessibilityRole()
2494 if ((m_ariaRole = determineAriaRoleAttribute()) != UnknownRole)
2497 Node* node = m_renderer->node();
2498 RenderBoxModelObject* cssBox = renderBoxModelObject();
2500 if (node && node->isLink())
2501 return WebCoreLinkRole;
2502 if (node && is<HTMLImageElement>(*node) && downcast<HTMLImageElement>(*node).fastHasAttribute(usemapAttr))
2503 return ImageMapRole;
2504 if ((cssBox && cssBox->isListItem()) || (node && node->hasTagName(liTag)))
2505 return ListItemRole;
2506 if (m_renderer->isListMarker())
2507 return ListMarkerRole;
2508 if (node && node->hasTagName(buttonTag))
2509 return buttonRoleType();
2510 if (node && node->hasTagName(legendTag))
2512 if (m_renderer->isText())
2513 return StaticTextRole;
2514 if (cssBox && cssBox->isImage()) {
2515 if (is<HTMLInputElement>(node))
2516 return ariaHasPopup() ? PopUpButtonRole : ButtonRole;
2522 if (node && node->hasTagName(canvasTag))
2525 if (cssBox && cssBox->isRenderView())
2528 if (cssBox && cssBox->isTextField()) {
2529 if (is<HTMLInputElement>(node))
2530 return downcast<HTMLInputElement>(*node).isSearchField() ? SearchFieldRole : TextFieldRole;
2533 if (cssBox && cssBox->isTextArea())
2534 return TextAreaRole;
2536 if (is<HTMLInputElement>(node)) {
2537 HTMLInputElement& input = downcast<HTMLInputElement>(*node);
2538 if (input.isCheckbox())
2539 return CheckBoxRole;
2540 if (input.isRadioButton())
2541 return RadioButtonRole;
2542 if (input.isTextButton())
2543 return buttonRoleType();
2544 // On iOS, the date field is a popup button. On other platforms this is a text field.
2546 if (input.isDateField())
2547 return PopUpButtonRole;
2550 #if ENABLE(INPUT_TYPE_COLOR)
2551 // FIXME: Shouldn't this use input.isColorControl()?
2552 const AtomicString& type = input.getAttribute(typeAttr);
2553 if (equalIgnoringCase(type, "color"))
2554 return ColorWellRole;
2558 if (hasContentEditableAttributeSet())
2559 return TextAreaRole;
2561 if (isFileUploadButton())
2564 if (cssBox && cssBox->isMenuList())
2565 return PopUpButtonRole;
2570 if (m_renderer->isSVGImage())
2572 if (m_renderer->isSVGRoot())
2574 if (node && node->hasTagName(SVGNames::gTag))
2578 if (node && node->hasTagName(MathMLNames::mathTag))
2579 return DocumentMathRole;
2581 // It's not clear which role a platform should choose for a math element.
2582 // Declaring a math element role should give flexibility to platforms to choose.
2583 if (isMathElement())
2584 return MathElementRole;
2586 if (node && node->hasTagName(ddTag))
2587 return DescriptionListDetailRole;
2589 if (node && node->hasTagName(dtTag))
2590 return DescriptionListTermRole;
2592 if (node && node->hasTagName(dlTag))
2593 return DescriptionListRole;
2595 // Check for Ruby elements
2596 if (m_renderer->isRubyText())
2597 return RubyTextRole;
2598 if (m_renderer->isRubyBase())
2599 return RubyBaseRole;
2600 if (m_renderer->isRubyRun())
2602 if (m_renderer->isRubyBlock())
2603 return RubyBlockRole;
2604 if (m_renderer->isRubyInline())
2605 return RubyInlineRole;
2607 // This return value is what will be used if AccessibilityTableCell determines
2608 // the cell should not be treated as a cell (e.g. because it is a layout table.
2609 // In ATK, there is a distinction between generic text block elements and other
2610 // generic containers; AX API does not make this distinction.
2611 if (node && (node->hasTagName(tdTag) || node->hasTagName(thTag)))
2612 #if PLATFORM(GTK) || PLATFORM(EFL)
2618 // Table sections should be ignored.
2619 if (m_renderer->isTableSection())
2622 if (m_renderer->isHR())
2623 return HorizontalRuleRole;
2625 if (node && node->hasTagName(pTag))
2626 return ParagraphRole;
2628 if (is<HTMLLabelElement>(node))
2631 if (node && node->hasTagName(dfnTag))
2632 return DefinitionRole;
2634 if (node && node->hasTagName(divTag))
2637 if (is<HTMLFormElement>(node))
2640 if (node && node->hasTagName(articleTag))
2641 return DocumentArticleRole;
2643 if (node && node->hasTagName(mainTag))
2644 return LandmarkMainRole;
2646 if (node && node->hasTagName(navTag))
2647 return LandmarkNavigationRole;
2649 if (node && node->hasTagName(asideTag))
2650 return LandmarkComplementaryRole;
2652 if (node && node->hasTagName(sectionTag))
2653 return DocumentRegionRole;
2655 if (node && node->hasTagName(addressTag))
2656 return LandmarkContentInfoRole;
2658 if (node && node->hasTagName(blockquoteTag))
2659 return BlockquoteRole;
2661 if (node && node->hasTagName(captionTag))
2664 if (node && node->hasTagName(preTag))
2667 if (is<HTMLDetailsElement>(node))
2669 if (is<HTMLSummaryElement>(node))
2673 if (is<HTMLVideoElement>(node))
2675 if (is<HTMLAudioElement>(node))
2679 // The HTML element should not be exposed as an element. That's what the RenderView element does.
2680 if (node && node->hasTagName(htmlTag))
2683 // There should only be one banner/contentInfo per page. If header/footer are being used within an article or section
2684 // then it should not be exposed as whole page's banner/contentInfo
2685 if (node && node->hasTagName(headerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
2686 return LandmarkBannerRole;
2687 if (node && node->hasTagName(footerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
2690 if (m_renderer->isRenderBlockFlow())
2693 // If the element does not have role, but it has ARIA attributes, or accepts tab focus, accessibility should fallback to exposing it as a group.
2694 if (supportsARIAAttributes() || canSetFocusAttribute())
2697 // InlineRole is the final fallback before assigning UnknownRole to an object. It makes it
2698 // possible to distinguish truly unknown objects from non-focusable inline text elements
2699 // which have an event handler or attribute suggesting possible inclusion by the platform.
2700 if (is<RenderInline>(*m_renderer)
2701 && (hasAttributesRequiredForInclusion()
2702 || (node && node->hasEventListeners())
2703 || (supportsDatetimeAttribute() && !getAttribute(datetimeAttr).isEmpty())))
2709 AccessibilityOrientation AccessibilityRenderObject::orientation() const
2711 const AtomicString& ariaOrientation = getAttribute(aria_orientationAttr);
2712 if (equalIgnoringCase(ariaOrientation, "horizontal"))
2713 return AccessibilityOrientationHorizontal;
2714 if (equalIgnoringCase(ariaOrientation, "vertical"))
2715 return AccessibilityOrientationVertical;
2718 return AccessibilityOrientationVertical;
2720 return AccessibilityObject::orientation();
2723 bool AccessibilityRenderObject::inheritsPresentationalRole() const
2725 // ARIA states if an item can get focus, it should not be presentational.
2726 if (canSetFocusAttribute())
2729 // ARIA spec says that when a parent object is presentational, and it has required child elements,
2730 // those child elements are also presentational. For example, <li> becomes presentational from <ul>.
2731 // http://www.w3.org/WAI/PF/aria/complete#presentation
2732 static NeverDestroyed<HashSet<QualifiedName>> listItemParents;
2733 static NeverDestroyed<HashSet<QualifiedName>> tableCellParents;
2735 HashSet<QualifiedName>* possibleParentTagNames = nullptr;
2736 switch (roleValue()) {
2738 case ListMarkerRole:
2739 if (listItemParents.get().isEmpty()) {
2740 listItemParents.get().add(ulTag);
2741 listItemParents.get().add(olTag);
2742 listItemParents.get().add(dlTag);
2744 possibleParentTagNames = &listItemParents.get();
2747 if (tableCellParents.get().isEmpty())
2748 tableCellParents.get().add(tableTag);
2749 possibleParentTagNames = &tableCellParents.get();
2755 // Not all elements need to check for this, only ones that are required children.
2756 if (!possibleParentTagNames)
2759 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
2760 if (!is<AccessibilityRenderObject>(*parent))
2763 Node* node = downcast<AccessibilityRenderObject>(*parent).node();
2764 if (!is<Element>(node))
2767 // If native tag of the parent element matches an acceptable name, then return
2768 // based on its presentational status.
2769 if (possibleParentTagNames->contains(downcast<Element>(node)->tagQName()))
2770 return parent->roleValue() == PresentationalRole;
2776 bool AccessibilityRenderObject::isPresentationalChildOfAriaRole() const
2778 // Walk the parent chain looking for a parent that has presentational children
2779 AccessibilityObject* parent;
2780 for (parent = parentObject(); parent && !parent->ariaRoleHasPresentationalChildren(); parent = parent->parentObject())
2786 bool AccessibilityRenderObject::ariaRoleHasPresentationalChildren() const
2788 switch (m_ariaRole) {
2792 case ProgressIndicatorRole:
2793 case SpinButtonRole:
2794 // case SeparatorRole:
2801 bool AccessibilityRenderObject::canSetExpandedAttribute() const
2803 if (roleValue() == DetailsRole)
2806 // An object can be expanded if it aria-expanded is true or false.
2807 const AtomicString& ariaExpanded = getAttribute(aria_expandedAttr);
2808 return equalIgnoringCase(ariaExpanded, "true") || equalIgnoringCase(ariaExpanded, "false");
2811 bool AccessibilityRenderObject::canSetValueAttribute() const
2814 // In the event of a (Boolean)@readonly and (True/False/Undefined)@aria-readonly
2815 // value mismatch, the host language native attribute value wins.
2816 if (isNativeTextControl())
2817 return !isReadOnly();
2822 if (equalIgnoringCase(getAttribute(aria_readonlyAttr), "true"))
2825 if (equalIgnoringCase(getAttribute(aria_readonlyAttr), "false"))
2828 if (isProgressIndicator() || isSlider())
2831 if (isTextControl() && !isNativeTextControl())
2834 // Any node could be contenteditable, so isReadOnly should be relied upon
2835 // for this information for all elements.
2836 return !isReadOnly();
2839 bool AccessibilityRenderObject::canSetTextRangeAttributes() const
2841 return isTextControl();
2844 void AccessibilityRenderObject::textChanged()
2846 // If this element supports ARIA live regions, or is part of a region with an ARIA editable role,
2847 // then notify the AT of changes.
2848 AXObjectCache* cache = axObjectCache();
2852 for (RenderObject* renderParent = m_renderer; renderParent; renderParent = renderParent->parent()) {
2853 AccessibilityObject* parent = cache->get(renderParent);
2857 if (parent->supportsARIALiveRegion())
2858 cache->postNotification(renderParent, AXObjectCache::AXLiveRegionChanged);
2860 if ((parent->isARIATextControl() || parent->hasContentEditableAttributeSet()) && !parent->isNativeTextControl())
2861 cache->postNotification(renderParent, AXObjectCache::AXValueChanged);
2865 void AccessibilityRenderObject::clearChildren()
2867 AccessibilityObject::clearChildren();
2868 m_childrenDirty = false;
2871 void AccessibilityRenderObject::addImageMapChildren()
2873 RenderBoxModelObject* cssBox = renderBoxModelObject();
2874 if (!is<RenderImage>(cssBox))
2877 HTMLMapElement* map = downcast<RenderImage>(*cssBox).imageMap();
2881 for (auto& area : descendantsOfType<HTMLAreaElement>(*map)) {
2882 // add an <area> element for this child if it has a link
2885 auto& areaObject = downcast<AccessibilityImageMapLink>(*axObjectCache()->getOrCreate(ImageMapLinkRole));
2886 areaObject.setHTMLAreaElement(&area);
2887 areaObject.setHTMLMapElement(map);
2888 areaObject.setParent(this);
2889 if (!areaObject.accessibilityIsIgnored())
2890 m_children.append(&areaObject);
2892 axObjectCache()->remove(areaObject.axObjectID());
2896 void AccessibilityRenderObject::updateChildrenIfNecessary()
2898 if (needsToUpdateChildren())
2901 AccessibilityObject::updateChildrenIfNecessary();
2904 void AccessibilityRenderObject::addTextFieldChildren()
2906 Node* node = this->node();
2907 if (!is<HTMLInputElement>(node))
2910 HTMLInputElement& input = downcast<HTMLInputElement>(*node);
2911 HTMLElement* spinButtonElement = input.innerSpinButtonElement();
2912 if (!is<SpinButtonElement>(spinButtonElement))
2915 auto& axSpinButton = downcast<AccessibilitySpinButton>(*axObjectCache()->getOrCreate(SpinButtonRole));
2916 axSpinButton.setSpinButtonElement(downcast<SpinButtonElement>(spinButtonElement));
2917 axSpinButton.setParent(this);
2918 m_children.append(&axSpinButton);
2921 bool AccessibilityRenderObject::isSVGImage() const
2923 return remoteSVGRootElement();
2926 void AccessibilityRenderObject::detachRemoteSVGRoot()
2928 if (AccessibilitySVGRoot* root = remoteSVGRootElement())
2929 root->setParent(nullptr);
2932 AccessibilitySVGRoot* AccessibilityRenderObject::remoteSVGRootElement() const
2934 if (!is<RenderImage>(m_renderer))
2937 CachedImage* cachedImage = downcast<RenderImage>(*m_renderer).cachedImage();
2941 Image* image = cachedImage->image();
2942 if (!is<SVGImage>(image))
2945 FrameView* frameView = downcast<SVGImage>(*image).frameView();
2948 Frame& frame = frameView->frame();
2950 Document* document = frame.document();
2951 if (!is<SVGDocument>(document))
2954 SVGSVGElement* rootElement = downcast<SVGDocument>(*document).rootElement();
2957 RenderObject* rendererRoot = rootElement->renderer();
2961 AXObjectCache* cache = frame.document()->axObjectCache();
2964 AccessibilityObject* rootSVGObject = cache->getOrCreate(rendererRoot);
2966 // In order to connect the AX hierarchy from the SVG root element from the loaded resource
2967 // the parent must be set, because there's no other way to get back to who created the image.
2968 ASSERT(rootSVGObject);
2969 if (!is<AccessibilitySVGRoot>(*rootSVGObject))
2972 return downcast<AccessibilitySVGRoot>(rootSVGObject);
2975 void AccessibilityRenderObject::addRemoteSVGChildren()
2977 AccessibilitySVGRoot* root = remoteSVGRootElement();
2981 root->setParent(this);
2983 if (root->accessibilityIsIgnored()) {
2984 for (const auto& child : root->children())
2985 m_children.append(child);
2987 m_children.append(root);
2990 void AccessibilityRenderObject::addCanvasChildren()
2992 // Add the unrendered canvas children as AX nodes, unless we're not using a canvas renderer
2993 // because JS is disabled for example.
2994 if (!node() || !node()->hasTagName(canvasTag) || (renderer() && !renderer()->isCanvas()))
2997 // If it's a canvas, it won't have rendered children, but it might have accessible fallback content.
2998 // Clear m_haveChildren because AccessibilityNodeObject::addChildren will expect it to be false.
2999 ASSERT(!m_children.size());
3000 m_haveChildren = false;
3001 AccessibilityNodeObject::addChildren();
3004 void AccessibilityRenderObject::addAttachmentChildren()
3006 if (!isAttachment())
3009 // FrameView's need to be inserted into the AX hierarchy when encountered.
3010 Widget* widget = widgetForAttachmentView();
3011 if (!widget || !widget->isFrameView())
3014 AccessibilityObject* axWidget = axObjectCache()->getOrCreate(widget);
3015 if (!axWidget->accessibilityIsIgnored())
3016 m_children.append(axWidget);
3020 void AccessibilityRenderObject::updateAttachmentViewParents()
3022 // Only the unignored parent should set the attachment parent, because that's what is reflected in the AX
3023 // hierarchy to the client.
3024 if (accessibilityIsIgnored())
3027 for (const auto& child : m_children) {
3028 if (child->isAttachment())
3029 child->overrideAttachmentParent(this);
3034 // Hidden children are those that are not rendered or visible, but are specifically marked as aria-hidden=false,
3035 // meaning that they should be exposed to the AX hierarchy.
3036 void AccessibilityRenderObject::addHiddenChildren()
3038 Node* node = this->node();
3042 // First do a quick run through to determine if we have any hidden nodes (most often we will not).
3043 // If we do have hidden nodes, we need to determine where to insert them so they match DOM order as close as possible.
3044 bool shouldInsertHiddenNodes = false;
3045 for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
3046 if (!child->renderer() && isNodeAriaVisible(child)) {
3047 shouldInsertHiddenNodes = true;
3052 if (!shouldInsertHiddenNodes)
3055 // Iterate through all of the children, including those that may have already been added, and
3056 // try to insert hidden nodes in the correct place in the DOM order.
3057 unsigned insertionIndex = 0;
3058 for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
3059 if (child->renderer()) {
3060 // Find out where the last render sibling is located within m_children.
3061 AccessibilityObject* childObject = axObjectCache()->get(child->renderer());
3062 if (childObject && childObject->accessibilityIsIgnored()) {
3063 auto& children = childObject->children();
3064 if (children.size())
3065 childObject = children.last().get();
3067 childObject = nullptr;
3071 insertionIndex = m_children.find(childObject) + 1;
3075 if (!isNodeAriaVisible(child))
3078 unsigned previousSize = m_children.size();
3079 if (insertionIndex > previousSize)
3080 insertionIndex = previousSize;
3082 insertChild(axObjectCache()->getOrCreate(child), insertionIndex);
3083 insertionIndex += (m_children.size() - previousSize);
3087 void AccessibilityRenderObject::updateRoleAfterChildrenCreation()
3089 // If a menu does not have valid menuitem children, it should not be exposed as a menu.
3090 if (roleValue() == MenuRole) {
3091 // Elements marked as menus must have at least one menu item child.
3092 size_t menuItemCount = 0;
3093 for (const auto& child : children()) {
3094 if (child->isMenuItem()) {
3105 void AccessibilityRenderObject::addChildren()
3107 // If the need to add more children in addition to existing children arises,
3108 // childrenChanged should have been called, leaving the object with no children.
3109 ASSERT(!m_haveChildren);
3111 m_haveChildren = true;
3113 if (!canHaveChildren())
3116 for (RefPtr<AccessibilityObject> obj = firstChild(); obj; obj = obj->nextSibling())
3117 addChild(obj.get());
3119 addHiddenChildren();
3120 addAttachmentChildren();
3121 addImageMapChildren();
3122 addTextFieldChildren();
3123 addCanvasChildren();
3124 addRemoteSVGChildren();
3127 updateAttachmentViewParents();
3130 updateRoleAfterChildrenCreation();
3133 bool AccessibilityRenderObject::canHaveChildren() const
3138 return AccessibilityNodeObject::canHaveChildren();
3141 const String AccessibilityRenderObject::ariaLiveRegionStatus() const
3143 const AtomicString& liveRegionStatus = getAttribute(aria_liveAttr);
3144 // These roles have implicit live region status.
3145 if (liveRegionStatus.isEmpty())
3146 return defaultLiveRegionStatusForRole(roleValue());
3148 return liveRegionStatus;
3151 const AtomicString& AccessibilityRenderObject::ariaLiveRegionRelevant() const
3153 static NeverDestroyed<const AtomicString> defaultLiveRegionRelevant("additions text", AtomicString::ConstructFromLiteral);
3154 const AtomicString& relevant = getAttribute(aria_relevantAttr);
3156 // Default aria-relevant = "additions text".
3157 if (relevant.isEmpty())
3158 return defaultLiveRegionRelevant;
3163 bool AccessibilityRenderObject::ariaLiveRegionAtomic() const
3165 const AtomicString& atomic = getAttribute(aria_atomicAttr);
3166 if (equalIgnoringCase(atomic, "true"))
3168 if (equalIgnoringCase(atomic, "false"))
3170 // WAI-ARIA "alert" and "status" roles have an implicit aria-atomic value of true.
3171 switch (roleValue()) {
3172 case ApplicationAlertRole:
3173 case ApplicationStatusRole:
3180 bool AccessibilityRenderObject::ariaLiveRegionBusy() const
3182 return elementAttributeValue(aria_busyAttr);
3185 void AccessibilityRenderObject::ariaSelectedRows(AccessibilityChildrenVector& result)
3187 // Determine which rows are selected.
3188 bool isMulti = isMultiSelectable();
3190 // Prefer active descendant over aria-selected.
3191 AccessibilityObject* activeDesc = activeDescendant();
3192 if (activeDesc && (activeDesc->isTreeItem() || activeDesc->isTableRow())) {
3193 result.append(activeDesc);
3198 // Get all the rows.
3199 auto rowsIteration = [&](const AccessibilityChildrenVector& rows) {
3200 for (auto& row : rows) {
3201 if (row->isSelected()) {
3209 AccessibilityChildrenVector allRows;
3210 ariaTreeRows(allRows);
3211 rowsIteration(allRows);
3212 } else if (is<AccessibilityTable>(*this)) {
3213 auto& thisTable = downcast<AccessibilityTable>(*this);
3214 if (thisTable.isExposableThroughAccessibility() && thisTable.supportsSelectedRows())
3215 rowsIteration(thisTable.rows());
3219 void AccessibilityRenderObject::ariaListboxSelectedChildren(AccessibilityChildrenVector& result)
3221 bool isMulti = isMultiSelectable();
3223 for (const auto& child : children()) {
3224 // Every child should have aria-role option, and if so, check for selected attribute/state.
3225 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRole) {
3226 result.append(child);
3233 void AccessibilityRenderObject::selectedChildren(AccessibilityChildrenVector& result)
3235 ASSERT(result.isEmpty());
3237 // only listboxes should be asked for their selected children.
3238 AccessibilityRole role = roleValue();
3239 if (role == ListBoxRole) // native list boxes would be AccessibilityListBoxes, so only check for aria list boxes
3240 ariaListboxSelectedChildren(result);
3241 else if (role == TreeRole || role == TreeGridRole || role == TableRole)
3242 ariaSelectedRows(result);
3245 void AccessibilityRenderObject::ariaListboxVisibleChildren(AccessibilityChildrenVector& result)
3250 for (const auto& child : children()) {
3251 if (child->isOffScreen())
3252 result.append(child);
3256 void AccessibilityRenderObject::visibleChildren(AccessibilityChildrenVector& result)
3258 ASSERT(result.isEmpty());
3260 // only listboxes are asked for their visible children.
3261 if (ariaRoleAttribute() != ListBoxRole) { // native list boxes would be AccessibilityListBoxes, so only check for aria list boxes
3262 ASSERT_NOT_REACHED();
3265 return ariaListboxVisibleChildren(result);
3268 void AccessibilityRenderObject::tabChildren(AccessibilityChildrenVector& result)
3270 ASSERT(roleValue() == TabListRole);
3272 for (const auto& child : children()) {
3273 if (child->isTabItem())
3274 result.append(child);