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 "RenderText.h"
80 #include "RenderTextControl.h"
81 #include "RenderTextControlSingleLine.h"
82 #include "RenderTextFragment.h"
83 #include "RenderTheme.h"
84 #include "RenderView.h"
85 #include "RenderWidget.h"
86 #include "RenderedPosition.h"
87 #include "SVGDocument.h"
89 #include "SVGImageChromeClient.h"
90 #include "SVGSVGElement.h"
92 #include "TextControlInnerElements.h"
93 #include "htmlediting.h"
94 #include "visible_units.h"
95 #include <wtf/StdLibExtras.h>
96 #include <wtf/text/StringBuilder.h>
97 #include <wtf/unicode/CharacterNames.h>
103 using namespace HTMLNames;
105 AccessibilityRenderObject::AccessibilityRenderObject(RenderObject* renderer)
106 : AccessibilityNodeObject(renderer->node())
107 , m_renderer(renderer)
110 m_renderer->setHasAXObject(true);
114 AccessibilityRenderObject::~AccessibilityRenderObject()
116 ASSERT(isDetached());
119 void AccessibilityRenderObject::init()
121 AccessibilityNodeObject::init();
124 PassRefPtr<AccessibilityRenderObject> AccessibilityRenderObject::create(RenderObject* renderer)
126 AccessibilityRenderObject* obj = new AccessibilityRenderObject(renderer);
128 return adoptRef(obj);
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 static_cast<Element*>(node);
584 String AccessibilityRenderObject::helpText() const
589 const AtomicString& ariaHelp = getAttribute(aria_helpAttr);
590 if (!ariaHelp.isEmpty())
593 String describedBy = ariaDescribedByAttribute();
594 if (!describedBy.isEmpty())
597 String description = accessibilityDescription();
598 for (RenderObject* curr = m_renderer; curr; curr = curr->parent()) {
599 if (curr->node() && curr->node()->isHTMLElement()) {
600 const AtomicString& summary = static_cast<Element*>(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 = static_cast<Element*>(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(static_cast<Element*>(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* element = m_renderer->node();
1049 HTMLLabelElement* label = labelForElement(static_cast<Element*>(element));
1050 if (label && label->renderer())
1051 return axObjectCache()->getOrCreate(label);
1056 bool AccessibilityRenderObject::ariaIsHidden() const
1058 if (equalIgnoringCase(getAttribute(aria_hiddenAttr), "true"))
1061 // aria-hidden hides this object and any children
1062 AccessibilityObject* object = parentObject();
1064 if (equalIgnoringCase(object->getAttribute(aria_hiddenAttr), "true"))
1066 object = object->parentObject();
1072 bool AccessibilityRenderObject::isAllowedChildOfTree() const
1074 // Determine if this is in a tree. If so, we apply special behavior to make it work like an AXOutline.
1075 AccessibilityObject* axObj = parentObject();
1076 bool isInTree = false;
1078 if (axObj->isTree()) {
1082 axObj = axObj->parentObject();
1085 // If the object is in a tree, only tree items should be exposed (and the children of tree items).
1087 AccessibilityRole role = roleValue();
1088 if (role != TreeItemRole && role != StaticTextRole)
1094 AccessibilityObjectInclusion AccessibilityRenderObject::accessibilityIsIgnoredBase() const
1096 // The following cases can apply to any element that's a subclass of AccessibilityRenderObject.
1099 return IgnoreObject;
1101 if (m_renderer->style()->visibility() != VISIBLE) {
1102 // aria-hidden is meant to override visibility as the determinant in AX hierarchy inclusion.
1103 if (equalIgnoringCase(getAttribute(aria_hiddenAttr), "false"))
1104 return DefaultBehavior;
1106 return IgnoreObject;
1109 // Anything marked as aria-hidden or a child of something aria-hidden must be hidden.
1111 return IgnoreObject;
1113 // Anything that is a presentational role must be hidden.
1114 if (isPresentationalChildOfAriaRole())
1115 return IgnoreObject;
1117 // Allow the platform to make a decision.
1118 AccessibilityObjectInclusion decision = accessibilityPlatformIncludesObject();
1119 if (decision == IncludeObject)
1120 return IncludeObject;
1121 if (decision == IgnoreObject)
1122 return IgnoreObject;
1124 return DefaultBehavior;
1127 bool AccessibilityRenderObject::accessibilityIsIgnored() const
1129 // Check first if any of the common reasons cause this element to be ignored.
1130 // Then process other use cases that need to be applied to all the various roles
1131 // that AccessibilityRenderObjects take on.
1132 AccessibilityObjectInclusion decision = accessibilityIsIgnoredBase();
1133 if (decision == IncludeObject)
1135 if (decision == IgnoreObject)
1138 // If this element is within a parent that cannot have children, it should not be exposed.
1139 if (isDescendantOfBarrenParent())
1142 if (roleValue() == IgnoredRole)
1145 if (roleValue() == PresentationalRole || inheritsPresentationalRole())
1148 // An ARIA tree can only have tree items and static text as children.
1149 if (!isAllowedChildOfTree())
1152 // Allow the platform to decide if the attachment is ignored or not.
1154 return accessibilityIgnoreAttachment();
1156 // ignore popup menu items because AppKit does
1157 for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
1158 if (parent->isBoxModelObject() && toRenderBoxModelObject(parent)->isMenuList())
1162 // find out if this element is inside of a label element.
1163 // if so, it may be ignored because it's the label for a checkbox or radio button
1164 AccessibilityObject* controlObject = correspondingControlForLabelElement();
1165 if (controlObject && !controlObject->exposesTitleUIElement() && controlObject->isCheckboxOrRadio())
1168 // NOTE: BRs always have text boxes now, so the text box check here can be removed
1169 if (m_renderer->isText()) {
1170 // static text beneath MenuItems and MenuButtons are just reported along with the menu item, so it's ignored on an individual level
1171 AccessibilityObject* parent = parentObjectUnignored();
1172 if (parent && (parent->ariaRoleAttribute() == MenuItemRole || parent->ariaRoleAttribute() == MenuButtonRole))
1174 RenderText* renderText = toRenderText(m_renderer);
1175 if (m_renderer->isBR() || !renderText->firstTextBox())
1178 // static text beneath TextControls is reported along with the text control text so it's ignored.
1179 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
1180 if (parent->roleValue() == TextFieldRole)
1184 // text elements that are just empty whitespace should not be returned
1185 return renderText->text()->containsOnlyWhitespace();
1194 // all controls are accessible
1198 if (ariaRoleAttribute() != UnknownRole)
1201 // don't ignore labels, because they serve as TitleUIElements
1202 Node* node = m_renderer->node();
1203 if (node && node->hasTagName(labelTag))
1206 // Anything that is content editable should not be ignored.
1207 // However, one cannot just call node->rendererIsEditable() since that will ask if its parents
1208 // are also editable. Only the top level content editable region should be exposed.
1209 if (hasContentEditableAttributeSet())
1212 // List items play an important role in defining the structure of lists. They should not be ignored.
1213 if (roleValue() == ListItemRole)
1216 // if this element has aria attributes on it, it should not be ignored.
1217 if (supportsARIAAttributes())
1221 // First check if this is a special case within the math tree that needs to be ignored.
1222 if (isIgnoredElementWithinMathTree())
1224 // Otherwise all other math elements are in the tree.
1225 if (isMathElement())
1229 // <span> tags are inline tags and not meant to convey information if they have no other aria
1230 // information on them. If we don't ignore them, they may emit signals expected to come from
1231 // their parent. In addition, because included spans are GroupRole objects, and GroupRole
1232 // objects are often containers with meaningful information, the inclusion of a span can have
1233 // the side effect of causing the immediate parent accessible to be ignored. This is especially
1234 // problematic for platforms which have distinct roles for textual block elements.
1235 if (node && node->hasTagName(spanTag))
1238 if (m_renderer->isBlockFlow() && m_renderer->childrenInline() && !canSetFocusAttribute())
1239 return !toRenderBlock(m_renderer)->firstLineBox() && !mouseButtonListener();
1241 // ignore images seemingly used as spacers
1244 // If the image can take focus, it should not be ignored, lest the user not be able to interact with something important.
1245 if (canSetFocusAttribute())
1248 if (node && node->isElementNode()) {
1249 Element* elt = static_cast<Element*>(node);
1250 const AtomicString& alt = elt->getAttribute(altAttr);
1251 // don't ignore an image that has an alt tag
1252 if (!alt.string().containsOnlyWhitespace())
1254 // informal standard is to ignore images with zero-length alt strings
1259 if (isNativeImage()) {
1260 // check for one-dimensional image
1261 RenderImage* image = toRenderImage(m_renderer);
1262 if (image->height() <= 1 || image->width() <= 1)
1265 // check whether rendered image was stretched from one-dimensional file image
1266 if (image->cachedImage()) {
1267 LayoutSize imageSize = image->cachedImage()->imageSizeForRenderer(m_renderer, image->view()->zoomFactor());
1268 return imageSize.height() <= 1 || imageSize.width() <= 1;
1275 if (canvasHasFallbackContent())
1277 RenderHTMLCanvas* canvas = toRenderHTMLCanvas(m_renderer);
1278 if (canvas->height() <= 1 || canvas->width() <= 1)
1280 // Otherwise fall through; use presence of help text, title, or description to decide.
1283 if (isWebArea() || isSeamlessWebArea() || m_renderer->isListMarker())
1286 // Using the help text, title or accessibility description (so we
1287 // check if there's some kind of accessible name for the element)
1288 // to decide an element's visibility is not as definitive as
1289 // previous checks, so this should remain as one of the last.
1291 // These checks are simplified in the interest of execution speed;
1292 // for example, any element having an alt attribute will make it
1293 // not ignored, rather than just images.
1294 if (!getAttribute(aria_helpAttr).isEmpty() || !getAttribute(aria_describedbyAttr).isEmpty() || !getAttribute(altAttr).isEmpty() || !getAttribute(titleAttr).isEmpty())
1297 // Don't ignore generic focusable elements like <div tabindex=0>
1298 // unless they're completely empty, with no children.
1299 if (isGenericFocusableElement() && node->firstChild())
1302 if (!ariaAccessibilityDescription().isEmpty())
1306 if (!getAttribute(MathMLNames::alttextAttr).isEmpty())
1310 // By default, objects should be ignored so that the AX hierarchy is not
1311 // filled with unnecessary items.
1315 bool AccessibilityRenderObject::isLoaded() const
1317 return !m_renderer->document()->parser();
1320 double AccessibilityRenderObject::estimatedLoadingProgress() const
1328 Page* page = m_renderer->document()->page();
1332 return page->progress()->estimatedProgress();
1335 int AccessibilityRenderObject::layoutCount() const
1337 if (!m_renderer->isRenderView())
1339 return toRenderView(m_renderer)->frameView()->layoutCount();
1342 String AccessibilityRenderObject::text() const
1344 if (isPasswordField())
1345 return passwordFieldValue();
1347 return AccessibilityNodeObject::text();
1350 int AccessibilityRenderObject::textLength() const
1352 ASSERT(isTextControl());
1354 if (isPasswordField())
1356 return passwordFieldValue().length();
1358 return -1; // need to return something distinct from 0
1361 return text().length();
1364 PlainTextRange AccessibilityRenderObject::ariaSelectedTextRange() const
1366 Node* node = m_renderer->node();
1368 return PlainTextRange();
1370 ExceptionCode ec = 0;
1371 VisibleSelection visibleSelection = selection();
1372 RefPtr<Range> currentSelectionRange = visibleSelection.toNormalizedRange();
1373 if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, ec))
1374 return PlainTextRange();
1376 int start = indexForVisiblePosition(visibleSelection.start());
1377 int end = indexForVisiblePosition(visibleSelection.end());
1379 return PlainTextRange(start, end - start);
1382 String AccessibilityRenderObject::selectedText() const
1384 ASSERT(isTextControl());
1386 if (isPasswordField())
1387 return String(); // need to return something distinct from empty string
1389 if (isNativeTextControl()) {
1390 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1391 return textControl->selectedText();
1394 if (ariaRoleAttribute() == UnknownRole)
1397 return doAXStringForRange(ariaSelectedTextRange());
1400 const AtomicString& AccessibilityRenderObject::accessKey() const
1402 Node* node = m_renderer->node();
1405 if (!node->isElementNode())
1407 return static_cast<Element*>(node)->getAttribute(accesskeyAttr);
1410 VisibleSelection AccessibilityRenderObject::selection() const
1412 return m_renderer->frame()->selection()->selection();
1415 PlainTextRange AccessibilityRenderObject::selectedTextRange() const
1417 ASSERT(isTextControl());
1419 if (isPasswordField())
1420 return PlainTextRange();
1422 AccessibilityRole ariaRole = ariaRoleAttribute();
1423 if (isNativeTextControl() && ariaRole == UnknownRole) {
1424 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1425 return PlainTextRange(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());
1428 if (ariaRole == UnknownRole)
1429 return PlainTextRange();
1431 return ariaSelectedTextRange();
1434 void AccessibilityRenderObject::setSelectedTextRange(const PlainTextRange& range)
1436 if (isNativeTextControl()) {
1437 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1438 textControl->setSelectionRange(range.start, range.start + range.length);
1442 Document* document = m_renderer->document();
1445 Frame* frame = document->frame();
1448 Node* node = m_renderer->node();
1449 frame->selection()->setSelection(VisibleSelection(Position(node, range.start, Position::PositionIsOffsetInAnchor),
1450 Position(node, range.start + range.length, Position::PositionIsOffsetInAnchor), DOWNSTREAM));
1453 KURL AccessibilityRenderObject::url() const
1455 if (isAnchor() && m_renderer->node()->hasTagName(aTag)) {
1456 if (HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(anchorElement()))
1457 return anchor->href();
1461 return m_renderer->document()->url();
1463 if (isImage() && m_renderer->node() && m_renderer->node()->hasTagName(imgTag))
1464 return static_cast<HTMLImageElement*>(m_renderer->node())->src();
1467 return static_cast<HTMLInputElement*>(m_renderer->node())->src();
1472 bool AccessibilityRenderObject::isUnvisited() const
1474 // FIXME: Is it a privacy violation to expose unvisited information to accessibility APIs?
1475 return m_renderer->style()->isLink() && m_renderer->style()->insideLink() == InsideUnvisitedLink;
1478 bool AccessibilityRenderObject::isVisited() const
1480 // FIXME: Is it a privacy violation to expose visited information to accessibility APIs?
1481 return m_renderer->style()->isLink() && m_renderer->style()->insideLink() == InsideVisitedLink;
1484 void AccessibilityRenderObject::setElementAttributeValue(const QualifiedName& attributeName, bool value)
1489 Node* node = m_renderer->node();
1490 if (!node || !node->isElementNode())
1493 Element* element = static_cast<Element*>(node);
1494 element->setAttribute(attributeName, (value) ? "true" : "false");
1497 bool AccessibilityRenderObject::elementAttributeValue(const QualifiedName& attributeName) const
1502 return equalIgnoringCase(getAttribute(attributeName), "true");
1505 bool AccessibilityRenderObject::isSelected() const
1510 Node* node = m_renderer->node();
1514 const AtomicString& ariaSelected = getAttribute(aria_selectedAttr);
1515 if (equalIgnoringCase(ariaSelected, "true"))
1518 if (isTabItem() && isTabItemSelected())
1524 bool AccessibilityRenderObject::isTabItemSelected() const
1526 if (!isTabItem() || !m_renderer)
1529 Node* node = m_renderer->node();
1530 if (!node || !node->isElementNode())
1533 // The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel
1534 // that has keyboard focus inside of it, or if a tabpanel in its aria-controls list has KB
1535 // focus inside of it.
1536 AccessibilityObject* focusedElement = focusedUIElement();
1537 if (!focusedElement)
1540 Vector<Element*> elements;
1541 elementsFromAttribute(elements, aria_controlsAttr);
1543 unsigned count = elements.size();
1544 for (unsigned k = 0; k < count; ++k) {
1545 Element* element = elements[k];
1546 AccessibilityObject* tabPanel = axObjectCache()->getOrCreate(element);
1548 // A tab item should only control tab panels.
1549 if (!tabPanel || tabPanel->roleValue() != TabPanelRole)
1552 AccessibilityObject* checkFocusElement = focusedElement;
1553 // Check if the focused element is a descendant of the element controlled by the tab item.
1554 while (checkFocusElement) {
1555 if (tabPanel == checkFocusElement)
1557 checkFocusElement = checkFocusElement->parentObject();
1564 bool AccessibilityRenderObject::isFocused() const
1569 Document* document = m_renderer->document();
1573 Node* focusedNode = document->focusedNode();
1577 // A web area is represented by the Document node in the DOM tree, which isn't focusable.
1578 // Check instead if the frame's selection controller is focused
1579 if (focusedNode == m_renderer->node()
1580 || (roleValue() == WebAreaRole && document->frame()->selection()->isFocusedAndActive()))
1586 void AccessibilityRenderObject::setFocused(bool on)
1588 if (!canSetFocusAttribute())
1591 Document* document = this->document();
1593 document->setFocusedNode(0);
1595 Node* node = this->node();
1596 if (node && node->isElementNode()) {
1597 // If this node is already the currently focused node, then calling focus() won't do anything.
1598 // That is a problem when focus is removed from the webpage to chrome, and then returns.
1599 // In these cases, we need to do what keyboard and mouse focus do, which is reset focus first.
1600 if (document->focusedNode() == node)
1601 document->setFocusedNode(0);
1603 toElement(node)->focus();
1605 document->setFocusedNode(node);
1609 void AccessibilityRenderObject::setSelectedRows(AccessibilityChildrenVector& selectedRows)
1611 // Setting selected only makes sense in trees and tables (and tree-tables).
1612 AccessibilityRole role = roleValue();
1613 if (role != TreeRole && role != TreeGridRole && role != TableRole)
1616 bool isMulti = isMultiSelectable();
1617 unsigned count = selectedRows.size();
1618 if (count > 1 && !isMulti)
1621 for (unsigned k = 0; k < count; ++k)
1622 selectedRows[k]->setSelected(true);
1625 void AccessibilityRenderObject::setValue(const String& string)
1627 if (!m_renderer || !m_renderer->node() || !m_renderer->node()->isElementNode())
1629 Element* element = static_cast<Element*>(m_renderer->node());
1631 if (!m_renderer->isBoxModelObject())
1633 RenderBoxModelObject* renderer = toRenderBoxModelObject(m_renderer);
1635 // FIXME: Do we want to do anything here for ARIA textboxes?
1636 if (renderer->isTextField()) {
1637 // FIXME: This is not safe! Other elements could have a TextField renderer.
1638 static_cast<HTMLInputElement*>(element)->setValue(string);
1639 } else if (renderer->isTextArea()) {
1640 // FIXME: This is not safe! Other elements could have a TextArea renderer.
1641 static_cast<HTMLTextAreaElement*>(element)->setValue(string);
1645 void AccessibilityRenderObject::ariaOwnsElements(AccessibilityChildrenVector& axObjects) const
1647 Vector<Element*> elements;
1648 elementsFromAttribute(elements, aria_ownsAttr);
1650 unsigned count = elements.size();
1651 for (unsigned k = 0; k < count; ++k) {
1652 RenderObject* render = elements[k]->renderer();
1653 AccessibilityObject* obj = axObjectCache()->getOrCreate(render);
1655 axObjects.append(obj);
1659 bool AccessibilityRenderObject::supportsARIAOwns() const
1663 const AtomicString& ariaOwns = getAttribute(aria_ownsAttr);
1665 return !ariaOwns.isEmpty();
1668 RenderView* AccessibilityRenderObject::topRenderer() const
1670 Document* topDoc = topDocument();
1674 return topDoc->renderView();
1677 Document* AccessibilityRenderObject::document() const
1681 return m_renderer->document();
1684 Document* AccessibilityRenderObject::topDocument() const
1688 return document()->topDocument();
1691 FrameView* AccessibilityRenderObject::topDocumentFrameView() const
1693 RenderView* renderView = topRenderer();
1694 if (!renderView || !renderView->view())
1696 return renderView->view()->frameView();
1699 Widget* AccessibilityRenderObject::widget() const
1701 if (!m_renderer->isBoxModelObject() || !toRenderBoxModelObject(m_renderer)->isWidget())
1703 return toRenderWidget(m_renderer)->widget();
1706 AccessibilityObject* AccessibilityRenderObject::accessibilityParentForImageMap(HTMLMapElement* map) const
1708 // find an image that is using this map
1712 HTMLImageElement* imageElement = map->imageElement();
1716 return axObjectCache()->getOrCreate(imageElement);
1719 void AccessibilityRenderObject::getDocumentLinks(AccessibilityChildrenVector& result)
1721 Document* document = m_renderer->document();
1722 RefPtr<HTMLCollection> links = document->links();
1723 for (unsigned i = 0; Node* curr = links->item(i); i++) {
1724 RenderObject* obj = curr->renderer();
1726 RefPtr<AccessibilityObject> axobj = document->axObjectCache()->getOrCreate(obj);
1728 if (!axobj->accessibilityIsIgnored() && axobj->isLink())
1729 result.append(axobj);
1731 Node* parent = curr->parentNode();
1732 if (parent && curr->hasTagName(areaTag) && parent->hasTagName(mapTag)) {
1733 AccessibilityImageMapLink* areaObject = static_cast<AccessibilityImageMapLink*>(axObjectCache()->getOrCreate(ImageMapLinkRole));
1734 areaObject->setHTMLAreaElement(static_cast<HTMLAreaElement*>(curr));
1735 areaObject->setHTMLMapElement(static_cast<HTMLMapElement*>(parent));
1736 areaObject->setParent(accessibilityParentForImageMap(static_cast<HTMLMapElement*>(parent)));
1738 result.append(areaObject);
1744 FrameView* AccessibilityRenderObject::documentFrameView() const
1746 if (!m_renderer || !m_renderer->document())
1749 // this is the RenderObject's Document's Frame's FrameView
1750 return m_renderer->document()->view();
1753 Widget* AccessibilityRenderObject::widgetForAttachmentView() const
1755 if (!isAttachment())
1757 return toRenderWidget(m_renderer)->widget();
1760 FrameView* AccessibilityRenderObject::frameViewIfRenderView() const
1762 if (!m_renderer->isRenderView())
1764 // this is the RenderObject's Document's renderer's FrameView
1765 return m_renderer->view()->frameView();
1768 // This function is like a cross-platform version of - (WebCoreTextMarkerRange*)textMarkerRange. It returns
1769 // a Range that we can convert to a WebCoreTextMarkerRange in the Obj-C file
1770 VisiblePositionRange AccessibilityRenderObject::visiblePositionRange() const
1773 return VisiblePositionRange();
1775 // construct VisiblePositions for start and end
1776 Node* node = m_renderer->node();
1778 return VisiblePositionRange();
1780 VisiblePosition startPos = firstPositionInOrBeforeNode(node);
1781 VisiblePosition endPos = lastPositionInOrAfterNode(node);
1783 // the VisiblePositions are equal for nodes like buttons, so adjust for that
1784 // FIXME: Really? [button, 0] and [button, 1] are distinct (before and after the button)
1785 // I expect this code is only hit for things like empty divs? In which case I don't think
1786 // the behavior is correct here -- eseidel
1787 if (startPos == endPos) {
1788 endPos = endPos.next();
1789 if (endPos.isNull())
1793 return VisiblePositionRange(startPos, endPos);
1796 VisiblePositionRange AccessibilityRenderObject::visiblePositionRangeForLine(unsigned lineCount) const
1798 if (!lineCount || !m_renderer)
1799 return VisiblePositionRange();
1801 // iterate over the lines
1802 // FIXME: this is wrong when lineNumber is lineCount+1, because nextLinePosition takes you to the
1803 // last offset of the last line
1804 VisiblePosition visiblePos = m_renderer->document()->renderer()->positionForPoint(IntPoint());
1805 VisiblePosition savedVisiblePos;
1806 while (--lineCount) {
1807 savedVisiblePos = visiblePos;
1808 visiblePos = nextLinePosition(visiblePos, 0);
1809 if (visiblePos.isNull() || visiblePos == savedVisiblePos)
1810 return VisiblePositionRange();
1813 // make a caret selection for the marker position, then extend it to the line
1814 // NOTE: ignores results of sel.modify because it returns false when
1815 // starting at an empty line. The resulting selection in that case
1816 // will be a caret at visiblePos.
1817 FrameSelection selection;
1818 selection.setSelection(VisibleSelection(visiblePos));
1819 selection.modify(FrameSelection::AlterationExtend, DirectionRight, LineBoundary);
1821 return VisiblePositionRange(selection.selection().visibleStart(), selection.selection().visibleEnd());
1824 VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(int index) const
1827 return VisiblePosition();
1829 if (isNativeTextControl())
1830 return toRenderTextControl(m_renderer)->visiblePositionForIndex(index);
1832 if (!allowsTextRanges() && !m_renderer->isText())
1833 return VisiblePosition();
1835 Node* node = m_renderer->node();
1837 return VisiblePosition();
1840 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
1842 ExceptionCode ec = 0;
1843 RefPtr<Range> range = Range::create(m_renderer->document());
1844 range->selectNodeContents(node, ec);
1845 CharacterIterator it(range.get());
1846 it.advance(index - 1);
1847 return VisiblePosition(Position(it.range()->endContainer(ec), it.range()->endOffset(ec), Position::PositionIsOffsetInAnchor), UPSTREAM);
1850 int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
1852 if (isNativeTextControl()) {
1853 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1854 return textControl->indexForVisiblePosition(pos);
1857 if (!isTextControl())
1860 Node* node = m_renderer->node();
1864 Position indexPosition = pos.deepEquivalent();
1865 if (indexPosition.isNull() || highestEditableRoot(indexPosition, HasEditableAXRole) != node)
1868 ExceptionCode ec = 0;
1869 RefPtr<Range> range = Range::create(m_renderer->document());
1870 range->setStart(node, 0, ec);
1871 range->setEnd(indexPosition, ec);
1874 // We need to consider replaced elements for GTK, as they will be
1875 // presented with the 'object replacement character' (0xFFFC).
1876 return TextIterator::rangeLength(range.get(), true);
1878 return TextIterator::rangeLength(range.get());
1882 Element* AccessibilityRenderObject::rootEditableElementForPosition(const Position& position) const
1884 // Find the root editable or pseudo-editable (i.e. having an editable ARIA role) element.
1885 Element* result = 0;
1887 Element* rootEditableElement = position.rootEditableElement();
1889 for (Element* e = position.element(); e && e != rootEditableElement; e = e->parentElement()) {
1890 if (nodeIsTextControl(e))
1892 if (e->hasTagName(bodyTag))
1899 return rootEditableElement;
1902 bool AccessibilityRenderObject::nodeIsTextControl(const Node* node) const
1907 const AccessibilityObject* axObjectForNode = axObjectCache()->getOrCreate(const_cast<Node*>(node));
1908 if (!axObjectForNode)
1911 return axObjectForNode->isTextControl();
1914 IntRect AccessibilityRenderObject::boundsForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange) const
1916 if (visiblePositionRange.isNull())
1919 // Create a mutable VisiblePositionRange.
1920 VisiblePositionRange range(visiblePositionRange);
1921 LayoutRect rect1 = range.start.absoluteCaretBounds();
1922 LayoutRect rect2 = range.end.absoluteCaretBounds();
1924 // 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
1925 if (rect2.y() != rect1.y()) {
1926 VisiblePosition endOfFirstLine = endOfLine(range.start);
1927 if (range.start == endOfFirstLine) {
1928 range.start.setAffinity(DOWNSTREAM);
1929 rect1 = range.start.absoluteCaretBounds();
1931 if (range.end == endOfFirstLine) {
1932 range.end.setAffinity(UPSTREAM);
1933 rect2 = range.end.absoluteCaretBounds();
1937 LayoutRect ourrect = rect1;
1938 ourrect.unite(rect2);
1940 // if the rectangle spans lines and contains multiple text chars, use the range's bounding box intead
1941 if (rect1.maxY() != rect2.maxY()) {
1942 RefPtr<Range> dataRange = makeRange(range.start, range.end);
1943 LayoutRect boundingBox = dataRange->boundingBox();
1944 String rangeString = plainText(dataRange.get());
1945 if (rangeString.length() > 1 && !boundingBox.isEmpty())
1946 ourrect = boundingBox;
1950 return m_renderer->document()->view()->contentsToScreen(pixelSnappedIntRect(ourrect));
1952 return pixelSnappedIntRect(ourrect);
1956 void AccessibilityRenderObject::setSelectedVisiblePositionRange(const VisiblePositionRange& range) const
1958 if (range.start.isNull() || range.end.isNull())
1961 // make selection and tell the document to use it. if it's zero length, then move to that position
1962 if (range.start == range.end)
1963 m_renderer->frame()->selection()->moveTo(range.start, UserTriggered);
1965 VisibleSelection newSelection = VisibleSelection(range.start, range.end);
1966 m_renderer->frame()->selection()->setSelection(newSelection);
1970 VisiblePosition AccessibilityRenderObject::visiblePositionForPoint(const IntPoint& point) const
1973 return VisiblePosition();
1975 // convert absolute point to view coordinates
1976 RenderView* renderView = topRenderer();
1978 return VisiblePosition();
1980 FrameView* frameView = renderView->frameView();
1982 return VisiblePosition();
1984 Node* innerNode = 0;
1986 // locate the node containing the point
1987 LayoutPoint pointResult;
1989 LayoutPoint ourpoint;
1991 ourpoint = frameView->screenToContents(point);
1995 HitTestRequest request(HitTestRequest::ReadOnly |
1996 HitTestRequest::Active);
1997 HitTestResult result(ourpoint);
1998 renderView->hitTest(request, result);
1999 innerNode = result.innerNode();
2001 return VisiblePosition();
2003 RenderObject* renderer = innerNode->renderer();
2005 return VisiblePosition();
2007 pointResult = result.localPoint();
2009 // done if hit something other than a widget
2010 if (!renderer->isWidget())
2013 // descend into widget (FRAME, IFRAME, OBJECT...)
2014 Widget* widget = toRenderWidget(renderer)->widget();
2015 if (!widget || !widget->isFrameView())
2017 Frame* frame = static_cast<FrameView*>(widget)->frame();
2020 renderView = frame->document()->renderView();
2021 frameView = static_cast<FrameView*>(widget);
2024 return innerNode->renderer()->positionForPoint(pointResult);
2027 // NOTE: Consider providing this utility method as AX API
2028 VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(unsigned indexValue, bool lastIndexOK) const
2030 if (!isTextControl())
2031 return VisiblePosition();
2033 // lastIndexOK specifies whether the position after the last character is acceptable
2034 if (indexValue >= text().length()) {
2035 if (!lastIndexOK || indexValue > text().length())
2036 return VisiblePosition();
2038 VisiblePosition position = visiblePositionForIndex(indexValue);
2039 position.setAffinity(DOWNSTREAM);
2043 // NOTE: Consider providing this utility method as AX API
2044 int AccessibilityRenderObject::index(const VisiblePosition& position) const
2046 if (position.isNull() || !isTextControl())
2049 if (renderObjectContainsPosition(m_renderer, position.deepEquivalent()))
2050 return indexForVisiblePosition(position);
2055 void AccessibilityRenderObject::lineBreaks(Vector<int>& lineBreaks) const
2057 if (!isTextControl())
2060 VisiblePosition visiblePos = visiblePositionForIndex(0);
2061 VisiblePosition savedVisiblePos = visiblePos;
2062 visiblePos = nextLinePosition(visiblePos, 0);
2063 while (!visiblePos.isNull() && visiblePos != savedVisiblePos) {
2064 lineBreaks.append(indexForVisiblePosition(visiblePos));
2065 savedVisiblePos = visiblePos;
2066 visiblePos = nextLinePosition(visiblePos, 0);
2070 // Given a line number, the range of characters of the text associated with this accessibility
2071 // object that contains the line number.
2072 PlainTextRange AccessibilityRenderObject::doAXRangeForLine(unsigned lineNumber) const
2074 if (!isTextControl())
2075 return PlainTextRange();
2077 // iterate to the specified line
2078 VisiblePosition visiblePos = visiblePositionForIndex(0);
2079 VisiblePosition savedVisiblePos;
2080 for (unsigned lineCount = lineNumber; lineCount; lineCount -= 1) {
2081 savedVisiblePos = visiblePos;
2082 visiblePos = nextLinePosition(visiblePos, 0);
2083 if (visiblePos.isNull() || visiblePos == savedVisiblePos)
2084 return PlainTextRange();
2087 // Get the end of the line based on the starting position.
2088 VisiblePosition endPosition = endOfLine(visiblePos);
2090 int index1 = indexForVisiblePosition(visiblePos);
2091 int index2 = indexForVisiblePosition(endPosition);
2093 // add one to the end index for a line break not caused by soft line wrap (to match AppKit)
2094 if (endPosition.affinity() == DOWNSTREAM && endPosition.next().isNotNull())
2097 // return nil rather than an zero-length range (to match AppKit)
2098 if (index1 == index2)
2099 return PlainTextRange();
2101 return PlainTextRange(index1, index2 - index1);
2104 // The composed character range in the text associated with this accessibility object that
2105 // is specified by the given index value. This parameterized attribute returns the complete
2106 // range of characters (including surrogate pairs of multi-byte glyphs) at the given index.
2107 PlainTextRange AccessibilityRenderObject::doAXRangeForIndex(unsigned index) const
2109 if (!isTextControl())
2110 return PlainTextRange();
2112 String elementText = text();
2113 if (!elementText.length() || index > elementText.length() - 1)
2114 return PlainTextRange();
2116 return PlainTextRange(index, 1);
2119 // A substring of the text associated with this accessibility object that is
2120 // specified by the given character range.
2121 String AccessibilityRenderObject::doAXStringForRange(const PlainTextRange& range) const
2126 if (!isTextControl())
2129 String elementText = isPasswordField() ? passwordFieldValue() : text();
2130 if (range.start + range.length > elementText.length())
2133 return elementText.substring(range.start, range.length);
2136 // The bounding rectangle of the text associated with this accessibility object that is
2137 // specified by the given range. This is the bounding rectangle a sighted user would see
2138 // on the display screen, in pixels.
2139 IntRect AccessibilityRenderObject::doAXBoundsForRange(const PlainTextRange& range) const
2141 if (allowsTextRanges())
2142 return boundsForVisiblePositionRange(visiblePositionRangeForRange(range));
2146 AccessibilityObject* AccessibilityRenderObject::accessibilityImageMapHitTest(HTMLAreaElement* area, const IntPoint& point) const
2151 HTMLMapElement* map = static_cast<HTMLMapElement*>(area->parentNode());
2152 AccessibilityObject* parent = accessibilityParentForImageMap(map);
2156 AccessibilityObject::AccessibilityChildrenVector children = parent->children();
2158 unsigned count = children.size();
2159 for (unsigned k = 0; k < count; ++k) {
2160 if (children[k]->elementRect().contains(point))
2161 return children[k].get();
2167 AccessibilityObject* AccessibilityRenderObject::remoteSVGElementHitTest(const IntPoint& point) const
2169 AccessibilityObject* remote = remoteSVGRootElement();
2173 IntSize offset = point - roundedIntPoint(boundingBoxRect().location());
2174 return remote->accessibilityHitTest(IntPoint(offset));
2177 AccessibilityObject* AccessibilityRenderObject::elementAccessibilityHitTest(const IntPoint& point) const
2180 return remoteSVGElementHitTest(point);
2182 return AccessibilityObject::elementAccessibilityHitTest(point);
2185 AccessibilityObject* AccessibilityRenderObject::accessibilityHitTest(const IntPoint& point) const
2187 if (!m_renderer || !m_renderer->hasLayer())
2190 RenderLayer* layer = toRenderBox(m_renderer)->layer();
2192 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
2193 HitTestResult hitTestResult = HitTestResult(point);
2194 layer->hitTest(request, hitTestResult);
2195 if (!hitTestResult.innerNode())
2197 Node* node = hitTestResult.innerNode()->shadowAncestorNode();
2199 if (node->hasTagName(areaTag))
2200 return accessibilityImageMapHitTest(static_cast<HTMLAreaElement*>(node), point);
2202 if (node->hasTagName(optionTag))
2203 node = static_cast<HTMLOptionElement*>(node)->ownerSelectElement();
2205 RenderObject* obj = node->renderer();
2209 AccessibilityObject* result = obj->document()->axObjectCache()->getOrCreate(obj);
2210 result->updateChildrenIfNecessary();
2212 // Allow the element to perform any hit-testing it might need to do to reach non-render children.
2213 result = result->elementAccessibilityHitTest(point);
2215 if (result && result->accessibilityIsIgnored()) {
2216 // If this element is the label of a control, a hit test should return the control.
2217 AccessibilityObject* controlObject = result->correspondingControlForLabelElement();
2218 if (controlObject && !controlObject->exposesTitleUIElement())
2219 return controlObject;
2221 result = result->parentObjectUnignored();
2227 bool AccessibilityRenderObject::shouldFocusActiveDescendant() const
2229 switch (ariaRoleAttribute()) {
2235 case RadioGroupRole:
2237 case PopUpButtonRole:
2238 case ProgressIndicatorRole:
2243 /* FIXME: replace these with actual roles when they are added to AccessibilityRole
2256 AccessibilityObject* AccessibilityRenderObject::activeDescendant() const
2261 if (m_renderer->node() && !m_renderer->node()->isElementNode())
2263 Element* element = static_cast<Element*>(m_renderer->node());
2265 const AtomicString& activeDescendantAttrStr = element->getAttribute(aria_activedescendantAttr);
2266 if (activeDescendantAttrStr.isNull() || activeDescendantAttrStr.isEmpty())
2269 Element* target = element->treeScope()->getElementById(activeDescendantAttrStr);
2273 AccessibilityObject* obj = axObjectCache()->getOrCreate(target);
2274 if (obj && obj->isAccessibilityRenderObject())
2275 // an activedescendant is only useful if it has a renderer, because that's what's needed to post the notification
2280 void AccessibilityRenderObject::handleAriaExpandedChanged()
2282 // Find if a parent of this object should handle aria-expanded changes.
2283 AccessibilityObject* containerParent = this->parentObject();
2284 while (containerParent) {
2285 bool foundParent = false;
2287 switch (containerParent->roleValue()) {
2302 containerParent = containerParent->parentObject();
2305 // Post that the row count changed.
2306 if (containerParent)
2307 axObjectCache()->postNotification(containerParent, document(), AXObjectCache::AXRowCountChanged, true);
2309 // Post that the specific row either collapsed or expanded.
2310 if (roleValue() == RowRole || roleValue() == TreeItemRole)
2311 axObjectCache()->postNotification(this, document(), isExpanded() ? AXObjectCache::AXRowExpanded : AXObjectCache::AXRowCollapsed, true);
2314 void AccessibilityRenderObject::handleActiveDescendantChanged()
2316 Element* element = static_cast<Element*>(renderer()->node());
2319 Document* doc = renderer()->document();
2320 if (!doc->frame()->selection()->isFocusedAndActive() || doc->focusedNode() != element)
2322 AccessibilityRenderObject* activedescendant = static_cast<AccessibilityRenderObject*>(activeDescendant());
2324 if (activedescendant && shouldFocusActiveDescendant())
2325 doc->axObjectCache()->postNotification(m_renderer, AXObjectCache::AXActiveDescendantChanged, true);
2328 AccessibilityObject* AccessibilityRenderObject::correspondingControlForLabelElement() const
2330 HTMLLabelElement* labelElement = labelElementContainer();
2334 HTMLElement* correspondingControl = labelElement->control();
2335 if (!correspondingControl)
2338 // Make sure the corresponding control isn't a descendant of this label that's in the middle of being destroyed.
2339 if (correspondingControl->renderer() && !correspondingControl->renderer()->parent())
2342 return axObjectCache()->getOrCreate(correspondingControl);
2345 AccessibilityObject* AccessibilityRenderObject::correspondingLabelForControlElement() const
2350 // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
2351 // override the "label" element association.
2352 if (hasTextAlternative())
2355 Node* node = m_renderer->node();
2356 if (node && node->isHTMLElement()) {
2357 HTMLLabelElement* label = labelForElement(static_cast<Element*>(node));
2359 return axObjectCache()->getOrCreate(label);
2365 bool AccessibilityRenderObject::renderObjectIsObservable(RenderObject* renderer) const
2367 // AX clients will listen for AXValueChange on a text control.
2368 if (renderer->isTextControl())
2371 // AX clients will listen for AXSelectedChildrenChanged on listboxes.
2372 Node* node = renderer->node();
2373 if (nodeHasRole(node, "listbox") || (renderer->isBoxModelObject() && toRenderBoxModelObject(renderer)->isListBox()))
2376 // Textboxes should send out notifications.
2377 if (nodeHasRole(node, "textbox"))
2383 AccessibilityObject* AccessibilityRenderObject::observableObject() const
2385 // Find the object going up the parent chain that is used in accessibility to monitor certain notifications.
2386 for (RenderObject* renderer = m_renderer; renderer && renderer->node(); renderer = renderer->parent()) {
2387 if (renderObjectIsObservable(renderer))
2388 return axObjectCache()->getOrCreate(renderer);
2394 bool AccessibilityRenderObject::isDescendantOfElementType(const QualifiedName& tagName) const
2396 for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
2397 if (parent->node() && parent->node()->hasTagName(tagName))
2403 AccessibilityRole AccessibilityRenderObject::determineAccessibilityRole()
2408 m_ariaRole = determineAriaRoleAttribute();
2410 Node* node = m_renderer->node();
2411 AccessibilityRole ariaRole = ariaRoleAttribute();
2412 if (ariaRole != UnknownRole)
2415 RenderBoxModelObject* cssBox = renderBoxModelObject();
2417 if (node && node->isLink()) {
2418 if (cssBox && cssBox->isImage())
2419 return ImageMapRole;
2420 return WebCoreLinkRole;
2422 if (cssBox && cssBox->isListItem())
2423 return ListItemRole;
2424 if (m_renderer->isListMarker())
2425 return ListMarkerRole;
2426 if (node && node->hasTagName(buttonTag))
2427 return buttonRoleType();
2428 if (node && node->hasTagName(legendTag))
2430 if (m_renderer->isText())
2431 return StaticTextRole;
2432 if (cssBox && cssBox->isImage()) {
2433 if (node && node->hasTagName(inputTag))
2434 return ariaHasPopup() ? PopUpButtonRole : ButtonRole;
2440 if (node && node->hasTagName(canvasTag))
2443 if (cssBox && cssBox->isRenderView()) {
2444 // If the iframe is seamless, it should not be announced as a web area to AT clients.
2445 if (document() && document()->shouldDisplaySeamlesslyWithParent())
2446 return SeamlessWebAreaRole;
2450 if (cssBox && cssBox->isTextField())
2451 return TextFieldRole;
2453 if (cssBox && cssBox->isTextArea())
2454 return TextAreaRole;
2456 if (node && node->hasTagName(inputTag)) {
2457 HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
2458 if (input->isCheckbox())
2459 return CheckBoxRole;
2460 if (input->isRadioButton())
2461 return RadioButtonRole;
2462 if (input->isTextButton())
2463 return buttonRoleType();
2466 if (isFileUploadButton())
2469 if (cssBox && cssBox->isMenuList())
2470 return PopUpButtonRole;
2476 if (m_renderer->isSVGImage())
2478 if (m_renderer->isSVGRoot())
2483 if (node && node->hasTagName(MathMLNames::mathTag))
2484 return DocumentMathRole;
2486 // It's not clear which role a platform should choose for a math element.
2487 // Declaring a math element role should give flexibility to platforms to choose.
2488 if (isMathElement())
2489 return MathElementRole;
2491 if (node && node->hasTagName(ddTag))
2492 return DefinitionListDefinitionRole;
2494 if (node && node->hasTagName(dtTag))
2495 return DefinitionListTermRole;
2497 if (node && (node->hasTagName(rpTag) || node->hasTagName(rtTag)))
2498 return AnnotationRole;
2501 // Gtk ATs expect all tables, data and layout, to be exposed as tables.
2502 if (node && (node->hasTagName(tdTag) || node->hasTagName(thTag)))
2505 if (node && node->hasTagName(trTag))
2508 if (node && node->hasTagName(tableTag))
2512 // Table sections should be ignored.
2513 if (m_renderer->isTableSection())
2516 if (m_renderer->isHR())
2517 return HorizontalRuleRole;
2519 if (node && node->hasTagName(pTag))
2520 return ParagraphRole;
2522 if (node && node->hasTagName(labelTag))
2525 if (node && node->hasTagName(divTag))
2528 if (node && node->hasTagName(formTag))
2531 if (node && node->hasTagName(articleTag))
2532 return DocumentArticleRole;
2534 if (node && node->hasTagName(navTag))
2535 return LandmarkNavigationRole;
2537 if (node && node->hasTagName(asideTag))
2538 return LandmarkComplementaryRole;
2540 if (node && node->hasTagName(sectionTag))
2541 return DocumentRegionRole;
2543 if (node && node->hasTagName(addressTag))
2544 return LandmarkContentInfoRole;
2546 // There should only be one banner/contentInfo per page. If header/footer are being used within an article or section
2547 // then it should not be exposed as whole page's banner/contentInfo
2548 if (node && node->hasTagName(headerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
2549 return LandmarkBannerRole;
2550 if (node && node->hasTagName(footerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
2553 if (m_renderer->isBlockFlow())
2556 // If the element does not have role, but it has ARIA attributes, accessibility should fallback to exposing it as a group.
2557 if (supportsARIAAttributes())
2563 AccessibilityOrientation AccessibilityRenderObject::orientation() const
2565 const AtomicString& ariaOrientation = getAttribute(aria_orientationAttr);
2566 if (equalIgnoringCase(ariaOrientation, "horizontal"))
2567 return AccessibilityOrientationHorizontal;
2568 if (equalIgnoringCase(ariaOrientation, "vertical"))
2569 return AccessibilityOrientationVertical;
2571 return AccessibilityObject::orientation();
2574 bool AccessibilityRenderObject::inheritsPresentationalRole() const
2576 // ARIA states if an item can get focus, it should not be presentational.
2577 if (canSetFocusAttribute())
2580 // ARIA spec says that when a parent object is presentational, and it has required child elements,
2581 // those child elements are also presentational. For example, <li> becomes presentational from <ul>.
2582 // http://www.w3.org/WAI/PF/aria/complete#presentation
2583 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, listItemParents, ());
2585 HashSet<QualifiedName>* possibleParentTagNames = 0;
2586 switch (roleValue()) {
2588 case ListMarkerRole:
2589 if (listItemParents.isEmpty()) {
2590 listItemParents.add(ulTag);
2591 listItemParents.add(olTag);
2592 listItemParents.add(dlTag);
2594 possibleParentTagNames = &listItemParents;
2600 // Not all elements need to check for this, only ones that are required children.
2601 if (!possibleParentTagNames)
2604 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
2605 if (!parent->isAccessibilityRenderObject())
2608 Node* elementNode = static_cast<AccessibilityRenderObject*>(parent)->node();
2609 if (!elementNode || !elementNode->isElementNode())
2612 // If native tag of the parent element matches an acceptable name, then return
2613 // based on its presentational status.
2614 if (possibleParentTagNames->contains(static_cast<Element*>(elementNode)->tagQName()))
2615 return parent->roleValue() == PresentationalRole;
2621 bool AccessibilityRenderObject::isPresentationalChildOfAriaRole() const
2623 // Walk the parent chain looking for a parent that has presentational children
2624 AccessibilityObject* parent;
2625 for (parent = parentObject(); parent && !parent->ariaRoleHasPresentationalChildren(); parent = parent->parentObject())
2631 bool AccessibilityRenderObject::ariaRoleHasPresentationalChildren() const
2633 switch (m_ariaRole) {
2637 case ProgressIndicatorRole:
2638 case SpinButtonRole:
2639 // case SeparatorRole:
2646 bool AccessibilityRenderObject::canSetExpandedAttribute() const
2648 // An object can be expanded if it aria-expanded is true or false.
2649 const AtomicString& ariaExpanded = getAttribute(aria_expandedAttr);
2650 return equalIgnoringCase(ariaExpanded, "true") || equalIgnoringCase(ariaExpanded, "false");
2653 bool AccessibilityRenderObject::canSetValueAttribute() const
2655 if (equalIgnoringCase(getAttribute(aria_readonlyAttr), "true"))
2658 if (isProgressIndicator() || isSlider())
2661 if (isTextControl() && !isNativeTextControl())
2664 // Any node could be contenteditable, so isReadOnly should be relied upon
2665 // for this information for all elements.
2666 return !isReadOnly();
2669 bool AccessibilityRenderObject::canSetTextRangeAttributes() const
2671 return isTextControl();
2674 void AccessibilityRenderObject::textChanged()
2676 // If this element supports ARIA live regions, or is part of a region with an ARIA editable role,
2677 // then notify the AT of changes.
2678 AXObjectCache* cache = axObjectCache();
2679 for (RenderObject* renderParent = m_renderer; renderParent; renderParent = renderParent->parent()) {
2680 AccessibilityObject* parent = cache->get(renderParent);
2684 if (parent->supportsARIALiveRegion())
2685 cache->postNotification(renderParent, AXObjectCache::AXLiveRegionChanged, true);
2687 if (parent->isARIATextControl() && !parent->isNativeTextControl() && !parent->node()->rendererIsEditable())
2688 cache->postNotification(renderParent, AXObjectCache::AXValueChanged, true);
2692 void AccessibilityRenderObject::clearChildren()
2694 AccessibilityObject::clearChildren();
2695 m_childrenDirty = false;
2698 void AccessibilityRenderObject::addImageMapChildren()
2700 RenderBoxModelObject* cssBox = renderBoxModelObject();
2701 if (!cssBox || !cssBox->isRenderImage())
2704 HTMLMapElement* map = toRenderImage(cssBox)->imageMap();
2708 for (Element* current = ElementTraversal::firstWithin(map); current; current = ElementTraversal::next(current, map)) {
2709 // add an <area> element for this child if it has a link
2710 if (current->hasTagName(areaTag) && current->isLink()) {
2711 AccessibilityImageMapLink* areaObject = static_cast<AccessibilityImageMapLink*>(axObjectCache()->getOrCreate(ImageMapLinkRole));
2712 areaObject->setHTMLAreaElement(static_cast<HTMLAreaElement*>(current));
2713 areaObject->setHTMLMapElement(map);
2714 areaObject->setParent(this);
2716 m_children.append(areaObject);
2721 void AccessibilityRenderObject::updateChildrenIfNecessary()
2723 if (needsToUpdateChildren())
2726 AccessibilityObject::updateChildrenIfNecessary();
2729 void AccessibilityRenderObject::addTextFieldChildren()
2731 Node* node = this->node();
2732 if (!node || !node->hasTagName(inputTag))
2735 HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
2736 HTMLElement* spinButtonElement = input->innerSpinButtonElement();
2737 if (!spinButtonElement || !spinButtonElement->isSpinButtonElement())
2740 AccessibilitySpinButton* axSpinButton = static_cast<AccessibilitySpinButton*>(axObjectCache()->getOrCreate(SpinButtonRole));
2741 axSpinButton->setSpinButtonElement(static_cast<SpinButtonElement*>(spinButtonElement));
2742 axSpinButton->setParent(this);
2743 m_children.append(axSpinButton);
2746 bool AccessibilityRenderObject::isSVGImage() const
2748 return remoteSVGRootElement();
2751 void AccessibilityRenderObject::detachRemoteSVGRoot()
2753 if (AccessibilitySVGRoot* root = remoteSVGRootElement())
2757 AccessibilitySVGRoot* AccessibilityRenderObject::remoteSVGRootElement() const
2760 if (!m_renderer || !m_renderer->isRenderImage())
2763 CachedImage* cachedImage = toRenderImage(m_renderer)->cachedImage();
2767 Image* image = cachedImage->image();
2768 if (!image || !image->isSVGImage())
2771 SVGImage* svgImage = static_cast<SVGImage*>(image);
2772 FrameView* frameView = svgImage->frameView();
2775 Frame* frame = frameView->frame();
2779 Document* doc = frame->document();
2780 if (!doc || !doc->isSVGDocument())
2783 SVGSVGElement* rootElement = static_cast<SVGDocument*>(doc)->rootElement();
2786 RenderObject* rendererRoot = rootElement->renderer();
2790 AccessibilityObject* rootSVGObject = frame->document()->axObjectCache()->getOrCreate(rendererRoot);
2792 // In order to connect the AX hierarchy from the SVG root element from the loaded resource
2793 // the parent must be set, because there's no other way to get back to who created the image.
2794 ASSERT(rootSVGObject && rootSVGObject->isAccessibilitySVGRoot());
2795 if (!rootSVGObject->isAccessibilitySVGRoot())
2798 return toAccessibilitySVGRoot(rootSVGObject);
2804 void AccessibilityRenderObject::addRemoteSVGChildren()
2806 AccessibilitySVGRoot* root = remoteSVGRootElement();
2810 root->setParent(this);
2812 if (root->accessibilityIsIgnored()) {
2813 AccessibilityChildrenVector children = root->children();
2814 unsigned length = children.size();
2815 for (unsigned i = 0; i < length; ++i)
2816 m_children.append(children[i]);
2818 m_children.append(root);
2821 void AccessibilityRenderObject::addCanvasChildren()
2823 if (!node() || !node()->hasTagName(canvasTag))
2826 // If it's a canvas, it won't have rendered children, but it might have accessible fallback content.
2827 // Clear m_haveChildren because AccessibilityNodeObject::addChildren will expect it to be false.
2828 ASSERT(!m_children.size());
2829 m_haveChildren = false;
2830 AccessibilityNodeObject::addChildren();
2833 void AccessibilityRenderObject::addAttachmentChildren()
2835 if (!isAttachment())
2838 // FrameView's need to be inserted into the AX hierarchy when encountered.
2839 Widget* widget = widgetForAttachmentView();
2840 if (!widget || !widget->isFrameView())
2843 AccessibilityObject* axWidget = axObjectCache()->getOrCreate(widget);
2844 if (!axWidget->accessibilityIsIgnored())
2845 m_children.append(axWidget);
2849 void AccessibilityRenderObject::updateAttachmentViewParents()
2851 // Only the unignored parent should set the attachment parent, because that's what is reflected in the AX
2852 // hierarchy to the client.
2853 if (accessibilityIsIgnored())
2856 size_t length = m_children.size();
2857 for (size_t k = 0; k < length; k++) {
2858 if (m_children[k]->isAttachment())
2859 m_children[k]->overrideAttachmentParent(this);
2864 // Hidden children are those that are not rendered or visible, but are specifically marked as aria-hidden=false,
2865 // meaning that they should be exposed to the AX hierarchy.
2866 void AccessibilityRenderObject::addHiddenChildren()
2868 Node* node = this->node();
2872 // First do a quick run through to determine if we have any hidden nodes (most often we will not).
2873 // If we do have hidden nodes, we need to determine where to insert them so they match DOM order as close as possible.
2874 bool shouldInsertHiddenNodes = false;
2875 for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
2876 if (!child->renderer() && isNodeAriaVisible(child)) {
2877 shouldInsertHiddenNodes = true;
2882 if (!shouldInsertHiddenNodes)
2885 // Iterate through all of the children, including those that may have already been added, and
2886 // try to insert hidden nodes in the correct place in the DOM order.
2887 unsigned insertionIndex = 0;
2888 for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
2889 if (child->renderer()) {
2890 // Find out where the last render sibling is located within m_children.
2891 AccessibilityObject* childObject = axObjectCache()->get(child->renderer());
2892 if (childObject && childObject->accessibilityIsIgnored()) {
2893 AccessibilityChildrenVector children = childObject->children();
2894 if (children.size())
2895 childObject = children.last().get();
2901 insertionIndex = m_children.find(childObject) + 1;
2905 if (!isNodeAriaVisible(child))
2908 unsigned previousSize = m_children.size();
2909 if (insertionIndex > previousSize)
2910 insertionIndex = previousSize;
2912 insertChild(axObjectCache()->getOrCreate(child), insertionIndex);
2913 insertionIndex += (m_children.size() - previousSize);
2917 void AccessibilityRenderObject::addChildren()
2919 // If the need to add more children in addition to existing children arises,
2920 // childrenChanged should have been called, leaving the object with no children.
2921 ASSERT(!m_haveChildren);
2923 m_haveChildren = true;
2925 if (!canHaveChildren())
2928 for (RefPtr<AccessibilityObject> obj = firstChild(); obj; obj = obj->nextSibling())
2929 addChild(obj.get());
2931 addHiddenChildren();
2932 addAttachmentChildren();
2933 addImageMapChildren();
2934 addTextFieldChildren();
2935 addCanvasChildren();
2936 addRemoteSVGChildren();
2939 updateAttachmentViewParents();
2943 bool AccessibilityRenderObject::canHaveChildren() const
2948 return AccessibilityNodeObject::canHaveChildren();
2951 const AtomicString& AccessibilityRenderObject::ariaLiveRegionStatus() const
2953 DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusAssertive, ("assertive", AtomicString::ConstructFromLiteral));
2954 DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusPolite, ("polite", AtomicString::ConstructFromLiteral));
2955 DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusOff, ("off", AtomicString::ConstructFromLiteral));
2957 const AtomicString& liveRegionStatus = getAttribute(aria_liveAttr);
2958 // These roles have implicit live region status.
2959 if (liveRegionStatus.isEmpty()) {
2960 switch (roleValue()) {
2961 case ApplicationAlertDialogRole:
2962 case ApplicationAlertRole:
2963 return liveRegionStatusAssertive;
2964 case ApplicationLogRole:
2965 case ApplicationStatusRole:
2966 return liveRegionStatusPolite;
2967 case ApplicationTimerRole:
2968 case ApplicationMarqueeRole:
2969 return liveRegionStatusOff;
2975 return liveRegionStatus;
2978 const AtomicString& AccessibilityRenderObject::ariaLiveRegionRelevant() const
2980 DEFINE_STATIC_LOCAL(const AtomicString, defaultLiveRegionRelevant, ("additions text", AtomicString::ConstructFromLiteral));
2981 const AtomicString& relevant = getAttribute(aria_relevantAttr);
2983 // Default aria-relevant = "additions text".
2984 if (relevant.isEmpty())
2985 return defaultLiveRegionRelevant;
2990 bool AccessibilityRenderObject::ariaLiveRegionAtomic() const
2992 return elementAttributeValue(aria_atomicAttr);
2995 bool AccessibilityRenderObject::ariaLiveRegionBusy() const
2997 return elementAttributeValue(aria_busyAttr);
3000 void AccessibilityRenderObject::ariaSelectedRows(AccessibilityChildrenVector& result)
3002 // Get all the rows.
3003 AccessibilityChildrenVector allRows;
3005 ariaTreeRows(allRows);
3006 else if (isAccessibilityTable() && toAccessibilityTable(this)->supportsSelectedRows())
3007 allRows = toAccessibilityTable(this)->rows();
3009 // Determine which rows are selected.
3010 bool isMulti = isMultiSelectable();
3012 // Prefer active descendant over aria-selected.
3013 AccessibilityObject* activeDesc = activeDescendant();
3014 if (activeDesc && (activeDesc->isTreeItem() || activeDesc->isTableRow())) {
3015 result.append(activeDesc);
3020 unsigned count = allRows.size();
3021 for (unsigned k = 0; k < count; ++k) {
3022 if (allRows[k]->isSelected()) {
3023 result.append(allRows[k]);
3030 void AccessibilityRenderObject::ariaListboxSelectedChildren(AccessibilityChildrenVector& result)
3032 bool isMulti = isMultiSelectable();
3034 AccessibilityChildrenVector childObjects = children();
3035 unsigned childrenSize = childObjects.size();
3036 for (unsigned k = 0; k < childrenSize; ++k) {
3037 // Every child should have aria-role option, and if so, check for selected attribute/state.
3038 AccessibilityObject* child = childObjects[k].get();
3039 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRole) {
3040 result.append(child);
3047 void AccessibilityRenderObject::selectedChildren(AccessibilityChildrenVector& result)
3049 ASSERT(result.isEmpty());
3051 // only listboxes should be asked for their selected children.
3052 AccessibilityRole role = roleValue();
3053 if (role == ListBoxRole) // native list boxes would be AccessibilityListBoxes, so only check for aria list boxes
3054 ariaListboxSelectedChildren(result);
3055 else if (role == TreeRole || role == TreeGridRole || role == TableRole)
3056 ariaSelectedRows(result);
3059 void AccessibilityRenderObject::ariaListboxVisibleChildren(AccessibilityChildrenVector& result)
3064 AccessibilityObject::AccessibilityChildrenVector children = this->children();
3065 size_t size = children.size();
3066 for (size_t i = 0; i < size; i++) {
3067 if (!children[i]->isOffScreen())
3068 result.append(children[i]);
3072 void AccessibilityRenderObject::visibleChildren(AccessibilityChildrenVector& result)
3074 ASSERT(result.isEmpty());
3076 // only listboxes are asked for their visible children.
3077 if (ariaRoleAttribute() != ListBoxRole) { // native list boxes would be AccessibilityListBoxes, so only check for aria list boxes
3078 ASSERT_NOT_REACHED();
3081 return ariaListboxVisibleChildren(result);
3084 void AccessibilityRenderObject::tabChildren(AccessibilityChildrenVector& result)
3086 ASSERT(roleValue() == TabListRole);
3088 AccessibilityObject::AccessibilityChildrenVector children = this->children();
3089 size_t size = children.size();
3090 for (size_t i = 0; i < size; ++i) {
3091 if (children[i]->isTabItem())
3092 result.append(children[i]);
3096 const String& AccessibilityRenderObject::actionVerb() const
3098 // FIXME: Need to add verbs for select elements.
3099 DEFINE_STATIC_LOCAL(const String, buttonAction, (AXButtonActionVerb()));
3100 DEFINE_STATIC_LOCAL(const String, textFieldAction, (AXTextFieldActionVerb()));
3101 DEFINE_STATIC_LOCAL(const String, radioButtonAction, (AXRadioButtonActionVerb()));
3102 DEFINE_STATIC_LOCAL(const String, checkedCheckBoxAction, (AXCheckedCheckBoxActionVerb()));
3103 DEFINE_STATIC_LOCAL(const String, uncheckedCheckBoxAction, (AXUncheckedCheckBoxActionVerb()));
3104 DEFINE_STATIC_LOCAL(const String, linkAction, (AXLinkActionVerb()));
3105 DEFINE_STATIC_LOCAL(const String, noAction, ());
3107 switch (roleValue()) {
3109 case ToggleButtonRole:
3110 return buttonAction;
3113 return textFieldAction;
3114 case RadioButtonRole:
3115 return radioButtonAction;
3117 return isChecked() ? checkedCheckBoxAction : uncheckedCheckBoxAction;
3119 case WebCoreLinkRole:
3126 void AccessibilityRenderObject::setAccessibleName(const AtomicString& name)
3128 // Setting the accessible name can store the value in the DOM
3133 // For web areas, set the aria-label on the HTML element.
3135 domNode = m_renderer->document()->documentElement();
3137 domNode = m_renderer->node();
3139 if (domNode && domNode->isElementNode())
3140 static_cast<Element*>(domNode)->setAttribute(aria_labelAttr, name);
3143 static bool isLinkable(const AccessibilityRenderObject& object)
3145 if (!object.renderer())
3148 // See https://wiki.mozilla.org/Accessibility/AT-Windows-API for the elements
3149 // Mozilla considers linkable.
3150 return object.isLink() || object.isImage() || object.renderer()->isText();
3153 String AccessibilityRenderObject::stringValueForMSAA() const
3155 if (isLinkable(*this)) {
3156 Element* anchor = anchorElement();
3157 if (anchor && anchor->hasTagName(aTag))
3158 return static_cast<HTMLAnchorElement*>(anchor)->href();
3161 return stringValue();
3164 bool AccessibilityRenderObject::isLinked() const
3166 if (!isLinkable(*this))
3169 Element* anchor = anchorElement();
3170 if (!anchor || !anchor->hasTagName(aTag))
3173 return !static_cast<HTMLAnchorElement*>(anchor)->href().isEmpty();
3176 bool AccessibilityRenderObject::hasBoldFont() const
3181 return m_renderer->style()->fontDescription().weight() >= FontWeightBold;
3184 bool AccessibilityRenderObject::hasItalicFont() const
3189 return m_renderer->style()->fontDescription().italic() == FontItalicOn;
3192 bool AccessibilityRenderObject::hasPlainText() const
3197 RenderStyle* style = m_renderer->style();
3199 return style->fontDescription().weight() == FontWeightNormal
3200 && style->fontDescription().italic() == FontItalicOff
3201 && style->textDecorationsInEffect() == TDNONE;
3204 bool AccessibilityRenderObject::hasSameFont(RenderObject* renderer) const
3206 if (!m_renderer || !renderer)
3209 return m_renderer->style()->fontDescription().family() == renderer->style()->fontDescription().family();
3212 bool AccessibilityRenderObject::hasSameFontColor(RenderObject* renderer) const
3214 if (!m_renderer || !renderer)
3217 return m_renderer->style()->visitedDependentColor(CSSPropertyColor) == renderer->style()->visitedDependentColor(CSSPropertyColor);
3220 bool AccessibilityRenderObject::hasSameStyle(RenderObject* renderer) const
3222 if (!m_renderer || !renderer)
3225 return m_renderer->style() == renderer->style();
3228 bool AccessibilityRenderObject::hasUnderline() const
3233 return m_renderer->style()->textDecorationsInEffect() & UNDERLINE;
3236 String AccessibilityRenderObject::nameForMSAA() const
3238 if (m_renderer && m_renderer->isText())
3239 return textUnderElement();
3244 static bool shouldReturnTagNameAsRoleForMSAA(const Element& element)
3246 // See "document structure",
3247 // https://wiki.mozilla.org/Accessibility/AT-Windows-API
3248 // FIXME: Add the other tag names that should be returned as the role.
3249 return element.hasTagName(h1Tag) || element.hasTagName(h2Tag)
3250 || element.hasTagName(h3Tag) || element.hasTagName(h4Tag)
3251 || element.hasTagName(h5Tag) || element.hasTagName(h6Tag);
3254 String AccessibilityRenderObject::stringRoleForMSAA() const
3259 Node* node = m_renderer->node();
3260 if (!node || !node->isElementNode())
3263 Element* element = static_cast<Element*>(node);
3264 if (!shouldReturnTagNameAsRoleForMSAA(*element))
3267 return element->tagName();
3270 String AccessibilityRenderObject::positionalDescriptionForMSAA() const
3272 // See "positional descriptions",
3273 // https://wiki.mozilla.org/Accessibility/AT-Windows-API
3275 return "L" + String::number(headingLevel());
3277 // FIXME: Add positional descriptions for other elements.
3281 String AccessibilityRenderObject::descriptionForMSAA() const
3283 String description = positionalDescriptionForMSAA();
3284 if (!description.isEmpty())
3287 description = accessibilityDescription();
3288 if (!description.isEmpty()) {
3289 // From the Mozilla MSAA implementation:
3290 // "Signal to screen readers that this description is speakable and is not
3291 // a formatted positional information description. Don't localize the
3292 // 'Description: ' part of this string, it will be parsed out by assistive
3294 return "Description: " + description;
3300 static AccessibilityRole msaaRoleForRenderer(const RenderObject* renderer)
3305 if (renderer->isText())
3306 return EditableTextRole;
3308 if (renderer->isBoxModelObject() && toRenderBoxModelObject(renderer)->isListItem())
3309 return ListItemRole;
3314 AccessibilityRole AccessibilityRenderObject::roleValueForMSAA() const
3316 if (m_roleForMSAA != UnknownRole)
3317 return m_roleForMSAA;
3319 m_roleForMSAA = msaaRoleForRenderer(m_renderer);
3321 if (m_roleForMSAA == UnknownRole)
3322 m_roleForMSAA = roleValue();
3324 return m_roleForMSAA;
3327 String AccessibilityRenderObject::passwordFieldValue() const
3330 ASSERT(isPasswordField());
3332 // Look for the RenderText object in the RenderObject tree for this input field.
3333 RenderObject* renderer = node()->renderer();
3334 while (renderer && !renderer->isText())
3335 renderer = renderer->firstChild();
3337 if (!renderer || !renderer->isText())
3340 // Return the text that is actually being rendered in the input field.
3341 return static_cast<RenderText*>(renderer)->textWithoutTranscoding();
3343 // It seems only GTK is interested in this at the moment.
3348 ScrollableArea* AccessibilityRenderObject::getScrollableAreaIfScrollable() const
3350 // If the parent is a scroll view, then this object isn't really scrollable, the parent ScrollView should handle the scrolling.
3351 if (parentObject() && parentObject()->isAccessibilityScrollView())
3354 if (!m_renderer || !m_renderer->isBox())
3357 RenderBox* box = toRenderBox(m_renderer);
3358 if (!box->canBeScrolledAndHasScrollableArea())
3361 return box->layer();
3364 void AccessibilityRenderObject::scrollTo(const IntPoint& point) const
3366 if (!m_renderer || !m_renderer->isBox())
3369 RenderBox* box = toRenderBox(m_renderer);
3370 if (!box->canBeScrolledAndHasScrollableArea())
3373 RenderLayer* layer = box->layer();
3374 layer->scrollToOffset(toIntSize(point), RenderLayer::ScrollOffsetClamped);
3378 bool AccessibilityRenderObject::isMathElement() const
3380 Node* node = this->node();
3381 if (!m_renderer || !node)
3384 return node->isElementNode() && toElement(node)->isMathMLElement();
3387 bool AccessibilityRenderObject::isMathFraction() const
3389 if (!m_renderer || !m_renderer->isRenderMathMLBlock())
3392 return toRenderMathMLBlock(m_renderer)->isRenderMathMLFraction();
3395 bool AccessibilityRenderObject::isMathFenced() const
3397 if (!m_renderer || !m_renderer->isRenderMathMLBlock())
3400 return toRenderMathMLBlock(m_renderer)->isRenderMathMLFenced();
3403 bool AccessibilityRenderObject::isMathSubscriptSuperscript() const
3405 if (!m_renderer || !m_renderer->isRenderMathMLBlock())
3408 return toRenderMathMLBlock(m_renderer)->isRenderMathMLSubSup();
3411 bool AccessibilityRenderObject::isMathRow() const
3413 if (!m_renderer || !m_renderer->isRenderMathMLBlock())
3416 return toRenderMathMLBlock(m_renderer)->isRenderMathMLRow();
3419 bool AccessibilityRenderObject::isMathUnderOver() const
3421 if (!m_renderer || !m_renderer->isRenderMathMLBlock())
3424 return toRenderMathMLBlock(m_renderer)->isRenderMathMLUnderOver();
3427 bool AccessibilityRenderObject::isMathSquareRoot() const
3429 if (!m_renderer || !m_renderer->isRenderMathMLBlock())
3432 return toRenderMathMLBlock(m_renderer)->isRenderMathMLSquareRoot();
3435 bool AccessibilityRenderObject::isMathRoot() const
3437 if (!m_renderer || !m_renderer->isRenderMathMLBlock())
3440 return toRenderMathMLBlock(m_renderer)->isRenderMathMLRoot();
3443 bool AccessibilityRenderObject::isMathOperator() const
3445 if (!m_renderer || !m_renderer->isRenderMathMLBlock())
3448 // Ensure that this is actually a render MathML operator because
3449 // MathML will create MathMLBlocks and use the original node as the node
3450 // of this new block that is not tied to the DOM.
3451 if (!toRenderMathMLBlock(m_renderer)->isRenderMathMLOperator())
3454 return isMathElement() && node()->hasTagName(MathMLNames::moTag);
3457 bool AccessibilityRenderObject::isMathFenceOperator() const
3459 if (!m_renderer || !m_renderer->isRenderMathMLBlock())
3462 if (!toRenderMathMLBlock(m_renderer)->isRenderMathMLOperator())
3465 RenderMathMLOperator* mathOperator = toRenderMathMLOperator(toRenderMathMLBlock(m_renderer));
3466 return mathOperator->operatorType() == RenderMathMLOperator::Fence;
3469 bool AccessibilityRenderObject::isMathSeparatorOperator() const
3471 if (!m_renderer || !m_renderer->isRenderMathMLBlock())
3474 if (!toRenderMathMLBlock(m_renderer)->isRenderMathMLOperator())
3477 RenderMathMLOperator* mathOperator = toRenderMathMLOperator(toRenderMathMLBlock(m_renderer));
3478 return mathOperator->operatorType() == RenderMathMLOperator::Separator;
3481 bool AccessibilityRenderObject::isMathText() const
3483 return node() && node()->hasTagName(MathMLNames::mtextTag);
3486 bool AccessibilityRenderObject::isMathNumber() const
3488 return node() && node()->hasTagName(MathMLNames::mnTag);
3491 bool AccessibilityRenderObject::isMathIdentifier() const
3493 return node() && node()->hasTagName(MathMLNames::miTag);
3496 bool AccessibilityRenderObject::isMathTable() const
3498 return node() && node()->hasTagName(MathMLNames::mtableTag);
3501 bool AccessibilityRenderObject::isMathTableRow() const
3503 return node() && node()->hasTagName(MathMLNames::mtrTag);
3506 bool AccessibilityRenderObject::isMathTableCell() const
3508 return node() && node()->hasTagName(MathMLNames::mtdTag);
3511 bool AccessibilityRenderObject::isIgnoredElementWithinMathTree() const
3516 // Ignore items that were created for layout purposes only.
3517 if (m_renderer->isRenderMathMLBlock() && toRenderMathMLBlock(m_renderer)->ignoreInAccessibilityTree())
3520 // Ignore anonymous renderers inside math blocks.
3521 if (m_renderer->isAnonymous()) {
3522 for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
3523 if (parent->isMathElement())
3528 // Only math elements that we explicitly recognize should be included
3529 // We don't want things like <mstyle> to appear in the tree.
3530 if (isMathElement()) {
3531 if (isMathFraction() || isMathFenced() || isMathSubscriptSuperscript() || isMathRow()
3532 || isMathUnderOver() || isMathRoot() || isMathText() || isMathNumber()
3533 || isMathOperator() || isMathFenceOperator() || isMathSeparatorOperator()
3534 || isMathIdentifier() || isMathTable() || isMathTableRow() || isMathTableCell())
3542 AccessibilityObject* AccessibilityRenderObject::mathRadicandObject()
3547 AccessibilityObject::AccessibilityChildrenVector children = this->children();
3548 if (children.size() < 1)
3551 // The radicand is the value being rooted and must be listed first.
3552 return children[0].get();
3555 AccessibilityObject* AccessibilityRenderObject::mathRootIndexObject()
3560 AccessibilityObject::AccessibilityChildrenVector children = this->children();
3561 if (children.size() != 2)
3564 // The index in a root is the value which determines if it's a square, cube, etc, root
3565 // and must be listed second.
3566 return children[1].get();
3569 AccessibilityObject* AccessibilityRenderObject::mathNumeratorObject()
3571 if (!isMathFraction())
3574 AccessibilityObject::AccessibilityChildrenVector children = this->children();
3575 if (children.size() != 2)
3578 return children[0].get();
3581 AccessibilityObject* AccessibilityRenderObject::mathDenominatorObject()
3583 if (!isMathFraction())
3586 AccessibilityObject::AccessibilityChildrenVector children = this->children();
3587 if (children.size() != 2)
3590 return children[1].get();
3593 AccessibilityObject* AccessibilityRenderObject::mathUnderObject()
3595 if (!isMathUnderOver() || !node())
3598 AccessibilityChildrenVector children = this->children();
3599 if (children.size() < 2)
3602 if (node()->hasTagName(MathMLNames::munderTag) || node()->hasTagName(MathMLNames::munderoverTag))
3603 return children[1].get();
3608 AccessibilityObject* AccessibilityRenderObject::mathOverObject()
3610 if (!isMathUnderOver() || !node())
3613 AccessibilityChildrenVector children = this->children();
3614 if (children.size() < 2)
3617 if (node()->hasTagName(MathMLNames::moverTag))
3618 return children[1].get();
3619 if (node()->hasTagName(MathMLNames::munderoverTag))
3620 return children[2].get();
3625 AccessibilityObject* AccessibilityRenderObject::mathBaseObject()
3627 if (!isMathSubscriptSuperscript() && !isMathUnderOver())
3630 AccessibilityChildrenVector children = this->children();
3631 // The base object in question is always the first child.
3632 if (children.size() > 0)
3633 return children[0].get();
3638 AccessibilityObject* AccessibilityRenderObject::mathSubscriptObject()
3640 if (!isMathSubscriptSuperscript() || !node())
3643 AccessibilityChildrenVector children = this->children();
3644 if (children.size() < 2)
3647 if (node()->hasTagName(MathMLNames::msubTag) || node()->hasTagName(MathMLNames::msubsupTag))
3648 return children[1].get();
3653 AccessibilityObject* AccessibilityRenderObject::mathSuperscriptObject()
3655 if (!isMathSubscriptSuperscript() || !node())
3658 AccessibilityChildrenVector children = this->children();
3659 if (children.size() < 2)
3662 if (node()->hasTagName(MathMLNames::msupTag))
3663 return children[1].get();
3664 if (node()->hasTagName(MathMLNames::msubsupTag))
3665 return children[2].get();
3670 String AccessibilityRenderObject::mathFencedOpenString() const
3672 if (!isMathFenced())
3675 return getAttribute(MathMLNames::openAttr);
3678 String AccessibilityRenderObject::mathFencedCloseString() const
3680 if (!isMathFenced())
3683 return getAttribute(MathMLNames::closeAttr);
3688 } // namespace WebCore