Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm

Issue 2798113002: [Mac] Remove more dead code from bookmark bar controller (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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)clearMenuTagMap;
234 - (int)preferredHeight; 233 - (int)preferredHeight;
235 - (void)addButtonsToView; 234 - (void)addButtonsToView;
236 - (BOOL)setManagedBookmarksButtonVisibility; 235 - (BOOL)setManagedBookmarksButtonVisibility;
237 - (BOOL)setSupervisedBookmarksButtonVisibility; 236 - (BOOL)setSupervisedBookmarksButtonVisibility;
238 - (BOOL)setOtherBookmarksButtonVisibility; 237 - (BOOL)setOtherBookmarksButtonVisibility;
239 - (BOOL)setAppsPageShortcutButtonVisibility; 238 - (BOOL)setAppsPageShortcutButtonVisibility;
240 - (BookmarkButton*)createCustomBookmarkButtonForCell:(NSCell*)cell; 239 - (BookmarkButton*)createCustomBookmarkButtonForCell:(NSCell*)cell;
241 - (void)createManagedBookmarksButton; 240 - (void)createManagedBookmarksButton;
242 - (void)createSupervisedBookmarksButton; 241 - (void)createSupervisedBookmarksButton;
243 - (void)createOtherBookmarksButton; 242 - (void)createOtherBookmarksButton;
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 1078
1080 // Actually open the URL. This is the last chance for a unit test to 1079 // Actually open the URL. This is the last chance for a unit test to
1081 // override. 1080 // override.
1082 - (void)openURL:(GURL)url disposition:(WindowOpenDisposition)disposition { 1081 - (void)openURL:(GURL)url disposition:(WindowOpenDisposition)disposition {
1083 OpenURLParams params( 1082 OpenURLParams params(
1084 url, Referrer(), disposition, ui::PAGE_TRANSITION_AUTO_BOOKMARK, 1083 url, Referrer(), disposition, ui::PAGE_TRANSITION_AUTO_BOOKMARK,
1085 false); 1084 false);
1086 browser_->OpenURL(params); 1085 browser_->OpenURL(params);
1087 } 1086 }
1088 1087
1089 - (void)clearMenuTagMap {
1090 seedId_ = 0;
1091 menuTagMap_.clear();
1092 }
1093
1094 - (int)preferredHeight { 1088 - (int)preferredHeight {
1095 DCHECK(![self isAnimationRunning]); 1089 DCHECK(![self isAnimationRunning]);
1096 1090
1097 if (!barIsEnabled_) 1091 if (!barIsEnabled_)
1098 return 0; 1092 return 0;
1099 1093
1100 switch (currentState_) { 1094 switch (currentState_) {
1101 case BookmarkBar::SHOW: 1095 case BookmarkBar::SHOW:
1102 return chrome::kMinimumBookmarkBarHeight; 1096 return chrome::kMinimumBookmarkBarHeight;
1103 case BookmarkBar::DETACHED: 1097 case BookmarkBar::DETACHED:
1104 return chrome::kNTPBookmarkBarHeight; 1098 return chrome::kNTPBookmarkBarHeight;
1105 case BookmarkBar::HIDDEN: 1099 case BookmarkBar::HIDDEN:
1106 return 0; 1100 return 0;
1107 } 1101 }
1108 } 1102 }
1109 1103
1110 // Return an appropriate width for the given bookmark button cell. 1104 // Return an appropriate width for the given bookmark button cell.
1111 - (CGFloat)widthForBookmarkButtonCell:(NSCell*)cell { 1105 - (CGFloat)widthForBookmarkButtonCell:(NSCell*)cell {
1112 return std::min([cell cellSize].width, bookmarks::kDefaultBookmarkWidth); 1106 return std::min([cell cellSize].width, bookmarks::kDefaultBookmarkWidth);
1113 } 1107 }
1114 1108
1115 - (IBAction)openBookmarkMenuItem:(id)sender {
1116 int64_t tag = [self nodeIdFromMenuTag:[sender tag]];
1117 const BookmarkNode* node =
1118 bookmarks::GetBookmarkNodeByID(bookmarkModel_, tag);
1119 WindowOpenDisposition disposition =
1120 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]);
1121 [self openURL:node->url() disposition:disposition];
1122 }
1123
1124 // For the given root node of the bookmark bar, show or hide (as 1109 // For the given root node of the bookmark bar, show or hide (as
1125 // appropriate) the "no items" container (text which says "bookmarks 1110 // appropriate) the "no items" container (text which says "bookmarks
1126 // go here"). 1111 // go here").
1127 - (void)showOrHideNoItemContainerForNode:(const BookmarkNode*)node { 1112 - (void)showOrHideNoItemContainerForNode:(const BookmarkNode*)node {
1128 BOOL hideNoItemWarning = !node->empty(); 1113 BOOL hideNoItemWarning = !node->empty();
1129 [[buttonView_ noItemContainer] setHidden:hideNoItemWarning]; 1114 [[buttonView_ noItemContainer] setHidden:hideNoItemWarning];
1130 } 1115 }
1131 1116
1132 // TODO(jrg): write a "build bar" so there is a nice spot for things 1117 // TODO(jrg): write a "build bar" so there is a nice spot for things
1133 // like the contextual menu which is invoked when not over a 1118 // like the contextual menu which is invoked when not over a
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 1788
1804 // Delete all buttons (bookmarks, chevron, "other bookmarks") from the 1789 // Delete all buttons (bookmarks, chevron, "other bookmarks") from the
1805 // bookmark bar; reset knowledge of bookmarks. 1790 // bookmark bar; reset knowledge of bookmarks.
1806 - (void)clearBookmarkBar { 1791 - (void)clearBookmarkBar {
1807 [self stopPulsingBookmarkNode]; 1792 [self stopPulsingBookmarkNode];
1808 for (BookmarkButton* button in buttons_.get()) { 1793 for (BookmarkButton* button in buttons_.get()) {
1809 [button setDelegate:nil]; 1794 [button setDelegate:nil];
1810 [button removeFromSuperview]; 1795 [button removeFromSuperview];
1811 } 1796 }
1812 [buttons_ removeAllObjects]; 1797 [buttons_ removeAllObjects];
1813 [self clearMenuTagMap];
1814 displayedButtonCount_ = 0; 1798 displayedButtonCount_ = 0;
1815 1799
1816 // Make sure there are no stale pointers in the pasteboard. This 1800 // Make sure there are no stale pointers in the pasteboard. This
1817 // can be important if a bookmark is deleted (via bookmark sync) 1801 // can be important if a bookmark is deleted (via bookmark sync)
1818 // while in the middle of a drag. The "drag completed" code 1802 // while in the middle of a drag. The "drag completed" code
1819 // (e.g. [BookmarkBarView performDragOperationForBookmarkButton:]) is 1803 // (e.g. [BookmarkBarView performDragOperationForBookmarkButton:]) is
1820 // careful enough to bail if there is no data found at "drop" time. 1804 // careful enough to bail if there is no data found at "drop" time.
1821 [[NSPasteboard pasteboardWithName:NSDragPboard] clearContents]; 1805 [[NSPasteboard pasteboardWithName:NSDragPboard] clearContents];
1822 } 1806 }
1823 1807
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 } 1890 }
1907 1891
1908 // Called when our controlled frame has changed size. 1892 // Called when our controlled frame has changed size.
1909 - (void)frameDidChange { 1893 - (void)frameDidChange {
1910 if (!bookmarkModel_->loaded()) 1894 if (!bookmarkModel_->loaded())
1911 return; 1895 return;
1912 [self updateTheme:[[[self view] window] themeProvider]]; 1896 [self updateTheme:[[[self view] window] themeProvider]];
1913 [self reconfigureBookmarkBar]; 1897 [self reconfigureBookmarkBar];
1914 } 1898 }
1915 1899
1916 // Given a NSMenuItem tag, return the appropriate bookmark node id.
1917 - (int64_t)nodeIdFromMenuTag:(int32_t)tag {
1918 return menuTagMap_[tag];
1919 }
1920
1921 // Create and return a new tag for the given node id.
1922 - (int32_t)menuTagFromNodeId:(int64_t)menuid {
1923 int tag = seedId_++;
1924 menuTagMap_[tag] = menuid;
1925 return tag;
1926 }
1927
1928 // Adapt appearance of buttons to the current theme. Called after 1900 // Adapt appearance of buttons to the current theme. Called after
1929 // theme changes, or when our view is added to the view hierarchy. 1901 // theme changes, or when our view is added to the view hierarchy.
1930 // Oddly, the view pings us instead of us pinging our view. This is 1902 // Oddly, the view pings us instead of us pinging our view. This is
1931 // because our trigger is an [NSView viewWillMoveToWindow:], which the 1903 // because our trigger is an [NSView viewWillMoveToWindow:], which the
1932 // controller doesn't normally know about. Otherwise we don't have 1904 // controller doesn't normally know about. Otherwise we don't have
1933 // access to the theme before we know what window we will be on. 1905 // access to the theme before we know what window we will be on.
1934 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider { 1906 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider {
1935 if (!themeProvider) 1907 if (!themeProvider)
1936 return; 1908 return;
1937 NSColor* color = 1909 NSColor* color =
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
2947 - (id<BookmarkButtonControllerProtocol>)controllerForNode: 2919 - (id<BookmarkButtonControllerProtocol>)controllerForNode:
2948 (const BookmarkNode*)node { 2920 (const BookmarkNode*)node {
2949 // See if it's in the bar, then if it is in the hierarchy of visible 2921 // See if it's in the bar, then if it is in the hierarchy of visible
2950 // folder menus. 2922 // folder menus.
2951 if (bookmarkModel_->bookmark_bar_node() == node) 2923 if (bookmarkModel_->bookmark_bar_node() == node)
2952 return self; 2924 return self;
2953 return [folderController_ controllerForNode:node]; 2925 return [folderController_ controllerForNode:node];
2954 } 2926 }
2955 2927
2956 @end 2928 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698