OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" | 5 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #import "base/mac/mac_util.h" | 9 #import "base/mac/mac_util.h" |
10 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 NSString* const NSAccessibilityLayoutCompleteNotification = | 51 NSString* const NSAccessibilityLayoutCompleteNotification = |
52 @"AXLayoutComplete"; | 52 @"AXLayoutComplete"; |
53 NSString* const NSAccessibilityLoadCompleteNotification = | 53 NSString* const NSAccessibilityLoadCompleteNotification = |
54 @"AXLoadComplete"; | 54 @"AXLoadComplete"; |
55 NSString* const NSAccessibilityInvalidStatusChangedNotification = | 55 NSString* const NSAccessibilityInvalidStatusChangedNotification = |
56 @"AXInvalidStatusChanged"; | 56 @"AXInvalidStatusChanged"; |
57 NSString* const NSAccessibilityLiveRegionChangedNotification = | 57 NSString* const NSAccessibilityLiveRegionChangedNotification = |
58 @"AXLiveRegionChanged"; | 58 @"AXLiveRegionChanged"; |
59 NSString* const NSAccessibilityMenuItemSelectedNotification = | 59 NSString* const NSAccessibilityMenuItemSelectedNotification = |
60 @"AXMenuItemSelected"; | 60 @"AXMenuItemSelected"; |
61 | |
62 // Attributes used for NSAccessibilitySelectedTextChangedNotification. | |
61 NSString* const NSAccessibilityTextStateChangeTypeKey = | 63 NSString* const NSAccessibilityTextStateChangeTypeKey = |
62 @"AXTextStateChangeType"; | 64 @"AXTextStateChangeType"; |
63 NSString* const NSAccessibilityTextStateSyncKey = @"AXTextStateSync"; | 65 NSString* const NSAccessibilityTextStateSyncKey = @"AXTextStateSync"; |
64 NSString* const NSAccessibilityTextSelectionDirection = | 66 NSString* const NSAccessibilityTextSelectionDirection = |
65 @"AXTextSelectionDirection"; | 67 @"AXTextSelectionDirection"; |
66 NSString* const NSAccessibilityTextSelectionGranularity = | 68 NSString* const NSAccessibilityTextSelectionGranularity = |
67 @"AXTextSelectionGranularity"; | 69 @"AXTextSelectionGranularity"; |
68 NSString* const NSAccessibilityTextSelectionChangedFocus = | 70 NSString* const NSAccessibilityTextSelectionChangedFocus = |
69 @"AXTextSelectionChangedFocus"; | 71 @"AXTextSelectionChangedFocus"; |
70 NSString* const NSAccessibilityTextChangeElement = | 72 NSString* const NSAccessibilitySelectedTextMarkerRangeAttribute = |
71 @"AXAccessibilityTextChangeElement"; | 73 @"AXSelectedTextMarkerRange"; |
74 NSString* const NSAccessibilityTextChangeElement = @"AXTextChangeElement"; | |
72 | 75 |
73 } // namespace | 76 } // namespace |
74 | 77 |
75 namespace content { | 78 namespace content { |
76 | 79 |
77 // static | 80 // static |
78 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( | 81 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( |
79 const ui::AXTreeUpdate& initial_tree, | 82 const ui::AXTreeUpdate& initial_tree, |
80 BrowserAccessibilityDelegate* delegate, | 83 BrowserAccessibilityDelegate* delegate, |
81 BrowserAccessibilityFactory* factory) { | 84 BrowserAccessibilityFactory* factory) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 mac_notification = NSAccessibilitySelectedChildrenChangedNotification; | 183 mac_notification = NSAccessibilitySelectedChildrenChangedNotification; |
181 } | 184 } |
182 break; | 185 break; |
183 case ui::AX_EVENT_DOCUMENT_SELECTION_CHANGED: { | 186 case ui::AX_EVENT_DOCUMENT_SELECTION_CHANGED: { |
184 mac_notification = NSAccessibilitySelectedTextChangedNotification; | 187 mac_notification = NSAccessibilitySelectedTextChangedNotification; |
185 if (base::mac::IsOSElCapitanOrLater()) { | 188 if (base::mac::IsOSElCapitanOrLater()) { |
186 // |NSAccessibilityPostNotificationWithUserInfo| should be used on OS X | 189 // |NSAccessibilityPostNotificationWithUserInfo| should be used on OS X |
187 // 10.11 or later to notify Voiceover about text selection changes. This | 190 // 10.11 or later to notify Voiceover about text selection changes. This |
188 // API has been present on versions of OS X since 10.7 but doesn't | 191 // API has been present on versions of OS X since 10.7 but doesn't |
189 // appear to be needed by Voiceover before version 10.11. | 192 // appear to be needed by Voiceover before version 10.11. |
193 // WebKit fires a notification both on the focused object and the root. | |
190 NSDictionary* user_info = | 194 NSDictionary* user_info = |
191 GetUserInfoForSelectedTextChangedNotification(); | 195 GetUserInfoForSelectedTextChangedNotification(); |
196 | |
197 BrowserAccessibility* focus = GetFocus(); | |
198 if (!focus) | |
199 return; | |
192 NSAccessibilityPostNotificationWithUserInfo( | 200 NSAccessibilityPostNotificationWithUserInfo( |
193 native_node, mac_notification, user_info); | 201 focus->ToBrowserAccessibilityCocoa(), mac_notification, user_info); |
202 | |
203 BrowserAccessibility* root = GetRoot(); | |
204 if (!root) | |
205 return; | |
206 NSAccessibilityPostNotificationWithUserInfo( | |
207 root->ToBrowserAccessibilityCocoa(), mac_notification, user_info); | |
194 return; | 208 return; |
195 } | 209 } |
196 break; | 210 break; |
197 } | 211 } |
198 case ui::AX_EVENT_CHECKED_STATE_CHANGED: | 212 case ui::AX_EVENT_CHECKED_STATE_CHANGED: |
199 case ui::AX_EVENT_VALUE_CHANGED: | 213 case ui::AX_EVENT_VALUE_CHANGED: |
200 mac_notification = NSAccessibilityValueChangedNotification; | 214 mac_notification = NSAccessibilityValueChangedNotification; |
201 break; | 215 break; |
202 // TODO(nektar): Need to add an event for live region created. | 216 // TODO(nektar): Need to add an event for live region created. |
203 case ui::AX_EVENT_LIVE_REGION_CHANGED: | 217 case ui::AX_EVENT_LIVE_REGION_CHANGED: |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 // internal state and find newly-added live regions this time. | 289 // internal state and find newly-added live regions this time. |
276 BrowserAccessibilityMac* root = | 290 BrowserAccessibilityMac* root = |
277 static_cast<BrowserAccessibilityMac*>(GetRoot()); | 291 static_cast<BrowserAccessibilityMac*>(GetRoot()); |
278 if (root) { | 292 if (root) { |
279 root->RecreateNativeObject(); | 293 root->RecreateNativeObject(); |
280 NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, root); | 294 NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, root); |
281 } | 295 } |
282 } | 296 } |
283 | 297 |
284 // Returns an autoreleased object. | 298 // Returns an autoreleased object. |
285 NSDictionary* BrowserAccessibilityManagerMac:: | 299 NSDictionary* |
286 GetUserInfoForSelectedTextChangedNotification() { | 300 BrowserAccessibilityManagerMac::GetUserInfoForSelectedTextChangedNotification() { |
287 NSMutableDictionary* user_info = [[[NSMutableDictionary alloc] init] | 301 NSMutableDictionary* user_info = [[[NSMutableDictionary alloc] init] |
288 autorelease]; | 302 autorelease]; |
289 [user_info setObject:[NSNumber numberWithBool:YES] | 303 [user_info setObject:[NSNumber numberWithBool:YES] |
290 forKey:NSAccessibilityTextStateSyncKey]; | 304 forKey:NSAccessibilityTextStateSyncKey]; |
291 [user_info setObject:[NSNumber numberWithInt:AXTextStateChangeTypeUnknown] | 305 [user_info setObject:[NSNumber numberWithInt:AXTextStateChangeTypeUnknown] |
292 forKey:NSAccessibilityTextStateChangeTypeKey]; | 306 forKey:NSAccessibilityTextStateChangeTypeKey]; |
293 [user_info | 307 [user_info |
294 setObject:[NSNumber numberWithInt:AXTextSelectionDirectionUnknown] | 308 setObject:[NSNumber numberWithInt:AXTextSelectionDirectionUnknown] |
295 forKey:NSAccessibilityTextSelectionDirection]; | 309 forKey:NSAccessibilityTextSelectionDirection]; |
296 [user_info | 310 [user_info |
297 setObject:[NSNumber numberWithInt:AXTextSelectionGranularityUnknown] | 311 setObject:[NSNumber numberWithInt:AXTextSelectionGranularityUnknown] |
298 forKey:NSAccessibilityTextSelectionGranularity]; | 312 forKey:NSAccessibilityTextSelectionGranularity]; |
299 [user_info setObject:[NSNumber numberWithBool:YES] | 313 [user_info setObject:[NSNumber numberWithBool:YES] |
300 forKey:NSAccessibilityTextSelectionChangedFocus]; | 314 forKey:NSAccessibilityTextSelectionChangedFocus]; |
301 // TODO(nektar): Set selected text marker range. | |
302 | 315 |
303 int32_t focus_id = GetTreeData().sel_focus_object_id; | 316 int32_t focus_id = GetTreeData().sel_focus_object_id; |
304 BrowserAccessibility* focus_object = GetFromID(focus_id); | 317 BrowserAccessibility* focus_object = GetFromID(focus_id); |
305 if (focus_object) { | 318 if (focus_object) { |
306 focus_object = focus_object->GetClosestPlatformObject(); | 319 focus_object = focus_object->GetClosestPlatformObject(); |
307 auto native_focus_object = focus_object->ToBrowserAccessibilityCocoa(); | 320 auto native_focus_object = focus_object->ToBrowserAccessibilityCocoa(); |
308 if (native_focus_object) | 321 if (native_focus_object) { |
322 LOG(ERROR) << "Marker range " << ([native_focus_object selectedTextMarkerR ange] == nil) << " " << [[native_focus_object role] UTF8String]; | |
Mark Mentovai
2016/02/19 00:33:29
Remove this LOG.
| |
323 [user_info setObject:[native_focus_object selectedTextMarkerRange] | |
324 forKey:NSAccessibilitySelectedTextMarkerRangeAttribute]; | |
309 [user_info setObject:native_focus_object | 325 [user_info setObject:native_focus_object |
310 forKey:NSAccessibilityTextChangeElement]; | 326 forKey:NSAccessibilityTextChangeElement]; |
327 } | |
311 } | 328 } |
312 | 329 |
313 return user_info; | 330 return user_info; |
314 } | 331 } |
315 | 332 |
316 } // namespace content | 333 } // namespace content |
OLD | NEW |