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
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "AXObjectCache.h"
30 #include "AccessibilityObject.h"
34 #include "RenderObject.h"
40 void AXObjectCache::detachWrapper(AccessibilityObject* obj)
42 // On Windows, AccessibilityObjects are created when get_accChildCount is
43 // called, but they are not wrapped until get_accChild is called, so this
44 // object may not have a wrapper.
45 if (AccessibilityObjectWrapper* wrapper = obj->wrapper())
49 void AXObjectCache::attachWrapper(AccessibilityObject*)
51 // On Windows, AccessibilityObjects are wrapped when the accessibility
52 // software requests them via get_accChild.
55 void AXObjectCache::handleScrolledToAnchor(const Node* anchorNode)
57 // The anchor node may not be accessible. Post the notification for the
58 // first accessible object.
59 postPlatformNotification(AccessibilityObject::firstAccessibleObjectFromNode(anchorNode), AXScrolledToAnchor);
62 void AXObjectCache::postPlatformNotification(AccessibilityObject* obj, AXNotification notification)
67 Document* document = obj->document();
71 Page* page = document->page();
72 if (!page || !page->chrome()->platformPageClient())
76 switch (notification) {
77 case AXFocusedUIElementChanged:
78 case AXActiveDescendantChanged:
79 msaaEvent = EVENT_OBJECT_FOCUS;
82 case AXScrolledToAnchor:
83 msaaEvent = EVENT_SYSTEM_SCROLLINGSTART;
87 case AXMenuListValueChanged:
88 msaaEvent = EVENT_OBJECT_VALUECHANGE;
91 case AXMenuListItemSelected:
92 msaaEvent = EVENT_OBJECT_SELECTION;
99 // Windows will end up calling get_accChild() on the root accessible
100 // object for the WebView, passing the child ID that we specify below. We
101 // negate the AXID so we know that the caller is passing the ID of an
102 // element, not the index of a child element.
104 ASSERT(obj->axObjectID() >= 1);
105 ASSERT(obj->axObjectID() <= numeric_limits<LONG>::max());
107 NotifyWinEvent(msaaEvent, page->chrome()->platformPageClient(), OBJID_CLIENT, -static_cast<LONG>(obj->axObjectID()));
110 void AXObjectCache::nodeTextChangePlatformNotification(AccessibilityObject*, AXTextChange, unsigned, unsigned)
114 AXID AXObjectCache::platformGenerateAXID() const
116 static AXID lastUsedID = 0;
118 // Generate a new ID. Windows accessibility relies on a positive AXID,
119 // ranging from 1 to LONG_MAX.
120 AXID objID = lastUsedID;
123 objID %= std::numeric_limits<LONG>::max();
124 } while (objID == 0 || HashTraits<AXID>::isDeletedValue(objID) || m_idsInUse.contains(objID));
126 ASSERT(objID >= 1 && objID <= std::numeric_limits<LONG>::max());
133 void AXObjectCache::handleFocusedUIElementChanged(RenderObject*, RenderObject* newFocusedRenderer)
135 if (!newFocusedRenderer)
138 Page* page = newFocusedRenderer->document()->page();
139 if (!page || !page->chrome()->platformPageClient())
142 AccessibilityObject* focusedObject = focusedUIElementForPage(page);
146 ASSERT(!focusedObject->accessibilityIsIgnored());
148 postPlatformNotification(focusedObject, AXFocusedUIElementChanged);
151 } // namespace WebCore