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

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

Issue 199024: (Mac) Display the bookmark bar off-the-side menu on mouse down. Also align the menu. (Closed)
Patch Set: Rebased ToT. Created 11 years, 3 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) 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 "base/mac_util.h" 5 #include "base/mac_util.h"
6 #include "base/sys_string_conversions.h" 6 #include "base/sys_string_conversions.h"
7 #include "chrome/browser/bookmarks/bookmark_editor.h" 7 #include "chrome/browser/bookmarks/bookmark_editor.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
11 #import "chrome/browser/cocoa/bookmark_bar_bridge.h" 11 #import "chrome/browser/cocoa/bookmark_bar_bridge.h"
12 #import "chrome/browser/cocoa/bookmark_bar_controller.h" 12 #import "chrome/browser/cocoa/bookmark_bar_controller.h"
13 #import "chrome/browser/cocoa/bookmark_button_cell.h" 13 #import "chrome/browser/cocoa/bookmark_button_cell.h"
14 #import "chrome/browser/cocoa/bookmark_editor_controller.h" 14 #import "chrome/browser/cocoa/bookmark_editor_controller.h"
15 #import "chrome/browser/cocoa/bookmark_name_folder_controller.h" 15 #import "chrome/browser/cocoa/bookmark_name_folder_controller.h"
16 #import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h" 16 #import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h"
17 #import "chrome/browser/cocoa/event_utils.h" 17 #import "chrome/browser/cocoa/event_utils.h"
18 #import "chrome/browser/cocoa/menu_button.h"
18 #import "chrome/browser/cocoa/view_resizer.h" 19 #import "chrome/browser/cocoa/view_resizer.h"
19 #include "chrome/browser/cocoa/nsimage_cache.h" 20 #include "chrome/browser/cocoa/nsimage_cache.h"
20 #include "chrome/browser/profile.h" 21 #include "chrome/browser/profile.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "chrome/common/pref_service.h" 23 #include "chrome/common/pref_service.h"
23 #include "skia/ext/skia_utils_mac.h" 24 #include "skia/ext/skia_utils_mac.h"
24 25
25 // Specialization of NSButton that responds to middle-clicks. By default, 26 // Specialization of NSButton that responds to middle-clicks. By default,
26 // NSButton ignores them. 27 // NSButton ignores them.
27 @interface BookmarkButton : NSButton 28 @interface BookmarkButton : NSButton
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 bridge_.reset(new BookmarkBarBridge(self, bookmarkModel_)); 95 bridge_.reset(new BookmarkBarBridge(self, bookmarkModel_));
95 96
96 // When resized we may need to add new buttons, or remove them (if 97 // When resized we may need to add new buttons, or remove them (if
97 // no longer visible), or add/remove the "off the side" menu. 98 // no longer visible), or add/remove the "off the side" menu.
98 [[self view] setPostsFrameChangedNotifications:YES]; 99 [[self view] setPostsFrameChangedNotifications:YES];
99 [[NSNotificationCenter defaultCenter] 100 [[NSNotificationCenter defaultCenter]
100 addObserver:self 101 addObserver:self
101 selector:@selector(frameDidChange) 102 selector:@selector(frameDidChange)
102 name:NSViewFrameDidChangeNotification 103 name:NSViewFrameDidChangeNotification
103 object:[self view]]; 104 object:[self view]];
105
106 DCHECK([offTheSideButton_ menu]);
104 } 107 }
105 108
106 - (void)showIfNeeded { 109 - (void)showIfNeeded {
107 if (profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) 110 if (profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar))
108 [self showBookmarkBar:YES immediately:YES]; 111 [self showBookmarkBar:YES immediately:YES];
109 } 112 }
110 113
111 // Check if we should enable the off-the-side button. 114 // Check if we should enable the off-the-side button.
112 // TODO(jrg): when we are smarter about creating buttons (e.g. don't 115 // TODO(jrg): when we are smarter about creating buttons (e.g. don't
113 // bother creating buttons which aren't visible), we'll have to be 116 // bother creating buttons which aren't visible), we'll have to be
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // Called from a Folder bookmark button. 290 // Called from a Folder bookmark button.
288 - (IBAction)openFolderMenuFromButton:(id)sender { 291 - (IBAction)openFolderMenuFromButton:(id)sender {
289 NSMenu* menu = [self menuForFolderNode:[self nodeFromButton:sender]]; 292 NSMenu* menu = [self menuForFolderNode:[self nodeFromButton:sender]];
290 if (menu) { 293 if (menu) {
291 [NSMenu popUpContextMenu:menu 294 [NSMenu popUpContextMenu:menu
292 withEvent:[NSApp currentEvent] 295 withEvent:[NSApp currentEvent]
293 forView:sender]; 296 forView:sender];
294 } 297 }
295 } 298 }
296 299
297 // TODO(jrg): cache the menu so we don't need to build it every time. 300 // Rebuild the off-the-side menu, taking into account which buttons are
301 // displayed.
302 // TODO(jrg,viettrungluu): only (re)build the menu when necessary.
298 // TODO(jrg): if we get smarter such that we don't even bother 303 // TODO(jrg): if we get smarter such that we don't even bother
299 // creating buttons which aren't visible, we'll need to be smarter 304 // creating buttons which aren't visible, we'll need to be smarter
300 // here. 305 // here.
301 - (IBAction)openOffTheSideMenuFromButton:(id)sender { 306 - (void)buildOffTheSideMenu {
302 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); 307 NSMenu* menu = [self offTheSideMenu];
308 DCHECK(menu);
309
310 // Remove old menu items (backwards order is as good as any); leave the
311 // blank one at position 0 (see menu_button.h).
312 for (NSInteger i = [menu numberOfItems] - 1; i >= 1 ; i--)
313 [menu removeItemAtIndex:i];
314
315 // Add items corresponding to buttons which aren't displayed or are only
316 // partly displayed.
303 for (NSButton* each_button in buttons_.get()) { 317 for (NSButton* each_button in buttons_.get()) {
304 if (NSMaxX([each_button frame]) > 318 if (NSMaxX([each_button frame]) >
305 NSMaxX([[each_button superview] frame])) { 319 NSMaxX([[each_button superview] frame])) {
306 [self addNode:[self nodeFromButton:each_button] toMenu:menu.get()]; 320 [self addNode:[self nodeFromButton:each_button] toMenu:menu];
307 } 321 }
308 } 322 }
323 }
309 324
310 // TODO(jrg): once we disable the button when the menu should be 325 // Get the off-the-side menu.
311 // empty, remove this 'helper'. 326 - (NSMenu*)offTheSideMenu {
312 if (![menu numberOfItems]) { 327 return [offTheSideButton_ menu];
313 [self tagEmptyMenu:menu]; 328 }
314 }
315 329
316 [NSMenu popUpContextMenu:menu 330 // Called by any menus which have set us as their delegate (right now just the
317 withEvent:[NSApp currentEvent] 331 // off-the-side menu?).
318 forView:sender]; 332 - (void)menuNeedsUpdate:(NSMenu*)menu {
333 if (menu == [self offTheSideMenu])
334 [self buildOffTheSideMenu];
319 } 335 }
320 336
321 // As a convention we set the menu's delegate to be the button's cell 337 // As a convention we set the menu's delegate to be the button's cell
322 // so we can easily obtain bookmark info. Convention applied in 338 // so we can easily obtain bookmark info. Convention applied in
323 // -[BookmarkButtonCell menu]. 339 // -[BookmarkButtonCell menu].
324 340
325 - (IBAction)openBookmarkInNewForegroundTab:(id)sender { 341 - (IBAction)openBookmarkInNewForegroundTab:(id)sender {
326 BookmarkNode* node = [self nodeFromMenuItem:sender]; 342 BookmarkNode* node = [self nodeFromMenuItem:sender];
327 [urlDelegate_ openBookmarkURL:node->GetURL() disposition:NEW_FOREGROUND_TAB]; 343 [urlDelegate_ openBookmarkURL:node->GetURL() disposition:NEW_FOREGROUND_TAB];
328 } 344 }
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 657
642 - (void)setUrlDelegate:(id<BookmarkURLOpener>)urlDelegate { 658 - (void)setUrlDelegate:(id<BookmarkURLOpener>)urlDelegate {
643 urlDelegate_ = urlDelegate; 659 urlDelegate_ = urlDelegate;
644 } 660 }
645 661
646 - (NSArray*)buttons { 662 - (NSArray*)buttons {
647 return buttons_.get(); 663 return buttons_.get();
648 } 664 }
649 665
650 @end 666 @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