OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
6 | 6 |
7 #include "app/mac/nsimage_cache.h" | 7 #include "app/mac/nsimage_cache.h" |
8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 [menu setSubmenu:submenu forItem:item]; | 1138 [menu setSubmenu:submenu forItem:item]; |
1139 if (child->child_count()) { | 1139 if (child->child_count()) { |
1140 [self addFolderNode:child toMenu:submenu]; // potentially recursive | 1140 [self addFolderNode:child toMenu:submenu]; // potentially recursive |
1141 } else { | 1141 } else { |
1142 [self tagEmptyMenu:submenu]; | 1142 [self tagEmptyMenu:submenu]; |
1143 } | 1143 } |
1144 } else { | 1144 } else { |
1145 [item setTarget:self]; | 1145 [item setTarget:self]; |
1146 [item setAction:@selector(openBookmarkMenuItem:)]; | 1146 [item setAction:@selector(openBookmarkMenuItem:)]; |
1147 [item setTag:[self menuTagFromNodeId:child->id()]]; | 1147 [item setTag:[self menuTagFromNodeId:child->id()]]; |
1148 if (child->is_url()) { | 1148 if (child->is_url()) |
1149 // Add a tooltip | 1149 [item setToolTip:[self tooltipForNode:child]]; |
1150 std::string url_string = child->GetURL().possibly_invalid_spec(); | |
1151 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", | |
1152 base::SysUTF16ToNSString(child->GetTitle()), | |
1153 url_string.c_str()]; | |
1154 [item setToolTip:tooltip]; | |
1155 } | |
1156 } | 1150 } |
1157 } | 1151 } |
1158 | 1152 |
1159 // Empty menus are odd; if empty, add something to look at. | 1153 // Empty menus are odd; if empty, add something to look at. |
1160 // Matches windows behavior. | 1154 // Matches windows behavior. |
1161 - (void)tagEmptyMenu:(NSMenu*)menu { | 1155 - (void)tagEmptyMenu:(NSMenu*)menu { |
1162 NSString* empty_menu_title = l10n_util::GetNSString(IDS_MENU_EMPTY_SUBMENU); | 1156 NSString* empty_menu_title = l10n_util::GetNSString(IDS_MENU_EMPTY_SUBMENU); |
1163 [menu addItem:[[[NSMenuItem alloc] initWithTitle:empty_menu_title | 1157 [menu addItem:[[[NSMenuItem alloc] initWithTitle:empty_menu_title |
1164 action:NULL | 1158 action:NULL |
1165 keyEquivalent:@""] autorelease]]; | 1159 keyEquivalent:@""] autorelease]]; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1225 int xOffset = 0; | 1219 int xOffset = 0; |
1226 for (int i = 0; i < node->child_count(); i++) { | 1220 for (int i = 0; i < node->child_count(); i++) { |
1227 const BookmarkNode* child = node->GetChild(i); | 1221 const BookmarkNode* child = node->GetChild(i); |
1228 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; | 1222 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; |
1229 if (NSMinX([button frame]) >= maxViewX) | 1223 if (NSMinX([button frame]) >= maxViewX) |
1230 break; | 1224 break; |
1231 [buttons_ addObject:button]; | 1225 [buttons_ addObject:button]; |
1232 } | 1226 } |
1233 } | 1227 } |
1234 | 1228 |
1229 - (NSString*)tooltipForNode:(const BookmarkNode*)node { | |
1230 NSString* title = base::SysUTF16ToNSString(node->GetTitle()); | |
1231 std::string url_string = node->GetURL().possibly_invalid_spec(); | |
1232 NSString *url = [NSString stringWithUTF8String:url_string.c_str()]; | |
mrossetti
2011/05/25 23:35:54
Nit: Move asterisk left.
| |
1233 if ([title length] == 0) | |
1234 return url; | |
1235 else if ([url length] == 0 || [url isEqualToString:title]) | |
1236 return title; | |
1237 else | |
1238 return [NSString stringWithFormat:@"%@\n%@", title, url]; | |
1239 } | |
1240 | |
1235 - (BookmarkButton*)buttonForNode:(const BookmarkNode*)node | 1241 - (BookmarkButton*)buttonForNode:(const BookmarkNode*)node |
1236 xOffset:(int*)xOffset { | 1242 xOffset:(int*)xOffset { |
1237 BookmarkButtonCell* cell = [self cellForBookmarkNode:node]; | 1243 BookmarkButtonCell* cell = [self cellForBookmarkNode:node]; |
1238 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:xOffset]; | 1244 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:xOffset]; |
1239 | 1245 |
1240 scoped_nsobject<BookmarkButton> | 1246 scoped_nsobject<BookmarkButton> |
1241 button([[BookmarkButton alloc] initWithFrame:frame]); | 1247 button([[BookmarkButton alloc] initWithFrame:frame]); |
1242 DCHECK(button.get()); | 1248 DCHECK(button.get()); |
1243 | 1249 |
1244 // [NSButton setCell:] warns to NOT use setCell: other than in the | 1250 // [NSButton setCell:] warns to NOT use setCell: other than in the |
(...skipping 19 matching lines...) Expand all Loading... | |
1264 } | 1270 } |
1265 | 1271 |
1266 if (node->is_folder()) { | 1272 if (node->is_folder()) { |
1267 [button setTarget:self]; | 1273 [button setTarget:self]; |
1268 [button setAction:@selector(openBookmarkFolderFromButton:)]; | 1274 [button setAction:@selector(openBookmarkFolderFromButton:)]; |
1269 [button setActsOnMouseDown:YES]; | 1275 [button setActsOnMouseDown:YES]; |
1270 } else { | 1276 } else { |
1271 // Make the button do something | 1277 // Make the button do something |
1272 [button setTarget:self]; | 1278 [button setTarget:self]; |
1273 [button setAction:@selector(openBookmark:)]; | 1279 [button setAction:@selector(openBookmark:)]; |
1274 if (node->is_url()) { | 1280 if (node->is_url()) |
1275 // Add a tooltip. | 1281 [button setToolTip:[self tooltipForNode:node]]; |
1276 NSString* title = base::SysUTF16ToNSString(node->GetTitle()); | |
1277 std::string url_string = node->GetURL().possibly_invalid_spec(); | |
1278 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", title, | |
1279 url_string.c_str()]; | |
1280 [button setToolTip:tooltip]; | |
1281 } | |
1282 } | 1282 } |
1283 return [[button.get() retain] autorelease]; | 1283 return [[button.get() retain] autorelease]; |
1284 } | 1284 } |
1285 | 1285 |
1286 // Add non-bookmark buttons to the view. This includes the chevron | 1286 // Add non-bookmark buttons to the view. This includes the chevron |
1287 // and the "other bookmarks" button. Technically "other bookmarks" is | 1287 // and the "other bookmarks" button. Technically "other bookmarks" is |
1288 // a bookmark button but it is treated specially. Only needs to be | 1288 // a bookmark button but it is treated specially. Only needs to be |
1289 // called when these buttons are new or when the bookmark bar is | 1289 // called when these buttons are new or when the bookmark bar is |
1290 // cleared (e.g. on a loaded: call). Unlike addButtonsToView below, | 1290 // cleared (e.g. on a loaded: call). Unlike addButtonsToView below, |
1291 // we don't need to add/remove these dynamically in response to window | 1291 // we don't need to add/remove these dynamically in response to window |
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2727 // to minimize touching the object passed in (likely a mock). | 2727 // to minimize touching the object passed in (likely a mock). |
2728 - (void)setButtonContextMenu:(id)menu { | 2728 - (void)setButtonContextMenu:(id)menu { |
2729 buttonContextMenu_ = menu; | 2729 buttonContextMenu_ = menu; |
2730 } | 2730 } |
2731 | 2731 |
2732 - (void)setIgnoreAnimations:(BOOL)ignore { | 2732 - (void)setIgnoreAnimations:(BOOL)ignore { |
2733 ignoreAnimations_ = ignore; | 2733 ignoreAnimations_ = ignore; |
2734 } | 2734 } |
2735 | 2735 |
2736 @end | 2736 @end |
OLD | NEW |