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 <execinfo.h> | 5 #include <execinfo.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 9 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/mac/foundation_util.h" | 13 #include "base/mac/foundation_util.h" |
14 #include "base/mac/scoped_cftyperef.h" | 14 #include "base/mac/scoped_cftyperef.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "content/app/strings/grit/content_strings.h" | 18 #include "content/app/strings/grit/content_strings.h" |
19 #include "content/browser/accessibility/browser_accessibility_mac.h" | 19 #include "content/browser/accessibility/browser_accessibility_mac.h" |
20 #include "content/browser/accessibility/browser_accessibility_manager.h" | 20 #include "content/browser/accessibility/browser_accessibility_manager.h" |
21 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" | 21 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" |
22 #include "content/browser/accessibility/one_shot_accessibility_tree_search.h" | 22 #include "content/browser/accessibility/one_shot_accessibility_tree_search.h" |
23 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
24 #include "third_party/skia/include/core/SkColor.h" | 24 #include "third_party/skia/include/core/SkColor.h" |
| 25 #include "ui/accessibility/ax_position.h" |
| 26 #include "ui/accessibility/ax_range.h" |
25 #import "ui/accessibility/platform/ax_platform_node_mac.h" | 27 #import "ui/accessibility/platform/ax_platform_node_mac.h" |
26 | 28 |
27 using content::AXTreeIDRegistry; | 29 using content::AXTreeIDRegistry; |
28 using content::AccessibilityMatchPredicate; | 30 using content::AccessibilityMatchPredicate; |
29 using content::BrowserAccessibility; | 31 using content::BrowserAccessibility; |
30 using content::BrowserAccessibilityDelegate; | 32 using content::BrowserAccessibilityDelegate; |
31 using content::BrowserAccessibilityManager; | 33 using content::BrowserAccessibilityManager; |
32 using content::BrowserAccessibilityManagerMac; | 34 using content::BrowserAccessibilityManagerMac; |
33 using content::ContentClient; | 35 using content::ContentClient; |
34 using content::OneShotAccessibilityTreeSearch; | 36 using content::OneShotAccessibilityTreeSearch; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 @"AXTextMarkerRangeForUnorderedTextMarkers"; | 89 @"AXTextMarkerRangeForUnorderedTextMarkers"; |
88 NSString* const NSAccessibilityIndexForChildUIElementParameterizedAttribute = | 90 NSString* const NSAccessibilityIndexForChildUIElementParameterizedAttribute = |
89 @"AXIndexForChildUIElement"; | 91 @"AXIndexForChildUIElement"; |
90 | 92 |
91 // Actions. | 93 // Actions. |
92 NSString* const NSAccessibilityScrollToVisibleAction = @"AXScrollToVisible"; | 94 NSString* const NSAccessibilityScrollToVisibleAction = @"AXScrollToVisible"; |
93 | 95 |
94 // A mapping from an accessibility attribute to its method name. | 96 // A mapping from an accessibility attribute to its method name. |
95 NSDictionary* attributeToMethodNameMap = nil; | 97 NSDictionary* attributeToMethodNameMap = nil; |
96 | 98 |
97 struct AXTextMarkerData { | |
98 AXTreeIDRegistry::AXTreeID tree_id; | |
99 int32_t node_id; | |
100 int offset; | |
101 ui::AXTextAffinity affinity; | |
102 }; | |
103 | |
104 // VoiceOver uses -1 to mean "no limit" for AXResultsLimit. | 99 // VoiceOver uses -1 to mean "no limit" for AXResultsLimit. |
105 const int kAXResultsLimitNoLimit = -1; | 100 const int kAXResultsLimitNoLimit = -1; |
106 | 101 |
107 extern "C" { | 102 extern "C" { |
108 | 103 |
109 // See http://openradar.appspot.com/9896491. This SPI has been tested on 10.5, | 104 // See http://openradar.appspot.com/9896491. This SPI has been tested on 10.5, |
110 // 10.6, and 10.7. It allows accessibility clients to observe events posted on | 105 // 10.6, and 10.7. It allows accessibility clients to observe events posted on |
111 // this object. | 106 // this object. |
112 void NSAccessibilityUnregisterUniqueIdForUIElement(id element); | 107 void NSAccessibilityUnregisterUniqueIdForUIElement(id element); |
113 | 108 |
(...skipping 18 matching lines...) Expand all Loading... |
132 AXTextMarkerRef AXTextMarkerRangeCopyEndMarker( | 127 AXTextMarkerRef AXTextMarkerRangeCopyEndMarker( |
133 AXTextMarkerRangeRef text_marker_range); | 128 AXTextMarkerRangeRef text_marker_range); |
134 | 129 |
135 #endif // MAC_OS_X_VERSION_10_11 | 130 #endif // MAC_OS_X_VERSION_10_11 |
136 | 131 |
137 } // extern "C" | 132 } // extern "C" |
138 | 133 |
139 id CreateTextMarker(const BrowserAccessibility& object, | 134 id CreateTextMarker(const BrowserAccessibility& object, |
140 int offset, | 135 int offset, |
141 ui::AXTextAffinity affinity) { | 136 ui::AXTextAffinity affinity) { |
142 AXTextMarkerData marker_data; | 137 if (!object.instance_active()) |
143 marker_data.tree_id = object.manager() ? object.manager()->ax_tree_id() : -1; | 138 return nil; |
144 marker_data.node_id = object.GetId(); | 139 |
145 marker_data.offset = offset; | 140 const auto manager = object.manager(); |
146 marker_data.affinity = affinity; | 141 DCHECK(manager); |
| 142 auto marker_data = AXPlatformPosition::CreateTextPosition( |
| 143 manager->ax_tree_id(), object.node_id(), offset); |
| 144 marker_data->set_affinity(affinity); |
147 return (id)base::mac::CFTypeRefToNSObjectAutorelease(AXTextMarkerCreate( | 145 return (id)base::mac::CFTypeRefToNSObjectAutorelease(AXTextMarkerCreate( |
148 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(&marker_data), | 146 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(marker_data), |
149 sizeof(marker_data))); | 147 sizeof(*marker_data))); |
150 } | 148 } |
151 | 149 |
152 id CreateTextMarkerRange(const BrowserAccessibility& start_object, | 150 id CreateTextMarkerRange(const BrowserAccessibility& start_object, |
153 int start_offset, | 151 int start_offset, |
154 ui::AXTextAffinity start_affinity, | 152 ui::AXTextAffinity start_affinity, |
155 const BrowserAccessibility& end_object, | 153 const BrowserAccessibility& end_object, |
156 int end_offset, | 154 int end_offset, |
157 ui::AXTextAffinity end_affinity) { | 155 ui::AXTextAffinity end_affinity) { |
158 id start_marker = CreateTextMarker( | 156 id start_marker = CreateTextMarker( |
159 start_object, start_offset, start_affinity); | 157 start_object, start_offset, start_affinity); |
160 id end_marker = CreateTextMarker(end_object, end_offset, end_affinity); | 158 id end_marker = CreateTextMarker(end_object, end_offset, end_affinity); |
161 return (id)base::mac::CFTypeRefToNSObjectAutorelease( | 159 return (id)base::mac::CFTypeRefToNSObjectAutorelease( |
162 AXTextMarkerRangeCreate(kCFAllocatorDefault, start_marker, end_marker)); | 160 AXTextMarkerRangeCreate(kCFAllocatorDefault, start_marker, end_marker)); |
163 } | 161 } |
164 | 162 |
165 bool GetTextMarkerData(AXTextMarkerRef text_marker, | 163 bool GetTextMarkerData(AXTextMarkerRef text_marker, |
166 BrowserAccessibility** object, | 164 BrowserAccessibility** object, |
167 int* offset, | 165 int* offset, |
168 ui::AXTextAffinity* affinity) { | 166 ui::AXTextAffinity* affinity) { |
169 DCHECK(text_marker); | 167 DCHECK(text_marker); |
170 DCHECK(object && offset); | 168 DCHECK(object && offset); |
171 const auto* marker_data = reinterpret_cast<const AXTextMarkerData*>( | 169 const auto* marker_data = reinterpret_cast<const AXPlatformPosition*>( |
172 AXTextMarkerGetBytePtr(text_marker)); | 170 AXTextMarkerGetBytePtr(text_marker)); |
173 if (!marker_data) | 171 if (!marker_data) |
174 return false; | 172 return false; |
175 | 173 |
176 const BrowserAccessibilityManager* manager = | 174 *object = marker_data->GetAnchor(); |
177 BrowserAccessibilityManager::FromID(marker_data->tree_id); | |
178 if (!manager) | |
179 return false; | |
180 | |
181 *object = manager->GetFromID(marker_data->node_id); | |
182 if (!*object) | 175 if (!*object) |
183 return false; | 176 return false; |
184 | 177 |
185 *offset = marker_data->offset; | 178 *offset = marker_data->get_text_offset(); |
186 if (*offset < 0) | 179 if (*offset < 0) |
187 return false; | 180 return false; |
188 | 181 |
189 *affinity = marker_data->affinity; | 182 *affinity = marker_data->get_affinity(); |
190 | |
191 return true; | 183 return true; |
192 } | 184 } |
193 | 185 |
194 bool GetTextMarkerRange(AXTextMarkerRangeRef marker_range, | 186 bool GetTextMarkerRange(AXTextMarkerRangeRef marker_range, |
195 BrowserAccessibility** start_object, | 187 BrowserAccessibility** start_object, |
196 int* start_offset, | 188 int* start_offset, |
197 ui::AXTextAffinity* start_affinity, | 189 ui::AXTextAffinity* start_affinity, |
198 BrowserAccessibility** end_object, | 190 BrowserAccessibility** end_object, |
199 int* end_offset, | 191 int* end_offset, |
200 ui::AXTextAffinity* end_affinity) { | 192 ui::AXTextAffinity* end_affinity) { |
(...skipping 2677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2878 if (![self instanceActive]) | 2870 if (![self instanceActive]) |
2879 return [super hash]; | 2871 return [super hash]; |
2880 return browserAccessibility_->GetId(); | 2872 return browserAccessibility_->GetId(); |
2881 } | 2873 } |
2882 | 2874 |
2883 - (BOOL)accessibilityShouldUseUniqueId { | 2875 - (BOOL)accessibilityShouldUseUniqueId { |
2884 return YES; | 2876 return YES; |
2885 } | 2877 } |
2886 | 2878 |
2887 @end | 2879 @end |
OLD | NEW |