This source file includes following definitions.
- createARIARoleMap
- m_detached
- detach
- isDetached
- axObjectCache
- updateBackingStore
- isARIATextControl
- isButton
- isLandmarkRelated
- isMenuRelated
- isTextControl
- isClickable
- isExpanded
- accessibilityIsIgnored
- accessibilityIsIgnoredByDefault
- accessibilityPlatformIncludesObject
- defaultObjectInclusion
- isInertOrAriaHidden
- lastKnownIsIgnoredValue
- setLastKnownIsIgnoredValue
- orientation
- queryString
- actionVerb
- checkboxOrRadioValue
- ariaIsMultiline
- ariaPressedIsPresent
- invalidStatus
- supportsARIAAttributes
- supportsRangeValue
- ariaTreeRows
- supportsARIALiveRegion
- markCachedElementRectDirty
- clickPoint
- boundingBoxForQuads
- elementAccessibilityHitTest
- children
- parentObjectUnignored
- firstAccessibleObjectFromNode
- updateChildrenIfNecessary
- clearChildren
- focusedUIElement
- document
- documentFrameView
- language
- hasAttribute
- getAttribute
- press
- scrollToMakeVisible
- computeBestScrollOffset
- scrollToMakeVisibleWithSubFocus
- scrollToGlobalPoint
- notifyIfIgnoredValueChanged
- selectionChanged
- lineForPosition
- isARIAControl
- isARIAInput
- ariaRoleToWebCoreRole
- buttonRoleType
#include "config.h"
#include "core/accessibility/AXObject.h"
#include "core/accessibility/AXObjectCache.h"
#include "core/dom/NodeTraversal.h"
#include "core/editing/VisibleUnits.h"
#include "core/editing/htmlediting.h"
#include "core/frame/LocalFrame.h"
#include "core/rendering/RenderListItem.h"
#include "core/rendering/RenderTheme.h"
#include "core/rendering/RenderView.h"
#include "platform/UserGestureIndicator.h"
#include "platform/text/PlatformLocale.h"
#include "wtf/StdLibExtras.h"
#include "wtf/text/WTFString.h"
using blink::WebLocalizedString;
namespace WebCore {
using namespace HTMLNames;
typedef HashMap<String, AccessibilityRole, CaseFoldingHash> ARIARoleMap;
struct RoleEntry {
String ariaRole;
AccessibilityRole webcoreRole;
};
static ARIARoleMap* createARIARoleMap()
{
const RoleEntry roles[] = {
{ "alert", AlertRole },
{ "alertdialog", AlertDialogRole },
{ "application", ApplicationRole },
{ "article", ArticleRole },
{ "banner", BannerRole },
{ "button", ButtonRole },
{ "checkbox", CheckBoxRole },
{ "complementary", ComplementaryRole },
{ "contentinfo", ContentInfoRole },
{ "dialog", DialogRole },
{ "directory", DirectoryRole },
{ "grid", GridRole },
{ "gridcell", CellRole },
{ "columnheader", ColumnHeaderRole },
{ "combobox", ComboBoxRole },
{ "definition", DefinitionRole },
{ "document", DocumentRole },
{ "rowheader", RowHeaderRole },
{ "group", GroupRole },
{ "heading", HeadingRole },
{ "img", ImageRole },
{ "link", LinkRole },
{ "list", ListRole },
{ "listitem", ListItemRole },
{ "listbox", ListBoxRole },
{ "log", LogRole },
{ "main", MainRole },
{ "marquee", MarqueeRole },
{ "math", MathRole },
{ "menu", MenuRole },
{ "menubar", MenuBarRole },
{ "menuitem", MenuItemRole },
{ "menuitemcheckbox", MenuItemRole },
{ "menuitemradio", MenuItemRole },
{ "note", NoteRole },
{ "navigation", NavigationRole },
{ "option", ListBoxOptionRole },
{ "presentation", PresentationalRole },
{ "progressbar", ProgressIndicatorRole },
{ "radio", RadioButtonRole },
{ "radiogroup", RadioGroupRole },
{ "region", RegionRole },
{ "row", RowRole },
{ "scrollbar", ScrollBarRole },
{ "search", SearchRole },
{ "separator", SplitterRole },
{ "slider", SliderRole },
{ "spinbutton", SpinButtonRole },
{ "status", StatusRole },
{ "tab", TabRole },
{ "tablist", TabListRole },
{ "tabpanel", TabPanelRole },
{ "text", StaticTextRole },
{ "textbox", TextAreaRole },
{ "timer", TimerRole },
{ "toolbar", ToolbarRole },
{ "tooltip", UserInterfaceTooltipRole },
{ "tree", TreeRole },
{ "treegrid", TreeGridRole },
{ "treeitem", TreeItemRole }
};
ARIARoleMap* roleMap = new ARIARoleMap;
for (size_t i = 0; i < WTF_ARRAY_LENGTH(roles); ++i)
roleMap->set(roles[i].ariaRole, roles[i].webcoreRole);
return roleMap;
}
AXObject::AXObject()
: m_id(0)
, m_haveChildren(false)
, m_role(UnknownRole)
, m_lastKnownIsIgnoredValue(DefaultBehavior)
, m_detached(false)
{
}
AXObject::~AXObject()
{
ASSERT(isDetached());
}
void AXObject::detach()
{
clearChildren();
m_detached = true;
}
bool AXObject::isDetached() const
{
return m_detached;
}
AXObjectCache* AXObject::axObjectCache() const
{
Document* doc = document();
if (doc)
return doc->axObjectCache();
return 0;
}
void AXObject::updateBackingStore()
{
if (Document* document = this->document())
document->updateLayoutIgnorePendingStylesheets();
}
bool AXObject::isARIATextControl() const
{
return ariaRoleAttribute() == TextAreaRole || ariaRoleAttribute() == TextFieldRole;
}
bool AXObject::isButton() const
{
AccessibilityRole role = roleValue();
return role == ButtonRole || role == PopUpButtonRole || role == ToggleButtonRole;
}
bool AXObject::isLandmarkRelated() const
{
switch (roleValue()) {
case ApplicationRole:
case ArticleRole:
case BannerRole:
case ComplementaryRole:
case ContentInfoRole:
case FooterRole:
case MainRole:
case NavigationRole:
case RegionRole:
case SearchRole:
return true;
default:
return false;
}
}
bool AXObject::isMenuRelated() const
{
switch (roleValue()) {
case MenuRole:
case MenuBarRole:
case MenuButtonRole:
case MenuItemRole:
return true;
default:
return false;
}
}
bool AXObject::isTextControl() const
{
switch (roleValue()) {
case TextAreaRole:
case TextFieldRole:
case ComboBoxRole:
return true;
default:
return false;
}
}
bool AXObject::isClickable() const
{
switch (roleValue()) {
case ButtonRole:
case CheckBoxRole:
case ColorWellRole:
case ComboBoxRole:
case EditableTextRole:
case ImageMapLinkRole:
case LinkRole:
case ListBoxOptionRole:
case MenuButtonRole:
case PopUpButtonRole:
case RadioButtonRole:
case TabRole:
case TextAreaRole:
case TextFieldRole:
case ToggleButtonRole:
return true;
default:
return false;
}
}
bool AXObject::isExpanded() const
{
if (equalIgnoringCase(getAttribute(aria_expandedAttr), "true"))
return true;
return false;
}
bool AXObject::accessibilityIsIgnored() const
{
AXComputedObjectAttributeCache* attributeCache = axObjectCache()->computedObjectAttributeCache();
if (attributeCache) {
AXObjectInclusion ignored = attributeCache->getIgnored(axObjectID());
switch (ignored) {
case IgnoreObject:
return true;
case IncludeObject:
return false;
case DefaultBehavior:
break;
}
}
bool result = computeAccessibilityIsIgnored();
if (attributeCache)
attributeCache->setIgnored(axObjectID(), result ? IgnoreObject : IncludeObject);
return result;
}
bool AXObject::accessibilityIsIgnoredByDefault() const
{
return defaultObjectInclusion() == IgnoreObject;
}
AXObjectInclusion AXObject::accessibilityPlatformIncludesObject() const
{
if (isMenuListPopup() || isMenuListOption())
return IncludeObject;
return DefaultBehavior;
}
AXObjectInclusion AXObject::defaultObjectInclusion() const
{
if (isInertOrAriaHidden())
return IgnoreObject;
if (isPresentationalChildOfAriaRole())
return IgnoreObject;
return accessibilityPlatformIncludesObject();
}
bool AXObject::isInertOrAriaHidden() const
{
bool mightBeInInertSubtree = true;
for (const AXObject* object = this; object; object = object->parentObject()) {
if (equalIgnoringCase(object->getAttribute(aria_hiddenAttr), "true"))
return true;
if (mightBeInInertSubtree && object->node()) {
if (object->node()->isInert())
return true;
mightBeInInertSubtree = false;
}
}
return false;
}
bool AXObject::lastKnownIsIgnoredValue()
{
if (m_lastKnownIsIgnoredValue == DefaultBehavior)
m_lastKnownIsIgnoredValue = accessibilityIsIgnored() ? IgnoreObject : IncludeObject;
return m_lastKnownIsIgnoredValue == IgnoreObject;
}
void AXObject::setLastKnownIsIgnoredValue(bool isIgnored)
{
m_lastKnownIsIgnoredValue = isIgnored ? IgnoreObject : IncludeObject;
}
AccessibilityOrientation AXObject::orientation() const
{
LayoutRect bounds = elementRect();
if (bounds.size().width() > bounds.size().height())
return AccessibilityOrientationHorizontal;
if (bounds.size().height() > bounds.size().width())
return AccessibilityOrientationVertical;
return AccessibilityOrientationHorizontal;
}
static String queryString(WebLocalizedString::Name name)
{
return Locale::defaultLocale().queryString(name);
}
String AXObject::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);
case PopUpButtonRole:
return String();
case MenuListPopupRole:
return String();
default:
return emptyString();
}
}
AccessibilityButtonState AXObject::checkboxOrRadioValue() const
{
const AtomicString& result = getAttribute(aria_checkedAttr);
if (equalIgnoringCase(result, "true"))
return ButtonStateOn;
if (equalIgnoringCase(result, "mixed"))
return ButtonStateMixed;
return ButtonStateOff;
}
bool AXObject::ariaIsMultiline() const
{
return equalIgnoringCase(getAttribute(aria_multilineAttr), "true");
}
bool AXObject::ariaPressedIsPresent() const
{
return !getAttribute(aria_pressedAttr).isEmpty();
}
const AtomicString& AXObject::invalidStatus() const
{
DEFINE_STATIC_LOCAL(const AtomicString, invalidStatusFalse, ("false", AtomicString::ConstructFromLiteral));
const AtomicString& ariaInvalid = getAttribute(aria_invalidAttr);
if (ariaInvalid.isEmpty())
return invalidStatusFalse;
return ariaInvalid;
}
bool AXObject::supportsARIAAttributes() const
{
return supportsARIALiveRegion()
|| supportsARIADragging()
|| supportsARIADropping()
|| supportsARIAFlowTo()
|| supportsARIAOwns()
|| hasAttribute(aria_labelAttr);
}
bool AXObject::supportsRangeValue() const
{
return isProgressIndicator()
|| isSlider()
|| isScrollbar()
|| isSpinButton();
}
void AXObject::ariaTreeRows(AccessibilityChildrenVector& result)
{
AccessibilityChildrenVector axChildren = children();
unsigned count = axChildren.size();
for (unsigned k = 0; k < count; ++k) {
AXObject* obj = axChildren[k].get();
if (obj->roleValue() == TreeItemRole)
result.append(obj);
obj->ariaTreeRows(result);
}
}
bool AXObject::supportsARIALiveRegion() const
{
const AtomicString& liveRegion = ariaLiveRegionStatus();
return equalIgnoringCase(liveRegion, "polite") || equalIgnoringCase(liveRegion, "assertive");
}
void AXObject::markCachedElementRectDirty() const
{
for (unsigned i = 0; i < m_children.size(); ++i)
m_children[i].get()->markCachedElementRectDirty();
}
IntPoint AXObject::clickPoint()
{
LayoutRect rect = elementRect();
return roundedIntPoint(LayoutPoint(rect.x() + rect.width() / 2, rect.y() + rect.height() / 2));
}
IntRect AXObject::boundingBoxForQuads(RenderObject* obj, const Vector<FloatQuad>& quads)
{
ASSERT(obj);
if (!obj)
return IntRect();
size_t count = quads.size();
if (!count)
return IntRect();
IntRect result;
for (size_t i = 0; i < count; ++i) {
IntRect r = quads[i].enclosingBoundingBox();
if (!r.isEmpty()) {
if (obj->style()->hasAppearance())
RenderTheme::theme().adjustRepaintRect(obj, r);
result.unite(r);
}
}
return result;
}
AXObject* AXObject::elementAccessibilityHitTest(const IntPoint& point) const
{
if (isAttachment()) {
Widget* widget = widgetForAttachmentView();
if (widget && widget->isFrameView())
return axObjectCache()->getOrCreate(widget)->accessibilityHitTest(IntPoint(point - widget->frameRect().location()));
}
size_t count = m_children.size();
for (size_t k = 0; k < count; k++) {
if (m_children[k]->isMockObject() && m_children[k]->elementRect().contains(point))
return m_children[k]->elementAccessibilityHitTest(point);
}
return const_cast<AXObject*>(this);
}
const AXObject::AccessibilityChildrenVector& AXObject::children()
{
updateChildrenIfNecessary();
return m_children;
}
AXObject* AXObject::parentObjectUnignored() const
{
AXObject* parent;
for (parent = parentObject(); parent && parent->accessibilityIsIgnored(); parent = parent->parentObject()) {
}
return parent;
}
AXObject* AXObject::firstAccessibleObjectFromNode(const Node* node)
{
if (!node)
return 0;
AXObjectCache* cache = node->document().axObjectCache();
AXObject* accessibleObject = cache->getOrCreate(node->renderer());
while (accessibleObject && accessibleObject->accessibilityIsIgnored()) {
node = NodeTraversal::next(*node);
while (node && !node->renderer())
node = NodeTraversal::nextSkippingChildren(*node);
if (!node)
return 0;
accessibleObject = cache->getOrCreate(node->renderer());
}
return accessibleObject;
}
void AXObject::updateChildrenIfNecessary()
{
if (!hasChildren())
addChildren();
}
void AXObject::clearChildren()
{
size_t length = m_children.size();
for (size_t i = 0; i < length; i++)
m_children[i]->detachFromParent();
m_children.clear();
m_haveChildren = false;
}
AXObject* AXObject::focusedUIElement() const
{
Document* doc = document();
if (!doc)
return 0;
Page* page = doc->page();
if (!page)
return 0;
return AXObjectCache::focusedUIElementForPage(page);
}
Document* AXObject::document() const
{
FrameView* frameView = documentFrameView();
if (!frameView)
return 0;
return frameView->frame().document();
}
FrameView* AXObject::documentFrameView() const
{
const AXObject* object = this;
while (object && !object->isAXRenderObject())
object = object->parentObject();
if (!object)
return 0;
return object->documentFrameView();
}
String AXObject::language() const
{
const AtomicString& lang = getAttribute(langAttr);
if (!lang.isEmpty())
return lang;
AXObject* parent = parentObject();
if (!parent) {
Document* doc = document();
if (doc)
return doc->contentLanguage();
return nullAtom;
}
return parent->language();
}
bool AXObject::hasAttribute(const QualifiedName& attribute) const
{
Node* elementNode = node();
if (!elementNode)
return false;
if (!elementNode->isElementNode())
return false;
Element* element = toElement(elementNode);
return element->fastHasAttribute(attribute);
}
const AtomicString& AXObject::getAttribute(const QualifiedName& attribute) const
{
Node* elementNode = node();
if (!elementNode)
return nullAtom;
if (!elementNode->isElementNode())
return nullAtom;
Element* element = toElement(elementNode);
return element->fastGetAttribute(attribute);
}
bool AXObject::press() const
{
Element* actionElem = actionElement();
if (!actionElem)
return false;
UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
actionElem->accessKeyAction(true);
return true;
}
void AXObject::scrollToMakeVisible() const
{
IntRect objectRect = pixelSnappedIntRect(elementRect());
objectRect.setLocation(IntPoint());
scrollToMakeVisibleWithSubFocus(objectRect);
}
static int computeBestScrollOffset(int currentScrollOffset, int subfocusMin, int subfocusMax, int objectMin, int objectMax, int viewportMin, int viewportMax)
{
int viewportSize = viewportMax - viewportMin;
if (objectMax - objectMin > viewportSize) {
subfocusMin = std::max(subfocusMin, objectMin);
subfocusMax = std::min(subfocusMax, objectMax);
if (subfocusMax - subfocusMin > viewportSize)
subfocusMax = subfocusMin + viewportSize;
if (subfocusMin + viewportSize > objectMax) {
objectMin = objectMax - viewportSize;
} else {
objectMin = subfocusMin;
objectMax = subfocusMin + viewportSize;
}
}
if (objectMin - currentScrollOffset >= viewportMin
&& objectMax - currentScrollOffset <= viewportMax)
return currentScrollOffset;
if (objectMax - currentScrollOffset > viewportMax)
return objectMax - viewportMax;
if (objectMin - currentScrollOffset < viewportMin)
return objectMin - viewportMin;
ASSERT_NOT_REACHED();
return currentScrollOffset;
}
void AXObject::scrollToMakeVisibleWithSubFocus(const IntRect& subfocus) const
{
AXObject* scrollParent = parentObject();
ScrollableArea* scrollableArea;
for (scrollableArea = 0;
scrollParent && !(scrollableArea = scrollParent->getScrollableAreaIfScrollable());
scrollParent = scrollParent->parentObject()) { }
if (!scrollableArea)
return;
LayoutRect objectRect = elementRect();
IntPoint scrollPosition = scrollableArea->scrollPosition();
IntRect scrollVisibleRect = scrollableArea->visibleContentRect();
int desiredX = computeBestScrollOffset(
scrollPosition.x(),
objectRect.x() + subfocus.x(), objectRect.x() + subfocus.maxX(),
objectRect.x(), objectRect.maxX(),
0, scrollVisibleRect.width());
int desiredY = computeBestScrollOffset(
scrollPosition.y(),
objectRect.y() + subfocus.y(), objectRect.y() + subfocus.maxY(),
objectRect.y(), objectRect.maxY(),
0, scrollVisibleRect.height());
scrollParent->scrollTo(IntPoint(desiredX, desiredY));
if (scrollParent->parentObject())
scrollParent->scrollToMakeVisible();
}
void AXObject::scrollToGlobalPoint(const IntPoint& globalPoint) const
{
Vector<const AXObject*> objects;
AXObject* parentObject;
for (parentObject = this->parentObject(); parentObject; parentObject = parentObject->parentObject()) {
if (parentObject->getScrollableAreaIfScrollable())
objects.prepend(parentObject);
}
objects.append(this);
int offsetX = 0, offsetY = 0;
IntPoint point = globalPoint;
size_t levels = objects.size() - 1;
for (size_t i = 0; i < levels; i++) {
const AXObject* outer = objects[i];
const AXObject* inner = objects[i + 1];
ScrollableArea* scrollableArea = outer->getScrollableAreaIfScrollable();
LayoutRect innerRect = inner->isAXScrollView() ? inner->parentObject()->elementRect() : inner->elementRect();
LayoutRect objectRect = innerRect;
IntPoint scrollPosition = scrollableArea->scrollPosition();
objectRect.move(offsetX, offsetY);
if (!outer->isAXScrollView())
objectRect.move(scrollPosition.x(), scrollPosition.y());
int desiredX = computeBestScrollOffset(
0,
objectRect.x(), objectRect.maxX(),
objectRect.x(), objectRect.maxX(),
point.x(), point.x());
int desiredY = computeBestScrollOffset(
0,
objectRect.y(), objectRect.maxY(),
objectRect.y(), objectRect.maxY(),
point.y(), point.y());
outer->scrollTo(IntPoint(desiredX, desiredY));
if (outer->isAXScrollView() && !inner->isAXScrollView()) {
scrollPosition = scrollableArea->scrollPosition();
offsetX -= (scrollPosition.x() + point.x());
offsetY -= (scrollPosition.y() + point.y());
point.move(scrollPosition.x() - innerRect.x(), scrollPosition.y() - innerRect.y());
} else if (inner->isAXScrollView()) {
offsetX = 0;
offsetY = 0;
}
}
}
void AXObject::notifyIfIgnoredValueChanged()
{
bool isIgnored = accessibilityIsIgnored();
if (lastKnownIsIgnoredValue() != isIgnored) {
axObjectCache()->childrenChanged(parentObject());
setLastKnownIsIgnoredValue(isIgnored);
}
}
void AXObject::selectionChanged()
{
if (AXObject* parent = parentObjectIfExists())
parent->selectionChanged();
}
int AXObject::lineForPosition(const VisiblePosition& visiblePos) const
{
if (visiblePos.isNull() || !node())
return -1;
Node* containerNode = visiblePos.deepEquivalent().containerNode();
if (!containerNode->containsIncludingShadowDOM(node()) && !node()->containsIncludingShadowDOM(containerNode))
return -1;
int lineCount = -1;
VisiblePosition currentVisiblePos = visiblePos;
VisiblePosition savedVisiblePos;
do {
savedVisiblePos = currentVisiblePos;
VisiblePosition prevVisiblePos = previousLinePosition(currentVisiblePos, 0, HasEditableAXRole);
currentVisiblePos = prevVisiblePos;
++lineCount;
} while (currentVisiblePos.isNotNull() && !(inSameLine(currentVisiblePos, savedVisiblePos)));
return lineCount;
}
bool AXObject::isARIAControl(AccessibilityRole ariaRole)
{
return isARIAInput(ariaRole) || ariaRole == TextAreaRole || ariaRole == ButtonRole
|| ariaRole == ComboBoxRole || ariaRole == SliderRole;
}
bool AXObject::isARIAInput(AccessibilityRole ariaRole)
{
return ariaRole == RadioButtonRole || ariaRole == CheckBoxRole || ariaRole == TextFieldRole;
}
AccessibilityRole AXObject::ariaRoleToWebCoreRole(const String& value)
{
ASSERT(!value.isEmpty());
static const ARIARoleMap* roleMap = createARIARoleMap();
Vector<String> roleVector;
value.split(' ', roleVector);
AccessibilityRole role = UnknownRole;
unsigned size = roleVector.size();
for (unsigned i = 0; i < size; ++i) {
String roleName = roleVector[i];
role = roleMap->get(roleName);
if (role)
return role;
}
return role;
}
AccessibilityRole AXObject::buttonRoleType() const
{
if (ariaPressedIsPresent())
return ToggleButtonRole;
if (ariaHasPopup())
return PopUpButtonRole;
return ButtonRole;
}
}