| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/cocoa/bookmark_bar_controller.h" | 5 #import "chrome/browser/cocoa/bookmark_bar_controller.h" |
| 6 #include "app/l10n_util_mac.h" | 6 #include "app/l10n_util_mac.h" |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_editor.h" | 10 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| (...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 } else { | 977 } else { |
| 978 [self tagEmptyMenu:submenu]; | 978 [self tagEmptyMenu:submenu]; |
| 979 } | 979 } |
| 980 } else { | 980 } else { |
| 981 [item setTarget:self]; | 981 [item setTarget:self]; |
| 982 [item setAction:@selector(openBookmarkMenuItem:)]; | 982 [item setAction:@selector(openBookmarkMenuItem:)]; |
| 983 [item setTag:[self menuTagFromNodeId:child->id()]]; | 983 [item setTag:[self menuTagFromNodeId:child->id()]]; |
| 984 // Add a tooltip | 984 // Add a tooltip |
| 985 std::string url_string = child->GetURL().possibly_invalid_spec(); | 985 std::string url_string = child->GetURL().possibly_invalid_spec(); |
| 986 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", | 986 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", |
| 987 base::SysWideToNSString(child->GetTitle()), | 987 base::SysUTF16ToNSString(child->GetTitleAsString16()), |
| 988 url_string.c_str()]; | 988 url_string.c_str()]; |
| 989 [item setToolTip:tooltip]; | 989 [item setToolTip:tooltip]; |
| 990 } | 990 } |
| 991 } | 991 } |
| 992 | 992 |
| 993 // Empty menus are odd; if empty, add something to look at. | 993 // Empty menus are odd; if empty, add something to look at. |
| 994 // Matches windows behavior. | 994 // Matches windows behavior. |
| 995 - (void)tagEmptyMenu:(NSMenu*)menu { | 995 - (void)tagEmptyMenu:(NSMenu*)menu { |
| 996 NSString* empty_menu_title = l10n_util::GetNSString(IDS_MENU_EMPTY_SUBMENU); | 996 NSString* empty_menu_title = l10n_util::GetNSString(IDS_MENU_EMPTY_SUBMENU); |
| 997 [menu addItem:[[[NSMenuItem alloc] initWithTitle:empty_menu_title | 997 [menu addItem:[[[NSMenuItem alloc] initWithTitle:empty_menu_title |
| 998 action:NULL | 998 action:NULL |
| 999 keyEquivalent:@""] autorelease]]; | 999 keyEquivalent:@""] autorelease]]; |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 // Add the children of the given bookmark node (and their children...) | 1002 // Add the children of the given bookmark node (and their children...) |
| 1003 // to menu, one menu item per node. | 1003 // to menu, one menu item per node. |
| 1004 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu { | 1004 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu { |
| 1005 for (int i = 0; i < node->GetChildCount(); i++) { | 1005 for (int i = 0; i < node->GetChildCount(); i++) { |
| 1006 const BookmarkNode* child = node->GetChild(i); | 1006 const BookmarkNode* child = node->GetChild(i); |
| 1007 [self addNode:child toMenu:menu]; | 1007 [self addNode:child toMenu:menu]; |
| 1008 } | 1008 } |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 // Return an autoreleased NSMenu that represents the given bookmark | 1011 // Return an autoreleased NSMenu that represents the given bookmark |
| 1012 // folder node. | 1012 // folder node. |
| 1013 - (NSMenu *)menuForFolderNode:(const BookmarkNode*)node { | 1013 - (NSMenu *)menuForFolderNode:(const BookmarkNode*)node { |
| 1014 if (!node->is_folder()) | 1014 if (!node->is_folder()) |
| 1015 return nil; | 1015 return nil; |
| 1016 NSString* title = base::SysWideToNSString(node->GetTitle()); | 1016 NSString* title = base::SysUTF16ToNSString(node->GetTitleAsString16()); |
| 1017 NSMenu* menu = [[[NSMenu alloc] initWithTitle:title] autorelease]; | 1017 NSMenu* menu = [[[NSMenu alloc] initWithTitle:title] autorelease]; |
| 1018 [self addFolderNode:node toMenu:menu]; | 1018 [self addFolderNode:node toMenu:menu]; |
| 1019 | 1019 |
| 1020 if (![menu numberOfItems]) { | 1020 if (![menu numberOfItems]) { |
| 1021 [self tagEmptyMenu:menu]; | 1021 [self tagEmptyMenu:menu]; |
| 1022 } | 1022 } |
| 1023 return menu; | 1023 return menu; |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 // Return an appropriate width for the given bookmark button cell. | 1026 // Return an appropriate width for the given bookmark button cell. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 if (node->is_folder()) { | 1100 if (node->is_folder()) { |
| 1101 [button setTarget:self]; | 1101 [button setTarget:self]; |
| 1102 [button setAction:@selector(openBookmarkFolderFromButton:)]; | 1102 [button setAction:@selector(openBookmarkFolderFromButton:)]; |
| 1103 } else { | 1103 } else { |
| 1104 // Make the button do something | 1104 // Make the button do something |
| 1105 [button setTarget:self]; | 1105 [button setTarget:self]; |
| 1106 [button setAction:@selector(openBookmark:)]; | 1106 [button setAction:@selector(openBookmark:)]; |
| 1107 // Add a tooltip. | 1107 // Add a tooltip. |
| 1108 NSString* title = base::SysWideToNSString(node->GetTitle()); | 1108 NSString* title = base::SysUTF16ToNSString(node->GetTitleAsString16()); |
| 1109 std::string url_string = node->GetURL().possibly_invalid_spec(); | 1109 std::string url_string = node->GetURL().possibly_invalid_spec(); |
| 1110 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", title, | 1110 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", title, |
| 1111 url_string.c_str()]; | 1111 url_string.c_str()]; |
| 1112 [button setToolTip:tooltip]; | 1112 [button setToolTip:tooltip]; |
| 1113 } | 1113 } |
| 1114 return [[button.get() retain] autorelease]; | 1114 return [[button.get() retain] autorelease]; |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 // Add non-bookmark buttons to the view. This includes the chevron | 1117 // Add non-bookmark buttons to the view. This includes the chevron |
| 1118 // and the "other bookmarks" button. Technically "other bookmarks" is | 1118 // and the "other bookmarks" button. Technically "other bookmarks" is |
| (...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2432 // to minimize touching the object passed in (likely a mock). | 2432 // to minimize touching the object passed in (likely a mock). |
| 2433 - (void)setButtonContextMenu:(id)menu { | 2433 - (void)setButtonContextMenu:(id)menu { |
| 2434 buttonContextMenu_ = menu; | 2434 buttonContextMenu_ = menu; |
| 2435 } | 2435 } |
| 2436 | 2436 |
| 2437 - (void)setIgnoreAnimations:(BOOL)ignore { | 2437 - (void)setIgnoreAnimations:(BOOL)ignore { |
| 2438 ignoreAnimations_ = ignore; | 2438 ignoreAnimations_ = ignore; |
| 2439 } | 2439 } |
| 2440 | 2440 |
| 2441 @end | 2441 @end |
| OLD | NEW |