| 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 const AXPlatformPositionFactory factory; |
| 143 AXPosition marker_data = factory.CreateTextPosition(manager->ax_tree_id(), |
| 144 object.node_id(), offset); |
| 145 marker_data.set_affinity(affinity); |
| 147 return (id)base::mac::CFTypeRefToNSObjectAutorelease(AXTextMarkerCreate( | 146 return (id)base::mac::CFTypeRefToNSObjectAutorelease(AXTextMarkerCreate( |
| 148 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(&marker_data), | 147 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(&marker_data), |
| 149 sizeof(marker_data))); | 148 sizeof(marker_data))); |
| 150 } | 149 } |
| 151 | 150 |
| 152 id CreateTextMarkerRange(const BrowserAccessibility& start_object, | 151 id CreateTextMarkerRange(const BrowserAccessibility& start_object, |
| 153 int start_offset, | 152 int start_offset, |
| 154 ui::AXTextAffinity start_affinity, | 153 ui::AXTextAffinity start_affinity, |
| 155 const BrowserAccessibility& end_object, | 154 const BrowserAccessibility& end_object, |
| 156 int end_offset, | 155 int end_offset, |
| 157 ui::AXTextAffinity end_affinity) { | 156 ui::AXTextAffinity end_affinity) { |
| 158 id start_marker = CreateTextMarker( | 157 id start_marker = CreateTextMarker( |
| 159 start_object, start_offset, start_affinity); | 158 start_object, start_offset, start_affinity); |
| 160 id end_marker = CreateTextMarker(end_object, end_offset, end_affinity); | 159 id end_marker = CreateTextMarker(end_object, end_offset, end_affinity); |
| 161 return (id)base::mac::CFTypeRefToNSObjectAutorelease( | 160 return (id)base::mac::CFTypeRefToNSObjectAutorelease( |
| 162 AXTextMarkerRangeCreate(kCFAllocatorDefault, start_marker, end_marker)); | 161 AXTextMarkerRangeCreate(kCFAllocatorDefault, start_marker, end_marker)); |
| 163 } | 162 } |
| 164 | 163 |
| 165 bool GetTextMarkerData(AXTextMarkerRef text_marker, | 164 bool GetTextMarkerData(AXTextMarkerRef text_marker, |
| 166 BrowserAccessibility** object, | 165 BrowserAccessibility** object, |
| 167 int* offset, | 166 int* offset, |
| 168 ui::AXTextAffinity* affinity) { | 167 ui::AXTextAffinity* affinity) { |
| 169 DCHECK(text_marker); | 168 DCHECK(text_marker); |
| 170 DCHECK(object && offset); | 169 DCHECK(object && offset); |
| 171 const auto* marker_data = reinterpret_cast<const AXTextMarkerData*>( | 170 const auto* marker_data = |
| 172 AXTextMarkerGetBytePtr(text_marker)); | 171 reinterpret_cast<const AXPosition*>(AXTextMarkerGetBytePtr(text_marker)); |
| 173 if (!marker_data) | 172 if (!marker_data) |
| 174 return false; | 173 return false; |
| 175 | 174 |
| 176 const BrowserAccessibilityManager* manager = | 175 *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) | 176 if (!*object) |
| 183 return false; | 177 return false; |
| 184 | 178 |
| 185 *offset = marker_data->offset; | 179 *offset = marker_data->get_text_offset(); |
| 186 if (*offset < 0) | 180 if (*offset < 0) |
| 187 return false; | 181 return false; |
| 188 | 182 |
| 189 *affinity = marker_data->affinity; | 183 *affinity = marker_data->get_affinity(); |
| 190 | |
| 191 return true; | 184 return true; |
| 192 } | 185 } |
| 193 | 186 |
| 194 bool GetTextMarkerRange(AXTextMarkerRangeRef marker_range, | 187 bool GetTextMarkerRange(AXTextMarkerRangeRef marker_range, |
| 195 BrowserAccessibility** start_object, | 188 BrowserAccessibility** start_object, |
| 196 int* start_offset, | 189 int* start_offset, |
| 197 ui::AXTextAffinity* start_affinity, | 190 ui::AXTextAffinity* start_affinity, |
| 198 BrowserAccessibility** end_object, | 191 BrowserAccessibility** end_object, |
| 199 int* end_offset, | 192 int* end_offset, |
| 200 ui::AXTextAffinity* end_affinity) { | 193 ui::AXTextAffinity* end_affinity) { |
| (...skipping 2677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2878 if (![self instanceActive]) | 2871 if (![self instanceActive]) |
| 2879 return [super hash]; | 2872 return [super hash]; |
| 2880 return browserAccessibility_->GetId(); | 2873 return browserAccessibility_->GetId(); |
| 2881 } | 2874 } |
| 2882 | 2875 |
| 2883 - (BOOL)accessibilityShouldUseUniqueId { | 2876 - (BOOL)accessibilityShouldUseUniqueId { |
| 2884 return YES; | 2877 return YES; |
| 2885 } | 2878 } |
| 2886 | 2879 |
| 2887 @end | 2880 @end |
| OLD | NEW |