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 Computer, 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 "EventNames.h"
41 #include "FloatRect.h"
43 #include "FrameLoader.h"
44 #include "FrameSelection.h"
45 #include "HTMLAreaElement.h"
46 #include "HTMLFormElement.h"
47 #include "HTMLFrameElementBase.h"
48 #include "HTMLImageElement.h"
49 #include "HTMLInputElement.h"
50 #include "HTMLLabelElement.h"
51 #include "HTMLMapElement.h"
52 #include "HTMLNames.h"
53 #include "HTMLOptGroupElement.h"
54 #include "HTMLOptionElement.h"
55 #include "HTMLOptionsCollection.h"
56 #include "HTMLSelectElement.h"
57 #include "HTMLTextAreaElement.h"
58 #include "HitTestRequest.h"
59 #include "HitTestResult.h"
61 #include "LocalizedStrings.h"
62 #include "MathMLNames.h"
64 #include "NodeTraversal.h"
66 #include "ProgressTracker.h"
67 #include "RenderButton.h"
68 #include "RenderFieldset.h"
69 #include "RenderFileUploadControl.h"
70 #include "RenderHTMLCanvas.h"
71 #include "RenderImage.h"
72 #include "RenderInline.h"
73 #include "RenderLayer.h"
74 #include "RenderListBox.h"
75 #include "RenderListMarker.h"
76 #include "RenderMathMLBlock.h"
77 #include "RenderMathMLOperator.h"
78 #include "RenderMenuList.h"
79 #include "RenderSVGShape.h"
80 #include "RenderText.h"
81 #include "RenderTextControl.h"
82 #include "RenderTextControlSingleLine.h"
83 #include "RenderTextFragment.h"
84 #include "RenderTheme.h"
85 #include "RenderView.h"
86 #include "RenderWidget.h"
87 #include "RenderedPosition.h"
88 #include "SVGDocument.h"
90 #include "SVGImageChromeClient.h"
92 #include "SVGSVGElement.h"
94 #include "TextControlInnerElements.h"
95 #include "VisibleUnits.h"
96 #include "htmlediting.h"
97 #include <wtf/StdLibExtras.h>
98 #include <wtf/text/StringBuilder.h>
99 #include <wtf/unicode/CharacterNames.h>
105 using namespace HTMLNames;
107 AccessibilityRenderObject::AccessibilityRenderObject(RenderObject* renderer)
108 : AccessibilityNodeObject(renderer->node())
109 , m_renderer(renderer)
112 m_renderer->setHasAXObject(true);
116 AccessibilityRenderObject::~AccessibilityRenderObject()
118 ASSERT(isDetached());
121 void AccessibilityRenderObject::init()
123 AccessibilityNodeObject::init();
126 PassRefPtr<AccessibilityRenderObject> AccessibilityRenderObject::create(RenderObject* renderer)
128 return adoptRef(new AccessibilityRenderObject(renderer));
131 void AccessibilityRenderObject::detach()
133 AccessibilityNodeObject::detach();
135 detachRemoteSVGRoot();
139 m_renderer->setHasAXObject(false);
144 RenderBoxModelObject* AccessibilityRenderObject::renderBoxModelObject() const
146 if (!m_renderer || !m_renderer->isBoxModelObject())
148 return toRenderBoxModelObject(m_renderer);
151 void AccessibilityRenderObject::setRenderer(RenderObject* renderer)
153 m_renderer = renderer;
154 setNode(renderer->node());
157 static inline bool isInlineWithContinuation(RenderObject* object)
159 if (!object->isBoxModelObject())
162 RenderBoxModelObject* renderer = toRenderBoxModelObject(object);
163 if (!renderer->isRenderInline())
166 return toRenderInline(renderer)->continuation();
169 static inline RenderObject* firstChildInContinuation(RenderObject* renderer)
171 RenderObject* r = toRenderInline(renderer)->continuation();
174 if (r->isRenderBlock())
176 if (RenderObject* child = r->firstChild())
178 r = toRenderInline(r)->continuation();
184 static inline RenderObject* firstChildConsideringContinuation(RenderObject* renderer)
186 RenderObject* firstChild = renderer->firstChild();
188 if (!firstChild && isInlineWithContinuation(renderer))
189 firstChild = firstChildInContinuation(renderer);
195 static inline RenderObject* lastChildConsideringContinuation(RenderObject* renderer)
197 RenderObject* lastChild = renderer->lastChild();
199 RenderObject* cur = renderer;
201 if (!cur->isRenderInline() && !cur->isRenderBlock())
207 if (RenderObject* lc = cur->lastChild())
210 if (cur->isRenderInline()) {
211 cur = toRenderInline(cur)->inlineElementContinuation();
212 ASSERT_UNUSED(prev, cur || !toRenderInline(prev)->continuation());
214 cur = toRenderBlock(cur)->inlineElementContinuation();
220 AccessibilityObject* AccessibilityRenderObject::firstChild() const
225 RenderObject* firstChild = firstChildConsideringContinuation(m_renderer);
230 return axObjectCache()->getOrCreate(firstChild);
233 AccessibilityObject* AccessibilityRenderObject::lastChild() const
238 RenderObject* lastChild = lastChildConsideringContinuation(m_renderer);
243 return axObjectCache()->getOrCreate(lastChild);
246 static inline RenderInline* startOfContinuations(RenderObject* r)
248 if (r->isInlineElementContinuation()) {
250 // MathML elements make anonymous RenderObjects, then set their node to the parent's node.
251 // This makes it so that the renderer() != renderer()->node()->renderer()
252 // (which is what isInlineElementContinuation() uses as a determinant).
253 if (r->node()->isElementNode() && toElement(r->node())->isMathMLElement())
257 return toRenderInline(r->node()->renderer());
260 // Blocks with a previous continuation always have a next continuation
261 if (r->isRenderBlock() && toRenderBlock(r)->inlineElementContinuation())
262 return toRenderInline(toRenderBlock(r)->inlineElementContinuation()->node()->renderer());
267 static inline RenderObject* endOfContinuations(RenderObject* renderer)
269 RenderObject* prev = renderer;
270 RenderObject* cur = renderer;
272 if (!cur->isRenderInline() && !cur->isRenderBlock())
277 if (cur->isRenderInline()) {
278 cur = toRenderInline(cur)->inlineElementContinuation();
279 ASSERT(cur || !toRenderInline(prev)->continuation());
281 cur = toRenderBlock(cur)->inlineElementContinuation();
288 static inline RenderObject* childBeforeConsideringContinuations(RenderInline* r, RenderObject* child)
290 RenderBoxModelObject* curContainer = r;
291 RenderObject* cur = 0;
292 RenderObject* prev = 0;
294 while (curContainer) {
295 if (curContainer->isRenderInline()) {
296 cur = curContainer->firstChild();
301 cur = cur->nextSibling();
304 curContainer = toRenderInline(curContainer)->continuation();
305 } else if (curContainer->isRenderBlock()) {
306 if (curContainer == child)
310 curContainer = toRenderBlock(curContainer)->inlineElementContinuation();
314 ASSERT_NOT_REACHED();
319 static inline bool firstChildIsInlineContinuation(RenderObject* renderer)
321 return renderer->firstChild() && renderer->firstChild()->isInlineElementContinuation();
324 AccessibilityObject* AccessibilityRenderObject::previousSibling() const
329 RenderObject* previousSibling = 0;
331 // Case 1: The node is a block and is an inline's continuation. In that case, the inline's
332 // last child is our previous sibling (or further back in the continuation chain)
333 RenderInline* startOfConts;
334 if (m_renderer->isRenderBlock() && (startOfConts = startOfContinuations(m_renderer)))
335 previousSibling = childBeforeConsideringContinuations(startOfConts, m_renderer);
337 // Case 2: Anonymous block parent of the end of a continuation - skip all the way to before
338 // the parent of the start, since everything in between will be linked up via the continuation.
339 else if (m_renderer->isAnonymousBlock() && firstChildIsInlineContinuation(m_renderer)) {
340 RenderObject* firstParent = startOfContinuations(m_renderer->firstChild())->parent();
341 while (firstChildIsInlineContinuation(firstParent))
342 firstParent = startOfContinuations(firstParent->firstChild())->parent();
343 previousSibling = firstParent->previousSibling();
346 // Case 3: The node has an actual previous sibling
347 else if (RenderObject* ps = m_renderer->previousSibling())
348 previousSibling = ps;
350 // Case 4: This node has no previous siblings, but its parent is an inline,
351 // and is another node's inline continutation. Follow the continuation chain.
352 else if (m_renderer->parent()->isRenderInline() && (startOfConts = startOfContinuations(m_renderer->parent())))
353 previousSibling = childBeforeConsideringContinuations(startOfConts, m_renderer->parent()->firstChild());
355 if (!previousSibling)
358 return axObjectCache()->getOrCreate(previousSibling);
361 static inline bool lastChildHasContinuation(RenderObject* renderer)
363 return renderer->lastChild() && isInlineWithContinuation(renderer->lastChild());
366 AccessibilityObject* AccessibilityRenderObject::nextSibling() const
371 RenderObject* nextSibling = 0;
373 // Case 1: node is a block and has an inline continuation. Next sibling is the inline continuation's
375 RenderInline* inlineContinuation;
376 if (m_renderer->isRenderBlock() && (inlineContinuation = toRenderBlock(m_renderer)->inlineElementContinuation()))
377 nextSibling = firstChildConsideringContinuation(inlineContinuation);
379 // Case 2: Anonymous block parent of the start of a continuation - skip all the way to
380 // after the parent of the end, since everything in between will be linked up via the continuation.
381 else if (m_renderer->isAnonymousBlock() && lastChildHasContinuation(m_renderer)) {
382 RenderObject* lastParent = endOfContinuations(m_renderer->lastChild())->parent();
383 while (lastChildHasContinuation(lastParent))
384 lastParent = endOfContinuations(lastParent->lastChild())->parent();
385 nextSibling = lastParent->nextSibling();
388 // Case 3: node has an actual next sibling
389 else if (RenderObject* ns = m_renderer->nextSibling())
392 // Case 4: node is an inline with a continuation. Next sibling is the next sibling of the end
393 // of the continuation chain.
394 else if (isInlineWithContinuation(m_renderer))
395 nextSibling = endOfContinuations(m_renderer)->nextSibling();
397 // Case 5: node has no next sibling, and its parent is an inline with a continuation.
398 else if (isInlineWithContinuation(m_renderer->parent())) {
399 RenderObject* continuation = toRenderInline(m_renderer->parent())->continuation();
401 // Case 5a: continuation is a block - in this case the block itself is the next sibling.
402 if (continuation->isRenderBlock())
403 nextSibling = continuation;
404 // Case 5b: continuation is an inline - in this case the inline's first child is the next sibling
406 nextSibling = firstChildConsideringContinuation(continuation);
412 return axObjectCache()->getOrCreate(nextSibling);
415 static RenderBoxModelObject* nextContinuation(RenderObject* renderer)
418 if (renderer->isRenderInline() && !renderer->isReplaced())
419 return toRenderInline(renderer)->continuation();
420 if (renderer->isRenderBlock())
421 return toRenderBlock(renderer)->inlineElementContinuation();
425 RenderObject* AccessibilityRenderObject::renderParentObject() const
430 RenderObject* parent = m_renderer->parent();
432 // Case 1: node is a block and is an inline's continuation. Parent
433 // is the start of the continuation chain.
434 RenderObject* startOfConts = 0;
435 RenderObject* firstChild = 0;
436 if (m_renderer->isRenderBlock() && (startOfConts = startOfContinuations(m_renderer)))
437 parent = startOfConts;
439 // Case 2: node's parent is an inline which is some node's continuation; parent is
440 // the earliest node in the continuation chain.
441 else if (parent && parent->isRenderInline() && (startOfConts = startOfContinuations(parent)))
442 parent = startOfConts;
444 // Case 3: The first sibling is the beginning of a continuation chain. Find the origin of that continuation.
445 else if (parent && (firstChild = parent->firstChild()) && firstChild->node()) {
446 // Get the node's renderer and follow that continuation chain until the first child is found
447 RenderObject* nodeRenderFirstChild = firstChild->node()->renderer();
448 while (nodeRenderFirstChild != firstChild) {
449 for (RenderObject* contsTest = nodeRenderFirstChild; contsTest; contsTest = nextContinuation(contsTest)) {
450 if (contsTest == firstChild) {
451 parent = nodeRenderFirstChild->parent();
455 if (firstChild == parent->firstChild())
457 firstChild = parent->firstChild();
458 if (!firstChild->node())
460 nodeRenderFirstChild = firstChild->node()->renderer();
467 AccessibilityObject* AccessibilityRenderObject::parentObjectIfExists() const
469 // WebArea's parent should be the scroll view containing it.
470 if (isWebArea() || isSeamlessWebArea())
471 return axObjectCache()->get(m_renderer->frame()->view());
473 return axObjectCache()->get(renderParentObject());
476 AccessibilityObject* AccessibilityRenderObject::parentObject() const
481 if (ariaRoleAttribute() == MenuBarRole)
482 return axObjectCache()->getOrCreate(m_renderer->parent());
484 // menuButton and its corresponding menu are DOM siblings, but Accessibility needs them to be parent/child
485 if (ariaRoleAttribute() == MenuRole) {
486 AccessibilityObject* parent = menuButtonForMenu();
491 RenderObject* parentObj = renderParentObject();
493 return axObjectCache()->getOrCreate(parentObj);
495 // WebArea's parent should be the scroll view containing it.
496 if (isWebArea() || isSeamlessWebArea())
497 return axObjectCache()->getOrCreate(m_renderer->frame()->view());
502 bool AccessibilityRenderObject::isAttachment() const
504 RenderBoxModelObject* renderer = renderBoxModelObject();
507 // Widgets are the replaced elements that we represent to AX as attachments
508 bool isWidget = renderer->isWidget();
509 ASSERT(!isWidget || (renderer->isReplaced() && !isImage()));
510 return isWidget && ariaRoleAttribute() == UnknownRole;
513 bool AccessibilityRenderObject::isFileUploadButton() const
515 if (m_renderer && m_renderer->node() && m_renderer->node()->hasTagName(inputTag)) {
516 HTMLInputElement* input = static_cast<HTMLInputElement*>(m_renderer->node());
517 return input->isFileUpload();
523 bool AccessibilityRenderObject::isReadOnly() const
528 Document* document = m_renderer->document();
532 HTMLElement* body = document->body();
533 if (body && body->rendererIsEditable())
536 return !document->rendererIsEditable();
539 return AccessibilityNodeObject::isReadOnly();
542 bool AccessibilityRenderObject::isOffScreen() const
545 IntRect contentRect = pixelSnappedIntRect(m_renderer->absoluteClippedOverflowRect());
546 FrameView* view = m_renderer->frame()->view();
547 IntRect viewRect = view->visibleContentRect();
548 viewRect.intersect(contentRect);
549 return viewRect.isEmpty();
552 Element* AccessibilityRenderObject::anchorElement() const
557 AXObjectCache* cache = axObjectCache();
558 RenderObject* currRenderer;
560 // Search up the render tree for a RenderObject with a DOM node. Defer to an earlier continuation, though.
561 for (currRenderer = m_renderer; currRenderer && !currRenderer->node(); currRenderer = currRenderer->parent()) {
562 if (currRenderer->isAnonymousBlock()) {
563 RenderObject* continuation = toRenderBlock(currRenderer)->continuation();
565 return cache->getOrCreate(continuation)->anchorElement();
569 // bail if none found
573 // search up the DOM tree for an anchor element
574 // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElement
575 Node* node = currRenderer->node();
576 for ( ; node; node = node->parentNode()) {
577 if (node->hasTagName(aTag) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
578 return toElement(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* curr = m_renderer; curr; curr = curr->parent()) {
599 if (curr->node() && curr->node()->isHTMLElement()) {
600 const AtomicString& summary = toElement(curr->node())->getAttribute(summaryAttr);
601 if (!summary.isEmpty())
604 // The title attribute should be used as help text unless it is already being used as descriptive text.
605 const AtomicString& title = toElement(curr->node())->getAttribute(titleAttr);
606 if (!title.isEmpty() && description != title)
610 // Only take help text from an ancestor element if its a group or an unknown role. If help was
611 // added to those kinds of elements, it is likely it was meant for a child element.
612 AccessibilityObject* axObj = axObjectCache()->getOrCreate(curr);
614 AccessibilityRole role = axObj->roleValue();
615 if (role != GroupRole && role != UnknownRole)
623 String AccessibilityRenderObject::textUnderElement() const
628 if (m_renderer->isFileUploadControl())
629 return toRenderFileUploadControl(m_renderer)->buttonValue();
632 // Math operators create RenderText nodes on the fly that are not tied into the DOM in a reasonable way,
633 // so rangeOfContents does not work for them (nor does regular text selection).
634 if (m_renderer->isText() && isMathElement()) {
635 for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
636 if (parent->isRenderMathMLBlock() && toRenderMathMLBlock(parent)->isRenderMathMLOperator())
637 return toRenderText(m_renderer)->text();
643 // On GTK, always use a text iterator in order to get embedded object characters.
644 // TODO: Add support for embedded object characters to the other codepaths that try
645 // to build the accessible text recursively, so this special case isn't needed.
646 // https://bugs.webkit.org/show_bug.cgi?id=105214
647 if (Node* node = this->node()) {
648 if (Frame* frame = node->document()->frame()) {
649 // catch stale WebCoreAXObject (see <rdar://problem/3960196>)
650 if (frame->document() != node->document())
653 return plainText(rangeOfContents(node).get(), textIteratorBehaviorForTextRange());
658 if (m_renderer->isText()) {
659 // If possible, use a text iterator to get the text, so that whitespace
660 // is handled consistently.
661 if (Node* node = this->node()) {
662 if (Frame* frame = node->document()->frame()) {
663 // catch stale WebCoreAXObject (see <rdar://problem/3960196>)
664 if (frame->document() != node->document())
667 return plainText(rangeOfContents(node).get(), textIteratorBehaviorForTextRange());
671 // Sometimes text fragments don't have Nodes associated with them (like when
672 // CSS content is used to insert text or when a RenderCounter is used.)
673 RenderText* renderTextObject = toRenderText(m_renderer);
674 if (renderTextObject->isTextFragment())
675 return String(static_cast<RenderTextFragment*>(m_renderer)->contentString());
677 return String(renderTextObject->text());
680 return AccessibilityNodeObject::textUnderElement();
683 Node* AccessibilityRenderObject::node() const
685 return m_renderer ? m_renderer->node() : 0;
688 String AccessibilityRenderObject::stringValue() const
693 if (isPasswordField())
694 return passwordFieldValue();
696 RenderBoxModelObject* cssBox = renderBoxModelObject();
698 if (ariaRoleAttribute() == StaticTextRole) {
699 String staticText = text();
700 if (!staticText.length())
701 staticText = textUnderElement();
705 if (m_renderer->isText())
706 return textUnderElement();
708 if (cssBox && cssBox->isMenuList()) {
709 // RenderMenuList will go straight to the text() of its selected item.
710 // This has to be overridden in the case where the selected item has an ARIA label.
711 HTMLSelectElement* selectElement = toHTMLSelectElement(m_renderer->node());
712 int selectedIndex = selectElement->selectedIndex();
713 const Vector<HTMLElement*> listItems = selectElement->listItems();
714 if (selectedIndex >= 0 && static_cast<size_t>(selectedIndex) < listItems.size()) {
715 const AtomicString& overriddenDescription = listItems[selectedIndex]->fastGetAttribute(aria_labelAttr);
716 if (!overriddenDescription.isNull())
717 return overriddenDescription;
719 return toRenderMenuList(m_renderer)->text();
722 if (m_renderer->isListMarker())
723 return toRenderListMarker(m_renderer)->text();
726 // FIXME: Why would a renderer exist when the Document isn't attached to a frame?
727 if (m_renderer->frame())
730 ASSERT_NOT_REACHED();
736 if (m_renderer->isFileUploadControl())
737 return toRenderFileUploadControl(m_renderer)->fileTextValue();
739 // FIXME: We might need to implement a value here for more types
740 // FIXME: It would be better not to advertise a value at all for the types for which we don't implement one;
741 // this would require subclassing or making accessibilityAttributeNames do something other than return a
742 // single static array.
746 HTMLLabelElement* AccessibilityRenderObject::labelElementContainer() const
751 // the control element should not be considered part of the label
755 // find if this has a parent that is a label
756 for (Node* parentNode = m_renderer->node(); parentNode; parentNode = parentNode->parentNode()) {
757 if (parentNode->hasTagName(labelTag))
758 return static_cast<HTMLLabelElement*>(parentNode);
764 // The boundingBox for elements within the remote SVG element needs to be offset by its position
765 // within the parent page, otherwise they are in relative coordinates only.
766 void AccessibilityRenderObject::offsetBoundingBoxForRemoteSVGElement(LayoutRect& rect) const
768 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
769 if (parent->isAccessibilitySVGRoot()) {
770 rect.moveBy(parent->parentObject()->boundingBoxRect().location());
776 LayoutRect AccessibilityRenderObject::boundingBoxRect() const
778 RenderObject* obj = m_renderer;
783 if (obj->node()) // If we are a continuation, we want to make sure to use the primary renderer.
784 obj = obj->node()->renderer();
786 // absoluteFocusRingQuads will query the hierarchy below this element, which for large webpages can be very slow.
787 // For a web area, which will have the most elements of any element, absoluteQuads should be used.
788 // We should also use absoluteQuads for SVG elements, otherwise transforms won't be applied.
789 Vector<FloatQuad> quads;
790 bool isSVGRoot = false;
792 if (obj->isSVGRoot())
796 toRenderText(obj)->absoluteQuads(quads, 0, RenderText::ClipToEllipsis);
797 else if (isWebArea() || isSeamlessWebArea() || isSVGRoot)
798 obj->absoluteQuads(quads);
800 obj->absoluteFocusRingQuads(quads);
802 LayoutRect result = boundingBoxForQuads(obj, quads);
805 Document* document = this->document();
806 if (document && document->isSVGDocument())
807 offsetBoundingBoxForRemoteSVGElement(result);
810 // The size of the web area should be the content size, not the clipped size.
811 if ((isWebArea() || isSeamlessWebArea()) && obj->frame()->view())
812 result.setSize(obj->frame()->view()->contentsSize());
817 LayoutRect AccessibilityRenderObject::checkboxOrRadioRect() const
822 HTMLLabelElement* label = labelForElement(toElement(m_renderer->node()));
823 if (!label || !label->renderer())
824 return boundingBoxRect();
826 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementRect();
827 labelRect.unite(boundingBoxRect());
831 LayoutRect AccessibilityRenderObject::elementRect() const
833 // a checkbox or radio button should encompass its label
834 if (isCheckboxOrRadio())
835 return checkboxOrRadioRect();
837 return boundingBoxRect();
840 IntPoint AccessibilityRenderObject::clickPoint()
842 // Headings are usually much wider than their textual content. If the mid point is used, often it can be wrong.
843 if (isHeading() && children().size() == 1)
844 return children()[0]->clickPoint();
846 // use the default position unless this is an editable web area, in which case we use the selection bounds.
847 if (!isWebArea() || isReadOnly())
848 return AccessibilityObject::clickPoint();
850 VisibleSelection visSelection = selection();
851 VisiblePositionRange range = VisiblePositionRange(visSelection.visibleStart(), visSelection.visibleEnd());
852 IntRect bounds = boundsForVisiblePositionRange(range);
854 bounds.setLocation(m_renderer->document()->view()->screenToContents(bounds.location()));
856 return IntPoint(bounds.x() + (bounds.width() / 2), bounds.y() - (bounds.height() / 2));
859 AccessibilityObject* AccessibilityRenderObject::internalLinkElement() const
861 Element* element = anchorElement();
865 // Right now, we do not support ARIA links as internal link elements
866 if (!element->hasTagName(aTag))
868 HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(element);
870 KURL linkURL = anchor->href();
871 String fragmentIdentifier = linkURL.fragmentIdentifier();
872 if (fragmentIdentifier.isEmpty())
875 // check if URL is the same as current URL
876 KURL documentURL = m_renderer->document()->url();
877 if (!equalIgnoringFragmentIdentifier(documentURL, linkURL))
880 Node* linkedNode = m_renderer->document()->findAnchor(fragmentIdentifier);
884 // The element we find may not be accessible, so find the first accessible object.
885 return firstAccessibleObjectFromNode(linkedNode);
888 ESpeak AccessibilityRenderObject::speakProperty() const
891 return AccessibilityObject::speakProperty();
893 return m_renderer->style()->speak();
896 void AccessibilityRenderObject::addRadioButtonGroupMembers(AccessibilityChildrenVector& linkedUIElements) const
898 if (!m_renderer || roleValue() != RadioButtonRole)
901 Node* node = m_renderer->node();
902 if (!node || !node->hasTagName(inputTag))
905 HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
906 // if there's a form, then this is easy
908 Vector<RefPtr<Node> > formElements;
909 input->form()->getNamedElements(input->name(), formElements);
911 unsigned len = formElements.size();
912 for (unsigned i = 0; i < len; ++i) {
913 Node* associateElement = formElements[i].get();
914 if (AccessibilityObject* object = axObjectCache()->getOrCreate(associateElement))
915 linkedUIElements.append(object);
918 RefPtr<NodeList> list = node->document()->getElementsByTagName("input");
919 unsigned len = list->length();
920 for (unsigned i = 0; i < len; ++i) {
921 if (list->item(i)->hasTagName(inputTag)) {
922 HTMLInputElement* associateElement = static_cast<HTMLInputElement*>(list->item(i));
923 if (associateElement->isRadioButton() && associateElement->name() == input->name()) {
924 if (AccessibilityObject* object = axObjectCache()->getOrCreate(associateElement))
925 linkedUIElements.append(object);
932 // linked ui elements could be all the related radio buttons in a group
933 // or an internal anchor connection
934 void AccessibilityRenderObject::linkedUIElements(AccessibilityChildrenVector& linkedUIElements) const
936 ariaFlowToElements(linkedUIElements);
939 AccessibilityObject* linkedAXElement = internalLinkElement();
941 linkedUIElements.append(linkedAXElement);
944 if (roleValue() == RadioButtonRole)
945 addRadioButtonGroupMembers(linkedUIElements);
948 bool AccessibilityRenderObject::hasTextAlternative() const
950 // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
951 // override the "label" element association.
952 if (!ariaLabeledByAttribute().isEmpty() || !getAttribute(aria_labelAttr).isEmpty())
958 bool AccessibilityRenderObject::ariaHasPopup() const
960 return elementAttributeValue(aria_haspopupAttr);
963 bool AccessibilityRenderObject::supportsARIAFlowTo() const
965 return !getAttribute(aria_flowtoAttr).isEmpty();
968 void AccessibilityRenderObject::ariaFlowToElements(AccessibilityChildrenVector& flowTo) const
970 Vector<Element*> elements;
971 elementsFromAttribute(elements, aria_flowtoAttr);
973 AXObjectCache* cache = axObjectCache();
974 unsigned count = elements.size();
975 for (unsigned k = 0; k < count; ++k) {
976 Element* element = elements[k];
977 AccessibilityObject* flowToElement = cache->getOrCreate(element);
979 flowTo.append(flowToElement);
984 bool AccessibilityRenderObject::supportsARIADropping() const
986 const AtomicString& dropEffect = getAttribute(aria_dropeffectAttr);
987 return !dropEffect.isEmpty();
990 bool AccessibilityRenderObject::supportsARIADragging() const
992 const AtomicString& grabbed = getAttribute(aria_grabbedAttr);
993 return equalIgnoringCase(grabbed, "true") || equalIgnoringCase(grabbed, "false");
996 bool AccessibilityRenderObject::isARIAGrabbed()
998 return elementAttributeValue(aria_grabbedAttr);
1001 void AccessibilityRenderObject::determineARIADropEffects(Vector<String>& effects)
1003 const AtomicString& dropEffects = getAttribute(aria_dropeffectAttr);
1004 if (dropEffects.isEmpty()) {
1009 String dropEffectsString = dropEffects.string();
1010 dropEffectsString.replace('\n', ' ');
1011 dropEffectsString.split(' ', effects);
1014 bool AccessibilityRenderObject::exposesTitleUIElement() const
1019 // If this control is ignored (because it's invisible),
1020 // then the label needs to be exposed so it can be visible to accessibility.
1021 if (accessibilityIsIgnored())
1024 // Checkboxes and radio buttons use the text of their title ui element as their own AXTitle.
1025 // This code controls whether the title ui element should appear in the AX tree (usually, no).
1026 // It should appear if the control already has a label (which will be used as the AXTitle instead).
1027 if (isCheckboxOrRadio())
1028 return hasTextAlternative();
1030 // When controls have their own descriptions, the title element should be ignored.
1031 if (hasTextAlternative())
1037 AccessibilityObject* AccessibilityRenderObject::titleUIElement() const
1042 // if isFieldset is true, the renderer is guaranteed to be a RenderFieldset
1044 return axObjectCache()->getOrCreate(toRenderFieldset(m_renderer)->findLegend(RenderFieldset::IncludeFloatingOrOutOfFlow));
1046 Node* node = m_renderer->node();
1047 if (!node || !node->isElementNode())
1049 HTMLLabelElement* label = labelForElement(toElement(node));
1050 if (label && label->renderer())
1051 return axObjectCache()->getOrCreate(label);
1056 bool AccessibilityRenderObject::isAllowedChildOfTree() const
1058 // Determine if this is in a tree. If so, we apply special behavior to make it work like an AXOutline.
1059 AccessibilityObject* axObj = parentObject();
1060 bool isInTree = false;
1062 if (axObj->isTree()) {
1066 axObj = axObj->parentObject();
1069 // If the object is in a tree, only tree items should be exposed (and the children of tree items).
1071 AccessibilityRole role = roleValue();
1072 if (role != TreeItemRole && role != StaticTextRole)
1078 AccessibilityObjectInclusion AccessibilityRenderObject::defaultObjectInclusion() const
1080 // The following cases can apply to any element that's a subclass of AccessibilityRenderObject.
1083 return IgnoreObject;
1085 if (m_renderer->style()->visibility() != VISIBLE) {
1086 // aria-hidden is meant to override visibility as the determinant in AX hierarchy inclusion.
1087 if (equalIgnoringCase(getAttribute(aria_hiddenAttr), "false"))
1088 return DefaultBehavior;
1090 return IgnoreObject;
1093 return AccessibilityObject::defaultObjectInclusion();
1096 bool AccessibilityRenderObject::computeAccessibilityIsIgnored() const
1099 ASSERT(m_initialized);
1102 // Check first if any of the common reasons cause this element to be ignored.
1103 // Then process other use cases that need to be applied to all the various roles
1104 // that AccessibilityRenderObjects take on.
1105 AccessibilityObjectInclusion decision = defaultObjectInclusion();
1106 if (decision == IncludeObject)
1108 if (decision == IgnoreObject)
1111 // If this element is within a parent that cannot have children, it should not be exposed.
1112 if (isDescendantOfBarrenParent())
1115 if (roleValue() == IgnoredRole)
1118 if (roleValue() == PresentationalRole || inheritsPresentationalRole())
1121 // An ARIA tree can only have tree items and static text as children.
1122 if (!isAllowedChildOfTree())
1125 // Allow the platform to decide if the attachment is ignored or not.
1127 return accessibilityIgnoreAttachment();
1129 // ignore popup menu items because AppKit does
1130 for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
1131 if (parent->isBoxModelObject() && toRenderBoxModelObject(parent)->isMenuList())
1135 // find out if this element is inside of a label element.
1136 // if so, it may be ignored because it's the label for a checkbox or radio button
1137 AccessibilityObject* controlObject = correspondingControlForLabelElement();
1138 if (controlObject && !controlObject->exposesTitleUIElement() && controlObject->isCheckboxOrRadio())
1141 // NOTE: BRs always have text boxes now, so the text box check here can be removed
1142 if (m_renderer->isText()) {
1143 // static text beneath MenuItems and MenuButtons are just reported along with the menu item, so it's ignored on an individual level
1144 AccessibilityObject* parent = parentObjectUnignored();
1145 if (parent && (parent->ariaRoleAttribute() == MenuItemRole || parent->ariaRoleAttribute() == MenuButtonRole))
1147 RenderText* renderText = toRenderText(m_renderer);
1148 if (m_renderer->isBR() || !renderText->firstTextBox())
1151 // static text beneath TextControls is reported along with the text control text so it's ignored.
1152 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
1153 if (parent->roleValue() == TextFieldRole)
1157 // text elements that are just empty whitespace should not be returned
1158 return renderText->text()->containsOnlyWhitespace();
1167 // all controls are accessible
1171 if (ariaRoleAttribute() != UnknownRole)
1174 // don't ignore labels, because they serve as TitleUIElements
1175 Node* node = m_renderer->node();
1176 if (node && node->hasTagName(labelTag))
1179 // Anything that is content editable should not be ignored.
1180 // However, one cannot just call node->rendererIsEditable() since that will ask if its parents
1181 // are also editable. Only the top level content editable region should be exposed.
1182 if (hasContentEditableAttributeSet())
1185 // List items play an important role in defining the structure of lists. They should not be ignored.
1186 if (roleValue() == ListItemRole)
1189 // if this element has aria attributes on it, it should not be ignored.
1190 if (supportsARIAAttributes())
1194 // First check if this is a special case within the math tree that needs to be ignored.
1195 if (isIgnoredElementWithinMathTree())
1197 // Otherwise all other math elements are in the tree.
1198 if (isMathElement())
1202 // <span> tags are inline tags and not meant to convey information if they have no other aria
1203 // information on them. If we don't ignore them, they may emit signals expected to come from
1204 // their parent. In addition, because included spans are GroupRole objects, and GroupRole
1205 // objects are often containers with meaningful information, the inclusion of a span can have
1206 // the side effect of causing the immediate parent accessible to be ignored. This is especially
1207 // problematic for platforms which have distinct roles for textual block elements.
1208 if (node && node->hasTagName(spanTag))
1211 if (m_renderer->isBlockFlow() && m_renderer->childrenInline() && !canSetFocusAttribute())
1212 return !toRenderBlock(m_renderer)->firstLineBox() && !mouseButtonListener();
1214 // ignore images seemingly used as spacers
1217 // If the image can take focus, it should not be ignored, lest the user not be able to interact with something important.
1218 if (canSetFocusAttribute())
1221 if (node && node->isElementNode()) {
1222 Element* elt = toElement(node);
1223 const AtomicString& alt = elt->getAttribute(altAttr);
1224 // don't ignore an image that has an alt tag
1225 if (!alt.string().containsOnlyWhitespace())
1227 // informal standard is to ignore images with zero-length alt strings
1232 if (isNativeImage()) {
1233 // check for one-dimensional image
1234 RenderImage* image = toRenderImage(m_renderer);
1235 if (image->height() <= 1 || image->width() <= 1)
1238 // check whether rendered image was stretched from one-dimensional file image
1239 if (image->cachedImage()) {
1240 LayoutSize imageSize = image->cachedImage()->imageSizeForRenderer(m_renderer, image->view()->zoomFactor());
1241 return imageSize.height() <= 1 || imageSize.width() <= 1;
1248 if (canvasHasFallbackContent())
1250 RenderHTMLCanvas* canvas = toRenderHTMLCanvas(m_renderer);
1251 if (canvas->height() <= 1 || canvas->width() <= 1)
1253 // Otherwise fall through; use presence of help text, title, or description to decide.
1256 if (isWebArea() || isSeamlessWebArea() || m_renderer->isListMarker())
1259 // Using the help text, title or accessibility description (so we
1260 // check if there's some kind of accessible name for the element)
1261 // to decide an element's visibility is not as definitive as
1262 // previous checks, so this should remain as one of the last.
1264 // These checks are simplified in the interest of execution speed;
1265 // for example, any element having an alt attribute will make it
1266 // not ignored, rather than just images.
1267 if (!getAttribute(aria_helpAttr).isEmpty() || !getAttribute(aria_describedbyAttr).isEmpty() || !getAttribute(altAttr).isEmpty() || !getAttribute(titleAttr).isEmpty())
1270 // Don't ignore generic focusable elements like <div tabindex=0>
1271 // unless they're completely empty, with no children.
1272 if (isGenericFocusableElement() && node->firstChild())
1275 if (!ariaAccessibilityDescription().isEmpty())
1279 if (!getAttribute(MathMLNames::alttextAttr).isEmpty())
1283 // By default, objects should be ignored so that the AX hierarchy is not
1284 // filled with unnecessary items.
1288 bool AccessibilityRenderObject::isLoaded() const
1290 return !m_renderer->document()->parser();
1293 double AccessibilityRenderObject::estimatedLoadingProgress() const
1301 Page* page = m_renderer->document()->page();
1305 return page->progress()->estimatedProgress();
1308 int AccessibilityRenderObject::layoutCount() const
1310 if (!m_renderer->isRenderView())
1312 return toRenderView(m_renderer)->frameView()->layoutCount();
1315 String AccessibilityRenderObject::text() const
1317 if (isPasswordField())
1318 return passwordFieldValue();
1320 return AccessibilityNodeObject::text();
1323 int AccessibilityRenderObject::textLength() const
1325 ASSERT(isTextControl());
1327 if (isPasswordField())
1329 return passwordFieldValue().length();
1331 return -1; // need to return something distinct from 0
1334 return text().length();
1337 PlainTextRange AccessibilityRenderObject::ariaSelectedTextRange() const
1339 Node* node = m_renderer->node();
1341 return PlainTextRange();
1343 VisibleSelection visibleSelection = selection();
1344 RefPtr<Range> currentSelectionRange = visibleSelection.toNormalizedRange();
1345 if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, IGNORE_EXCEPTION))
1346 return PlainTextRange();
1348 int start = indexForVisiblePosition(visibleSelection.start());
1349 int end = indexForVisiblePosition(visibleSelection.end());
1351 return PlainTextRange(start, end - start);
1354 String AccessibilityRenderObject::selectedText() const
1356 ASSERT(isTextControl());
1358 if (isPasswordField())
1359 return String(); // need to return something distinct from empty string
1361 if (isNativeTextControl()) {
1362 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1363 return textControl->selectedText();
1366 if (ariaRoleAttribute() == UnknownRole)
1369 return doAXStringForRange(ariaSelectedTextRange());
1372 const AtomicString& AccessibilityRenderObject::accessKey() const
1374 Node* node = m_renderer->node();
1377 if (!node->isElementNode())
1379 return toElement(node)->getAttribute(accesskeyAttr);
1382 VisibleSelection AccessibilityRenderObject::selection() const
1384 return m_renderer->frame()->selection()->selection();
1387 PlainTextRange AccessibilityRenderObject::selectedTextRange() const
1389 ASSERT(isTextControl());
1391 if (isPasswordField())
1392 return PlainTextRange();
1394 AccessibilityRole ariaRole = ariaRoleAttribute();
1395 if (isNativeTextControl() && ariaRole == UnknownRole) {
1396 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1397 return PlainTextRange(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());
1400 if (ariaRole == UnknownRole)
1401 return PlainTextRange();
1403 return ariaSelectedTextRange();
1406 void AccessibilityRenderObject::setSelectedTextRange(const PlainTextRange& range)
1408 if (isNativeTextControl()) {
1409 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1410 textControl->setSelectionRange(range.start, range.start + range.length);
1414 Document* document = m_renderer->document();
1417 Frame* frame = document->frame();
1420 Node* node = m_renderer->node();
1421 frame->selection()->setSelection(VisibleSelection(Position(node, range.start, Position::PositionIsOffsetInAnchor),
1422 Position(node, range.start + range.length, Position::PositionIsOffsetInAnchor), DOWNSTREAM));
1425 KURL AccessibilityRenderObject::url() const
1427 if (isAnchor() && m_renderer->node()->hasTagName(aTag)) {
1428 if (HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(anchorElement()))
1429 return anchor->href();
1433 return m_renderer->document()->url();
1435 if (isImage() && m_renderer->node() && m_renderer->node()->hasTagName(imgTag))
1436 return static_cast<HTMLImageElement*>(m_renderer->node())->src();
1439 return static_cast<HTMLInputElement*>(m_renderer->node())->src();
1444 bool AccessibilityRenderObject::isUnvisited() const
1446 // FIXME: Is it a privacy violation to expose unvisited information to accessibility APIs?
1447 return m_renderer->style()->isLink() && m_renderer->style()->insideLink() == InsideUnvisitedLink;
1450 bool AccessibilityRenderObject::isVisited() const
1452 // FIXME: Is it a privacy violation to expose visited information to accessibility APIs?
1453 return m_renderer->style()->isLink() && m_renderer->style()->insideLink() == InsideVisitedLink;
1456 void AccessibilityRenderObject::setElementAttributeValue(const QualifiedName& attributeName, bool value)
1461 Node* node = m_renderer->node();
1462 if (!node || !node->isElementNode())
1465 Element* element = toElement(node);
1466 element->setAttribute(attributeName, (value) ? "true" : "false");
1469 bool AccessibilityRenderObject::elementAttributeValue(const QualifiedName& attributeName) const
1474 return equalIgnoringCase(getAttribute(attributeName), "true");
1477 bool AccessibilityRenderObject::isSelected() const
1482 Node* node = m_renderer->node();
1486 const AtomicString& ariaSelected = getAttribute(aria_selectedAttr);
1487 if (equalIgnoringCase(ariaSelected, "true"))
1490 if (isTabItem() && isTabItemSelected())
1496 bool AccessibilityRenderObject::isTabItemSelected() const
1498 if (!isTabItem() || !m_renderer)
1501 Node* node = m_renderer->node();
1502 if (!node || !node->isElementNode())
1505 // The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel
1506 // that has keyboard focus inside of it, or if a tabpanel in its aria-controls list has KB
1507 // focus inside of it.
1508 AccessibilityObject* focusedElement = focusedUIElement();
1509 if (!focusedElement)
1512 Vector<Element*> elements;
1513 elementsFromAttribute(elements, aria_controlsAttr);
1515 unsigned count = elements.size();
1516 for (unsigned k = 0; k < count; ++k) {
1517 Element* element = elements[k];
1518 AccessibilityObject* tabPanel = axObjectCache()->getOrCreate(element);
1520 // A tab item should only control tab panels.
1521 if (!tabPanel || tabPanel->roleValue() != TabPanelRole)
1524 AccessibilityObject* checkFocusElement = focusedElement;
1525 // Check if the focused element is a descendant of the element controlled by the tab item.
1526 while (checkFocusElement) {
1527 if (tabPanel == checkFocusElement)
1529 checkFocusElement = checkFocusElement->parentObject();
1536 bool AccessibilityRenderObject::isFocused() const
1541 Document* document = m_renderer->document();
1545 Node* focusedNode = document->focusedNode();
1549 // A web area is represented by the Document node in the DOM tree, which isn't focusable.
1550 // Check instead if the frame's selection controller is focused
1551 if (focusedNode == m_renderer->node()
1552 || (roleValue() == WebAreaRole && document->frame()->selection()->isFocusedAndActive()))
1558 void AccessibilityRenderObject::setFocused(bool on)
1560 if (!canSetFocusAttribute())
1563 Document* document = this->document();
1565 document->setFocusedNode(0);
1567 Node* node = this->node();
1568 if (node && node->isElementNode()) {
1569 // If this node is already the currently focused node, then calling focus() won't do anything.
1570 // That is a problem when focus is removed from the webpage to chrome, and then returns.
1571 // In these cases, we need to do what keyboard and mouse focus do, which is reset focus first.
1572 if (document->focusedNode() == node)
1573 document->setFocusedNode(0);
1575 toElement(node)->focus();
1577 document->setFocusedNode(node);
1581 void AccessibilityRenderObject::setSelectedRows(AccessibilityChildrenVector& selectedRows)
1583 // Setting selected only makes sense in trees and tables (and tree-tables).
1584 AccessibilityRole role = roleValue();
1585 if (role != TreeRole && role != TreeGridRole && role != TableRole)
1588 bool isMulti = isMultiSelectable();
1589 unsigned count = selectedRows.size();
1590 if (count > 1 && !isMulti)
1593 for (unsigned k = 0; k < count; ++k)
1594 selectedRows[k]->setSelected(true);
1597 void AccessibilityRenderObject::setValue(const String& string)
1599 if (!m_renderer || !m_renderer->node() || !m_renderer->node()->isElementNode())
1601 Element* element = toElement(m_renderer->node());
1603 if (!m_renderer->isBoxModelObject())
1605 RenderBoxModelObject* renderer = toRenderBoxModelObject(m_renderer);
1607 // FIXME: Do we want to do anything here for ARIA textboxes?
1608 if (renderer->isTextField()) {
1609 // FIXME: This is not safe! Other elements could have a TextField renderer.
1610 static_cast<HTMLInputElement*>(element)->setValue(string);
1611 } else if (renderer->isTextArea()) {
1612 // FIXME: This is not safe! Other elements could have a TextArea renderer.
1613 static_cast<HTMLTextAreaElement*>(element)->setValue(string);
1617 void AccessibilityRenderObject::ariaOwnsElements(AccessibilityChildrenVector& axObjects) const
1619 Vector<Element*> elements;
1620 elementsFromAttribute(elements, aria_ownsAttr);
1622 unsigned count = elements.size();
1623 for (unsigned k = 0; k < count; ++k) {
1624 RenderObject* render = elements[k]->renderer();
1625 AccessibilityObject* obj = axObjectCache()->getOrCreate(render);
1627 axObjects.append(obj);
1631 bool AccessibilityRenderObject::supportsARIAOwns() const
1635 const AtomicString& ariaOwns = getAttribute(aria_ownsAttr);
1637 return !ariaOwns.isEmpty();
1640 RenderView* AccessibilityRenderObject::topRenderer() const
1642 Document* topDoc = topDocument();
1646 return topDoc->renderView();
1649 Document* AccessibilityRenderObject::document() const
1653 return m_renderer->document();
1656 Document* AccessibilityRenderObject::topDocument() const
1660 return document()->topDocument();
1663 FrameView* AccessibilityRenderObject::topDocumentFrameView() const
1665 RenderView* renderView = topRenderer();
1666 if (!renderView || !renderView->view())
1668 return renderView->view()->frameView();
1671 Widget* AccessibilityRenderObject::widget() const
1673 if (!m_renderer->isBoxModelObject() || !toRenderBoxModelObject(m_renderer)->isWidget())
1675 return toRenderWidget(m_renderer)->widget();
1678 AccessibilityObject* AccessibilityRenderObject::accessibilityParentForImageMap(HTMLMapElement* map) const
1680 // find an image that is using this map
1684 HTMLImageElement* imageElement = map->imageElement();
1688 return axObjectCache()->getOrCreate(imageElement);
1691 void AccessibilityRenderObject::getDocumentLinks(AccessibilityChildrenVector& result)
1693 Document* document = m_renderer->document();
1694 RefPtr<HTMLCollection> links = document->links();
1695 for (unsigned i = 0; Node* curr = links->item(i); i++) {
1696 RenderObject* obj = curr->renderer();
1698 RefPtr<AccessibilityObject> axobj = document->axObjectCache()->getOrCreate(obj);
1700 if (!axobj->accessibilityIsIgnored() && axobj->isLink())
1701 result.append(axobj);
1703 Node* parent = curr->parentNode();
1704 if (parent && curr->hasTagName(areaTag) && parent->hasTagName(mapTag)) {
1705 AccessibilityImageMapLink* areaObject = static_cast<AccessibilityImageMapLink*>(axObjectCache()->getOrCreate(ImageMapLinkRole));
1706 areaObject->setHTMLAreaElement(static_cast<HTMLAreaElement*>(curr));
1707 areaObject->setHTMLMapElement(static_cast<HTMLMapElement*>(parent));
1708 areaObject->setParent(accessibilityParentForImageMap(static_cast<HTMLMapElement*>(parent)));
1710 result.append(areaObject);
1716 FrameView* AccessibilityRenderObject::documentFrameView() const
1718 if (!m_renderer || !m_renderer->document())
1721 // this is the RenderObject's Document's Frame's FrameView
1722 return m_renderer->document()->view();
1725 Widget* AccessibilityRenderObject::widgetForAttachmentView() const
1727 if (!isAttachment())
1729 return toRenderWidget(m_renderer)->widget();
1732 FrameView* AccessibilityRenderObject::frameViewIfRenderView() const
1734 if (!m_renderer->isRenderView())
1736 // this is the RenderObject's Document's renderer's FrameView
1737 return m_renderer->view()->frameView();
1740 // This function is like a cross-platform version of - (WebCoreTextMarkerRange*)textMarkerRange. It returns
1741 // a Range that we can convert to a WebCoreTextMarkerRange in the Obj-C file
1742 VisiblePositionRange AccessibilityRenderObject::visiblePositionRange() const
1745 return VisiblePositionRange();
1747 // construct VisiblePositions for start and end
1748 Node* node = m_renderer->node();
1750 return VisiblePositionRange();
1752 VisiblePosition startPos = firstPositionInOrBeforeNode(node);
1753 VisiblePosition endPos = lastPositionInOrAfterNode(node);
1755 // the VisiblePositions are equal for nodes like buttons, so adjust for that
1756 // FIXME: Really? [button, 0] and [button, 1] are distinct (before and after the button)
1757 // I expect this code is only hit for things like empty divs? In which case I don't think
1758 // the behavior is correct here -- eseidel
1759 if (startPos == endPos) {
1760 endPos = endPos.next();
1761 if (endPos.isNull())
1765 return VisiblePositionRange(startPos, endPos);
1768 VisiblePositionRange AccessibilityRenderObject::visiblePositionRangeForLine(unsigned lineCount) const
1770 if (!lineCount || !m_renderer)
1771 return VisiblePositionRange();
1773 // iterate over the lines
1774 // FIXME: this is wrong when lineNumber is lineCount+1, because nextLinePosition takes you to the
1775 // last offset of the last line
1776 VisiblePosition visiblePos = m_renderer->document()->renderer()->positionForPoint(IntPoint());
1777 VisiblePosition savedVisiblePos;
1778 while (--lineCount) {
1779 savedVisiblePos = visiblePos;
1780 visiblePos = nextLinePosition(visiblePos, 0);
1781 if (visiblePos.isNull() || visiblePos == savedVisiblePos)
1782 return VisiblePositionRange();
1785 // make a caret selection for the marker position, then extend it to the line
1786 // NOTE: ignores results of sel.modify because it returns false when
1787 // starting at an empty line. The resulting selection in that case
1788 // will be a caret at visiblePos.
1789 FrameSelection selection;
1790 selection.setSelection(VisibleSelection(visiblePos));
1791 selection.modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary);
1793 return VisiblePositionRange(selection.selection().visibleStart(), selection.selection().visibleEnd());
1796 VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(int index) const
1799 return VisiblePosition();
1801 if (isNativeTextControl())
1802 return toRenderTextControl(m_renderer)->visiblePositionForIndex(index);
1804 if (!allowsTextRanges() && !m_renderer->isText())
1805 return VisiblePosition();
1807 Node* node = m_renderer->node();
1809 return VisiblePosition();
1812 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
1814 RefPtr<Range> range = Range::create(m_renderer->document());
1815 range->selectNodeContents(node, IGNORE_EXCEPTION);
1816 CharacterIterator it(range.get());
1817 it.advance(index - 1);
1818 return VisiblePosition(Position(it.range()->endContainer(), it.range()->endOffset(), Position::PositionIsOffsetInAnchor), UPSTREAM);
1821 int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
1823 if (isNativeTextControl()) {
1824 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1825 return textControl->indexForVisiblePosition(pos);
1828 if (!isTextControl())
1831 Node* node = m_renderer->node();
1835 Position indexPosition = pos.deepEquivalent();
1836 if (indexPosition.isNull() || highestEditableRoot(indexPosition, HasEditableAXRole) != node)
1839 RefPtr<Range> range = Range::create(m_renderer->document());
1840 range->setStart(node, 0, IGNORE_EXCEPTION);
1841 range->setEnd(indexPosition, IGNORE_EXCEPTION);
1844 // We need to consider replaced elements for GTK, as they will be
1845 // presented with the 'object replacement character' (0xFFFC).
1846 return TextIterator::rangeLength(range.get(), true);
1848 return TextIterator::rangeLength(range.get());
1852 Element* AccessibilityRenderObject::rootEditableElementForPosition(const Position& position) const
1854 // Find the root editable or pseudo-editable (i.e. having an editable ARIA role) element.
1855 Element* result = 0;
1857 Element* rootEditableElement = position.rootEditableElement();
1859 for (Element* e = position.element(); e && e != rootEditableElement; e = e->parentElement()) {
1860 if (nodeIsTextControl(e))
1862 if (e->hasTagName(bodyTag))
1869 return rootEditableElement;
1872 bool AccessibilityRenderObject::nodeIsTextControl(const Node* node) const
1877 const AccessibilityObject* axObjectForNode = axObjectCache()->getOrCreate(const_cast<Node*>(node));
1878 if (!axObjectForNode)
1881 return axObjectForNode->isTextControl();
1884 IntRect AccessibilityRenderObject::boundsForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange) const
1886 if (visiblePositionRange.isNull())
1889 // Create a mutable VisiblePositionRange.
1890 VisiblePositionRange range(visiblePositionRange);
1891 LayoutRect rect1 = range.start.absoluteCaretBounds();
1892 LayoutRect rect2 = range.end.absoluteCaretBounds();
1894 // 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
1895 if (rect2.y() != rect1.y()) {
1896 VisiblePosition endOfFirstLine = endOfLine(range.start);
1897 if (range.start == endOfFirstLine) {
1898 range.start.setAffinity(DOWNSTREAM);
1899 rect1 = range.start.absoluteCaretBounds();
1901 if (range.end == endOfFirstLine) {
1902 range.end.setAffinity(UPSTREAM);
1903 rect2 = range.end.absoluteCaretBounds();
1907 LayoutRect ourrect = rect1;
1908 ourrect.unite(rect2);
1910 // if the rectangle spans lines and contains multiple text chars, use the range's bounding box intead
1911 if (rect1.maxY() != rect2.maxY()) {
1912 RefPtr<Range> dataRange = makeRange(range.start, range.end);
1913 LayoutRect boundingBox = dataRange->boundingBox();
1914 String rangeString = plainText(dataRange.get());
1915 if (rangeString.length() > 1 && !boundingBox.isEmpty())
1916 ourrect = boundingBox;
1920 return m_renderer->document()->view()->contentsToScreen(pixelSnappedIntRect(ourrect));
1922 return pixelSnappedIntRect(ourrect);
1926 void AccessibilityRenderObject::setSelectedVisiblePositionRange(const VisiblePositionRange& range) const
1928 if (range.start.isNull() || range.end.isNull())
1931 // make selection and tell the document to use it. if it's zero length, then move to that position
1932 if (range.start == range.end)
1933 m_renderer->frame()->selection()->moveTo(range.start, UserTriggered);
1935 VisibleSelection newSelection = VisibleSelection(range.start, range.end);
1936 m_renderer->frame()->selection()->setSelection(newSelection);
1940 VisiblePosition AccessibilityRenderObject::visiblePositionForPoint(const IntPoint& point) const
1943 return VisiblePosition();
1945 // convert absolute point to view coordinates
1946 RenderView* renderView = topRenderer();
1948 return VisiblePosition();
1950 FrameView* frameView = renderView->frameView();
1952 return VisiblePosition();
1954 Node* innerNode = 0;
1956 // locate the node containing the point
1957 LayoutPoint pointResult;
1959 LayoutPoint ourpoint;
1961 ourpoint = frameView->screenToContents(point);
1965 HitTestRequest request(HitTestRequest::ReadOnly |
1966 HitTestRequest::Active);
1967 HitTestResult result(ourpoint);
1968 renderView->hitTest(request, result);
1969 innerNode = result.innerNode();
1971 return VisiblePosition();
1973 RenderObject* renderer = innerNode->renderer();
1975 return VisiblePosition();
1977 pointResult = result.localPoint();
1979 // done if hit something other than a widget
1980 if (!renderer->isWidget())
1983 // descend into widget (FRAME, IFRAME, OBJECT...)
1984 Widget* widget = toRenderWidget(renderer)->widget();
1985 if (!widget || !widget->isFrameView())
1987 Frame* frame = toFrameView(widget)->frame();
1990 renderView = frame->document()->renderView();
1991 frameView = toFrameView(widget);
1994 return innerNode->renderer()->positionForPoint(pointResult);
1997 // NOTE: Consider providing this utility method as AX API
1998 VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(unsigned indexValue, bool lastIndexOK) const
2000 if (!isTextControl())
2001 return VisiblePosition();
2003 // lastIndexOK specifies whether the position after the last character is acceptable
2004 if (indexValue >= text().length()) {
2005 if (!lastIndexOK || indexValue > text().length())
2006 return VisiblePosition();
2008 VisiblePosition position = visiblePositionForIndex(indexValue);
2009 position.setAffinity(DOWNSTREAM);
2013 // NOTE: Consider providing this utility method as AX API
2014 int AccessibilityRenderObject::index(const VisiblePosition& position) const
2016 if (position.isNull() || !isTextControl())
2019 if (renderObjectContainsPosition(m_renderer, position.deepEquivalent()))
2020 return indexForVisiblePosition(position);
2025 void AccessibilityRenderObject::lineBreaks(Vector<int>& lineBreaks) const
2027 if (!isTextControl())
2030 VisiblePosition visiblePos = visiblePositionForIndex(0);
2031 VisiblePosition savedVisiblePos = visiblePos;
2032 visiblePos = nextLinePosition(visiblePos, 0);
2033 while (!visiblePos.isNull() && visiblePos != savedVisiblePos) {
2034 lineBreaks.append(indexForVisiblePosition(visiblePos));
2035 savedVisiblePos = visiblePos;
2036 visiblePos = nextLinePosition(visiblePos, 0);
2040 // Given a line number, the range of characters of the text associated with this accessibility
2041 // object that contains the line number.
2042 PlainTextRange AccessibilityRenderObject::doAXRangeForLine(unsigned lineNumber) const
2044 if (!isTextControl())
2045 return PlainTextRange();
2047 // iterate to the specified line
2048 VisiblePosition visiblePos = visiblePositionForIndex(0);
2049 VisiblePosition savedVisiblePos;
2050 for (unsigned lineCount = lineNumber; lineCount; lineCount -= 1) {
2051 savedVisiblePos = visiblePos;
2052 visiblePos = nextLinePosition(visiblePos, 0);
2053 if (visiblePos.isNull() || visiblePos == savedVisiblePos)
2054 return PlainTextRange();
2057 // Get the end of the line based on the starting position.
2058 VisiblePosition endPosition = endOfLine(visiblePos);
2060 int index1 = indexForVisiblePosition(visiblePos);
2061 int index2 = indexForVisiblePosition(endPosition);
2063 // add one to the end index for a line break not caused by soft line wrap (to match AppKit)
2064 if (endPosition.affinity() == DOWNSTREAM && endPosition.next().isNotNull())
2067 // return nil rather than an zero-length range (to match AppKit)
2068 if (index1 == index2)
2069 return PlainTextRange();
2071 return PlainTextRange(index1, index2 - index1);
2074 // The composed character range in the text associated with this accessibility object that
2075 // is specified by the given index value. This parameterized attribute returns the complete
2076 // range of characters (including surrogate pairs of multi-byte glyphs) at the given index.
2077 PlainTextRange AccessibilityRenderObject::doAXRangeForIndex(unsigned index) const
2079 if (!isTextControl())
2080 return PlainTextRange();
2082 String elementText = text();
2083 if (!elementText.length() || index > elementText.length() - 1)
2084 return PlainTextRange();
2086 return PlainTextRange(index, 1);
2089 // A substring of the text associated with this accessibility object that is
2090 // specified by the given character range.
2091 String AccessibilityRenderObject::doAXStringForRange(const PlainTextRange& range) const
2096 if (!isTextControl())
2099 String elementText = isPasswordField() ? passwordFieldValue() : text();
2100 if (range.start + range.length > elementText.length())
2103 return elementText.substring(range.start, range.length);
2106 // The bounding rectangle of the text associated with this accessibility object that is
2107 // specified by the given range. This is the bounding rectangle a sighted user would see
2108 // on the display screen, in pixels.
2109 IntRect AccessibilityRenderObject::doAXBoundsForRange(const PlainTextRange& range) const
2111 if (allowsTextRanges())
2112 return boundsForVisiblePositionRange(visiblePositionRangeForRange(range));
2116 AccessibilityObject* AccessibilityRenderObject::accessibilityImageMapHitTest(HTMLAreaElement* area, const IntPoint& point) const
2121 HTMLMapElement* map = static_cast<HTMLMapElement*>(area->parentNode());
2122 AccessibilityObject* parent = accessibilityParentForImageMap(map);
2126 AccessibilityObject::AccessibilityChildrenVector children = parent->children();
2128 unsigned count = children.size();
2129 for (unsigned k = 0; k < count; ++k) {
2130 if (children[k]->elementRect().contains(point))
2131 return children[k].get();
2137 AccessibilityObject* AccessibilityRenderObject::remoteSVGElementHitTest(const IntPoint& point) const
2139 AccessibilityObject* remote = remoteSVGRootElement();
2143 IntSize offset = point - roundedIntPoint(boundingBoxRect().location());
2144 return remote->accessibilityHitTest(IntPoint(offset));
2147 AccessibilityObject* AccessibilityRenderObject::elementAccessibilityHitTest(const IntPoint& point) const
2150 return remoteSVGElementHitTest(point);
2152 return AccessibilityObject::elementAccessibilityHitTest(point);
2155 AccessibilityObject* AccessibilityRenderObject::accessibilityHitTest(const IntPoint& point) const
2157 if (!m_renderer || !m_renderer->hasLayer())
2160 RenderLayer* layer = toRenderBox(m_renderer)->layer();
2162 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::AccessibilityHitTest);
2163 HitTestResult hitTestResult = HitTestResult(point);
2164 layer->hitTest(request, hitTestResult);
2165 if (!hitTestResult.innerNode())
2167 Node* node = hitTestResult.innerNode()->deprecatedShadowAncestorNode();
2169 if (node->hasTagName(areaTag))
2170 return accessibilityImageMapHitTest(static_cast<HTMLAreaElement*>(node), point);
2172 if (node->hasTagName(optionTag))
2173 node = static_cast<HTMLOptionElement*>(node)->ownerSelectElement();
2175 RenderObject* obj = node->renderer();
2179 AccessibilityObject* result = obj->document()->axObjectCache()->getOrCreate(obj);
2180 result->updateChildrenIfNecessary();
2182 // Allow the element to perform any hit-testing it might need to do to reach non-render children.
2183 result = result->elementAccessibilityHitTest(point);
2185 if (result && result->accessibilityIsIgnored()) {
2186 // If this element is the label of a control, a hit test should return the control.
2187 AccessibilityObject* controlObject = result->correspondingControlForLabelElement();
2188 if (controlObject && !controlObject->exposesTitleUIElement())
2189 return controlObject;
2191 result = result->parentObjectUnignored();
2197 bool AccessibilityRenderObject::shouldNotifyActiveDescendant() const
2199 // We want to notify that the combo box has changed its active descendant,
2200 // but we do not want to change the focus, because focus should remain with the combo box.
2204 return shouldFocusActiveDescendant();
2207 bool AccessibilityRenderObject::shouldFocusActiveDescendant() const
2209 switch (ariaRoleAttribute()) {
2214 case RadioGroupRole:
2216 case PopUpButtonRole:
2217 case ProgressIndicatorRole:
2222 /* FIXME: replace these with actual roles when they are added to AccessibilityRole
2235 AccessibilityObject* AccessibilityRenderObject::activeDescendant() const
2240 if (m_renderer->node() && !m_renderer->node()->isElementNode())
2242 Element* element = toElement(m_renderer->node());
2244 const AtomicString& activeDescendantAttrStr = element->getAttribute(aria_activedescendantAttr);
2245 if (activeDescendantAttrStr.isNull() || activeDescendantAttrStr.isEmpty())
2248 Element* target = element->treeScope()->getElementById(activeDescendantAttrStr);
2252 AccessibilityObject* obj = axObjectCache()->getOrCreate(target);
2253 if (obj && obj->isAccessibilityRenderObject())
2254 // an activedescendant is only useful if it has a renderer, because that's what's needed to post the notification
2259 void AccessibilityRenderObject::handleAriaExpandedChanged()
2261 // Find if a parent of this object should handle aria-expanded changes.
2262 AccessibilityObject* containerParent = this->parentObject();
2263 while (containerParent) {
2264 bool foundParent = false;
2266 switch (containerParent->roleValue()) {
2281 containerParent = containerParent->parentObject();
2284 // Post that the row count changed.
2285 if (containerParent)
2286 axObjectCache()->postNotification(containerParent, document(), AXObjectCache::AXRowCountChanged, true);
2288 // Post that the specific row either collapsed or expanded.
2289 if (roleValue() == RowRole || roleValue() == TreeItemRole)
2290 axObjectCache()->postNotification(this, document(), isExpanded() ? AXObjectCache::AXRowExpanded : AXObjectCache::AXRowCollapsed, true);
2293 void AccessibilityRenderObject::handleActiveDescendantChanged()
2295 Element* element = toElement(renderer()->node());
2298 Document* doc = renderer()->document();
2299 if (!doc->frame()->selection()->isFocusedAndActive() || doc->focusedNode() != element)
2301 AccessibilityRenderObject* activedescendant = static_cast<AccessibilityRenderObject*>(activeDescendant());
2303 if (activedescendant && shouldNotifyActiveDescendant())
2304 doc->axObjectCache()->postNotification(m_renderer, AXObjectCache::AXActiveDescendantChanged, true);
2307 AccessibilityObject* AccessibilityRenderObject::correspondingControlForLabelElement() const
2309 HTMLLabelElement* labelElement = labelElementContainer();
2313 HTMLElement* correspondingControl = labelElement->control();
2314 if (!correspondingControl)
2317 // Make sure the corresponding control isn't a descendant of this label that's in the middle of being destroyed.
2318 if (correspondingControl->renderer() && !correspondingControl->renderer()->parent())
2321 return axObjectCache()->getOrCreate(correspondingControl);
2324 AccessibilityObject* AccessibilityRenderObject::correspondingLabelForControlElement() const
2329 // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
2330 // override the "label" element association.
2331 if (hasTextAlternative())
2334 Node* node = m_renderer->node();
2335 if (node && node->isHTMLElement()) {
2336 HTMLLabelElement* label = labelForElement(toElement(node));
2338 return axObjectCache()->getOrCreate(label);
2344 bool AccessibilityRenderObject::renderObjectIsObservable(RenderObject* renderer) const
2346 // AX clients will listen for AXValueChange on a text control.
2347 if (renderer->isTextControl())
2350 // AX clients will listen for AXSelectedChildrenChanged on listboxes.
2351 Node* node = renderer->node();
2352 if (nodeHasRole(node, "listbox") || (renderer->isBoxModelObject() && toRenderBoxModelObject(renderer)->isListBox()))
2355 // Textboxes should send out notifications.
2356 if (nodeHasRole(node, "textbox"))
2362 AccessibilityObject* AccessibilityRenderObject::observableObject() const
2364 // Find the object going up the parent chain that is used in accessibility to monitor certain notifications.
2365 for (RenderObject* renderer = m_renderer; renderer && renderer->node(); renderer = renderer->parent()) {
2366 if (renderObjectIsObservable(renderer))
2367 return axObjectCache()->getOrCreate(renderer);
2373 bool AccessibilityRenderObject::isDescendantOfElementType(const QualifiedName& tagName) const
2375 for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
2376 if (parent->node() && parent->node()->hasTagName(tagName))
2382 AccessibilityRole AccessibilityRenderObject::determineAccessibilityRole()
2387 m_ariaRole = determineAriaRoleAttribute();
2389 Node* node = m_renderer->node();
2390 AccessibilityRole ariaRole = ariaRoleAttribute();
2391 if (ariaRole != UnknownRole)
2394 RenderBoxModelObject* cssBox = renderBoxModelObject();
2396 if (node && node->isLink()) {
2397 if (cssBox && cssBox->isImage())
2398 return ImageMapRole;
2399 return WebCoreLinkRole;
2401 if (cssBox && cssBox->isListItem())
2402 return ListItemRole;
2403 if (m_renderer->isListMarker())
2404 return ListMarkerRole;
2405 if (node && node->hasTagName(buttonTag))
2406 return buttonRoleType();
2407 if (node && node->hasTagName(legendTag))
2409 if (m_renderer->isText())
2410 return StaticTextRole;
2411 if (cssBox && cssBox->isImage()) {
2412 if (node && node->hasTagName(inputTag))
2413 return ariaHasPopup() ? PopUpButtonRole : ButtonRole;
2419 if (node && node->hasTagName(canvasTag))
2422 if (cssBox && cssBox->isRenderView()) {
2423 // If the iframe is seamless, it should not be announced as a web area to AT clients.
2424 if (document() && document()->shouldDisplaySeamlesslyWithParent())
2425 return SeamlessWebAreaRole;
2429 if (cssBox && cssBox->isTextField())
2430 return TextFieldRole;
2432 if (cssBox && cssBox->isTextArea())
2433 return TextAreaRole;
2435 if (node && node->hasTagName(inputTag)) {
2436 HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
2437 if (input->isCheckbox())
2438 return CheckBoxRole;
2439 if (input->isRadioButton())
2440 return RadioButtonRole;
2441 if (input->isTextButton())
2442 return buttonRoleType();
2444 #if ENABLE(INPUT_TYPE_COLOR)
2445 const AtomicString& type = input->getAttribute(typeAttr);
2446 if (equalIgnoringCase(type, "color"))
2447 return ColorWellRole;
2451 if (isFileUploadButton())
2454 if (cssBox && cssBox->isMenuList())
2455 return PopUpButtonRole;
2461 if (m_renderer->isSVGImage())
2463 if (m_renderer->isSVGRoot())
2465 if (node && node->hasTagName(SVGNames::gTag))
2470 if (node && node->hasTagName(MathMLNames::mathTag))
2471 return DocumentMathRole;
2473 // It's not clear which role a platform should choose for a math element.
2474 // Declaring a math element role should give flexibility to platforms to choose.
2475 if (isMathElement())
2476 return MathElementRole;
2478 if (node && node->hasTagName(ddTag))
2479 return DescriptionListDetailRole;
2481 if (node && node->hasTagName(dtTag))
2482 return DescriptionListTermRole;
2484 if (node && node->hasTagName(dlTag))
2485 return DescriptionListRole;
2487 if (node && (node->hasTagName(rpTag) || node->hasTagName(rtTag)))
2488 return AnnotationRole;
2491 // Gtk ATs expect all tables, data and layout, to be exposed as tables.
2492 if (node && (node->hasTagName(tdTag) || node->hasTagName(thTag)))
2495 if (node && node->hasTagName(trTag))
2498 if (node && node->hasTagName(tableTag))
2502 // Table sections should be ignored.
2503 if (m_renderer->isTableSection())
2506 if (m_renderer->isHR())
2507 return HorizontalRuleRole;
2509 if (node && node->hasTagName(pTag))
2510 return ParagraphRole;
2512 if (node && node->hasTagName(labelTag))
2515 if (node && node->hasTagName(divTag))
2518 if (node && node->hasTagName(formTag))
2521 if (node && node->hasTagName(articleTag))
2522 return DocumentArticleRole;
2524 if (node && node->hasTagName(mainTag))
2525 return LandmarkMainRole;
2527 if (node && node->hasTagName(navTag))
2528 return LandmarkNavigationRole;
2530 if (node && node->hasTagName(asideTag))
2531 return LandmarkComplementaryRole;
2533 if (node && node->hasTagName(sectionTag))
2534 return DocumentRegionRole;
2536 if (node && node->hasTagName(addressTag))
2537 return LandmarkContentInfoRole;
2539 // The HTML element should not be exposed as an element. That's what the RenderView element does.
2540 if (node && node->hasTagName(htmlTag))
2543 // There should only be one banner/contentInfo per page. If header/footer are being used within an article or section
2544 // then it should not be exposed as whole page's banner/contentInfo
2545 if (node && node->hasTagName(headerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
2546 return LandmarkBannerRole;
2547 if (node && node->hasTagName(footerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
2550 if (m_renderer->isBlockFlow())
2553 // If the element does not have role, but it has ARIA attributes, accessibility should fallback to exposing it as a group.
2554 if (supportsARIAAttributes())
2560 AccessibilityOrientation AccessibilityRenderObject::orientation() const
2562 const AtomicString& ariaOrientation = getAttribute(aria_orientationAttr);
2563 if (equalIgnoringCase(ariaOrientation, "horizontal"))
2564 return AccessibilityOrientationHorizontal;
2565 if (equalIgnoringCase(ariaOrientation, "vertical"))
2566 return AccessibilityOrientationVertical;
2568 return AccessibilityObject::orientation();
2571 bool AccessibilityRenderObject::inheritsPresentationalRole() const
2573 // ARIA states if an item can get focus, it should not be presentational.
2574 if (canSetFocusAttribute())
2577 // ARIA spec says that when a parent object is presentational, and it has required child elements,
2578 // those child elements are also presentational. For example, <li> becomes presentational from <ul>.
2579 // http://www.w3.org/WAI/PF/aria/complete#presentation
2580 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, listItemParents, ());
2582 HashSet<QualifiedName>* possibleParentTagNames = 0;
2583 switch (roleValue()) {
2585 case ListMarkerRole:
2586 if (listItemParents.isEmpty()) {
2587 listItemParents.add(ulTag);
2588 listItemParents.add(olTag);
2589 listItemParents.add(dlTag);
2591 possibleParentTagNames = &listItemParents;
2597 // Not all elements need to check for this, only ones that are required children.
2598 if (!possibleParentTagNames)
2601 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
2602 if (!parent->isAccessibilityRenderObject())
2605 Node* elementNode = static_cast<AccessibilityRenderObject*>(parent)->node();
2606 if (!elementNode || !elementNode->isElementNode())
2609 // If native tag of the parent element matches an acceptable name, then return
2610 // based on its presentational status.
2611 if (possibleParentTagNames->contains(toElement(elementNode)->tagQName()))
2612 return parent->roleValue() == PresentationalRole;
2618 bool AccessibilityRenderObject::isPresentationalChildOfAriaRole() const
2620 // Walk the parent chain looking for a parent that has presentational children
2621 AccessibilityObject* parent;
2622 for (parent = parentObject(); parent && !parent->ariaRoleHasPresentationalChildren(); parent = parent->parentObject())
2628 bool AccessibilityRenderObject::ariaRoleHasPresentationalChildren() const
2630 switch (m_ariaRole) {
2634 case ProgressIndicatorRole:
2635 case SpinButtonRole:
2636 // case SeparatorRole:
2643 bool AccessibilityRenderObject::canSetExpandedAttribute() const
2645 // An object can be expanded if it aria-expanded is true or false.
2646 const AtomicString& ariaExpanded = getAttribute(aria_expandedAttr);
2647 return equalIgnoringCase(ariaExpanded, "true") || equalIgnoringCase(ariaExpanded, "false");
2650 bool AccessibilityRenderObject::canSetValueAttribute() const
2652 if (equalIgnoringCase(getAttribute(aria_readonlyAttr), "true"))
2655 if (isProgressIndicator() || isSlider())
2658 if (isTextControl() && !isNativeTextControl())
2661 // Any node could be contenteditable, so isReadOnly should be relied upon
2662 // for this information for all elements.
2663 return !isReadOnly();
2666 bool AccessibilityRenderObject::canSetTextRangeAttributes() const
2668 return isTextControl();
2671 void AccessibilityRenderObject::textChanged()
2673 // If this element supports ARIA live regions, or is part of a region with an ARIA editable role,
2674 // then notify the AT of changes.
2675 AXObjectCache* cache = axObjectCache();
2676 for (RenderObject* renderParent = m_renderer; renderParent; renderParent = renderParent->parent()) {
2677 AccessibilityObject* parent = cache->get(renderParent);
2681 if (parent->supportsARIALiveRegion())
2682 cache->postNotification(renderParent, AXObjectCache::AXLiveRegionChanged, true);
2684 if (parent->isARIATextControl() && !parent->isNativeTextControl() && !parent->node()->rendererIsEditable())
2685 cache->postNotification(renderParent, AXObjectCache::AXValueChanged, true);
2689 void AccessibilityRenderObject::clearChildren()
2691 AccessibilityObject::clearChildren();
2692 m_childrenDirty = false;
2695 void AccessibilityRenderObject::addImageMapChildren()
2697 RenderBoxModelObject* cssBox = renderBoxModelObject();
2698 if (!cssBox || !cssBox->isRenderImage())
2701 HTMLMapElement* map = toRenderImage(cssBox)->imageMap();
2705 for (Element* current = ElementTraversal::firstWithin(map); current; current = ElementTraversal::next(current, map)) {
2706 // add an <area> element for this child if it has a link
2707 if (current->hasTagName(areaTag) && current->isLink()) {
2708 AccessibilityImageMapLink* areaObject = static_cast<AccessibilityImageMapLink*>(axObjectCache()->getOrCreate(ImageMapLinkRole));
2709 areaObject->setHTMLAreaElement(static_cast<HTMLAreaElement*>(current));
2710 areaObject->setHTMLMapElement(map);
2711 areaObject->setParent(this);
2712 if (!areaObject->accessibilityIsIgnored())
2713 m_children.append(areaObject);
2715 axObjectCache()->remove(areaObject->axObjectID());
2720 void AccessibilityRenderObject::updateChildrenIfNecessary()
2722 if (needsToUpdateChildren())
2725 AccessibilityObject::updateChildrenIfNecessary();
2728 void AccessibilityRenderObject::addTextFieldChildren()
2730 Node* node = this->node();
2731 if (!node || !node->hasTagName(inputTag))
2734 HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
2735 HTMLElement* spinButtonElement = input->innerSpinButtonElement();
2736 if (!spinButtonElement || !spinButtonElement->isSpinButtonElement())
2739 AccessibilitySpinButton* axSpinButton = static_cast<AccessibilitySpinButton*>(axObjectCache()->getOrCreate(SpinButtonRole));
2740 axSpinButton->setSpinButtonElement(static_cast<SpinButtonElement*>(spinButtonElement));
2741 axSpinButton->setParent(this);
2742 m_children.append(axSpinButton);
2745 bool AccessibilityRenderObject::isSVGImage() const
2747 return remoteSVGRootElement();
2750 void AccessibilityRenderObject::detachRemoteSVGRoot()
2752 if (AccessibilitySVGRoot* root = remoteSVGRootElement())
2756 AccessibilitySVGRoot* AccessibilityRenderObject::remoteSVGRootElement() const
2759 if (!m_renderer || !m_renderer->isRenderImage())
2762 CachedImage* cachedImage = toRenderImage(m_renderer)->cachedImage();
2766 Image* image = cachedImage->image();
2767 if (!image || !image->isSVGImage())
2770 SVGImage* svgImage = static_cast<SVGImage*>(image);
2771 FrameView* frameView = svgImage->frameView();
2774 Frame* frame = frameView->frame();
2778 Document* doc = frame->document();
2779 if (!doc || !doc->isSVGDocument())
2782 SVGSVGElement* rootElement = toSVGDocument(doc)->rootElement();
2785 RenderObject* rendererRoot = rootElement->renderer();
2789 AccessibilityObject* rootSVGObject = frame->document()->axObjectCache()->getOrCreate(rendererRoot);
2791 // In order to connect the AX hierarchy from the SVG root element from the loaded resource
2792 // the parent must be set, because there's no other way to get back to who created the image.
2793 ASSERT(rootSVGObject && rootSVGObject->isAccessibilitySVGRoot());
2794 if (!rootSVGObject->isAccessibilitySVGRoot())
2797 return toAccessibilitySVGRoot(rootSVGObject);
2803 void AccessibilityRenderObject::addRemoteSVGChildren()
2805 AccessibilitySVGRoot* root = remoteSVGRootElement();
2809 root->setParent(this);
2811 if (root->accessibilityIsIgnored()) {
2812 AccessibilityChildrenVector children = root->children();
2813 unsigned length = children.size();
2814 for (unsigned i = 0; i < length; ++i)
2815 m_children.append(children[i]);
2817 m_children.append(root);
2820 void AccessibilityRenderObject::addCanvasChildren()
2822 if (!node() || !node()->hasTagName(canvasTag))
2825 // If it's a canvas, it won't have rendered children, but it might have accessible fallback content.
2826 // Clear m_haveChildren because AccessibilityNodeObject::addChildren will expect it to be false.
2827 ASSERT(!m_children.size());
2828 m_haveChildren = false;
2829 AccessibilityNodeObject::addChildren();
2832 void AccessibilityRenderObject::addAttachmentChildren()
2834 if (!isAttachment())
2837 // FrameView's need to be inserted into the AX hierarchy when encountered.
2838 Widget* widget = widgetForAttachmentView();
2839 if (!widget || !widget->isFrameView())
2842 AccessibilityObject* axWidget = axObjectCache()->getOrCreate(widget);
2843 if (!axWidget->accessibilityIsIgnored())
2844 m_children.append(axWidget);
2848 void AccessibilityRenderObject::updateAttachmentViewParents()
2850 // Only the unignored parent should set the attachment parent, because that's what is reflected in the AX
2851 // hierarchy to the client.
2852 if (accessibilityIsIgnored())
2855 size_t length = m_children.size();
2856 for (size_t k = 0; k < length; k++) {
2857 if (m_children[k]->isAttachment())
2858 m_children[k]->overrideAttachmentParent(this);
2863 // Hidden children are those that are not rendered or visible, but are specifically marked as aria-hidden=false,
2864 // meaning that they should be exposed to the AX hierarchy.
2865 void AccessibilityRenderObject::addHiddenChildren()
2867 Node* node = this->node();
2871 // First do a quick run through to determine if we have any hidden nodes (most often we will not).
2872 // If we do have hidden nodes, we need to determine where to insert them so they match DOM order as close as possible.
2873 bool shouldInsertHiddenNodes = false;
2874 for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
2875 if (!child->renderer() && isNodeAriaVisible(child)) {
2876 shouldInsertHiddenNodes = true;
2881 if (!shouldInsertHiddenNodes)
2884 // Iterate through all of the children, including those that may have already been added, and
2885 // try to insert hidden nodes in the correct place in the DOM order.
2886 unsigned insertionIndex = 0;
2887 for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
2888 if (child->renderer()) {
2889 // Find out where the last render sibling is located within m_children.
2890 AccessibilityObject* childObject = axObjectCache()->get(child->renderer());
2891 if (childObject && childObject->accessibilityIsIgnored()) {
2892 AccessibilityChildrenVector children = childObject->children();
2893 if (children.size())
2894 childObject = children.last().get();
2900 insertionIndex = m_children.find(childObject) + 1;
2904 if (!isNodeAriaVisible(child))
2907 unsigned previousSize = m_children.size();
2908 if (insertionIndex > previousSize)
2909 insertionIndex = previousSize;
2911 insertChild(axObjectCache()->getOrCreate(child), insertionIndex);
2912 insertionIndex += (m_children.size() - previousSize);
2916 void AccessibilityRenderObject::addChildren()
2918 // If the need to add more children in addition to existing children arises,
2919 // childrenChanged should have been called, leaving the object with no children.
2920 ASSERT(!m_haveChildren);
2922 m_haveChildren = true;
2924 if (!canHaveChildren())
2927 for (RefPtr<AccessibilityObject> obj = firstChild(); obj; obj = obj->nextSibling())
2928 addChild(obj.get());
2930 addHiddenChildren();
2931 addAttachmentChildren();
2932 addImageMapChildren();
2933 addTextFieldChildren();
2934 addCanvasChildren();
2935 addRemoteSVGChildren();
2938 updateAttachmentViewParents();
2942 bool AccessibilityRenderObject::canHaveChildren() const
2947 return AccessibilityNodeObject::canHaveChildren();
2950 const AtomicString& AccessibilityRenderObject::ariaLiveRegionStatus() const
2952 DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusAssertive, ("assertive", AtomicString::ConstructFromLiteral));
2953 DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusPolite, ("polite", AtomicString::ConstructFromLiteral));
2954 DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusOff, ("off", AtomicString::ConstructFromLiteral));
2956 const AtomicString& liveRegionStatus = getAttribute(aria_liveAttr);
2957 // These roles have implicit live region status.
2958 if (liveRegionStatus.isEmpty()) {
2959 switch (roleValue()) {
2960 case ApplicationAlertDialogRole:
2961 case ApplicationAlertRole:
2962 return liveRegionStatusAssertive;
2963 case ApplicationLogRole:
2964 case ApplicationStatusRole:
2965 return liveRegionStatusPolite;
2966 case ApplicationTimerRole:
2967 case ApplicationMarqueeRole:
2968 return liveRegionStatusOff;
2974 return liveRegionStatus;
2977 const AtomicString& AccessibilityRenderObject::ariaLiveRegionRelevant() const
2979 DEFINE_STATIC_LOCAL(const AtomicString, defaultLiveRegionRelevant, ("additions text", AtomicString::ConstructFromLiteral));
2980 const AtomicString& relevant = getAttribute(aria_relevantAttr);
2982 // Default aria-relevant = "additions text".
2983 if (relevant.isEmpty())
2984 return defaultLiveRegionRelevant;
2989 bool AccessibilityRenderObject::ariaLiveRegionAtomic() const
2991 return elementAttributeValue(aria_atomicAttr);
2994 bool AccessibilityRenderObject::ariaLiveRegionBusy() const
2996 return elementAttributeValue(aria_busyAttr);
2999 void AccessibilityRenderObject::ariaSelectedRows(AccessibilityChildrenVector& result)
3001 // Get all the rows.
3002 AccessibilityChildrenVector allRows;
3004 ariaTreeRows(allRows);
3005 else if (isAccessibilityTable() && toAccessibilityTable(this)->supportsSelectedRows())
3006 allRows = toAccessibilityTable(this)->rows();
3008 // Determine which rows are selected.
3009 bool isMulti = isMultiSelectable();
3011 // Prefer active descendant over aria-selected.
3012 AccessibilityObject* activeDesc = activeDescendant();
3013 if (activeDesc && (activeDesc->isTreeItem() || activeDesc->isTableRow())) {
3014 result.append(activeDesc);
3019 unsigned count = allRows.size();
3020 for (unsigned k = 0; k < count; ++k) {
3021 if (allRows[k]->isSelected()) {
3022 result.append(allRows[k]);
3029 void AccessibilityRenderObject::ariaListboxSelectedChildren(AccessibilityChildrenVector& result)
3031 bool isMulti = isMultiSelectable();
3033 AccessibilityChildrenVector childObjects = children();
3034 unsigned childrenSize = childObjects.size();
3035 for (unsigned k = 0; k < childrenSize; ++k) {
3036 // Every child should have aria-role option, and if so, check for selected attribute/state.
3037 AccessibilityObject* child = childObjects[k].get();
3038 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRole) {
3039 result.append(child);
3046 void AccessibilityRenderObject::selectedChildren(AccessibilityChildrenVector& result)
3048 ASSERT(result.isEmpty());
3050 // only listboxes should be asked for their selected children.
3051 AccessibilityRole role = roleValue();
3052 if (role == ListBoxRole) // native list boxes would be AccessibilityListBoxes, so only check for aria list boxes
3053 ariaListboxSelectedChildren(result);
3054 else if (role == TreeRole || role == TreeGridRole || role == TableRole)
3055 ariaSelectedRows(result);
3058 void AccessibilityRenderObject::ariaListboxVisibleChildren(AccessibilityChildrenVector& result)
3063 AccessibilityObject::AccessibilityChildrenVector children = this->children();
3064 size_t size = children.size();
3065 for (size_t i = 0; i < size; i++) {
3066 if (!children[i]->isOffScreen())
3067 result.append(children[i]);
3071 void AccessibilityRenderObject::visibleChildren(AccessibilityChildrenVector& result)
3073 ASSERT(result.isEmpty());
3075 // only listboxes are asked for their visible children.
3076 if (ariaRoleAttribute() != ListBoxRole) { // native list boxes would be AccessibilityListBoxes, so only check for aria list boxes
3077 ASSERT_NOT_REACHED();
3080 return ariaListboxVisibleChildren(result);
3083 void AccessibilityRenderObject::tabChildren(AccessibilityChildrenVector& result)
3085 ASSERT(roleValue() == TabListRole);
3087 AccessibilityObject::AccessibilityChildrenVector children = this->children();
3088 size_t size = children.size();
3089 for (size_t i = 0; i < size; ++i) {
3090 if (children[i]->isTabItem())
3091 result.append(children[i]);
3095 const String& AccessibilityRenderObject::actionVerb() const
3097 // FIXME: Need to add verbs for select elements.
3098 DEFINE_STATIC_LOCAL(const String, buttonAction, (AXButtonActionVerb()));
3099 DEFINE_STATIC_LOCAL(const String, textFieldAction, (AXTextFieldActionVerb()));
3100 DEFINE_STATIC_LOCAL(const String, radioButtonAction, (AXRadioButtonActionVerb()));
3101 DEFINE_STATIC_LOCAL(const String, checkedCheckBoxAction, (AXCheckedCheckBoxActionVerb()));
3102 DEFINE_STATIC_LOCAL(const String, uncheckedCheckBoxAction, (AXUncheckedCheckBoxActionVerb()));
3103 DEFINE_STATIC_LOCAL(const String, linkAction, (AXLinkActionVerb()));
3104 DEFINE_STATIC_LOCAL(const String, noAction, ());
3106 switch (roleValue()) {
3108 case ToggleButtonRole:
3109 return buttonAction;
3112 return textFieldAction;
3113 case RadioButtonRole:
3114 return radioButtonAction;
3116 return isChecked() ? checkedCheckBoxAction : uncheckedCheckBoxAction;
3118 case WebCoreLinkRole:
3125 void AccessibilityRenderObject::setAccessibleName(const AtomicString& name)
3127 // Setting the accessible name can store the value in the DOM
3132 // For web areas, set the aria-label on the HTML element.
3134 domNode = m_renderer->document()->documentElement();
3136 domNode = m_renderer->node();
3138 if (domNode && domNode->isElementNode())
3139 toElement(domNode)->setAttribute(aria_labelAttr, name);
3142 static bool isLinkable(const AccessibilityRenderObject& object)
3144 if (!object.renderer())
3147 // See https://wiki.mozilla.org/Accessibility/AT-Windows-API for the elements
3148 // Mozilla considers linkable.
3149 return object.isLink() || object.isImage() || object.renderer()->isText();
3152 String AccessibilityRenderObject::stringValueForMSAA() const
3154 if (isLinkable(*this)) {
3155 Element* anchor = anchorElement();
3156 if (anchor && anchor->hasTagName(aTag))
3157 return static_cast<HTMLAnchorElement*>(anchor)->href();
3160 return stringValue();
3163 bool AccessibilityRenderObject::isLinked() const
3165 if (!isLinkable(*this))
3168 Element* anchor = anchorElement();
3169 if (!anchor || !anchor->hasTagName(aTag))
3172 return !static_cast<HTMLAnchorElement*>(anchor)->href().isEmpty();
3175 bool AccessibilityRenderObject::hasBoldFont() const
3180 return m_renderer->style()->fontDescription().weight() >= FontWeightBold;
3183 bool AccessibilityRenderObject::hasItalicFont() const
3188 return m_renderer->style()->fontDescription().italic() == FontItalicOn;
3191 bool AccessibilityRenderObject::hasPlainText() const
3196 RenderStyle* style = m_renderer->style();
3198 return style->fontDescription().weight() == FontWeightNormal
3199 && style->fontDescription().italic() == FontItalicOff
3200 && style->textDecorationsInEffect() == TDNONE;
3203 bool AccessibilityRenderObject::hasSameFont(RenderObject* renderer) const
3205 if (!m_renderer || !renderer)
3208 return m_renderer->style()->fontDescription().family() == renderer->style()->fontDescription().family();
3211 bool AccessibilityRenderObject::hasSameFontColor(RenderObject* renderer) const
3213 if (!m_renderer || !renderer)
3216 return m_renderer->style()->visitedDependentColor(CSSPropertyColor) == renderer->style()->visitedDependentColor(CSSPropertyColor);
3219 bool AccessibilityRenderObject::hasSameStyle(RenderObject* renderer) const
3221 if (!m_renderer || !renderer)
3224 return m_renderer->style() == renderer->style();
3227 bool AccessibilityRenderObject::hasUnderline() const
3232 return m_renderer->style()->textDecorationsInEffect() & UNDERLINE;
3235 String AccessibilityRenderObject::nameForMSAA() const
3237 if (m_renderer && m_renderer->isText())
3238 return textUnderElement();
3243 static bool shouldReturnTagNameAsRoleForMSAA(const Element& element)
3245 // See "document structure",
3246 // https://wiki.mozilla.org/Accessibility/AT-Windows-API
3247 // FIXME: Add the other tag names that should be returned as the role.
3248 return element.hasTagName(h1Tag) || element.hasTagName(h2Tag)
3249 || element.hasTagName(h3Tag) || element.hasTagName(h4Tag)
3250 || element.hasTagName(h5Tag) || element.hasTagName(h6Tag);
3253 String AccessibilityRenderObject::stringRoleForMSAA() const
3258 Node* node = m_renderer->node();
3259 if (!node || !node->isElementNode())
3262 Element* element = toElement(node);
3263 if (!shouldReturnTagNameAsRoleForMSAA(*element))
3266 return element->tagName();
3269 String AccessibilityRenderObject::positionalDescriptionForMSAA() const
3271 // See "positional descriptions",
3272 // https://wiki.mozilla.org/Accessibility/AT-Windows-API
3274 return "L" + String::number(headingLevel());
3276 // FIXME: Add positional descriptions for other elements.
3280 String AccessibilityRenderObject::descriptionForMSAA() const
3282 String description = positionalDescriptionForMSAA();
3283 if (!description.isEmpty())
3286 description = accessibilityDescription();
3287 if (!description.isEmpty()) {
3288 // From the Mozilla MSAA implementation:
3289 // "Signal to screen readers that this description is speakable and is not
3290 // a formatted positional information description. Don't localize the
3291 // 'Description: ' part of th