This source file includes following definitions.
- getIgnored
- setIgnored
- clear
- m_notificationPostTimer
- focusedImageMapUIElement
- focusedUIElementForPage
- get
- get
- get
- get
- nodeHasRole
- createFromRenderer
- createFromNode
- createFromInlineTextBox
- getOrCreate
- getOrCreate
- getOrCreate
- getOrCreate
- rootObject
- getOrCreate
- remove
- remove
- remove
- remove
- remove
- platformGenerateAXID
- getAXID
- removeAXID
- selectionChanged
- textChanged
- textChanged
- textChanged
- updateCacheAfterNodeIsAttached
- childrenChanged
- childrenChanged
- childrenChanged
- notificationPostTimerFired
- postNotification
- postNotification
- postNotification
- checkedStateChanged
- selectedChildrenChanged
- selectedChildrenChanged
- handleScrollbarUpdate
- handleLayoutComplete
- handleAriaExpandedChange
- handleActiveDescendantChanged
- handleAriaRoleChanged
- handleAttributeChanged
- labelChanged
- recomputeIsIgnored
- inlineTextBoxesUpdated
- startCachingComputedObjectAttributesUntilTreeMutates
- stopCachingComputedObjectAttributes
- visiblePositionForTextMarkerData
- textMarkerDataForVisiblePosition
- rootAXEditableElement
- nodeIsTextControl
- isNodeAriaVisible
- detachWrapper
- attachWrapper
- postPlatformNotification
- handleFocusedUIElementChanged
- handleScrolledToAnchor
- handleScrollPositionChanged
- handleScrollPositionChanged
#include "config.h"
#include "core/accessibility/AXObjectCache.h"
#include "HTMLNames.h"
#include "core/accessibility/AXARIAGrid.h"
#include "core/accessibility/AXARIAGridCell.h"
#include "core/accessibility/AXARIAGridRow.h"
#include "core/accessibility/AXImageMapLink.h"
#include "core/accessibility/AXInlineTextBox.h"
#include "core/accessibility/AXList.h"
#include "core/accessibility/AXListBox.h"
#include "core/accessibility/AXListBoxOption.h"
#include "core/accessibility/AXMediaControls.h"
#include "core/accessibility/AXMenuList.h"
#include "core/accessibility/AXMenuListOption.h"
#include "core/accessibility/AXMenuListPopup.h"
#include "core/accessibility/AXProgressIndicator.h"
#include "core/accessibility/AXRenderObject.h"
#include "core/accessibility/AXSVGRoot.h"
#include "core/accessibility/AXScrollView.h"
#include "core/accessibility/AXScrollbar.h"
#include "core/accessibility/AXSlider.h"
#include "core/accessibility/AXSpinButton.h"
#include "core/accessibility/AXTable.h"
#include "core/accessibility/AXTableCell.h"
#include "core/accessibility/AXTableColumn.h"
#include "core/accessibility/AXTableHeaderContainer.h"
#include "core/accessibility/AXTableRow.h"
#include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLAreaElement.h"
#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLLabelElement.h"
#include "core/page/Chrome.h"
#include "core/page/ChromeClient.h"
#include "core/page/FocusController.h"
#include "core/page/Page.h"
#include "core/rendering/AbstractInlineTextBox.h"
#include "core/rendering/RenderListBox.h"
#include "core/rendering/RenderMenuList.h"
#include "core/rendering/RenderProgress.h"
#include "core/rendering/RenderSlider.h"
#include "core/rendering/RenderTable.h"
#include "core/rendering/RenderTableCell.h"
#include "core/rendering/RenderTableRow.h"
#include "core/rendering/RenderView.h"
#include "platform/scroll/ScrollView.h"
#include "wtf/PassRefPtr.h"
namespace WebCore {
using namespace HTMLNames;
AXObjectInclusion AXComputedObjectAttributeCache::getIgnored(AXID id) const
{
    HashMap<AXID, CachedAXObjectAttributes>::const_iterator it = m_idMapping.find(id);
    return it != m_idMapping.end() ? it->value.ignored : DefaultBehavior;
}
void AXComputedObjectAttributeCache::setIgnored(AXID id, AXObjectInclusion inclusion)
{
    HashMap<AXID, CachedAXObjectAttributes>::iterator it = m_idMapping.find(id);
    if (it != m_idMapping.end()) {
        it->value.ignored = inclusion;
    } else {
        CachedAXObjectAttributes attributes;
        attributes.ignored = inclusion;
        m_idMapping.set(id, attributes);
    }
}
void AXComputedObjectAttributeCache::clear()
{
    m_idMapping.clear();
}
bool AXObjectCache::gAccessibilityEnabled = false;
bool AXObjectCache::gInlineTextBoxAccessibility = false;
AXObjectCache::AXObjectCache(Document& document)
    : m_document(document)
    , m_notificationPostTimer(this, &AXObjectCache::notificationPostTimerFired)
{
    m_computedObjectAttributeCache = AXComputedObjectAttributeCache::create();
}
AXObjectCache::~AXObjectCache()
{
    m_notificationPostTimer.stop();
    HashMap<AXID, RefPtr<AXObject> >::iterator end = m_objects.end();
    for (HashMap<AXID, RefPtr<AXObject> >::iterator it = m_objects.begin(); it != end; ++it) {
        AXObject* obj = (*it).value.get();
        detachWrapper(obj);
        obj->detach();
        removeAXID(obj);
    }
}
AXObject* AXObjectCache::focusedImageMapUIElement(HTMLAreaElement* areaElement)
{
    
    
    if (!areaElement)
        return 0;
    HTMLImageElement* imageElement = areaElement->imageElement();
    if (!imageElement)
        return 0;
    AXObject* axRenderImage = areaElement->document().axObjectCache()->getOrCreate(imageElement);
    if (!axRenderImage)
        return 0;
    AXObject::AccessibilityChildrenVector imageChildren = axRenderImage->children();
    unsigned count = imageChildren.size();
    for (unsigned k = 0; k < count; ++k) {
        AXObject* child = imageChildren[k].get();
        if (!child->isImageMapLink())
            continue;
        if (toAXImageMapLink(child)->areaElement() == areaElement)
            return child;
    }
    return 0;
}
AXObject* AXObjectCache::focusedUIElementForPage(const Page* page)
{
    if (!gAccessibilityEnabled)
        return 0;
    
    Document* focusedDocument = page->focusController().focusedOrMainFrame()->document();
    Node* focusedNode = focusedDocument->focusedElement();
    if (!focusedNode)
        focusedNode = focusedDocument;
    if (isHTMLAreaElement(*focusedNode))
        return focusedImageMapUIElement(toHTMLAreaElement(focusedNode));
    AXObject* obj = focusedNode->document().axObjectCache()->getOrCreate(focusedNode);
    if (!obj)
        return 0;
    if (obj->shouldFocusActiveDescendant()) {
        if (AXObject* descendant = obj->activeDescendant())
            obj = descendant;
    }
    
    if (obj->accessibilityIsIgnored())
        obj = obj->parentObjectUnignored();
    return obj;
}
AXObject* AXObjectCache::get(Widget* widget)
{
    if (!widget)
        return 0;
    AXID axID = m_widgetObjectMapping.get(widget);
    ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
    if (!axID)
        return 0;
    return m_objects.get(axID);
}
AXObject* AXObjectCache::get(RenderObject* renderer)
{
    if (!renderer)
        return 0;
    AXID axID = m_renderObjectMapping.get(renderer);
    ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
    if (!axID)
        return 0;
    return m_objects.get(axID);
}
AXObject* AXObjectCache::get(Node* node)
{
    if (!node)
        return 0;
    AXID renderID = node->renderer() ? m_renderObjectMapping.get(node->renderer()) : 0;
    ASSERT(!HashTraits<AXID>::isDeletedValue(renderID));
    AXID nodeID = m_nodeObjectMapping.get(node);
    ASSERT(!HashTraits<AXID>::isDeletedValue(nodeID));
    if (node->renderer() && nodeID && !renderID) {
        
        
        
        remove(nodeID);
        return 0;
    }
    if (renderID)
        return m_objects.get(renderID);
    if (!nodeID)
        return 0;
    return m_objects.get(nodeID);
}
AXObject* AXObjectCache::get(AbstractInlineTextBox* inlineTextBox)
{
    if (!inlineTextBox)
        return 0;
    AXID axID = m_inlineTextBoxObjectMapping.get(inlineTextBox);
    ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
    if (!axID)
        return 0;
    return m_objects.get(axID);
}
bool nodeHasRole(Node* node, const String& role)
{
    if (!node || !node->isElementNode())
        return false;
    return equalIgnoringCase(toElement(node)->getAttribute(roleAttr), role);
}
static PassRefPtr<AXObject> createFromRenderer(RenderObject* renderer)
{
    
    Node* node = renderer->node();
    
    
    if (node && ((nodeHasRole(node, "list") || nodeHasRole(node, "directory"))
        || (nodeHasRole(node, nullAtom) && (isHTMLUListElement(*node) || isHTMLOListElement(*node) || isHTMLDListElement(*node)))))
        return AXList::create(renderer);
    
    if (nodeHasRole(node, "grid") || nodeHasRole(node, "treegrid"))
        return AXARIAGrid::create(renderer);
    if (nodeHasRole(node, "row"))
        return AXARIAGridRow::create(renderer);
    if (nodeHasRole(node, "gridcell") || nodeHasRole(node, "columnheader") || nodeHasRole(node, "rowheader"))
        return AXARIAGridCell::create(renderer);
    
    if (node && node->isMediaControlElement())
        return AccessibilityMediaControl::create(renderer);
    if (renderer->isSVGRoot())
        return AXSVGRoot::create(renderer);
    if (renderer->isBoxModelObject()) {
        RenderBoxModelObject* cssBox = toRenderBoxModelObject(renderer);
        if (cssBox->isListBox())
            return AXListBox::create(toRenderListBox(cssBox));
        if (cssBox->isMenuList())
            return AXMenuList::create(toRenderMenuList(cssBox));
        
        if (cssBox->isTable())
            return AXTable::create(toRenderTable(cssBox));
        if (cssBox->isTableRow())
            return AXTableRow::create(toRenderTableRow(cssBox));
        if (cssBox->isTableCell())
            return AXTableCell::create(toRenderTableCell(cssBox));
        
        if (cssBox->isProgress())
            return AXProgressIndicator::create(toRenderProgress(cssBox));
        
        if (cssBox->isSlider())
            return AXSlider::create(toRenderSlider(cssBox));
    }
    return AXRenderObject::create(renderer);
}
static PassRefPtr<AXObject> createFromNode(Node* node)
{
    return AXNodeObject::create(node);
}
static PassRefPtr<AXObject> createFromInlineTextBox(AbstractInlineTextBox* inlineTextBox)
{
    return AXInlineTextBox::create(inlineTextBox);
}
AXObject* AXObjectCache::getOrCreate(Widget* widget)
{
    if (!widget)
        return 0;
    if (AXObject* obj = get(widget))
        return obj;
    RefPtr<AXObject> newObj = nullptr;
    if (widget->isFrameView())
        newObj = AXScrollView::create(toScrollView(widget));
    else if (widget->isScrollbar())
        newObj = AXScrollbar::create(toScrollbar(widget));
    
    ASSERT(!get(widget));
    
    ASSERT(newObj);
    if (!newObj)
        return 0;
    getAXID(newObj.get());
    m_widgetObjectMapping.set(widget, newObj->axObjectID());
    m_objects.set(newObj->axObjectID(), newObj);
    newObj->init();
    attachWrapper(newObj.get());
    return newObj.get();
}
AXObject* AXObjectCache::getOrCreate(Node* node)
{
    if (!node)
        return 0;
    if (AXObject* obj = get(node))
        return obj;
    if (node->renderer())
        return getOrCreate(node->renderer());
    if (!node->parentElement())
        return 0;
    
    
    bool inCanvasSubtree = node->parentElement()->isInCanvasSubtree();
    bool isHidden = !node->renderer() && isNodeAriaVisible(node);
    if (!inCanvasSubtree && !isHidden)
        return 0;
    RefPtr<AXObject> newObj = createFromNode(node);
    
    ASSERT(!get(node));
    getAXID(newObj.get());
    m_nodeObjectMapping.set(node, newObj->axObjectID());
    m_objects.set(newObj->axObjectID(), newObj);
    newObj->init();
    attachWrapper(newObj.get());
    newObj->setLastKnownIsIgnoredValue(newObj->accessibilityIsIgnored());
    return newObj.get();
}
AXObject* AXObjectCache::getOrCreate(RenderObject* renderer)
{
    if (!renderer)
        return 0;
    if (AXObject* obj = get(renderer))
        return obj;
    RefPtr<AXObject> newObj = createFromRenderer(renderer);
    
    ASSERT(!get(renderer));
    getAXID(newObj.get());
    m_renderObjectMapping.set(renderer, newObj->axObjectID());
    m_objects.set(newObj->axObjectID(), newObj);
    newObj->init();
    attachWrapper(newObj.get());
    newObj->setLastKnownIsIgnoredValue(newObj->accessibilityIsIgnored());
    return newObj.get();
}
AXObject* AXObjectCache::getOrCreate(AbstractInlineTextBox* inlineTextBox)
{
    if (!inlineTextBox)
        return 0;
    if (AXObject* obj = get(inlineTextBox))
        return obj;
    RefPtr<AXObject> newObj = createFromInlineTextBox(inlineTextBox);
    
    ASSERT(!get(inlineTextBox));
    getAXID(newObj.get());
    m_inlineTextBoxObjectMapping.set(inlineTextBox, newObj->axObjectID());
    m_objects.set(newObj->axObjectID(), newObj);
    newObj->init();
    attachWrapper(newObj.get());
    newObj->setLastKnownIsIgnoredValue(newObj->accessibilityIsIgnored());
    return newObj.get();
}
AXObject* AXObjectCache::rootObject()
{
    if (!gAccessibilityEnabled)
        return 0;
    return getOrCreate(m_document.view());
}
AXObject* AXObjectCache::getOrCreate(AccessibilityRole role)
{
    RefPtr<AXObject> obj = nullptr;
    
    switch (role) {
    case ListBoxOptionRole:
        obj = AXListBoxOption::create();
        break;
    case ImageMapLinkRole:
        obj = AXImageMapLink::create();
        break;
    case ColumnRole:
        obj = AXTableColumn::create();
        break;
    case TableHeaderContainerRole:
        obj = AXTableHeaderContainer::create();
        break;
    case SliderThumbRole:
        obj = AXSliderThumb::create();
        break;
    case MenuListPopupRole:
        obj = AXMenuListPopup::create();
        break;
    case MenuListOptionRole:
        obj = AXMenuListOption::create();
        break;
    case SpinButtonRole:
        obj = AXSpinButton::create();
        break;
    case SpinButtonPartRole:
        obj = AXSpinButtonPart::create();
        break;
    default:
        obj = nullptr;
    }
    if (obj)
        getAXID(obj.get());
    else
        return 0;
    m_objects.set(obj->axObjectID(), obj);
    obj->init();
    attachWrapper(obj.get());
    return obj.get();
}
void AXObjectCache::remove(AXID axID)
{
    if (!axID)
        return;
    
    AXObject* obj = m_objects.get(axID);
    if (!obj)
        return;
    detachWrapper(obj);
    obj->detach();
    removeAXID(obj);
    
    if (!m_objects.take(axID))
        return;
    ASSERT(m_objects.size() >= m_idsInUse.size());
}
void AXObjectCache::remove(RenderObject* renderer)
{
    if (!renderer)
        return;
    AXID axID = m_renderObjectMapping.get(renderer);
    remove(axID);
    m_renderObjectMapping.remove(renderer);
}
void AXObjectCache::remove(Node* node)
{
    if (!node)
        return;
    removeNodeForUse(node);
    
    AXID axID = m_nodeObjectMapping.get(node);
    remove(axID);
    m_nodeObjectMapping.remove(node);
    if (node->renderer()) {
        remove(node->renderer());
        return;
    }
}
void AXObjectCache::remove(Widget* view)
{
    if (!view)
        return;
    AXID axID = m_widgetObjectMapping.get(view);
    remove(axID);
    m_widgetObjectMapping.remove(view);
}
void AXObjectCache::remove(AbstractInlineTextBox* inlineTextBox)
{
    if (!inlineTextBox)
        return;
    AXID axID = m_inlineTextBoxObjectMapping.get(inlineTextBox);
    remove(axID);
    m_inlineTextBoxObjectMapping.remove(inlineTextBox);
}
AXID AXObjectCache::platformGenerateAXID() const
{
    static AXID lastUsedID = 0;
    
    AXID objID = lastUsedID;
    do {
        ++objID;
    } while (!objID || HashTraits<AXID>::isDeletedValue(objID) || m_idsInUse.contains(objID));
    lastUsedID = objID;
    return objID;
}
AXID AXObjectCache::getAXID(AXObject* obj)
{
    
    AXID objID = obj->axObjectID();
    if (objID) {
        ASSERT(m_idsInUse.contains(objID));
        return objID;
    }
    objID = platformGenerateAXID();
    m_idsInUse.add(objID);
    obj->setAXObjectID(objID);
    return objID;
}
void AXObjectCache::removeAXID(AXObject* object)
{
    if (!object)
        return;
    AXID objID = object->axObjectID();
    if (!objID)
        return;
    ASSERT(!HashTraits<AXID>::isDeletedValue(objID));
    ASSERT(m_idsInUse.contains(objID));
    object->setAXObjectID(0);
    m_idsInUse.remove(objID);
}
void AXObjectCache::selectionChanged(Node* node)
{
    
    
    while (node) {
        if (AXObject* obj = get(node)) {
            obj->selectionChanged();
            return;
        }
        node = node->parentNode();
    }
}
void AXObjectCache::textChanged(Node* node)
{
    textChanged(getOrCreate(node));
}
void AXObjectCache::textChanged(RenderObject* renderer)
{
    textChanged(getOrCreate(renderer));
}
void AXObjectCache::textChanged(AXObject* obj)
{
    if (!obj)
        return;
    bool parentAlreadyExists = obj->parentObjectIfExists();
    obj->textChanged();
    postNotification(obj, obj->document(), AXObjectCache::AXTextChanged, true);
    if (parentAlreadyExists)
        obj->notifyIfIgnoredValueChanged();
}
void AXObjectCache::updateCacheAfterNodeIsAttached(Node* node)
{
    
    
    get(node);
}
void AXObjectCache::childrenChanged(Node* node)
{
    childrenChanged(get(node));
}
void AXObjectCache::childrenChanged(RenderObject* renderer)
{
    childrenChanged(get(renderer));
}
void AXObjectCache::childrenChanged(AXObject* obj)
{
    if (!obj)
        return;
    obj->childrenChanged();
}
void AXObjectCache::notificationPostTimerFired(Timer<AXObjectCache>*)
{
    RefPtr<Document> protectorForCacheOwner(m_document);
    m_notificationPostTimer.stop();
    unsigned i = 0, count = m_notificationsToPost.size();
    for (i = 0; i < count; ++i) {
        AXObject* obj = m_notificationsToPost[i].first.get();
        if (!obj->axObjectID())
            continue;
        if (!obj->axObjectCache())
            continue;
#ifndef NDEBUG
        
        
        if (obj->isAXRenderObject()) {
            AXRenderObject* renderObj = toAXRenderObject(obj);
            RenderObject* renderer = renderObj->renderer();
            if (renderer && renderer->view())
                ASSERT(!renderer->view()->layoutState());
        }
#endif
        AXNotification notification = m_notificationsToPost[i].second;
        postPlatformNotification(obj, notification);
        if (notification == AXChildrenChanged && obj->parentObjectIfExists() && obj->lastKnownIsIgnoredValue() != obj->accessibilityIsIgnored())
            childrenChanged(obj->parentObject());
    }
    m_notificationsToPost.clear();
}
void AXObjectCache::postNotification(RenderObject* renderer, AXNotification notification, bool postToElement, PostType postType)
{
    if (!renderer)
        return;
    m_computedObjectAttributeCache->clear();
    
    
    RefPtr<AXObject> object = get(renderer);
    while (!object && renderer) {
        renderer = renderer->parent();
        object = get(renderer);
    }
    if (!renderer)
        return;
    postNotification(object.get(), &renderer->document(), notification, postToElement, postType);
}
void AXObjectCache::postNotification(Node* node, AXNotification notification, bool postToElement, PostType postType)
{
    if (!node)
        return;
    m_computedObjectAttributeCache->clear();
    
    
    RefPtr<AXObject> object = get(node);
    while (!object && node) {
        node = node->parentNode();
        object = get(node);
    }
    if (!node)
        return;
    postNotification(object.get(), &node->document(), notification, postToElement, postType);
}
void AXObjectCache::postNotification(AXObject* object, Document* document, AXNotification notification, bool postToElement, PostType postType)
{
    m_computedObjectAttributeCache->clear();
    if (object && !postToElement)
        object = object->observableObject();
    if (!object && document)
        object = get(document->renderer());
    if (!object)
        return;
    if (postType == PostAsynchronously) {
        m_notificationsToPost.append(std::make_pair(object, notification));
        if (!m_notificationPostTimer.isActive())
            m_notificationPostTimer.startOneShot(0, FROM_HERE);
    } else {
        postPlatformNotification(object, notification);
    }
}
void AXObjectCache::checkedStateChanged(Node* node)
{
    postNotification(node, AXObjectCache::AXCheckedStateChanged, true);
}
void AXObjectCache::selectedChildrenChanged(Node* node)
{
    
    
    postNotification(node, AXSelectedChildrenChanged, false);
}
void AXObjectCache::selectedChildrenChanged(RenderObject* renderer)
{
    
    
    postNotification(renderer, AXSelectedChildrenChanged, false);
}
void AXObjectCache::handleScrollbarUpdate(ScrollView* view)
{
    if (!view)
        return;
    
    if (AXObject* scrollViewObject = get(view)) {
        m_computedObjectAttributeCache->clear();
        scrollViewObject->updateChildrenIfNecessary();
    }
}
void AXObjectCache::handleLayoutComplete(RenderObject* renderer)
{
    if (!renderer)
        return;
    m_computedObjectAttributeCache->clear();
    
    
    
    if (AXObject* obj = getOrCreate(renderer))
        postNotification(obj, obj->document(), AXLayoutComplete, true);
}
void AXObjectCache::handleAriaExpandedChange(Node* node)
{
    if (AXObject* obj = getOrCreate(node))
        obj->handleAriaExpandedChanged();
}
void AXObjectCache::handleActiveDescendantChanged(Node* node)
{
    if (AXObject* obj = getOrCreate(node))
        obj->handleActiveDescendantChanged();
}
void AXObjectCache::handleAriaRoleChanged(Node* node)
{
    if (AXObject* obj = getOrCreate(node)) {
        obj->updateAccessibilityRole();
        m_computedObjectAttributeCache->clear();
        obj->notifyIfIgnoredValueChanged();
    }
}
void AXObjectCache::handleAttributeChanged(const QualifiedName& attrName, Element* element)
{
    if (attrName == roleAttr)
        handleAriaRoleChanged(element);
    else if (attrName == altAttr || attrName == titleAttr)
        textChanged(element);
    else if (attrName == forAttr && isHTMLLabelElement(*element))
        labelChanged(element);
    if (!attrName.localName().string().startsWith("aria-"))
        return;
    if (attrName == aria_activedescendantAttr)
        handleActiveDescendantChanged(element);
    else if (attrName == aria_valuenowAttr || attrName == aria_valuetextAttr)
        postNotification(element, AXObjectCache::AXValueChanged, true);
    else if (attrName == aria_labelAttr || attrName == aria_labeledbyAttr || attrName == aria_labelledbyAttr)
        textChanged(element);
    else if (attrName == aria_checkedAttr)
        checkedStateChanged(element);
    else if (attrName == aria_selectedAttr)
        selectedChildrenChanged(element);
    else if (attrName == aria_expandedAttr)
        handleAriaExpandedChange(element);
    else if (attrName == aria_hiddenAttr)
        childrenChanged(element->parentNode());
    else if (attrName == aria_invalidAttr)
        postNotification(element, AXObjectCache::AXInvalidStatusChanged, true);
    else
        postNotification(element, AXObjectCache::AXAriaAttributeChanged, true);
}
void AXObjectCache::labelChanged(Element* element)
{
    textChanged(toHTMLLabelElement(element)->control());
}
void AXObjectCache::recomputeIsIgnored(RenderObject* renderer)
{
    if (AXObject* obj = get(renderer))
        obj->notifyIfIgnoredValueChanged();
}
void AXObjectCache::inlineTextBoxesUpdated(RenderObject* renderer)
{
    if (!gInlineTextBoxAccessibility)
        return;
    
    
    if (AXObject* obj = get(renderer)) {
        if (!obj->needsToUpdateChildren()) {
            obj->setNeedsToUpdateChildren();
            postNotification(renderer, AXChildrenChanged, true);
        }
    }
}
void AXObjectCache::startCachingComputedObjectAttributesUntilTreeMutates()
{
    
    
    
}
void AXObjectCache::stopCachingComputedObjectAttributes()
{
    
}
VisiblePosition AXObjectCache::visiblePositionForTextMarkerData(TextMarkerData& textMarkerData)
{
    if (!isNodeInUse(textMarkerData.node))
        return VisiblePosition();
    
    VisiblePosition visiblePos = VisiblePosition(createLegacyEditingPosition(textMarkerData.node, textMarkerData.offset), textMarkerData.affinity);
    Position deepPos = visiblePos.deepEquivalent();
    if (deepPos.isNull())
        return VisiblePosition();
    RenderObject* renderer = deepPos.deprecatedNode()->renderer();
    if (!renderer)
        return VisiblePosition();
    AXObjectCache* cache = renderer->document().axObjectCache();
    if (!cache->isIDinUse(textMarkerData.axID))
        return VisiblePosition();
    if (deepPos.deprecatedNode() != textMarkerData.node || deepPos.deprecatedEditingOffset() != textMarkerData.offset)
        return VisiblePosition();
    return visiblePos;
}
void AXObjectCache::textMarkerDataForVisiblePosition(TextMarkerData& textMarkerData, const VisiblePosition& visiblePos)
{
    
    
    memset(&textMarkerData, 0, sizeof(TextMarkerData));
    if (visiblePos.isNull())
        return;
    Position deepPos = visiblePos.deepEquivalent();
    Node* domNode = deepPos.deprecatedNode();
    ASSERT(domNode);
    if (!domNode)
        return;
    if (isHTMLInputElement(*domNode) && toHTMLInputElement(*domNode).isPasswordField())
        return;
    
    AXObjectCache* cache = domNode->document().axObjectCache();
    RefPtr<AXObject> obj = cache->getOrCreate(domNode);
    textMarkerData.axID = obj.get()->axObjectID();
    textMarkerData.node = domNode;
    textMarkerData.offset = deepPos.deprecatedEditingOffset();
    textMarkerData.affinity = visiblePos.affinity();
    cache->setNodeInUse(domNode);
}
const Element* AXObjectCache::rootAXEditableElement(const Node* node)
{
    const Element* result = node->rootEditableElement();
    const Element* element = node->isElementNode() ? toElement(node) : node->parentElement();
    for (; element; element = element->parentElement()) {
        if (nodeIsTextControl(element))
            result = element;
    }
    return result;
}
bool AXObjectCache::nodeIsTextControl(const Node* node)
{
    if (!node)
        return false;
    const AXObject* axObject = getOrCreate(const_cast<Node*>(node));
    return axObject && axObject->isTextControl();
}
bool isNodeAriaVisible(Node* node)
{
    if (!node)
        return false;
    if (!node->isElementNode())
        return false;
    return equalIgnoringCase(toElement(node)->getAttribute(aria_hiddenAttr), "false");
}
void AXObjectCache::detachWrapper(AXObject* obj)
{
    
}
void AXObjectCache::attachWrapper(AXObject*)
{
    
}
void AXObjectCache::postPlatformNotification(AXObject* obj, AXNotification notification)
{
    if (obj && obj->isAXScrollbar() && notification == AXValueChanged) {
        
        Scrollbar* scrollBar = toAXScrollbar(obj)->scrollbar();
        if (!scrollBar || !scrollBar->parent() || !scrollBar->parent()->isFrameView())
            return;
        Document* document = toFrameView(scrollBar->parent())->frame().document();
        if (document != document->topDocument())
            return;
        obj = get(document->renderer());
    }
    if (!obj || !obj->document() || !obj->documentFrameView() || !obj->documentFrameView()->frame().page())
        return;
    ChromeClient& client = obj->documentFrameView()->frame().page()->chrome().client();
    if (notification == AXActiveDescendantChanged
        && obj->document()->focusedElement()
        && obj->node() == obj->document()->focusedElement()) {
        
        
        handleFocusedUIElementChanged(0, obj->document()->focusedElement());
    }
    client.postAccessibilityNotification(obj, notification);
}
void AXObjectCache::handleFocusedUIElementChanged(Node*, Node* newFocusedNode)
{
    if (!newFocusedNode)
        return;
    Page* page = newFocusedNode->document().page();
    if (!page)
        return;
    AXObject* focusedObject = focusedUIElementForPage(page);
    if (!focusedObject)
        return;
    postPlatformNotification(focusedObject, AXFocusedUIElementChanged);
}
void AXObjectCache::handleScrolledToAnchor(const Node* anchorNode)
{
    
    
    postPlatformNotification(AXObject::firstAccessibleObjectFromNode(anchorNode), AXScrolledToAnchor);
}
void AXObjectCache::handleScrollPositionChanged(ScrollView* scrollView)
{
    postPlatformNotification(getOrCreate(scrollView), AXScrollPositionChanged);
}
void AXObjectCache::handleScrollPositionChanged(RenderObject* renderObject)
{
    postPlatformNotification(getOrCreate(renderObject), AXScrollPositionChanged);
}
}