2 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2012 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 "RenderObject.h"
33 #import "WebAccessibilityObjectWrapperMac.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<WebAccessibilityObjectWrapper> wrapper = adoptNS([[WebAccessibilityObjectWrapper 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 NSString *macNotification;
65 switch (notification) {
66 case AXActiveDescendantChanged:
67 // An active descendant change for trees means a selected rows change.
69 macNotification = NSAccessibilitySelectedRowsChangedNotification;
71 // When a combobox uses active descendant, it means the selected item in its associated
72 // list has changed. In these cases we should use selected children changed, because
73 // we don't want the focus to change away from the combobox where the user is typing.
74 else if (obj->isComboBox())
75 macNotification = NSAccessibilitySelectedChildrenChangedNotification;
77 macNotification = NSAccessibilityFocusedUIElementChangedNotification;
79 case AXAutocorrectionOccured:
80 macNotification = @"AXAutocorrectionOccurred";
82 case AXFocusedUIElementChanged:
83 macNotification = NSAccessibilityFocusedUIElementChangedNotification;
85 case AXLayoutComplete:
86 macNotification = @"AXLayoutComplete";
89 macNotification = @"AXLoadComplete";
91 case AXInvalidStatusChanged:
92 macNotification = @"AXInvalidStatusChanged";
94 case AXSelectedChildrenChanged:
95 if (obj->isAccessibilityTable())
96 macNotification = NSAccessibilitySelectedRowsChangedNotification;
98 macNotification = NSAccessibilitySelectedChildrenChangedNotification;
100 case AXSelectedTextChanged:
101 macNotification = NSAccessibilitySelectedTextChangedNotification;
104 macNotification = NSAccessibilityValueChangedNotification;
106 case AXLiveRegionChanged:
107 macNotification = NSAccessibilityLiveRegionChangedNotification;
109 case AXRowCountChanged:
110 macNotification = NSAccessibilityRowCountChangedNotification;
113 macNotification = NSAccessibilityRowExpandedNotification;
116 macNotification = NSAccessibilityRowCollapsedNotification;
118 // Does not exist on Mac.
119 case AXCheckedStateChanged:
124 // NSAccessibilityPostNotification will call this method, (but not when running DRT), so ASSERT here to make sure it does not crash.
125 // https://bugs.webkit.org/show_bug.cgi?id=46662
126 ASSERT([obj->wrapper() accessibilityIsIgnored] || true);
128 NSAccessibilityPostNotification(obj->wrapper(), macNotification);
130 // Used by DRT to know when notifications are posted.
131 [obj->wrapper() accessibilityPostedNotification:macNotification];
134 void AXObjectCache::nodeTextChangePlatformNotification(AccessibilityObject*, AXTextChange, unsigned, const String&)
138 void AXObjectCache::frameLoadingEventPlatformNotification(AccessibilityObject*, AXLoadingEvent)
142 void AXObjectCache::handleFocusedUIElementChanged(Node*, Node*)
144 wkAccessibilityHandleFocusChanged();
147 void AXObjectCache::handleScrolledToAnchor(const Node*)
153 #endif // HAVE(ACCESSIBILITY)