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

Unified Diff: chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.mm

Issue 6732007: Native menu implementation for bug 5679. Followup to http://codereview.chromium.org/2928005/ Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: More code review updates. Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.mm
diff --git a/chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.mm b/chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.mm
index d64637fc92ecb201e74bcf1217c9e93ece1bd2bd..59240681ae795e15cf18ce4f7f219364a0992d99 100644
--- a/chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.mm
+++ b/chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.mm
@@ -22,6 +22,23 @@ using gfx::SkBitmapToNSImage;
@synthesize type = type_;
+namespace BackForwardMenuControllerInternal {
+
+class MenuDelegate : public ui::MenuModelDelegate {
+ public:
+ explicit MenuDelegate(BackForwardMenuController* owner)
+ : owner_(owner) {}
+ // Called by ui::MenuModelDelegate when an icon changes.
+ virtual void OnIconChanged(int modelIndex) OVERRIDE {
+ [owner_ onIconChanged:modelIndex];
+ }
+
+ private:
+ BackForwardMenuController* owner_;
+};
+
+} // BackForwardMenuControllerInternal namespace
+
// Own methods:
- (id)initWithBrowser:(Browser*)browser
@@ -35,19 +52,39 @@ using gfx::SkBitmapToNSImage;
backForwardMenu_.reset([[NSMenu alloc] initWithTitle:@""]);
DCHECK(backForwardMenu_.get());
[backForwardMenu_ setDelegate:self];
-
+ contextMenuDelegate_.reset(
+ new BackForwardMenuControllerInternal::MenuDelegate(self));
+ model_->SetMenuModelDelegate(contextMenuDelegate_.get());
[button_ setAttachedMenu:backForwardMenu_];
[button_ setOpenMenuOnClick:NO];
}
return self;
}
+- (void)dealloc {
+ model_->SetMenuModelDelegate(NULL);
+ [super dealloc];
+}
+
+// Called by MenuDelegate when an icon changes.
+- (void)onIconChanged:(int)modelIndex {
+ // modelIndex + 1 since 0-th item is the "title"
+ NSMenuItem* menuItem =
+ [backForwardMenu_ itemAtIndex:modelIndex + 1];
+ SkBitmap icon;
+ if (model_->GetIconAt(modelIndex, &icon)) {
+ [menuItem setImage:SkBitmapToNSImage(icon)];
+ }
+}
+
// Methods as delegate:
// Called by backForwardMenu_ just before tracking begins.
//TODO(viettrungluu): should we do anything for chapter stops (see model)?
- (void)menuNeedsUpdate:(NSMenu*)menu {
DCHECK(menu == backForwardMenu_);
+ // Retrieving favicons from history requires nestable tasks.
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
// Remove old menu items (backwards order is as good as any).
for (NSInteger i = [menu numberOfItems]; i > 0; i--)

Powered by Google App Engine
This is Rietveld 408576698