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 #if HAVE(ACCESSIBILITY)
33 #include "AXObjectCache.h"
35 #include "AccessibilityARIAGrid.h"
36 #include "AccessibilityARIAGridCell.h"
37 #include "AccessibilityARIAGridRow.h"
38 #include "AccessibilityImageMapLink.h"
39 #include "AccessibilityList.h"
40 #include "AccessibilityListBox.h"
41 #include "AccessibilityListBoxOption.h"
42 #include "AccessibilityMediaControls.h"
43 #include "AccessibilityMenuList.h"
44 #include "AccessibilityMenuListOption.h"
45 #include "AccessibilityMenuListPopup.h"
46 #include "AccessibilityProgressIndicator.h"
47 #include "AccessibilityRenderObject.h"
48 #include "AccessibilitySVGRoot.h"
49 #include "AccessibilityScrollView.h"
50 #include "AccessibilityScrollbar.h"
51 #include "AccessibilitySlider.h"
52 #include "AccessibilitySpinButton.h"
53 #include "AccessibilityTable.h"
54 #include "AccessibilityTableCell.h"
55 #include "AccessibilityTableColumn.h"
56 #include "AccessibilityTableHeaderContainer.h"
57 #include "AccessibilityTableRow.h"
60 #include "FocusController.h"
62 #include "HTMLAreaElement.h"
63 #include "HTMLImageElement.h"
64 #include "HTMLInputElement.h"
65 #include "HTMLLabelElement.h"
66 #include "HTMLMeterElement.h"
67 #include "HTMLNames.h"
69 #include "RenderListBox.h"
70 #include "RenderMenuList.h"
71 #include "RenderMeter.h"
72 #include "RenderProgress.h"
73 #include "RenderSlider.h"
74 #include "RenderTable.h"
75 #include "RenderTableCell.h"
76 #include "RenderTableRow.h"
77 #include "RenderView.h"
78 #include "ScrollView.h"
79 #include <wtf/PassRefPtr.h>
82 #include "MediaControlElements.h"
87 using namespace HTMLNames;
89 AccessibilityObjectInclusion AXComputedObjectAttributeCache::getIgnored(AXID id) const
91 HashMap<AXID, CachedAXObjectAttributes>::const_iterator it = m_idMapping.find(id);
92 return it != m_idMapping.end() ? it->value.ignored : DefaultBehavior;
95 void AXComputedObjectAttributeCache::setIgnored(AXID id, AccessibilityObjectInclusion inclusion)
97 HashMap<AXID, CachedAXObjectAttributes>::iterator it = m_idMapping.find(id);
98 if (it != m_idMapping.end())
99 it->value.ignored = inclusion;
101 CachedAXObjectAttributes attributes;
102 attributes.ignored = inclusion;
103 m_idMapping.set(id, attributes);
107 bool AXObjectCache::gAccessibilityEnabled = false;
108 bool AXObjectCache::gAccessibilityEnhancedUserInterfaceEnabled = false;
110 AXObjectCache::AXObjectCache(const Document* doc)
111 : m_notificationPostTimer(this, &AXObjectCache::notificationPostTimerFired)
113 m_document = const_cast<Document*>(doc);
116 AXObjectCache::~AXObjectCache()
118 m_notificationPostTimer.stop();
120 HashMap<AXID, RefPtr<AccessibilityObject> >::iterator end = m_objects.end();
121 for (HashMap<AXID, RefPtr<AccessibilityObject> >::iterator it = m_objects.begin(); it != end; ++it) {
122 AccessibilityObject* obj = (*it).value.get();
129 AccessibilityObject* AXObjectCache::focusedImageMapUIElement(HTMLAreaElement* areaElement)
131 // Find the corresponding accessibility object for the HTMLAreaElement. This should be
132 // in the list of children for its corresponding image.
136 HTMLImageElement* imageElement = areaElement->imageElement();
140 AccessibilityObject* axRenderImage = areaElement->document()->axObjectCache()->getOrCreate(imageElement);
144 AccessibilityObject::AccessibilityChildrenVector imageChildren = axRenderImage->children();
145 unsigned count = imageChildren.size();
146 for (unsigned k = 0; k < count; ++k) {
147 AccessibilityObject* child = imageChildren[k].get();
148 if (!child->isImageMapLink())
151 if (static_cast<AccessibilityImageMapLink*>(child)->areaElement() == areaElement)
158 AccessibilityObject* AXObjectCache::focusedUIElementForPage(const Page* page)
160 if (!gAccessibilityEnabled)
163 // get the focused node in the page
164 Document* focusedDocument = page->focusController().focusedOrMainFrame().document();
165 Element* focusedElement = focusedDocument->focusedElement();
166 if (focusedElement && isHTMLAreaElement(focusedElement))
167 return focusedImageMapUIElement(toHTMLAreaElement(focusedElement));
169 AccessibilityObject* obj = focusedDocument->axObjectCache()->getOrCreate(focusedElement ? static_cast<Node*>(focusedElement) : focusedDocument);
173 if (obj->shouldFocusActiveDescendant()) {
174 if (AccessibilityObject* descendant = obj->activeDescendant())
178 // the HTML element, for example, is focusable but has an AX object that is ignored
179 if (obj->accessibilityIsIgnored())
180 obj = obj->parentObjectUnignored();
185 AccessibilityObject* AXObjectCache::get(Widget* widget)
190 AXID axID = m_widgetObjectMapping.get(widget);
191 ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
195 return m_objects.get(axID);
198 AccessibilityObject* AXObjectCache::get(RenderObject* renderer)
203 AXID axID = m_renderObjectMapping.get(renderer);
204 ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
208 return m_objects.get(axID);
211 AccessibilityObject* AXObjectCache::get(Node* node)
216 AXID renderID = node->renderer() ? m_renderObjectMapping.get(node->renderer()) : 0;
217 ASSERT(!HashTraits<AXID>::isDeletedValue(renderID));
219 AXID nodeID = m_nodeObjectMapping.get(node);
220 ASSERT(!HashTraits<AXID>::isDeletedValue(nodeID));
222 if (node->renderer() && nodeID && !renderID) {
223 // This can happen if an AccessibilityNodeObject is created for a node that's not
224 // rendered, but later something changes and it gets a renderer (like if it's
231 return m_objects.get(renderID);
236 return m_objects.get(nodeID);
239 // FIXME: This probably belongs on Node.
240 // FIXME: This should take a const char*, but one caller passes nullAtom.
241 bool nodeHasRole(Node* node, const String& role)
243 if (!node || !node->isElementNode())
246 return equalIgnoringCase(toElement(node)->getAttribute(roleAttr), role);
249 static PassRefPtr<AccessibilityObject> createFromRenderer(RenderObject* renderer)
251 // FIXME: How could renderer->node() ever not be an Element?
252 Node* node = renderer->node();
254 // If the node is aria role="list" or the aria role is empty and its a
255 // ul/ol/dl type (it shouldn't be a list if aria says otherwise).
256 if (node && ((nodeHasRole(node, "list") || nodeHasRole(node, "directory"))
257 || (nodeHasRole(node, nullAtom) && (node->hasTagName(ulTag) || node->hasTagName(olTag) || node->hasTagName(dlTag)))))
258 return AccessibilityList::create(renderer);
261 if (nodeHasRole(node, "grid") || nodeHasRole(node, "treegrid"))
262 return AccessibilityARIAGrid::create(renderer);
263 if (nodeHasRole(node, "row"))
264 return AccessibilityARIAGridRow::create(renderer);
265 if (nodeHasRole(node, "gridcell") || nodeHasRole(node, "columnheader") || nodeHasRole(node, "rowheader"))
266 return AccessibilityARIAGridCell::create(renderer);
270 if (node && node->isMediaControlElement())
271 return AccessibilityMediaControl::create(renderer);
275 if (renderer->isSVGRoot())
276 return AccessibilitySVGRoot::create(renderer);
279 if (renderer->isBoxModelObject()) {
280 RenderBoxModelObject* cssBox = toRenderBoxModelObject(renderer);
281 if (cssBox->isListBox())
282 return AccessibilityListBox::create(toRenderListBox(cssBox));
283 if (cssBox->isMenuList())
284 return AccessibilityMenuList::create(toRenderMenuList(cssBox));
287 if (cssBox->isTable())
288 return AccessibilityTable::create(toRenderTable(cssBox));
289 if (cssBox->isTableRow())
290 return AccessibilityTableRow::create(toRenderTableRow(cssBox));
291 if (cssBox->isTableCell())
292 return AccessibilityTableCell::create(toRenderTableCell(cssBox));
294 #if ENABLE(PROGRESS_ELEMENT)
296 if (cssBox->isProgress())
297 return AccessibilityProgressIndicator::create(toRenderProgress(cssBox));
299 #if ENABLE(METER_ELEMENT)
300 if (cssBox->isMeter())
301 return AccessibilityProgressIndicator::create(toRenderMeter(cssBox));
305 if (cssBox->isSlider())
306 return AccessibilitySlider::create(toRenderSlider(cssBox));
309 return AccessibilityRenderObject::create(renderer);
312 static PassRefPtr<AccessibilityObject> createFromNode(Node* node)
314 return AccessibilityNodeObject::create(node);
317 AccessibilityObject* AXObjectCache::getOrCreate(Widget* widget)
322 if (AccessibilityObject* obj = get(widget))
325 RefPtr<AccessibilityObject> newObj = 0;
326 if (widget->isFrameView())
327 newObj = AccessibilityScrollView::create(static_cast<ScrollView*>(widget));
328 else if (widget->isScrollbar())
329 newObj = AccessibilityScrollbar::create(static_cast<Scrollbar*>(widget));
331 // Will crash later if we have two objects for the same widget.
332 ASSERT(!get(widget));
334 getAXID(newObj.get());
336 m_widgetObjectMapping.set(widget, newObj->axObjectID());
337 m_objects.set(newObj->axObjectID(), newObj);
339 attachWrapper(newObj.get());
343 AccessibilityObject* AXObjectCache::getOrCreate(Node* node)
348 if (AccessibilityObject* obj = get(node))
351 if (node->renderer())
352 return getOrCreate(node->renderer());
354 if (!node->parentElement())
357 // It's only allowed to create an AccessibilityObject from a Node if it's in a canvas subtree.
358 // Or if it's a hidden element, but we still want to expose it because of other ARIA attributes.
359 bool inCanvasSubtree = node->parentElement()->isInCanvasSubtree();
360 bool isHidden = !node->renderer() && isNodeAriaVisible(node);
362 bool insideMeterElement = false;
363 #if ENABLE(METER_ELEMENT)
364 insideMeterElement = isHTMLMeterElement(node->parentElement());
367 if (!inCanvasSubtree && !isHidden && !insideMeterElement)
370 RefPtr<AccessibilityObject> newObj = createFromNode(node);
372 // Will crash later if we have two objects for the same node.
375 getAXID(newObj.get());
377 m_nodeObjectMapping.set(node, newObj->axObjectID());
378 m_objects.set(newObj->axObjectID(), newObj);
380 attachWrapper(newObj.get());
381 newObj->setLastKnownIsIgnoredValue(newObj->accessibilityIsIgnored());
386 AccessibilityObject* AXObjectCache::getOrCreate(RenderObject* renderer)
391 if (AccessibilityObject* obj = get(renderer))
394 RefPtr<AccessibilityObject> newObj = createFromRenderer(renderer);
396 // Will crash later if we have two objects for the same renderer.
397 ASSERT(!get(renderer));
399 getAXID(newObj.get());
401 m_renderObjectMapping.set(renderer, newObj->axObjectID());
402 m_objects.set(newObj->axObjectID(), newObj);
404 attachWrapper(newObj.get());
405 newObj->setLastKnownIsIgnoredValue(newObj->accessibilityIsIgnored());
410 AccessibilityObject* AXObjectCache::rootObject()
412 if (!gAccessibilityEnabled)
415 return getOrCreate(m_document->view());
418 AccessibilityObject* AXObjectCache::rootObjectForFrame(Frame* frame)
420 if (!gAccessibilityEnabled)
425 return getOrCreate(frame->view());
428 AccessibilityObject* AXObjectCache::getOrCreate(AccessibilityRole role)
430 RefPtr<AccessibilityObject> obj = 0;
432 // will be filled in...
434 case ListBoxOptionRole:
435 obj = AccessibilityListBoxOption::create();
437 case ImageMapLinkRole:
438 obj = AccessibilityImageMapLink::create();
441 obj = AccessibilityTableColumn::create();
443 case TableHeaderContainerRole:
444 obj = AccessibilityTableHeaderContainer::create();
446 case SliderThumbRole:
447 obj = AccessibilitySliderThumb::create();
449 case MenuListPopupRole:
450 obj = AccessibilityMenuListPopup::create();
452 case MenuListOptionRole:
453 obj = AccessibilityMenuListOption::create();
456 obj = AccessibilitySpinButton::create();
458 case SpinButtonPartRole:
459 obj = AccessibilitySpinButtonPart::create();
470 m_objects.set(obj->axObjectID(), obj);
472 attachWrapper(obj.get());
476 void AXObjectCache::remove(AXID axID)
481 // first fetch object to operate some cleanup functions on it
482 AccessibilityObject* obj = m_objects.get(axID);
490 // finally remove the object
491 if (!m_objects.take(axID))
494 ASSERT(m_objects.size() >= m_idsInUse.size());
497 void AXObjectCache::remove(RenderObject* renderer)
502 AXID axID = m_renderObjectMapping.get(renderer);
504 m_renderObjectMapping.remove(renderer);
507 void AXObjectCache::remove(Node* node)
512 removeNodeForUse(node);
514 // This is all safe even if we didn't have a mapping.
515 AXID axID = m_nodeObjectMapping.get(node);
517 m_nodeObjectMapping.remove(node);
519 if (node->renderer()) {
520 remove(node->renderer());
525 void AXObjectCache::remove(Widget* view)
530 AXID axID = m_widgetObjectMapping.get(view);
532 m_widgetObjectMapping.remove(view);
536 #if !PLATFORM(WIN) || OS(WINCE)
537 AXID AXObjectCache::platformGenerateAXID() const
539 static AXID lastUsedID = 0;
541 // Generate a new ID.
542 AXID objID = lastUsedID;
545 } while (!objID || HashTraits<AXID>::isDeletedValue(objID) || m_idsInUse.contains(objID));
553 AXID AXObjectCache::getAXID(AccessibilityObject* obj)
555 // check for already-assigned ID
556 AXID objID = obj->axObjectID();
558 ASSERT(m_idsInUse.contains(objID));
562 objID = platformGenerateAXID();
564 m_idsInUse.add(objID);
565 obj->setAXObjectID(objID);
570 void AXObjectCache::removeAXID(AccessibilityObject* object)
575 AXID objID = object->axObjectID();
578 ASSERT(!HashTraits<AXID>::isDeletedValue(objID));
579 ASSERT(m_idsInUse.contains(objID));
580 object->setAXObjectID(0);
581 m_idsInUse.remove(objID);
584 void AXObjectCache::textChanged(Node* node)
586 textChanged(getOrCreate(node));
589 void AXObjectCache::textChanged(RenderObject* renderer)
591 textChanged(getOrCreate(renderer));
594 void AXObjectCache::textChanged(AccessibilityObject* obj)
599 bool parentAlreadyExists = obj->parentObjectIfExists();
601 postNotification(obj, obj->document(), AXObjectCache::AXTextChanged, true);
602 if (parentAlreadyExists)
603 obj->notifyIfIgnoredValueChanged();
606 void AXObjectCache::updateCacheAfterNodeIsAttached(Node* node)
608 // Calling get() will update the AX object if we had an AccessibilityNodeObject but now we need
609 // an AccessibilityRenderObject, because it was reparented to a location outside of a canvas.
613 void AXObjectCache::childrenChanged(Node* node)
615 childrenChanged(get(node));
618 void AXObjectCache::childrenChanged(RenderObject* renderer)
620 childrenChanged(get(renderer));
623 void AXObjectCache::childrenChanged(AccessibilityObject* obj)
628 obj->childrenChanged();
631 void AXObjectCache::notificationPostTimerFired(Timer<AXObjectCache>*)
633 RefPtr<Document> protectorForCacheOwner(m_document);
635 m_notificationPostTimer.stop();
637 unsigned i = 0, count = m_notificationsToPost.size();
638 for (i = 0; i < count; ++i) {
639 AccessibilityObject* obj = m_notificationsToPost[i].first.get();
640 if (!obj->axObjectID())
643 if (!obj->axObjectCache())
647 // Make sure none of the render views are in the process of being layed out.
648 // Notifications should only be sent after the renderer has finished
649 if (obj->isAccessibilityRenderObject()) {
650 AccessibilityRenderObject* renderObj = static_cast<AccessibilityRenderObject*>(obj);
651 RenderObject* renderer = renderObj->renderer();
653 ASSERT(!renderer->view().layoutState());
657 AXNotification notification = m_notificationsToPost[i].second;
658 postPlatformNotification(obj, notification);
660 if (notification == AXChildrenChanged && obj->parentObjectIfExists() && obj->lastKnownIsIgnoredValue() != obj->accessibilityIsIgnored())
661 childrenChanged(obj->parentObject());
664 m_notificationsToPost.clear();
667 void AXObjectCache::postNotification(RenderObject* renderer, AXNotification notification, bool postToElement, PostType postType)
672 stopCachingComputedObjectAttributes();
674 // Get an accessibility object that already exists. One should not be created here
675 // because a render update may be in progress and creating an AX object can re-trigger a layout
676 RefPtr<AccessibilityObject> object = get(renderer);
677 while (!object && renderer) {
678 renderer = renderer->parent();
679 object = get(renderer);
685 postNotification(object.get(), &renderer->document(), notification, postToElement, postType);
688 void AXObjectCache::postNotification(Node* node, AXNotification notification, bool postToElement, PostType postType)
693 stopCachingComputedObjectAttributes();
695 // Get an accessibility object that already exists. One should not be created here
696 // because a render update may be in progress and creating an AX object can re-trigger a layout
697 RefPtr<AccessibilityObject> object = get(node);
698 while (!object && node) {
699 node = node->parentNode();
706 postNotification(object.get(), node->document(), notification, postToElement, postType);
709 void AXObjectCache::postNotification(AccessibilityObject* object, Document* document, AXNotification notification, bool postToElement, PostType postType)
711 stopCachingComputedObjectAttributes();
713 if (object && !postToElement)
714 object = object->observableObject();
716 if (!object && document)
717 object = get(document->renderer());
722 if (postType == PostAsynchronously) {
723 m_notificationsToPost.append(std::make_pair(object, notification));
724 if (!m_notificationPostTimer.isActive())
725 m_notificationPostTimer.startOneShot(0);
727 postPlatformNotification(object, notification);
730 void AXObjectCache::checkedStateChanged(Node* node)
732 postNotification(node, AXObjectCache::AXCheckedStateChanged, true);
735 void AXObjectCache::selectedChildrenChanged(Node* node)
737 // postToElement is false so that you can pass in any child of an element and it will go up the parent tree
738 // to find the container which should send out the notification.
739 postNotification(node, AXSelectedChildrenChanged, false);
742 void AXObjectCache::selectedChildrenChanged(RenderObject* renderer)
744 // postToElement is false so that you can pass in any child of an element and it will go up the parent tree
745 // to find the container which should send out the notification.
746 postNotification(renderer, AXSelectedChildrenChanged, false);
749 void AXObjectCache::nodeTextChangeNotification(Node* node, AXTextChange textChange, unsigned offset, const String& text)
754 stopCachingComputedObjectAttributes();
756 // Delegate on the right platform
757 AccessibilityObject* obj = getOrCreate(node);
758 nodeTextChangePlatformNotification(obj, textChange, offset, text);
761 void AXObjectCache::frameLoadingEventNotification(Frame* frame, AXLoadingEvent loadingEvent)
766 // Delegate on the right platform
767 RenderView* contentRenderer = frame->contentRenderer();
768 if (!contentRenderer)
771 AccessibilityObject* obj = getOrCreate(contentRenderer);
772 frameLoadingEventPlatformNotification(obj, loadingEvent);
775 void AXObjectCache::handleScrollbarUpdate(ScrollView* view)
780 // We don't want to create a scroll view from this method, only update an existing one.
781 if (AccessibilityObject* scrollViewObject = get(view)) {
782 stopCachingComputedObjectAttributes();
783 scrollViewObject->updateChildrenIfNecessary();
787 void AXObjectCache::handleAriaExpandedChange(Node* node)
789 if (AccessibilityObject* obj = getOrCreate(node))
790 obj->handleAriaExpandedChanged();
793 void AXObjectCache::handleActiveDescendantChanged(Node* node)
795 if (AccessibilityObject* obj = getOrCreate(node))
796 obj->handleActiveDescendantChanged();
799 void AXObjectCache::handleAriaRoleChanged(Node* node)
801 stopCachingComputedObjectAttributes();
803 if (AccessibilityObject* obj = getOrCreate(node)) {
804 obj->updateAccessibilityRole();
805 obj->notifyIfIgnoredValueChanged();
809 void AXObjectCache::handleAttributeChanged(const QualifiedName& attrName, Element* element)
811 if (attrName == roleAttr)
812 handleAriaRoleChanged(element);
813 else if (attrName == altAttr || attrName == titleAttr)
814 textChanged(element);
815 else if (attrName == forAttr && isHTMLLabelElement(element))
816 labelChanged(element);
818 if (!attrName.localName().string().startsWith("aria-"))
821 if (attrName == aria_activedescendantAttr)
822 handleActiveDescendantChanged(element);
823 else if (attrName == aria_valuenowAttr || attrName == aria_valuetextAttr)
824 postNotification(element, AXObjectCache::AXValueChanged, true);
825 else if (attrName == aria_labelAttr || attrName == aria_labeledbyAttr || attrName == aria_labelledbyAttr)
826 textChanged(element);
827 else if (attrName == aria_checkedAttr)
828 checkedStateChanged(element);
829 else if (attrName == aria_selectedAttr)
830 selectedChildrenChanged(element);
831 else if (attrName == aria_expandedAttr)
832 handleAriaExpandedChange(element);
833 else if (attrName == aria_hiddenAttr)
834 childrenChanged(element->parentNode());
835 else if (attrName == aria_invalidAttr)
836 postNotification(element, AXObjectCache::AXInvalidStatusChanged, true);
838 postNotification(element, AXObjectCache::AXAriaAttributeChanged, true);
841 void AXObjectCache::labelChanged(Element* element)
843 ASSERT(isHTMLLabelElement(element));
844 HTMLElement* correspondingControl = toHTMLLabelElement(element)->control();
845 textChanged(correspondingControl);
848 void AXObjectCache::recomputeIsIgnored(RenderObject* renderer)
850 if (AccessibilityObject* obj = get(renderer))
851 obj->notifyIfIgnoredValueChanged();
854 void AXObjectCache::startCachingComputedObjectAttributesUntilTreeMutates()
856 if (!m_computedObjectAttributeCache)
857 m_computedObjectAttributeCache = AXComputedObjectAttributeCache::create();
860 void AXObjectCache::stopCachingComputedObjectAttributes()
862 if (m_computedObjectAttributeCache)
863 m_computedObjectAttributeCache.clear();
866 VisiblePosition AXObjectCache::visiblePositionForTextMarkerData(TextMarkerData& textMarkerData)
868 if (!isNodeInUse(textMarkerData.node))
869 return VisiblePosition();
871 // FIXME: Accessability should make it clear these are DOM-compliant offsets or store Position objects.
872 VisiblePosition visiblePos = VisiblePosition(createLegacyEditingPosition(textMarkerData.node, textMarkerData.offset), textMarkerData.affinity);
873 Position deepPos = visiblePos.deepEquivalent();
874 if (deepPos.isNull())
875 return VisiblePosition();
877 RenderObject* renderer = deepPos.deprecatedNode()->renderer();
879 return VisiblePosition();
881 AXObjectCache* cache = renderer->document().axObjectCache();
882 if (!cache->isIDinUse(textMarkerData.axID))
883 return VisiblePosition();
885 if (deepPos.deprecatedNode() != textMarkerData.node || deepPos.deprecatedEditingOffset() != textMarkerData.offset)
886 return VisiblePosition();
891 void AXObjectCache::textMarkerDataForVisiblePosition(TextMarkerData& textMarkerData, const VisiblePosition& visiblePos)
893 // This memory must be bzero'd so instances of TextMarkerData can be tested for byte-equivalence.
894 // This also allows callers to check for failure by looking at textMarkerData upon return.
895 memset(&textMarkerData, 0, sizeof(TextMarkerData));
897 if (visiblePos.isNull())
900 Position deepPos = visiblePos.deepEquivalent();
901 Node* domNode = deepPos.deprecatedNode();
906 if (domNode->isHTMLElement()) {
907 HTMLInputElement* inputElement = domNode->toInputElement();
908 if (inputElement && inputElement->isPasswordField())
912 // find or create an accessibility object for this node
913 AXObjectCache* cache = domNode->document()->axObjectCache();
914 RefPtr<AccessibilityObject> obj = cache->getOrCreate(domNode);
916 textMarkerData.axID = obj.get()->axObjectID();
917 textMarkerData.node = domNode;
918 textMarkerData.offset = deepPos.deprecatedEditingOffset();
919 textMarkerData.affinity = visiblePos.affinity();
921 cache->setNodeInUse(domNode);
924 const Element* AXObjectCache::rootAXEditableElement(const Node* node)
926 const Element* result = node->rootEditableElement();
927 const Element* element = node->isElementNode() ? toElement(node) : node->parentElement();
929 for (; element; element = element->parentElement()) {
930 if (nodeIsTextControl(element))
937 bool AXObjectCache::nodeIsTextControl(const Node* node)
942 const AccessibilityObject* axObject = getOrCreate(const_cast<Node*>(node));
943 return axObject && axObject->isTextControl();
946 bool isNodeAriaVisible(Node* node)
951 if (!node->isElementNode())
954 return equalIgnoringCase(toElement(node)->getAttribute(aria_hiddenAttr), "false");
957 AXAttributeCacheEnabler::AXAttributeCacheEnabler(AXObjectCache* cache)
961 m_cache->startCachingComputedObjectAttributesUntilTreeMutates();
964 AXAttributeCacheEnabler::~AXAttributeCacheEnabler()
967 m_cache->stopCachingComputedObjectAttributes();
970 } // namespace WebCore
972 #endif // HAVE(ACCESSIBILITY)