AccessibilityNodeObject.cpp [plain text]
#include "config.h"
#include "AccessibilityNodeObject.h"
#include "AXObjectCache.h"
#include "AccessibilityImageMapLink.h"
#include "AccessibilityList.h"
#include "AccessibilityListBox.h"
#include "AccessibilitySpinButton.h"
#include "AccessibilityTable.h"
#include "Editing.h"
#include "ElementIterator.h"
#include "EventNames.h"
#include "FloatRect.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameSelection.h"
#include "FrameView.h"
#include "HTMLCanvasElement.h"
#include "HTMLDetailsElement.h"
#include "HTMLFieldSetElement.h"
#include "HTMLFormElement.h"
#include "HTMLImageElement.h"
#include "HTMLInputElement.h"
#include "HTMLLabelElement.h"
#include "HTMLLegendElement.h"
#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
#include "HTMLSelectElement.h"
#include "HTMLTextAreaElement.h"
#include "HTMLTextFormControlElement.h"
#include "LabelableElement.h"
#include "LocalizedStrings.h"
#include "MathMLElement.h"
#include "MathMLNames.h"
#include "NodeList.h"
#include "NodeTraversal.h"
#include "ProgressTracker.h"
#include "RenderImage.h"
#include "RenderView.h"
#include "SVGElement.h"
#include "Text.h"
#include "TextControlInnerElements.h"
#include "UserGestureIndicator.h"
#include "VisibleUnits.h"
#include "Widget.h"
#include <wtf/StdLibExtras.h>
#include <wtf/text/StringBuilder.h>
#include <wtf/unicode/CharacterNames.h>
namespace WebCore {
using namespace HTMLNames;
static String accessibleNameForNode(Node* node, Node* labelledbyNode = nullptr);
AccessibilityNodeObject::AccessibilityNodeObject(Node* node)
: AccessibilityObject()
, m_ariaRole(UnknownRole)
, m_roleForMSAA(UnknownRole)
#ifndef NDEBUG
, m_initialized(false)
#endif
, m_node(node)
{
}
AccessibilityNodeObject::~AccessibilityNodeObject()
{
ASSERT(isDetached());
}
void AccessibilityNodeObject::init()
{
#ifndef NDEBUG
ASSERT(!m_initialized);
m_initialized = true;
#endif
m_role = determineAccessibilityRole();
}
Ref<AccessibilityNodeObject> AccessibilityNodeObject::create(Node* node)
{
return adoptRef(*new AccessibilityNodeObject(node));
}
void AccessibilityNodeObject::detach(AccessibilityDetachmentType detachmentType, AXObjectCache* cache)
{
AccessibilityObject::detach(detachmentType, cache);
m_node = nullptr;
}
void AccessibilityNodeObject::childrenChanged()
{
if (!node() && !renderer())
return;
AXObjectCache* cache = axObjectCache();
if (!cache)
return;
cache->postNotification(this, document(), AXObjectCache::AXChildrenChanged);
this->setNeedsToUpdateSubtree();
bool shouldStopUpdatingParent = false;
for (AccessibilityObject* parent = this; parent; parent = parent->parentObjectIfExists()) {
if (!shouldStopUpdatingParent)
parent->setNeedsToUpdateChildren();
if (parent->supportsARIALiveRegion())
cache->postLiveRegionChangeNotification(parent);
if (parent->isNonNativeTextControl()) {
cache->postNotification(parent, parent->document(), AXObjectCache::AXValueChanged);
shouldStopUpdatingParent = true;
}
}
}
void AccessibilityNodeObject::updateAccessibilityRole()
{
bool ignoredStatus = accessibilityIsIgnored();
m_role = determineAccessibilityRole();
if (ignoredStatus != accessibilityIsIgnored())
childrenChanged();
}
AccessibilityObject* AccessibilityNodeObject::firstChild() const
{
if (!node())
return nullptr;
Node* firstChild = node()->firstChild();
if (!firstChild)
return nullptr;
return axObjectCache()->getOrCreate(firstChild);
}
AccessibilityObject* AccessibilityNodeObject::lastChild() const
{
if (!node())
return nullptr;
Node* lastChild = node()->lastChild();
if (!lastChild)
return nullptr;
return axObjectCache()->getOrCreate(lastChild);
}
AccessibilityObject* AccessibilityNodeObject::previousSibling() const
{
if (!node())
return nullptr;
Node* previousSibling = node()->previousSibling();
if (!previousSibling)
return nullptr;
return axObjectCache()->getOrCreate(previousSibling);
}
AccessibilityObject* AccessibilityNodeObject::nextSibling() const
{
if (!node())
return nullptr;
Node* nextSibling = node()->nextSibling();
if (!nextSibling)
return nullptr;
return axObjectCache()->getOrCreate(nextSibling);
}
AccessibilityObject* AccessibilityNodeObject::parentObjectIfExists() const
{
return parentObject();
}
AccessibilityObject* AccessibilityNodeObject::parentObject() const
{
if (!node())
return nullptr;
Node* parentObj = node()->parentNode();
if (!parentObj)
return nullptr;
if (AXObjectCache* cache = axObjectCache())
return cache->getOrCreate(parentObj);
return nullptr;
}
LayoutRect AccessibilityNodeObject::elementRect() const
{
return boundingBoxRect();
}
LayoutRect AccessibilityNodeObject::boundingBoxRect() const
{
LayoutRect boundingBox;
for (AccessibilityObject* positionProvider = parentObject(); positionProvider; positionProvider = positionProvider->parentObject()) {
if (positionProvider->isAccessibilityRenderObject()) {
LayoutRect parentRect = positionProvider->elementRect();
boundingBox.setSize(LayoutSize(parentRect.width(), LayoutUnit(std::min(10.0f, parentRect.height().toFloat()))));
boundingBox.setLocation(parentRect.location());
break;
}
}
return boundingBox;
}
void AccessibilityNodeObject::setNode(Node* node)
{
m_node = node;
}
Document* AccessibilityNodeObject::document() const
{
if (!node())
return nullptr;
return &node()->document();
}
AccessibilityRole AccessibilityNodeObject::determineAccessibilityRole()
{
if (!node())
return UnknownRole;
if ((m_ariaRole = determineAriaRoleAttribute()) != UnknownRole)
return m_ariaRole;
if (node()->isLink())
return WebCoreLinkRole;
if (node()->isTextNode())
return StaticTextRole;
if (node()->hasTagName(buttonTag))
return buttonRoleType();
if (is<HTMLInputElement>(*node())) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node());
if (input.isCheckbox())
return CheckBoxRole;
if (input.isRadioButton())
return RadioButtonRole;
if (input.isTextButton())
return buttonRoleType();
if (input.isRangeControl())
return SliderRole;
if (input.isInputTypeHidden())
return IgnoredRole;
if (input.isSearchField())
return SearchFieldRole;
#if ENABLE(INPUT_TYPE_COLOR)
if (input.isColorControl())
return ColorWellRole;
#endif
return TextFieldRole;
}
if (node()->hasTagName(selectTag)) {
HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*node());
return selectElement.multiple() ? ListBoxRole : PopUpButtonRole;
}
if (is<HTMLTextAreaElement>(*node()))
return TextAreaRole;
if (headingLevel())
return HeadingRole;
if (node()->hasTagName(blockquoteTag))
return BlockquoteRole;
if (node()->hasTagName(divTag))
return DivRole;
if (node()->hasTagName(pTag))
return ParagraphRole;
if (is<HTMLLabelElement>(*node()))
return LabelRole;
if (is<Element>(*node()) && downcast<Element>(*node()).isFocusable())
return GroupRole;
return UnknownRole;
}
void AccessibilityNodeObject::addChildren()
{
ASSERT(!m_haveChildren);
if (!m_node)
return;
m_haveChildren = true;
if (renderer() && !m_node->hasTagName(canvasTag))
return;
for (Node* child = m_node->firstChild(); child; child = child->nextSibling())
addChild(axObjectCache()->getOrCreate(child));
m_subtreeDirty = false;
}
bool AccessibilityNodeObject::canHaveChildren() const
{
if (!node() && !isAccessibilityRenderObject())
return false;
if (node() && !renderer() && node()->hasTagName(noscriptTag))
return false;
switch (roleValue()) {
case ImageRole:
case ButtonRole:
case PopUpButtonRole:
case CheckBoxRole:
case RadioButtonRole:
case TabRole:
case ToggleButtonRole:
case StaticTextRole:
case ListBoxOptionRole:
case ScrollBarRole:
case ProgressIndicatorRole:
case SwitchRole:
return false;
default:
return true;
}
}
bool AccessibilityNodeObject::computeAccessibilityIsIgnored() const
{
#ifndef NDEBUG
ASSERT(m_initialized);
#endif
if (m_node && m_node->isTextNode() && !renderer()) {
if (m_node->parentNode() && m_node->parentNode()->hasTagName(iframeTag) && m_node->parentNode()->renderer())
return true;
String string = stringValue().stripWhiteSpace().simplifyWhiteSpace();
if (!string.length())
return true;
}
AccessibilityObjectInclusion decision = defaultObjectInclusion();
if (decision == IncludeObject)
return false;
if (decision == IgnoreObject)
return true;
if (isDescendantOfBarrenParent())
return true;
if (roleValue() == IgnoredRole)
return true;
return m_role == UnknownRole;
}
bool AccessibilityNodeObject::canvasHasFallbackContent() const
{
Node* node = this->node();
if (!is<HTMLCanvasElement>(node))
return false;
HTMLCanvasElement& canvasElement = downcast<HTMLCanvasElement>(*node);
return childrenOfType<Element>(canvasElement).first();
}
bool AccessibilityNodeObject::isImageButton() const
{
return isNativeImage() && isButton();
}
bool AccessibilityNodeObject::isNativeTextControl() const
{
Node* node = this->node();
if (!node)
return false;
if (is<HTMLTextAreaElement>(*node))
return true;
if (is<HTMLInputElement>(*node)) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node);
return input.isText() || input.isNumberField();
}
return false;
}
bool AccessibilityNodeObject::isSearchField() const
{
Node* node = this->node();
if (!node)
return false;
if (roleValue() == SearchFieldRole)
return true;
if (!is<HTMLInputElement>(*node))
return false;
auto& inputElement = downcast<HTMLInputElement>(*node);
const AtomicString& nameAttribute = getAttribute(nameAttr);
if (nameAttribute.contains("search", false))
return true;
auto* form = inputElement.form();
if (form && (form->name().contains("search", false) || form->action().contains("search", false)))
return true;
return false;
}
bool AccessibilityNodeObject::isNativeImage() const
{
Node* node = this->node();
if (!node)
return false;
if (is<HTMLImageElement>(*node))
return true;
if (node->hasTagName(appletTag) || node->hasTagName(embedTag) || node->hasTagName(objectTag))
return true;
if (is<HTMLInputElement>(*node)) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node);
return input.isImageButton();
}
return false;
}
bool AccessibilityNodeObject::isImage() const
{
return roleValue() == ImageRole;
}
bool AccessibilityNodeObject::isPasswordField() const
{
auto* node = this->node();
if (!is<HTMLInputElement>(node))
return false;
if (ariaRoleAttribute() != UnknownRole)
return false;
return downcast<HTMLInputElement>(*node).isPasswordField();
}
AccessibilityObject* AccessibilityNodeObject::passwordFieldOrContainingPasswordField()
{
Node* node = this->node();
if (!node)
return nullptr;
if (is<HTMLInputElement>(*node) && downcast<HTMLInputElement>(*node).isPasswordField())
return this;
auto* element = node->shadowHost();
if (!is<HTMLInputElement>(element))
return nullptr;
if (auto* cache = axObjectCache())
return cache->getOrCreate(element);
return nullptr;
}
bool AccessibilityNodeObject::isInputImage() const
{
Node* node = this->node();
if (is<HTMLInputElement>(node) && roleValue() == ButtonRole) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node);
return input.isImageButton();
}
return false;
}
bool AccessibilityNodeObject::isProgressIndicator() const
{
return roleValue() == ProgressIndicatorRole;
}
bool AccessibilityNodeObject::isSlider() const
{
return roleValue() == SliderRole;
}
bool AccessibilityNodeObject::isMenuRelated() const
{
switch (roleValue()) {
case MenuRole:
case MenuBarRole:
case MenuButtonRole:
case MenuItemRole:
case MenuItemCheckboxRole:
case MenuItemRadioRole:
return true;
default:
return false;
}
}
bool AccessibilityNodeObject::isMenu() const
{
return roleValue() == MenuRole;
}
bool AccessibilityNodeObject::isMenuBar() const
{
return roleValue() == MenuBarRole;
}
bool AccessibilityNodeObject::isMenuButton() const
{
return roleValue() == MenuButtonRole;
}
bool AccessibilityNodeObject::isMenuItem() const
{
switch (roleValue()) {
case MenuItemRole:
case MenuItemRadioRole:
case MenuItemCheckboxRole:
return true;
default:
return false;
}
}
bool AccessibilityNodeObject::isNativeCheckboxOrRadio() const
{
Node* node = this->node();
if (!is<HTMLInputElement>(node))
return false;
auto& input = downcast<HTMLInputElement>(*node);
return input.isCheckbox() || input.isRadioButton();
}
bool AccessibilityNodeObject::isEnabled() const
{
for (AccessibilityObject* object = const_cast<AccessibilityNodeObject*>(this); object; object = object->parentObject()) {
const AtomicString& disabledStatus = object->getAttribute(aria_disabledAttr);
if (equalLettersIgnoringASCIICase(disabledStatus, "true"))
return false;
if (equalLettersIgnoringASCIICase(disabledStatus, "false"))
break;
}
if (roleValue() == HorizontalRuleRole)
return false;
Node* node = this->node();
if (!is<Element>(node))
return true;
return !downcast<Element>(*node).isDisabledFormControl();
}
bool AccessibilityNodeObject::isIndeterminate() const
{
return equalLettersIgnoringASCIICase(getAttribute(indeterminateAttr), "true");
}
bool AccessibilityNodeObject::isPressed() const
{
if (!isButton())
return false;
Node* node = this->node();
if (!node)
return false;
if (isToggleButton())
return equalLettersIgnoringASCIICase(getAttribute(aria_pressedAttr), "true");
if (!is<Element>(*node))
return false;
return downcast<Element>(*node).active();
}
bool AccessibilityNodeObject::isChecked() const
{
Node* node = this->node();
if (!node)
return false;
if (is<HTMLInputElement>(*node))
return downcast<HTMLInputElement>(*node).shouldAppearChecked();
bool validRole = false;
switch (ariaRoleAttribute()) {
case RadioButtonRole:
case CheckBoxRole:
case MenuItemRole:
case MenuItemCheckboxRole:
case MenuItemRadioRole:
case SwitchRole:
validRole = true;
break;
default:
break;
}
if (validRole && equalLettersIgnoringASCIICase(getAttribute(aria_checkedAttr), "true"))
return true;
return false;
}
bool AccessibilityNodeObject::isHovered() const
{
Node* node = this->node();
return is<Element>(node) && downcast<Element>(*node).hovered();
}
bool AccessibilityNodeObject::isMultiSelectable() const
{
const AtomicString& ariaMultiSelectable = getAttribute(aria_multiselectableAttr);
if (equalLettersIgnoringASCIICase(ariaMultiSelectable, "true"))
return true;
if (equalLettersIgnoringASCIICase(ariaMultiSelectable, "false"))
return false;
return node() && node()->hasTagName(selectTag) && downcast<HTMLSelectElement>(*node()).multiple();
}
bool AccessibilityNodeObject::isRequired() const
{
const AtomicString& requiredValue = getAttribute(aria_requiredAttr);
if (equalLettersIgnoringASCIICase(requiredValue, "true"))
return true;
if (equalLettersIgnoringASCIICase(requiredValue, "false"))
return false;
Node* n = this->node();
if (is<HTMLFormControlElement>(n))
return downcast<HTMLFormControlElement>(*n).isRequired();
return false;
}
bool AccessibilityNodeObject::supportsRequiredAttribute() const
{
switch (roleValue()) {
case ButtonRole:
return isFileUploadButton();
case CellRole:
case ColumnHeaderRole:
case CheckBoxRole:
case ComboBoxRole:
case GridRole:
case GridCellRole:
case IncrementorRole:
case ListBoxRole:
case PopUpButtonRole:
case RadioButtonRole:
case RadioGroupRole:
case RowHeaderRole:
case SliderRole:
case SpinButtonRole:
case TableHeaderContainerRole:
case TextAreaRole:
case TextFieldRole:
case ToggleButtonRole:
return true;
default:
return false;
}
}
int AccessibilityNodeObject::headingLevel() const
{
Node* node = this->node();
if (!node)
return false;
if (isHeading()) {
int ariaLevel = getAttribute(aria_levelAttr).toInt();
if (ariaLevel > 0)
return ariaLevel;
}
if (node->hasTagName(h1Tag))
return 1;
if (node->hasTagName(h2Tag))
return 2;
if (node->hasTagName(h3Tag))
return 3;
if (node->hasTagName(h4Tag))
return 4;
if (node->hasTagName(h5Tag))
return 5;
if (node->hasTagName(h6Tag))
return 6;
if (ariaRoleAttribute() == HeadingRole)
return 2;
return 0;
}
String AccessibilityNodeObject::valueDescription() const
{
if (!isRangeControl())
return String();
return getAttribute(aria_valuetextAttr).string();
}
float AccessibilityNodeObject::valueForRange() const
{
if (is<HTMLInputElement>(node())) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node());
if (input.isRangeControl())
return input.valueAsNumber();
}
if (!isRangeControl())
return 0.0f;
auto& value = getAttribute(aria_valuenowAttr);
if (!value.isEmpty())
return value.toFloat();
return isSpinButton() ? 0 : (minValueForRange() + maxValueForRange()) / 2;
}
float AccessibilityNodeObject::maxValueForRange() const
{
if (is<HTMLInputElement>(node())) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node());
if (input.isRangeControl())
return input.maximum();
}
if (!isRangeControl())
return 0.0f;
auto& value = getAttribute(aria_valuemaxAttr);
if (!value.isEmpty())
return value.toFloat();
return isSpinButton() ? std::numeric_limits<float>::max() : 100.0f;
}
float AccessibilityNodeObject::minValueForRange() const
{
if (is<HTMLInputElement>(node())) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node());
if (input.isRangeControl())
return input.minimum();
}
if (!isRangeControl())
return 0.0f;
auto& value = getAttribute(aria_valueminAttr);
if (!value.isEmpty())
return value.toFloat();
return isSpinButton() ? -std::numeric_limits<float>::max() : 0.0f;
}
float AccessibilityNodeObject::stepValueForRange() const
{
return getAttribute(stepAttr).toFloat();
}
bool AccessibilityNodeObject::isHeading() const
{
return roleValue() == HeadingRole;
}
bool AccessibilityNodeObject::isLink() const
{
return roleValue() == WebCoreLinkRole;
}
bool AccessibilityNodeObject::isControl() const
{
Node* node = this->node();
if (!node)
return false;
return is<HTMLFormControlElement>(*node) || AccessibilityObject::isARIAControl(ariaRoleAttribute());
}
bool AccessibilityNodeObject::isFieldset() const
{
Node* node = this->node();
if (!node)
return false;
return node->hasTagName(fieldsetTag);
}
bool AccessibilityNodeObject::isGroup() const
{
AccessibilityRole role = roleValue();
return role == GroupRole || role == TextGroupRole || role == ApplicationGroupRole || role == ApplicationTextGroupRole;
}
AccessibilityObject* AccessibilityNodeObject::selectedRadioButton()
{
if (!isRadioGroup())
return nullptr;
for (const auto& child : children()) {
if (child->roleValue() == RadioButtonRole && child->checkboxOrRadioValue() == ButtonStateOn)
return child.get();
}
return nullptr;
}
AccessibilityObject* AccessibilityNodeObject::selectedTabItem()
{
if (!isTabList())
return nullptr;
AccessibilityObject::AccessibilityChildrenVector tabs;
tabChildren(tabs);
for (const auto& child : children()) {
if (child->isTabItem() && (child->isChecked() || child->isSelected()))
return child.get();
}
return nullptr;
}
AccessibilityButtonState AccessibilityNodeObject::checkboxOrRadioValue() const
{
if (isNativeCheckboxOrRadio())
return isIndeterminate() ? ButtonStateMixed : isChecked() ? ButtonStateOn : ButtonStateOff;
return AccessibilityObject::checkboxOrRadioValue();
}
Element* AccessibilityNodeObject::anchorElement() const
{
Node* node = this->node();
if (!node)
return nullptr;
AXObjectCache* cache = axObjectCache();
for ( ; node; node = node->parentNode()) {
if (is<HTMLAnchorElement>(*node) || (node->renderer() && cache->getOrCreate(node->renderer())->isLink()))
return downcast<Element>(node);
}
return nullptr;
}
static bool isNodeActionElement(Node* node)
{
if (is<HTMLInputElement>(*node)) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node);
if (!input.isDisabledFormControl() && (input.isRadioButton() || input.isCheckbox() || input.isTextButton() || input.isFileUpload() || input.isImageButton()))
return true;
} else if (node->hasTagName(buttonTag) || node->hasTagName(selectTag))
return true;
return false;
}
static Element* nativeActionElement(Node* start)
{
if (!start)
return nullptr;
for (Node* child = start->firstChild(); child; child = child->nextSibling()) {
if (isNodeActionElement(child))
return downcast<Element>(child);
if (Element* subChild = nativeActionElement(child))
return subChild;
}
return nullptr;
}
Element* AccessibilityNodeObject::actionElement() const
{
Node* node = this->node();
if (!node)
return nullptr;
if (isNodeActionElement(node))
return downcast<Element>(node);
if (AccessibilityObject::isARIAInput(ariaRoleAttribute()))
return downcast<Element>(node);
switch (roleValue()) {
case ButtonRole:
case PopUpButtonRole:
case ToggleButtonRole:
case TabRole:
case MenuItemRole:
case MenuItemCheckboxRole:
case MenuItemRadioRole:
case ListItemRole:
if (Element* nativeElement = nativeActionElement(node))
return nativeElement;
return downcast<Element>(node);
default:
break;
}
Element* elt = anchorElement();
if (!elt)
elt = mouseButtonListener();
return elt;
}
Element* AccessibilityNodeObject::mouseButtonListener(MouseButtonListenerResultFilter filter) const
{
Node* node = this->node();
if (!node)
return nullptr;
for (auto& element : elementLineage(is<Element>(*node) ? downcast<Element>(node) : node->parentElement())) {
if (element.hasTagName(bodyTag) && isStaticText() && filter == ExcludeBodyElement)
break;
if (element.hasEventListeners(eventNames().clickEvent) || element.hasEventListeners(eventNames().mousedownEvent) || element.hasEventListeners(eventNames().mouseupEvent))
return &element;
}
return nullptr;
}
bool AccessibilityNodeObject::isDescendantOfBarrenParent() const
{
if (!m_isIgnoredFromParentData.isNull())
return m_isIgnoredFromParentData.isDescendantOfBarrenParent;
for (AccessibilityObject* object = parentObject(); object; object = object->parentObject()) {
if (!object->canHaveChildren())
return true;
}
return false;
}
void AccessibilityNodeObject::alterSliderValue(bool increase)
{
if (roleValue() != SliderRole)
return;
if (!getAttribute(stepAttr).isEmpty())
changeValueByStep(increase);
else
changeValueByPercent(increase ? 5 : -5);
}
void AccessibilityNodeObject::increment()
{
UserGestureIndicator gestureIndicator(ProcessingUserGesture, document());
alterSliderValue(true);
}
void AccessibilityNodeObject::decrement()
{
UserGestureIndicator gestureIndicator(ProcessingUserGesture, document());
alterSliderValue(false);
}
void AccessibilityNodeObject::changeValueByStep(bool increase)
{
float step = stepValueForRange();
float value = valueForRange();
value += increase ? step : -step;
setValue(String::number(value));
axObjectCache()->postNotification(node(), AXObjectCache::AXValueChanged);
}
void AccessibilityNodeObject::changeValueByPercent(float percentChange)
{
float range = maxValueForRange() - minValueForRange();
float step = range * (percentChange / 100);
float value = valueForRange();
if (fabs(step) < 1)
step = fabs(percentChange) * (1 / percentChange);
value += step;
setValue(String::number(value));
axObjectCache()->postNotification(node(), AXObjectCache::AXValueChanged);
}
bool AccessibilityNodeObject::isGenericFocusableElement() const
{
if (!canSetFocusAttribute())
return false;
if (isControl())
return false;
AccessibilityRole role = roleValue();
if (role == VideoRole || role == AudioRole)
return false;
if (m_ariaRole != UnknownRole)
return false;
if (hasContentEditableAttributeSet())
return false;
if (role == WebAreaRole)
return false;
if (node() && node()->hasTagName(bodyTag))
return false;
if (role == SVGRootRole)
return false;
return true;
}
HTMLLabelElement* AccessibilityNodeObject::labelForElement(Element* element) const
{
if (!is<HTMLElement>(*element) || !downcast<HTMLElement>(*element).isLabelable())
return nullptr;
const AtomicString& id = element->getIdAttribute();
if (!id.isEmpty()) {
if (HTMLLabelElement* label = element->treeScope().labelElementForId(id))
return label;
}
return ancestorsOfType<HTMLLabelElement>(*element).first();
}
String AccessibilityNodeObject::ariaAccessibilityDescription() const
{
String ariaLabeledBy = ariaLabeledByAttribute();
if (!ariaLabeledBy.isEmpty())
return ariaLabeledBy;
const AtomicString& ariaLabel = getAttribute(aria_labelAttr);
if (!ariaLabel.isEmpty())
return ariaLabel;
return String();
}
static Element* siblingWithAriaRole(Node* node, const char* role)
{
ContainerNode* parent = node->parentNode();
if (!parent)
return nullptr;
for (auto& sibling : childrenOfType<Element>(*parent)) {
if (equalIgnoringASCIICase(sibling.attributeWithoutSynchronization(roleAttr), role))
return &sibling;
}
return nullptr;
}
Element* AccessibilityNodeObject::menuElementForMenuButton() const
{
if (ariaRoleAttribute() != MenuButtonRole)
return nullptr;
return siblingWithAriaRole(node(), "menu");
}
AccessibilityObject* AccessibilityNodeObject::menuForMenuButton() const
{
if (AXObjectCache* cache = axObjectCache())
return cache->getOrCreate(menuElementForMenuButton());
return nullptr;
}
Element* AccessibilityNodeObject::menuItemElementForMenu() const
{
if (ariaRoleAttribute() != MenuRole)
return nullptr;
return siblingWithAriaRole(node(), "menuitem");
}
AccessibilityObject* AccessibilityNodeObject::menuButtonForMenu() const
{
AXObjectCache* cache = axObjectCache();
if (!cache)
return nullptr;
Element* menuItem = menuItemElementForMenu();
if (menuItem) {
AccessibilityObject* menuItemAX = cache->getOrCreate(menuItem);
if (menuItemAX && menuItemAX->isMenuButton())
return menuItemAX;
}
return nullptr;
}
AccessibilityObject* AccessibilityNodeObject::captionForFigure() const
{
if (!isFigureElement())
return nullptr;
AXObjectCache* cache = axObjectCache();
if (!cache)
return nullptr;
Node* node = this->node();
for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
if (child->hasTagName(figcaptionTag))
return cache->getOrCreate(child);
}
return nullptr;
}
bool AccessibilityNodeObject::usesAltTagForTextComputation() const
{
return isImage() || isInputImage() || isNativeImage() || isCanvas() || (node() && node()->hasTagName(imgTag));
}
bool AccessibilityNodeObject::isLabelable() const
{
Node* node = this->node();
if (!node)
return false;
return is<HTMLInputElement>(*node) || AccessibilityObject::isARIAInput(ariaRoleAttribute()) || isControl() || isProgressIndicator() || isMeter();
}
String AccessibilityNodeObject::textForLabelElement(Element* element) const
{
String result = String();
if (!is<HTMLLabelElement>(*element))
return result;
HTMLLabelElement* label = downcast<HTMLLabelElement>(element);
if (AccessibilityObject* labelObject = axObjectCache()->getOrCreate(label))
result = labelObject->ariaLabeledByAttribute();
if (result.isEmpty())
result = label->attributeWithoutSynchronization(aria_labelAttr);
return !result.isEmpty() ? result : label->innerText();
}
void AccessibilityNodeObject::titleElementText(Vector<AccessibilityText>& textOrder) const
{
Node* node = this->node();
if (!node)
return;
if (isLabelable()) {
if (HTMLLabelElement* label = labelForElement(downcast<Element>(node))) {
AccessibilityObject* labelObject = axObjectCache()->getOrCreate(label);
String innerText = textForLabelElement(label);
if (!innerText.isEmpty() && !ariaAccessibilityDescription())
textOrder.append(AccessibilityText(innerText, isMeter() ? AlternativeText : LabelByElementText, labelObject));
return;
}
}
AccessibilityObject* titleUIElement = this->titleUIElement();
if (titleUIElement)
textOrder.append(AccessibilityText(String(), LabelByElementText, titleUIElement));
}
void AccessibilityNodeObject::alternativeText(Vector<AccessibilityText>& textOrder) const
{
if (isWebArea()) {
String webAreaText = alternativeTextForWebArea();
if (!webAreaText.isEmpty())
textOrder.append(AccessibilityText(webAreaText, AlternativeText));
return;
}
ariaLabeledByText(textOrder);
const AtomicString& ariaLabel = getAttribute(aria_labelAttr);
if (!ariaLabel.isEmpty())
textOrder.append(AccessibilityText(ariaLabel, AlternativeText));
if (usesAltTagForTextComputation()) {
if (is<RenderImage>(renderer())) {
String renderAltText = downcast<RenderImage>(*renderer()).altText();
if (!renderAltText.isEmpty() && renderAltText != getAttribute(titleAttr)) {
textOrder.append(AccessibilityText(renderAltText, AlternativeText));
return;
}
}
const AtomicString& alt = getAttribute(altAttr);
if (!alt.isEmpty())
textOrder.append(AccessibilityText(alt, AlternativeText));
}
Node* node = this->node();
if (!node)
return;
if (is<HTMLFieldSetElement>(*node)) {
AccessibilityObject* object = axObjectCache()->getOrCreate(downcast<HTMLFieldSetElement>(*node).legend());
if (object && !object->isHidden())
textOrder.append(AccessibilityText(accessibleNameForNode(object->node()), AlternativeText));
}
if (isFigureElement()) {
AccessibilityObject* captionForFigure = this->captionForFigure();
if (captionForFigure && !captionForFigure->isHidden())
textOrder.append(AccessibilityText(accessibleNameForNode(captionForFigure->node()), AlternativeText));
}
if (isTreeItem() && ariaLabel.isEmpty() && ariaLabeledByAttribute().isEmpty())
textOrder.append(AccessibilityText(accessibleNameForNode(node), AlternativeText));
#if ENABLE(MATHML)
if (node->isMathMLElement())
textOrder.append(AccessibilityText(getAttribute(MathMLNames::alttextAttr), AlternativeText));
#endif
}
void AccessibilityNodeObject::visibleText(Vector<AccessibilityText>& textOrder) const
{
Node* node = this->node();
if (!node)
return;
bool isInputTag = is<HTMLInputElement>(*node);
if (isInputTag) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node);
if (input.isTextButton()) {
textOrder.append(AccessibilityText(input.valueWithDefault(), VisibleText));
return;
}
}
if (!isAccessibilityRenderObject() && node->hasTagName(selectTag))
return;
bool useTextUnderElement = false;
switch (roleValue()) {
case PopUpButtonRole:
if (node->hasTagName(selectTag))
break;
FALLTHROUGH;
case ButtonRole:
case ToggleButtonRole:
case CheckBoxRole:
case ListBoxOptionRole:
#if !PLATFORM(COCOA)
case ListItemRole:
#endif
case MenuButtonRole:
case MenuItemRole:
case MenuItemCheckboxRole:
case MenuItemRadioRole:
case RadioButtonRole:
case SwitchRole:
case TabRole:
useTextUnderElement = true;
break;
default:
break;
}
if (isHeading() || isLink())
useTextUnderElement = true;
if (isOutput())
useTextUnderElement = true;
if (useTextUnderElement) {
AccessibilityTextUnderElementMode mode;
if (isHeading())
mode.includeFocusableContent = true;
String text = textUnderElement(mode);
if (!text.isEmpty())
textOrder.append(AccessibilityText(text, ChildrenText));
}
}
void AccessibilityNodeObject::helpText(Vector<AccessibilityText>& textOrder) const
{
const AtomicString& ariaHelp = getAttribute(aria_helpAttr);
if (!ariaHelp.isEmpty())
textOrder.append(AccessibilityText(ariaHelp, HelpText));
String describedBy = ariaDescribedByAttribute();
if (!describedBy.isEmpty())
textOrder.append(AccessibilityText(describedBy, SummaryText));
const AtomicString& summary = getAttribute(summaryAttr);
if (!summary.isEmpty())
textOrder.append(AccessibilityText(summary, SummaryText));
const AtomicString& title = getAttribute(titleAttr);
if (!title.isEmpty()) {
if (!isMeter())
textOrder.append(AccessibilityText(title, TitleTagText));
else
textOrder.append(AccessibilityText(title, HelpText));
}
}
void AccessibilityNodeObject::accessibilityText(Vector<AccessibilityText>& textOrder)
{
titleElementText(textOrder);
alternativeText(textOrder);
visibleText(textOrder);
helpText(textOrder);
String placeholder = placeholderValue();
if (!placeholder.isEmpty())
textOrder.append(AccessibilityText(placeholder, PlaceholderText));
}
void AccessibilityNodeObject::ariaLabeledByText(Vector<AccessibilityText>& textOrder) const
{
String ariaLabeledBy = ariaLabeledByAttribute();
if (!ariaLabeledBy.isEmpty()) {
Vector<Element*> elements;
ariaLabeledByElements(elements);
Vector<RefPtr<AccessibilityObject>> axElements;
for (const auto& element : elements) {
RefPtr<AccessibilityObject> axElement = axObjectCache()->getOrCreate(element);
axElements.append(axElement);
}
textOrder.append(AccessibilityText(ariaLabeledBy, AlternativeText, WTFMove(axElements)));
}
}
String AccessibilityNodeObject::alternativeTextForWebArea() const
{
Document* document = this->document();
if (!document)
return String();
if (Element* documentElement = document->documentElement()) {
const AtomicString& ariaLabel = documentElement->attributeWithoutSynchronization(aria_labelAttr);
if (!ariaLabel.isEmpty())
return ariaLabel;
}
if (auto* owner = document->ownerElement()) {
if (owner->hasTagName(frameTag) || owner->hasTagName(iframeTag)) {
const AtomicString& title = owner->attributeWithoutSynchronization(titleAttr);
if (!title.isEmpty())
return title;
}
return owner->getNameAttribute();
}
String documentTitle = document->title();
if (!documentTitle.isEmpty())
return documentTitle;
if (auto* body = document->bodyOrFrameset())
return body->getNameAttribute();
return String();
}
String AccessibilityNodeObject::accessibilityDescription() const
{
if (roleValue() == StaticTextRole)
return String();
String ariaDescription = ariaAccessibilityDescription();
if (!ariaDescription.isEmpty())
return ariaDescription;
if (usesAltTagForTextComputation()) {
const AtomicString& alt = getAttribute(altAttr);
if (!alt.isNull())
return alt;
}
#if ENABLE(MATHML)
if (is<MathMLElement>(m_node))
return getAttribute(MathMLNames::alttextAttr);
#endif
if (title().isEmpty())
return getAttribute(titleAttr);
return String();
}
String AccessibilityNodeObject::helpText() const
{
Node* node = this->node();
if (!node)
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 (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
if (is<HTMLElement>(*ancestor)) {
HTMLElement& element = downcast<HTMLElement>(*ancestor);
const AtomicString& summary = element.getAttribute(summaryAttr);
if (!summary.isEmpty())
return summary;
const AtomicString& title = element.getAttribute(titleAttr);
if (!title.isEmpty() && description != title)
return title;
}
if (AccessibilityObject* axObj = axObjectCache()->getOrCreate(ancestor)) {
if (!axObj->isGroup() && axObj->roleValue() != UnknownRole)
break;
}
}
return String();
}
unsigned AccessibilityNodeObject::hierarchicalLevel() const
{
Node* node = this->node();
if (!is<Element>(node))
return 0;
Element& element = downcast<Element>(*node);
const AtomicString& ariaLevel = element.attributeWithoutSynchronization(aria_levelAttr);
if (!ariaLevel.isEmpty())
return ariaLevel.toInt();
if (roleValue() != TreeItemRole)
return 0;
unsigned level = 1;
for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
AccessibilityRole parentRole = parent->ariaRoleAttribute();
if (parentRole == ApplicationGroupRole)
level++;
else if (parentRole == TreeRole)
break;
}
return level;
}
void AccessibilityNodeObject::setIsExpanded(bool expand)
{
if (is<HTMLDetailsElement>(node())) {
auto& details = downcast<HTMLDetailsElement>(*node());
if (expand != details.isOpen())
details.toggleOpen();
}
}
static bool shouldUseAccessibilityObjectInnerText(AccessibilityObject* obj, AccessibilityTextUnderElementMode mode)
{
if (mode.childrenInclusion == AccessibilityTextUnderElementMode::TextUnderElementModeIncludeAllChildren)
return true;
if (mode.childrenInclusion == AccessibilityTextUnderElementMode::TextUnderElementModeIncludeNameFromContentsChildren
&& !obj->accessibleNameDerivesFromContent())
return false;
if (equalLettersIgnoringASCIICase(obj->getAttribute(aria_hiddenAttr), "true"))
return false;
if (obj->isDescendantOfBarrenParent())
return true;
if (obj->canSetFocusAttribute() && !mode.includeFocusableContent)
return false;
if (is<AccessibilityList>(*obj))
return false;
if (is<AccessibilityTable>(*obj) && downcast<AccessibilityTable>(*obj).isExposableThroughAccessibility())
return false;
if (obj->isTree() || obj->isCanvas())
return false;
return true;
}
static bool shouldAddSpaceBeforeAppendingNextElement(StringBuilder& builder, const String& childText)
{
if (!builder.length() || !childText.length())
return false;
return !(isHTMLLineBreak(childText[0]) || isHTMLLineBreak(builder[builder.length() - 1]));
}
static void appendNameToStringBuilder(StringBuilder& builder, const String& text)
{
if (shouldAddSpaceBeforeAppendingNextElement(builder, text))
builder.append(' ');
builder.append(text);
}
String AccessibilityNodeObject::textUnderElement(AccessibilityTextUnderElementMode mode) const
{
Node* node = this->node();
if (is<Text>(node))
return downcast<Text>(*node).wholeText();
StringBuilder builder;
for (AccessibilityObject* child = firstChild(); child; child = child->nextSibling()) {
if (mode.ignoredChildNode && child->node() == mode.ignoredChildNode)
continue;
bool shouldDeriveNameFromAuthor = (mode.childrenInclusion == AccessibilityTextUnderElementMode::TextUnderElementModeIncludeNameFromContentsChildren && !child->accessibleNameDerivesFromContent());
if (shouldDeriveNameFromAuthor) {
appendNameToStringBuilder(builder, accessibleNameForNode(child->node()));
continue;
}
if (!shouldUseAccessibilityObjectInnerText(child, mode))
continue;
if (is<AccessibilityNodeObject>(*child)) {
Vector<Element*> labeledByElements;
downcast<AccessibilityNodeObject>(*child).ariaLabeledByElements(labeledByElements);
if (labeledByElements.contains(node))
continue;
Vector<AccessibilityText> textOrder;
downcast<AccessibilityNodeObject>(*child).alternativeText(textOrder);
if (textOrder.size() > 0 && textOrder[0].text.length()) {
appendNameToStringBuilder(builder, textOrder[0].text);
continue;
}
}
String childText = child->textUnderElement(mode);
if (childText.length())
appendNameToStringBuilder(builder, childText);
}
return builder.toString().stripWhiteSpace().simplifyWhiteSpace(isHTMLSpaceButNotLineBreak);
}
String AccessibilityNodeObject::title() const
{
Node* node = this->node();
if (!node)
return String();
bool isInputTag = is<HTMLInputElement>(*node);
if (isInputTag) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node);
if (input.isTextButton())
return input.valueWithDefault();
}
if (isLabelable()) {
HTMLLabelElement* label = labelForElement(downcast<Element>(node));
if (label && !exposesTitleUIElement() && !ariaAccessibilityDescription().length())
return textForLabelElement(label);
}
if (!isAccessibilityRenderObject() && node->hasTagName(selectTag))
return String();
switch (roleValue()) {
case PopUpButtonRole:
if (node->hasTagName(selectTag))
return String();
FALLTHROUGH;
case ButtonRole:
case ToggleButtonRole:
case CheckBoxRole:
case ListBoxOptionRole:
case ListItemRole:
case MenuButtonRole:
case MenuItemRole:
case MenuItemCheckboxRole:
case MenuItemRadioRole:
case RadioButtonRole:
case SwitchRole:
case TabRole:
return textUnderElement();
case SVGRootRole:
return String();
default:
break;
}
if (isLink())
return textUnderElement();
if (isHeading())
return textUnderElement(AccessibilityTextUnderElementMode(AccessibilityTextUnderElementMode::TextUnderElementModeSkipIgnoredChildren, true));
return String();
}
String AccessibilityNodeObject::text() const
{
if (ariaRoleAttribute() == StaticTextRole) {
Vector<AccessibilityText> textOrder;
alternativeText(textOrder);
if (textOrder.size() > 0 && textOrder[0].text.length())
return textOrder[0].text;
}
if (!isTextControl())
return String();
Node* node = this->node();
if (!node)
return String();
if (isNativeTextControl() && is<HTMLTextFormControlElement>(*node))
return downcast<HTMLTextFormControlElement>(*node).value();
if (!node->isElementNode())
return String();
return downcast<Element>(node)->innerText();
}
String AccessibilityNodeObject::stringValue() const
{
Node* node = this->node();
if (!node)
return String();
if (ariaRoleAttribute() == StaticTextRole) {
String staticText = text();
if (!staticText.length())
staticText = textUnderElement();
return staticText;
}
if (node->isTextNode())
return textUnderElement();
if (node->hasTagName(selectTag)) {
HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*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]->attributeWithoutSynchronization(aria_labelAttr);
if (!overriddenDescription.isNull())
return overriddenDescription;
}
if (!selectElement.multiple())
return selectElement.value();
return String();
}
if (isTextControl())
return text();
return String();
}
void AccessibilityNodeObject::colorValue(int& r, int& g, int& b) const
{
r = 0;
g = 0;
b = 0;
#if ENABLE(INPUT_TYPE_COLOR)
if (!isColorWell())
return;
if (!is<HTMLInputElement>(node()))
return;
auto& input = downcast<HTMLInputElement>(*node());
if (!input.isColorControl())
return;
Color color(input.value());
r = color.red();
g = color.green();
b = color.blue();
#endif
}
static String accessibleNameForNode(Node* node, Node* labelledbyNode)
{
ASSERT(node);
if (!is<Element>(node))
return String();
Element& element = downcast<Element>(*node);
const AtomicString& ariaLabel = element.attributeWithoutSynchronization(aria_labelAttr);
if (!ariaLabel.isEmpty())
return ariaLabel;
const AtomicString& alt = element.attributeWithoutSynchronization(altAttr);
if (!alt.isEmpty())
return alt;
AccessibilityObject* axObject = node->document().axObjectCache()->getOrCreate(node);
if (axObject) {
String valueDescription = axObject->valueDescription();
if (!valueDescription.isEmpty())
return valueDescription;
}
if (is<HTMLInputElement>(*node))
return downcast<HTMLInputElement>(*node).value();
String text;
if (axObject) {
if (axObject->accessibleNameDerivesFromContent())
text = axObject->textUnderElement(AccessibilityTextUnderElementMode(AccessibilityTextUnderElementMode::TextUnderElementModeIncludeNameFromContentsChildren, true, labelledbyNode));
} else
text = element.innerText();
if (!text.isEmpty())
return text;
const AtomicString& title = element.attributeWithoutSynchronization(titleAttr);
if (!title.isEmpty())
return title;
return String();
}
String AccessibilityNodeObject::accessibilityDescriptionForChildren() const
{
Node* node = this->node();
if (!node)
return String();
AXObjectCache* cache = axObjectCache();
if (!cache)
return String();
StringBuilder builder;
for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
if (!is<Element>(child))
continue;
if (AccessibilityObject* axObject = cache->getOrCreate(child)) {
String description = axObject->ariaLabeledByAttribute();
if (description.isEmpty())
description = accessibleNameForNode(child);
appendNameToStringBuilder(builder, description);
}
}
return builder.toString();
}
String AccessibilityNodeObject::accessibilityDescriptionForElements(Vector<Element*> &elements) const
{
StringBuilder builder;
unsigned size = elements.size();
for (unsigned i = 0; i < size; ++i)
appendNameToStringBuilder(builder, accessibleNameForNode(elements[i], node()));
return builder.toString();
}
String AccessibilityNodeObject::ariaDescribedByAttribute() const
{
Vector<Element*> elements;
elementsFromAttribute(elements, aria_describedbyAttr);
return accessibilityDescriptionForElements(elements);
}
void AccessibilityNodeObject::ariaLabeledByElements(Vector<Element*>& elements) const
{
elementsFromAttribute(elements, aria_labelledbyAttr);
if (!elements.size())
elementsFromAttribute(elements, aria_labeledbyAttr);
}
String AccessibilityNodeObject::ariaLabeledByAttribute() const
{
Vector<Element*> elements;
ariaLabeledByElements(elements);
return accessibilityDescriptionForElements(elements);
}
bool AccessibilityNodeObject::hasAttributesRequiredForInclusion() const
{
if (AccessibilityObject::hasAttributesRequiredForInclusion())
return true;
if (!ariaAccessibilityDescription().isEmpty())
return true;
return false;
}
bool AccessibilityNodeObject::canSetFocusAttribute() const
{
Node* node = this->node();
if (!node)
return false;
if (isWebArea())
return true;
if (!is<Element>(node))
return false;
Element& element = downcast<Element>(*node);
if (element.isDisabledFormControl())
return false;
return element.supportsFocus();
}
bool AccessibilityNodeObject::canSetValueAttribute() const
{
Node* node = this->node();
if (!node)
return false;
if (is<HTMLTextAreaElement>(*node))
return !downcast<HTMLTextAreaElement>(*node).isReadOnly();
if (is<HTMLInputElement>(*node)) {
HTMLInputElement& input = downcast<HTMLInputElement>(*node);
if (input.isTextField())
return !input.isReadOnly();
}
String readOnly = ariaReadOnlyValue();
if (!readOnly.isEmpty())
return readOnly == "true" ? false : true;
if (isNonNativeTextControl())
return true;
if (isMeter())
return false;
if (isProgressIndicator() || isSlider())
return true;
#if PLATFORM(GTK)
if (supportsARIAReadOnly() || isRadioButton())
return true;
#endif
if (isWebArea()) {
Document* document = this->document();
if (!document)
return false;
if (HTMLElement* body = document->bodyOrFrameset()) {
if (body->hasEditableStyle())
return true;
}
return document->hasEditableStyle();
}
return node->hasEditableStyle();
}
AccessibilityRole AccessibilityNodeObject::determineAriaRoleAttribute() const
{
const AtomicString& ariaRole = getAttribute(roleAttr);
if (ariaRole.isNull() || ariaRole.isEmpty())
return UnknownRole;
AccessibilityRole role = ariaRoleToWebCoreRole(ariaRole);
if (role == PresentationalRole && canSetFocusAttribute())
return UnknownRole;
if (role == ButtonRole)
role = buttonRoleType();
if (role == TextAreaRole && !ariaIsMultiline())
role = TextFieldRole;
role = remapAriaRoleDueToParent(role);
if (role == PresentationalRole && supportsARIAAttributes())
role = UnknownRole;
if (role == LandmarkRegionRole && !hasAttribute(aria_labelAttr) && !hasAttribute(aria_labelledbyAttr))
role = UnknownRole;
if (role)
return role;
return UnknownRole;
}
AccessibilityRole AccessibilityNodeObject::ariaRoleAttribute() const
{
return m_ariaRole;
}
AccessibilityRole AccessibilityNodeObject::remapAriaRoleDueToParent(AccessibilityRole role) const
{
if (role != ListBoxOptionRole && role != MenuItemRole)
return role;
for (AccessibilityObject* parent = parentObject(); parent && !parent->accessibilityIsIgnored(); parent = parent->parentObject()) {
AccessibilityRole parentAriaRole = parent->ariaRoleAttribute();
if (role == ListBoxOptionRole && parentAriaRole == MenuRole)
return MenuItemRole;
if (role == MenuItemRole && parentAriaRole == ApplicationGroupRole)
return MenuButtonRole;
if (parentAriaRole)
break;
}
return role;
}
bool AccessibilityNodeObject::canSetSelectedAttribute() const
{
switch (roleValue()) {
case CellRole:
case GridCellRole:
case RadioButtonRole:
case RowHeaderRole:
case RowRole:
case TabListRole:
case TabRole:
case TreeGridRole:
case TreeItemRole:
case TreeRole:
case MenuItemCheckboxRole:
case MenuItemRadioRole:
case MenuItemRole:
return isEnabled();
default:
return false;
}
}
}