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