Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: content/browser/accessibility/browser_accessibility_cocoa.mm

Issue 2271893002: Creates AXPosition to uniquely identify a position in the accessibility tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed AXRange class. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
27 using content::AXTreeIDRegistry; 28 using content::AXTreeIDRegistry;
28 using content::AccessibilityMatchPredicate; 29 using content::AccessibilityMatchPredicate;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 @"AXTextMarkerRangeForUnorderedTextMarkers"; 88 @"AXTextMarkerRangeForUnorderedTextMarkers";
88 NSString* const NSAccessibilityIndexForChildUIElementParameterizedAttribute = 89 NSString* const NSAccessibilityIndexForChildUIElementParameterizedAttribute =
89 @"AXIndexForChildUIElement"; 90 @"AXIndexForChildUIElement";
90 91
91 // Actions. 92 // Actions.
92 NSString* const NSAccessibilityScrollToVisibleAction = @"AXScrollToVisible"; 93 NSString* const NSAccessibilityScrollToVisibleAction = @"AXScrollToVisible";
93 94
94 // A mapping from an accessibility attribute to its method name. 95 // A mapping from an accessibility attribute to its method name.
95 NSDictionary* attributeToMethodNameMap = nil; 96 NSDictionary* attributeToMethodNameMap = nil;
96 97
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. 98 // VoiceOver uses -1 to mean "no limit" for AXResultsLimit.
105 const int kAXResultsLimitNoLimit = -1; 99 const int kAXResultsLimitNoLimit = -1;
106 100
107 extern "C" { 101 extern "C" {
108 102
109 // The following are private accessibility APIs required for cursor navigation 103 // The following are private accessibility APIs required for cursor navigation
110 // and text selection. VoiceOver started relying on them in Mac OS X 10.11. 104 // and text selection. VoiceOver started relying on them in Mac OS X 10.11.
111 #if !defined(MAC_OS_X_VERSION_10_11) || \ 105 #if !defined(MAC_OS_X_VERSION_10_11) || \
112 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11 106 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11
113 107
(...skipping 13 matching lines...) Expand all
127 AXTextMarkerRef AXTextMarkerRangeCopyEndMarker( 121 AXTextMarkerRef AXTextMarkerRangeCopyEndMarker(
128 AXTextMarkerRangeRef text_marker_range); 122 AXTextMarkerRangeRef text_marker_range);
129 123
130 #endif // MAC_OS_X_VERSION_10_11 124 #endif // MAC_OS_X_VERSION_10_11
131 125
132 } // extern "C" 126 } // extern "C"
133 127
134 id CreateTextMarker(const BrowserAccessibility& object, 128 id CreateTextMarker(const BrowserAccessibility& object,
135 int offset, 129 int offset,
136 ui::AXTextAffinity affinity) { 130 ui::AXTextAffinity affinity) {
137 AXTextMarkerData marker_data; 131 if (!object.instance_active())
138 marker_data.tree_id = object.manager() ? object.manager()->ax_tree_id() : -1; 132 return nil;
139 marker_data.node_id = object.GetId(); 133
140 marker_data.offset = offset; 134 const auto manager = object.manager();
141 marker_data.affinity = affinity; 135 DCHECK(manager);
136 auto marker_data = AXPlatformPosition::CreateTextPosition(
137 manager->ax_tree_id(), object.node_id(), offset, affinity);
142 return (id)base::mac::CFTypeRefToNSObjectAutorelease(AXTextMarkerCreate( 138 return (id)base::mac::CFTypeRefToNSObjectAutorelease(AXTextMarkerCreate(
143 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(&marker_data), 139 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(marker_data),
144 sizeof(marker_data))); 140 sizeof(*marker_data)));
145 } 141 }
146 142
147 id CreateTextMarkerRange(const BrowserAccessibility& start_object, 143 id CreateTextMarkerRange(const BrowserAccessibility& start_object,
148 int start_offset, 144 int start_offset,
149 ui::AXTextAffinity start_affinity, 145 ui::AXTextAffinity start_affinity,
150 const BrowserAccessibility& end_object, 146 const BrowserAccessibility& end_object,
151 int end_offset, 147 int end_offset,
152 ui::AXTextAffinity end_affinity) { 148 ui::AXTextAffinity end_affinity) {
153 id start_marker = CreateTextMarker( 149 id start_marker = CreateTextMarker(
154 start_object, start_offset, start_affinity); 150 start_object, start_offset, start_affinity);
155 id end_marker = CreateTextMarker(end_object, end_offset, end_affinity); 151 id end_marker = CreateTextMarker(end_object, end_offset, end_affinity);
156 return (id)base::mac::CFTypeRefToNSObjectAutorelease( 152 return (id)base::mac::CFTypeRefToNSObjectAutorelease(
157 AXTextMarkerRangeCreate(kCFAllocatorDefault, start_marker, end_marker)); 153 AXTextMarkerRangeCreate(kCFAllocatorDefault, start_marker, end_marker));
158 } 154 }
159 155
160 bool GetTextMarkerData(AXTextMarkerRef text_marker, 156 bool GetTextMarkerData(AXTextMarkerRef text_marker,
161 BrowserAccessibility** object, 157 BrowserAccessibility** object,
162 int* offset, 158 int* offset,
163 ui::AXTextAffinity* affinity) { 159 ui::AXTextAffinity* affinity) {
164 DCHECK(text_marker); 160 DCHECK(text_marker);
165 DCHECK(object && offset); 161 DCHECK(object && offset);
166 const auto* marker_data = reinterpret_cast<const AXTextMarkerData*>( 162 const auto* marker_data = reinterpret_cast<const AXPlatformPosition*>(
167 AXTextMarkerGetBytePtr(text_marker)); 163 AXTextMarkerGetBytePtr(text_marker));
168 if (!marker_data) 164 if (!marker_data)
169 return false; 165 return false;
170 166
171 const BrowserAccessibilityManager* manager = 167 *object = marker_data->GetAnchor();
172 BrowserAccessibilityManager::FromID(marker_data->tree_id);
173 if (!manager)
174 return false;
175
176 *object = manager->GetFromID(marker_data->node_id);
177 if (!*object) 168 if (!*object)
178 return false; 169 return false;
179 170
180 *offset = marker_data->offset; 171 *offset = marker_data->text_offset();
181 if (*offset < 0) 172 if (*offset < 0)
182 return false; 173 return false;
183 174
184 *affinity = marker_data->affinity; 175 *affinity = marker_data->affinity();
185
186 return true; 176 return true;
187 } 177 }
188 178
189 bool GetTextMarkerRange(AXTextMarkerRangeRef marker_range, 179 bool GetTextMarkerRange(AXTextMarkerRangeRef marker_range,
190 BrowserAccessibility** start_object, 180 BrowserAccessibility** start_object,
191 int* start_offset, 181 int* start_offset,
192 ui::AXTextAffinity* start_affinity, 182 ui::AXTextAffinity* start_affinity,
193 BrowserAccessibility** end_object, 183 BrowserAccessibility** end_object,
194 int* end_offset, 184 int* end_offset,
195 ui::AXTextAffinity* end_affinity) { 185 ui::AXTextAffinity* end_affinity) {
(...skipping 2682 matching lines...) Expand 10 before | Expand all | Expand 10 after
2878 } 2868 }
2879 2869
2880 - (BOOL)accessibilityNotifiesWhenDestroyed { 2870 - (BOOL)accessibilityNotifiesWhenDestroyed {
2881 // Indicate that BrowserAccessibilityCocoa will post a notification when it's 2871 // Indicate that BrowserAccessibilityCocoa will post a notification when it's
2882 // destroyed (see -detach). This allows VoiceOver to do some internal things 2872 // destroyed (see -detach). This allows VoiceOver to do some internal things
2883 // more efficiently. 2873 // more efficiently.
2884 return YES; 2874 return YES;
2885 } 2875 }
2886 2876
2887 @end 2877 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698