2 * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "core/accessibility/AXObjectCache.h"
33 #include "core/HTMLNames.h"
34 #include "core/accessibility/AXARIAGrid.h"
35 #include "core/accessibility/AXARIAGridCell.h"
36 #include "core/accessibility/AXARIAGridRow.h"
37 #include "core/accessibility/AXImageMapLink.h"
38 #include "core/accessibility/AXInlineTextBox.h"
39 #include "core/accessibility/AXList.h"
40 #include "core/accessibility/AXListBox.h"
41 #include "core/accessibility/AXListBoxOption.h"
42 #include "core/accessibility/AXMediaControls.h"
43 #include "core/accessibility/AXMenuList.h"
44 #include "core/accessibility/AXMenuListOption.h"
45 #include "core/accessibility/AXMenuListPopup.h"
46 #include "core/accessibility/AXProgressIndicator.h"
47 #include "core/accessibility/AXRenderObject.h"
48 #include "core/accessibility/AXSVGRoot.h"
49 #include "core/accessibility/AXScrollView.h"
50 #include "core/accessibility/AXScrollbar.h"
51 #include "core/accessibility/AXSlider.h"
52 #include "core/accessibility/AXSpinButton.h"
53 #include "core/accessibility/AXTable.h"
54 #include "core/accessibility/AXTableCell.h"
55 #include "core/accessibility/AXTableColumn.h"
56 #include "core/accessibility/AXTableHeaderContainer.h"
57 #include "core/accessibility/AXTableRow.h"
58 #include "core/dom/Document.h"
59 #include "core/frame/LocalFrame.h"
60 #include "core/html/HTMLAreaElement.h"
61 #include "core/html/HTMLImageElement.h"
62 #include "core/html/HTMLInputElement.h"
63 #include "core/html/HTMLLabelElement.h"
64 #include "core/page/Chrome.h"
65 #include "core/page/ChromeClient.h"
66 #include "core/page/FocusController.h"
67 #include "core/page/Page.h"
68 #include "core/rendering/AbstractInlineTextBox.h"
69 #include "core/rendering/RenderListBox.h"
70 #include "core/rendering/RenderMenuList.h"
71 #include "core/rendering/RenderProgress.h"
72 #include "core/rendering/RenderSlider.h"
73 #include "core/rendering/RenderTable.h"
74 #include "core/rendering/RenderTableCell.h"
75 #include "core/rendering/RenderTableRow.h"
76 #include "core/rendering/RenderView.h"
77 #include "platform/scroll/ScrollView.h"
78 #include "wtf/PassRefPtr.h"
82 using namespace HTMLNames;
84 AXObjectInclusion AXComputedObjectAttributeCache::getIgnored(AXID id) const
86 HashMap<AXID, CachedAXObjectAttributes>::const_iterator it = m_idMapping.find(id);
87 return it != m_idMapping.end() ? it->value.ignored : DefaultBehavior;
90 void AXComputedObjectAttributeCache::setIgnored(AXID id, AXObjectInclusion inclusion)
92 HashMap<AXID, CachedAXObjectAttributes>::iterator it = m_idMapping.find(id);
93 if (it != m_idMapping.end()) {
94 it->value.ignored = inclusion;
96 CachedAXObjectAttributes attributes;
97 attributes.ignored = inclusion;
98 m_idMapping.set(id, attributes);
102 void AXComputedObjectAttributeCache::clear()
107 bool AXObjectCache::gAccessibilityEnabled = false;
108 bool AXObjectCache::gInlineTextBoxAccessibility = false;
110 AXObjectCache::AXObjectCache(Document& document)
111 : m_document(document)
112 , m_notificationPostTimer(this, &AXObjectCache::notificationPostTimerFired)
114 m_computedObjectAttributeCache = AXComputedObjectAttributeCache::create();
117 AXObjectCache::~AXObjectCache()
119 m_notificationPostTimer.stop();
121 HashMap<AXID, RefPtr<AXObject> >::iterator end = m_objects.end();
122 for (HashMap<AXID, RefPtr<AXObject> >::iterator it = m_objects.begin(); it != end; ++it) {
123 AXObject* obj = (*it).value.get();
130 AXObject* AXObjectCache::focusedImageMapUIElement(HTMLAreaElement* areaElement)
132 // Find the corresponding accessibility object for the HTMLAreaElement. This should be
133 // in the list of children for its corresponding image.
137 HTMLImageElement* imageElement = areaElement->imageElement();
141 AXObject* axRenderImage = areaElement->document().axObjectCache()->getOrCreate(imageElement);
145 AXObject::AccessibilityChildrenVector imageChildren = axRenderImage->children();
146 unsigned count = imageChildren.size();
147 for (unsigned k = 0; k < count; ++k) {
148 AXObject* child = imageChildren[k].get();
149 if (!child->isImageMapLink())
152 if (toAXImageMapLink(child)->areaElement() == areaElement)
159 AXObject* AXObjectCache::focusedUIElementForPage(const Page* page)
161 if (!gAccessibilityEnabled)
164 // Cross-process accessibility is not yet implemented.
165 if (!page->focusController().focusedOrMainFrame()->isLocalFrame())
168 // get the focused node in the page
169 Document* focusedDocument = toLocalFrame(page->focusController().focusedOrMainFrame())->document();
170 Node* focusedNode = focusedDocument->focusedElement();
172 focusedNode = focusedDocument;
174 if (isHTMLAreaElement(*focusedNode))
175 return focusedImageMapUIElement(toHTMLAreaElement(focusedNode));
177 AXObject* obj = focusedNode->document().axObjectCache()->getOrCreate(focusedNode);
181 if (obj->shouldFocusActiveDescendant()) {
182 if (AXObject* descendant = obj->activeDescendant())
186 // the HTML element, for example, is focusable but has an AX object that is ignored
187 if (obj->accessibilityIsIgnored())
188 obj = obj->parentObjectUnignored();
193 AXObject* AXObjectCache::get(Widget* widget)
198 AXID axID = m_widgetObjectMapping.get(widget);
199 ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
203 return m_objects.get(axID);
206 AXObject* AXObjectCache::get(RenderObject* renderer)
211 AXID axID = m_renderObjectMapping.get(renderer);
212 ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
216 return m_objects.get(axID);
219 AXObject* AXObjectCache::get(Node* node)
224 AXID renderID = node->renderer() ? m_renderObjectMapping.get(node->renderer()) : 0;
225 ASSERT(!HashTraits<AXID>::isDeletedValue(renderID));
227 AXID nodeID = m_nodeObjectMapping.get(node);
228 ASSERT(!HashTraits<AXID>::isDeletedValue(nodeID));
230 if (node->renderer() && nodeID && !renderID) {
231 // This can happen if an AXNodeObject is created for a node that's not
232 // rendered, but later something changes and it gets a renderer (like if it's
239 return m_objects.get(renderID);
244 return m_objects.get(nodeID);
247 AXObject* AXObjectCache::get(AbstractInlineTextBox* inlineTextBox)
252 AXID axID = m_inlineTextBoxObjectMapping.get(inlineTextBox);
253 ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
257 return m_objects.get(axID);
260 // FIXME: This probably belongs on Node.
261 // FIXME: This should take a const char*, but one caller passes nullAtom.
262 bool nodeHasRole(Node* node, const String& role)
264 if (!node || !node->isElementNode())
267 return equalIgnoringCase(toElement(node)->getAttribute(roleAttr), role);
270 static PassRefPtr<AXObject> createFromRenderer(RenderObject* renderer)
272 // FIXME: How could renderer->node() ever not be an Element?
273 Node* node = renderer->node();
275 // If the node is aria role="list" or the aria role is empty and its a
276 // ul/ol/dl type (it shouldn't be a list if aria says otherwise).
277 if (node && ((nodeHasRole(node, "list") || nodeHasRole(node, "directory"))
278 || (nodeHasRole(node, nullAtom) && (isHTMLUListElement(*node) || isHTMLOListElement(*node) || isHTMLDListElement(*node)))))
279 return AXList::create(renderer);
282 if (nodeHasRole(node, "grid") || nodeHasRole(node, "treegrid"))
283 return AXARIAGrid::create(renderer);
284 if (nodeHasRole(node, "row"))
285 return AXARIAGridRow::create(renderer);
286 if (nodeHasRole(node, "gridcell") || nodeHasRole(node, "columnheader") || nodeHasRole(node, "rowheader"))
287 return AXARIAGridCell::create(renderer);
290 if (node && node->isMediaControlElement())
291 return AccessibilityMediaControl::create(renderer);
293 if (isHTMLOptionElement(node))
294 return AXListBoxOption::create(renderer);
296 if (renderer->isSVGRoot())
297 return AXSVGRoot::create(renderer);
299 if (renderer->isBoxModelObject()) {
300 RenderBoxModelObject* cssBox = toRenderBoxModelObject(renderer);
301 if (cssBox->isListBox())
302 return AXListBox::create(toRenderListBox(cssBox));
303 if (cssBox->isMenuList())
304 return AXMenuList::create(toRenderMenuList(cssBox));
307 if (cssBox->isTable())
308 return AXTable::create(toRenderTable(cssBox));
309 if (cssBox->isTableRow())
310 return AXTableRow::create(toRenderTableRow(cssBox));
311 if (cssBox->isTableCell())
312 return AXTableCell::create(toRenderTableCell(cssBox));
315 if (cssBox->isProgress())
316 return AXProgressIndicator::create(toRenderProgress(cssBox));
319 if (cssBox->isSlider())
320 return AXSlider::create(toRenderSlider(cssBox));
323 return AXRenderObject::create(renderer);
326 static PassRefPtr<AXObject> createFromNode(Node* node)
328 return AXNodeObject::create(node);
331 static PassRefPtr<AXObject> createFromInlineTextBox(AbstractInlineTextBox* inlineTextBox)
333 return AXInlineTextBox::create(inlineTextBox);
336 AXObject* AXObjectCache::getOrCreate(Widget* widget)
341 if (AXObject* obj = get(widget))
344 RefPtr<AXObject> newObj = nullptr;
345 if (widget->isFrameView())
346 newObj = AXScrollView::create(toScrollView(widget));
347 else if (widget->isScrollbar())
348 newObj = AXScrollbar::create(toScrollbar(widget));
350 // Will crash later if we have two objects for the same widget.
351 ASSERT(!get(widget));
353 // Catch the case if an (unsupported) widget type is used. Only FrameView and ScrollBar are supported now.
358 getAXID(newObj.get());
360 m_widgetObjectMapping.set(widget, newObj->axObjectID());
361 m_objects.set(newObj->axObjectID(), newObj);
363 attachWrapper(newObj.get());
367 AXObject* AXObjectCache::getOrCreate(Node* node)
372 if (AXObject* obj = get(node))
375 if (node->renderer())
376 return getOrCreate(node->renderer());
378 if (!node->parentElement())
381 // It's only allowed to create an AXObject from a Node if it's in a canvas subtree.
382 // Or if it's a hidden element, but we still want to expose it because of other ARIA attributes.
383 bool inCanvasSubtree = node->parentElement()->isInCanvasSubtree();
384 bool isHidden = !node->renderer() && isNodeAriaVisible(node);
385 if (!inCanvasSubtree && !isHidden)
388 RefPtr<AXObject> newObj = createFromNode(node);
390 // Will crash later if we have two objects for the same node.
393 getAXID(newObj.get());
395 m_nodeObjectMapping.set(node, newObj->axObjectID());
396 m_objects.set(newObj->axObjectID(), newObj);
398 attachWrapper(newObj.get());
399 newObj->setLastKnownIsIgnoredValue(newObj->accessibilityIsIgnored());
404 AXObject* AXObjectCache::getOrCreate(RenderObject* renderer)
409 if (AXObject* obj = get(renderer))
412 RefPtr<AXObject> newObj = createFromRenderer(renderer);
414 // Will crash later if we have two objects for the same renderer.
415 ASSERT(!get(renderer));
417 getAXID(newObj.get());
419 m_renderObjectMapping.set(renderer, newObj->axObjectID());
420 m_objects.set(newObj->axObjectID(), newObj);
422 attachWrapper(newObj.get());
423 newObj->setLastKnownIsIgnoredValue(newObj->accessibilityIsIgnored());
428 AXObject* AXObjectCache::getOrCreate(AbstractInlineTextBox* inlineTextBox)
433 if (AXObject* obj = get(inlineTextBox))
436 RefPtr<AXObject> newObj = createFromInlineTextBox(inlineTextBox);
438 // Will crash later if we have two objects for the same inlineTextBox.
439 ASSERT(!get(inlineTextBox));
441 getAXID(newObj.get());
443 m_inlineTextBoxObjectMapping.set(inlineTextBox, newObj->axObjectID());
444 m_objects.set(newObj->axObjectID(), newObj);
446 attachWrapper(newObj.get());
447 newObj->setLastKnownIsIgnoredValue(newObj->accessibilityIsIgnored());
452 AXObject* AXObjectCache::rootObject()
454 if (!gAccessibilityEnabled)
457 return getOrCreate(m_document.view());
460 AXObject* AXObjectCache::getOrCreate(AccessibilityRole role)
462 RefPtr<AXObject> obj = nullptr;
464 // will be filled in...
466 case ImageMapLinkRole:
467 obj = AXImageMapLink::create();
470 obj = AXTableColumn::create();
472 case TableHeaderContainerRole:
473 obj = AXTableHeaderContainer::create();
475 case SliderThumbRole:
476 obj = AXSliderThumb::create();
478 case MenuListPopupRole:
479 obj = AXMenuListPopup::create();
481 case MenuListOptionRole:
482 obj = AXMenuListOption::create();
485 obj = AXSpinButton::create();
487 case SpinButtonPartRole:
488 obj = AXSpinButtonPart::create();
499 m_objects.set(obj->axObjectID(), obj);
501 attachWrapper(obj.get());
505 void AXObjectCache::remove(AXID axID)
510 // first fetch object to operate some cleanup functions on it
511 AXObject* obj = m_objects.get(axID);
519 // finally remove the object
520 if (!m_objects.take(axID))
523 ASSERT(m_objects.size() >= m_idsInUse.size());
526 void AXObjectCache::remove(RenderObject* renderer)
531 AXID axID = m_renderObjectMapping.get(renderer);
533 m_renderObjectMapping.remove(renderer);
536 void AXObjectCache::remove(Node* node)
541 removeNodeForUse(node);
543 // This is all safe even if we didn't have a mapping.
544 AXID axID = m_nodeObjectMapping.get(node);
546 m_nodeObjectMapping.remove(node);
548 if (node->renderer()) {
549 remove(node->renderer());
554 void AXObjectCache::remove(Widget* view)
559 AXID axID = m_widgetObjectMapping.get(view);
561 m_widgetObjectMapping.remove(view);
564 void AXObjectCache::remove(AbstractInlineTextBox* inlineTextBox)
569 AXID axID = m_inlineTextBoxObjectMapping.get(inlineTextBox);
571 m_inlineTextBoxObjectMapping.remove(inlineTextBox);
574 // FIXME: Oilpan: Use a weak hashmap for this instead.
575 void AXObjectCache::clearWeakMembers(Visitor* visitor)
577 Vector<Node*> deadNodes;
578 for (HashMap<Node*, AXID>::iterator it = m_nodeObjectMapping.begin(); it != m_nodeObjectMapping.end(); ++it) {
579 if (!visitor->isAlive(it->key))
580 deadNodes.append(it->key);
582 for (unsigned i = 0; i < deadNodes.size(); ++i)
583 remove(deadNodes[i]);
586 AXID AXObjectCache::platformGenerateAXID() const
588 static AXID lastUsedID = 0;
590 // Generate a new ID.
591 AXID objID = lastUsedID;
594 } while (!objID || HashTraits<AXID>::isDeletedValue(objID) || m_idsInUse.contains(objID));
601 AXID AXObjectCache::getAXID(AXObject* obj)
603 // check for already-assigned ID
604 AXID objID = obj->axObjectID();
606 ASSERT(m_idsInUse.contains(objID));
610 objID = platformGenerateAXID();
612 m_idsInUse.add(objID);
613 obj->setAXObjectID(objID);
618 void AXObjectCache::removeAXID(AXObject* object)
623 AXID objID = object->axObjectID();
626 ASSERT(!HashTraits<AXID>::isDeletedValue(objID));
627 ASSERT(m_idsInUse.contains(objID));
628 object->setAXObjectID(0);
629 m_idsInUse.remove(objID);
632 void AXObjectCache::selectionChanged(Node* node)
634 // Find the nearest ancestor that already has an accessibility object, since we
635 // might be in the middle of a layout.
637 if (AXObject* obj = get(node)) {
638 obj->selectionChanged();
641 node = node->parentNode();
645 void AXObjectCache::textChanged(Node* node)
647 textChanged(getOrCreate(node));
650 void AXObjectCache::textChanged(RenderObject* renderer)
652 textChanged(getOrCreate(renderer));
655 void AXObjectCache::textChanged(AXObject* obj)
660 bool parentAlreadyExists = obj->parentObjectIfExists();
662 postNotification(obj, obj->document(), AXObjectCache::AXTextChanged, true);
663 if (parentAlreadyExists)
664 obj->notifyIfIgnoredValueChanged();
667 void AXObjectCache::updateCacheAfterNodeIsAttached(Node* node)
669 // Calling get() will update the AX object if we had an AXNodeObject but now we need
670 // an AXRenderObject, because it was reparented to a location outside of a canvas.
674 void AXObjectCache::childrenChanged(Node* node)
676 childrenChanged(get(node));
679 void AXObjectCache::childrenChanged(RenderObject* renderer)
681 childrenChanged(get(renderer));
684 void AXObjectCache::childrenChanged(AXObject* obj)
689 obj->childrenChanged();
692 void AXObjectCache::notificationPostTimerFired(Timer<AXObjectCache>*)
694 RefPtrWillBeRawPtr<Document> protectorForCacheOwner(m_document);
696 m_notificationPostTimer.stop();
698 unsigned i = 0, count = m_notificationsToPost.size();
699 for (i = 0; i < count; ++i) {
700 AXObject* obj = m_notificationsToPost[i].first.get();
701 if (!obj->axObjectID())
704 if (!obj->axObjectCache())
708 // Make sure none of the render views are in the process of being layed out.
709 // Notifications should only be sent after the renderer has finished
710 if (obj->isAXRenderObject()) {
711 AXRenderObject* renderObj = toAXRenderObject(obj);
712 RenderObject* renderer = renderObj->renderer();
713 if (renderer && renderer->view())
714 ASSERT(!renderer->view()->layoutState());
718 AXNotification notification = m_notificationsToPost[i].second;
719 postPlatformNotification(obj, notification);
721 if (notification == AXChildrenChanged && obj->parentObjectIfExists() && obj->lastKnownIsIgnoredValue() != obj->accessibilityIsIgnored())
722 childrenChanged(obj->parentObject());
725 m_notificationsToPost.clear();
728 void AXObjectCache::postNotification(RenderObject* renderer, AXNotification notification, bool postToElement, PostType postType)
733 m_computedObjectAttributeCache->clear();
735 // Get an accessibility object that already exists. One should not be created here
736 // because a render update may be in progress and creating an AX object can re-trigger a layout
737 RefPtr<AXObject> object = get(renderer);
738 while (!object && renderer) {
739 renderer = renderer->parent();
740 object = get(renderer);
746 postNotification(object.get(), &renderer->document(), notification, postToElement, postType);
749 void AXObjectCache::postNotification(Node* node, AXNotification notification, bool postToElement, PostType postType)
754 m_computedObjectAttributeCache->clear();
756 // Get an accessibility object that already exists. One should not be created here
757 // because a render update may be in progress and creating an AX object can re-trigger a layout
758 RefPtr<AXObject> object = get(node);
759 while (!object && node) {
760 node = node->parentNode();
767 postNotification(object.get(), &node->document(), notification, postToElement, postType);
770 void AXObjectCache::postNotification(AXObject* object, Document* document, AXNotification notification, bool postToElement, PostType postType)
772 m_computedObjectAttributeCache->clear();
774 if (object && !postToElement)
775 object = object->observableObject();
777 if (!object && document)
778 object = get(document->renderView());
783 if (postType == PostAsynchronously) {
784 m_notificationsToPost.append(std::make_pair(object, notification));
785 if (!m_notificationPostTimer.isActive())
786 m_notificationPostTimer.startOneShot(0, FROM_HERE);
788 postPlatformNotification(object, notification);
792 void AXObjectCache::checkedStateChanged(Node* node)
794 postNotification(node, AXObjectCache::AXCheckedStateChanged, true);
797 void AXObjectCache::selectedChildrenChanged(Node* node)
799 // postToElement is false so that you can pass in any child of an element and it will go up the parent tree
800 // to find the container which should send out the notification.
801 postNotification(node, AXSelectedChildrenChanged, false);
804 void AXObjectCache::selectedChildrenChanged(RenderObject* renderer)
806 // postToElement is false so that you can pass in any child of an element and it will go up the parent tree
807 // to find the container which should send out the notification.
808 postNotification(renderer, AXSelectedChildrenChanged, false);
811 void AXObjectCache::handleScrollbarUpdate(ScrollView* view)
816 // We don't want to create a scroll view from this method, only update an existing one.
817 if (AXObject* scrollViewObject = get(view)) {
818 m_computedObjectAttributeCache->clear();
819 scrollViewObject->updateChildrenIfNecessary();
823 void AXObjectCache::handleLayoutComplete(RenderObject* renderer)
828 m_computedObjectAttributeCache->clear();
830 // Create the AXObject if it didn't yet exist - that's always safe at the end of a layout, and it
831 // allows an AX notification to be sent when a page has its first layout, rather than when the
832 // document first loads.
833 if (AXObject* obj = getOrCreate(renderer))
834 postNotification(obj, obj->document(), AXLayoutComplete, true);
837 void AXObjectCache::handleAriaExpandedChange(Node* node)
839 if (AXObject* obj = getOrCreate(node))
840 obj->handleAriaExpandedChanged();
843 void AXObjectCache::handleActiveDescendantChanged(Node* node)
845 if (AXObject* obj = getOrCreate(node))
846 obj->handleActiveDescendantChanged();
849 void AXObjectCache::handleAriaRoleChanged(Node* node)
851 if (AXObject* obj = getOrCreate(node)) {
852 obj->updateAccessibilityRole();
853 m_computedObjectAttributeCache->clear();
854 obj->notifyIfIgnoredValueChanged();
858 void AXObjectCache::handleAttributeChanged(const QualifiedName& attrName, Element* element)
860 if (attrName == roleAttr)
861 handleAriaRoleChanged(element);
862 else if (attrName == altAttr || attrName == titleAttr)
863 textChanged(element);
864 else if (attrName == forAttr && isHTMLLabelElement(*element))
865 labelChanged(element);
867 if (!attrName.localName().string().startsWith("aria-"))
870 if (attrName == aria_activedescendantAttr)
871 handleActiveDescendantChanged(element);
872 else if (attrName == aria_valuenowAttr || attrName == aria_valuetextAttr)
873 postNotification(element, AXObjectCache::AXValueChanged, true);
874 else if (attrName == aria_labelAttr || attrName == aria_labeledbyAttr || attrName == aria_labelledbyAttr)
875 textChanged(element);
876 else if (attrName == aria_checkedAttr)
877 checkedStateChanged(element);
878 else if (attrName == aria_selectedAttr)
879 selectedChildrenChanged(element);
880 else if (attrName == aria_expandedAttr)
881 handleAriaExpandedChange(element);
882 else if (attrName == aria_hiddenAttr)
883 childrenChanged(element->parentNode());
884 else if (attrName == aria_invalidAttr)
885 postNotification(element, AXObjectCache::AXInvalidStatusChanged, true);
887 postNotification(element, AXObjectCache::AXAriaAttributeChanged, true);
890 void AXObjectCache::labelChanged(Element* element)
892 textChanged(toHTMLLabelElement(element)->control());
895 void AXObjectCache::recomputeIsIgnored(RenderObject* renderer)
897 if (AXObject* obj = get(renderer))
898 obj->notifyIfIgnoredValueChanged();
901 void AXObjectCache::inlineTextBoxesUpdated(RenderObject* renderer)
903 if (!gInlineTextBoxAccessibility)
906 // Only update if the accessibility object already exists and it's
907 // not already marked as dirty.
908 if (AXObject* obj = get(renderer)) {
909 if (!obj->needsToUpdateChildren()) {
910 obj->setNeedsToUpdateChildren();
911 postNotification(renderer, AXChildrenChanged, true);
916 const Element* AXObjectCache::rootAXEditableElement(const Node* node)
918 const Element* result = node->rootEditableElement();
919 const Element* element = node->isElementNode() ? toElement(node) : node->parentElement();
921 for (; element; element = element->parentElement()) {
922 if (nodeIsTextControl(element))
929 bool AXObjectCache::nodeIsTextControl(const Node* node)
934 const AXObject* axObject = getOrCreate(const_cast<Node*>(node));
935 return axObject && axObject->isTextControl();
938 bool isNodeAriaVisible(Node* node)
943 if (!node->isElementNode())
946 return equalIgnoringCase(toElement(node)->getAttribute(aria_hiddenAttr), "false");
949 void AXObjectCache::detachWrapper(AXObject* obj)
951 // In Chromium, AXObjects are not wrapped.
954 void AXObjectCache::attachWrapper(AXObject*)
956 // In Chromium, AXObjects are not wrapped.
959 void AXObjectCache::postPlatformNotification(AXObject* obj, AXNotification notification)
961 if (obj && obj->isAXScrollbar() && notification == AXValueChanged) {
962 // Send document value changed on scrollbar value changed notification.
963 Scrollbar* scrollBar = toAXScrollbar(obj)->scrollbar();
964 if (!scrollBar || !scrollBar->parent() || !scrollBar->parent()->isFrameView())
966 Document* document = toFrameView(scrollBar->parent())->frame().document();
967 if (document != document->topDocument())
969 obj = get(document->renderView());
972 if (!obj || !obj->document() || !obj->documentFrameView() || !obj->documentFrameView()->frame().page())
975 ChromeClient& client = obj->documentFrameView()->frame().page()->chrome().client();
977 if (notification == AXActiveDescendantChanged
978 && obj->document()->focusedElement()
979 && obj->node() == obj->document()->focusedElement()) {
980 // Calling handleFocusedUIElementChanged will focus the new active
981 // descendant and send the AXFocusedUIElementChanged notification.
982 handleFocusedUIElementChanged(0, obj->document()->focusedElement());
985 client.postAccessibilityNotification(obj, notification);
988 void AXObjectCache::handleFocusedUIElementChanged(Node*, Node* newFocusedNode)
993 Page* page = newFocusedNode->document().page();
997 AXObject* focusedObject = focusedUIElementForPage(page);
1001 postPlatformNotification(focusedObject, AXFocusedUIElementChanged);
1004 void AXObjectCache::handleScrolledToAnchor(const Node* anchorNode)
1006 // The anchor node may not be accessible. Post the notification for the
1007 // first accessible object.
1008 postPlatformNotification(AXObject::firstAccessibleObjectFromNode(anchorNode), AXScrolledToAnchor);
1011 void AXObjectCache::handleScrollPositionChanged(ScrollView* scrollView)
1013 postPlatformNotification(getOrCreate(scrollView), AXScrollPositionChanged);
1016 void AXObjectCache::handleScrollPositionChanged(RenderObject* renderObject)
1018 postPlatformNotification(getOrCreate(renderObject), AXScrollPositionChanged);
1021 void AXObjectCache::setCanvasObjectBounds(Element* element, const LayoutRect& rect)
1023 AXObject* obj = getOrCreate(element);
1027 obj->setElementRect(rect);
1030 } // namespace blink