2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / WebCore / page / AXObjectCache.h
blob5e95f74bad6744f8b3316e7ed0e9027b2ae2abd1
1 /*
2 * Copyright (C) 2003, 2006, 2007, 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
6 * are met:
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"
30 #include <limits.h>
31 #include <wtf/HashMap.h>
32 #include <wtf/HashSet.h>
33 #include <wtf/RefPtr.h>
35 #ifdef __OBJC__
36 @class WebCoreTextMarker;
37 #else
38 class WebCoreTextMarker;
39 #endif
41 namespace WebCore {
43 class RenderObject;
44 class String;
45 class VisiblePosition;
46 class AccessibilityObject;
47 class Node;
49 typedef unsigned AXID;
51 struct TextMarkerData {
52 AXID axID;
53 Node* node;
54 int offset;
55 EAffinity affinity;
58 class AXObjectCache {
59 public:
60 ~AXObjectCache();
62 // to be used with render objects
63 AccessibilityObject* get(RenderObject*);
65 // used for objects without backing elements
66 AccessibilityObject* get(AccessibilityRole);
68 void remove(RenderObject*);
69 void remove(AXID);
71 void detachWrapper(AccessibilityObject*);
72 void attachWrapper(AccessibilityObject*);
73 void postNotification(RenderObject*, const String&);
74 void postNotificationToElement(RenderObject*, const String&);
75 void childrenChanged(RenderObject*);
76 void selectedChildrenChanged(RenderObject*);
77 void handleActiveDescendantChanged(RenderObject*);
78 void handleAriaRoleChanged(RenderObject*);
79 void handleFocusedUIElementChanged();
80 static void enableAccessibility() { gAccessibilityEnabled = true; }
81 static void enableEnhancedUserInterfaceAccessibility() { gAccessibilityEnhancedUserInterfaceEnabled = true; }
83 static bool accessibilityEnabled() { return gAccessibilityEnabled; }
84 static bool accessibilityEnhancedUserInterfaceEnabled() { return gAccessibilityEnhancedUserInterfaceEnabled; }
86 void removeAXID(AccessibilityObject*);
87 bool isIDinUse(AXID id) const { return m_idsInUse.contains(id); }
89 private:
90 HashMap<AXID, RefPtr<AccessibilityObject> > m_objects;
91 HashMap<RenderObject*, AXID> m_renderObjectMapping;
92 static bool gAccessibilityEnabled;
93 static bool gAccessibilityEnhancedUserInterfaceEnabled;
95 HashSet<AXID> m_idsInUse;
97 AXID getAXID(AccessibilityObject*);
100 #if !HAVE(ACCESSIBILITY)
101 inline void AXObjectCache::handleActiveDescendantChanged(RenderObject*) { }
102 inline void AXObjectCache::handleAriaRoleChanged(RenderObject*) { }
103 inline void AXObjectCache::handleFocusedUIElementChanged() { }
104 inline void AXObjectCache::detachWrapper(AccessibilityObject*) { }
105 inline void AXObjectCache::attachWrapper(AccessibilityObject*) { }
106 inline void AXObjectCache::selectedChildrenChanged(RenderObject*) { }
107 inline void AXObjectCache::postNotification(RenderObject*, const String&) { }
108 inline void AXObjectCache::postNotificationToElement(RenderObject*, const String&) { }
109 #endif
113 #endif