initial import
[vuplus_webkit] / Source / WebCore / accessibility / mac / AXObjectCacheMac.mm
1 /*
2  * Copyright (C) 2003, 2004, 2005, 2006, 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 #import "config.h"
27 #import "AXObjectCache.h"
28
29 #if HAVE(ACCESSIBILITY)
30
31 #import "AccessibilityObject.h"
32 #import "AccessibilityObjectWrapper.h"
33 #import "RenderObject.h"
34 #import "WebCoreSystemInterface.h"
35
36 #import <wtf/PassRefPtr.h>
37
38 #ifndef NSAccessibilityLiveRegionChangedNotification
39 #define NSAccessibilityLiveRegionChangedNotification @"AXLiveRegionChanged"
40 #endif
41
42 // The simple Cocoa calls in this file don't throw exceptions.
43
44 namespace WebCore {
45
46 void AXObjectCache::detachWrapper(AccessibilityObject* obj)
47 {
48     [obj->wrapper() detach];
49     obj->setWrapper(0);
50 }
51
52 void AXObjectCache::attachWrapper(AccessibilityObject* obj)
53 {
54     RetainPtr<AccessibilityObjectWrapper> wrapper(AdoptNS, [[AccessibilityObjectWrapper alloc] initWithAccessibilityObject:obj]);
55     obj->setWrapper(wrapper.get());
56 }
57
58 void AXObjectCache::postPlatformNotification(AccessibilityObject* obj, AXNotification notification)
59 {
60     if (!obj)
61         return;
62     
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.
68             if (obj->isTree())
69                 macNotification = NSAccessibilitySelectedRowsChangedNotification;
70             else
71                 macNotification = NSAccessibilityFocusedUIElementChangedNotification;                
72             break;
73         case AXAutocorrectionOccured:
74 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
75             macNotification = @"AXAutocorrectionOccurred";
76             break;
77 #else
78             return;
79 #endif
80         case AXFocusedUIElementChanged:
81             macNotification = NSAccessibilityFocusedUIElementChangedNotification;
82             break;
83         case AXLayoutComplete:
84             macNotification = "AXLayoutComplete";
85             break;
86         case AXLoadComplete:
87             macNotification = "AXLoadComplete";
88             break;
89         case AXInvalidStatusChanged:
90             macNotification = "AXInvalidStatusChanged";
91             break;
92         case AXSelectedChildrenChanged:
93             macNotification = NSAccessibilitySelectedChildrenChangedNotification;
94             break;
95         case AXSelectedTextChanged:
96             macNotification = NSAccessibilitySelectedTextChangedNotification;
97             break;
98         case AXValueChanged:
99             macNotification = NSAccessibilityValueChangedNotification;
100             break;
101         case AXLiveRegionChanged:
102             macNotification = NSAccessibilityLiveRegionChangedNotification;
103             break;
104         case AXRowCountChanged:
105             macNotification = NSAccessibilityRowCountChangedNotification;
106             break;
107 #ifndef BUILDING_ON_LEOPARD
108         case AXRowExpanded:
109             macNotification = NSAccessibilityRowExpandedNotification;
110             break;
111         case AXRowCollapsed:
112             macNotification = NSAccessibilityRowCollapsedNotification;
113             break;
114 #endif
115             // Does not exist on Mac.
116         case AXCheckedStateChanged:
117         default:
118             return;
119     }
120     
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);
124     
125     NSAccessibilityPostNotification(obj->wrapper(), macNotification);
126     
127     // Used by DRT to know when notifications are posted.
128     [obj->wrapper() accessibilityPostedNotification:macNotification];
129 }
130
131 void AXObjectCache::nodeTextChangePlatformNotification(AccessibilityObject*, AXTextChange, unsigned, unsigned)
132 {
133 }
134
135 void AXObjectCache::handleFocusedUIElementChanged(RenderObject*, RenderObject*)
136 {
137     wkAccessibilityHandleFocusChanged();
138 }
139
140 void AXObjectCache::handleScrolledToAnchor(const Node*)
141 {
142 }
143
144 }
145
146 #endif // HAVE(ACCESSIBILITY)