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 // Case 5.1: After case 4, (the element was inline w/ continuation but had no sibling), then check it's parent.
392 if (!nextSibling && isInlineWithContinuation(*m_renderer->parent())) {
393 auto& continuation = *downcast<RenderInline>(*m_renderer->parent()).continuation();
395 // Case 5a: continuation is a block - in this case the block itself is the next sibling.
396 if (is<RenderBlock>(continuation))
397 nextSibling = &continuation;
398 // Case 5b: continuation is an inline - in this case the inline's first child is the next sibling
400 nextSibling = firstChildConsideringContinuation(continuation);
406 return axObjectCache()->getOrCreate(nextSibling);
409 static RenderBoxModelObject* nextContinuation(RenderObject& renderer)
411 if (is<RenderInline>(renderer) && !renderer.isReplaced())
412 return downcast<RenderInline>(renderer).continuation();
413 if (is<RenderBlock>(renderer))
414 return downcast<RenderBlock>(renderer).inlineElementContinuation();
418 RenderObject* AccessibilityRenderObject::renderParentObject() const
423 RenderElement* parent = m_renderer->parent();
425 // Case 1: node is a block and is an inline's continuation. Parent
426 // is the start of the continuation chain.
427 RenderInline* startOfConts = nullptr;
428 RenderObject* firstChild = nullptr;
429 if (is<RenderBlock>(*m_renderer) && (startOfConts = startOfContinuations(*m_renderer)))
430 parent = startOfConts;
432 // Case 2: node's parent is an inline which is some node's continuation; parent is
433 // the earliest node in the continuation chain.
434 else if (is<RenderInline>(parent) && (startOfConts = startOfContinuations(*parent)))
435 parent = startOfConts;
437 // Case 3: The first sibling is the beginning of a continuation chain. Find the origin of that continuation.
438 else if (parent && (firstChild = parent->firstChild()) && firstChild->node()) {
439 // Get the node's renderer and follow that continuation chain until the first child is found
440 RenderObject* nodeRenderFirstChild = firstChild->node()->renderer();
441 while (nodeRenderFirstChild != firstChild) {
442 for (RenderObject* contsTest = nodeRenderFirstChild; contsTest; contsTest = nextContinuation(*contsTest)) {
443 if (contsTest == firstChild) {
444 parent = nodeRenderFirstChild->parent();
448 RenderObject* parentFirstChild = parent->firstChild();
449 if (firstChild == parentFirstChild)
451 firstChild = parentFirstChild;
452 if (!firstChild->node())
454 nodeRenderFirstChild = firstChild->node()->renderer();
461 AccessibilityObject* AccessibilityRenderObject::parentObjectIfExists() const
463 AXObjectCache* cache = axObjectCache();
467 // WebArea's parent should be the scroll view containing it.
469 return cache->get(&m_renderer->view().frameView());
471 return cache->get(renderParentObject());
474 AccessibilityObject* AccessibilityRenderObject::parentObject() const
479 if (ariaRoleAttribute() == MenuBarRole)
480 return axObjectCache()->getOrCreate(m_renderer->parent());
482 // menuButton and its corresponding menu are DOM siblings, but Accessibility needs them to be parent/child
483 if (ariaRoleAttribute() == MenuRole) {
484 AccessibilityObject* parent = menuButtonForMenu();
489 AXObjectCache* cache = axObjectCache();
493 RenderObject* parentObj = renderParentObject();
495 return cache->getOrCreate(parentObj);
497 // WebArea's parent should be the scroll view containing it.
499 return cache->getOrCreate(&m_renderer->view().frameView());
504 bool AccessibilityRenderObject::isAttachment() const
506 RenderBoxModelObject* renderer = renderBoxModelObject();
509 // Widgets are the replaced elements that we represent to AX as attachments
510 bool isWidget = renderer->isWidget();
512 return isWidget && ariaRoleAttribute() == UnknownRole;
515 bool AccessibilityRenderObject::isFileUploadButton() const
517 if (m_renderer && is<HTMLInputElement>(m_renderer->node())) {
518 HTMLInputElement& input = downcast<HTMLInputElement>(*m_renderer->node());
519 return input.isFileUpload();
525 bool AccessibilityRenderObject::isReadOnly() const
530 if (HTMLElement* body = m_renderer->document().bodyOrFrameset()) {
531 if (body->hasEditableStyle())
535 return !m_renderer->document().hasEditableStyle();
538 return AccessibilityNodeObject::isReadOnly();
541 bool AccessibilityRenderObject::isOffScreen() const
544 IntRect contentRect = snappedIntRect(m_renderer->absoluteClippedOverflowRect());
545 // FIXME: unclear if we need LegacyIOSDocumentVisibleRect.
546 IntRect viewRect = m_renderer->view().frameView().visibleContentRect(ScrollableArea::LegacyIOSDocumentVisibleRect);
547 viewRect.intersect(contentRect);
548 return viewRect.isEmpty();
551 Element* AccessibilityRenderObject::anchorElement() const
556 AXObjectCache* cache = axObjectCache();
560 RenderObject* currentRenderer;
562 // Search up the render tree for a RenderObject with a DOM node. Defer to an earlier continuation, though.
563 for (currentRenderer = m_renderer; currentRenderer && !currentRenderer->node(); currentRenderer = currentRenderer->parent()) {
564 if (currentRenderer->isAnonymousBlock()) {
565 if (RenderObject* continuation = downcast<RenderBlock>(*currentRenderer).continuation())
566 return cache->getOrCreate(continuation)->anchorElement();
570 // bail if none found
571 if (!currentRenderer)
574 // search up the DOM tree for an anchor element
575 // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElement
576 for (Node* node = currentRenderer->node(); node; node = node->parentNode()) {
577 if (is<HTMLAnchorElement>(*node) || (node->renderer() && cache->getOrCreate(node->renderer())->isLink()))
578 return downcast<Element>(node);
584 String AccessibilityRenderObject::helpText() const
589 const AtomicString& ariaHelp = getAttribute(aria_helpAttr);
590 if (!ariaHelp.isEmpty())
593 String describedBy = ariaDescribedByAttribute();
594 if (!describedBy.isEmpty())
597 String description = accessibilityDescription();
598 for (RenderObject* ancestor = m_renderer; ancestor; ancestor = ancestor->parent()) {
599 if (is<HTMLElement>(ancestor->node())) {
600 HTMLElement& element = downcast<HTMLElement>(*ancestor->node());
601 const AtomicString& summary = element.getAttribute(summaryAttr);
602 if (!summary.isEmpty())
605 // The title attribute should be used as help text unless it is already being used as descriptive text.
606 const AtomicString& title = element.getAttribute(titleAttr);
607 if (!title.isEmpty() && description != title)
611 // Only take help text from an ancestor element if its a group or an unknown role. If help was
612 // added to those kinds of elements, it is likely it was meant for a child element.
613 AccessibilityObject* axObj = axObjectCache()->getOrCreate(ancestor);
615 AccessibilityRole role = axObj->roleValue();
616 if (role != GroupRole && role != UnknownRole)
624 String AccessibilityRenderObject::textUnderElement(AccessibilityTextUnderElementMode mode) const
629 if (is<RenderFileUploadControl>(*m_renderer))
630 return downcast<RenderFileUploadControl>(*m_renderer).buttonValue();
632 // Reflect when a content author has explicitly marked a line break.
633 if (m_renderer->isBR())
634 return ASCIILiteral("\n");
636 bool isRenderText = is<RenderText>(*m_renderer);
639 // Math operators create RenderText nodes on the fly that are not tied into the DOM in a reasonable way,
640 // so rangeOfContents does not work for them (nor does regular text selection).
641 if (isRenderText && m_renderer->isAnonymous() && ancestorsOfType<RenderMathMLOperator>(*m_renderer).first())
642 return downcast<RenderText>(*m_renderer).text();
643 if (is<RenderMathMLOperator>(*m_renderer) && !m_renderer->isAnonymous())
644 return downcast<RenderMathMLOperator>(*m_renderer).element().textContent();
647 // rangeOfContents does not include CSS-generated content.
648 if (m_renderer->isBeforeOrAfterContent())
649 return AccessibilityNodeObject::textUnderElement(mode);
651 // We use a text iterator for text objects AND for those cases where we are
652 // explicitly asking for the full text under a given element.
653 bool shouldIncludeAllChildren = mode.childrenInclusion == AccessibilityTextUnderElementMode::TextUnderElementModeIncludeAllChildren;
654 if (isRenderText || shouldIncludeAllChildren) {
655 // If possible, use a text iterator to get the text, so that whitespace
656 // is handled consistently.
657 Document* nodeDocument = nullptr;
658 RefPtr<Range> textRange;
659 if (Node* node = m_renderer->node()) {
660 // rangeOfContents does not include CSS-generated content.
661 Node* firstChild = node->pseudoAwareFirstChild();
662 Node* lastChild = node->pseudoAwareLastChild();
663 if ((firstChild && firstChild->isPseudoElement()) || (lastChild && lastChild->isPseudoElement()))
664 return AccessibilityNodeObject::textUnderElement(mode);
666 nodeDocument = &node->document();
667 textRange = rangeOfContents(*node);
669 // For anonymous blocks, we work around not having a direct node to create a range from
670 // defining one based in the two external positions defining the boundaries of the subtree.
671 RenderObject* firstChildRenderer = m_renderer->firstChildSlow();
672 RenderObject* lastChildRenderer = m_renderer->lastChildSlow();
673 if (firstChildRenderer && lastChildRenderer) {
674 ASSERT(firstChildRenderer->node());
675 ASSERT(lastChildRenderer->node());
677 // We define the start and end positions for the range as the ones right before and after
678 // the first and the last nodes in the DOM tree that is wrapped inside the anonymous block.
679 Node* firstNodeInBlock = firstChildRenderer->node();
680 Position startPosition = positionInParentBeforeNode(firstNodeInBlock);
681 Position endPosition = positionInParentAfterNode(lastChildRenderer->node());
683 nodeDocument = &firstNodeInBlock->document();
684 textRange = Range::create(*nodeDocument, startPosition, endPosition);
688 if (nodeDocument && textRange) {
689 if (Frame* frame = nodeDocument->frame()) {
690 // catch stale WebCoreAXObject (see <rdar://problem/3960196>)
691 if (frame->document() != nodeDocument)
694 // The tree should be stable before looking through the children of a non-Render Text object.
695 // Otherwise, further uses of TextIterator will force a layout update, potentially altering
696 // the accessibility tree and causing crashes in the loop that computes the result text.
697 ASSERT((isRenderText || !shouldIncludeAllChildren) || (!nodeDocument->renderView()->layoutState() && !nodeDocument->childNeedsStyleRecalc()));
699 return plainText(textRange.get(), textIteratorBehaviorForTextRange());
703 // Sometimes text fragments don't have Nodes associated with them (like when
704 // CSS content is used to insert text or when a RenderCounter is used.)
705 if (is<RenderText>(*m_renderer)) {
706 RenderText& renderTextObject = downcast<RenderText>(*m_renderer);
707 if (is<RenderTextFragment>(renderTextObject)) {
708 RenderTextFragment& renderTextFragment = downcast<RenderTextFragment>(renderTextObject);
709 // The alt attribute may be set on a text fragment through CSS, which should be honored.
710 const String& altText = renderTextFragment.altText();
711 if (!altText.isEmpty())
713 return renderTextFragment.contentString();
716 return renderTextObject.text();
720 return AccessibilityNodeObject::textUnderElement(mode);
723 Node* AccessibilityRenderObject::node() const
727 if (m_renderer->isRenderView())
728 return &m_renderer->document();
729 return m_renderer->node();
732 String AccessibilityRenderObject::stringValue() const
737 if (isPasswordField())
738 return passwordFieldValue();
740 RenderBoxModelObject* cssBox = renderBoxModelObject();
742 if (ariaRoleAttribute() == StaticTextRole) {
743 String staticText = text();
744 if (!staticText.length())
745 staticText = textUnderElement();
749 if (is<RenderText>(*m_renderer))
750 return textUnderElement();
752 if (is<RenderMenuList>(cssBox)) {
753 // RenderMenuList will go straight to the text() of its selected item.
754 // This has to be overridden in the case where the selected item has an ARIA label.
755 HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*m_renderer->node());
756 int selectedIndex = selectElement.selectedIndex();
757 const Vector<HTMLElement*>& listItems = selectElement.listItems();
758 if (selectedIndex >= 0 && static_cast<size_t>(selectedIndex) < listItems.size()) {
759 const AtomicString& overriddenDescription = listItems[selectedIndex]->fastGetAttribute(aria_labelAttr);
760 if (!overriddenDescription.isNull())
761 return overriddenDescription;
763 return downcast<RenderMenuList>(*m_renderer).text();
766 if (is<RenderListMarker>(*m_renderer))
767 return downcast<RenderListMarker>(*m_renderer).text();
775 if (is<RenderFileUploadControl>(*m_renderer))
776 return downcast<RenderFileUploadControl>(*m_renderer).fileTextValue();
778 // FIXME: We might need to implement a value here for more types
779 // FIXME: It would be better not to advertise a value at all for the types for which we don't implement one;
780 // this would require subclassing or making accessibilityAttributeNames do something other than return a
781 // single static array.
785 HTMLLabelElement* AccessibilityRenderObject::labelElementContainer() const
790 // the control element should not be considered part of the label
794 // find if this has a parent that is a label
795 for (Node* parentNode = m_renderer->node(); parentNode; parentNode = parentNode->parentNode()) {
796 if (is<HTMLLabelElement>(*parentNode))
797 return downcast<HTMLLabelElement>(parentNode);
803 // The boundingBox for elements within the remote SVG element needs to be offset by its position
804 // within the parent page, otherwise they are in relative coordinates only.
805 void AccessibilityRenderObject::offsetBoundingBoxForRemoteSVGElement(LayoutRect& rect) const
807 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
808 if (parent->isAccessibilitySVGRoot()) {
809 rect.moveBy(parent->parentObject()->boundingBoxRect().location());
815 LayoutRect AccessibilityRenderObject::boundingBoxRect() const
817 RenderObject* obj = m_renderer;
822 if (obj->node()) // If we are a continuation, we want to make sure to use the primary renderer.
823 obj = obj->node()->renderer();
825 // absoluteFocusRingQuads will query the hierarchy below this element, which for large webpages can be very slow.
826 // For a web area, which will have the most elements of any element, absoluteQuads should be used.
827 // We should also use absoluteQuads for SVG elements, otherwise transforms won't be applied.
828 Vector<FloatQuad> quads;
829 bool isSVGRoot = false;
831 if (obj->isSVGRoot())
834 if (is<RenderText>(*obj))
835 quads = downcast<RenderText>(*obj).absoluteQuadsClippedToEllipsis();
836 else if (isWebArea() || isSVGRoot)
837 obj->absoluteQuads(quads);
839 obj->absoluteFocusRingQuads(quads);
841 LayoutRect result = boundingBoxForQuads(obj, quads);
843 Document* document = this->document();
844 if (document && document->isSVGDocument())
845 offsetBoundingBoxForRemoteSVGElement(result);
847 // The size of the web area should be the content size, not the clipped size.
849 result.setSize(obj->view().frameView().contentsSize());
854 LayoutRect AccessibilityRenderObject::checkboxOrRadioRect() const
859 HTMLLabelElement* label = labelForElement(downcast<Element>(m_renderer->node()));
860 if (!label || !label->renderer())
861 return boundingBoxRect();
863 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementRect();
864 labelRect.unite(boundingBoxRect());
868 LayoutRect AccessibilityRenderObject::elementRect() const
870 // a checkbox or radio button should encompass its label
871 if (isCheckboxOrRadio())
872 return checkboxOrRadioRect();
874 return boundingBoxRect();
877 bool AccessibilityRenderObject::supportsPath() const
879 return is<RenderSVGShape>(m_renderer);
882 Path AccessibilityRenderObject::elementPath() const
884 if (is<RenderSVGShape>(m_renderer) && downcast<RenderSVGShape>(*m_renderer).hasPath()) {
885 Path path = downcast<RenderSVGShape>(*m_renderer).path();
887 // The SVG path is in terms of the parent's bounding box. The path needs to be offset to frame coordinates.
888 if (auto svgRoot = ancestorsOfType<RenderSVGRoot>(*m_renderer).first()) {
889 LayoutPoint parentOffset = axObjectCache()->getOrCreate(&*svgRoot)->elementRect().location();
890 path.transform(AffineTransform().translate(parentOffset.x(), parentOffset.y()));
899 IntPoint AccessibilityRenderObject::clickPoint()
901 // Headings are usually much wider than their textual content. If the mid point is used, often it can be wrong.
902 if (isHeading() && children().size() == 1)
903 return children()[0]->clickPoint();
905 // use the default position unless this is an editable web area, in which case we use the selection bounds.
906 if (!isWebArea() || isReadOnly())
907 return AccessibilityObject::clickPoint();
909 VisibleSelection visSelection = selection();
910 VisiblePositionRange range = VisiblePositionRange(visSelection.visibleStart(), visSelection.visibleEnd());
911 IntRect bounds = boundsForVisiblePositionRange(range);
913 bounds.setLocation(m_renderer->view().frameView().screenToContents(bounds.location()));
915 return IntPoint(bounds.x() + (bounds.width() / 2), bounds.y() - (bounds.height() / 2));
918 AccessibilityObject* AccessibilityRenderObject::internalLinkElement() const
920 Element* element = anchorElement();
921 // Right now, we do not support ARIA links as internal link elements
922 if (!is<HTMLAnchorElement>(element))
924 HTMLAnchorElement& anchor = downcast<HTMLAnchorElement>(*element);
926 URL linkURL = anchor.href();
927 String fragmentIdentifier = linkURL.fragmentIdentifier();
928 if (fragmentIdentifier.isEmpty())
931 // check if URL is the same as current URL
932 URL documentURL = m_renderer->document().url();
933 if (!equalIgnoringFragmentIdentifier(documentURL, linkURL))
936 Node* linkedNode = m_renderer->document().findAnchor(fragmentIdentifier);
940 // The element we find may not be accessible, so find the first accessible object.
941 return firstAccessibleObjectFromNode(linkedNode);
944 ESpeak AccessibilityRenderObject::speakProperty() const
947 return AccessibilityObject::speakProperty();
949 return m_renderer->style().speak();
952 void AccessibilityRenderObject::addRadioButtonGroupMembers(AccessibilityChildrenVector& linkedUIElements) const
954 if (!m_renderer || roleValue() != RadioButtonRole)
957 Node* node = m_renderer->node();
958 if (!is<HTMLInputElement>(node))
961 HTMLInputElement& input = downcast<HTMLInputElement>(*node);
962 // if there's a form, then this is easy
964 for (auto& associateElement : input.form()->namedElements(input.name())) {
965 if (AccessibilityObject* object = axObjectCache()->getOrCreate(&associateElement.get()))
966 linkedUIElements.append(object);
969 for (auto& associateElement : descendantsOfType<HTMLInputElement>(node->document())) {
970 if (associateElement.isRadioButton() && associateElement.name() == input.name()) {
971 if (AccessibilityObject* object = axObjectCache()->getOrCreate(&associateElement))
972 linkedUIElements.append(object);
978 // linked ui elements could be all the related radio buttons in a group
979 // or an internal anchor connection
980 void AccessibilityRenderObject::linkedUIElements(AccessibilityChildrenVector& linkedUIElements) const
982 ariaFlowToElements(linkedUIElements);
985 AccessibilityObject* linkedAXElement = internalLinkElement();
987 linkedUIElements.append(linkedAXElement);
990 if (roleValue() == RadioButtonRole)
991 addRadioButtonGroupMembers(linkedUIElements);
994 bool AccessibilityRenderObject::hasTextAlternative() const
996 // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
997 // override the "label" element association.
998 return ariaAccessibilityDescription().length();
1001 bool AccessibilityRenderObject::ariaHasPopup() const
1003 return elementAttributeValue(aria_haspopupAttr);
1006 bool AccessibilityRenderObject::supportsARIADropping() const
1008 const AtomicString& dropEffect = getAttribute(aria_dropeffectAttr);
1009 return !dropEffect.isEmpty();
1012 bool AccessibilityRenderObject::supportsARIADragging() const
1014 const AtomicString& grabbed = getAttribute(aria_grabbedAttr);
1015 return equalLettersIgnoringASCIICase(grabbed, "true") || equalLettersIgnoringASCIICase(grabbed, "false");
1018 bool AccessibilityRenderObject::isARIAGrabbed()
1020 return elementAttributeValue(aria_grabbedAttr);
1023 void AccessibilityRenderObject::determineARIADropEffects(Vector<String>& effects)
1025 const AtomicString& dropEffects = getAttribute(aria_dropeffectAttr);
1026 if (dropEffects.isEmpty()) {
1031 String dropEffectsString = dropEffects.string();
1032 dropEffectsString.replace('\n', ' ');
1033 dropEffectsString.split(' ', effects);
1036 bool AccessibilityRenderObject::exposesTitleUIElement() const
1041 // If this control is ignored (because it's invisible),
1042 // then the label needs to be exposed so it can be visible to accessibility.
1043 if (accessibilityIsIgnored())
1046 // When controls have their own descriptions, the title element should be ignored.
1047 if (hasTextAlternative())
1053 AccessibilityObject* AccessibilityRenderObject::titleUIElement() const
1058 // if isFieldset is true, the renderer is guaranteed to be a RenderFieldset
1060 return axObjectCache()->getOrCreate(downcast<RenderFieldset>(*m_renderer).findLegend(RenderFieldset::IncludeFloatingOrOutOfFlow));
1062 Node* node = m_renderer->node();
1063 if (!is<Element>(node))
1065 HTMLLabelElement* label = labelForElement(downcast<Element>(node));
1066 if (label && label->renderer())
1067 return axObjectCache()->getOrCreate(label);
1072 bool AccessibilityRenderObject::isAllowedChildOfTree() const
1074 // Determine if this is in a tree. If so, we apply special behavior to make it work like an AXOutline.
1075 AccessibilityObject* axObj = parentObject();
1076 bool isInTree = false;
1077 bool isTreeItemDescendant = false;
1079 if (axObj->roleValue() == TreeItemRole)
1080 isTreeItemDescendant = true;
1081 if (axObj->isTree()) {
1085 axObj = axObj->parentObject();
1088 // If the object is in a tree, only tree items should be exposed (and the children of tree items).
1090 AccessibilityRole role = roleValue();
1091 if (role != TreeItemRole && role != StaticTextRole && !isTreeItemDescendant)
1097 static AccessibilityObjectInclusion objectInclusionFromAltText(const String& altText)
1099 // Don't ignore an image that has an alt tag.
1100 if (!altText.containsOnlyWhitespace())
1101 return IncludeObject;
1103 // The informal standard is to ignore images with zero-length alt strings.
1104 if (!altText.isNull())
1105 return IgnoreObject;
1107 return DefaultBehavior;
1110 AccessibilityObjectInclusion AccessibilityRenderObject::defaultObjectInclusion() const
1112 // The following cases can apply to any element that's a subclass of AccessibilityRenderObject.
1115 return IgnoreObject;
1117 if (m_renderer->style().visibility() != VISIBLE) {
1118 // aria-hidden is meant to override visibility as the determinant in AX hierarchy inclusion.
1119 if (equalLettersIgnoringASCIICase(getAttribute(aria_hiddenAttr), "false"))
1120 return DefaultBehavior;
1122 return IgnoreObject;
1125 return AccessibilityObject::defaultObjectInclusion();
1128 bool AccessibilityRenderObject::computeAccessibilityIsIgnored() const
1131 ASSERT(m_initialized);
1137 // Check first if any of the common reasons cause this element to be ignored.
1138 // Then process other use cases that need to be applied to all the various roles
1139 // that AccessibilityRenderObjects take on.
1140 AccessibilityObjectInclusion decision = defaultObjectInclusion();
1141 if (decision == IncludeObject)
1143 if (decision == IgnoreObject)
1146 // If this element is within a parent that cannot have children, it should not be exposed.
1147 if (isDescendantOfBarrenParent())
1150 if (roleValue() == IgnoredRole)
1153 if (roleValue() == PresentationalRole || inheritsPresentationalRole())
1156 // An ARIA tree can only have tree items and static text as children.
1157 if (!isAllowedChildOfTree())
1160 // Allow the platform to decide if the attachment is ignored or not.
1162 return accessibilityIgnoreAttachment();
1164 // ignore popup menu items because AppKit does
1165 if (m_renderer && ancestorsOfType<RenderMenuList>(*m_renderer).first())
1168 // find out if this element is inside of a label element.
1169 // if so, it may be ignored because it's the label for a checkbox or radio button
1170 AccessibilityObject* controlObject = correspondingControlForLabelElement();
1171 if (controlObject && !controlObject->exposesTitleUIElement() && controlObject->isCheckboxOrRadio())
1174 if (m_renderer->isBR())
1177 if (is<RenderText>(*m_renderer)) {
1178 // static text beneath MenuItems and MenuButtons are just reported along with the menu item, so it's ignored on an individual level
1179 AccessibilityObject* parent = parentObjectUnignored();
1180 if (parent && (parent->isMenuItem() || parent->ariaRoleAttribute() == MenuButtonRole))
1182 auto& renderText = downcast<RenderText>(*m_renderer);
1183 if (!renderText.hasRenderedText())
1186 // static text beneath TextControls is reported along with the text control text so it's ignored.
1187 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
1188 if (parent->roleValue() == TextFieldRole)
1192 // The alt attribute may be set on a text fragment through CSS, which should be honored.
1193 if (is<RenderTextFragment>(renderText)) {
1194 AccessibilityObjectInclusion altTextInclusion = objectInclusionFromAltText(downcast<RenderTextFragment>(renderText).altText());
1195 if (altTextInclusion == IgnoreObject)
1197 if (altTextInclusion == IncludeObject)
1201 // text elements that are just empty whitespace should not be returned
1202 return renderText.text()->containsOnlyWhitespace();
1214 // all controls are accessible
1218 switch (roleValue()) {
1220 case DescriptionListTermRole:
1221 case DescriptionListDetailRole:
1223 case DocumentArticleRole:
1224 case DocumentRegionRole:
1232 if (ariaRoleAttribute() != UnknownRole)
1235 if (roleValue() == HorizontalRuleRole)
1238 // don't ignore labels, because they serve as TitleUIElements
1239 Node* node = m_renderer->node();
1240 if (is<HTMLLabelElement>(node))
1243 // Anything that is content editable should not be ignored.
1244 // However, one cannot just call node->hasEditableStyle() since that will ask if its parents
1245 // are also editable. Only the top level content editable region should be exposed.
1246 if (hasContentEditableAttributeSet())
1250 // if this element has aria attributes on it, it should not be ignored.
1251 if (supportsARIAAttributes())
1255 // First check if this is a special case within the math tree that needs to be ignored.
1256 if (isIgnoredElementWithinMathTree())
1258 // Otherwise all other math elements are in the tree.
1259 if (isMathElement())
1263 if (is<RenderBlockFlow>(*m_renderer) && m_renderer->childrenInline() && !canSetFocusAttribute())
1264 return !downcast<RenderBlockFlow>(*m_renderer).hasLines() && !mouseButtonListener();
1266 // ignore images seemingly used as spacers
1269 // If the image can take focus, it should not be ignored, lest the user not be able to interact with something important.
1270 if (canSetFocusAttribute())
1273 // First check the RenderImage's altText (which can be set through a style sheet, or come from the Element).
1274 // However, if this is not a native image, fallback to the attribute on the Element.
1275 AccessibilityObjectInclusion altTextInclusion = DefaultBehavior;
1276 bool isRenderImage = is<RenderImage>(m_renderer);
1278 altTextInclusion = objectInclusionFromAltText(downcast<RenderImage>(*m_renderer).altText());
1280 altTextInclusion = objectInclusionFromAltText(getAttribute(altAttr).string());
1282 if (altTextInclusion == IgnoreObject)
1284 if (altTextInclusion == IncludeObject)
1287 // 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).
1288 if (!getAttribute(titleAttr).isEmpty())
1291 if (isRenderImage) {
1292 // check for one-dimensional image
1293 RenderImage& image = downcast<RenderImage>(*m_renderer);
1294 if (image.height() <= 1 || image.width() <= 1)
1297 // check whether rendered image was stretched from one-dimensional file image
1298 if (image.cachedImage()) {
1299 LayoutSize imageSize = image.cachedImage()->imageSizeForRenderer(&image, image.view().zoomFactor());
1300 return imageSize.height() <= 1 || imageSize.width() <= 1;
1307 if (canvasHasFallbackContent())
1310 if (is<RenderBox>(*m_renderer)) {
1311 auto& canvasBox = downcast<RenderBox>(*m_renderer);
1312 if (canvasBox.height() <= 1 || canvasBox.width() <= 1)
1315 // Otherwise fall through; use presence of help text, title, or description to decide.
1318 if (m_renderer->isListMarker()) {
1319 AccessibilityObject* parent = parentObjectUnignored();
1320 return parent && !parent->isListItem();
1326 // Using the presence of an accessible name to decide an element's visibility is not
1327 // as definitive as previous checks, so this should remain as one of the last.
1328 if (hasAttributesRequiredForInclusion())
1331 // Don't ignore generic focusable elements like <div tabindex=0>
1332 // unless they're completely empty, with no children.
1333 if (isGenericFocusableElement() && node->firstChild())
1336 // <span> tags are inline tags and not meant to convey information if they have no other aria
1337 // information on them. If we don't ignore them, they may emit signals expected to come from
1338 // their parent. In addition, because included spans are GroupRole objects, and GroupRole
1339 // objects are often containers with meaningful information, the inclusion of a span can have
1340 // the side effect of causing the immediate parent accessible to be ignored. This is especially
1341 // problematic for platforms which have distinct roles for textual block elements.
1342 if (node && node->hasTagName(spanTag))
1345 // Other non-ignored host language elements
1346 if (node && node->hasTagName(dfnTag))
1349 if (isStyleFormatGroup())
1352 // Make sure that ruby containers are not ignored.
1353 if (m_renderer->isRubyRun() || m_renderer->isRubyBlock() || m_renderer->isRubyInline())
1356 // By default, objects should be ignored so that the AX hierarchy is not
1357 // filled with unnecessary items.
1361 bool AccessibilityRenderObject::isLoaded() const
1363 return !m_renderer->document().parser();
1366 double AccessibilityRenderObject::estimatedLoadingProgress() const
1374 Page* page = m_renderer->document().page();
1378 return page->progress().estimatedProgress();
1381 int AccessibilityRenderObject::layoutCount() const
1383 if (!is<RenderView>(*m_renderer))
1385 return downcast<RenderView>(*m_renderer).frameView().layoutCount();
1388 String AccessibilityRenderObject::text() const
1390 if (isPasswordField())
1391 return passwordFieldValue();
1393 return AccessibilityNodeObject::text();
1396 int AccessibilityRenderObject::textLength() const
1398 ASSERT(isTextControl());
1400 if (isPasswordField())
1401 return passwordFieldValue().length();
1403 return text().length();
1406 PlainTextRange AccessibilityRenderObject::documentBasedSelectedTextRange() const
1408 Node* node = m_renderer->node();
1410 return PlainTextRange();
1412 VisibleSelection visibleSelection = selection();
1413 RefPtr<Range> currentSelectionRange = visibleSelection.toNormalizedRange();
1414 if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, IGNORE_EXCEPTION))
1415 return PlainTextRange();
1417 int start = indexForVisiblePosition(visibleSelection.start());
1418 int end = indexForVisiblePosition(visibleSelection.end());
1420 return PlainTextRange(start, end - start);
1423 String AccessibilityRenderObject::selectedText() const
1425 ASSERT(isTextControl());
1427 if (isPasswordField())
1428 return String(); // need to return something distinct from empty string
1430 if (isNativeTextControl()) {
1431 HTMLTextFormControlElement& textControl = downcast<RenderTextControl>(*m_renderer).textFormControlElement();
1432 return textControl.selectedText();
1435 return doAXStringForRange(documentBasedSelectedTextRange());
1438 const AtomicString& AccessibilityRenderObject::accessKey() const
1440 Node* node = m_renderer->node();
1441 if (!is<Element>(node))
1443 return downcast<Element>(*node).getAttribute(accesskeyAttr);
1446 VisibleSelection AccessibilityRenderObject::selection() const
1448 return m_renderer->frame().selection().selection();
1451 PlainTextRange AccessibilityRenderObject::selectedTextRange() const
1453 ASSERT(isTextControl());
1455 if (isPasswordField())
1456 return PlainTextRange();
1458 AccessibilityRole ariaRole = ariaRoleAttribute();
1459 // Use the text control native range if it's a native object and it has no ARIA role (or has a text based ARIA role).
1460 if (isNativeTextControl() && (ariaRole == UnknownRole || isARIATextControl())) {
1461 HTMLTextFormControlElement& textControl = downcast<RenderTextControl>(*m_renderer).textFormControlElement();
1462 return PlainTextRange(textControl.selectionStart(), textControl.selectionEnd() - textControl.selectionStart());
1465 return documentBasedSelectedTextRange();
1468 static void setTextSelectionIntent(AXObjectCache* cache, AXTextStateChangeType type)
1472 AXTextStateChangeIntent intent(type, AXTextSelection { AXTextSelectionDirectionDiscontiguous, AXTextSelectionGranularityUnknown, false });
1473 cache->setTextSelectionIntent(intent);
1474 cache->setIsSynchronizingSelection(true);
1477 static void clearTextSelectionIntent(AXObjectCache* cache)
1481 cache->setTextSelectionIntent(AXTextStateChangeIntent());
1482 cache->setIsSynchronizingSelection(false);
1485 void AccessibilityRenderObject::setSelectedTextRange(const PlainTextRange& range)
1487 if (isNativeTextControl()) {
1488 setTextSelectionIntent(axObjectCache(), range.length ? AXTextStateChangeTypeSelectionExtend : AXTextStateChangeTypeSelectionMove);
1489 HTMLTextFormControlElement& textControl = downcast<RenderTextControl>(*m_renderer).textFormControlElement();
1490 textControl.setSelectionRange(range.start, range.start + range.length);
1491 clearTextSelectionIntent(axObjectCache());
1495 Node* node = m_renderer->node();
1496 VisibleSelection newSelection(Position(node, range.start, Position::PositionIsOffsetInAnchor), Position(node, range.start + range.length, Position::PositionIsOffsetInAnchor), DOWNSTREAM);
1497 setTextSelectionIntent(axObjectCache(), range.length ? AXTextStateChangeTypeSelectionExtend : AXTextStateChangeTypeSelectionMove);
1498 m_renderer->frame().selection().setSelection(newSelection, FrameSelection::defaultSetSelectionOptions());
1499 clearTextSelectionIntent(axObjectCache());
1502 URL AccessibilityRenderObject::url() const
1504 if (isLink() && is<HTMLAnchorElement>(*m_renderer->node())) {
1505 if (HTMLAnchorElement* anchor = downcast<HTMLAnchorElement>(anchorElement()))
1506 return anchor->href();
1510 return m_renderer->document().url();
1512 if (isImage() && is<HTMLImageElement>(m_renderer->node()))
1513 return downcast<HTMLImageElement>(*m_renderer->node()).src();
1516 return downcast<HTMLInputElement>(*m_renderer->node()).src();
1521 bool AccessibilityRenderObject::isUnvisited() const
1523 // FIXME: Is it a privacy violation to expose unvisited information to accessibility APIs?
1524 return m_renderer->style().isLink() && m_renderer->style().insideLink() == InsideUnvisitedLink;
1527 bool AccessibilityRenderObject::isVisited() const
1529 // FIXME: Is it a privacy violation to expose visited information to accessibility APIs?
1530 return m_renderer->style().isLink() && m_renderer->style().insideLink() == InsideVisitedLink;
1533 void AccessibilityRenderObject::setElementAttributeValue(const QualifiedName& attributeName, bool value)
1538 Node* node = m_renderer->node();
1539 if (!is<Element>(node))
1542 downcast<Element>(*node).setAttribute(attributeName, (value) ? "true" : "false");
1545 bool AccessibilityRenderObject::elementAttributeValue(const QualifiedName& attributeName) const
1550 return equalLettersIgnoringASCIICase(getAttribute(attributeName), "true");
1553 bool AccessibilityRenderObject::isSelected() const
1558 if (!m_renderer->node())
1561 if (equalLettersIgnoringASCIICase(getAttribute(aria_selectedAttr), "true"))
1564 if (isTabItem() && isTabItemSelected())
1570 bool AccessibilityRenderObject::isTabItemSelected() const
1572 if (!isTabItem() || !m_renderer)
1575 Node* node = m_renderer->node();
1576 if (!node || !node->isElementNode())
1579 // The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel
1580 // that has keyboard focus inside of it, or if a tabpanel in its aria-controls list has KB
1581 // focus inside of it.
1582 AccessibilityObject* focusedElement = focusedUIElement();
1583 if (!focusedElement)
1586 Vector<Element*> elements;
1587 elementsFromAttribute(elements, aria_controlsAttr);
1589 AXObjectCache* cache = axObjectCache();
1593 for (const auto& element : elements) {
1594 AccessibilityObject* tabPanel = cache->getOrCreate(element);
1596 // A tab item should only control tab panels.
1597 if (!tabPanel || tabPanel->roleValue() != TabPanelRole)
1600 AccessibilityObject* checkFocusElement = focusedElement;
1601 // Check if the focused element is a descendant of the element controlled by the tab item.
1602 while (checkFocusElement) {
1603 if (tabPanel == checkFocusElement)
1605 checkFocusElement = checkFocusElement->parentObject();
1612 bool AccessibilityRenderObject::isFocused() const
1617 Document& document = m_renderer->document();
1619 Element* focusedElement = document.focusedElement();
1620 if (!focusedElement)
1623 // A web area is represented by the Document node in the DOM tree, which isn't focusable.
1624 // Check instead if the frame's selection controller is focused
1625 if (focusedElement == m_renderer->node()
1626 || (roleValue() == WebAreaRole && document.frame()->selection().isFocusedAndActive()))
1632 void AccessibilityRenderObject::setFocused(bool on)
1634 if (!canSetFocusAttribute())
1637 Document* document = this->document();
1638 Node* node = this->node();
1640 if (!on || !is<Element>(node)) {
1641 document->setFocusedElement(nullptr);
1645 // When a node is told to set focus, that can cause it to be deallocated, which means that doing
1646 // anything else inside this object will crash. To fix this, we added a RefPtr to protect this object
1647 // long enough for duration.
1648 RefPtr<AccessibilityObject> protect(this);
1650 // If this node is already the currently focused node, then calling focus() won't do anything.
1651 // That is a problem when focus is removed from the webpage to chrome, and then returns.
1652 // In these cases, we need to do what keyboard and mouse focus do, which is reset focus first.
1653 if (document->focusedElement() == node)
1654 document->setFocusedElement(nullptr);
1656 // If we return from setFocusedElement and our element has been removed from a tree, axObjectCache() may be null.
1657 if (AXObjectCache* cache = axObjectCache()) {
1658 cache->setIsSynchronizingSelection(true);
1659 downcast<Element>(*node).focus();
1660 cache->setIsSynchronizingSelection(false);
1664 void AccessibilityRenderObject::setSelectedRows(AccessibilityChildrenVector& selectedRows)
1666 // Setting selected only makes sense in trees and tables (and tree-tables).
1667 AccessibilityRole role = roleValue();
1668 if (role != TreeRole && role != TreeGridRole && role != TableRole && role != GridRole)
1671 bool isMulti = isMultiSelectable();
1672 unsigned count = selectedRows.size();
1673 if (count > 1 && !isMulti)
1676 for (const auto& selectedRow : selectedRows)
1677 selectedRow->setSelected(true);
1680 void AccessibilityRenderObject::setValue(const String& string)
1682 if (!m_renderer || !is<Element>(m_renderer->node()))
1684 Element& element = downcast<Element>(*m_renderer->node());
1686 if (!is<RenderBoxModelObject>(*m_renderer))
1688 RenderBoxModelObject& renderer = downcast<RenderBoxModelObject>(*m_renderer);
1690 // FIXME: Do we want to do anything here for ARIA textboxes?
1691 if (renderer.isTextField() && is<HTMLInputElement>(element))
1692 downcast<HTMLInputElement>(element).setValue(string);
1693 else if (renderer.isTextArea() && is<HTMLTextAreaElement>(element))
1694 downcast<HTMLTextAreaElement>(element).setValue(string);
1697 bool AccessibilityRenderObject::supportsARIAOwns() const
1701 const AtomicString& ariaOwns = getAttribute(aria_ownsAttr);
1703 return !ariaOwns.isEmpty();
1706 RenderView* AccessibilityRenderObject::topRenderer() const
1708 Document* topDoc = topDocument();
1712 return topDoc->renderView();
1715 Document* AccessibilityRenderObject::document() const
1719 return &m_renderer->document();
1722 Widget* AccessibilityRenderObject::widget() const
1724 if (!is<RenderWidget>(*m_renderer))
1726 return downcast<RenderWidget>(*m_renderer).widget();
1729 AccessibilityObject* AccessibilityRenderObject::accessibilityParentForImageMap(HTMLMapElement* map) const
1731 // find an image that is using this map
1735 HTMLImageElement* imageElement = map->imageElement();
1739 if (AXObjectCache* cache = axObjectCache())
1740 return cache->getOrCreate(imageElement);
1745 void AccessibilityRenderObject::getDocumentLinks(AccessibilityChildrenVector& result)
1747 Document& document = m_renderer->document();
1748 Ref<HTMLCollection> links = document.links();
1749 for (unsigned i = 0; auto* current = links->item(i); ++i) {
1750 if (auto* renderer = current->renderer()) {
1751 RefPtr<AccessibilityObject> axObject = document.axObjectCache()->getOrCreate(renderer);
1753 if (!axObject->accessibilityIsIgnored() && axObject->isLink())
1754 result.append(axObject);
1756 auto* parent = current->parentNode();
1757 if (is<HTMLAreaElement>(*current) && is<HTMLMapElement>(parent)) {
1758 auto& areaObject = downcast<AccessibilityImageMapLink>(*axObjectCache()->getOrCreate(ImageMapLinkRole));
1759 HTMLMapElement& map = downcast<HTMLMapElement>(*parent);
1760 areaObject.setHTMLAreaElement(downcast<HTMLAreaElement>(current));
1761 areaObject.setHTMLMapElement(&map);
1762 areaObject.setParent(accessibilityParentForImageMap(&map));
1764 result.append(&areaObject);
1770 FrameView* AccessibilityRenderObject::documentFrameView() const
1775 // this is the RenderObject's Document's Frame's FrameView
1776 return &m_renderer->view().frameView();
1779 Widget* AccessibilityRenderObject::widgetForAttachmentView() const
1781 if (!isAttachment())
1783 return downcast<RenderWidget>(*m_renderer).widget();
1786 // This function is like a cross-platform version of - (WebCoreTextMarkerRange*)textMarkerRange. It returns
1787 // a Range that we can convert to a WebCoreTextMarkerRange in the Obj-C file
1788 VisiblePositionRange AccessibilityRenderObject::visiblePositionRange() const
1791 return VisiblePositionRange();
1793 // construct VisiblePositions for start and end
1794 Node* node = m_renderer->node();
1796 return VisiblePositionRange();
1798 VisiblePosition startPos = firstPositionInOrBeforeNode(node);
1799 VisiblePosition endPos = lastPositionInOrAfterNode(node);
1801 // the VisiblePositions are equal for nodes like buttons, so adjust for that
1802 // FIXME: Really? [button, 0] and [button, 1] are distinct (before and after the button)
1803 // I expect this code is only hit for things like empty divs? In which case I don't think
1804 // the behavior is correct here -- eseidel
1805 if (startPos == endPos) {
1806 endPos = endPos.next();
1807 if (endPos.isNull())
1811 return VisiblePositionRange(startPos, endPos);
1814 VisiblePositionRange AccessibilityRenderObject::visiblePositionRangeForLine(unsigned lineCount) const
1816 if (!lineCount || !m_renderer)
1817 return VisiblePositionRange();
1819 // iterate over the lines
1820 // FIXME: this is wrong when lineNumber is lineCount+1, because nextLinePosition takes you to the
1821 // last offset of the last line
1822 VisiblePosition visiblePos = m_renderer->view().positionForPoint(IntPoint(), nullptr);
1823 VisiblePosition savedVisiblePos;
1824 while (--lineCount) {
1825 savedVisiblePos = visiblePos;
1826 visiblePos = nextLinePosition(visiblePos, 0);
1827 if (visiblePos.isNull() || visiblePos == savedVisiblePos)
1828 return VisiblePositionRange();
1831 // make a caret selection for the marker position, then extend it to the line
1832 // NOTE: ignores results of sel.modify because it returns false when
1833 // starting at an empty line. The resulting selection in that case
1834 // will be a caret at visiblePos.
1835 FrameSelection selection;
1836 selection.setSelection(VisibleSelection(visiblePos));
1837 selection.modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary);
1839 return VisiblePositionRange(selection.selection().visibleStart(), selection.selection().visibleEnd());
1842 VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(int index) const
1845 return VisiblePosition();
1847 if (isNativeTextControl())
1848 return downcast<RenderTextControl>(*m_renderer).textFormControlElement().visiblePositionForIndex(index);
1850 if (!allowsTextRanges() && !is<RenderText>(*m_renderer))
1851 return VisiblePosition();
1853 Node* node = m_renderer->node();
1855 return VisiblePosition();
1857 return visiblePositionForIndexUsingCharacterIterator(node, index);
1860 int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
1862 if (isNativeTextControl())
1863 return downcast<RenderTextControl>(*m_renderer).textFormControlElement().indexForVisiblePosition(pos);
1865 if (!isTextControl())
1868 Node* node = m_renderer->node();
1872 Position indexPosition = pos.deepEquivalent();
1873 if (indexPosition.isNull() || highestEditableRoot(indexPosition, HasEditableAXRole) != node)
1877 // We need to consider replaced elements for GTK, as they will be
1878 // presented with the 'object replacement character' (0xFFFC).
1879 bool forSelectionPreservation = true;
1881 bool forSelectionPreservation = false;
1884 return WebCore::indexForVisiblePosition(node, pos, forSelectionPreservation);
1887 Element* AccessibilityRenderObject::rootEditableElementForPosition(const Position& position) const
1889 // Find the root editable or pseudo-editable (i.e. having an editable ARIA role) element.
1890 Element* result = nullptr;
1892 Element* rootEditableElement = position.rootEditableElement();
1894 for (Element* e = position.element(); e && e != rootEditableElement; e = e->parentElement()) {
1895 if (nodeIsTextControl(e))
1897 if (e->hasTagName(bodyTag))
1904 return rootEditableElement;
1907 bool AccessibilityRenderObject::nodeIsTextControl(const Node* node) const
1912 if (AXObjectCache* cache = axObjectCache()) {
1913 if (AccessibilityObject* axObjectForNode = cache->getOrCreate(const_cast<Node*>(node)))
1914 return axObjectForNode->isTextControl();
1920 IntRect AccessibilityRenderObject::boundsForRects(LayoutRect& rect1, LayoutRect& rect2, RefPtr<Range> dataRange) const
1922 LayoutRect ourRect = rect1;
1923 ourRect.unite(rect2);
1925 // if the rectangle spans lines and contains multiple text chars, use the range's bounding box intead
1926 if (rect1.maxY() != rect2.maxY()) {
1927 LayoutRect boundingBox = dataRange->absoluteBoundingBox();
1928 String rangeString = plainText(dataRange.get());
1929 if (rangeString.length() > 1 && !boundingBox.isEmpty())
1930 ourRect = boundingBox;
1934 return m_renderer->view().frameView().contentsToScreen(snappedIntRect(ourRect));
1936 return snappedIntRect(ourRect);
1940 IntRect AccessibilityRenderObject::boundsForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange) const
1942 if (visiblePositionRange.isNull())
1945 // Create a mutable VisiblePositionRange.
1946 VisiblePositionRange range(visiblePositionRange);
1947 LayoutRect rect1 = range.start.absoluteCaretBounds();
1948 LayoutRect rect2 = range.end.absoluteCaretBounds();
1950 // 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
1951 if (rect2.y() != rect1.y()) {
1952 VisiblePosition endOfFirstLine = endOfLine(range.start);
1953 if (range.start == endOfFirstLine) {
1954 range.start.setAffinity(DOWNSTREAM);
1955 rect1 = range.start.absoluteCaretBounds();
1957 if (range.end == endOfFirstLine) {
1958 range.end.setAffinity(UPSTREAM);
1959 rect2 = range.end.absoluteCaretBounds();
1963 RefPtr<Range> dataRange = makeRange(range.start, range.end);
1964 return boundsForRects(rect1, rect2, dataRange);
1967 IntRect AccessibilityRenderObject::boundsForRange(const RefPtr<Range> range) const
1972 AXObjectCache* cache = this->axObjectCache();
1976 CharacterOffset start = cache->startOrEndCharacterOffsetForRange(range, true);
1977 CharacterOffset end = cache->startOrEndCharacterOffsetForRange(range, false);
1979 LayoutRect rect1 = cache->absoluteCaretBoundsForCharacterOffset(start);
1980 LayoutRect rect2 = cache->absoluteCaretBoundsForCharacterOffset(end);
1982 // 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.
1983 if (rect2.y() != rect1.y()) {
1984 CharacterOffset endOfFirstLine = cache->endCharacterOffsetOfLine(start);
1985 if (start.isEqual(endOfFirstLine)) {
1986 start = cache->nextCharacterOffset(start, false);
1987 rect1 = cache->absoluteCaretBoundsForCharacterOffset(start);
1989 if (end.isEqual(endOfFirstLine)) {
1990 end = cache->previousCharacterOffset(end, false);
1991 rect2 = cache->absoluteCaretBoundsForCharacterOffset(end);
1995 return boundsForRects(rect1, rect2, range);
1998 void AccessibilityRenderObject::setSelectedVisiblePositionRange(const VisiblePositionRange& range) const
2000 if (range.start.isNull() || range.end.isNull())
2003 // make selection and tell the document to use it. if it's zero length, then move to that position
2004 if (range.start == range.end) {
2005 setTextSelectionIntent(axObjectCache(), AXTextStateChangeTypeSelectionMove);
2006 m_renderer->frame().selection().moveTo(range.start, UserTriggered);
2007 clearTextSelectionIntent(axObjectCache());
2010 setTextSelectionIntent(axObjectCache(), AXTextStateChangeTypeSelectionExtend);
2011 VisibleSelection newSelection = VisibleSelection(range.start, range.end);
2012 m_renderer->frame().selection().setSelection(newSelection, FrameSelection::defaultSetSelectionOptions());
2013 clearTextSelectionIntent(axObjectCache());
2017 VisiblePosition AccessibilityRenderObject::visiblePositionForPoint(const IntPoint& point) const
2020 return VisiblePosition();
2022 // convert absolute point to view coordinates
2023 RenderView* renderView = topRenderer();
2025 return VisiblePosition();
2028 FrameView* frameView = &renderView->frameView();
2031 Node* innerNode = nullptr;
2033 // locate the node containing the point
2034 LayoutPoint pointResult;
2036 LayoutPoint ourpoint;
2038 ourpoint = frameView->screenToContents(point);
2042 HitTestRequest request(HitTestRequest::ReadOnly |
2043 HitTestRequest::Active);
2044 HitTestResult result(ourpoint);
2045 renderView->hitTest(request, result);
2046 innerNode = result.innerNode();
2048 return VisiblePosition();
2050 RenderObject* renderer = innerNode->renderer();
2052 return VisiblePosition();
2054 pointResult = result.localPoint();
2056 // done if hit something other than a widget
2057 if (!is<RenderWidget>(*renderer))
2060 // descend into widget (FRAME, IFRAME, OBJECT...)
2061 Widget* widget = downcast<RenderWidget>(*renderer).widget();
2062 if (!is<FrameView>(widget))
2064 Frame& frame = downcast<FrameView>(*widget).frame();
2065 renderView = frame.document()->renderView();
2067 frameView = downcast<FrameView>(widget);
2071 return innerNode->renderer()->positionForPoint(pointResult, nullptr);
2074 // NOTE: Consider providing this utility method as AX API
2075 VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(unsigned indexValue, bool lastIndexOK) const
2077 if (!isTextControl())
2078 return VisiblePosition();
2080 // lastIndexOK specifies whether the position after the last character is acceptable
2081 if (indexValue >= text().length()) {
2082 if (!lastIndexOK || indexValue > text().length())
2083 return VisiblePosition();
2085 VisiblePosition position = visiblePositionForIndex(indexValue);
2086 position.setAffinity(DOWNSTREAM);
2090 // NOTE: Consider providing this utility method as AX API
2091 int AccessibilityRenderObject::index(const VisiblePosition& position) const
2093 if (position.isNull() || !isTextControl())
2096 if (renderObjectContainsPosition(m_renderer, position.deepEquivalent()))
2097 return indexForVisiblePosition(position);
2102 void AccessibilityRenderObject::lineBreaks(Vector<int>& lineBreaks) const
2104 if (!isTextControl())
2107 VisiblePosition visiblePos = visiblePositionForIndex(0);
2108 VisiblePosition savedVisiblePos = visiblePos;
2109 visiblePos = nextLinePosition(visiblePos, 0);
2110 while (!visiblePos.isNull() && visiblePos != savedVisiblePos) {
2111 lineBreaks.append(indexForVisiblePosition(visiblePos));
2112 savedVisiblePos = visiblePos;
2113 visiblePos = nextLinePosition(visiblePos, 0);
2117 // Given a line number, the range of characters of the text associated with this accessibility
2118 // object that contains the line number.
2119 PlainTextRange AccessibilityRenderObject::doAXRangeForLine(unsigned lineNumber) const
2121 if (!isTextControl())
2122 return PlainTextRange();
2124 // iterate to the specified line
2125 VisiblePosition visiblePos = visiblePositionForIndex(0);
2126 VisiblePosition savedVisiblePos;
2127 for (unsigned lineCount = lineNumber; lineCount; lineCount -= 1) {
2128 savedVisiblePos = visiblePos;
2129 visiblePos = nextLinePosition(visiblePos, 0);
2130 if (visiblePos.isNull() || visiblePos == savedVisiblePos)
2131 return PlainTextRange();
2134 // Get the end of the line based on the starting position.
2135 VisiblePosition endPosition = endOfLine(visiblePos);
2137 int index1 = indexForVisiblePosition(visiblePos);
2138 int index2 = indexForVisiblePosition(endPosition);
2140 // add one to the end index for a line break not caused by soft line wrap (to match AppKit)
2141 if (endPosition.affinity() == DOWNSTREAM && endPosition.next().isNotNull())
2144 // return nil rather than an zero-length range (to match AppKit)
2145 if (index1 == index2)
2146 return PlainTextRange();
2148 return PlainTextRange(index1, index2 - index1);
2151 // The composed character range in the text associated with this accessibility object that
2152 // is specified by the given index value. This parameterized attribute returns the complete
2153 // range of characters (including surrogate pairs of multi-byte glyphs) at the given index.
2154 PlainTextRange AccessibilityRenderObject::doAXRangeForIndex(unsigned index) const
2156 if (!isTextControl())
2157 return PlainTextRange();
2159 String elementText = text();
2160 if (!elementText.length() || index > elementText.length() - 1)
2161 return PlainTextRange();
2163 return PlainTextRange(index, 1);
2166 // A substring of the text associated with this accessibility object that is
2167 // specified by the given character range.
2168 String AccessibilityRenderObject::doAXStringForRange(const PlainTextRange& range) const
2173 if (!isTextControl())
2176 String elementText = isPasswordField() ? passwordFieldValue() : text();
2177 return elementText.substring(range.start, range.length);
2180 // The bounding rectangle of the text associated with this accessibility object that is
2181 // specified by the given range. This is the bounding rectangle a sighted user would see
2182 // on the display screen, in pixels.
2183 IntRect AccessibilityRenderObject::doAXBoundsForRange(const PlainTextRange& range) const
2185 if (allowsTextRanges())
2186 return boundsForVisiblePositionRange(visiblePositionRangeForRange(range));
2190 IntRect AccessibilityRenderObject::doAXBoundsForRangeUsingCharacterOffset(const PlainTextRange& range) const
2192 if (allowsTextRanges())
2193 return boundsForRange(rangeForPlainTextRange(range));
2197 AccessibilityObject* AccessibilityRenderObject::accessibilityImageMapHitTest(HTMLAreaElement* area, const IntPoint& point) const
2202 AccessibilityObject* parent = nullptr;
2203 for (Element* mapParent = area->parentElement(); mapParent; mapParent = mapParent->parentElement()) {
2204 if (is<HTMLMapElement>(*mapParent)) {
2205 parent = accessibilityParentForImageMap(downcast<HTMLMapElement>(mapParent));
2212 for (const auto& child : parent->children()) {
2213 if (child->elementRect().contains(point))
2220 AccessibilityObject* AccessibilityRenderObject::remoteSVGElementHitTest(const IntPoint& point) const
2222 AccessibilityObject* remote = remoteSVGRootElement();
2226 IntSize offset = point - roundedIntPoint(boundingBoxRect().location());
2227 return remote->accessibilityHitTest(IntPoint(offset));
2230 AccessibilityObject* AccessibilityRenderObject::elementAccessibilityHitTest(const IntPoint& point) const
2233 return remoteSVGElementHitTest(point);
2235 return AccessibilityObject::elementAccessibilityHitTest(point);
2238 AccessibilityObject* AccessibilityRenderObject::accessibilityHitTest(const IntPoint& point) const
2240 if (!m_renderer || !m_renderer->hasLayer())
2243 m_renderer->document().updateLayout();
2245 RenderLayer* layer = downcast<RenderBox>(*m_renderer).layer();
2247 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::AccessibilityHitTest);
2248 HitTestResult hitTestResult = HitTestResult(point);
2249 layer->hitTest(request, hitTestResult);
2250 if (!hitTestResult.innerNode())
2252 Node* node = hitTestResult.innerNode()->deprecatedShadowAncestorNode();
2255 if (is<HTMLAreaElement>(*node))
2256 return accessibilityImageMapHitTest(downcast<HTMLAreaElement>(node), point);
2258 if (is<HTMLOptionElement>(*node))
2259 node = downcast<HTMLOptionElement>(*node).ownerSelectElement();
2261 RenderObject* obj = node->renderer();
2265 AccessibilityObject* result = obj->document().axObjectCache()->getOrCreate(obj);
2266 result->updateChildrenIfNecessary();
2268 // Allow the element to perform any hit-testing it might need to do to reach non-render children.
2269 result = result->elementAccessibilityHitTest(point);
2271 if (result && result->accessibilityIsIgnored()) {
2272 // If this element is the label of a control, a hit test should return the control.
2273 AccessibilityObject* controlObject = result->correspondingControlForLabelElement();
2274 if (controlObject && !controlObject->exposesTitleUIElement())
2275 return controlObject;
2277 result = result->parentObjectUnignored();
2283 bool AccessibilityRenderObject::shouldNotifyActiveDescendant() const
2285 // We want to notify that the combo box has changed its active descendant,
2286 // but we do not want to change the focus, because focus should remain with the combo box.
2290 return shouldFocusActiveDescendant();
2293 bool AccessibilityRenderObject::shouldFocusActiveDescendant() const
2295 switch (ariaRoleAttribute()) {
2300 case RadioGroupRole:
2302 case PopUpButtonRole:
2303 case ProgressIndicatorRole:
2308 /* FIXME: replace these with actual roles when they are added to AccessibilityRole
2321 AccessibilityObject* AccessibilityRenderObject::activeDescendant() const
2326 const AtomicString& activeDescendantAttrStr = getAttribute(aria_activedescendantAttr);
2327 if (activeDescendantAttrStr.isNull() || activeDescendantAttrStr.isEmpty())
2330 Element* element = this->element();
2334 Element* target = element->treeScope().getElementById(activeDescendantAttrStr);
2338 if (AXObjectCache* cache = axObjectCache()) {
2339 AccessibilityObject* obj = cache->getOrCreate(target);
2340 if (obj && obj->isAccessibilityRenderObject())
2341 // an activedescendant is only useful if it has a renderer, because that's what's needed to post the notification
2348 void AccessibilityRenderObject::handleAriaExpandedChanged()
2350 // Find if a parent of this object should handle aria-expanded changes.
2351 AccessibilityObject* containerParent = this->parentObject();
2352 while (containerParent) {
2353 bool foundParent = false;
2355 switch (containerParent->roleValue()) {
2370 containerParent = containerParent->parentObject();
2373 // Post that the row count changed.
2374 AXObjectCache* cache = axObjectCache();
2378 if (containerParent)
2379 cache->postNotification(containerParent, document(), AXObjectCache::AXRowCountChanged);
2381 // Post that the specific row either collapsed or expanded.
2382 if (roleValue() == RowRole || roleValue() == TreeItemRole)
2383 cache->postNotification(this, document(), isExpanded() ? AXObjectCache::AXRowExpanded : AXObjectCache::AXRowCollapsed);
2385 cache->postNotification(this, document(), AXObjectCache::AXExpandedChanged);
2388 void AccessibilityRenderObject::handleActiveDescendantChanged()
2390 Element* element = downcast<Element>(renderer()->node());
2393 if (!renderer()->frame().selection().isFocusedAndActive() || renderer()->document().focusedElement() != element)
2396 if (activeDescendant() && shouldNotifyActiveDescendant())
2397 renderer()->document().axObjectCache()->postNotification(m_renderer, AXObjectCache::AXActiveDescendantChanged);
2400 AccessibilityObject* AccessibilityRenderObject::correspondingControlForLabelElement() const
2402 HTMLLabelElement* labelElement = labelElementContainer();
2406 HTMLElement* correspondingControl = labelElement->control();
2407 if (!correspondingControl)
2410 // Make sure the corresponding control isn't a descendant of this label that's in the middle of being destroyed.
2411 if (correspondingControl->renderer() && !correspondingControl->renderer()->parent())
2414 return axObjectCache()->getOrCreate(correspondingControl);
2417 AccessibilityObject* AccessibilityRenderObject::correspondingLabelForControlElement() const
2422 // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
2423 // override the "label" element association.
2424 if (hasTextAlternative())
2427 Node* node = m_renderer->node();
2428 if (is<HTMLElement>(node)) {
2429 if (HTMLLabelElement* label = labelForElement(downcast<HTMLElement>(node)))
2430 return axObjectCache()->getOrCreate(label);
2436 bool AccessibilityRenderObject::renderObjectIsObservable(RenderObject& renderer) const
2438 // AX clients will listen for AXValueChange on a text control.
2439 if (is<RenderTextControl>(renderer))
2442 // AX clients will listen for AXSelectedChildrenChanged on listboxes.
2443 Node* node = renderer.node();
2447 if (nodeHasRole(node, "listbox") || (is<RenderBoxModelObject>(renderer) && downcast<RenderBoxModelObject>(renderer).isListBox()))
2450 // Textboxes should send out notifications.
2451 if (nodeHasRole(node, "textbox") || (is<Element>(*node) && contentEditableAttributeIsEnabled(downcast<Element>(node))))
2457 AccessibilityObject* AccessibilityRenderObject::observableObject() const
2459 // Find the object going up the parent chain that is used in accessibility to monitor certain notifications.
2460 for (RenderObject* renderer = m_renderer; renderer && renderer->node(); renderer = renderer->parent()) {
2461 if (renderObjectIsObservable(*renderer)) {
2462 if (AXObjectCache* cache = axObjectCache())
2463 return cache->getOrCreate(renderer);
2470 bool AccessibilityRenderObject::isDescendantOfElementType(const QualifiedName& tagName) const
2472 for (auto& ancestor : ancestorsOfType<RenderElement>(*m_renderer)) {
2473 if (ancestor.element() && ancestor.element()->hasTagName(tagName))
2479 String AccessibilityRenderObject::expandedTextValue() const
2481 if (AccessibilityObject* parent = parentObject()) {
2482 if (parent->hasTagName(abbrTag) || parent->hasTagName(acronymTag))
2483 return parent->getAttribute(titleAttr);
2489 bool AccessibilityRenderObject::supportsExpandedTextValue() const
2491 if (roleValue() == StaticTextRole) {
2492 if (AccessibilityObject* parent = parentObject())
2493 return parent->hasTagName(abbrTag) || parent->hasTagName(acronymTag);
2499 AccessibilityRole AccessibilityRenderObject::determineAccessibilityRole()
2504 // Sometimes we need to ignore the attribute role. Like if a tree is malformed,
2505 // we want to ignore the treeitem's attribute role.
2506 if ((m_ariaRole = determineAriaRoleAttribute()) != UnknownRole && !shouldIgnoreAttributeRole())
2509 Node* node = m_renderer->node();
2510 RenderBoxModelObject* cssBox = renderBoxModelObject();
2512 if (node && node->isLink())
2513 return WebCoreLinkRole;
2514 if (node && is<HTMLImageElement>(*node) && downcast<HTMLImageElement>(*node).fastHasAttribute(usemapAttr))
2515 return ImageMapRole;
2516 if ((cssBox && cssBox->isListItem()) || (node && node->hasTagName(liTag)))
2517 return ListItemRole;
2518 if (m_renderer->isListMarker())
2519 return ListMarkerRole;
2520 if (node && node->hasTagName(buttonTag))
2521 return buttonRoleType();
2522 if (node && node->hasTagName(legendTag))
2524 if (m_renderer->isText())
2525 return StaticTextRole;
2526 if (cssBox && cssBox->isImage()) {
2527 if (is<HTMLInputElement>(node))
2528 return ariaHasPopup() ? PopUpButtonRole : ButtonRole;
2534 if (node && node->hasTagName(canvasTag))
2537 if (cssBox && cssBox->isRenderView())
2540 if (cssBox && cssBox->isTextField()) {
2541 if (is<HTMLInputElement>(node))
2542 return downcast<HTMLInputElement>(*node).isSearchField() ? SearchFieldRole : TextFieldRole;
2545 if (cssBox && cssBox->isTextArea())
2546 return TextAreaRole;
2548 if (is<HTMLInputElement>(node)) {
2549 HTMLInputElement& input = downcast<HTMLInputElement>(*node);
2550 if (input.isCheckbox())
2551 return CheckBoxRole;
2552 if (input.isRadioButton())
2553 return RadioButtonRole;
2554 if (input.isTextButton())
2555 return buttonRoleType();
2556 // On iOS, the date field and time field are popup buttons. On other platforms they are text fields.
2558 if (input.isDateField() || input.isTimeField())
2559 return PopUpButtonRole;
2561 #if ENABLE(INPUT_TYPE_COLOR)
2562 if (input.isColorControl())
2563 return ColorWellRole;
2567 if (hasContentEditableAttributeSet())
2568 return TextAreaRole;
2570 if (isFileUploadButton())
2573 if (cssBox && cssBox->isMenuList())
2574 return PopUpButtonRole;
2579 if (m_renderer->isSVGRoot())
2582 if (isStyleFormatGroup())
2586 if (node && node->hasTagName(MathMLNames::mathTag))
2587 return DocumentMathRole;
2589 // It's not clear which role a platform should choose for a math element.
2590 // Declaring a math element role should give flexibility to platforms to choose.
2591 if (isMathElement())
2592 return MathElementRole;
2594 if (node && node->hasTagName(ddTag))
2595 return DescriptionListDetailRole;
2597 if (node && node->hasTagName(dtTag))
2598 return DescriptionListTermRole;
2600 if (node && node->hasTagName(dlTag))
2601 return DescriptionListRole;
2603 // Check for Ruby elements
2604 if (m_renderer->isRubyText())
2605 return RubyTextRole;
2606 if (m_renderer->isRubyBase())
2607 return RubyBaseRole;
2608 if (m_renderer->isRubyRun())
2610 if (m_renderer->isRubyBlock())
2611 return RubyBlockRole;
2612 if (m_renderer->isRubyInline())
2613 return RubyInlineRole;
2615 // This return value is what will be used if AccessibilityTableCell determines
2616 // the cell should not be treated as a cell (e.g. because it is a layout table.
2617 // In ATK, there is a distinction between generic text block elements and other
2618 // generic containers; AX API does not make this distinction.
2619 if (node && (node->hasTagName(tdTag) || node->hasTagName(thTag)))
2620 #if PLATFORM(GTK) || PLATFORM(EFL)
2626 // Table sections should be ignored.
2627 if (m_renderer->isTableSection())
2630 if (m_renderer->isHR())
2631 return HorizontalRuleRole;
2633 if (node && node->hasTagName(pTag))
2634 return ParagraphRole;
2636 if (is<HTMLLabelElement>(node))
2639 if (node && node->hasTagName(dfnTag))
2640 return DefinitionRole;
2642 if (node && node->hasTagName(divTag))
2645 if (is<HTMLFormElement>(node))
2648 if (node && node->hasTagName(articleTag))
2649 return DocumentArticleRole;
2651 if (node && node->hasTagName(mainTag))
2652 return LandmarkMainRole;
2654 if (node && node->hasTagName(navTag))
2655 return LandmarkNavigationRole;
2657 if (node && node->hasTagName(asideTag))
2658 return LandmarkComplementaryRole;
2660 if (node && node->hasTagName(sectionTag))
2661 return DocumentRegionRole;
2663 if (node && node->hasTagName(addressTag))
2664 return LandmarkContentInfoRole;
2666 if (node && node->hasTagName(blockquoteTag))
2667 return BlockquoteRole;
2669 if (node && node->hasTagName(captionTag))
2672 if (node && node->hasTagName(preTag))
2675 if (is<HTMLDetailsElement>(node))
2677 if (is<HTMLSummaryElement>(node))
2681 if (is<HTMLVideoElement>(node))
2683 if (is<HTMLAudioElement>(node))
2687 // The HTML element should not be exposed as an element. That's what the RenderView element does.
2688 if (node && node->hasTagName(htmlTag))
2691 // There should only be one banner/contentInfo per page. If header/footer are being used within an article or section
2692 // then it should not be exposed as whole page's banner/contentInfo
2693 if (node && node->hasTagName(headerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
2694 return LandmarkBannerRole;
2695 if (node && node->hasTagName(footerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
2698 // 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.
2699 if (supportsARIAAttributes() || canSetFocusAttribute())
2702 if (m_renderer->isRenderBlockFlow()) {
2703 #if PLATFORM(GTK) || PLATFORM(EFL)
2704 // For ATK, GroupRole maps to ATK_ROLE_PANEL. Panels are most commonly found (and hence
2705 // expected) in UI elements; not text blocks.
2706 return m_renderer->isAnonymousBlock() ? DivRole : GroupRole;
2712 // InlineRole is the final fallback before assigning UnknownRole to an object. It makes it
2713 // possible to distinguish truly unknown objects from non-focusable inline text elements
2714 // which have an event handler or attribute suggesting possible inclusion by the platform.
2715 if (is<RenderInline>(*m_renderer)
2716 && (hasAttributesRequiredForInclusion()
2717 || (node && node->hasEventListeners())
2718 || (supportsDatetimeAttribute() && !getAttribute(datetimeAttr).isEmpty())))
2724 AccessibilityOrientation AccessibilityRenderObject::orientation() const
2726 const AtomicString& ariaOrientation = getAttribute(aria_orientationAttr);
2727 if (equalLettersIgnoringASCIICase(ariaOrientation, "horizontal"))
2728 return AccessibilityOrientationHorizontal;
2729 if (equalLettersIgnoringASCIICase(ariaOrientation, "vertical"))
2730 return AccessibilityOrientationVertical;
2731 if (equalLettersIgnoringASCIICase(ariaOrientation, "undefined"))
2732 return AccessibilityOrientationUndefined;
2734 // ARIA 1.1 Implicit defaults are defined on some roles.
2735 // http://www.w3.org/TR/wai-aria-1.1/#aria-orientation
2736 if (isScrollbar() || isComboBox() || isListBox() || isMenu() || isTree())
2737 return AccessibilityOrientationVertical;
2739 if (isMenuBar() || isSplitter() || isTabList() || isToolbar())
2740 return AccessibilityOrientationHorizontal;
2742 return AccessibilityObject::orientation();
2745 bool AccessibilityRenderObject::inheritsPresentationalRole() const
2747 // ARIA states if an item can get focus, it should not be presentational.
2748 if (canSetFocusAttribute())
2751 // ARIA spec says that when a parent object is presentational, and it has required child elements,
2752 // those child elements are also presentational. For example, <li> becomes presentational from <ul>.
2753 // http://www.w3.org/WAI/PF/aria/complete#presentation
2754 static NeverDestroyed<HashSet<QualifiedName>> listItemParents;
2755 static NeverDestroyed<HashSet<QualifiedName>> tableCellParents;
2757 HashSet<QualifiedName>* possibleParentTagNames = nullptr;
2758 switch (roleValue()) {
2760 case ListMarkerRole:
2761 if (listItemParents.get().isEmpty()) {
2762 listItemParents.get().add(ulTag);
2763 listItemParents.get().add(olTag);
2764 listItemParents.get().add(dlTag);
2766 possibleParentTagNames = &listItemParents.get();
2770 if (tableCellParents.get().isEmpty())
2771 tableCellParents.get().add(tableTag);
2772 possibleParentTagNames = &tableCellParents.get();
2778 // Not all elements need to check for this, only ones that are required children.
2779 if (!possibleParentTagNames)
2782 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
2783 if (!is<AccessibilityRenderObject>(*parent))
2786 Node* node = downcast<AccessibilityRenderObject>(*parent).node();
2787 if (!is<Element>(node))
2790 // If native tag of the parent element matches an acceptable name, then return
2791 // based on its presentational status.
2792 if (possibleParentTagNames->contains(downcast<Element>(node)->tagQName()))
2793 return parent->roleValue() == PresentationalRole;
2799 bool AccessibilityRenderObject::isPresentationalChildOfAriaRole() const
2801 // Walk the parent chain looking for a parent that has presentational children
2802 AccessibilityObject* parent;
2803 for (parent = parentObject(); parent && !parent->ariaRoleHasPresentationalChildren(); parent = parent->parentObject())
2809 bool AccessibilityRenderObject::ariaRoleHasPresentationalChildren() const
2811 switch (m_ariaRole) {
2815 case ProgressIndicatorRole:
2816 case SpinButtonRole:
2817 // case SeparatorRole:
2824 bool AccessibilityRenderObject::canSetExpandedAttribute() const
2826 if (roleValue() == DetailsRole)
2829 // An object can be expanded if it aria-expanded is true or false.
2830 const AtomicString& ariaExpanded = getAttribute(aria_expandedAttr);
2831 return equalLettersIgnoringASCIICase(ariaExpanded, "true") || equalLettersIgnoringASCIICase(ariaExpanded, "false");
2834 bool AccessibilityRenderObject::canSetValueAttribute() const
2837 // In the event of a (Boolean)@readonly and (True/False/Undefined)@aria-readonly
2838 // value mismatch, the host language native attribute value wins.
2839 if (isNativeTextControl())
2840 return !isReadOnly();
2845 auto& readOnly = getAttribute(aria_readonlyAttr);
2846 if (equalLettersIgnoringASCIICase(readOnly, "true"))
2848 if (equalLettersIgnoringASCIICase(readOnly, "false"))
2851 if (isProgressIndicator() || isSlider())
2854 if (isTextControl() && !isNativeTextControl())
2857 // Any node could be contenteditable, so isReadOnly should be relied upon
2858 // for this information for all elements.
2859 return !isReadOnly();
2862 bool AccessibilityRenderObject::canSetTextRangeAttributes() const
2864 return isTextControl();
2867 void AccessibilityRenderObject::textChanged()
2869 // If this element supports ARIA live regions, or is part of a region with an ARIA editable role,
2870 // then notify the AT of changes.
2871 AXObjectCache* cache = axObjectCache();
2875 for (RenderObject* renderParent = m_renderer; renderParent; renderParent = renderParent->parent()) {
2876 AccessibilityObject* parent = cache->get(renderParent);
2880 if (parent->supportsARIALiveRegion())
2881 cache->postNotification(renderParent, AXObjectCache::AXLiveRegionChanged);
2883 if ((parent->isARIATextControl() || parent->hasContentEditableAttributeSet()) && !parent->isNativeTextControl())
2884 cache->postNotification(renderParent, AXObjectCache::AXValueChanged);
2888 void AccessibilityRenderObject::clearChildren()
2890 AccessibilityObject::clearChildren();
2891 m_childrenDirty = false;
2894 void AccessibilityRenderObject::addImageMapChildren()
2896 RenderBoxModelObject* cssBox = renderBoxModelObject();
2897 if (!is<RenderImage>(cssBox))
2900 HTMLMapElement* map = downcast<RenderImage>(*cssBox).imageMap();
2904 for (auto& area : descendantsOfType<HTMLAreaElement>(*map)) {
2905 // add an <area> element for this child if it has a link
2908 auto& areaObject = downcast<AccessibilityImageMapLink>(*axObjectCache()->getOrCreate(ImageMapLinkRole));
2909 areaObject.setHTMLAreaElement(&area);
2910 areaObject.setHTMLMapElement(map);
2911 areaObject.setParent(this);
2912 if (!areaObject.accessibilityIsIgnored())
2913 m_children.append(&areaObject);
2915 axObjectCache()->remove(areaObject.axObjectID());
2919 void AccessibilityRenderObject::updateChildrenIfNecessary()
2921 if (needsToUpdateChildren())
2924 AccessibilityObject::updateChildrenIfNecessary();
2927 void AccessibilityRenderObject::addTextFieldChildren()
2929 Node* node = this->node();
2930 if (!is<HTMLInputElement>(node))
2933 HTMLInputElement& input = downcast<HTMLInputElement>(*node);
2934 if (HTMLElement* autoFillElement = input.autoFillButtonElement())
2935 m_children.append(axObjectCache()->getOrCreate(autoFillElement));
2937 HTMLElement* spinButtonElement = input.innerSpinButtonElement();
2938 if (!is<SpinButtonElement>(spinButtonElement))
2941 auto& axSpinButton = downcast<AccessibilitySpinButton>(*axObjectCache()->getOrCreate(SpinButtonRole));
2942 axSpinButton.setSpinButtonElement(downcast<SpinButtonElement>(spinButtonElement));
2943 axSpinButton.setParent(this);
2944 m_children.append(&axSpinButton);
2947 bool AccessibilityRenderObject::isSVGImage() const
2949 return remoteSVGRootElement();
2952 void AccessibilityRenderObject::detachRemoteSVGRoot()
2954 if (AccessibilitySVGRoot* root = remoteSVGRootElement())
2955 root->setParent(nullptr);
2958 AccessibilitySVGRoot* AccessibilityRenderObject::remoteSVGRootElement() const
2960 if (!is<RenderImage>(m_renderer))
2963 CachedImage* cachedImage = downcast<RenderImage>(*m_renderer).cachedImage();
2967 Image* image = cachedImage->image();
2968 if (!is<SVGImage>(image))
2971 FrameView* frameView = downcast<SVGImage>(*image).frameView();
2974 Frame& frame = frameView->frame();
2976 Document* document = frame.document();
2977 if (!is<SVGDocument>(document))
2980 SVGSVGElement* rootElement = downcast<SVGDocument>(*document).rootElement();
2983 RenderObject* rendererRoot = rootElement->renderer();
2987 AXObjectCache* cache = frame.document()->axObjectCache();
2990 AccessibilityObject* rootSVGObject = cache->getOrCreate(rendererRoot);
2992 // In order to connect the AX hierarchy from the SVG root element from the loaded resource
2993 // the parent must be set, because there's no other way to get back to who created the image.
2994 ASSERT(rootSVGObject);
2995 if (!is<AccessibilitySVGRoot>(*rootSVGObject))
2998 return downcast<AccessibilitySVGRoot>(rootSVGObject);
3001 void AccessibilityRenderObject::addRemoteSVGChildren()
3003 AccessibilitySVGRoot* root = remoteSVGRootElement();
3007 root->setParent(this);
3009 if (root->accessibilityIsIgnored()) {
3010 for (const auto& child : root->children())
3011 m_children.append(child);
3013 m_children.append(root);
3016 void AccessibilityRenderObject::addCanvasChildren()
3018 // Add the unrendered canvas children as AX nodes, unless we're not using a canvas renderer
3019 // because JS is disabled for example.
3020 if (!node() || !node()->hasTagName(canvasTag) || (renderer() && !renderer()->isCanvas()))
3023 // If it's a canvas, it won't have rendered children, but it might have accessible fallback content.
3024 // Clear m_haveChildren because AccessibilityNodeObject::addChildren will expect it to be false.
3025 ASSERT(!m_children.size());
3026 m_haveChildren = false;
3027 AccessibilityNodeObject::addChildren();
3030 void AccessibilityRenderObject::addAttachmentChildren()
3032 if (!isAttachment())
3035 // FrameView's need to be inserted into the AX hierarchy when encountered.
3036 Widget* widget = widgetForAttachmentView();
3037 if (!widget || !widget->isFrameView())
3040 AccessibilityObject* axWidget = axObjectCache()->getOrCreate(widget);
3041 if (!axWidget->accessibilityIsIgnored())
3042 m_children.append(axWidget);
3046 void AccessibilityRenderObject::updateAttachmentViewParents()
3048 // Only the unignored parent should set the attachment parent, because that's what is reflected in the AX
3049 // hierarchy to the client.
3050 if (accessibilityIsIgnored())
3053 for (const auto& child : m_children) {
3054 if (child->isAttachment())
3055 child->overrideAttachmentParent(this);
3060 // Hidden children are those that are not rendered or visible, but are specifically marked as aria-hidden=false,
3061 // meaning that they should be exposed to the AX hierarchy.
3062 void AccessibilityRenderObject::addHiddenChildren()
3064 Node* node = this->node();
3068 // First do a quick run through to determine if we have any hidden nodes (most often we will not).
3069 // If we do have hidden nodes, we need to determine where to insert them so they match DOM order as close as possible.
3070 bool shouldInsertHiddenNodes = false;
3071 for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
3072 if (!child->renderer() && isNodeAriaVisible(child)) {
3073 shouldInsertHiddenNodes = true;
3078 if (!shouldInsertHiddenNodes)
3081 // Iterate through all of the children, including those that may have already been added, and
3082 // try to insert hidden nodes in the correct place in the DOM order.
3083 unsigned insertionIndex = 0;
3084 for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
3085 if (child->renderer()) {
3086 // Find out where the last render sibling is located within m_children.
3087 AccessibilityObject* childObject = axObjectCache()->get(child->renderer());
3088 if (childObject && childObject->accessibilityIsIgnored()) {
3089 auto& children = childObject->children();
3090 if (children.size())
3091 childObject = children.last().get();
3093 childObject = nullptr;
3097 insertionIndex = m_children.find(childObject) + 1;
3101 if (!isNodeAriaVisible(child))
3104 unsigned previousSize = m_children.size();
3105 if (insertionIndex > previousSize)
3106 insertionIndex = previousSize;
3108 insertChild(axObjectCache()->getOrCreate(child), insertionIndex);
3109 insertionIndex += (m_children.size() - previousSize);
3113 void AccessibilityRenderObject::updateRoleAfterChildrenCreation()
3115 // If a menu does not have valid menuitem children, it should not be exposed as a menu.
3116 if (roleValue() == MenuRole) {
3117 // Elements marked as menus must have at least one menu item child.
3118 size_t menuItemCount = 0;
3119 for (const auto& child : children()) {
3120 if (child->isMenuItem()) {
3131 void AccessibilityRenderObject::addChildren()
3133 // If the need to add more children in addition to existing children arises,
3134 // childrenChanged should have been called, leaving the object with no children.
3135 ASSERT(!m_haveChildren);
3137 m_haveChildren = true;
3139 if (!canHaveChildren())
3142 for (RefPtr<AccessibilityObject> obj = firstChild(); obj; obj = obj->nextSibling())
3143 addChild(obj.get());
3145 addHiddenChildren();
3146 addAttachmentChildren();
3147 addImageMapChildren();
3148 addTextFieldChildren();
3149 addCanvasChildren();
3150 addRemoteSVGChildren();
3153 updateAttachmentViewParents();
3156 updateRoleAfterChildrenCreation();
3159 bool AccessibilityRenderObject::canHaveChildren() const
3164 return AccessibilityNodeObject::canHaveChildren();
3167 const String AccessibilityRenderObject::ariaLiveRegionStatus() const
3169 const AtomicString& liveRegionStatus = getAttribute(aria_liveAttr);
3170 // These roles have implicit live region status.
3171 if (liveRegionStatus.isEmpty())
3172 return defaultLiveRegionStatusForRole(roleValue());
3174 return liveRegionStatus;
3177 const AtomicString& AccessibilityRenderObject::ariaLiveRegionRelevant() const
3179 static NeverDestroyed<const AtomicString> defaultLiveRegionRelevant("additions text", AtomicString::ConstructFromLiteral);
3180 const AtomicString& relevant = getAttribute(aria_relevantAttr);
3182 // Default aria-relevant = "additions text".
3183 if (relevant.isEmpty())
3184 return defaultLiveRegionRelevant;
3189 bool AccessibilityRenderObject::ariaLiveRegionAtomic() const
3191 const AtomicString& atomic = getAttribute(aria_atomicAttr);
3192 if (equalLettersIgnoringASCIICase(atomic, "true"))
3194 if (equalLettersIgnoringASCIICase(atomic, "false"))
3197 // WAI-ARIA "alert" and "status" roles have an implicit aria-atomic value of true.
3198 switch (roleValue()) {
3199 case ApplicationAlertRole:
3200 case ApplicationStatusRole:
3207 bool AccessibilityRenderObject::ariaLiveRegionBusy() const
3209 return elementAttributeValue(aria_busyAttr);
3212 void AccessibilityRenderObject::ariaSelectedRows(AccessibilityChildrenVector& result)
3214 // Determine which rows are selected.
3215 bool isMulti = isMultiSelectable();
3217 // Prefer active descendant over aria-selected.
3218 AccessibilityObject* activeDesc = activeDescendant();
3219 if (activeDesc && (activeDesc->isTreeItem() || activeDesc->isTableRow())) {
3220 result.append(activeDesc);
3225 // Get all the rows.
3226 auto rowsIteration = [&](const AccessibilityChildrenVector& rows) {
3227 for (auto& row : rows) {
3228 if (row->isSelected()) {
3236 AccessibilityChildrenVector allRows;
3237 ariaTreeRows(allRows);
3238 rowsIteration(allRows);
3239 } else if (is<AccessibilityTable>(*this)) {
3240 auto& thisTable = downcast<AccessibilityTable>(*this);
3241 if (thisTable.isExposableThroughAccessibility() && thisTable.supportsSelectedRows())
3242 rowsIteration(thisTable.rows());
3246 void AccessibilityRenderObject::ariaListboxSelectedChildren(AccessibilityChildrenVector& result)
3248 bool isMulti = isMultiSelectable();
3250 for (const auto& child : children()) {
3251 // Every child should have aria-role option, and if so, check for selected attribute/state.
3252 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRole) {
3253 result.append(child);
3260 void AccessibilityRenderObject::selectedChildren(AccessibilityChildrenVector& result)
3262 ASSERT(result.isEmpty());
3264 // only listboxes should be asked for their selected children.
3265 AccessibilityRole role = roleValue();
3266 if (role == ListBoxRole) /