2 * Copyright (C) 2003, 2004, 2005, 2006, 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
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.
27 #import "AXObjectCache.h"
29 #if HAVE(ACCESSIBILITY)
31 #import "AccessibilityObject.h"
32 #import "AccessibilityObjectWrapper.h"
33 #import "RenderObject.h"
34 #import "WebCoreSystemInterface.h"
36 #import <wtf/PassRefPtr.h>
38 #ifndef NSAccessibilityLiveRegionChangedNotification
39 #define NSAccessibilityLiveRegionChangedNotification @"AXLiveRegionChanged"
42 // The simple Cocoa calls in this file don't throw exceptions.
46 void AXObjectCache::detachWrapper(AccessibilityObject* obj)
48 [obj->wrapper() detach];
52 void AXObjectCache::attachWrapper(AccessibilityObject* obj)
54 RetainPtr<AccessibilityObjectWrapper> wrapper(AdoptNS, [[AccessibilityObjectWrapper alloc] initWithAccessibilityObject:obj]);
55 obj->setWrapper(wrapper.get());
58 void AXObjectCache::postPlatformNotification(AccessibilityObject* obj, AXNotification notification)
63 // Some notifications are unique to Safari and do not have NSAccessibility equivalents.
64 String macNotification;
65 switch (notification) {
66 case AXActiveDescendantChanged:
67 // An active descendant change for trees means a selected rows change.
69 macNotification = NSAccessibilitySelectedRowsChangedNotification;
71 macNotification = NSAccessibilityFocusedUIElementChangedNotification;
73 case AXAutocorrectionOccured:
74 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
75 macNotification = @"AXAutocorrectionOccurred";
80 case AXFocusedUIElementChanged:
81 macNotification = NSAccessibilityFocusedUIElementChangedNotification;
83 case AXLayoutComplete:
84 macNotification = "AXLayoutComplete";
87 macNotification = "AXLoadComplete";
89 case AXInvalidStatusChanged:
90 macNotification = "AXInvalidStatusChanged";
92 case AXSelectedChildrenChanged:
93 macNotification = NSAccessibilitySelectedChildrenChangedNotification;
95 case AXSelectedTextChanged:
96 macNotification = NSAccessibilitySelectedTextChangedNotification;
99 macNotification = NSAccessibilityValueChangedNotification;
101 case AXLiveRegionChanged:
102 macNotification = NSAccessibilityLiveRegionChangedNotification;
104 case AXRowCountChanged:
105 macNotification = NSAccessibilityRowCountChangedNotification;
107 #ifndef BUILDING_ON_LEOPARD
109 macNotification = NSAccessibilityRowExpandedNotification;
112 macNotification = NSAccessibilityRowCollapsedNotification;
115 // Does not exist on Mac.
116 case AXCheckedStateChanged:
121 // NSAccessibilityPostNotification will call this method, (but not when running DRT), so ASSERT here to make sure it does not crash.
122 // https://bugs.webkit.org/show_bug.cgi?id=46662
123 ASSERT([obj->wrapper() accessibilityIsIgnored] || true);
125 NSAccessibilityPostNotification(obj->wrapper(), macNotification);
127 // Used by DRT to know when notifications are posted.
128 [obj->wrapper() accessibilityPostedNotification:macNotification];
131 void AXObjectCache::nodeTextChangePlatformNotification(AccessibilityObject*, AXTextChange, unsigned, unsigned)
135 void AXObjectCache::handleFocusedUIElementChanged(RenderObject*, RenderObject*)
137 wkAccessibilityHandleFocusChanged();
140 void AXObjectCache::handleScrolledToAnchor(const Node*)
146 #endif // HAVE(ACCESSIBILITY)