cc33a2bce2ed447466235b29914c48f799c2288f
[WebKit-https.git] / Source / WebCore / accessibility / ios / AXObjectCacheIOS.mm
1 /*
2  * Copyright (C) 2010 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 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 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 ENABLE(ACCESSIBILITY) && PLATFORM(IOS_FAMILY)
30
31 #import "AccessibilityObject.h"
32 #import "WebAccessibilityObjectWrapperIOS.h"
33 #import "RenderObject.h"
34
35 #import <wtf/RetainPtr.h>
36
37 namespace WebCore {
38     
39 void AXObjectCache::attachWrapper(AXCoreObject* obj)
40 {
41     RetainPtr<AccessibilityObjectWrapper> wrapper = adoptNS([[WebAccessibilityObjectWrapper alloc] initWithAccessibilityObject:obj]);
42     obj->setWrapper(wrapper.get());
43 }
44
45 void AXObjectCache::postPlatformNotification(AXCoreObject* obj, AXNotification notification)
46 {
47     if (!obj)
48         return;
49
50     NSString *notificationString = nil;
51     switch (notification) {
52         case AXActiveDescendantChanged:
53         case AXFocusedUIElementChanged:
54             [obj->wrapper() postFocusChangeNotification];
55             notificationString = @"AXFocusChanged";
56             break;
57         case AXSelectedTextChanged:
58             [obj->wrapper() postSelectedTextChangeNotification];
59             break;
60         case AXLayoutComplete:
61             [obj->wrapper() postLayoutChangeNotification];
62             break;
63         case AXLiveRegionChanged:
64             [obj->wrapper() postLiveRegionChangeNotification];
65             break;
66         case AXLiveRegionCreated:
67             [obj->wrapper() postLiveRegionCreatedNotification];
68             break;
69         case AXChildrenChanged:
70             [obj->wrapper() postChildrenChangedNotification];
71             break;
72         case AXLoadComplete:
73             [obj->wrapper() postLoadCompleteNotification];
74             break;
75         case AXInvalidStatusChanged:
76             [obj->wrapper() postInvalidStatusChangedNotification];
77             break;
78         case AXValueChanged:
79             [obj->wrapper() postValueChangedNotification];
80             break;
81         case AXExpandedChanged:
82             [obj->wrapper() postExpandedChangedNotification];
83             break;
84         case AXSelectedChildrenChanged:
85         case AXCheckedStateChanged:
86         default:
87             break;
88     }
89     
90     // Used by DRT to know when notifications are posted.
91     if (notificationString)
92         [obj->wrapper() accessibilityPostedNotification:notificationString];
93 }
94
95 void AXObjectCache::postTextStateChangePlatformNotification(AccessibilityObject* object, const AXTextStateChangeIntent&, const VisibleSelection&)
96 {
97     postPlatformNotification(object, AXSelectedTextChanged);
98 }
99
100 void AXObjectCache::postTextStateChangePlatformNotification(AccessibilityObject* object, AXTextEditType, const String&, const VisiblePosition&)
101 {
102     postPlatformNotification(object, AXValueChanged);
103 }
104
105 void AXObjectCache::postTextReplacementPlatformNotification(AccessibilityObject* object, AXTextEditType, const String&, AXTextEditType, const String&, const VisiblePosition&)
106 {
107     postPlatformNotification(object, AXValueChanged);
108 }
109
110 void AXObjectCache::postTextReplacementPlatformNotificationForTextControl(AccessibilityObject* object, const String&, const String&, HTMLTextFormControlElement&)
111 {
112     postPlatformNotification(object, AXValueChanged);
113 }
114
115 void AXObjectCache::frameLoadingEventPlatformNotification(AccessibilityObject* axFrameObject, AXLoadingEvent loadingEvent)
116 {
117     if (!axFrameObject)
118         return;
119     
120     if (loadingEvent == AXLoadingFinished && axFrameObject->document() == axFrameObject->topDocument())
121         postPlatformNotification(axFrameObject, AXLoadComplete);
122 }
123
124 void AXObjectCache::platformHandleFocusedUIElementChanged(Node*, Node* newNode)
125 {
126     postNotification(newNode, AXFocusedUIElementChanged, TargetElement, PostAsynchronously);
127 }
128
129 void AXObjectCache::handleScrolledToAnchor(const Node*)
130 {
131 }
132
133 void AXObjectCache::platformPerformDeferredCacheUpdate()
134 {
135 }
136
137 }
138
139 #endif // ENABLE(ACCESSIBILITY) && PLATFORM(IOS_FAMILY)