| 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 "content/browser/accessibility/accessibility_tree_formatter.h" | 5 #include "content/browser/accessibility/accessibility_tree_formatter.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 std::unique_ptr<base::Value> PopulateObject(id value); | 86 std::unique_ptr<base::Value> PopulateObject(id value); |
| 87 | 87 |
| 88 std::unique_ptr<base::ListValue> PopulateArray(NSArray* array) { | 88 std::unique_ptr<base::ListValue> PopulateArray(NSArray* array) { |
| 89 std::unique_ptr<base::ListValue> list(new base::ListValue); | 89 std::unique_ptr<base::ListValue> list(new base::ListValue); |
| 90 for (NSUInteger i = 0; i < [array count]; i++) | 90 for (NSUInteger i = 0; i < [array count]; i++) |
| 91 list->Append(PopulateObject([array objectAtIndex:i]).release()); | 91 list->Append(PopulateObject([array objectAtIndex:i]).release()); |
| 92 return list; | 92 return list; |
| 93 } | 93 } |
| 94 | 94 |
| 95 std::unique_ptr<base::StringValue> StringForBrowserAccessibility( | 95 std::unique_ptr<base::Value> StringForBrowserAccessibility( |
| 96 BrowserAccessibilityCocoa* obj) { | 96 BrowserAccessibilityCocoa* obj) { |
| 97 NSMutableArray* tokens = [[NSMutableArray alloc] init]; | 97 NSMutableArray* tokens = [[NSMutableArray alloc] init]; |
| 98 | 98 |
| 99 // Always include the role | 99 // Always include the role |
| 100 id role = [obj role]; | 100 id role = [obj role]; |
| 101 [tokens addObject:role]; | 101 [tokens addObject:role]; |
| 102 | 102 |
| 103 // If the role is "group", include the role description as well. | 103 // If the role is "group", include the role description as well. |
| 104 id roleDescription = [obj roleDescription]; | 104 id roleDescription = [obj roleDescription]; |
| 105 if ([role isEqualToString:NSAccessibilityGroupRole] && | 105 if ([role isEqualToString:NSAccessibilityGroupRole] && |
| 106 roleDescription != nil && | 106 roleDescription != nil && |
| 107 ![roleDescription isEqualToString:@""] && | 107 ![roleDescription isEqualToString:@""] && |
| 108 ![roleDescription isEqualToString:@"group"]) { | 108 ![roleDescription isEqualToString:@"group"]) { |
| 109 [tokens addObject:roleDescription]; | 109 [tokens addObject:roleDescription]; |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Include the description, title, or value - the first one not empty. | 112 // Include the description, title, or value - the first one not empty. |
| 113 id title = [obj title]; | 113 id title = [obj title]; |
| 114 id description = [obj description]; | 114 id description = [obj description]; |
| 115 id value = [obj value]; | 115 id value = [obj value]; |
| 116 if (description && ![description isEqual:@""]) { | 116 if (description && ![description isEqual:@""]) { |
| 117 [tokens addObject:description]; | 117 [tokens addObject:description]; |
| 118 } else if (title && ![title isEqual:@""]) { | 118 } else if (title && ![title isEqual:@""]) { |
| 119 [tokens addObject:title]; | 119 [tokens addObject:title]; |
| 120 } else if (value && ![value isEqual:@""]) { | 120 } else if (value && ![value isEqual:@""]) { |
| 121 [tokens addObject:value]; | 121 [tokens addObject:value]; |
| 122 } | 122 } |
| 123 | 123 |
| 124 NSString* result = [tokens componentsJoinedByString:@" "]; | 124 NSString* result = [tokens componentsJoinedByString:@" "]; |
| 125 return std::unique_ptr<base::StringValue>( | 125 return std::unique_ptr<base::Value>( |
| 126 new base::StringValue(SysNSStringToUTF16(result))); | 126 new base::Value(SysNSStringToUTF16(result))); |
| 127 } | 127 } |
| 128 | 128 |
| 129 std::unique_ptr<base::Value> PopulateObject(id value) { | 129 std::unique_ptr<base::Value> PopulateObject(id value) { |
| 130 if ([value isKindOfClass:[NSArray class]]) | 130 if ([value isKindOfClass:[NSArray class]]) |
| 131 return std::unique_ptr<base::Value>(PopulateArray((NSArray*)value)); | 131 return std::unique_ptr<base::Value>(PopulateArray((NSArray*)value)); |
| 132 if (IsRangeValue(value)) | 132 if (IsRangeValue(value)) |
| 133 return std::unique_ptr<base::Value>(PopulateRange([value rangeValue])); | 133 return std::unique_ptr<base::Value>(PopulateRange([value rangeValue])); |
| 134 if ([value isKindOfClass:[BrowserAccessibilityCocoa class]]) { | 134 if ([value isKindOfClass:[BrowserAccessibilityCocoa class]]) { |
| 135 std::string str; | 135 std::string str; |
| 136 StringForBrowserAccessibility(value)->GetAsString(&str); | 136 StringForBrowserAccessibility(value)->GetAsString(&str); |
| 137 return std::unique_ptr<base::Value>( | 137 return std::unique_ptr<base::Value>( |
| 138 StringForBrowserAccessibility((BrowserAccessibilityCocoa*)value)); | 138 StringForBrowserAccessibility((BrowserAccessibilityCocoa*)value)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 return std::unique_ptr<base::Value>(new base::StringValue( | 141 return std::unique_ptr<base::Value>(new base::Value( |
| 142 SysNSStringToUTF16([NSString stringWithFormat:@"%@", value]))); | 142 SysNSStringToUTF16([NSString stringWithFormat:@"%@", value]))); |
| 143 } | 143 } |
| 144 | 144 |
| 145 NSArray* BuildAllAttributesArray() { | 145 NSArray* BuildAllAttributesArray() { |
| 146 // Note: clang-format tries to put multiple attributes on one line, | 146 // Note: clang-format tries to put multiple attributes on one line, |
| 147 // but we prefer to have one per line for readability. | 147 // but we prefer to have one per line for readability. |
| 148 // clang-format off | 148 // clang-format off |
| 149 NSArray* array = [NSArray arrayWithObjects: | 149 NSArray* array = [NSArray arrayWithObjects: |
| 150 NSAccessibilityRoleDescriptionAttribute, | 150 NSAccessibilityRoleDescriptionAttribute, |
| 151 NSAccessibilityTitleAttribute, | 151 NSAccessibilityTitleAttribute, |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 340 |
| 341 const string AccessibilityTreeFormatterMac::GetAllowString() { | 341 const string AccessibilityTreeFormatterMac::GetAllowString() { |
| 342 return "@MAC-ALLOW:"; | 342 return "@MAC-ALLOW:"; |
| 343 } | 343 } |
| 344 | 344 |
| 345 const string AccessibilityTreeFormatterMac::GetDenyString() { | 345 const string AccessibilityTreeFormatterMac::GetDenyString() { |
| 346 return "@MAC-DENY:"; | 346 return "@MAC-DENY:"; |
| 347 } | 347 } |
| 348 | 348 |
| 349 } // namespace content | 349 } // namespace content |
| OLD | NEW |