| 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 #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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #import "base/mac/bundle_locations.h" | 9 #import "base/mac/bundle_locations.h" |
| 10 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 - (int)indexForDragToPoint:(NSPoint)point; | 223 - (int)indexForDragToPoint:(NSPoint)point; |
| 224 | 224 |
| 225 // Add or remove buttons to/from the bar until it is filled but not overflowed. | 225 // Add or remove buttons to/from the bar until it is filled but not overflowed. |
| 226 - (void)redistributeButtonsOnBarAsNeeded; | 226 - (void)redistributeButtonsOnBarAsNeeded; |
| 227 | 227 |
| 228 // Determine the nature of the bookmark bar contents based on the number of | 228 // Determine the nature of the bookmark bar contents based on the number of |
| 229 // buttons showing. If too many then show the off-the-side list, if none | 229 // buttons showing. If too many then show the off-the-side list, if none |
| 230 // then show the no items label. | 230 // then show the no items label. |
| 231 - (void)reconfigureBookmarkBar; | 231 - (void)reconfigureBookmarkBar; |
| 232 | 232 |
| 233 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu; | |
| 234 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu; | |
| 235 - (void)tagEmptyMenu:(NSMenu*)menu; | |
| 236 - (void)clearMenuTagMap; | 233 - (void)clearMenuTagMap; |
| 237 - (int)preferredHeight; | 234 - (int)preferredHeight; |
| 238 - (void)addButtonsToView; | 235 - (void)addButtonsToView; |
| 239 - (BOOL)setManagedBookmarksButtonVisibility; | 236 - (BOOL)setManagedBookmarksButtonVisibility; |
| 240 - (BOOL)setSupervisedBookmarksButtonVisibility; | 237 - (BOOL)setSupervisedBookmarksButtonVisibility; |
| 241 - (BOOL)setOtherBookmarksButtonVisibility; | 238 - (BOOL)setOtherBookmarksButtonVisibility; |
| 242 - (BOOL)setAppsPageShortcutButtonVisibility; | 239 - (BOOL)setAppsPageShortcutButtonVisibility; |
| 243 - (BookmarkButton*)createCustomBookmarkButtonForCell:(NSCell*)cell; | 240 - (BookmarkButton*)createCustomBookmarkButtonForCell:(NSCell*)cell; |
| 244 - (void)createManagedBookmarksButton; | 241 - (void)createManagedBookmarksButton; |
| 245 - (void)createSupervisedBookmarksButton; | 242 - (void)createSupervisedBookmarksButton; |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 switch (currentState_) { | 1109 switch (currentState_) { |
| 1113 case BookmarkBar::SHOW: | 1110 case BookmarkBar::SHOW: |
| 1114 return chrome::kMinimumBookmarkBarHeight; | 1111 return chrome::kMinimumBookmarkBarHeight; |
| 1115 case BookmarkBar::DETACHED: | 1112 case BookmarkBar::DETACHED: |
| 1116 return chrome::kNTPBookmarkBarHeight; | 1113 return chrome::kNTPBookmarkBarHeight; |
| 1117 case BookmarkBar::HIDDEN: | 1114 case BookmarkBar::HIDDEN: |
| 1118 return 0; | 1115 return 0; |
| 1119 } | 1116 } |
| 1120 } | 1117 } |
| 1121 | 1118 |
| 1122 // Recursively add the given bookmark node and all its children to | |
| 1123 // menu, one menu item per node. | |
| 1124 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu { | |
| 1125 NSString* title = [BookmarkMenuCocoaController menuTitleForNode:child]; | |
| 1126 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title | |
| 1127 action:nil | |
| 1128 keyEquivalent:@""] autorelease]; | |
| 1129 [menu addItem:item]; | |
| 1130 [item setImage:[self faviconForNode:child forADarkTheme:NO]]; | |
| 1131 if (child->is_folder()) { | |
| 1132 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease]; | |
| 1133 [menu setSubmenu:submenu forItem:item]; | |
| 1134 if (!child->empty()) { | |
| 1135 [self addFolderNode:child toMenu:submenu]; // potentially recursive | |
| 1136 } else { | |
| 1137 [self tagEmptyMenu:submenu]; | |
| 1138 } | |
| 1139 } else { | |
| 1140 [item setTarget:self]; | |
| 1141 [item setAction:@selector(openBookmarkMenuItem:)]; | |
| 1142 [item setTag:[self menuTagFromNodeId:child->id()]]; | |
| 1143 if (child->is_url()) | |
| 1144 [item setToolTip:[BookmarkMenuCocoaController tooltipForNode:child]]; | |
| 1145 } | |
| 1146 } | |
| 1147 | |
| 1148 // Empty menus are odd; if empty, add something to look at. | |
| 1149 // Matches windows behavior. | |
| 1150 - (void)tagEmptyMenu:(NSMenu*)menu { | |
| 1151 NSString* empty_menu_title = l10n_util::GetNSString(IDS_MENU_EMPTY_SUBMENU); | |
| 1152 [menu addItem:[[[NSMenuItem alloc] initWithTitle:empty_menu_title | |
| 1153 action:NULL | |
| 1154 keyEquivalent:@""] autorelease]]; | |
| 1155 } | |
| 1156 | |
| 1157 // Add the children of the given bookmark node (and their children...) | |
| 1158 // to menu, one menu item per node. | |
| 1159 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu { | |
| 1160 for (int i = 0; i < node->child_count(); i++) { | |
| 1161 const BookmarkNode* child = node->GetChild(i); | |
| 1162 [self addNode:child toMenu:menu]; | |
| 1163 } | |
| 1164 } | |
| 1165 | |
| 1166 // Return an autoreleased NSMenu that represents the given bookmark | |
| 1167 // folder node. | |
| 1168 - (NSMenu *)menuForFolderNode:(const BookmarkNode*)node { | |
| 1169 if (!node->is_folder()) | |
| 1170 return nil; | |
| 1171 NSString* title = base::SysUTF16ToNSString(node->GetTitle()); | |
| 1172 NSMenu* menu = [[[NSMenu alloc] initWithTitle:title] autorelease]; | |
| 1173 [self addFolderNode:node toMenu:menu]; | |
| 1174 | |
| 1175 if (![menu numberOfItems]) { | |
| 1176 [self tagEmptyMenu:menu]; | |
| 1177 } | |
| 1178 return menu; | |
| 1179 } | |
| 1180 | |
| 1181 // Return an appropriate width for the given bookmark button cell. | 1119 // Return an appropriate width for the given bookmark button cell. |
| 1182 - (CGFloat)widthForBookmarkButtonCell:(NSCell*)cell { | 1120 - (CGFloat)widthForBookmarkButtonCell:(NSCell*)cell { |
| 1183 return std::min([cell cellSize].width, bookmarks::kDefaultBookmarkWidth); | 1121 return std::min([cell cellSize].width, bookmarks::kDefaultBookmarkWidth); |
| 1184 } | 1122 } |
| 1185 | 1123 |
| 1186 - (IBAction)openBookmarkMenuItem:(id)sender { | 1124 - (IBAction)openBookmarkMenuItem:(id)sender { |
| 1187 int64_t tag = [self nodeIdFromMenuTag:[sender tag]]; | 1125 int64_t tag = [self nodeIdFromMenuTag:[sender tag]]; |
| 1188 const BookmarkNode* node = | 1126 const BookmarkNode* node = |
| 1189 bookmarks::GetBookmarkNodeByID(bookmarkModel_, tag); | 1127 bookmarks::GetBookmarkNodeByID(bookmarkModel_, tag); |
| 1190 WindowOpenDisposition disposition = | 1128 WindowOpenDisposition disposition = |
| (...skipping 1811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3002 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 2940 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
| 3003 (const BookmarkNode*)node { | 2941 (const BookmarkNode*)node { |
| 3004 // See if it's in the bar, then if it is in the hierarchy of visible | 2942 // See if it's in the bar, then if it is in the hierarchy of visible |
| 3005 // folder menus. | 2943 // folder menus. |
| 3006 if (bookmarkModel_->bookmark_bar_node() == node) | 2944 if (bookmarkModel_->bookmark_bar_node() == node) |
| 3007 return self; | 2945 return self; |
| 3008 return [folderController_ controllerForNode:node]; | 2946 return [folderController_ controllerForNode:node]; |
| 3009 } | 2947 } |
| 3010 | 2948 |
| 3011 @end | 2949 @end |
| OLD | NEW |