1 /* 2 * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * 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. 12 * 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. 24 */ 25 26 #ifndef AXObjectCache_h 27 #define AXObjectCache_h 28 29 #include "AccessibilityObject.h" 30 #include "EventHandler.h" 31 #include "Timer.h" 32 #include <limits.h> 33 #include <wtf/HashMap.h> 34 #include <wtf/HashSet.h> 35 #include <wtf/RefPtr.h> 36 37 #ifdef __OBJC__ 38 @class WebCoreTextMarker; 39 #else 40 class WebCoreTextMarker; 41 #endif 42 43 namespace WebCore { 44 45 class RenderObject; 46 class String; 47 class VisiblePosition; 48 class AccessibilityObject; 49 class Node; 50 51 typedef unsigned AXID; 52 53 struct TextMarkerData { 54 AXID axID; 55 Node* node; 56 int offset; 57 EAffinity affinity; 58 }; 59 60 class AXObjectCache { 61 public: 62 AXObjectCache(); 63 ~AXObjectCache(); 64 65 // to be used with render objects 66 AccessibilityObject* getOrCreate(RenderObject*); 67 68 // used for objects without backing elements 69 AccessibilityObject* getOrCreate(AccessibilityRole); 70 71 // will only return the AccessibilityObject if it already exists 72 AccessibilityObject* get(RenderObject*); 73 74 void remove(RenderObject*); 75 void remove(AXID); 76 77 void detachWrapper(AccessibilityObject*); 78 void attachWrapper(AccessibilityObject*); 79 void postNotification(RenderObject*, const String&, bool postToElement); 80 void postPlatformNotification(AccessibilityObject*, const String&); 81 void childrenChanged(RenderObject*); 82 void selectedChildrenChanged(RenderObject*); 83 void handleActiveDescendantChanged(RenderObject*); 84 void handleAriaRoleChanged(RenderObject*); 85 void handleFocusedUIElementChanged(); 86 #if PLATFORM(GTK) 87 void handleFocusedUIElementChangedWithRenderers(RenderObject*, RenderObject*); 88 #endif enableAccessibility()89 static void enableAccessibility() { gAccessibilityEnabled = true; } enableEnhancedUserInterfaceAccessibility()90 static void enableEnhancedUserInterfaceAccessibility() { gAccessibilityEnhancedUserInterfaceEnabled = true; } 91 accessibilityEnabled()92 static bool accessibilityEnabled() { return gAccessibilityEnabled; } accessibilityEnhancedUserInterfaceEnabled()93 static bool accessibilityEnhancedUserInterfaceEnabled() { return gAccessibilityEnhancedUserInterfaceEnabled; } 94 95 void removeAXID(AccessibilityObject*); isIDinUse(AXID id)96 bool isIDinUse(AXID id) const { return m_idsInUse.contains(id); } 97 98 // Text marker utilities. 99 static void textMarkerDataForVisiblePosition(TextMarkerData&, const VisiblePosition&); 100 static VisiblePosition visiblePositionForTextMarkerData(TextMarkerData&); 101 102 private: 103 HashMap<AXID, RefPtr<AccessibilityObject> > m_objects; 104 HashMap<RenderObject*, AXID> m_renderObjectMapping; 105 static bool gAccessibilityEnabled; 106 static bool gAccessibilityEnhancedUserInterfaceEnabled; 107 108 HashSet<AXID> m_idsInUse; 109 110 Timer<AXObjectCache> m_notificationPostTimer; 111 Vector<pair<RefPtr<AccessibilityObject>, const String> > m_notificationsToPost; 112 void notificationPostTimerFired(Timer<AXObjectCache>*); 113 114 AXID getAXID(AccessibilityObject*); 115 bool nodeIsAriaType(Node* node, String role); 116 }; 117 118 #if !HAVE(ACCESSIBILITY) handleActiveDescendantChanged(RenderObject *)119 inline void AXObjectCache::handleActiveDescendantChanged(RenderObject*) { } handleAriaRoleChanged(RenderObject *)120 inline void AXObjectCache::handleAriaRoleChanged(RenderObject*) { } handleFocusedUIElementChanged()121 inline void AXObjectCache::handleFocusedUIElementChanged() { } detachWrapper(AccessibilityObject *)122 inline void AXObjectCache::detachWrapper(AccessibilityObject*) { } attachWrapper(AccessibilityObject *)123 inline void AXObjectCache::attachWrapper(AccessibilityObject*) { } selectedChildrenChanged(RenderObject *)124 inline void AXObjectCache::selectedChildrenChanged(RenderObject*) { } postNotification(RenderObject *,const String &,bool postToElement)125 inline void AXObjectCache::postNotification(RenderObject*, const String&, bool postToElement) { } postPlatformNotification(AccessibilityObject *,const String &)126 inline void AXObjectCache::postPlatformNotification(AccessibilityObject*, const String&) { } 127 #if PLATFORM(GTK) handleFocusedUIElementChangedWithRenderers(RenderObject *,RenderObject *)128 inline void AXObjectCache::handleFocusedUIElementChangedWithRenderers(RenderObject*, RenderObject*) { } 129 #endif 130 #endif 131 132 } 133 134 #endif 135