| 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/dump_accessibility_tree_helper.h" | 5 #include "content/browser/accessibility/dump_accessibility_tree_helper.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "content/browser/accessibility/browser_accessibility_cocoa.h" | 11 #include "content/browser/accessibility/browser_accessibility_cocoa.h" |
| 12 #include "content/browser/accessibility/browser_accessibility_mac.h" | 12 #include "content/browser/accessibility/browser_accessibility_mac.h" |
| 13 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 16 |
| 15 namespace { | 17 namespace { |
| 18 |
| 16 string16 Format(BrowserAccessibility* node, | 19 string16 Format(BrowserAccessibility* node, |
| 17 const char *prefix, | 20 const char *prefix, |
| 18 SEL selector, | 21 SEL selector, |
| 19 const char *suffix) { | 22 const char *suffix) { |
| 20 BrowserAccessibilityCocoa* cocoa_node = node->ToBrowserAccessibilityCocoa(); | 23 BrowserAccessibilityCocoa* cocoa_node = node->ToBrowserAccessibilityCocoa(); |
| 21 id value = [cocoa_node performSelector:selector]; | 24 id value = [cocoa_node performSelector:selector]; |
| 22 if (!value) | 25 if (!value) |
| 23 return string16(); | 26 return string16(); |
| 24 NSString* format_str = | 27 NSString* format_str = |
| 25 [NSString stringWithFormat:@"%s%%@%s", prefix, suffix]; | 28 [NSString stringWithFormat:@"%s%%@%s", prefix, suffix]; |
| 26 NSString* tmp = [NSString stringWithFormat:format_str, value]; | 29 NSString* tmp = [NSString stringWithFormat:format_str, value]; |
| 27 return UTF8ToUTF16([tmp cStringUsingEncoding:NSUTF8StringEncoding]); | 30 return UTF8ToUTF16([tmp cStringUsingEncoding:NSUTF8StringEncoding]); |
| 28 } | 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]); |
| 29 } | 55 } |
| 30 | 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 |
| 31 void DumpAccessibilityTreeHelper::Initialize() {} | 69 void DumpAccessibilityTreeHelper::Initialize() {} |
| 32 | 70 |
| 33 string16 DumpAccessibilityTreeHelper::ToString(BrowserAccessibility* node, | 71 string16 DumpAccessibilityTreeHelper::ToString(BrowserAccessibility* node, |
| 34 char* prefix) { | 72 char* prefix) { |
| 35 StartLine(); | 73 StartLine(); |
| 36 Add(true, Format(node, "", @selector(role), "")); | 74 Add(true, Format(node, "", @selector(role), "")); |
| 37 Add(false, Format(node, "subrole=", @selector(subrole), "")); | 75 Add(false, Format(node, "subrole=", @selector(subrole), "")); |
| 38 Add(false, Format(node, "roleDescription='", | 76 Add(false, Format(node, "roleDescription='", |
| 39 @selector(roleDescription), | 77 @selector(roleDescription), |
| 40 "'")); | 78 "'")); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 Add(false, Format(node, "ariaLive='", @selector(ariaLive), "'")); | 94 Add(false, Format(node, "ariaLive='", @selector(ariaLive), "'")); |
| 57 Add(false, Format(node, "ariaRelevant='", @selector(ariaRelevant), "'")); | 95 Add(false, Format(node, "ariaRelevant='", @selector(ariaRelevant), "'")); |
| 58 Add(false, Format(node, "enabled='", @selector(enabled), "'")); | 96 Add(false, Format(node, "enabled='", @selector(enabled), "'")); |
| 59 Add(false, Format(node, "focused='", @selector(focused), "'")); | 97 Add(false, Format(node, "focused='", @selector(focused), "'")); |
| 60 Add(false, Format(node, "loaded='", @selector(loaded), "'")); | 98 Add(false, Format(node, "loaded='", @selector(loaded), "'")); |
| 61 Add(false, Format(node, "loadingProgress='", @selector(loadingProgress), | 99 Add(false, Format(node, "loadingProgress='", @selector(loadingProgress), |
| 62 "'")); | 100 "'")); |
| 63 Add(false, Format(node, "numberOfCharacters='", | 101 Add(false, Format(node, "numberOfCharacters='", |
| 64 @selector(numberOfCharacters), "'")); | 102 @selector(numberOfCharacters), "'")); |
| 65 Add(false, Format(node, "orientation='", @selector(orientation), "'")); | 103 Add(false, Format(node, "orientation='", @selector(orientation), "'")); |
| 66 Add(false, Format(node, "position='", @selector(position), "'")); | |
| 67 Add(false, Format(node, "required='", @selector(required), "'")); | 104 Add(false, Format(node, "required='", @selector(required), "'")); |
| 68 Add(false, Format(node, "size='", @selector(size), "'")); | |
| 69 Add(false, Format(node, "url='", @selector(url), "'")); | 105 Add(false, Format(node, "url='", @selector(url), "'")); |
| 70 Add(false, Format(node, "visibleCharacterRange='", | 106 Add(false, Format(node, "visibleCharacterRange='", |
| 71 @selector(visibleCharacterRange), "'")); | 107 @selector(visibleCharacterRange), "'")); |
| 72 Add(false, Format(node, "visited='", @selector(visited), "'")); | 108 Add(false, Format(node, "visited='", @selector(visited), "'")); |
| 109 Add(false, FormatPosition(node)); |
| 110 Add(false, FormatSize(node)); |
| 111 |
| 73 return ASCIIToUTF16(prefix) + FinishLine() + ASCIIToUTF16("\n"); | 112 return ASCIIToUTF16(prefix) + FinishLine() + ASCIIToUTF16("\n"); |
| 74 } | 113 } |
| 75 | 114 |
| 76 const FilePath::StringType DumpAccessibilityTreeHelper::GetActualFileSuffix() | 115 const FilePath::StringType DumpAccessibilityTreeHelper::GetActualFileSuffix() |
| 77 const { | 116 const { |
| 78 return FILE_PATH_LITERAL("-actual-mac.txt"); | 117 return FILE_PATH_LITERAL("-actual-mac.txt"); |
| 79 } | 118 } |
| 80 | 119 |
| 81 const FilePath::StringType DumpAccessibilityTreeHelper::GetExpectedFileSuffix() | 120 const FilePath::StringType DumpAccessibilityTreeHelper::GetExpectedFileSuffix() |
| 82 const { | 121 const { |
| 83 return FILE_PATH_LITERAL("-expected-mac.txt"); | 122 return FILE_PATH_LITERAL("-expected-mac.txt"); |
| 84 } | 123 } |
| 85 | 124 |
| 86 const std::string DumpAccessibilityTreeHelper::GetAllowEmptyString() const { | 125 const std::string DumpAccessibilityTreeHelper::GetAllowEmptyString() const { |
| 87 return "@MAC-ALLOW-EMPTY:"; | 126 return "@MAC-ALLOW-EMPTY:"; |
| 88 } | 127 } |
| 89 | 128 |
| 90 const std::string DumpAccessibilityTreeHelper::GetAllowString() const { | 129 const std::string DumpAccessibilityTreeHelper::GetAllowString() const { |
| 91 return "@MAC-ALLOW:"; | 130 return "@MAC-ALLOW:"; |
| 92 } | 131 } |
| 93 | 132 |
| 94 const std::string DumpAccessibilityTreeHelper::GetDenyString() const { | 133 const std::string DumpAccessibilityTreeHelper::GetDenyString() const { |
| 95 return "@MAC-DENY:"; | 134 return "@MAC-DENY:"; |
| 96 } | 135 } |
| 97 | 136 |
| 98 } // namespace content | 137 } // namespace content |
| OLD | NEW |