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 "core/accessibility/AXRenderObject.h"
32 #include "bindings/v8/ExceptionStatePlaceholder.h"
33 #include "core/accessibility/AXImageMapLink.h"
34 #include "core/accessibility/AXInlineTextBox.h"
35 #include "core/accessibility/AXObjectCache.h"
36 #include "core/accessibility/AXSVGRoot.h"
37 #include "core/accessibility/AXSpinButton.h"
38 #include "core/accessibility/AXTable.h"
39 #include "core/dom/ElementTraversal.h"
40 #include "core/dom/shadow/ShadowRoot.h"
41 #include "core/editing/FrameSelection.h"
42 #include "core/editing/RenderedPosition.h"
43 #include "core/editing/TextIterator.h"
44 #include "core/editing/VisibleUnits.h"
45 #include "core/editing/htmlediting.h"
46 #include "core/frame/Frame.h"
47 #include "core/html/HTMLImageElement.h"
48 #include "core/html/HTMLLabelElement.h"
49 #include "core/html/HTMLOptionElement.h"
50 #include "core/html/HTMLSelectElement.h"
51 #include "core/html/HTMLTextAreaElement.h"
52 #include "core/html/shadow/ShadowElementNames.h"
53 #include "core/loader/ProgressTracker.h"
54 #include "core/page/Page.h"
55 #include "core/rendering/HitTestResult.h"
56 #include "core/rendering/RenderFieldset.h"
57 #include "core/rendering/RenderFileUploadControl.h"
58 #include "core/rendering/RenderHTMLCanvas.h"
59 #include "core/rendering/RenderImage.h"
60 #include "core/rendering/RenderInline.h"
61 #include "core/rendering/RenderLayer.h"
62 #include "core/rendering/RenderListMarker.h"
63 #include "core/rendering/RenderMenuList.h"
64 #include "core/rendering/RenderTextControlSingleLine.h"
65 #include "core/rendering/RenderTextFragment.h"
66 #include "core/rendering/RenderView.h"
67 #include "core/rendering/RenderWidget.h"
68 #include "core/svg/SVGDocument.h"
69 #include "core/svg/SVGSVGElement.h"
70 #include "core/svg/graphics/SVGImage.h"
71 #include "platform/text/PlatformLocale.h"
72 #include "wtf/StdLibExtras.h"
74 using blink::WebLocalizedString;
79 using namespace HTMLNames;
81 static inline RenderObject* firstChildInContinuation(RenderObject* renderer)
83 RenderObject* r = toRenderInline(renderer)->continuation();
86 if (r->isRenderBlock())
88 if (RenderObject* child = r->firstChild())
90 r = toRenderInline(r)->continuation();
96 static inline bool isInlineWithContinuation(RenderObject* object)
98 if (!object->isBoxModelObject())
101 RenderBoxModelObject* renderer = toRenderBoxModelObject(object);
102 if (!renderer->isRenderInline())
105 return toRenderInline(renderer)->continuation();
108 static inline RenderObject* firstChildConsideringContinuation(RenderObject* renderer)
110 RenderObject* firstChild = renderer->firstChild();
112 if (!firstChild && isInlineWithContinuation(renderer))
113 firstChild = firstChildInContinuation(renderer);
118 static inline RenderInline* startOfContinuations(RenderObject* r)
120 if (r->isInlineElementContinuation()) {
121 return toRenderInline(r->node()->renderer());
124 // Blocks with a previous continuation always have a next continuation
125 if (r->isRenderBlock() && toRenderBlock(r)->inlineElementContinuation())
126 return toRenderInline(toRenderBlock(r)->inlineElementContinuation()->node()->renderer());
131 static inline RenderObject* endOfContinuations(RenderObject* renderer)
133 RenderObject* prev = renderer;
134 RenderObject* cur = renderer;
136 if (!cur->isRenderInline() && !cur->isRenderBlock())
141 if (cur->isRenderInline()) {
142 cur = toRenderInline(cur)->inlineElementContinuation();
143 ASSERT(cur || !toRenderInline(prev)->continuation());
145 cur = toRenderBlock(cur)->inlineElementContinuation();
152 static inline bool lastChildHasContinuation(RenderObject* renderer)
154 return renderer->lastChild() && isInlineWithContinuation(renderer->lastChild());
157 static RenderBoxModelObject* nextContinuation(RenderObject* renderer)
160 if (renderer->isRenderInline() && !renderer->isReplaced())
161 return toRenderInline(renderer)->continuation();
162 if (renderer->isRenderBlock())
163 return toRenderBlock(renderer)->inlineElementContinuation();
167 AXRenderObject::AXRenderObject(RenderObject* renderer)
168 : AXNodeObject(renderer->node())
169 , m_renderer(renderer)
170 , m_cachedElementRectDirty(true)
173 m_renderer->setHasAXObject(true);
177 PassRefPtr<AXRenderObject> AXRenderObject::create(RenderObject* renderer)
179 return adoptRef(new AXRenderObject(renderer));
182 AXRenderObject::~AXRenderObject()
184 ASSERT(isDetached());
187 LayoutRect AXRenderObject::elementRect() const
189 if (!m_explicitElementRect.isEmpty())
190 return m_explicitElementRect;
193 if (!m_renderer->isBox())
194 return computeElementRect();
196 for (const AXObject* obj = this; obj; obj = obj->parentObject()) {
197 if (obj->isAXRenderObject())
198 toAXRenderObject(obj)->checkCachedElementRect();
200 for (const AXObject* obj = this; obj; obj = obj->parentObject()) {
201 if (obj->isAXRenderObject())
202 toAXRenderObject(obj)->updateCachedElementRect();
205 return m_cachedElementRect;
208 void AXRenderObject::setRenderer(RenderObject* renderer)
210 m_renderer = renderer;
211 setNode(renderer->node());
214 RenderBoxModelObject* AXRenderObject::renderBoxModelObject() const
216 if (!m_renderer || !m_renderer->isBoxModelObject())
218 return toRenderBoxModelObject(m_renderer);
221 RenderView* AXRenderObject::topRenderer() const
223 Document* topDoc = topDocument();
227 return topDoc->renderView();
230 Document* AXRenderObject::topDocument() const
234 return document()->topDocument();
237 bool AXRenderObject::shouldNotifyActiveDescendant() const
239 // We want to notify that the combo box has changed its active descendant,
240 // but we do not want to change the focus, because focus should remain with the combo box.
244 return shouldFocusActiveDescendant();
247 ScrollableArea* AXRenderObject::getScrollableAreaIfScrollable() const
249 // If the parent is a scroll view, then this object isn't really scrollable, the parent ScrollView should handle the scrolling.
250 if (parentObject() && parentObject()->isAXScrollView())
253 if (!m_renderer || !m_renderer->isBox())
256 RenderBox* box = toRenderBox(m_renderer);
257 if (!box->canBeScrolledAndHasScrollableArea())
260 return box->scrollableArea();
263 AccessibilityRole AXRenderObject::determineAccessibilityRole()
268 m_ariaRole = determineAriaRoleAttribute();
270 Node* node = m_renderer->node();
271 AccessibilityRole ariaRole = ariaRoleAttribute();
272 if (ariaRole != UnknownRole)
275 RenderBoxModelObject* cssBox = renderBoxModelObject();
277 if (node && node->isLink()) {
278 if (cssBox && cssBox->isImage())
282 if (cssBox && cssBox->isListItem())
284 if (m_renderer->isListMarker())
285 return ListMarkerRole;
286 if (node && node->hasTagName(buttonTag))
287 return buttonRoleType();
288 if (node && node->hasTagName(legendTag))
290 if (m_renderer->isText())
291 return StaticTextRole;
292 if (cssBox && cssBox->isImage()) {
293 if (node && node->hasTagName(inputTag))
294 return ariaHasPopup() ? PopUpButtonRole : ButtonRole;
300 // Note: if JavaScript is disabled, the renderer won't be a RenderHTMLCanvas.
301 if (node && node->hasTagName(canvasTag) && m_renderer->isCanvas())
304 if (cssBox && cssBox->isRenderView())
307 if (cssBox && cssBox->isTextField())
308 return TextFieldRole;
310 if (cssBox && cssBox->isTextArea())
313 if (node && node->hasTagName(inputTag)) {
314 HTMLInputElement* input = toHTMLInputElement(node);
315 if (input->isCheckbox())
317 if (input->isRadioButton())
318 return RadioButtonRole;
319 if (input->isTextButton())
320 return buttonRoleType();
322 const AtomicString& type = input->getAttribute(typeAttr);
323 if (equalIgnoringCase(type, "color"))
324 return ColorWellRole;
327 if (isFileUploadButton())
330 if (cssBox && cssBox->isMenuList())
331 return PopUpButtonRole;
336 if (m_renderer->isSVGImage())
338 if (m_renderer->isSVGRoot())
341 if (node && node->hasTagName(ddTag))
342 return DescriptionListDetailRole;
344 if (node && node->hasTagName(dtTag))
345 return DescriptionListTermRole;
347 if (node && (node->hasTagName(rpTag) || node->hasTagName(rtTag)))
348 return AnnotationRole;
350 // Table sections should be ignored.
351 if (m_renderer->isTableSection())
354 if (m_renderer->isHR())
355 return HorizontalRuleRole;
357 if (node && node->hasTagName(pTag))
358 return ParagraphRole;
360 if (node && node->hasTagName(labelTag))
363 if (node && node->hasTagName(divTag))
366 if (node && node->hasTagName(formTag))
369 if (node && node->hasTagName(articleTag))
372 if (node && node->hasTagName(mainTag))
375 if (node && node->hasTagName(navTag))
376 return NavigationRole;
378 if (node && node->hasTagName(asideTag))
379 return ComplementaryRole;
381 if (node && node->hasTagName(sectionTag))
384 if (node && node->hasTagName(addressTag))
385 return ContentInfoRole;
387 if (node && node->hasTagName(dialogTag))
390 // The HTML element should not be exposed as an element. That's what the RenderView element does.
391 if (node && node->hasTagName(htmlTag))
394 // There should only be one banner/contentInfo per page. If header/footer are being used within an article or section
395 // then it should not be exposed as whole page's banner/contentInfo
396 if (node && node->hasTagName(headerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
398 if (node && node->hasTagName(footerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
401 if (node && node->hasTagName(aTag) && isClickable())
404 if (m_renderer->isRenderBlockFlow())
407 // If the element does not have role, but it has ARIA attributes, accessibility should fallback to exposing it as a group.
408 if (supportsARIAAttributes())
414 void AXRenderObject::init()
416 AXNodeObject::init();
419 void AXRenderObject::detach()
421 AXNodeObject::detach();
423 detachRemoteSVGRoot();
427 m_renderer->setHasAXObject(false);
433 // Check object role or purpose.
436 bool AXRenderObject::isAttachment() const
438 RenderBoxModelObject* renderer = renderBoxModelObject();
441 // Widgets are the replaced elements that we represent to AX as attachments
442 bool isWidget = renderer->isWidget();
443 ASSERT(!isWidget || (renderer->isReplaced() && !isImage()));
447 bool AXRenderObject::isFileUploadButton() const
449 if (m_renderer && m_renderer->node() && m_renderer->node()->hasTagName(inputTag)) {
450 HTMLInputElement* input = toHTMLInputElement(m_renderer->node());
451 return input->isFileUpload();
457 static bool isLinkable(const AXObject& object)
459 if (!object.renderer())
462 // See https://wiki.mozilla.org/Accessibility/AT-Windows-API for the elements
463 // Mozilla considers linkable.
464 return object.isLink() || object.isImage() || object.renderer()->isText();
467 bool AXRenderObject::isLinked() const
469 if (!isLinkable(*this))
472 Element* anchor = anchorElement();
473 if (!anchor || !anchor->hasTagName(aTag))
476 return !toHTMLAnchorElement(anchor)->href().isEmpty();
479 bool AXRenderObject::isLoaded() const
481 return !m_renderer->document().parser();
484 bool AXRenderObject::isOffScreen() const
487 IntRect contentRect = pixelSnappedIntRect(m_renderer->absoluteClippedOverflowRect());
488 FrameView* view = m_renderer->frame()->view();
489 IntRect viewRect = view->visibleContentRect();
490 viewRect.intersect(contentRect);
491 return viewRect.isEmpty();
494 bool AXRenderObject::isReadOnly() const
499 Document& document = m_renderer->document();
500 HTMLElement* body = document.body();
501 if (body && body->rendererIsEditable())
504 return !document.rendererIsEditable();
507 return AXNodeObject::isReadOnly();
510 bool AXRenderObject::isVisited() const
512 // FIXME: Is it a privacy violation to expose visited information to accessibility APIs?
513 return m_renderer->style()->isLink() && m_renderer->style()->insideLink() == InsideVisitedLink;
517 // Check object state.
520 bool AXRenderObject::isFocused() const
525 Document& document = m_renderer->document();
526 Element* focusedElement = document.focusedElement();
530 // A web area is represented by the Document node in the DOM tree, which isn't focusable.
531 // Check instead if the frame's selection controller is focused
532 if (focusedElement == m_renderer->node()
533 || (roleValue() == WebAreaRole && document.frame()->selection().isFocusedAndActive()))
539 bool AXRenderObject::isSelected() const
544 Node* node = m_renderer->node();
548 const AtomicString& ariaSelected = getAttribute(aria_selectedAttr);
549 if (equalIgnoringCase(ariaSelected, "true"))
552 if (isTabItem() && isTabItemSelected())
559 // Whether objects are ignored, i.e. not included in the tree.
562 AXObjectInclusion AXRenderObject::defaultObjectInclusion() const
564 // The following cases can apply to any element that's a subclass of AXRenderObject.
569 if (m_renderer->style()->visibility() != VISIBLE) {
570 // aria-hidden is meant to override visibility as the determinant in AX hierarchy inclusion.
571 if (equalIgnoringCase(getAttribute(aria_hiddenAttr), "false"))
572 return DefaultBehavior;
577 return AXObject::defaultObjectInclusion();
580 bool AXRenderObject::computeAccessibilityIsIgnored() const
583 ASSERT(m_initialized);
586 // Check first if any of the common reasons cause this element to be ignored.
587 // Then process other use cases that need to be applied to all the various roles
588 // that AXRenderObjects take on.
589 AXObjectInclusion decision = defaultObjectInclusion();
590 if (decision == IncludeObject)
592 if (decision == IgnoreObject)
595 // If this element is within a parent that cannot have children, it should not be exposed.
596 if (isDescendantOfBarrenParent())
599 if (roleValue() == IgnoredRole)
602 if (roleValue() == PresentationalRole || inheritsPresentationalRole())
605 // An ARIA tree can only have tree items and static text as children.
606 if (!isAllowedChildOfTree())
609 // TODO: we should refactor this - but right now this is necessary to make
610 // sure scroll areas stay in the tree.
614 // ignore popup menu items because AppKit does
615 for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
616 if (parent->isBoxModelObject() && toRenderBoxModelObject(parent)->isMenuList())
620 // find out if this element is inside of a label element.
621 // if so, it may be ignored because it's the label for a checkbox or radio button
622 AXObject* controlObject = correspondingControlForLabelElement();
623 if (controlObject && !controlObject->exposesTitleUIElement() && controlObject->isCheckboxOrRadio())
626 // NOTE: BRs always have text boxes now, so the text box check here can be removed
627 if (m_renderer->isText()) {
628 // static text beneath MenuItems and MenuButtons are just reported along with the menu item, so it's ignored on an individual level
629 AXObject* parent = parentObjectUnignored();
630 if (parent && (parent->ariaRoleAttribute() == MenuItemRole || parent->ariaRoleAttribute() == MenuButtonRole))
632 RenderText* renderText = toRenderText(m_renderer);
633 if (m_renderer->isBR() || !renderText->firstTextBox())
636 // Don't ignore static text in editable text controls.
637 for (AXObject* parent = parentObject(); parent; parent = parent->parentObject()) {
638 if (parent->roleValue() == TextFieldRole || parent->roleValue() == TextAreaRole)
642 // text elements that are just empty whitespace should not be returned
643 // FIXME(dmazzoni): we probably shouldn't ignore this if the style is 'pre', or similar...
644 return renderText->text().impl()->containsOnlyWhitespace();
650 if (isLandmarkRelated())
656 // all controls are accessible
660 if (ariaRoleAttribute() != UnknownRole)
663 // don't ignore labels, because they serve as TitleUIElements
664 Node* node = m_renderer->node();
665 if (node && node->hasTagName(labelTag))
668 // Anything that is content editable should not be ignored.
669 // However, one cannot just call node->rendererIsEditable() since that will ask if its parents
670 // are also editable. Only the top level content editable region should be exposed.
671 if (hasContentEditableAttributeSet())
674 // List items play an important role in defining the structure of lists. They should not be ignored.
675 if (roleValue() == ListItemRole)
678 if (roleValue() == DialogRole)
681 // if this element has aria attributes on it, it should not be ignored.
682 if (supportsARIAAttributes())
685 // <span> tags are inline tags and not meant to convey information if they have no other aria
686 // information on them. If we don't ignore them, they may emit signals expected to come from
687 // their parent. In addition, because included spans are GroupRole objects, and GroupRole
688 // objects are often containers with meaningful information, the inclusion of a span can have
689 // the side effect of causing the immediate parent accessible to be ignored. This is especially
690 // problematic for platforms which have distinct roles for textual block elements.
691 if (node && node->hasTagName(spanTag))
694 if (m_renderer->isRenderBlockFlow() && m_renderer->childrenInline() && !canSetFocusAttribute())
695 return !toRenderBlock(m_renderer)->firstLineBox() && !mouseButtonListener();
697 // ignore images seemingly used as spacers
700 // If the image can take focus, it should not be ignored, lest the user not be able to interact with something important.
701 if (canSetFocusAttribute())
704 if (node && node->isElementNode()) {
705 Element* elt = toElement(node);
706 const AtomicString& alt = elt->getAttribute(altAttr);
707 // don't ignore an image that has an alt tag
708 if (!alt.string().containsOnlyWhitespace())
710 // informal standard is to ignore images with zero-length alt strings
715 if (isNativeImage() && m_renderer->isImage()) {
716 // check for one-dimensional image
717 RenderImage* image = toRenderImage(m_renderer);
718 if (image->height() <= 1 || image->width() <= 1)
721 // check whether rendered image was stretched from one-dimensional file image
722 if (image->cachedImage()) {
723 LayoutSize imageSize = image->cachedImage()->imageSizeForRenderer(m_renderer, image->view()->zoomFactor());
724 return imageSize.height() <= 1 || imageSize.width() <= 1;
731 if (canvasHasFallbackContent())
733 RenderHTMLCanvas* canvas = toRenderHTMLCanvas(m_renderer);
734 if (canvas->height() <= 1 || canvas->width() <= 1)
736 // Otherwise fall through; use presence of help text, title, or description to decide.
739 if (isWebArea() || m_renderer->isListMarker())
742 // Using the help text, title or accessibility description (so we
743 // check if there's some kind of accessible name for the element)
744 // to decide an element's visibility is not as definitive as
745 // previous checks, so this should remain as one of the last.
747 // These checks are simplified in the interest of execution speed;
748 // for example, any element having an alt attribute will make it
749 // not ignored, rather than just images.
750 if (!getAttribute(aria_helpAttr).isEmpty() || !getAttribute(aria_describedbyAttr).isEmpty() || !getAttribute(altAttr).isEmpty() || !getAttribute(titleAttr).isEmpty())
753 // Don't ignore generic focusable elements like <div tabindex=0>
754 // unless they're completely empty, with no children.
755 if (isGenericFocusableElement() && node->firstChild())
758 if (!ariaAccessibilityDescription().isEmpty())
761 // By default, objects should be ignored so that the AX hierarchy is not
762 // filled with unnecessary items.
767 // Properties of static elements.
770 const AtomicString& AXRenderObject::accessKey() const
772 Node* node = m_renderer->node();
775 if (!node->isElementNode())
777 return toElement(node)->getAttribute(accesskeyAttr);
780 AccessibilityOrientation AXRenderObject::orientation() const
782 const AtomicString& ariaOrientation = getAttribute(aria_orientationAttr);
783 if (equalIgnoringCase(ariaOrientation, "horizontal"))
784 return AccessibilityOrientationHorizontal;
785 if (equalIgnoringCase(ariaOrientation, "vertical"))
786 return AccessibilityOrientationVertical;
788 return AXObject::orientation();
791 String AXRenderObject::text() const
793 if (isPasswordField())
796 return AXNodeObject::text();
799 int AXRenderObject::textLength() const
801 ASSERT(isTextControl());
803 if (isPasswordField())
804 return -1; // need to return something distinct from 0
806 return text().length();
809 KURL AXRenderObject::url() const
811 if (isAnchor() && m_renderer->node()->hasTagName(aTag)) {
812 if (HTMLAnchorElement* anchor = toHTMLAnchorElement(anchorElement()))
813 return anchor->href();
817 return m_renderer->document().url();
819 if (isImage() && m_renderer->node() && m_renderer->node()->hasTagName(imgTag))
820 return toHTMLImageElement(m_renderer->node())->src();
823 return toHTMLInputElement(m_renderer->node())->src();
829 // Properties of interactive elements.
832 static String queryString(WebLocalizedString::Name name)
834 return Locale::defaultLocale().queryString(name);
837 String AXRenderObject::actionVerb() const
839 switch (roleValue()) {
841 case ToggleButtonRole:
842 return queryString(WebLocalizedString::AXButtonActionVerb);
845 return queryString(WebLocalizedString::AXTextFieldActionVerb);
846 case RadioButtonRole:
847 return queryString(WebLocalizedString::AXRadioButtonActionVerb);
849 return queryString(isChecked() ? WebLocalizedString::AXCheckedCheckBoxActionVerb : WebLocalizedString::AXUncheckedCheckBoxActionVerb);
851 return queryString(WebLocalizedString::AXLinkActionVerb);
853 return emptyString();
857 void AXRenderObject::selectedChildren(AccessibilityChildrenVector& result)
859 ASSERT(result.isEmpty());
861 // only listboxes should be asked for their selected children.
862 AccessibilityRole role = roleValue();
863 if (role == ListBoxRole) // native list boxes would be AXListBoxes, so only check for aria list boxes
864 ariaListboxSelectedChildren(result);
865 else if (role == TreeRole || role == TreeGridRole || role == TableRole)
866 ariaSelectedRows(result);
869 String AXRenderObject::stringValue() const
874 if (isPasswordField())
877 RenderBoxModelObject* cssBox = renderBoxModelObject();
879 if (ariaRoleAttribute() == StaticTextRole) {
880 String staticText = text();
881 if (!staticText.length())
882 staticText = textUnderElement();
886 if (m_renderer->isText())
887 return textUnderElement();
889 if (cssBox && cssBox->isMenuList()) {
890 // RenderMenuList will go straight to the text() of its selected item.
891 // This has to be overridden in the case where the selected item has an ARIA label.
892 HTMLSelectElement* selectElement = toHTMLSelectElement(m_renderer->node());
893 int selectedIndex = selectElement->selectedIndex();
894 const Vector<HTMLElement*> listItems = selectElement->listItems();
895 if (selectedIndex >= 0 && static_cast<size_t>(selectedIndex) < listItems.size()) {
896 const AtomicString& overriddenDescription = listItems[selectedIndex]->fastGetAttribute(aria_labelAttr);
897 if (!overriddenDescription.isNull())
898 return overriddenDescription;
900 return toRenderMenuList(m_renderer)->text();
903 if (m_renderer->isListMarker())
904 return toRenderListMarker(m_renderer)->text();
907 // FIXME: Why would a renderer exist when the Document isn't attached to a frame?
908 if (m_renderer->frame())
911 ASSERT_NOT_REACHED();
917 if (m_renderer->isFileUploadControl())
918 return toRenderFileUploadControl(m_renderer)->fileTextValue();
920 // FIXME: We might need to implement a value here for more types
921 // FIXME: It would be better not to advertise a value at all for the types for which we don't implement one;
922 // this would require subclassing or making accessibilityAttributeNames do something other than return a
923 // single static array.
931 AXObject* AXRenderObject::activeDescendant() const
936 if (m_renderer->node() && !m_renderer->node()->isElementNode())
938 Element* element = toElement(m_renderer->node());
940 const AtomicString& activeDescendantAttrStr = element->getAttribute(aria_activedescendantAttr);
941 if (activeDescendantAttrStr.isNull() || activeDescendantAttrStr.isEmpty())
944 Element* target = element->treeScope().getElementById(activeDescendantAttrStr);
948 AXObject* obj = axObjectCache()->getOrCreate(target);
950 // An activedescendant is only useful if it has a renderer, because that's what's needed to post the notification.
951 if (obj && obj->isAXRenderObject())
957 void AXRenderObject::ariaFlowToElements(AccessibilityChildrenVector& flowTo) const
959 Vector<Element*> elements;
960 elementsFromAttribute(elements, aria_flowtoAttr);
962 AXObjectCache* cache = axObjectCache();
963 unsigned count = elements.size();
964 for (unsigned k = 0; k < count; ++k) {
965 Element* element = elements[k];
966 AXObject* flowToElement = cache->getOrCreate(element);
968 flowTo.append(flowToElement);
972 bool AXRenderObject::ariaHasPopup() const
974 return elementAttributeValue(aria_haspopupAttr);
977 bool AXRenderObject::ariaRoleHasPresentationalChildren() const
979 switch (m_ariaRole) {
983 case ProgressIndicatorRole:
985 // case SeparatorRole:
992 bool AXRenderObject::isPresentationalChildOfAriaRole() const
994 // Walk the parent chain looking for a parent that has presentational children
996 for (parent = parentObject(); parent && !parent->ariaRoleHasPresentationalChildren(); parent = parent->parentObject())
1002 bool AXRenderObject::shouldFocusActiveDescendant() const
1004 switch (ariaRoleAttribute()) {
1009 case RadioGroupRole:
1011 case PopUpButtonRole:
1012 case ProgressIndicatorRole:
1017 /* FIXME: replace these with actual roles when they are added to AccessibilityRole
1030 bool AXRenderObject::supportsARIADragging() const
1032 const AtomicString& grabbed = getAttribute(aria_grabbedAttr);
1033 return equalIgnoringCase(grabbed, "true") || equalIgnoringCase(grabbed, "false");
1036 bool AXRenderObject::supportsARIADropping() const
1038 const AtomicString& dropEffect = getAttribute(aria_dropeffectAttr);
1039 return !dropEffect.isEmpty();
1042 bool AXRenderObject::supportsARIAFlowTo() const
1044 return !getAttribute(aria_flowtoAttr).isEmpty();
1047 bool AXRenderObject::supportsARIAOwns() const
1051 const AtomicString& ariaOwns = getAttribute(aria_ownsAttr);
1053 return !ariaOwns.isEmpty();
1057 // ARIA live-region features.
1060 const AtomicString& AXRenderObject::ariaLiveRegionStatus() const
1062 DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusAssertive, ("assertive", AtomicString::ConstructFromLiteral));
1063 DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusPolite, ("polite", AtomicString::ConstructFromLiteral));
1064 DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusOff, ("off", AtomicString::ConstructFromLiteral));
1066 const AtomicString& liveRegionStatus = getAttribute(aria_liveAttr);
1067 // These roles have implicit live region status.
1068 if (liveRegionStatus.isEmpty()) {
1069 switch (roleValue()) {
1070 case AlertDialogRole:
1072 return liveRegionStatusAssertive;
1075 return liveRegionStatusPolite;
1078 return liveRegionStatusOff;
1084 return liveRegionStatus;
1087 const AtomicString& AXRenderObject::ariaLiveRegionRelevant() const
1089 DEFINE_STATIC_LOCAL(const AtomicString, defaultLiveRegionRelevant, ("additions text", AtomicString::ConstructFromLiteral));
1090 const AtomicString& relevant = getAttribute(aria_relevantAttr);
1092 // Default aria-relevant = "additions text".
1093 if (relevant.isEmpty())
1094 return defaultLiveRegionRelevant;
1099 bool AXRenderObject::ariaLiveRegionAtomic() const
1101 return elementAttributeValue(aria_atomicAttr);
1104 bool AXRenderObject::ariaLiveRegionBusy() const
1106 return elementAttributeValue(aria_busyAttr);
1110 // Accessibility Text.
1113 String AXRenderObject::textUnderElement() const
1118 if (m_renderer->isFileUploadControl())
1119 return toRenderFileUploadControl(m_renderer)->buttonValue();
1121 if (m_renderer->isText())
1122 return toRenderText(m_renderer)->plainText();
1124 return AXNodeObject::textUnderElement();
1128 // Accessibility Text - (To be deprecated).
1131 String AXRenderObject::helpText() const
1136 const AtomicString& ariaHelp = getAttribute(aria_helpAttr);
1137 if (!ariaHelp.isEmpty())
1140 String describedBy = ariaDescribedByAttribute();
1141 if (!describedBy.isEmpty())
1144 String description = accessibilityDescription();
1145 for (RenderObject* curr = m_renderer; curr; curr = curr->parent()) {
1146 if (curr->node() && curr->node()->isHTMLElement()) {
1147 const AtomicString& summary = toElement(curr->node())->getAttribute(summaryAttr);
1148 if (!summary.isEmpty())
1151 // The title attribute should be used as help text unless it is already being used as descriptive text.
1152 const AtomicString& title = toElement(curr->node())->getAttribute(titleAttr);
1153 if (!title.isEmpty() && description != title)
1157 // Only take help text from an ancestor element if its a group or an unknown role. If help was
1158 // added to those kinds of elements, it is likely it was meant for a child element.
1159 AXObject* axObj = axObjectCache()->getOrCreate(curr);
1161 AccessibilityRole role = axObj->roleValue();
1162 if (role != GroupRole && role != UnknownRole)
1171 // Position and size.
1174 void AXRenderObject::checkCachedElementRect() const
1176 if (m_cachedElementRectDirty)
1182 if (!m_renderer->isBox())
1186 RenderBox* box = toRenderBox(m_renderer);
1187 if (box->frameRect() != m_cachedFrameRect)
1190 if (box->canBeScrolledAndHasScrollableArea()) {
1191 ScrollableArea* scrollableArea = box->scrollableArea();
1192 if (scrollableArea && scrollableArea->scrollPosition() != m_cachedScrollPosition)
1197 markCachedElementRectDirty();
1200 void AXRenderObject::updateCachedElementRect() const
1202 if (!m_cachedElementRectDirty)
1208 if (!m_renderer->isBox())
1211 RenderBox* box = toRenderBox(m_renderer);
1212 m_cachedFrameRect = box->frameRect();
1214 if (box->canBeScrolledAndHasScrollableArea()) {
1215 ScrollableArea* scrollableArea = box->scrollableArea();
1217 m_cachedScrollPosition = scrollableArea->scrollPosition();
1220 m_cachedElementRect = computeElementRect();
1221 m_cachedElementRectDirty = false;
1224 void AXRenderObject::markCachedElementRectDirty() const
1226 if (m_cachedElementRectDirty)
1229 // Marks children recursively, if this element changed.
1230 m_cachedElementRectDirty = true;
1231 for (AXObject* child = firstChild(); child; child = child->nextSibling())
1232 child->markCachedElementRectDirty();
1235 IntPoint AXRenderObject::clickPoint()
1237 // Headings are usually much wider than their textual content. If the mid point is used, often it can be wrong.
1238 if (isHeading() && children().size() == 1)
1239 return children()[0]->clickPoint();
1241 // use the default position unless this is an editable web area, in which case we use the selection bounds.
1242 if (!isWebArea() || isReadOnly())
1243 return AXObject::clickPoint();
1245 LayoutRect bounds = elementRect();
1246 return IntPoint(bounds.x() + (bounds.width() / 2), bounds.y() - (bounds.height() / 2));
1253 AXObject* AXRenderObject::accessibilityHitTest(const IntPoint& point) const
1255 if (!m_renderer || !m_renderer->hasLayer())
1258 RenderLayer* layer = toRenderBox(m_renderer)->layer();
1260 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
1261 HitTestResult hitTestResult = HitTestResult(point);
1262 layer->hitTest(request, hitTestResult);
1263 if (!hitTestResult.innerNode())
1265 Node* node = hitTestResult.innerNode()->deprecatedShadowAncestorNode();
1267 if (node->hasTagName(areaTag))
1268 return accessibilityImageMapHitTest(toHTMLAreaElement(node), point);
1270 if (node->hasTagName(optionTag))
1271 node = toHTMLOptionElement(node)->ownerSelectElement();
1273 RenderObject* obj = node->renderer();
1277 AXObject* result = obj->document().axObjectCache()->getOrCreate(obj);
1278 result->updateChildrenIfNecessary();
1280 // Allow the element to perform any hit-testing it might need to do to reach non-render children.
1281 result = result->elementAccessibilityHitTest(point);
1283 if (result && result->accessibilityIsIgnored()) {
1284 // If this element is the label of a control, a hit test should return the control.
1285 if (result->isAXRenderObject()) {
1286 AXObject* controlObject = toAXRenderObject(result)->correspondingControlForLabelElement();
1287 if (controlObject && !controlObject->exposesTitleUIElement())
1288 return controlObject;
1291 result = result->parentObjectUnignored();
1297 AXObject* AXRenderObject::elementAccessibilityHitTest(const IntPoint& point) const
1300 return remoteSVGElementHitTest(point);
1302 return AXObject::elementAccessibilityHitTest(point);
1306 // High-level accessibility tree access.
1309 AXObject* AXRenderObject::parentObject() const
1314 if (ariaRoleAttribute() == MenuBarRole)
1315 return axObjectCache()->getOrCreate(m_renderer->parent());
1317 // menuButton and its corresponding menu are DOM siblings, but Accessibility needs them to be parent/child
1318 if (ariaRoleAttribute() == MenuRole) {
1319 AXObject* parent = menuButtonForMenu();
1324 RenderObject* parentObj = renderParentObject();
1326 return axObjectCache()->getOrCreate(parentObj);
1328 // WebArea's parent should be the scroll view containing it.
1330 return axObjectCache()->getOrCreate(m_renderer->frame()->view());
1335 AXObject* AXRenderObject::parentObjectIfExists() const
1337 // WebArea's parent should be the scroll view containing it.
1339 return axObjectCache()->get(m_renderer->frame()->view());
1341 return axObjectCache()->get(renderParentObject());
1345 // Low-level accessibility tree exploration, only for use within the accessibility module.
1348 AXObject* AXRenderObject::firstChild() const
1353 RenderObject* firstChild = firstChildConsideringContinuation(m_renderer);
1358 return axObjectCache()->getOrCreate(firstChild);
1361 AXObject* AXRenderObject::nextSibling() const
1366 RenderObject* nextSibling = 0;
1368 RenderInline* inlineContinuation;
1369 if (m_renderer->isRenderBlock() && (inlineContinuation = toRenderBlock(m_renderer)->inlineElementContinuation())) {
1370 // Case 1: node is a block and has an inline continuation. Next sibling is the inline continuation's first child.
1371 nextSibling = firstChildConsideringContinuation(inlineContinuation);
1372 } else if (m_renderer->isAnonymousBlock() && lastChildHasContinuation(m_renderer)) {
1373 // Case 2: Anonymous block parent of the start of a continuation - skip all the way to
1374 // after the parent of the end, since everything in between will be linked up via the continuation.
1375 RenderObject* lastParent = endOfContinuations(m_renderer->lastChild())->parent();
1376 while (lastChildHasContinuation(lastParent))
1377 lastParent = endOfContinuations(lastParent->lastChild())->parent();
1378 nextSibling = lastParent->nextSibling();
1379 } else if (RenderObject* ns = m_renderer->nextSibling()) {
1380 // Case 3: node has an actual next sibling
1382 } else if (isInlineWithContinuation(m_renderer)) {
1383 // Case 4: node is an inline with a continuation. Next sibling is the next sibling of the end
1384 // of the continuation chain.
1385 nextSibling = endOfContinuations(m_renderer)->nextSibling();
1386 } else if (isInlineWithContinuation(m_renderer->parent())) {
1387 // Case 5: node has no next sibling, and its parent is an inline with a continuation.
1388 RenderObject* continuation = toRenderInline(m_renderer->parent())->continuation();
1390 if (continuation->isRenderBlock()) {
1391 // Case 5a: continuation is a block - in this case the block itself is the next sibling.
1392 nextSibling = continuation;
1394 // Case 5b: continuation is an inline - in this case the inline's first child is the next sibling.
1395 nextSibling = firstChildConsideringContinuation(continuation);
1402 return axObjectCache()->getOrCreate(nextSibling);
1405 void AXRenderObject::addChildren()
1407 // If the need to add more children in addition to existing children arises,
1408 // childrenChanged should have been called, leaving the object with no children.
1409 ASSERT(!m_haveChildren);
1411 m_haveChildren = true;
1413 if (!canHaveChildren())
1416 for (RefPtr<AXObject> obj = firstChild(); obj; obj = obj->nextSibling())
1417 addChild(obj.get());
1419 addHiddenChildren();
1420 addAttachmentChildren();
1421 addImageMapChildren();
1422 addTextFieldChildren();
1423 addCanvasChildren();
1424 addRemoteSVGChildren();
1425 addInlineTextBoxChildren();
1428 bool AXRenderObject::canHaveChildren() const
1433 return AXNodeObject::canHaveChildren();
1436 void AXRenderObject::updateChildrenIfNecessary()
1438 if (needsToUpdateChildren())
1441 AXObject::updateChildrenIfNecessary();
1444 void AXRenderObject::clearChildren()
1446 AXObject::clearChildren();
1447 m_childrenDirty = false;
1450 AXObject* AXRenderObject::observableObject() const
1452 // Find the object going up the parent chain that is used in accessibility to monitor certain notifications.
1453 for (RenderObject* renderer = m_renderer; renderer && renderer->node(); renderer = renderer->parent()) {
1454 if (renderObjectIsObservable(renderer))
1455 return axObjectCache()->getOrCreate(renderer);
1462 // Properties of the object's owning document or page.
1465 double AXRenderObject::estimatedLoadingProgress() const
1473 if (Page* page = m_renderer->document().page())
1474 return page->progress().estimatedProgress();
1479 // DOM and Render tree access.
1482 Node* AXRenderObject::node() const
1484 return m_renderer ? m_renderer->node() : 0;
1487 Document* AXRenderObject::document() const
1491 return &m_renderer->document();
1494 FrameView* AXRenderObject::documentFrameView() const
1499 // this is the RenderObject's Document's Frame's FrameView
1500 return m_renderer->document().view();
1503 Element* AXRenderObject::anchorElement() const
1508 AXObjectCache* cache = axObjectCache();
1509 RenderObject* currRenderer;
1511 // Search up the render tree for a RenderObject with a DOM node. Defer to an earlier continuation, though.
1512 for (currRenderer = m_renderer; currRenderer && !currRenderer->node(); currRenderer = currRenderer->parent()) {
1513 if (currRenderer->isAnonymousBlock()) {
1514 RenderObject* continuation = toRenderBlock(currRenderer)->continuation();
1516 return cache->getOrCreate(continuation)->anchorElement();
1520 // bail if none found
1524 // search up the DOM tree for an anchor element
1525 // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElement
1526 Node* node = currRenderer->node();
1527 for ( ; node; node = node->parentNode()) {
1528 if (node->hasTagName(aTag) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
1529 return toElement(node);
1535 Widget* AXRenderObject::widgetForAttachmentView() const
1537 if (!isAttachment())
1539 return toRenderWidget(m_renderer)->widget();
1546 AXObject::PlainTextRange AXRenderObject::selectedTextRange() const
1548 ASSERT(isTextControl());
1550 if (isPasswordField())
1551 return PlainTextRange();
1553 AccessibilityRole ariaRole = ariaRoleAttribute();
1554 if (isNativeTextControl() && ariaRole == UnknownRole && m_renderer->isTextControl()) {
1555 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1556 return PlainTextRange(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());
1559 if (ariaRole == UnknownRole)
1560 return PlainTextRange();
1562 return ariaSelectedTextRange();
1565 VisibleSelection AXRenderObject::selection() const
1567 return m_renderer->frame()->selection().selection();
1571 // Modify or take an action on an object.
1574 void AXRenderObject::setSelectedTextRange(const PlainTextRange& range)
1576 if (isNativeTextControl() && m_renderer->isTextControl()) {
1577 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1578 textControl->setSelectionRange(range.start, range.start + range.length);
1582 Document& document = m_renderer->document();
1583 Frame* frame = document.frame();
1586 Node* node = m_renderer->node();
1587 frame->selection().setSelection(VisibleSelection(Position(node, range.start, Position::PositionIsOffsetInAnchor),
1588 Position(node, range.start + range.length, Position::PositionIsOffsetInAnchor), DOWNSTREAM));
1591 void AXRenderObject::setValue(const String& string)
1593 if (!node() || !node()->isElementNode())
1595 if (!m_renderer || !m_renderer->isBoxModelObject())
1598 RenderBoxModelObject* renderer = toRenderBoxModelObject(m_renderer);
1599 if (renderer->isTextField() && node()->hasTagName(inputTag)) {
1600 toHTMLInputElement(node())->setValue(string);
1601 } else if (renderer->isTextArea() && node()->hasTagName(textareaTag)) {
1602 toHTMLTextAreaElement(node())->setValue(string);
1606 // FIXME: This function should use an IntSize to avoid the conversion below.
1607 void AXRenderObject::scrollTo(const IntPoint& point) const
1609 if (!m_renderer || !m_renderer->isBox())
1612 RenderBox* box = toRenderBox(m_renderer);
1613 if (!box->canBeScrolledAndHasScrollableArea())
1616 box->scrollToOffset(IntSize(point.x(), point.y()));
1620 // Notifications that this object may have changed.
1623 void AXRenderObject::handleActiveDescendantChanged()
1625 Element* element = toElement(renderer()->node());
1628 Document& doc = renderer()->document();
1629 if (!doc.frame()->selection().isFocusedAndActive() || doc.focusedElement() != element)
1631 AXRenderObject* activedescendant = toAXRenderObject(activeDescendant());
1633 if (activedescendant && shouldNotifyActiveDescendant())
1634 doc.axObjectCache()->postNotification(m_renderer, AXObjectCache::AXActiveDescendantChanged, true);
1637 void AXRenderObject::handleAriaExpandedChanged()
1639 // Find if a parent of this object should handle aria-expanded changes.
1640 AXObject* containerParent = this->parentObject();
1641 while (containerParent) {
1642 bool foundParent = false;
1644 switch (containerParent->roleValue()) {
1659 containerParent = containerParent->parentObject();
1662 // Post that the row count changed.
1663 if (containerParent)
1664 axObjectCache()->postNotification(containerParent, document(), AXObjectCache::AXRowCountChanged, true);
1666 // Post that the specific row either collapsed or expanded.
1667 if (roleValue() == RowRole || roleValue() == TreeItemRole)
1668 axObjectCache()->postNotification(this, document(), isExpanded() ? AXObjectCache::AXRowExpanded : AXObjectCache::AXRowCollapsed, true);
1671 void AXRenderObject::textChanged()
1676 if (AXObjectCache::inlineTextBoxAccessibility() && roleValue() == StaticTextRole)
1679 // Do this last - AXNodeObject::textChanged posts live region announcements,
1680 // and we should update the inline text boxes first.
1681 AXNodeObject::textChanged();
1685 // Text metrics. Most of these should be deprecated, needs major cleanup.
1688 // NOTE: Consider providing this utility method as AX API
1689 int AXRenderObject::index(const VisiblePosition& position) const
1691 if (position.isNull() || !isTextControl())
1694 if (renderObjectContainsPosition(m_renderer, position.deepEquivalent()))
1695 return indexForVisiblePosition(position);
1700 VisiblePosition AXRenderObject::visiblePositionForIndex(int index) const
1703 return VisiblePosition();
1705 if (isNativeTextControl() && m_renderer->isTextControl())
1706 return toRenderTextControl(m_renderer)->textFormControlElement()->visiblePositionForIndex(index);
1708 if (!allowsTextRanges() && !m_renderer->isText())
1709 return VisiblePosition();
1711 Node* node = m_renderer->node();
1713 return VisiblePosition();
1716 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
1718 RefPtr<Range> range = Range::create(m_renderer->document());
1719 range->selectNodeContents(node, IGNORE_EXCEPTION);
1720 CharacterIterator it(range.get());
1721 it.advance(index - 1);
1722 return VisiblePosition(Position(it.range()->endContainer(), it.range()->endOffset(), Position::PositionIsOffsetInAnch\
1726 int AXRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
1728 if (isNativeTextControl() && m_renderer->isTextControl()) {
1729 HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
1730 return textControl->indexForVisiblePosition(pos);
1733 if (!isTextControl())
1736 Node* node = m_renderer->node();
1740 Position indexPosition = pos.deepEquivalent();
1741 if (indexPosition.isNull() || highestEditableRoot(indexPosition, HasEditableAXRole) != node)
1744 RefPtr<Range> range = Range::create(m_renderer->document());
1745 range->setStart(node, 0, IGNORE_EXCEPTION);
1746 range->setEnd(indexPosition, IGNORE_EXCEPTION);
1748 return TextIterator::rangeLength(range.get());
1751 void AXRenderObject::addInlineTextBoxChildren()
1753 if (!axObjectCache()->inlineTextBoxAccessibility())
1756 if (!renderer() || !renderer()->isText())
1759 RenderText* renderText = toRenderText(renderer());
1760 if (renderText->needsLayout())
1761 renderText->document().updateLayoutIgnorePendingStylesheets();
1763 for (RefPtr<AbstractInlineTextBox> box = renderText->firstAbstractInlineTextBox(); box.get(); box = box->nextInlineTextBox()) {
1764 AXObject* axObject = axObjectCache()->getOrCreate(box.get());
1765 if (!axObject->accessibilityIsIgnored())
1766 m_children.append(axObject);
1770 void AXRenderObject::lineBreaks(Vector<int>& lineBreaks) const
1772 if (!isTextControl())
1775 VisiblePosition visiblePos = visiblePositionForIndex(0);
1776 VisiblePosition savedVisiblePos = visiblePos;
1777 visiblePos = nextLinePosition(visiblePos, 0);
1778 while (!visiblePos.isNull() && visiblePos != savedVisiblePos) {
1779 lineBreaks.append(indexForVisiblePosition(visiblePos));
1780 savedVisiblePos = visiblePos;
1781 visiblePos = nextLinePosition(visiblePos, 0);
1789 bool AXRenderObject::isAllowedChildOfTree() const
1791 // Determine if this is in a tree. If so, we apply special behavior to make it work like an AXOutline.
1792 AXObject* axObj = parentObject();
1793 bool isInTree = false;
1795 if (axObj->isTree()) {
1799 axObj = axObj->parentObject();
1802 // If the object is in a tree, only tree items should be exposed (and the children of tree items).
1804 AccessibilityRole role = roleValue();
1805 if (role != TreeItemRole && role != StaticTextRole)
1811 void AXRenderObject::ariaListboxSelectedChildren(AccessibilityChildrenVector& result)
1813 bool isMulti = isMultiSelectable();
1815 AccessibilityChildrenVector childObjects = children();
1816 unsigned childrenSize = childObjects.size();
1817 for (unsigned k = 0; k < childrenSize; ++k) {
1818 // Every child should have aria-role option, and if so, check for selected attribute/state.
1819 AXObject* child = childObjects[k].get();
1820 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRole) {
1821 result.append(child);
1828 AXObject::PlainTextRange AXRenderObject::ariaSelectedTextRange() const
1830 Node* node = m_renderer->node();
1832 return PlainTextRange();
1834 VisibleSelection visibleSelection = selection();
1835 RefPtr<Range> currentSelectionRange = visibleSelection.toNormalizedRange();
1836 if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, IGNORE_EXCEPTION))
1837 return PlainTextRange();
1839 int start = indexForVisiblePosition(visibleSelection.start());
1840 int end = indexForVisiblePosition(visibleSelection.end());
1842 return PlainTextRange(start, end - start);
1845 bool AXRenderObject::nodeIsTextControl(const Node* node) const
1850 const AXObject* axObjectForNode = axObjectCache()->getOrCreate(const_cast<Node*>(node));
1851 if (!axObjectForNode)
1854 return axObjectForNode->isTextControl();
1857 bool AXRenderObject::isTabItemSelected() const
1859 if (!isTabItem() || !m_renderer)
1862 Node* node = m_renderer->node();
1863 if (!node || !node->isElementNode())
1866 // The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel
1867 // that has keyboard focus inside of it, or if a tabpanel in its aria-controls list has KB
1868 // focus inside of it.
1869 AXObject* focusedElement = focusedUIElement();
1870 if (!focusedElement)
1873 Vector<Element*> elements;
1874 elementsFromAttribute(elements, aria_controlsAttr);
1876 unsigned count = elements.size();
1877 for (unsigned k = 0; k < count; ++k) {
1878 Element* element = elements[k];
1879 AXObject* tabPanel = axObjectCache()->getOrCreate(element);
1881 // A tab item should only control tab panels.
1882 if (!tabPanel || tabPanel->roleValue() != TabPanelRole)
1885 AXObject* checkFocusElement = focusedElement;
1886 // Check if the focused element is a descendant of the element controlled by the tab item.
1887 while (checkFocusElement) {
1888 if (tabPanel == checkFocusElement)
1890 checkFocusElement = checkFocusElement->parentObject();
1897 AXObject* AXRenderObject::internalLinkElement() const
1899 Element* element = anchorElement();
1903 // Right now, we do not support ARIA links as internal link elements
1904 if (!element->hasTagName(aTag))
1906 HTMLAnchorElement* anchor = toHTMLAnchorElement(element);
1908 KURL linkURL = anchor->href();
1909 String fragmentIdentifier = linkURL.fragmentIdentifier();
1910 if (fragmentIdentifier.isEmpty())
1913 // check if URL is the same as current URL
1914 KURL documentURL = m_renderer->document().url();
1915 if (!equalIgnoringFragmentIdentifier(documentURL, linkURL))
1918 Node* linkedNode = m_renderer->document().findAnchor(fragmentIdentifier);
1922 // The element we find may not be accessible, so find the first accessible object.
1923 return firstAccessibleObjectFromNode(linkedNode);
1926 AXObject* AXRenderObject::accessibilityImageMapHitTest(HTMLAreaElement* area, const IntPoint& point) const
1931 AXObject* parent = axObjectCache()->getOrCreate(area->imageElement());
1935 AXObject::AccessibilityChildrenVector children = parent->children();
1936 unsigned count = children.size();
1937 for (unsigned k = 0; k < count; ++k) {
1938 if (children[k]->elementRect().contains(point))
1939 return children[k].get();
1945 bool AXRenderObject::renderObjectIsObservable(RenderObject* renderer) const
1947 // AX clients will listen for AXValueChange on a text control.
1948 if (renderer->isTextControl())
1951 // AX clients will listen for AXSelectedChildrenChanged on listboxes.
1952 Node* node = renderer->node();
1953 if (nodeHasRole(node, "listbox") || (renderer->isBoxModelObject() && toRenderBoxModelObject(renderer)->isListBox()))
1956 // Textboxes should send out notifications.
1957 if (nodeHasRole(node, "textbox"))
1963 RenderObject* AXRenderObject::renderParentObject() const
1968 RenderObject* parent = m_renderer->parent();
1970 RenderObject* startOfConts = 0;
1971 RenderObject* firstChild = 0;
1972 if (m_renderer->isRenderBlock() && (startOfConts = startOfContinuations(m_renderer))) {
1973 // Case 1: node is a block and is an inline's continuation. Parent
1974 // is the start of the continuation chain.
1975 parent = startOfConts;
1976 } else if (parent && parent->isRenderInline() && (startOfConts = startOfContinuations(parent))) {
1977 // Case 2: node's parent is an inline which is some node's continuation; parent is
1978 // the earliest node in the continuation chain.
1979 parent = startOfConts;
1980 } else if (parent && (firstChild = parent->firstChild()) && firstChild->node()) {
1981 // Case 3: The first sibling is the beginning of a continuation chain. Find the origin of that continuation.
1982 // Get the node's renderer and follow that continuation chain until the first child is found.
1983 RenderObject* nodeRenderFirstChild = firstChild->node()->renderer();
1984 while (nodeRenderFirstChild != firstChild) {
1985 for (RenderObject* contsTest = nodeRenderFirstChild; contsTest; contsTest = nextContinuation(contsTest)) {
1986 if (contsTest == firstChild) {
1987 parent = nodeRenderFirstChild->parent();
1991 if (firstChild == parent->firstChild())
1993 firstChild = parent->firstChild();
1994 if (!firstChild->node())
1996 nodeRenderFirstChild = firstChild->node()->renderer();
2003 bool AXRenderObject::isDescendantOfElementType(const QualifiedName& tagName) const
2005 for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
2006 if (parent->node() && parent->node()->hasTagName(tagName))
2012 bool AXRenderObject::isSVGImage() const
2014 return remoteSVGRootElement();
2017 void AXRenderObject::detachRemoteSVGRoot()
2019 if (AXSVGRoot* root = remoteSVGRootElement())
2023 AXSVGRoot* AXRenderObject::remoteSVGRootElement() const
2025 if (!m_renderer || !m_renderer->isRenderImage())
2028 ImageResource* cachedImage = toRenderImage(m_renderer)->cachedImage();
2032 Image* image = cachedImage->image();
2033 if (!image || !image->isSVGImage())
2036 FrameView* frameView = toSVGImage(image)->frameView();
2039 Document* doc = frameView->frame().document();
2040 if (!doc || !doc->isSVGDocument())
2043 SVGSVGElement* rootElement = toSVGDocument(doc)->rootElement();
2046 RenderObject* rendererRoot = rootElement->renderer();
2050 AXObject* rootSVGObject = doc->axObjectCache()->getOrCreate(rendererRoot);
2052 // In order to connect the AX hierarchy from the SVG root element from the loaded resource
2053 // the parent must be set, because there's no other way to get back to who created the image.
2054 ASSERT(rootSVGObject && rootSVGObject->isAXSVGRoot());
2055 if (!rootSVGObject->isAXSVGRoot())
2058 return toAXSVGRoot(rootSVGObject);
2061 AXObject* AXRenderObject::remoteSVGElementHitTest(const IntPoint& point) const
2063 AXObject* remote = remoteSVGRootElement();
2067 IntSize offset = point - roundedIntPoint(elementRect().location());
2068 return remote->accessibilityHitTest(IntPoint(offset));
2071 // The boundingBox for elements within the remote SVG element needs to be offset by its position
2072 // within the parent page, otherwise they are in relative coordinates only.
2073 void AXRenderObject::offsetBoundingBoxForRemoteSVGElement(LayoutRect& rect) const
2075 for (AXObject* parent = parentObject(); parent; parent = parent->parentObject()) {
2076 if (parent->isAXSVGRoot()) {
2077 rect.moveBy(parent->parentObject()->elementRect().location());
2083 // Hidden children are those that are not rendered or visible, but are specifically marked as aria-hidden=false,
2084 // meaning that they should be exposed to the AX hierarchy.
2085 void AXRenderObject::addHiddenChildren()
2087 Node* node = this->node();
2091 // First do a quick run through to determine if we have any hidden nodes (most often we will not).
2092 // If we do have hidden nodes, we need to determine where to insert them so they match DOM order as close as possible.
2093 bool shouldInsertHiddenNodes = false;
2094 for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
2095 if (!child->renderer() && isNodeAriaVisible(child)) {
2096 shouldInsertHiddenNodes = true;
2101 if (!shouldInsertHiddenNodes)
2104 // Iterate through all of the children, including those that may have already been added, and
2105 // try to insert hidden nodes in the correct place in the DOM order.
2106 unsigned insertionIndex = 0;
2107 for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
2108 if (child->renderer()) {
2109 // Find out where the last render sibling is located within m_children.
2110 AXObject* childObject = axObjectCache()->get(child->renderer());
2111 if (childObject && childObject->accessibilityIsIgnored()) {
2112 AccessibilityChildrenVector children = childObject->children();
2113 if (children.size())
2114 childObject = children.last().get();
2120 insertionIndex = m_children.find(childObject) + 1;
2124 if (!isNodeAriaVisible(child))
2127 unsigned previousSize = m_children.size();
2128 if (insertionIndex > previousSize)
2129 insertionIndex = previousSize;
2131 insertChild(axObjectCache()->getOrCreate(child), insertionIndex);
2132 insertionIndex += (m_children.size() - previousSize);
2136 void AXRenderObject::addTextFieldChildren()
2138 Node* node = this->node();
2139 if (!node || !node->hasTagName(inputTag))
2142 HTMLInputElement* input = toHTMLInputElement(node);
2143 Element* spinButtonElement = input->userAgentShadowRoot()->getElementById(ShadowElementNames::spinButton());
2144 if (!spinButtonElement || !spinButtonElement->isSpinButtonElement())
2147 AXSpinButton* axSpinButton = toAXSpinButton(axObjectCache()->getOrCreate(SpinButtonRole));
2148 axSpinButton->setSpinButtonElement(toSpinButtonElement(spinButtonElement));
2149 axSpinButton->setParent(this);
2150 m_children.append(axSpinButton);
2153 void AXRenderObject::addImageMapChildren()
2155 RenderBoxModelObject* cssBox = renderBoxModelObject();
2156 if (!cssBox || !cssBox->isRenderImage())
2159 HTMLMapElement* map = toRenderImage(cssBox)->imageMap();
2163 for (Element* current = ElementTraversal::firstWithin(*map); current; current = ElementTraversal::next(*current, map)) {
2164 // add an <area> element for this child if it has a link
2165 if (current->hasTagName(areaTag) && current->isLink()) {
2166 AXImageMapLink* areaObject = toAXImageMapLink(axObjectCache()->getOrCreate(ImageMapLinkRole));
2167 areaObject->setHTMLAreaElement(toHTMLAreaElement(current));
2168 areaObject->setHTMLMapElement(map);
2169 areaObject->setParent(this);
2170 if (!areaObject->accessibilityIsIgnored())
2171 m_children.append(areaObject);
2173 axObjectCache()->remove(areaObject->axObjectID());
2178 void AXRenderObject::addCanvasChildren()
2180 if (!node() || !node()->hasTagName(canvasTag))
2183 // If it's a canvas, it won't have rendered children, but it might have accessible fallback content.
2184 // Clear m_haveChildren because AXNodeObject::addChildren will expect it to be false.
2185 ASSERT(!m_children.size());
2186 m_haveChildren = false;
2187 AXNodeObject::addChildren();
2190 void AXRenderObject::addAttachmentChildren()
2192 if (!isAttachment())
2195 // FrameView's need to be inserted into the AX hierarchy when encountered.
2196 Widget* widget = widgetForAttachmentView();
2197 if (!widget || !widget->isFrameView())
2200 AXObject* axWidget = axObjectCache()->getOrCreate(widget);
2201 if (!axWidget->accessibilityIsIgnored())
2202 m_children.append(axWidget);
2205 void AXRenderObject::addRemoteSVGChildren()
2207 AXSVGRoot* root = remoteSVGRootElement();
2211 root->setParent(this);
2213 if (root->accessibilityIsIgnored()) {
2214 AccessibilityChildrenVector children = root->children();
2215 unsigned length = children.size();
2216 for (unsigned i = 0; i < length; ++i)
2217 m_children.append(children[i]);
2219 m_children.append(root);
2223 void AXRenderObject::ariaSelectedRows(AccessibilityChildrenVector& result)
2225 // Get all the rows.
2226 AccessibilityChildrenVector allRows;
2228 ariaTreeRows(allRows);
2229 else if (isAXTable() && toAXTable(this)->supportsSelectedRows())
2230 allRows = toAXTable(this)->rows();
2232 // Determine which rows are selected.
2233 bool isMulti = isMultiSelectable();
2235 // Prefer active descendant over aria-selected.
2236 AXObject* activeDesc = activeDescendant();
2237 if (activeDesc && (activeDesc->isTreeItem() || activeDesc->isTableRow())) {
2238 result.append(activeDesc);
2243 unsigned count = allRows.size();
2244 for (unsigned k = 0; k < count; ++k) {
2245 if (allRows[k]->isSelected()) {
2246 result.append(allRows[k]);
2253 bool AXRenderObject::elementAttributeValue(const QualifiedName& attributeName) const
2258 return equalIgnoringCase(getAttribute(attributeName), "true");
2261 bool AXRenderObject::inheritsPresentationalRole() const
2263 // ARIA states if an item can get focus, it should not be presentational.
2264 if (canSetFocusAttribute())
2267 // ARIA spec says that when a parent object is presentational, and it has required child elements,
2268 // those child elements are also presentational. For example, <li> becomes presentational from <ul>.
2269 // http://www.w3.org/WAI/PF/aria/complete#presentation
2270 if (roleValue() != ListItemRole && roleValue() != ListMarkerRole)
2273 AXObject* parent = parentObject();
2274 if (!parent->isAXRenderObject())
2277 Node* elementNode = toAXRenderObject(parent)->node();
2278 if (!elementNode || !elementNode->isElementNode())
2281 QualifiedName tagName = toElement(elementNode)->tagQName();
2282 if (tagName == ulTag || tagName == olTag || tagName == dlTag)
2283 return parent->roleValue() == PresentationalRole;
2288 LayoutRect AXRenderObject::computeElementRect() const
2290 RenderObject* obj = m_renderer;
2293 return LayoutRect();
2295 if (obj->node()) // If we are a continuation, we want to make sure to use the primary renderer.
2296 obj = obj->node()->renderer();
2298 // absoluteFocusRingQuads will query the hierarchy below this element, which for large webpages can be very slow.
2299 // For a web area, which will have the most elements of any element, absoluteQuads should be used.
2300 // We should also use absoluteQuads for SVG elements, otherwise transforms won't be applied.
2301 Vector<FloatQuad> quads;
2304 toRenderText(obj)->absoluteQuads(quads, 0, RenderText::ClipToEllipsis);
2305 else if (isWebArea() || obj->isSVGRoot())
2306 obj->absoluteQuads(quads);
2308 obj->absoluteFocusRingQuads(quads);
2310 LayoutRect result = boundingBoxForQuads(obj, quads);
2312 Document* document = this->document();
2313 if (document && document->isSVGDocument())
2314 offsetBoundingBoxForRemoteSVGElement(result);
2316 // The size of the web area should be the content size, not the clipped size.
2317 if (isWebArea() && obj->frame()->view())
2318 result.setSize(obj->frame()->view()->contentsSize());
2320 // Checkboxes and radio buttons include their label as part of their rect.
2321 if (isCheckboxOrRadio()) {
2322 HTMLLabelElement* label = labelForElement(toElement(m_renderer->node()));
2323 if (label && label->renderer()) {
2324 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementRect();
2325 result.unite(labelRect);
2332 } // namespace WebCore