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

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

Issue 164547: Mac: make save/open dialogs operate as tab-modal sheets.... Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Painfully (but hopefully correctly) merged ToT. Created 11 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/l10n_util_mac.h" 5 #include "app/l10n_util_mac.h"
6 #include "app/resource_bundle.h" 6 #include "app/resource_bundle.h"
7 #include "base/mac_util.h" 7 #include "base/mac_util.h"
8 #include "base/nsimage_cache_mac.h" 8 #include "base/nsimage_cache_mac.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/app/chrome_dll_resource.h" // IDC_*
10 #include "chrome/browser/bookmarks/bookmark_editor.h" 11 #include "chrome/browser/bookmarks/bookmark_editor.h"
11 #include "chrome/browser/bookmarks/bookmark_model.h" 12 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #include "chrome/browser/browser.h" 13 #include "chrome/browser/browser.h"
13 #include "chrome/browser/browser_list.h" 14 #include "chrome/browser/browser_list.h"
14 #import "chrome/browser/cocoa/bookmark_bar_bridge.h" 15 #import "chrome/browser/cocoa/bookmark_bar_bridge.h"
15 #import "chrome/browser/cocoa/bookmark_bar_controller.h" 16 #import "chrome/browser/cocoa/bookmark_bar_controller.h"
16 #import "chrome/browser/cocoa/bookmark_bar_view.h" 17 #import "chrome/browser/cocoa/bookmark_bar_view.h"
17 #import "chrome/browser/cocoa/bookmark_button_cell.h" 18 #import "chrome/browser/cocoa/bookmark_button_cell.h"
18 #import "chrome/browser/cocoa/bookmark_editor_controller.h" 19 #import "chrome/browser/cocoa/bookmark_editor_controller.h"
19 #import "chrome/browser/cocoa/bookmark_name_folder_controller.h" 20 #import "chrome/browser/cocoa/bookmark_name_folder_controller.h"
(...skipping 22 matching lines...) Expand all
42 @end 43 @end
43 44
44 @interface BookmarkBarController(Private) 45 @interface BookmarkBarController(Private)
45 - (void)applyContentAreaOffset:(BOOL)apply immediately:(BOOL)immediately; 46 - (void)applyContentAreaOffset:(BOOL)apply immediately:(BOOL)immediately;
46 - (void)showBookmarkBar:(BOOL)enable immediately:(BOOL)immediately; 47 - (void)showBookmarkBar:(BOOL)enable immediately:(BOOL)immediately;
47 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu; 48 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu;
48 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu; 49 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu;
49 - (void)tagEmptyMenu:(NSMenu*)menu; 50 - (void)tagEmptyMenu:(NSMenu*)menu;
50 - (void)clearMenuTagMap; 51 - (void)clearMenuTagMap;
51 - (int)preferredHeight; 52 - (int)preferredHeight;
53 - (void)greyOutBookmarkBar:(BOOL)doGreyOut;
52 @end 54 @end
53 55
54 namespace { 56 namespace {
55 57
56 // Our height, when opened in "always visible" mode. 58 // Our height, when opened in "always visible" mode.
57 const int kBookmarkBarHeight = 28; 59 const int kBookmarkBarHeight = 28;
58 60
59 // Our height, when visible in "new tab page" mode. 61 // Our height, when visible in "new tab page" mode.
60 const int kNTPBookmarkBarHeight = 40; 62 const int kNTPBookmarkBarHeight = 40;
61 63
62 // Magic numbers from Cole 64 // Magic numbers from Cole
63 const CGFloat kDefaultBookmarkWidth = 150.0; 65 const CGFloat kDefaultBookmarkWidth = 150.0;
64 const CGFloat kBookmarkVerticalPadding = 2.0; 66 const CGFloat kBookmarkVerticalPadding = 2.0;
65 const CGFloat kBookmarkHorizontalPadding = 1.0; 67 const CGFloat kBookmarkHorizontalPadding = 1.0;
66 68
67 } // namespace 69 } // namespace
68 70
69 @implementation BookmarkBarController 71 @implementation BookmarkBarController
70 72
71 - (id)initWithBrowser:(Browser*)browser 73 - (id)initWithBrowser:(Browser*)browser
72 initialWidth:(float)initialWidth 74 initialWidth:(float)initialWidth
73 compressDelegate:(id<ToolbarCompressable>)compressDelegate 75 compressDelegate:(id<ToolbarCompressable>)compressDelegate
74 resizeDelegate:(id<ViewResizer>)resizeDelegate 76 resizeDelegate:(id<ViewResizer>)resizeDelegate
75 urlDelegate:(id<BookmarkURLOpener>)urlDelegate { 77 urlDelegate:(id<BookmarkURLOpener>)urlDelegate
78 commands:(CommandUpdater*)commands {
76 if ((self = [super initWithNibName:@"BookmarkBar" 79 if ((self = [super initWithNibName:@"BookmarkBar"
77 bundle:mac_util::MainAppBundle()])) { 80 bundle:mac_util::MainAppBundle()])) {
78 browser_ = browser; 81 browser_ = browser;
79 initialWidth_ = initialWidth; 82 initialWidth_ = initialWidth;
80 bookmarkModel_ = browser_->profile()->GetBookmarkModel(); 83 bookmarkModel_ = browser_->profile()->GetBookmarkModel();
81 buttons_.reset([[NSMutableArray alloc] init]); 84 buttons_.reset([[NSMutableArray alloc] init]);
82 compressDelegate_ = compressDelegate; 85 compressDelegate_ = compressDelegate;
83 resizeDelegate_ = resizeDelegate; 86 resizeDelegate_ = resizeDelegate;
84 urlDelegate_ = urlDelegate; 87 urlDelegate_ = urlDelegate;
85 tabObserver_.reset( 88 tabObserver_.reset(
86 new TabStripModelObserverBridge(browser_->tabstrip_model(), self)); 89 new TabStripModelObserverBridge(browser_->tabstrip_model(), self));
87 90
88 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 91 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
89 folderImage_.reset([rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER) retain]); 92 folderImage_.reset([rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER) retain]);
93
94 // We grey out if |IDC_BOOKMARK_MENU_CONTENTS| is disabled. Note that the
95 // unit tests don't provide a |CommandUpdater|.
96 if (commands) {
97 commandObserver_.reset(new CommandObserverBridge(self, commands));
98 commandObserver_->ObserveCommand(IDC_BOOKMARK_MENU_CONTENTS);
99 }
90 } 100 }
91 return self; 101 return self;
92 } 102 }
93 103
94 - (void)dealloc { 104 - (void)dealloc {
95 bridge_.reset(NULL); 105 bridge_.reset(NULL);
96 [[NSNotificationCenter defaultCenter] removeObserver:self]; 106 [[NSNotificationCenter defaultCenter] removeObserver:self];
97 [super dealloc]; 107 [super dealloc];
98 } 108 }
99 109
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 269 }
260 270
261 - (void)tabChangedWithContents:(TabContents*)contents 271 - (void)tabChangedWithContents:(TabContents*)contents
262 atIndex:(NSInteger)index 272 atIndex:(NSInteger)index
263 loadingOnly:(BOOL)loading { 273 loadingOnly:(BOOL)loading {
264 // We need tabChangedWithContents: for when the user clicks a bookmark from 274 // We need tabChangedWithContents: for when the user clicks a bookmark from
265 // the bookmark bar on the new tab page. 275 // the bookmark bar on the new tab page.
266 [self updateVisibility]; 276 [self updateVisibility];
267 } 277 }
268 278
279 // Possibly (un)grey out the bookmark bar (i.e., enable/disable its buttons).
280 // Needed for tab-modal sheets.
281 - (void)greyOutBookmarkBar:(BOOL)doGreyOut {
282 if (barIsGreyedOut_ == doGreyOut)
283 return;
284
285 barIsGreyedOut_ = doGreyOut;
286 for (NSButton* each_button in buttons_.get())
287 [each_button setEnabled:!doGreyOut];
288 [offTheSideButton_ setEnabled:!doGreyOut];
289 }
290
291 // Called for state changes in commands (we're only interested in
292 // |IDC_BOOKMARK_MENU_CONTENTS|); part (all) of the |CommandObserverProtocol|.
293 - (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled {
294 if (command == IDC_BOOKMARK_MENU_CONTENTS) {
295 [self greyOutBookmarkBar:!enabled];
296 } else {
297 NOTREACHED() << "Got state change for command we didn't ask to observe.";
298 }
299 }
300
269 // Recursively add the given bookmark node and all its children to 301 // Recursively add the given bookmark node and all its children to
270 // menu, one menu item per node. 302 // menu, one menu item per node.
271 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu { 303 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu {
272 NSString* title = [BookmarkMenuCocoaController menuTitleForNode:child]; 304 NSString* title = [BookmarkMenuCocoaController menuTitleForNode:child];
273 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title 305 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title
274 action:nil 306 action:nil
275 keyEquivalent:@""] autorelease]; 307 keyEquivalent:@""] autorelease];
276 [menu addItem:item]; 308 [menu addItem:item];
277 if (child->is_folder()) { 309 if (child->is_folder()) {
278 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease]; 310 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease];
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 755
724 - (void)setUrlDelegate:(id<BookmarkURLOpener>)urlDelegate { 756 - (void)setUrlDelegate:(id<BookmarkURLOpener>)urlDelegate {
725 urlDelegate_ = urlDelegate; 757 urlDelegate_ = urlDelegate;
726 } 758 }
727 759
728 - (NSArray*)buttons { 760 - (NSArray*)buttons {
729 return buttons_.get(); 761 return buttons_.get();
730 } 762 }
731 763
732 @end 764 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bar_controller.h ('k') | chrome/browser/cocoa/bookmark_bar_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698