| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/accessibility/dump_accessibility_tree_helper.h" | |
| 6 | |
| 7 #import <Cocoa/Cocoa.h> | |
| 8 | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/utf_string_conversions.h" | |
| 11 #include "content/browser/accessibility/browser_accessibility_cocoa.h" | |
| 12 #include "content/browser/accessibility/browser_accessibility_mac.h" | |
| 13 #include "content/browser/accessibility/browser_accessibility_manager.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 string16 Format(BrowserAccessibility* node, | |
| 20 const char *prefix, | |
| 21 SEL selector, | |
| 22 const char *suffix) { | |
| 23 BrowserAccessibilityCocoa* cocoa_node = node->ToBrowserAccessibilityCocoa(); | |
| 24 id value = [cocoa_node performSelector:selector]; | |
| 25 if (!value) | |
| 26 return string16(); | |
| 27 NSString* format_str = | |
| 28 [NSString stringWithFormat:@"%s%%@%s", prefix, suffix]; | |
| 29 NSString* tmp = [NSString stringWithFormat:format_str, value]; | |
| 30 return UTF8ToUTF16([tmp cStringUsingEncoding:NSUTF8StringEncoding]); | |
| 31 } | |
| 32 | |
| 33 string16 FormatPosition(BrowserAccessibility* node) { | |
| 34 // The NSAccessibility position of an object is in global coordinates and | |
| 35 // based on the lower-left corner of the object. To make this easier and less | |
| 36 // confusing, convert it to local window coordinates using the top-left | |
| 37 // corner when dumping the position. | |
| 38 BrowserAccessibility* root = node->manager()->GetRoot(); | |
| 39 BrowserAccessibilityCocoa* cocoa_root = root->ToBrowserAccessibilityCocoa(); | |
| 40 NSPoint root_position = [[cocoa_root position] pointValue]; | |
| 41 NSSize root_size = [[cocoa_root size] sizeValue]; | |
| 42 int root_top = -static_cast<int>(root_position.y + root_size.height); | |
| 43 int root_left = static_cast<int>(root_position.x); | |
| 44 | |
| 45 BrowserAccessibilityCocoa* cocoa_node = node->ToBrowserAccessibilityCocoa(); | |
| 46 NSPoint node_position = [[cocoa_node position] pointValue]; | |
| 47 NSSize node_size = [[cocoa_node size] sizeValue]; | |
| 48 | |
| 49 NSString* position_str = | |
| 50 [NSString stringWithFormat:@"position=(%d, %d)", | |
| 51 static_cast<int>(node_position.x - root_left), | |
| 52 static_cast<int>( | |
| 53 -node_position.y - node_size.height - root_top)]; | |
| 54 return UTF8ToUTF16([position_str cStringUsingEncoding:NSUTF8StringEncoding]); | |
| 55 } | |
| 56 | |
| 57 string16 FormatSize(BrowserAccessibility* node) { | |
| 58 BrowserAccessibilityCocoa* cocoa_node = node->ToBrowserAccessibilityCocoa(); | |
| 59 NSSize node_size = [[cocoa_node size] sizeValue]; | |
| 60 NSString* size_str = | |
| 61 [NSString stringWithFormat:@"size=(%d, %d)", | |
| 62 static_cast<int>(node_size.width), | |
| 63 static_cast<int>(node_size.height)]; | |
| 64 return UTF8ToUTF16([size_str cStringUsingEncoding:NSUTF8StringEncoding]); | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 | |
| 69 void DumpAccessibilityTreeHelper::Initialize() {} | |
| 70 | |
| 71 string16 DumpAccessibilityTreeHelper::ToString(BrowserAccessibility* node, | |
| 72 char* prefix) { | |
| 73 StartLine(); | |
| 74 Add(true, Format(node, "", @selector(role), "")); | |
| 75 Add(false, Format(node, "subrole=", @selector(subrole), "")); | |
| 76 Add(false, Format(node, "roleDescription='", | |
| 77 @selector(roleDescription), | |
| 78 "'")); | |
| 79 Add(true, Format(node, "title='", @selector(title), "'")); | |
| 80 Add(true, Format(node, "value='", @selector(value), "'")); | |
| 81 Add(false, Format(node, "minValue='", @selector(minValue), "'")); | |
| 82 Add(false, Format(node, "maxValue='", @selector(maxValue), "'")); | |
| 83 Add(false, Format(node, "valueDescription='", @selector(valueDescription), | |
| 84 "'")); | |
| 85 Add(false, Format(node, "description='", @selector(description), "'")); | |
| 86 Add(false, Format(node, "help='", @selector(help), "'")); | |
| 87 Add(false, Format(node, "invalid='", @selector(invalid), "'")); | |
| 88 Add(false, Format(node, "disclosing='", @selector(disclosing), "'")); | |
| 89 Add(false, Format(node, "disclosureLevel='", @selector(disclosureLevel), | |
| 90 "'")); | |
| 91 Add(false, Format(node, "accessKey='", @selector(accessKey), "'")); | |
| 92 Add(false, Format(node, "ariaAtomic='", @selector(ariaAtomic), "'")); | |
| 93 Add(false, Format(node, "ariaBusy='", @selector(ariaBusy), "'")); | |
| 94 Add(false, Format(node, "ariaLive='", @selector(ariaLive), "'")); | |
| 95 Add(false, Format(node, "ariaRelevant='", @selector(ariaRelevant), "'")); | |
| 96 Add(false, Format(node, "enabled='", @selector(enabled), "'")); | |
| 97 Add(false, Format(node, "focused='", @selector(focused), "'")); | |
| 98 Add(false, Format(node, "loaded='", @selector(loaded), "'")); | |
| 99 Add(false, Format(node, "loadingProgress='", @selector(loadingProgress), | |
| 100 "'")); | |
| 101 Add(false, Format(node, "numberOfCharacters='", | |
| 102 @selector(numberOfCharacters), "'")); | |
| 103 Add(false, Format(node, "orientation='", @selector(orientation), "'")); | |
| 104 Add(false, Format(node, "required='", @selector(required), "'")); | |
| 105 Add(false, Format(node, "url='", @selector(url), "'")); | |
| 106 Add(false, Format(node, "visibleCharacterRange='", | |
| 107 @selector(visibleCharacterRange), "'")); | |
| 108 Add(false, Format(node, "visited='", @selector(visited), "'")); | |
| 109 Add(false, FormatPosition(node)); | |
| 110 Add(false, FormatSize(node)); | |
| 111 | |
| 112 return ASCIIToUTF16(prefix) + FinishLine() + ASCIIToUTF16("\n"); | |
| 113 } | |
| 114 | |
| 115 const base::FilePath::StringType | |
| 116 DumpAccessibilityTreeHelper::GetActualFileSuffix() | |
| 117 const { | |
| 118 return FILE_PATH_LITERAL("-actual-mac.txt"); | |
| 119 } | |
| 120 | |
| 121 const base::FilePath::StringType | |
| 122 DumpAccessibilityTreeHelper::GetExpectedFileSuffix() | |
| 123 const { | |
| 124 return FILE_PATH_LITERAL("-expected-mac.txt"); | |
| 125 } | |
| 126 | |
| 127 const std::string DumpAccessibilityTreeHelper::GetAllowEmptyString() const { | |
| 128 return "@MAC-ALLOW-EMPTY:"; | |
| 129 } | |
| 130 | |
| 131 const std::string DumpAccessibilityTreeHelper::GetAllowString() const { | |
| 132 return "@MAC-ALLOW:"; | |
| 133 } | |
| 134 | |
| 135 const std::string DumpAccessibilityTreeHelper::GetDenyString() const { | |
| 136 return "@MAC-DENY:"; | |
| 137 } | |
| 138 | |
| 139 } // namespace content | |
| OLD | NEW |