| 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/ax_platform_position.h" |
| 19 #include "content/browser/accessibility/browser_accessibility_mac.h" | 20 #include "content/browser/accessibility/browser_accessibility_mac.h" |
| 20 #include "content/browser/accessibility/browser_accessibility_manager.h" | 21 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 21 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" | 22 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" |
| 22 #include "content/browser/accessibility/one_shot_accessibility_tree_search.h" | 23 #include "content/browser/accessibility/one_shot_accessibility_tree_search.h" |
| 23 #include "content/public/common/content_client.h" | 24 #include "content/public/common/content_client.h" |
| 24 #include "third_party/skia/include/core/SkColor.h" | 25 #include "third_party/skia/include/core/SkColor.h" |
| 25 #import "ui/accessibility/platform/ax_platform_node_mac.h" | 26 #import "ui/accessibility/platform/ax_platform_node_mac.h" |
| 26 | 27 |
| 28 using content::AXPlatformPosition; |
| 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; |
| 35 using ui::AXNodeData; | 37 using ui::AXNodeData; |
| 36 using StringAttribute = ui::AXStringAttribute; | 38 using StringAttribute = ui::AXStringAttribute; |
| (...skipping 50 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.GetId(), offset, affinity); |
| 147 return (id)base::mac::CFTypeRefToNSObjectAutorelease(AXTextMarkerCreate( | 144 return (id)base::mac::CFTypeRefToNSObjectAutorelease(AXTextMarkerCreate( |
| 148 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(&marker_data), | 145 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(marker_data), |
| 149 sizeof(marker_data))); | 146 sizeof(*marker_data))); |
| 150 } | 147 } |
| 151 | 148 |
| 152 id CreateTextMarkerRange(const BrowserAccessibility& start_object, | 149 id CreateTextMarkerRange(const BrowserAccessibility& start_object, |
| 153 int start_offset, | 150 int start_offset, |
| 154 ui::AXTextAffinity start_affinity, | 151 ui::AXTextAffinity start_affinity, |
| 155 const BrowserAccessibility& end_object, | 152 const BrowserAccessibility& end_object, |
| 156 int end_offset, | 153 int end_offset, |
| 157 ui::AXTextAffinity end_affinity) { | 154 ui::AXTextAffinity end_affinity) { |
| 158 id start_marker = CreateTextMarker( | 155 id start_marker = CreateTextMarker( |
| 159 start_object, start_offset, start_affinity); | 156 start_object, start_offset, start_affinity); |
| 160 id end_marker = CreateTextMarker(end_object, end_offset, end_affinity); | 157 id end_marker = CreateTextMarker(end_object, end_offset, end_affinity); |
| 161 return (id)base::mac::CFTypeRefToNSObjectAutorelease( | 158 return (id)base::mac::CFTypeRefToNSObjectAutorelease( |
| 162 AXTextMarkerRangeCreate(kCFAllocatorDefault, start_marker, end_marker)); | 159 AXTextMarkerRangeCreate(kCFAllocatorDefault, start_marker, end_marker)); |
| 163 } | 160 } |
| 164 | 161 |
| 165 bool GetTextMarkerData(AXTextMarkerRef text_marker, | 162 bool GetTextMarkerData(AXTextMarkerRef text_marker, |
| 166 BrowserAccessibility** object, | 163 BrowserAccessibility** object, |
| 167 int* offset, | 164 int* offset, |
| 168 ui::AXTextAffinity* affinity) { | 165 ui::AXTextAffinity* affinity) { |
| 169 DCHECK(text_marker); | 166 DCHECK(text_marker); |
| 170 DCHECK(object && offset); | 167 DCHECK(object && offset); |
| 171 const auto* marker_data = reinterpret_cast<const AXTextMarkerData*>( | 168 const auto* marker_data = reinterpret_cast<const AXPlatformPosition*>( |
| 172 AXTextMarkerGetBytePtr(text_marker)); | 169 AXTextMarkerGetBytePtr(text_marker)); |
| 173 if (!marker_data) | 170 if (!marker_data) |
| 174 return false; | 171 return false; |
| 175 | 172 |
| 176 const BrowserAccessibilityManager* manager = | 173 *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) | 174 if (!*object) |
| 183 return false; | 175 return false; |
| 184 | 176 |
| 185 *offset = marker_data->offset; | 177 *offset = marker_data->text_offset(); |
| 186 if (*offset < 0) | 178 if (*offset < 0) |
| 187 return false; | 179 return false; |
| 188 | 180 |
| 189 *affinity = marker_data->affinity; | 181 *affinity = marker_data->affinity(); |
| 190 | |
| 191 return true; | 182 return true; |
| 192 } | 183 } |
| 193 | 184 |
| 194 bool GetTextMarkerRange(AXTextMarkerRangeRef marker_range, | 185 bool GetTextMarkerRange(AXTextMarkerRangeRef marker_range, |
| 195 BrowserAccessibility** start_object, | 186 BrowserAccessibility** start_object, |
| 196 int* start_offset, | 187 int* start_offset, |
| 197 ui::AXTextAffinity* start_affinity, | 188 ui::AXTextAffinity* start_affinity, |
| 198 BrowserAccessibility** end_object, | 189 BrowserAccessibility** end_object, |
| 199 int* end_offset, | 190 int* end_offset, |
| 200 ui::AXTextAffinity* end_affinity) { | 191 ui::AXTextAffinity* end_affinity) { |
| (...skipping 2659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2860 if (![self instanceActive]) | 2851 if (![self instanceActive]) |
| 2861 return [super hash]; | 2852 return [super hash]; |
| 2862 return browserAccessibility_->GetId(); | 2853 return browserAccessibility_->GetId(); |
| 2863 } | 2854 } |
| 2864 | 2855 |
| 2865 - (BOOL)accessibilityShouldUseUniqueId { | 2856 - (BOOL)accessibilityShouldUseUniqueId { |
| 2866 return YES; | 2857 return YES; |
| 2867 } | 2858 } |
| 2868 | 2859 |
| 2869 @end | 2860 @end |
| OLD | NEW |