OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "ui/accessibility/platform/text_marker_helper_mac.h" | 5 #import "ui/accessibility/platform/text_marker_helper_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| 11 #include "base/mac/scoped_nsobject.h" |
11 #include "ui/accessibility/ax_position.h" | 12 #include "ui/accessibility/ax_position.h" |
12 #include "ui/accessibility/ax_range.h" | 13 #include "ui/accessibility/ax_range.h" |
13 | 14 |
14 using ui::AXPositionPointer; | 15 using ui::AXPositionPointer; |
15 using ui::AXRangePointer; | 16 using ui::AXRangePointer; |
16 using ui::AXPositionData; | 17 using ui::AXPositionData; |
17 | 18 |
18 extern "C" { | 19 extern "C" { |
19 | 20 |
20 // The following are private accessibility APIs required for cursor navigation | 21 // The following are private accessibility APIs required for cursor navigation |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 std::unique_ptr<ui::PositionFactory> factory_; | 97 std::unique_ptr<ui::PositionFactory> factory_; |
97 } | 98 } |
98 | 99 |
99 - (instancetype)initWithFactory:(std::unique_ptr<ui::PositionFactory>)factory { | 100 - (instancetype)initWithFactory:(std::unique_ptr<ui::PositionFactory>)factory { |
100 if ((self = [super init])) { | 101 if ((self = [super init])) { |
101 factory_ = std::move(factory); | 102 factory_ = std::move(factory); |
102 } | 103 } |
103 return self; | 104 return self; |
104 } | 105 } |
105 | 106 |
106 - (id)startTextMarker { | 107 + (NSArray*)getSupportedAttributes { |
107 AXPositionPointer root = factory_->GetRoot(); | 108 return @[ |
108 return root ? CreateTextMarker(root->PositionAtStartOfAnchor()) : nil; | 109 @"AXEndTextMarker", |
| 110 @"AXSelectedTextMarkerRange", |
| 111 @"AXStartTextMarker", |
| 112 ]; |
109 } | 113 } |
110 | 114 |
111 - (id)endTextMarker { | 115 + (NSArray*)getSupportedParameterizedAttributesExtended:(BOOL)extended { |
112 AXPositionPointer root = factory_->GetRoot(); | 116 static NSArray* const generalAttributes = [@[ |
113 return root ? CreateTextMarker(root->PositionAtEndOfAnchor()) : nil; | 117 @"AXAttributedStringForTextMarkerRange", |
| 118 @"AXBoundsForTextMarkerRange", |
| 119 @"AXEndTextMarkerForBounds", |
| 120 @"AXLeftLineTextMarkerRangeForTextMarker", // Done. |
| 121 @"AXLeftWordTextMarkerRangeForTextMarker", // Done. |
| 122 @"AXLengthForTextMarkerRange", |
| 123 @"AXLineForTextMarker", |
| 124 @"AXLineTextMarkerRangeForTextMarker", // Done. |
| 125 @"AXNextLineEndTextMarkerForTextMarker", // Done. |
| 126 @"AXNextParagraphEndTextMarkerForTextMarker", |
| 127 @"AXNextSentenceEndTextMarkerForTextMarker", |
| 128 @"AXNextTextMarkerForTextMarker", // Done. |
| 129 @"AXNextWordEndTextMarkerForTextMarker", // Done. |
| 130 @"AXParagraphTextMarkerRangeForTextMarker", |
| 131 @"AXPreviousLineStartTextMarkerForTextMarker", // Done. |
| 132 @"AXPreviousParagraphStartTextMarkerForTextMarker", |
| 133 @"AXPreviousSentenceStartTextMarkerForTextMarker", |
| 134 @"AXPreviousTextMarkerForTextMarker", // Done. |
| 135 @"AXPreviousWordStartTextMarkerForTextMarker", // Done. |
| 136 @"AXRightLineTextMarkerRangeForTextMarker", // Done. |
| 137 @"AXRightWordTextMarkerRangeForTextMarker", // Done. |
| 138 @"AXSentenceTextMarkerRangeForTextMarker", |
| 139 @"AXStartTextMarkerForBounds", |
| 140 @"AXStringForTextMarkerRange", |
| 141 @"AXStyleTextMarkerRangeForTextMarker", |
| 142 @"AXTextMarkerForPosition", |
| 143 @"AXTextMarkerRangeForLine", // Done. |
| 144 @"AXTextMarkerRangeForUIElement", // Done. |
| 145 @"AXTextMarkerRangeForUnorderedTextMarkers", // Done. |
| 146 @"AXUIElementForTextMarker", // Done. |
| 147 ] retain]; |
| 148 static NSArray* const extendedAttributes = [@[ |
| 149 @"AXTextMarkerIsValid", |
| 150 @"AXIndexForTextMarker", |
| 151 @"AXTextMarkerForIndex", |
| 152 ] retain]; |
| 153 base::scoped_nsobject<NSMutableArray> ret([[NSMutableArray alloc] init]); |
| 154 [ret addObjectsFromArray:generalAttributes]; |
| 155 if (extended) |
| 156 [ret addObjectsFromArray:extendedAttributes]; |
| 157 return ret.autorelease(); |
114 } | 158 } |
115 | 159 |
116 - (id)selectedTextMarkerRange { | 160 + (BOOL)getRangeDataFromMarkerRange:(id)parameter |
117 AXRangePointer selection = factory_->GetSelection(); | 161 start:(ui::AXPositionData*)start |
118 if (!selection.first || !selection.second) | 162 end:(ui::AXPositionData*)end { |
119 return nil; | 163 AXTextMarkerRangeRef markerRange = |
120 return CreateTextMarkerRange(std::move(selection)); | 164 base::mac::CFCastStrict<AXTextMarkerRangeRef>(parameter); |
| 165 DCHECK(markerRange); |
| 166 |
| 167 base::ScopedCFTypeRef<AXTextMarkerRef> startMarker( |
| 168 AXTextMarkerRangeCopyStartMarker(markerRange)); |
| 169 base::ScopedCFTypeRef<AXTextMarkerRef> endMarker( |
| 170 AXTextMarkerRangeCopyEndMarker(markerRange)); |
| 171 if (!startMarker || !endMarker) |
| 172 return NO; |
| 173 |
| 174 return ExtractData(startMarker, start) && ExtractData(endMarker, end); |
121 } | 175 } |
122 | 176 |
123 - (AXPositionPointer)extractFrom:(id)parameter { | 177 - (AXPositionPointer)extractFrom:(id)parameter { |
124 AXPositionData data; | 178 AXPositionData data; |
125 if (ExtractData(base::mac::CFCastStrict<AXTextMarkerRef>(parameter), &data)) | 179 if (ExtractData(base::mac::CFCastStrict<AXTextMarkerRef>(parameter), &data)) |
126 return factory_->GetFromData(data); | 180 return factory_->GetFromData(data); |
127 return factory_->GetFromData(ui::AXAbstractPosition::kNullData); | 181 return factory_->GetFromData(ui::AXAbstractPosition::kNullData); |
128 } | 182 } |
129 | 183 |
| 184 // Non-parameterized attributes. Keep sorted. |
| 185 |
| 186 // Returns a text marker that points to the last character in the document that |
| 187 // can be selected with VoiceOver. |
| 188 - (id)AXEndTextMarker { |
| 189 AXPositionPointer root = factory_->GetRoot(); |
| 190 return root ? CreateTextMarker(root->PositionAtEndOfAnchor()) : nil; |
| 191 } |
| 192 |
| 193 // Returns a text marker range corresponding to the current selection. |
| 194 - (id)AXSelectedTextMarkerRange { |
| 195 AXRangePointer selection = factory_->GetSelection(); |
| 196 if (!selection.first || !selection.second) |
| 197 return nil; |
| 198 return CreateTextMarkerRange(std::move(selection)); |
| 199 } |
| 200 |
| 201 // Returns a text marker that points to the first character in the document that |
| 202 // can be selected with VoiceOver. |
| 203 - (id)AXStartTextMarker { |
| 204 AXPositionPointer root = factory_->GetRoot(); |
| 205 return root ? CreateTextMarker(root->PositionAtStartOfAnchor()) : nil; |
| 206 } |
| 207 |
| 208 // Parameterized attributes. TOOD(tapted): Sort these. |
| 209 |
130 - (id)AXTextMarkerRangeForUIElement:(id)parameter { | 210 - (id)AXTextMarkerRangeForUIElement:(id)parameter { |
131 AXPositionPointer startPosition = factory_->GetRoot(); | 211 AXPositionPointer startPosition = factory_->GetRoot(); |
132 AXPositionPointer endPosition = startPosition->PositionAtEndOfAnchor(); | 212 AXPositionPointer endPosition = startPosition->PositionAtEndOfAnchor(); |
133 AXRangePointer range = | 213 AXRangePointer range = |
134 AXRangePointer(std::move(startPosition), std::move(endPosition)); | 214 AXRangePointer(std::move(startPosition), std::move(endPosition)); |
135 return CreateTextMarkerRange(std::move(range)); | 215 return CreateTextMarkerRange(std::move(range)); |
136 } | 216 } |
137 | 217 |
138 - (id)AXUIElementForTextMarker:(id)parameter { | 218 - (id)AXUIElementForTextMarker:(id)parameter { |
139 AXPositionData data; | 219 AXPositionData data; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 AXPositionPointer endPosition = | 346 AXPositionPointer endPosition = |
267 [self extractFrom:[textMarkerArray objectAtIndex:1]]; | 347 [self extractFrom:[textMarkerArray objectAtIndex:1]]; |
268 if (endPosition->Compare(startPosition)) { | 348 if (endPosition->Compare(startPosition)) { |
269 return CreateTextMarkerRange( | 349 return CreateTextMarkerRange( |
270 AXRangePointer(std::move(endPosition), std::move(startPosition))); | 350 AXRangePointer(std::move(endPosition), std::move(startPosition))); |
271 } | 351 } |
272 return CreateTextMarkerRange( | 352 return CreateTextMarkerRange( |
273 AXRangePointer(std::move(startPosition), std::move(endPosition))); | 353 AXRangePointer(std::move(startPosition), std::move(endPosition))); |
274 } | 354 } |
275 | 355 |
276 + (BOOL)getRangeDataFromMarkerRange:(id)parameter | |
277 start:(ui::AXPositionData*)start | |
278 end:(ui::AXPositionData*)end { | |
279 AXTextMarkerRangeRef markerRange = | |
280 base::mac::CFCastStrict<AXTextMarkerRangeRef>(parameter); | |
281 DCHECK(markerRange); | |
282 | |
283 base::ScopedCFTypeRef<AXTextMarkerRef> startMarker( | |
284 AXTextMarkerRangeCopyStartMarker(markerRange)); | |
285 base::ScopedCFTypeRef<AXTextMarkerRef> endMarker( | |
286 AXTextMarkerRangeCopyEndMarker(markerRange)); | |
287 if (!startMarker || !endMarker) | |
288 return NO; | |
289 | |
290 return ExtractData(startMarker, start) && ExtractData(endMarker, end); | |
291 } | |
292 | |
293 @end | 356 @end |
OLD | NEW |