2 * Copyright (C) 2003, 2006, 2007, 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 COMPUTER, 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 COMPUTER, 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.
26 #ifndef AXObjectCache_h
27 #define AXObjectCache_h
29 #include "AccessibilityObject.h"
32 #include <wtf/Forward.h>
33 #include <wtf/HashMap.h>
34 #include <wtf/HashSet.h>
35 #include <wtf/RefPtr.h>
38 @class WebCoreTextMarker;
40 class WebCoreTextMarker;
45 class HTMLAreaElement;
49 class VisiblePosition;
51 struct TextMarkerData {
58 enum PostType { PostSynchronously, PostAsynchronously };
60 class AXObjectCache : public Noncopyable {
65 static AccessibilityObject* focusedUIElementForPage(const Page*);
67 // to be used with render objects
68 AccessibilityObject* getOrCreate(RenderObject*);
70 // used for objects without backing elements
71 AccessibilityObject* getOrCreate(AccessibilityRole);
73 // will only return the AccessibilityObject if it already exists
74 AccessibilityObject* get(RenderObject*);
76 void remove(RenderObject*);
79 void detachWrapper(AccessibilityObject*);
80 void attachWrapper(AccessibilityObject*);
81 void childrenChanged(RenderObject*);
82 void selectedChildrenChanged(RenderObject*);
83 // Called by a node when text or a text equivalent (e.g. alt) attribute is changed.
84 void contentChanged(RenderObject*);
86 void handleActiveDescendantChanged(RenderObject*);
87 void handleAriaRoleChanged(RenderObject*);
88 void handleFocusedUIElementChanged(RenderObject* oldFocusedRenderer, RenderObject* newFocusedRenderer);
89 void handleScrolledToAnchor(const Node* anchorNode);
90 void handleAriaExpandedChange(RenderObject*);
92 static void enableAccessibility() { gAccessibilityEnabled = true; }
93 static void enableEnhancedUserInterfaceAccessibility() { gAccessibilityEnhancedUserInterfaceEnabled = true; }
95 static bool accessibilityEnabled() { return gAccessibilityEnabled; }
96 static bool accessibilityEnhancedUserInterfaceEnabled() { return gAccessibilityEnhancedUserInterfaceEnabled; }
98 void removeAXID(AccessibilityObject*);
99 bool isIDinUse(AXID id) const { return m_idsInUse.contains(id); }
100 AXID platformGenerateAXID() const;
101 AccessibilityObject* objectFromAXID(AXID id) const { return m_objects.get(id).get(); }
103 // Text marker utilities.
104 static void textMarkerDataForVisiblePosition(TextMarkerData&, const VisiblePosition&);
105 static VisiblePosition visiblePositionForTextMarkerData(TextMarkerData&);
107 enum AXNotification {
108 AXActiveDescendantChanged,
109 AXCheckedStateChanged,
111 AXFocusedUIElementChanged,
114 AXSelectedChildrenChanged,
115 AXSelectedTextChanged,
119 AXMenuListValueChanged,
125 void postNotification(RenderObject*, AXNotification, bool postToElement, PostType = PostAsynchronously);
126 void postNotification(AccessibilityObject*, Document*, AXNotification, bool postToElement, PostType = PostAsynchronously);
133 void nodeTextChangeNotification(RenderObject*, AXTextChange, unsigned offset, unsigned count);
135 bool nodeHasRole(Node*, const AtomicString& role);
138 void postPlatformNotification(AccessibilityObject*, AXNotification);
139 void nodeTextChangePlatformNotification(AccessibilityObject*, AXTextChange, unsigned offset, unsigned count);
142 HashMap<AXID, RefPtr<AccessibilityObject> > m_objects;
143 HashMap<RenderObject*, AXID> m_renderObjectMapping;
144 static bool gAccessibilityEnabled;
145 static bool gAccessibilityEnhancedUserInterfaceEnabled;
147 HashSet<AXID> m_idsInUse;
149 Timer<AXObjectCache> m_notificationPostTimer;
150 Vector<pair<RefPtr<AccessibilityObject>, AXNotification> > m_notificationsToPost;
151 void notificationPostTimerFired(Timer<AXObjectCache>*);
153 static AccessibilityObject* focusedImageMapUIElement(HTMLAreaElement*);
155 AXID getAXID(AccessibilityObject*);
158 bool nodeHasRole(Node*, const String& role);
160 #if !HAVE(ACCESSIBILITY)
161 inline void AXObjectCache::handleActiveDescendantChanged(RenderObject*) { }
162 inline void AXObjectCache::handleAriaRoleChanged(RenderObject*) { }
163 inline void AXObjectCache::detachWrapper(AccessibilityObject*) { }
164 inline void AXObjectCache::attachWrapper(AccessibilityObject*) { }
165 inline void AXObjectCache::selectedChildrenChanged(RenderObject*) { }
166 inline void AXObjectCache::postNotification(RenderObject*, AXNotification, bool postToElement, PostType) { }
167 inline void AXObjectCache::postNotification(AccessibilityObject*, Document*, AXNotification, bool postToElement, PostType) { }
168 inline void AXObjectCache::postPlatformNotification(AccessibilityObject*, AXNotification) { }
169 inline void AXObjectCache::nodeTextChangeNotification(RenderObject*, AXTextChange, unsigned, unsigned) { }
170 inline void AXObjectCache::nodeTextChangePlatformNotification(AccessibilityObject*, AXTextChange, unsigned, unsigned) { }
171 inline void AXObjectCache::handleFocusedUIElementChanged(RenderObject*, RenderObject*) { }
172 inline void AXObjectCache::handleScrolledToAnchor(const Node*) { }
173 inline void AXObjectCache::contentChanged(RenderObject*) { }
174 inline void AXObjectCache::handleAriaExpandedChange(RenderObject*) { }