summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bookmark_bar_controller.mm
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-04 20:43:14 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-04 20:43:14 +0000
commit04a3942cf4419e0f21105934e92168583e1d49c4 (patch)
tree4ace473662dcaf431cc392a78cce6dd817e0f08d /chrome/browser/cocoa/bookmark_bar_controller.mm
parent1319d3b2391006b26b095b2d1f69c424eb237ae9 (diff)
downloadchromium_src-04a3942cf4419e0f21105934e92168583e1d49c4.zip
chromium_src-04a3942cf4419e0f21105934e92168583e1d49c4.tar.gz
chromium_src-04a3942cf4419e0f21105934e92168583e1d49c4.tar.bz2
(Mac) Display the bookmark bar off-the-side menu on mouse down. Also align the menu.
(Basically, make it like Safari's button.) We make the button into a |MenuButton|, attach a fixed menu to it in the nib, and make the |BookmarkBarController| the delegate for this menu so that we can update the menu just before it's displayed. As a side effect, also fixes bug 20813. BUG=21093,20813 TEST=Make sure the bookmark bar off-the-side button works properly under a variety of circumstances, making sure the menu is properly aligned, etc. Review URL: http://codereview.chromium.org/199024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25507 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_bar_controller.mm')
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.mm40
1 files changed, 28 insertions, 12 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm
index e8e5daf..a8cac69 100644
--- a/chrome/browser/cocoa/bookmark_bar_controller.mm
+++ b/chrome/browser/cocoa/bookmark_bar_controller.mm
@@ -15,6 +15,7 @@
#import "chrome/browser/cocoa/bookmark_name_folder_controller.h"
#import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h"
#import "chrome/browser/cocoa/event_utils.h"
+#import "chrome/browser/cocoa/menu_button.h"
#import "chrome/browser/cocoa/view_resizer.h"
#include "chrome/browser/cocoa/nsimage_cache.h"
#include "chrome/browser/profile.h"
@@ -101,6 +102,8 @@ const CGFloat kBookmarkHorizontalPadding = 1.0;
selector:@selector(frameDidChange)
name:NSViewFrameDidChangeNotification
object:[self view]];
+
+ DCHECK([offTheSideButton_ menu]);
}
- (void)showIfNeeded {
@@ -294,28 +297,41 @@ const CGFloat kBookmarkHorizontalPadding = 1.0;
}
}
-// TODO(jrg): cache the menu so we don't need to build it every time.
+// Rebuild the off-the-side menu, taking into account which buttons are
+// displayed.
+// TODO(jrg,viettrungluu): only (re)build the menu when necessary.
// TODO(jrg): if we get smarter such that we don't even bother
// creating buttons which aren't visible, we'll need to be smarter
// here.
-- (IBAction)openOffTheSideMenuFromButton:(id)sender {
- scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
+- (void)buildOffTheSideMenu {
+ NSMenu* menu = [self offTheSideMenu];
+ DCHECK(menu);
+
+ // Remove old menu items (backwards order is as good as any); leave the
+ // blank one at position 0 (see menu_button.h).
+ for (NSInteger i = [menu numberOfItems] - 1; i >= 1 ; i--)
+ [menu removeItemAtIndex:i];
+
+ // Add items corresponding to buttons which aren't displayed or are only
+ // partly displayed.
for (NSButton* each_button in buttons_.get()) {
if (NSMaxX([each_button frame]) >
NSMaxX([[each_button superview] frame])) {
- [self addNode:[self nodeFromButton:each_button] toMenu:menu.get()];
+ [self addNode:[self nodeFromButton:each_button] toMenu:menu];
}
}
+}
- // TODO(jrg): once we disable the button when the menu should be
- // empty, remove this 'helper'.
- if (![menu numberOfItems]) {
- [self tagEmptyMenu:menu];
- }
+// Get the off-the-side menu.
+- (NSMenu*)offTheSideMenu {
+ return [offTheSideButton_ menu];
+}
- [NSMenu popUpContextMenu:menu
- withEvent:[NSApp currentEvent]
- forView:sender];
+// Called by any menus which have set us as their delegate (right now just the
+// off-the-side menu?).
+- (void)menuNeedsUpdate:(NSMenu*)menu {
+ if (menu == [self offTheSideMenu])
+ [self buildOffTheSideMenu];
}
// As a convention we set the menu's delegate to be the button's cell