This source file includes following definitions.
- firstChildInContinuation
- isInlineWithContinuation
- firstChildConsideringContinuation
- startOfContinuations
- endOfContinuations
- lastChildHasContinuation
- nextContinuation
- m_cachedElementRectDirty
- create
- elementRect
- setRenderer
- renderBoxModelObject
- topRenderer
- topDocument
- shouldNotifyActiveDescendant
- getScrollableAreaIfScrollable
- determineAccessibilityRole
- init
- detach
- isAttachment
- isFileUploadButton
- isLinkable
- isLinked
- isLoaded
- isOffScreen
- isReadOnly
- isVisited
- isFocused
- isSelected
- defaultObjectInclusion
- computeAccessibilityIsIgnored
- accessKey
- orientation
- text
- textLength
- url
- queryString
- actionVerb
- selectedChildren
- stringValue
- activeDescendant
- accessibilityChildrenFromAttribute
- ariaFlowToElements
- ariaControlsElements
- ariaDescribedbyElements
- ariaLabelledbyElements
- ariaOwnsElements
- ariaHasPopup
- ariaRoleHasPresentationalChildren
- isPresentationalChildOfAriaRole
- shouldFocusActiveDescendant
- supportsARIADragging
- supportsARIADropping
- supportsARIAFlowTo
- supportsARIAOwns
- ariaLiveRegionStatus
- ariaLiveRegionRelevant
- ariaLiveRegionAtomic
- ariaLiveRegionBusy
- textUnderElement
- helpText
- checkCachedElementRect
- updateCachedElementRect
- markCachedElementRectDirty
- clickPoint
- accessibilityHitTest
- elementAccessibilityHitTest
- parentObject
- parentObjectIfExists
- firstChild
- nextSibling
- addChildren
- canHaveChildren
- updateChildrenIfNecessary
- clearChildren
- observableObject
- estimatedLoadingProgress
- node
- document
- documentFrameView
- anchorElement
- widgetForAttachmentView
- selectedTextRange
- selection
- setSelectedTextRange
- setValue
- scrollTo
- handleActiveDescendantChanged
- handleAriaExpandedChanged
- textChanged
- index
- visiblePositionForIndex
- indexForVisiblePosition
- addInlineTextBoxChildren
- lineBreaks
- isAllowedChildOfTree
- ariaListboxSelectedChildren
- ariaSelectedTextRange
- nodeIsTextControl
- isTabItemSelected
- internalLinkElement
- accessibilityImageMapHitTest
- renderObjectIsObservable
- renderParentObject
- isDescendantOfElementType
- isSVGImage
- detachRemoteSVGRoot
- remoteSVGRootElement
- remoteSVGElementHitTest
- offsetBoundingBoxForRemoteSVGElement
- addHiddenChildren
- addTextFieldChildren
- addImageMapChildren
- addCanvasChildren
- addAttachmentChildren
- addRemoteSVGChildren
- ariaSelectedRows
- elementAttributeValue
- inheritsPresentationalRole
- computeElementRect
#include "config.h"
#include "core/accessibility/AXRenderObject.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/accessibility/AXImageMapLink.h"
#include "core/accessibility/AXInlineTextBox.h"
#include "core/accessibility/AXObjectCache.h"
#include "core/accessibility/AXSVGRoot.h"
#include "core/accessibility/AXSpinButton.h"
#include "core/accessibility/AXTable.h"
#include "core/dom/ElementTraversal.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/editing/FrameSelection.h"
#include "core/editing/RenderedPosition.h"
#include "core/editing/TextIterator.h"
#include "core/editing/VisibleUnits.h"
#include "core/editing/htmlediting.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLLabelElement.h"
#include "core/html/HTMLOptionElement.h"
#include "core/html/HTMLSelectElement.h"
#include "core/html/HTMLTextAreaElement.h"
#include "core/html/shadow/ShadowElementNames.h"
#include "core/loader/ProgressTracker.h"
#include "core/page/Page.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/RenderFieldset.h"
#include "core/rendering/RenderFileUploadControl.h"
#include "core/rendering/RenderHTMLCanvas.h"
#include "core/rendering/RenderImage.h"
#include "core/rendering/RenderInline.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderListMarker.h"
#include "core/rendering/RenderMenuList.h"
#include "core/rendering/RenderTextControlSingleLine.h"
#include "core/rendering/RenderTextFragment.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/RenderWidget.h"
#include "core/svg/SVGDocument.h"
#include "core/svg/SVGSVGElement.h"
#include "core/svg/graphics/SVGImage.h"
#include "platform/text/PlatformLocale.h"
#include "wtf/StdLibExtras.h"
using blink::WebLocalizedString;
namespace WebCore {
using namespace HTMLNames;
static inline RenderObject* firstChildInContinuation(RenderObject* renderer)
{
RenderObject* r = toRenderInline(renderer)->continuation();
while (r) {
if (r->isRenderBlock())
return r;
if (RenderObject* child = r->firstChild())
return child;
r = toRenderInline(r)->continuation();
}
return 0;
}
static inline bool isInlineWithContinuation(RenderObject* object)
{
if (!object->isBoxModelObject())
return false;
RenderBoxModelObject* renderer = toRenderBoxModelObject(object);
if (!renderer->isRenderInline())
return false;
return toRenderInline(renderer)->continuation();
}
static inline RenderObject* firstChildConsideringContinuation(RenderObject* renderer)
{
RenderObject* firstChild = renderer->firstChild();
if (!firstChild && isInlineWithContinuation(renderer))
firstChild = firstChildInContinuation(renderer);
return firstChild;
}
static inline RenderInline* startOfContinuations(RenderObject* r)
{
if (r->isInlineElementContinuation()) {
return toRenderInline(r->node()->renderer());
}
if (r->isRenderBlock() && toRenderBlock(r)->inlineElementContinuation())
return toRenderInline(toRenderBlock(r)->inlineElementContinuation()->node()->renderer());
return 0;
}
static inline RenderObject* endOfContinuations(RenderObject* renderer)
{
RenderObject* prev = renderer;
RenderObject* cur = renderer;
if (!cur->isRenderInline() && !cur->isRenderBlock())
return renderer;
while (cur) {
prev = cur;
if (cur->isRenderInline()) {
cur = toRenderInline(cur)->inlineElementContinuation();
ASSERT(cur || !toRenderInline(prev)->continuation());
} else {
cur = toRenderBlock(cur)->inlineElementContinuation();
}
}
return prev;
}
static inline bool lastChildHasContinuation(RenderObject* renderer)
{
return renderer->lastChild() && isInlineWithContinuation(renderer->lastChild());
}
static RenderBoxModelObject* nextContinuation(RenderObject* renderer)
{
ASSERT(renderer);
if (renderer->isRenderInline() && !renderer->isReplaced())
return toRenderInline(renderer)->continuation();
if (renderer->isRenderBlock())
return toRenderBlock(renderer)->inlineElementContinuation();
return 0;
}
AXRenderObject::AXRenderObject(RenderObject* renderer)
: AXNodeObject(renderer->node())
, m_renderer(renderer)
, m_cachedElementRectDirty(true)
{
#ifndef NDEBUG
m_renderer->setHasAXObject(true);
#endif
}
PassRefPtr<AXRenderObject> AXRenderObject::create(RenderObject* renderer)
{
return adoptRef(new AXRenderObject(renderer));
}
AXRenderObject::~AXRenderObject()
{
ASSERT(isDetached());
}
LayoutRect AXRenderObject::elementRect() const
{
if (!m_explicitElementRect.isEmpty())
return m_explicitElementRect;
if (!m_renderer)
return LayoutRect();
if (!m_renderer->isBox())
return computeElementRect();
for (const AXObject* obj = this; obj; obj = obj->parentObject()) {
if (obj->isAXRenderObject())
toAXRenderObject(obj)->checkCachedElementRect();
}
for (const AXObject* obj = this; obj; obj = obj->parentObject()) {
if (obj->isAXRenderObject())
toAXRenderObject(obj)->updateCachedElementRect();
}
return m_cachedElementRect;
}
void AXRenderObject::setRenderer(RenderObject* renderer)
{
m_renderer = renderer;
setNode(renderer->node());
}
RenderBoxModelObject* AXRenderObject::renderBoxModelObject() const
{
if (!m_renderer || !m_renderer->isBoxModelObject())
return 0;
return toRenderBoxModelObject(m_renderer);
}
RenderView* AXRenderObject::topRenderer() const
{
Document* topDoc = topDocument();
if (!topDoc)
return 0;
return topDoc->renderView();
}
Document* AXRenderObject::topDocument() const
{
if (!document())
return 0;
return &document()->topDocument();
}
bool AXRenderObject::shouldNotifyActiveDescendant() const
{
if (isComboBox())
return true;
return shouldFocusActiveDescendant();
}
ScrollableArea* AXRenderObject::getScrollableAreaIfScrollable() const
{
if (parentObject() && parentObject()->isAXScrollView())
return 0;
if (!m_renderer || !m_renderer->isBox())
return 0;
RenderBox* box = toRenderBox(m_renderer);
if (!box->canBeScrolledAndHasScrollableArea())
return 0;
return box->scrollableArea();
}
AccessibilityRole AXRenderObject::determineAccessibilityRole()
{
if (!m_renderer)
return UnknownRole;
m_ariaRole = determineAriaRoleAttribute();
Node* node = m_renderer->node();
AccessibilityRole ariaRole = ariaRoleAttribute();
if (ariaRole != UnknownRole)
return ariaRole;
RenderBoxModelObject* cssBox = renderBoxModelObject();
if (node && node->isLink()) {
if (cssBox && cssBox->isImage())
return ImageMapRole;
return LinkRole;
}
if (cssBox && cssBox->isListItem())
return ListItemRole;
if (m_renderer->isListMarker())
return ListMarkerRole;
if (isHTMLButtonElement(node))
return buttonRoleType();
if (isHTMLLegendElement(node))
return LegendRole;
if (m_renderer->isText())
return StaticTextRole;
if (cssBox && cssBox->isImage()) {
if (isHTMLInputElement(node))
return ariaHasPopup() ? PopUpButtonRole : ButtonRole;
if (isSVGImage())
return SVGRootRole;
return ImageRole;
}
if (isHTMLCanvasElement(node) && m_renderer->isCanvas())
return CanvasRole;
if (cssBox && cssBox->isRenderView())
return WebAreaRole;
if (cssBox && cssBox->isTextField())
return TextFieldRole;
if (cssBox && cssBox->isTextArea())
return TextAreaRole;
if (isHTMLInputElement(node)) {
HTMLInputElement& input = toHTMLInputElement(*node);
if (input.isCheckbox())
return CheckBoxRole;
if (input.isRadioButton())
return RadioButtonRole;
if (input.isTextButton())
return buttonRoleType();
const AtomicString& type = input.getAttribute(typeAttr);
if (equalIgnoringCase(type, "color"))
return ColorWellRole;
}
if (isFileUploadButton())
return ButtonRole;
if (cssBox && cssBox->isMenuList())
return PopUpButtonRole;
if (headingLevel())
return HeadingRole;
if (m_renderer->isSVGImage())
return ImageRole;
if (m_renderer->isSVGRoot())
return SVGRootRole;
if (node && node->hasTagName(ddTag))
return DescriptionListDetailRole;
if (node && node->hasTagName(dtTag))
return DescriptionListTermRole;
if (node && (node->hasTagName(rpTag) || node->hasTagName(rtTag)))
return AnnotationRole;
if (m_renderer->isTableSection())
return IgnoredRole;
if (m_renderer->isHR())
return HorizontalRuleRole;
if (isHTMLParagraphElement(node))
return ParagraphRole;
if (isHTMLLabelElement(node))
return LabelRole;
if (isHTMLDivElement(node))
return DivRole;
if (isHTMLFormElement(node))
return FormRole;
if (node && node->hasTagName(articleTag))
return ArticleRole;
if (node && node->hasTagName(mainTag))
return MainRole;
if (node && node->hasTagName(navTag))
return NavigationRole;
if (node && node->hasTagName(asideTag))
return ComplementaryRole;
if (node && node->hasTagName(sectionTag))
return RegionRole;
if (node && node->hasTagName(addressTag))
return ContentInfoRole;
if (node && node->hasTagName(dialogTag))
return DialogRole;
if (isHTMLHtmlElement(node))
return IgnoredRole;
if (node && node->hasTagName(iframeTag))
return IframeRole;
if (node && node->hasTagName(headerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
return BannerRole;
if (node && node->hasTagName(footerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
return FooterRole;
if (isHTMLAnchorElement(node) && isClickable())
return LinkRole;
if (m_renderer->isRenderBlockFlow())
return GroupRole;
if (supportsARIAAttributes())
return GroupRole;
return UnknownRole;
}
void AXRenderObject::init()
{
AXNodeObject::init();
}
void AXRenderObject::detach()
{
AXNodeObject::detach();
detachRemoteSVGRoot();
#ifndef NDEBUG
if (m_renderer)
m_renderer->setHasAXObject(false);
#endif
m_renderer = 0;
}
bool AXRenderObject::isAttachment() const
{
RenderBoxModelObject* renderer = renderBoxModelObject();
if (!renderer)
return false;
bool isWidget = renderer->isWidget();
ASSERT(!isWidget || (renderer->isReplaced() && !isImage()));
return isWidget;
}
bool AXRenderObject::isFileUploadButton() const
{
if (m_renderer && isHTMLInputElement(m_renderer->node())) {
HTMLInputElement& input = toHTMLInputElement(*m_renderer->node());
return input.isFileUpload();
}
return false;
}
static bool isLinkable(const AXObject& object)
{
if (!object.renderer())
return false;
return object.isLink() || object.isImage() || object.renderer()->isText();
}
bool AXRenderObject::isLinked() const
{
if (!isLinkable(*this))
return false;
Element* anchor = anchorElement();
if (!isHTMLAnchorElement(anchor))
return false;
return !toHTMLAnchorElement(*anchor).href().isEmpty();
}
bool AXRenderObject::isLoaded() const
{
return !m_renderer->document().parser();
}
bool AXRenderObject::isOffScreen() const
{
ASSERT(m_renderer);
IntRect contentRect = pixelSnappedIntRect(m_renderer->absoluteClippedOverflowRect());
FrameView* view = m_renderer->frame()->view();
IntRect viewRect = view->visibleContentRect();
viewRect.intersect(contentRect);
return viewRect.isEmpty();
}
bool AXRenderObject::isReadOnly() const
{
ASSERT(m_renderer);
if (isWebArea()) {
Document& document = m_renderer->document();
HTMLElement* body = document.body();
if (body && body->rendererIsEditable())
return false;
return !document.rendererIsEditable();
}
return AXNodeObject::isReadOnly();
}
bool AXRenderObject::isVisited() const
{
return m_renderer->style()->isLink() && m_renderer->style()->insideLink() == InsideVisitedLink;
}
bool AXRenderObject::isFocused() const
{
if (!m_renderer)
return false;
Document& document = m_renderer->document();
Element* focusedElement = document.focusedElement();
if (!focusedElement)
return false;
if (focusedElement == m_renderer->node()
|| (roleValue() == WebAreaRole && document.frame()->selection().isFocusedAndActive()))
return true;
return false;
}
bool AXRenderObject::isSelected() const
{
if (!m_renderer)
return false;
Node* node = m_renderer->node();
if (!node)
return false;
const AtomicString& ariaSelected = getAttribute(aria_selectedAttr);
if (equalIgnoringCase(ariaSelected, "true"))
return true;
if (isTabItem() && isTabItemSelected())
return true;
return false;
}
AXObjectInclusion AXRenderObject::defaultObjectInclusion() const
{
if (!m_renderer)
return IgnoreObject;
if (m_renderer->style()->visibility() != VISIBLE) {
if (equalIgnoringCase(getAttribute(aria_hiddenAttr), "false"))
return DefaultBehavior;
return IgnoreObject;
}
return AXObject::defaultObjectInclusion();
}
bool AXRenderObject::computeAccessibilityIsIgnored() const
{
#ifndef NDEBUG
ASSERT(m_initialized);
#endif
AXObjectInclusion decision = defaultObjectInclusion();
if (decision == IncludeObject)
return false;
if (decision == IgnoreObject)
return true;
if (isDescendantOfBarrenParent())
return true;
if (roleValue() == IgnoredRole)
return true;
if (roleValue() == PresentationalRole || inheritsPresentationalRole())
return true;
if (!isAllowedChildOfTree())
return true;
if (isAttachment())
return false;
for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
if (parent->isBoxModelObject() && toRenderBoxModelObject(parent)->isMenuList())
return true;
}
AXObject* controlObject = correspondingControlForLabelElement();
if (controlObject && !controlObject->exposesTitleUIElement() && controlObject->isCheckboxOrRadio())
return true;
if (m_renderer->isText()) {
AXObject* parent = parentObjectUnignored();
if (parent && (parent->ariaRoleAttribute() == MenuItemRole || parent->ariaRoleAttribute() == MenuButtonRole))
return true;
RenderText* renderText = toRenderText(m_renderer);
if (m_renderer->isBR() || !renderText->firstTextBox())
return true;
for (AXObject* parent = parentObject(); parent; parent = parent->parentObject()) {
if (parent->roleValue() == TextFieldRole || parent->roleValue() == TextAreaRole)
return false;
}
return renderText->text().impl()->containsOnlyWhitespace();
}
if (isHeading())
return false;
if (isLandmarkRelated())
return false;
if (isLink())
return false;
if (isControl())
return false;
if (ariaRoleAttribute() != UnknownRole)
return false;
Node* node = m_renderer->node();
if (isHTMLLabelElement(node))
return false;
if (hasContentEditableAttributeSet())
return false;
if (roleValue() == ListItemRole)
return false;
if (roleValue() == DialogRole)
return false;
if (supportsARIAAttributes())
return false;
if (isHTMLSpanElement(node))
return true;
if (m_renderer->isRenderBlockFlow() && m_renderer->childrenInline() && !canSetFocusAttribute())
return !toRenderBlock(m_renderer)->firstLineBox() && !mouseButtonListener();
if (isImage()) {
if (canSetFocusAttribute())
return false;
if (node && node->isElementNode()) {
Element* elt = toElement(node);
const AtomicString& alt = elt->getAttribute(altAttr);
if (!alt.string().containsOnlyWhitespace())
return false;
if (!alt.isNull())
return true;
}
if (isNativeImage() && m_renderer->isImage()) {
RenderImage* image = toRenderImage(m_renderer);
if (image->height() <= 1 || image->width() <= 1)
return true;
if (image->cachedImage()) {
LayoutSize imageSize = image->cachedImage()->imageSizeForRenderer(m_renderer, image->view()->zoomFactor());
return imageSize.height() <= 1 || imageSize.width() <= 1;
}
}
return false;
}
if (isCanvas()) {
if (canvasHasFallbackContent())
return false;
RenderHTMLCanvas* canvas = toRenderHTMLCanvas(m_renderer);
if (canvas->height() <= 1 || canvas->width() <= 1)
return true;
}
if (isWebArea() || m_renderer->isListMarker())
return false;
if (!getAttribute(aria_helpAttr).isEmpty() || !getAttribute(aria_describedbyAttr).isEmpty() || !getAttribute(altAttr).isEmpty() || !getAttribute(titleAttr).isEmpty())
return false;
if (isGenericFocusableElement() && node->firstChild())
return false;
if (!ariaAccessibilityDescription().isEmpty())
return false;
return true;
}
const AtomicString& AXRenderObject::accessKey() const
{
Node* node = m_renderer->node();
if (!node)
return nullAtom;
if (!node->isElementNode())
return nullAtom;
return toElement(node)->getAttribute(accesskeyAttr);
}
AccessibilityOrientation AXRenderObject::orientation() const
{
const AtomicString& ariaOrientation = getAttribute(aria_orientationAttr);
if (equalIgnoringCase(ariaOrientation, "horizontal"))
return AccessibilityOrientationHorizontal;
if (equalIgnoringCase(ariaOrientation, "vertical"))
return AccessibilityOrientationVertical;
return AXObject::orientation();
}
String AXRenderObject::text() const
{
if (isPasswordField())
return String();
return AXNodeObject::text();
}
int AXRenderObject::textLength() const
{
if (!isTextControl())
return -1;
if (isPasswordField())
return -1;
return text().length();
}
KURL AXRenderObject::url() const
{
if (isAnchor() && isHTMLAnchorElement(m_renderer->node())) {
if (HTMLAnchorElement* anchor = toHTMLAnchorElement(anchorElement()))
return anchor->href();
}
if (isWebArea())
return m_renderer->document().url();
if (isImage() && isHTMLImageElement(m_renderer->node()))
return toHTMLImageElement(*m_renderer->node()).src();
if (isInputImage())
return toHTMLInputElement(m_renderer->node())->src();
return KURL();
}
static String queryString(WebLocalizedString::Name name)
{
return Locale::defaultLocale().queryString(name);
}
String AXRenderObject::actionVerb() const
{
switch (roleValue()) {
case ButtonRole:
case ToggleButtonRole:
return queryString(WebLocalizedString::AXButtonActionVerb);
case TextFieldRole:
case TextAreaRole:
return queryString(WebLocalizedString::AXTextFieldActionVerb);
case RadioButtonRole:
return queryString(WebLocalizedString::AXRadioButtonActionVerb);
case CheckBoxRole:
return queryString(isChecked() ? WebLocalizedString::AXCheckedCheckBoxActionVerb : WebLocalizedString::AXUncheckedCheckBoxActionVerb);
case LinkRole:
return queryString(WebLocalizedString::AXLinkActionVerb);
default:
return emptyString();
}
}
void AXRenderObject::selectedChildren(AccessibilityChildrenVector& result)
{
ASSERT(result.isEmpty());
AccessibilityRole role = roleValue();
if (role == ListBoxRole)
ariaListboxSelectedChildren(result);
else if (role == TreeRole || role == TreeGridRole || role == TableRole)
ariaSelectedRows(result);
}
String AXRenderObject::stringValue() const
{
if (!m_renderer)
return String();
if (isPasswordField())
return String();
RenderBoxModelObject* cssBox = renderBoxModelObject();
if (ariaRoleAttribute() == StaticTextRole) {
String staticText = text();
if (!staticText.length())
staticText = textUnderElement();
return staticText;
}
if (m_renderer->isText())
return textUnderElement();
if (cssBox && cssBox->isMenuList()) {
HTMLSelectElement* selectElement = toHTMLSelectElement(m_renderer->node());
int selectedIndex = selectElement->selectedIndex();
const Vector<HTMLElement*> listItems = selectElement->listItems();
if (selectedIndex >= 0 && static_cast<size_t>(selectedIndex) < listItems.size()) {
const AtomicString& overriddenDescription = listItems[selectedIndex]->fastGetAttribute(aria_labelAttr);
if (!overriddenDescription.isNull())
return overriddenDescription;
}
return toRenderMenuList(m_renderer)->text();
}
if (m_renderer->isListMarker())
return toRenderListMarker(m_renderer)->text();
if (isWebArea()) {
if (m_renderer->frame())
return String();
ASSERT_NOT_REACHED();
}
if (isTextControl())
return text();
if (m_renderer->isFileUploadControl())
return toRenderFileUploadControl(m_renderer)->fileTextValue();
return String();
}
AXObject* AXRenderObject::activeDescendant() const
{
if (!m_renderer)
return 0;
if (m_renderer->node() && !m_renderer->node()->isElementNode())
return 0;
Element* element = toElement(m_renderer->node());
if (!element)
return 0;
const AtomicString& activeDescendantAttrStr = element->getAttribute(aria_activedescendantAttr);
if (activeDescendantAttrStr.isNull() || activeDescendantAttrStr.isEmpty())
return 0;
Element* target = element->treeScope().getElementById(activeDescendantAttrStr);
if (!target)
return 0;
AXObject* obj = axObjectCache()->getOrCreate(target);
if (obj && obj->isAXRenderObject())
return obj;
return 0;
}
void AXRenderObject::accessibilityChildrenFromAttribute(QualifiedName attr, AccessibilityChildrenVector& children) const
{
Vector<Element*> elements;
elementsFromAttribute(elements, attr);
AXObjectCache* cache = axObjectCache();
unsigned count = elements.size();
for (unsigned k = 0; k < count; ++k) {
Element* element = elements[k];
AXObject* child = cache->getOrCreate(element);
if (child)
children.append(child);
}
}
void AXRenderObject::ariaFlowToElements(AccessibilityChildrenVector& flowTo) const
{
accessibilityChildrenFromAttribute(aria_flowtoAttr, flowTo);
}
void AXRenderObject::ariaControlsElements(AccessibilityChildrenVector& controls) const
{
accessibilityChildrenFromAttribute(aria_controlsAttr, controls);
}
void AXRenderObject::ariaDescribedbyElements(AccessibilityChildrenVector& describedby) const
{
accessibilityChildrenFromAttribute(aria_describedbyAttr, describedby);
}
void AXRenderObject::ariaLabelledbyElements(AccessibilityChildrenVector& labelledby) const
{
accessibilityChildrenFromAttribute(aria_labelledbyAttr, labelledby);
}
void AXRenderObject::ariaOwnsElements(AccessibilityChildrenVector& owns) const
{
accessibilityChildrenFromAttribute(aria_ownsAttr, owns);
}
bool AXRenderObject::ariaHasPopup() const
{
return elementAttributeValue(aria_haspopupAttr);
}
bool AXRenderObject::ariaRoleHasPresentationalChildren() const
{
switch (m_ariaRole) {
case ButtonRole:
case SliderRole:
case ImageRole:
case ProgressIndicatorRole:
case SpinButtonRole:
return true;
default:
return false;
}
}
bool AXRenderObject::isPresentationalChildOfAriaRole() const
{
AXObject* parent;
for (parent = parentObject(); parent && !parent->ariaRoleHasPresentationalChildren(); parent = parent->parentObject())
{ }
return parent;
}
bool AXRenderObject::shouldFocusActiveDescendant() const
{
switch (ariaRoleAttribute()) {
case ComboBoxRole:
case GridRole:
case GroupRole:
case ListBoxRole:
case MenuRole:
case MenuBarRole:
case OutlineRole:
case PopUpButtonRole:
case ProgressIndicatorRole:
case RadioGroupRole:
case RowRole:
case TabListRole:
case ToolbarRole:
case TreeRole:
case TreeGridRole:
return true;
default:
return false;
}
}
bool AXRenderObject::supportsARIADragging() const
{
const AtomicString& grabbed = getAttribute(aria_grabbedAttr);
return equalIgnoringCase(grabbed, "true") || equalIgnoringCase(grabbed, "false");
}
bool AXRenderObject::supportsARIADropping() const
{
const AtomicString& dropEffect = getAttribute(aria_dropeffectAttr);
return !dropEffect.isEmpty();
}
bool AXRenderObject::supportsARIAFlowTo() const
{
return !getAttribute(aria_flowtoAttr).isEmpty();
}
bool AXRenderObject::supportsARIAOwns() const
{
if (!m_renderer)
return false;
const AtomicString& ariaOwns = getAttribute(aria_ownsAttr);
return !ariaOwns.isEmpty();
}
const AtomicString& AXRenderObject::ariaLiveRegionStatus() const
{
DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusAssertive, ("assertive", AtomicString::ConstructFromLiteral));
DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusPolite, ("polite", AtomicString::ConstructFromLiteral));
DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusOff, ("off", AtomicString::ConstructFromLiteral));
const AtomicString& liveRegionStatus = getAttribute(aria_liveAttr);
if (liveRegionStatus.isEmpty()) {
switch (roleValue()) {
case AlertDialogRole:
case AlertRole:
return liveRegionStatusAssertive;
case LogRole:
case StatusRole:
return liveRegionStatusPolite;
case TimerRole:
case MarqueeRole:
return liveRegionStatusOff;
default:
break;
}
}
return liveRegionStatus;
}
const AtomicString& AXRenderObject::ariaLiveRegionRelevant() const
{
DEFINE_STATIC_LOCAL(const AtomicString, defaultLiveRegionRelevant, ("additions text", AtomicString::ConstructFromLiteral));
const AtomicString& relevant = getAttribute(aria_relevantAttr);
if (relevant.isEmpty())
return defaultLiveRegionRelevant;
return relevant;
}
bool AXRenderObject::ariaLiveRegionAtomic() const
{
return elementAttributeValue(aria_atomicAttr);
}
bool AXRenderObject::ariaLiveRegionBusy() const
{
return elementAttributeValue(aria_busyAttr);
}
String AXRenderObject::textUnderElement() const
{
if (!m_renderer)
return String();
if (m_renderer->isFileUploadControl())
return toRenderFileUploadControl(m_renderer)->buttonValue();
if (m_renderer->isText())
return toRenderText(m_renderer)->plainText();
return AXNodeObject::textUnderElement();
}
String AXRenderObject::helpText() const
{
if (!m_renderer)
return String();
const AtomicString& ariaHelp = getAttribute(aria_helpAttr);
if (!ariaHelp.isEmpty())
return ariaHelp;
String describedBy = ariaDescribedByAttribute();
if (!describedBy.isEmpty())
return describedBy;
String description = accessibilityDescription();
for (RenderObject* curr = m_renderer; curr; curr = curr->parent()) {
if (curr->node() && curr->node()->isHTMLElement()) {
const AtomicString& summary = toElement(curr->node())->getAttribute(summaryAttr);
if (!summary.isEmpty())
return summary;
const AtomicString& title = toElement(curr->node())->getAttribute(titleAttr);
if (!title.isEmpty() && description != title)
return title;
}
AXObject* axObj = axObjectCache()->getOrCreate(curr);
if (axObj) {
AccessibilityRole role = axObj->roleValue();
if (role != GroupRole && role != UnknownRole)
break;
}
}
return String();
}
void AXRenderObject::checkCachedElementRect() const
{
if (m_cachedElementRectDirty)
return;
if (!m_renderer)
return;
if (!m_renderer->isBox())
return;
bool dirty = false;
RenderBox* box = toRenderBox(m_renderer);
if (box->frameRect() != m_cachedFrameRect)
dirty = true;
if (box->canBeScrolledAndHasScrollableArea()) {
ScrollableArea* scrollableArea = box->scrollableArea();
if (scrollableArea && scrollableArea->scrollPosition() != m_cachedScrollPosition)
dirty = true;
}
if (dirty)
markCachedElementRectDirty();
}
void AXRenderObject::updateCachedElementRect() const
{
if (!m_cachedElementRectDirty)
return;
if (!m_renderer)
return;
if (!m_renderer->isBox())
return;
RenderBox* box = toRenderBox(m_renderer);
m_cachedFrameRect = box->frameRect();
if (box->canBeScrolledAndHasScrollableArea()) {
ScrollableArea* scrollableArea = box->scrollableArea();
if (scrollableArea)
m_cachedScrollPosition = scrollableArea->scrollPosition();
}
m_cachedElementRect = computeElementRect();
m_cachedElementRectDirty = false;
}
void AXRenderObject::markCachedElementRectDirty() const
{
if (m_cachedElementRectDirty)
return;
m_cachedElementRectDirty = true;
for (AXObject* child = firstChild(); child; child = child->nextSibling())
child->markCachedElementRectDirty();
}
IntPoint AXRenderObject::clickPoint()
{
if (isHeading() && children().size() == 1)
return children()[0]->clickPoint();
if (!isWebArea() || isReadOnly())
return AXObject::clickPoint();
LayoutRect bounds = elementRect();
return IntPoint(bounds.x() + (bounds.width() / 2), bounds.y() - (bounds.height() / 2));
}
AXObject* AXRenderObject::accessibilityHitTest(const IntPoint& point) const
{
if (!m_renderer || !m_renderer->hasLayer())
return 0;
RenderLayer* layer = toRenderBox(m_renderer)->layer();
HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
HitTestResult hitTestResult = HitTestResult(point);
layer->hitTest(request, hitTestResult);
if (!hitTestResult.innerNode())
return 0;
Node* node = hitTestResult.innerNode()->deprecatedShadowAncestorNode();
if (isHTMLAreaElement(node))
return accessibilityImageMapHitTest(toHTMLAreaElement(node), point);
if (isHTMLOptionElement(node))
node = toHTMLOptionElement(*node).ownerSelectElement();
RenderObject* obj = node->renderer();
if (!obj)
return 0;
AXObject* result = obj->document().axObjectCache()->getOrCreate(obj);
result->updateChildrenIfNecessary();
result = result->elementAccessibilityHitTest(point);
if (result && result->accessibilityIsIgnored()) {
if (result->isAXRenderObject()) {
AXObject* controlObject = toAXRenderObject(result)->correspondingControlForLabelElement();
if (controlObject && !controlObject->exposesTitleUIElement())
return controlObject;
}
result = result->parentObjectUnignored();
}
return result;
}
AXObject* AXRenderObject::elementAccessibilityHitTest(const IntPoint& point) const
{
if (isSVGImage())
return remoteSVGElementHitTest(point);
return AXObject::elementAccessibilityHitTest(point);
}
AXObject* AXRenderObject::parentObject() const
{
if (!m_renderer)
return 0;
if (ariaRoleAttribute() == MenuBarRole)
return axObjectCache()->getOrCreate(m_renderer->parent());
if (ariaRoleAttribute() == MenuRole) {
AXObject* parent = menuButtonForMenu();
if (parent)
return parent;
}
RenderObject* parentObj = renderParentObject();
if (parentObj)
return axObjectCache()->getOrCreate(parentObj);
if (isWebArea())
return axObjectCache()->getOrCreate(m_renderer->frame()->view());
return 0;
}
AXObject* AXRenderObject::parentObjectIfExists() const
{
if (isWebArea())
return axObjectCache()->get(m_renderer->frame()->view());
return axObjectCache()->get(renderParentObject());
}
AXObject* AXRenderObject::firstChild() const
{
if (!m_renderer)
return 0;
RenderObject* firstChild = firstChildConsideringContinuation(m_renderer);
if (!firstChild)
return 0;
return axObjectCache()->getOrCreate(firstChild);
}
AXObject* AXRenderObject::nextSibling() const
{
if (!m_renderer)
return 0;
RenderObject* nextSibling = 0;
RenderInline* inlineContinuation;
if (m_renderer->isRenderBlock() && (inlineContinuation = toRenderBlock(m_renderer)->inlineElementContinuation())) {
nextSibling = firstChildConsideringContinuation(inlineContinuation);
} else if (m_renderer->isAnonymousBlock() && lastChildHasContinuation(m_renderer)) {
RenderObject* lastParent = endOfContinuations(m_renderer->lastChild())->parent();
while (lastChildHasContinuation(lastParent))
lastParent = endOfContinuations(lastParent->lastChild())->parent();
nextSibling = lastParent->nextSibling();
} else if (RenderObject* ns = m_renderer->nextSibling()) {
nextSibling = ns;
} else if (isInlineWithContinuation(m_renderer)) {
nextSibling = endOfContinuations(m_renderer)->nextSibling();
} else if (isInlineWithContinuation(m_renderer->parent())) {
RenderObject* continuation = toRenderInline(m_renderer->parent())->continuation();
if (continuation->isRenderBlock()) {
nextSibling = continuation;
} else {
nextSibling = firstChildConsideringContinuation(continuation);
}
}
if (!nextSibling)
return 0;
return axObjectCache()->getOrCreate(nextSibling);
}
void AXRenderObject::addChildren()
{
ASSERT(!m_haveChildren);
m_haveChildren = true;
if (!canHaveChildren())
return;
for (RefPtr<AXObject> obj = firstChild(); obj; obj = obj->nextSibling())
addChild(obj.get());
addHiddenChildren();
addAttachmentChildren();
addImageMapChildren();
addTextFieldChildren();
addCanvasChildren();
addRemoteSVGChildren();
addInlineTextBoxChildren();
}
bool AXRenderObject::canHaveChildren() const
{
if (!m_renderer)
return false;
return AXNodeObject::canHaveChildren();
}
void AXRenderObject::updateChildrenIfNecessary()
{
if (needsToUpdateChildren())
clearChildren();
AXObject::updateChildrenIfNecessary();
}
void AXRenderObject::clearChildren()
{
AXObject::clearChildren();
m_childrenDirty = false;
}
AXObject* AXRenderObject::observableObject() const
{
for (RenderObject* renderer = m_renderer; renderer && renderer->node(); renderer = renderer->parent()) {
if (renderObjectIsObservable(renderer))
return axObjectCache()->getOrCreate(renderer);
}
return 0;
}
double AXRenderObject::estimatedLoadingProgress() const
{
if (!m_renderer)
return 0;
if (isLoaded())
return 1.0;
if (LocalFrame* frame = m_renderer->document().frame())
return frame->loader().progress().estimatedProgress();
return 0;
}
Node* AXRenderObject::node() const
{
return m_renderer ? m_renderer->node() : 0;
}
Document* AXRenderObject::document() const
{
if (!m_renderer)
return 0;
return &m_renderer->document();
}
FrameView* AXRenderObject::documentFrameView() const
{
if (!m_renderer)
return 0;
return m_renderer->document().view();
}
Element* AXRenderObject::anchorElement() const
{
if (!m_renderer)
return 0;
AXObjectCache* cache = axObjectCache();
RenderObject* currRenderer;
for (currRenderer = m_renderer; currRenderer && !currRenderer->node(); currRenderer = currRenderer->parent()) {
if (currRenderer->isAnonymousBlock()) {
RenderObject* continuation = toRenderBlock(currRenderer)->continuation();
if (continuation)
return cache->getOrCreate(continuation)->anchorElement();
}
}
if (!currRenderer)
return 0;
Node* node = currRenderer->node();
for ( ; node; node = node->parentNode()) {
if (isHTMLAnchorElement(*node) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
return toElement(node);
}
return 0;
}
Widget* AXRenderObject::widgetForAttachmentView() const
{
if (!isAttachment())
return 0;
return toRenderWidget(m_renderer)->widget();
}
AXObject::PlainTextRange AXRenderObject::selectedTextRange() const
{
if (!isTextControl())
return PlainTextRange();
if (isPasswordField())
return PlainTextRange();
AccessibilityRole ariaRole = ariaRoleAttribute();
if (isNativeTextControl() && ariaRole == UnknownRole && m_renderer->isTextControl()) {
HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
return PlainTextRange(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());
}
if (ariaRole == UnknownRole)
return PlainTextRange();
return ariaSelectedTextRange();
}
VisibleSelection AXRenderObject::selection() const
{
return m_renderer->frame()->selection().selection();
}
void AXRenderObject::setSelectedTextRange(const PlainTextRange& range)
{
if (isNativeTextControl() && m_renderer->isTextControl()) {
HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
textControl->setSelectionRange(range.start, range.start + range.length);
return;
}
Document& document = m_renderer->document();
LocalFrame* frame = document.frame();
if (!frame)
return;
Node* node = m_renderer->node();
frame->selection().setSelection(VisibleSelection(Position(node, range.start, Position::PositionIsOffsetInAnchor),
Position(node, range.start + range.length, Position::PositionIsOffsetInAnchor), DOWNSTREAM));
}
void AXRenderObject::setValue(const String& string)
{
if (!node() || !node()->isElementNode())
return;
if (!m_renderer || !m_renderer->isBoxModelObject())
return;
RenderBoxModelObject* renderer = toRenderBoxModelObject(m_renderer);
if (renderer->isTextField() && isHTMLInputElement(*node()))
toHTMLInputElement(*node()).setValue(string);
else if (renderer->isTextArea() && isHTMLTextAreaElement(*node()))
toHTMLTextAreaElement(*node()).setValue(string);
}
void AXRenderObject::scrollTo(const IntPoint& point) const
{
if (!m_renderer || !m_renderer->isBox())
return;
RenderBox* box = toRenderBox(m_renderer);
if (!box->canBeScrolledAndHasScrollableArea())
return;
box->scrollToOffset(IntSize(point.x(), point.y()));
}
void AXRenderObject::handleActiveDescendantChanged()
{
Element* element = toElement(renderer()->node());
if (!element)
return;
Document& doc = renderer()->document();
if (!doc.frame()->selection().isFocusedAndActive() || doc.focusedElement() != element)
return;
AXRenderObject* activedescendant = toAXRenderObject(activeDescendant());
if (activedescendant && shouldNotifyActiveDescendant())
doc.axObjectCache()->postNotification(m_renderer, AXObjectCache::AXActiveDescendantChanged, true);
}
void AXRenderObject::handleAriaExpandedChanged()
{
AXObject* containerParent = this->parentObject();
while (containerParent) {
bool foundParent = false;
switch (containerParent->roleValue()) {
case TreeRole:
case TreeGridRole:
case GridRole:
case TableRole:
case BrowserRole:
foundParent = true;
break;
default:
break;
}
if (foundParent)
break;
containerParent = containerParent->parentObject();
}
if (containerParent)
axObjectCache()->postNotification(containerParent, document(), AXObjectCache::AXRowCountChanged, true);
if (roleValue() == RowRole || roleValue() == TreeItemRole)
axObjectCache()->postNotification(this, document(), isExpanded() ? AXObjectCache::AXRowExpanded : AXObjectCache::AXRowCollapsed, true);
}
void AXRenderObject::textChanged()
{
if (!m_renderer)
return;
if (AXObjectCache::inlineTextBoxAccessibility() && roleValue() == StaticTextRole)
childrenChanged();
AXNodeObject::textChanged();
}
int AXRenderObject::index(const VisiblePosition& position) const
{
if (position.isNull() || !isTextControl())
return -1;
if (renderObjectContainsPosition(m_renderer, position.deepEquivalent()))
return indexForVisiblePosition(position);
return -1;
}
VisiblePosition AXRenderObject::visiblePositionForIndex(int index) const
{
if (!m_renderer)
return VisiblePosition();
if (isNativeTextControl() && m_renderer->isTextControl())
return toRenderTextControl(m_renderer)->textFormControlElement()->visiblePositionForIndex(index);
if (!allowsTextRanges() && !m_renderer->isText())
return VisiblePosition();
Node* node = m_renderer->node();
if (!node)
return VisiblePosition();
if (index <= 0)
return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
RefPtrWillBeRawPtr<Range> range = Range::create(m_renderer->document());
range->selectNodeContents(node, IGNORE_EXCEPTION);
CharacterIterator it(range.get());
it.advance(index - 1);
return VisiblePosition(Position(it.range()->endContainer(), it.range()->endOffset(), Position::PositionIsOffsetInAnch\
or), UPSTREAM);
}
int AXRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
{
if (isNativeTextControl() && m_renderer->isTextControl()) {
HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
return textControl->indexForVisiblePosition(pos);
}
if (!isTextControl())
return 0;
Node* node = m_renderer->node();
if (!node)
return 0;
Position indexPosition = pos.deepEquivalent();
if (indexPosition.isNull() || highestEditableRoot(indexPosition, HasEditableAXRole) != node)
return 0;
RefPtrWillBeRawPtr<Range> range = Range::create(m_renderer->document());
range->setStart(node, 0, IGNORE_EXCEPTION);
range->setEnd(indexPosition, IGNORE_EXCEPTION);
return TextIterator::rangeLength(range.get());
}
void AXRenderObject::addInlineTextBoxChildren()
{
if (!axObjectCache()->inlineTextBoxAccessibility())
return;
if (!renderer() || !renderer()->isText())
return;
if (renderer()->needsLayout()) {
return;
}
RenderText* renderText = toRenderText(renderer());
for (RefPtr<AbstractInlineTextBox> box = renderText->firstAbstractInlineTextBox(); box.get(); box = box->nextInlineTextBox()) {
AXObject* axObject = axObjectCache()->getOrCreate(box.get());
if (!axObject->accessibilityIsIgnored())
m_children.append(axObject);
}
}
void AXRenderObject::lineBreaks(Vector<int>& lineBreaks) const
{
if (!isTextControl())
return;
VisiblePosition visiblePos = visiblePositionForIndex(0);
VisiblePosition savedVisiblePos = visiblePos;
visiblePos = nextLinePosition(visiblePos, 0);
while (!visiblePos.isNull() && visiblePos != savedVisiblePos) {
lineBreaks.append(indexForVisiblePosition(visiblePos));
savedVisiblePos = visiblePos;
visiblePos = nextLinePosition(visiblePos, 0);
}
}
bool AXRenderObject::isAllowedChildOfTree() const
{
AXObject* axObj = parentObject();
bool isInTree = false;
while (axObj) {
if (axObj->isTree()) {
isInTree = true;
break;
}
axObj = axObj->parentObject();
}
if (isInTree) {
AccessibilityRole role = roleValue();
if (role != TreeItemRole && role != StaticTextRole)
return false;
}
return true;
}
void AXRenderObject::ariaListboxSelectedChildren(AccessibilityChildrenVector& result)
{
bool isMulti = isMultiSelectable();
AccessibilityChildrenVector childObjects = children();
unsigned childrenSize = childObjects.size();
for (unsigned k = 0; k < childrenSize; ++k) {
AXObject* child = childObjects[k].get();
if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRole) {
result.append(child);
if (!isMulti)
return;
}
}
}
AXObject::PlainTextRange AXRenderObject::ariaSelectedTextRange() const
{
Node* node = m_renderer->node();
if (!node)
return PlainTextRange();
VisibleSelection visibleSelection = selection();
RefPtrWillBeRawPtr<Range> currentSelectionRange = visibleSelection.toNormalizedRange();
if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, IGNORE_EXCEPTION))
return PlainTextRange();
int start = indexForVisiblePosition(visibleSelection.visibleStart());
int end = indexForVisiblePosition(visibleSelection.visibleEnd());
return PlainTextRange(start, end - start);
}
bool AXRenderObject::nodeIsTextControl(const Node* node) const
{
if (!node)
return false;
const AXObject* axObjectForNode = axObjectCache()->getOrCreate(const_cast<Node*>(node));
if (!axObjectForNode)
return false;
return axObjectForNode->isTextControl();
}
bool AXRenderObject::isTabItemSelected() const
{
if (!isTabItem() || !m_renderer)
return false;
Node* node = m_renderer->node();
if (!node || !node->isElementNode())
return false;
AXObject* focusedElement = focusedUIElement();
if (!focusedElement)
return false;
Vector<Element*> elements;
elementsFromAttribute(elements, aria_controlsAttr);
unsigned count = elements.size();
for (unsigned k = 0; k < count; ++k) {
Element* element = elements[k];
AXObject* tabPanel = axObjectCache()->getOrCreate(element);
if (!tabPanel || tabPanel->roleValue() != TabPanelRole)
continue;
AXObject* checkFocusElement = focusedElement;
while (checkFocusElement) {
if (tabPanel == checkFocusElement)
return true;
checkFocusElement = checkFocusElement->parentObject();
}
}
return false;
}
AXObject* AXRenderObject::internalLinkElement() const
{
Element* element = anchorElement();
if (!isHTMLAnchorElement(element))
return 0;
HTMLAnchorElement& anchor = toHTMLAnchorElement(*element);
KURL linkURL = anchor.href();
String fragmentIdentifier = linkURL.fragmentIdentifier();
if (fragmentIdentifier.isEmpty())
return 0;
KURL documentURL = m_renderer->document().url();
if (!equalIgnoringFragmentIdentifier(documentURL, linkURL))
return 0;
Node* linkedNode = m_renderer->document().findAnchor(fragmentIdentifier);
if (!linkedNode)
return 0;
return firstAccessibleObjectFromNode(linkedNode);
}
AXObject* AXRenderObject::accessibilityImageMapHitTest(HTMLAreaElement* area, const IntPoint& point) const
{
if (!area)
return 0;
AXObject* parent = axObjectCache()->getOrCreate(area->imageElement());
if (!parent)
return 0;
AXObject::AccessibilityChildrenVector children = parent->children();
unsigned count = children.size();
for (unsigned k = 0; k < count; ++k) {
if (children[k]->elementRect().contains(point))
return children[k].get();
}
return 0;
}
bool AXRenderObject::renderObjectIsObservable(RenderObject* renderer) const
{
if (renderer->isTextControl())
return true;
Node* node = renderer->node();
if (nodeHasRole(node, "listbox") || (renderer->isBoxModelObject() && toRenderBoxModelObject(renderer)->isListBox()))
return true;
if (nodeHasRole(node, "textbox"))
return true;
return false;
}
RenderObject* AXRenderObject::renderParentObject() const
{
if (!m_renderer)
return 0;
RenderObject* parent = m_renderer->parent();
RenderObject* startOfConts = 0;
RenderObject* firstChild = 0;
if (m_renderer->isRenderBlock() && (startOfConts = startOfContinuations(m_renderer))) {
parent = startOfConts;
} else if (parent && parent->isRenderInline() && (startOfConts = startOfContinuations(parent))) {
parent = startOfConts;
} else if (parent && (firstChild = parent->firstChild()) && firstChild->node()) {
RenderObject* nodeRenderFirstChild = firstChild->node()->renderer();
while (nodeRenderFirstChild != firstChild) {
for (RenderObject* contsTest = nodeRenderFirstChild; contsTest; contsTest = nextContinuation(contsTest)) {
if (contsTest == firstChild) {
parent = nodeRenderFirstChild->parent();
break;
}
}
if (firstChild == parent->firstChild())
break;
firstChild = parent->firstChild();
if (!firstChild->node())
break;
nodeRenderFirstChild = firstChild->node()->renderer();
}
}
return parent;
}
bool AXRenderObject::isDescendantOfElementType(const QualifiedName& tagName) const
{
for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
if (parent->node() && parent->node()->hasTagName(tagName))
return true;
}
return false;
}
bool AXRenderObject::isSVGImage() const
{
return remoteSVGRootElement();
}
void AXRenderObject::detachRemoteSVGRoot()
{
if (AXSVGRoot* root = remoteSVGRootElement())
root->setParent(0);
}
AXSVGRoot* AXRenderObject::remoteSVGRootElement() const
{
if (!m_renderer || !m_renderer->isRenderImage())
return 0;
ImageResource* cachedImage = toRenderImage(m_renderer)->cachedImage();
if (!cachedImage)
return 0;
Image* image = cachedImage->image();
if (!image || !image->isSVGImage())
return 0;
FrameView* frameView = toSVGImage(image)->frameView();
if (!frameView)
return 0;
Document* doc = frameView->frame().document();
if (!doc || !doc->isSVGDocument())
return 0;
SVGSVGElement* rootElement = toSVGDocument(doc)->rootElement();
if (!rootElement)
return 0;
RenderObject* rendererRoot = rootElement->renderer();
if (!rendererRoot)
return 0;
AXObject* rootSVGObject = doc->axObjectCache()->getOrCreate(rendererRoot);
ASSERT(rootSVGObject && rootSVGObject->isAXSVGRoot());
if (!rootSVGObject->isAXSVGRoot())
return 0;
return toAXSVGRoot(rootSVGObject);
}
AXObject* AXRenderObject::remoteSVGElementHitTest(const IntPoint& point) const
{
AXObject* remote = remoteSVGRootElement();
if (!remote)
return 0;
IntSize offset = point - roundedIntPoint(elementRect().location());
return remote->accessibilityHitTest(IntPoint(offset));
}
void AXRenderObject::offsetBoundingBoxForRemoteSVGElement(LayoutRect& rect) const
{
for (AXObject* parent = parentObject(); parent; parent = parent->parentObject()) {
if (parent->isAXSVGRoot()) {
rect.moveBy(parent->parentObject()->elementRect().location());
break;
}
}
}
void AXRenderObject::addHiddenChildren()
{
Node* node = this->node();
if (!node)
return;
bool shouldInsertHiddenNodes = false;
for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
if (!child->renderer() && isNodeAriaVisible(child)) {
shouldInsertHiddenNodes = true;
break;
}
}
if (!shouldInsertHiddenNodes)
return;
unsigned insertionIndex = 0;
for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
if (child->renderer()) {
AXObject* childObject = axObjectCache()->get(child->renderer());
if (childObject && childObject->accessibilityIsIgnored()) {
AccessibilityChildrenVector children = childObject->children();
if (children.size())
childObject = children.last().get();
else
childObject = 0;
}
if (childObject)
insertionIndex = m_children.find(childObject) + 1;
continue;
}
if (!isNodeAriaVisible(child))
continue;
unsigned previousSize = m_children.size();
if (insertionIndex > previousSize)
insertionIndex = previousSize;
insertChild(axObjectCache()->getOrCreate(child), insertionIndex);
insertionIndex += (m_children.size() - previousSize);
}
}
void AXRenderObject::addTextFieldChildren()
{
Node* node = this->node();
if (!isHTMLInputElement(node))
return;
HTMLInputElement& input = toHTMLInputElement(*node);
Element* spinButtonElement = input.userAgentShadowRoot()->getElementById(ShadowElementNames::spinButton());
if (!spinButtonElement || !spinButtonElement->isSpinButtonElement())
return;
AXSpinButton* axSpinButton = toAXSpinButton(axObjectCache()->getOrCreate(SpinButtonRole));
axSpinButton->setSpinButtonElement(toSpinButtonElement(spinButtonElement));
axSpinButton->setParent(this);
m_children.append(axSpinButton);
}
void AXRenderObject::addImageMapChildren()
{
RenderBoxModelObject* cssBox = renderBoxModelObject();
if (!cssBox || !cssBox->isRenderImage())
return;
HTMLMapElement* map = toRenderImage(cssBox)->imageMap();
if (!map)
return;
for (HTMLAreaElement* area = Traversal<HTMLAreaElement>::firstWithin(*map); area; area = Traversal<HTMLAreaElement>::next(*area, map)) {
if (area->isLink()) {
AXImageMapLink* areaObject = toAXImageMapLink(axObjectCache()->getOrCreate(ImageMapLinkRole));
areaObject->setHTMLAreaElement(area);
areaObject->setHTMLMapElement(map);
areaObject->setParent(this);
if (!areaObject->accessibilityIsIgnored())
m_children.append(areaObject);
else
axObjectCache()->remove(areaObject->axObjectID());
}
}
}
void AXRenderObject::addCanvasChildren()
{
if (!isHTMLCanvasElement(node()))
return;
ASSERT(!m_children.size());
m_haveChildren = false;
AXNodeObject::addChildren();
}
void AXRenderObject::addAttachmentChildren()
{
if (!isAttachment())
return;
Widget* widget = widgetForAttachmentView();
if (!widget || !widget->isFrameView())
return;
AXObject* axWidget = axObjectCache()->getOrCreate(widget);
if (!axWidget->accessibilityIsIgnored())
m_children.append(axWidget);
}
void AXRenderObject::addRemoteSVGChildren()
{
AXSVGRoot* root = remoteSVGRootElement();
if (!root)
return;
root->setParent(this);
if (root->accessibilityIsIgnored()) {
AccessibilityChildrenVector children = root->children();
unsigned length = children.size();
for (unsigned i = 0; i < length; ++i)
m_children.append(children[i]);
} else {
m_children.append(root);
}
}
void AXRenderObject::ariaSelectedRows(AccessibilityChildrenVector& result)
{
AccessibilityChildrenVector allRows;
if (isTree())
ariaTreeRows(allRows);
else if (isAXTable() && toAXTable(this)->supportsSelectedRows())
allRows = toAXTable(this)->rows();
bool isMulti = isMultiSelectable();
AXObject* activeDesc = activeDescendant();
if (activeDesc && (activeDesc->isTreeItem() || activeDesc->isTableRow())) {
result.append(activeDesc);
if (!isMulti)
return;
}
unsigned count = allRows.size();
for (unsigned k = 0; k < count; ++k) {
if (allRows[k]->isSelected()) {
result.append(allRows[k]);
if (!isMulti)
break;
}
}
}
bool AXRenderObject::elementAttributeValue(const QualifiedName& attributeName) const
{
if (!m_renderer)
return false;
return equalIgnoringCase(getAttribute(attributeName), "true");
}
bool AXRenderObject::inheritsPresentationalRole() const
{
if (canSetFocusAttribute())
return false;
if (roleValue() != ListItemRole && roleValue() != ListMarkerRole)
return false;
AXObject* parent = parentObject();
if (!parent->isAXRenderObject())
return false;
Node* elementNode = toAXRenderObject(parent)->node();
if (!elementNode || !elementNode->isElementNode())
return false;
QualifiedName tagName = toElement(elementNode)->tagQName();
if (tagName == ulTag || tagName == olTag || tagName == dlTag)
return parent->roleValue() == PresentationalRole;
return false;
}
LayoutRect AXRenderObject::computeElementRect() const
{
RenderObject* obj = m_renderer;
if (!obj)
return LayoutRect();
if (obj->node())
obj = obj->node()->renderer();
Vector<FloatQuad> quads;
if (obj->isText())
toRenderText(obj)->absoluteQuads(quads, 0, RenderText::ClipToEllipsis);
else if (isWebArea() || obj->isSVGRoot())
obj->absoluteQuads(quads);
else
obj->absoluteFocusRingQuads(quads);
LayoutRect result = boundingBoxForQuads(obj, quads);
Document* document = this->document();
if (document && document->isSVGDocument())
offsetBoundingBoxForRemoteSVGElement(result);
if (isWebArea() && obj->frame()->view())
result.setSize(obj->frame()->view()->contentsSize());
if (isCheckboxOrRadio()) {
HTMLLabelElement* label = labelForElement(toElement(m_renderer->node()));
if (label && label->renderer()) {
LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementRect();
result.unite(labelRect);
}
}
return result;
}
}