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

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

Issue 2207573002: Implement 3 Mac accessibility parameterized attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switched to enum Created 4 years, 4 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
« no previous file with comments | « no previous file | content/browser/accessibility/browser_accessibility_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 @"AXTextMarkerForIndex"; 75 @"AXTextMarkerForIndex";
76 NSString* const NSAccessibilityEndTextMarkerForBoundsParameterizedAttribute = 76 NSString* const NSAccessibilityEndTextMarkerForBoundsParameterizedAttribute =
77 @"AXEndTextMarkerForBounds"; 77 @"AXEndTextMarkerForBounds";
78 NSString* const NSAccessibilityStartTextMarkerForBoundsParameterizedAttribute = 78 NSString* const NSAccessibilityStartTextMarkerForBoundsParameterizedAttribute =
79 @"AXStartTextMarkerForBounds"; 79 @"AXStartTextMarkerForBounds";
80 NSString* const 80 NSString* const
81 NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute = 81 NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute =
82 @"AXLineTextMarkerRangeForTextMarker"; 82 @"AXLineTextMarkerRangeForTextMarker";
83 NSString* const NSAccessibilitySelectTextWithCriteriaParameterizedAttribute = 83 NSString* const NSAccessibilitySelectTextWithCriteriaParameterizedAttribute =
84 @"AXSelectTextWithCriteria"; 84 @"AXSelectTextWithCriteria";
85 NSString* const NSAccessibilityBoundsForTextMarkerRangeParameterizedAttribute =
86 @"AXBoundsForTextMarkerRange";
87 NSString* const NSAccessibilityTextMarkerRangeForUnorderedTextMarkersParameteriz edAttribute =
88 @"AXTextMarkerRangeForUnorderedTextMarkers";
89 NSString* const NSAccessibilityIndexForChildUIElementParameterizedAttribute =
90 @"AXIndexForChildUIElement";
85 91
86 // Actions. 92 // Actions.
87 NSString* const NSAccessibilityScrollToVisibleAction = @"AXScrollToVisible"; 93 NSString* const NSAccessibilityScrollToVisibleAction = @"AXScrollToVisible";
88 94
89 // A mapping from an accessibility attribute to its method name. 95 // A mapping from an accessibility attribute to its method name.
90 NSDictionary* attributeToMethodNameMap = nil; 96 NSDictionary* attributeToMethodNameMap = nil;
91 97
92 struct AXTextMarkerData { 98 struct AXTextMarkerData {
93 AXTreeIDRegistry::AXTreeID tree_id; 99 AXTreeIDRegistry::AXTreeID tree_id;
94 int32_t node_id; 100 int32_t node_id;
(...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 return [NSValue valueWithRange: 2002 return [NSValue valueWithRange:
1997 NSMakeRange(start, end - start)]; 2003 NSMakeRange(start, end - start)];
1998 } 2004 }
1999 2005
2000 if ([attribute isEqualToString: 2006 if ([attribute isEqualToString:
2001 NSAccessibilityCellForColumnAndRowParameterizedAttribute]) { 2007 NSAccessibilityCellForColumnAndRowParameterizedAttribute]) {
2002 if ([self internalRole] != ui::AX_ROLE_TABLE && 2008 if ([self internalRole] != ui::AX_ROLE_TABLE &&
2003 [self internalRole] != ui::AX_ROLE_GRID) { 2009 [self internalRole] != ui::AX_ROLE_GRID) {
2004 return nil; 2010 return nil;
2005 } 2011 }
2006 if (![parameter isKindOfClass:[NSArray self]]) 2012 if (![parameter isKindOfClass:[NSArray class]])
2013 return nil;
2014 if (2 != [parameter count])
2007 return nil; 2015 return nil;
2008 NSArray* array = parameter; 2016 NSArray* array = parameter;
2009 int column = [[array objectAtIndex:0] intValue]; 2017 int column = [[array objectAtIndex:0] intValue];
2010 int row = [[array objectAtIndex:1] intValue]; 2018 int row = [[array objectAtIndex:1] intValue];
2011 int num_columns = browserAccessibility_->GetIntAttribute( 2019 int num_columns = browserAccessibility_->GetIntAttribute(
2012 ui::AX_ATTR_TABLE_COLUMN_COUNT); 2020 ui::AX_ATTR_TABLE_COLUMN_COUNT);
2013 int num_rows = browserAccessibility_->GetIntAttribute( 2021 int num_rows = browserAccessibility_->GetIntAttribute(
2014 ui::AX_ATTR_TABLE_ROW_COUNT); 2022 ui::AX_ATTR_TABLE_ROW_COUNT);
2015 if (column < 0 || column >= num_columns || 2023 if (column < 0 || column >= num_columns ||
2016 row < 0 || row >= num_rows) { 2024 row < 0 || row >= num_rows) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 NSMutableArray* result = [NSMutableArray arrayWithCapacity:count]; 2272 NSMutableArray* result = [NSMutableArray arrayWithCapacity:count];
2265 for (size_t i = 0; i < count; ++i) { 2273 for (size_t i = 0; i < count; ++i) {
2266 BrowserAccessibility* match = search.GetMatchAtIndex(i); 2274 BrowserAccessibility* match = search.GetMatchAtIndex(i);
2267 [result addObject:ToBrowserAccessibilityCocoa(match)]; 2275 [result addObject:ToBrowserAccessibilityCocoa(match)];
2268 } 2276 }
2269 return result; 2277 return result;
2270 } 2278 }
2271 return nil; 2279 return nil;
2272 } 2280 }
2273 2281
2274 if ([attribute 2282 if ([attribute isEqualToString:
2275 isEqualToString: 2283 NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute ]) {
2276 NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttrib ute]) {
2277 BrowserAccessibility* object; 2284 BrowserAccessibility* object;
2278 int offset; 2285 int offset;
2279 ui::AXTextAffinity affinity; 2286 ui::AXTextAffinity affinity;
2280 if (!GetTextMarkerData(parameter, &object, &offset, &affinity)) 2287 if (!GetTextMarkerData(parameter, &object, &offset, &affinity))
2281 return nil; 2288 return nil;
2282 2289
2283 DCHECK(object); 2290 DCHECK(object);
2284 int start_offset = 2291 int startOffset =
2285 object->GetLineStartBoundary(offset, ui::BACKWARDS_DIRECTION, affinity); 2292 object->GetLineStartBoundary(offset, ui::BACKWARDS_DIRECTION, affinity);
2286 int end_offset = 2293 int endOffset =
2287 object->GetLineStartBoundary(offset, ui::FORWARDS_DIRECTION, affinity); 2294 object->GetLineStartBoundary(offset, ui::FORWARDS_DIRECTION, affinity);
2288 return CreateTextMarkerRange( 2295 return CreateTextMarkerRange(
2289 *object, start_offset, ui::AX_TEXT_AFFINITY_UPSTREAM, 2296 *object, startOffset, ui::AX_TEXT_AFFINITY_UPSTREAM,
2290 *object, end_offset, ui::AX_TEXT_AFFINITY_DOWNSTREAM); 2297 *object, endOffset, ui::AX_TEXT_AFFINITY_DOWNSTREAM);
2298 }
2299
2300 if ([attribute isEqualToString:
2301 NSAccessibilityBoundsForTextMarkerRangeParameterizedAttribute]) {
2302 BrowserAccessibility* startObject;
2303 BrowserAccessibility* endObject;
2304 int startOffset, endOffset;
2305 ui::AXTextAffinity startAffinity, endAffinity;
2306 if (!GetTextMarkerRange(parameter,
2307 &startObject, &startOffset, &startAffinity,
2308 &endObject, &endOffset, &endAffinity)) {
2309 return nil;
2310 }
2311 DCHECK(startObject && endObject);
2312 DCHECK_GE(startOffset, 0);
2313 DCHECK_GE(endOffset, 0);
2314
2315 gfx::Rect rect = BrowserAccessibilityManager::GetLocalBoundsForRange(
2316 *startObject, startOffset, *endObject, endOffset);
2317 NSPoint origin = NSMakePoint(rect.x(), rect.y());
2318 NSSize size = NSMakeSize(rect.width(), rect.height());
2319 NSPoint pointInScreen = [self pointInScreen:origin size:size];
2320 NSRect nsrect = NSMakeRect(
2321 pointInScreen.x, pointInScreen.y, rect.width(), rect.height());
2322 return [NSValue valueWithRect:nsrect];
2323 }
2324
2325 if ([attribute isEqualToString:
2326 NSAccessibilityTextMarkerRangeForUnorderedTextMarkersParameterizedAtt ribute]) {
2327 if (![parameter isKindOfClass:[NSArray class]])
2328 return nil;
2329
2330 NSArray* array = parameter;
2331 id first = [array objectAtIndex:0];
2332 id second = [array objectAtIndex:1];
2333 BrowserAccessibility* object1;
2334 int offset1;
2335 ui::AXTextAffinity affinity1;
2336 if (!GetTextMarkerData(first, &object1, &offset1, &affinity1))
2337 return nil;
2338
2339 BrowserAccessibility* object2;
2340 int offset2;
2341 ui::AXTextAffinity affinity2;
2342 if (!GetTextMarkerData(second, &object2, &offset2, &affinity2))
2343 return nil;
2344
2345 bool isInOrder = true;
2346 if (object1 == object2) {
2347 if (offset2 > offset1)
2348 isInOrder = true;
2349 else if (offset2 < offset1)
2350 isInOrder = false;
2351 else
2352 return nil;
2353 }
2354
2355 ui::AXTreeOrder order = BrowserAccessibilityManager::CompareNodes(
2356 *object1, *object2);
2357 if (order == ui::AX_TREE_ORDER_BEFORE ||
2358 (order == ui::AX_TREE_ORDER_EQUAL && offset1 < offset2)) {
2359 return CreateTextMarkerRange(*object1, offset1, affinity1,
2360 *object2, offset2, affinity2);
2361 }
2362 if (order == ui::AX_TREE_ORDER_AFTER ||
2363 (order == ui::AX_TREE_ORDER_EQUAL && offset1 > offset2)) {
2364 return CreateTextMarkerRange(*object2, offset2, affinity2,
2365 *object1, offset1, affinity1);
2366 }
2367 return nil;
2368 }
2369
2370 if ([attribute isEqualToString:
2371 NSAccessibilityIndexForChildUIElementParameterizedAttribute]) {
2372 if (![parameter isKindOfClass:[BrowserAccessibilityCocoa class]])
2373 return nil;
2374
2375 BrowserAccessibilityCocoa* childCocoaObj =
2376 (BrowserAccessibilityCocoa*)parameter;
2377 BrowserAccessibility* child = [childCocoaObj browserAccessibility];
2378 if (!child)
2379 return nil;
2380
2381 if (child->GetParent() != browserAccessibility_)
2382 return nil;
2383
2384 return @(child->GetIndexInParent());
2291 } 2385 }
2292 2386
2293 return nil; 2387 return nil;
2294 } 2388 }
2295 2389
2296 // Returns an array of parameterized attributes names that this object will 2390 // Returns an array of parameterized attributes names that this object will
2297 // respond to. 2391 // respond to.
2298 - (NSArray*)accessibilityParameterizedAttributeNames { 2392 - (NSArray*)accessibilityParameterizedAttributeNames {
2299 if (![self instanceActive]) 2393 if (![self instanceActive])
2300 return nil; 2394 return nil;
2301 2395
2302 // General attributes. 2396 // General attributes.
2303 NSMutableArray* ret = [NSMutableArray 2397 NSMutableArray* ret = [NSMutableArray
2304 arrayWithObjects: 2398 arrayWithObjects:
2305 @"AXUIElementForTextMarker", @"AXTextMarkerRangeForUIElement", 2399 @"AXUIElementForTextMarker", @"AXTextMarkerRangeForUIElement",
2306 @"AXLineForTextMarker", @"AXTextMarkerRangeForLine", 2400 @"AXLineForTextMarker", @"AXTextMarkerRangeForLine",
2307 @"AXStringForTextMarkerRange", @"AXTextMarkerForPosition", 2401 @"AXStringForTextMarkerRange", @"AXTextMarkerForPosition",
2308 @"AXBoundsForTextMarkerRange",
2309 @"AXAttributedStringForTextMarkerRange", 2402 @"AXAttributedStringForTextMarkerRange",
2310 @"AXTextMarkerRangeForUnorderedTextMarkers",
2311 @"AXNextTextMarkerForTextMarker", 2403 @"AXNextTextMarkerForTextMarker",
2312 @"AXPreviousTextMarkerForTextMarker", 2404 @"AXPreviousTextMarkerForTextMarker",
2313 @"AXLeftWordTextMarkerRangeForTextMarker", 2405 @"AXLeftWordTextMarkerRangeForTextMarker",
2314 @"AXRightWordTextMarkerRangeForTextMarker", 2406 @"AXRightWordTextMarkerRangeForTextMarker",
2315 @"AXLeftLineTextMarkerRangeForTextMarker", 2407 @"AXLeftLineTextMarkerRangeForTextMarker",
2316 @"AXRightLineTextMarkerRangeForTextMarker", 2408 @"AXRightLineTextMarkerRangeForTextMarker",
2317 @"AXSentenceTextMarkerRangeForTextMarker", 2409 @"AXSentenceTextMarkerRangeForTextMarker",
2318 @"AXParagraphTextMarkerRangeForTextMarker", 2410 @"AXParagraphTextMarkerRangeForTextMarker",
2319 @"AXNextWordEndTextMarkerForTextMarker", 2411 @"AXNextWordEndTextMarkerForTextMarker",
2320 @"AXPreviousWordStartTextMarkerForTextMarker", 2412 @"AXPreviousWordStartTextMarkerForTextMarker",
2321 @"AXNextLineEndTextMarkerForTextMarker", 2413 @"AXNextLineEndTextMarkerForTextMarker",
2322 @"AXPreviousLineStartTextMarkerForTextMarker", 2414 @"AXPreviousLineStartTextMarkerForTextMarker",
2323 @"AXNextSentenceEndTextMarkerForTextMarker", 2415 @"AXNextSentenceEndTextMarkerForTextMarker",
2324 @"AXPreviousSentenceStartTextMarkerForTextMarker", 2416 @"AXPreviousSentenceStartTextMarkerForTextMarker",
2325 @"AXNextParagraphEndTextMarkerForTextMarker", 2417 @"AXNextParagraphEndTextMarkerForTextMarker",
2326 @"AXPreviousParagraphStartTextMarkerForTextMarker", 2418 @"AXPreviousParagraphStartTextMarkerForTextMarker",
2327 @"AXStyleTextMarkerRangeForTextMarker", @"AXLengthForTextMarkerRange", 2419 @"AXStyleTextMarkerRangeForTextMarker", @"AXLengthForTextMarkerRange",
2420 NSAccessibilityBoundsForTextMarkerRangeParameterizedAttribute,
2421 NSAccessibilityTextMarkerRangeForUnorderedTextMarkersParameterizedAttr ibute,
2422 NSAccessibilityIndexForChildUIElementParameterizedAttribute,
2328 NSAccessibilityBoundsForRangeParameterizedAttribute, 2423 NSAccessibilityBoundsForRangeParameterizedAttribute,
2329 NSAccessibilityStringForRangeParameterizedAttribute, 2424 NSAccessibilityStringForRangeParameterizedAttribute,
2330 NSAccessibilityUIElementCountForSearchPredicateParameterizedAttribute, 2425 NSAccessibilityUIElementCountForSearchPredicateParameterizedAttribute,
2331 NSAccessibilityUIElementsForSearchPredicateParameterizedAttribute, 2426 NSAccessibilityUIElementsForSearchPredicateParameterizedAttribute,
2332 NSAccessibilityEndTextMarkerForBoundsParameterizedAttribute, 2427 NSAccessibilityEndTextMarkerForBoundsParameterizedAttribute,
2333 NSAccessibilityStartTextMarkerForBoundsParameterizedAttribute, 2428 NSAccessibilityStartTextMarkerForBoundsParameterizedAttribute,
2334 NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute, 2429 NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute,
2335 NSAccessibilitySelectTextWithCriteriaParameterizedAttribute, nil]; 2430 NSAccessibilitySelectTextWithCriteriaParameterizedAttribute, nil];
2336 2431
2337 if ([[self role] isEqualToString:NSAccessibilityTableRole] || 2432 if ([[self role] isEqualToString:NSAccessibilityTableRole] ||
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
2756 if (![self instanceActive]) 2851 if (![self instanceActive])
2757 return [super hash]; 2852 return [super hash];
2758 return browserAccessibility_->GetId(); 2853 return browserAccessibility_->GetId();
2759 } 2854 }
2760 2855
2761 - (BOOL)accessibilityShouldUseUniqueId { 2856 - (BOOL)accessibilityShouldUseUniqueId {
2762 return YES; 2857 return YES;
2763 } 2858 }
2764 2859
2765 @end 2860 @end
OLDNEW
« no previous file with comments | « no previous file | content/browser/accessibility/browser_accessibility_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698