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

Unified Diff: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm

Issue 10797054: Use NSMenuDelegate for browser action overflow menu to update it upon opening. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/extensions/browser_actions_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
diff --git a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
index eae0e9b2d79b9ba8f34acad690b989d3d689b8ce..137a7b51e3218076031d3c07f42b3a7e205b0952 100644
--- a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
+++ b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
@@ -121,10 +121,6 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0;
// toolbar know that the drag has finished.
- (void)containerDragFinished:(NSNotification*)notification;
-// Updates the image associated with the button should it be within the chevron
-// menu.
-- (void)actionButtonUpdated:(NSNotification*)notification;
-
// Adjusts the position of the surrounding action buttons depending on where the
// button is within the container.
- (void)actionButtonDragging:(NSNotification*)notification;
@@ -167,9 +163,10 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0;
// Handles when a menu item within the chevron overflow menu is selected.
- (void)chevronItemSelected:(id)menuItem;
+// NSMenuDelegate override:
// Clears and then populates the overflow menu based on the contents of
// |hiddenButtons_|.
-- (void)updateOverflowMenu;
+- (void)menuNeedsUpdate:(NSMenu*)menu;
Robert Sesek 2012/07/23 17:39:40 Can remove
Yoyo Zhou 2012/07/23 18:47:24 Removed.
// Updates the container's grippy cursor based on the number of hidden buttons.
- (void)updateGrippyCursors;
@@ -438,12 +435,6 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver,
[self createActionButtonForExtension:*iter withIndex:i++];
}
- [[NSNotificationCenter defaultCenter]
- addObserver:self
- selector:@selector(actionButtonUpdated:)
- name:kBrowserActionButtonUpdatedNotification
- object:nil];
-
CGFloat width = [self savedWidth];
[containerView_ resizeToWidth:width animate:NO];
}
@@ -511,7 +502,6 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver,
// It may or may not be hidden, but it won't matter to NSMutableArray either
// way.
[hiddenButtons_ removeObject:button];
- [self updateOverflowMenu];
[buttons_ removeObjectForKey:buttonKey];
if ([self buttonCount] == 0) {
@@ -636,7 +626,6 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver,
[hiddenButtons_ addObject:button];
}
}
- [self updateOverflowMenu];
[self updateGrippyCursors];
if (!profile_->IsOffTheRecord())
@@ -647,18 +636,6 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver,
object:self];
}
-- (void)actionButtonUpdated:(NSNotification*)notification {
- BrowserActionButton* button = [notification object];
- if (![hiddenButtons_ containsObject:button])
- return;
-
- // +1 item because of the title placeholder. See |updateOverflowMenu|.
- NSUInteger menuIndex = [hiddenButtons_ indexOfObject:button] + 1;
- NSMenuItem* item = [[chevronMenuButton_ attachedMenu] itemAtIndex:menuIndex];
- DCHECK(button == [item representedObject]);
- [item setImage:[button compositedImage]];
-}
-
- (void)actionButtonDragging:(NSNotification*)notification {
if (![self chevronIsHidden])
[self setChevronHidden:YES inFrame:[containerView_ frame] animate:YES];
@@ -711,7 +688,6 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver,
[hiddenButtons_ addObject:button];
[button removeFromSuperview];
[button setAlphaValue:0.0];
- [self updateOverflowMenu];
}
}
@@ -774,12 +750,14 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver,
[[chevronMenuButton_ cell] setImageID:IDR_BROWSER_ACTIONS_OVERFLOW_P
forButtonState:image_button_cell::kPressedState];
+ overflowMenu_.reset([[NSMenu alloc] initWithTitle:@""]);
+ [overflowMenu_ setAutoenablesItems:NO];
+ [overflowMenu_ setDelegate:self];
+ [chevronMenuButton_ setAttachedMenu:overflowMenu_];
+
[containerView_ addSubview:chevronMenuButton_];
}
- if (!hidden)
- [self updateOverflowMenu];
-
[self updateChevronPositionInFrame:frame];
// Stop any running animation.
@@ -812,27 +790,22 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver,
[self browserActionClicked:[menuItem representedObject]];
}
-// TODO(yoz): This only gets called when the set of actions in the overflow
-// menu changes (not for things that would update page actions).
-// It should instead be called each time the menu is opened.
-- (void)updateOverflowMenu {
- overflowMenu_.reset([[NSMenu alloc] initWithTitle:@""]);
- // See menu_button.h for documentation on why this is needed.
- [overflowMenu_ addItemWithTitle:@"" action:nil keyEquivalent:@""];
- [overflowMenu_ setAutoenablesItems:NO];
+- (void)menuNeedsUpdate:(NSMenu*)menu {
+ [menu removeAllItems];
Robert Sesek 2012/07/23 17:39:40 nit: blank line after.
Yoyo Zhou 2012/07/23 18:47:24 Done.
+ // See menu_button.h for documentation on why this is needed.
Robert Sesek 2012/07/23 17:39:40 nit: indention
Yoyo Zhou 2012/07/23 18:47:24 Done.
+ [menu addItemWithTitle:@"" action:nil keyEquivalent:@""];
for (BrowserActionButton* button in hiddenButtons_.get()) {
NSString* name = base::SysUTF8ToNSString([button extension]->name());
NSMenuItem* item =
- [overflowMenu_ addItemWithTitle:name
- action:@selector(chevronItemSelected:)
- keyEquivalent:@""];
+ [menu addItemWithTitle:name
+ action:@selector(chevronItemSelected:)
+ keyEquivalent:@""];
[item setRepresentedObject:button];
[item setImage:[button compositedImage]];
[item setTarget:self];
[item setEnabled:[button isEnabled]];
}
- [chevronMenuButton_ setAttachedMenu:overflowMenu_];
}
- (void)updateGrippyCursors {
« no previous file with comments | « chrome/browser/ui/cocoa/extensions/browser_actions_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698