2 * Copyright (C) 2008 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.
30 #include "AXObjectCache.h"
32 #include "AccessibilityListBox.h"
33 #include "AccessibilityListBoxOption.h"
34 #include "AccessibilityRenderObject.h"
35 #include "RenderObject.h"
37 #include <wtf/PassRefPtr.h>
41 bool AXObjectCache::gAccessibilityEnabled = false;
43 AXObjectCache::~AXObjectCache()
45 HashMap<AXID, RefPtr<AccessibilityObject> >::iterator end = m_objects.end();
46 for (HashMap<AXID, RefPtr<AccessibilityObject> >::iterator it = m_objects.begin(); it != end; ++it) {
47 AccessibilityObject* obj = (*it).second.get();
53 AccessibilityObject* AXObjectCache::get(RenderObject* renderer)
58 RefPtr<AccessibilityObject> obj = 0;
59 AXID axID = m_renderObjectMapping.get(renderer);
60 ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
63 obj = m_objects.get(axID).get();
66 if (renderer->isListBox())
67 obj = AccessibilityListBox::create(renderer);
69 obj = AccessibilityRenderObject::create(renderer);
73 m_renderObjectMapping.set(renderer, obj.get()->axObjectID());
74 m_objects.set(obj.get()->axObjectID(), obj);
75 attachWrapper(obj.get());
81 AccessibilityObject* AXObjectCache::get(AccessibilityRole role)
83 RefPtr<AccessibilityObject> obj = 0;
85 // will be filled in...
87 case ListBoxOptionRole:
88 obj = AccessibilityListBoxOption::create();
99 m_objects.set(obj->axObjectID(), obj);
100 attachWrapper(obj.get());
104 void AXObjectCache::remove(AXID axID)
109 // first fetch object to operate some cleanup functions on it
110 AccessibilityObject* obj = m_objects.get(axID).get();
118 // finally remove the object
119 if (!m_objects.take(axID)) {
123 ASSERT(m_objects.size() >= m_idsInUse.size());
126 void AXObjectCache::remove(RenderObject* renderer)
131 AXID axID = m_renderObjectMapping.get(renderer);
133 m_renderObjectMapping.remove(renderer);
136 AXID AXObjectCache::getAXID(AccessibilityObject* obj)
138 // check for already-assigned ID
139 AXID objID = obj->axObjectID();
141 ASSERT(m_idsInUse.contains(objID));
146 static AXID lastUsedID = 0;
150 while (objID == 0 || HashTraits<AXID>::isDeletedValue(objID) || m_idsInUse.contains(objID));
151 m_idsInUse.add(objID);
153 obj->setAXObjectID(objID);
158 void AXObjectCache::removeAXID(AccessibilityObject* obj)
160 AXID objID = obj->axObjectID();
163 ASSERT(!HashTraits<AXID>::isDeletedValue(objID));
164 ASSERT(m_idsInUse.contains(objID));
165 obj->setAXObjectID(0);
166 m_idsInUse.remove(objID);
169 void AXObjectCache::childrenChanged(RenderObject* renderer)
174 AXID axID = m_renderObjectMapping.get(renderer);
178 AccessibilityObject* obj = m_objects.get(axID).get();
180 obj->childrenChanged();
183 void AXObjectCache::selectedChildrenChanged(RenderObject* renderer)
185 postNotificationToElement(renderer, "AXSelectedChildrenChanged");
188 } // namespace WebCore