| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.h" | 5 #import "chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #import "chrome/browser/ui/cocoa/event_utils.h" | 10 #import "chrome/browser/ui/cocoa/event_utils.h" |
| 11 #import "chrome/browser/ui/cocoa/menu_button.h" | 11 #import "chrome/browser/ui/cocoa/menu_button.h" |
| 12 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" | 12 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" |
| 13 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image.h" |
| 14 #include "ui/gfx/image/image_skia_util_mac.h" | |
| 15 | 14 |
| 16 using base::SysUTF16ToNSString; | 15 using base::SysUTF16ToNSString; |
| 17 using gfx::NSImageFromImageSkia; | |
| 18 | 16 |
| 19 @implementation BackForwardMenuController | 17 @implementation BackForwardMenuController |
| 20 | 18 |
| 21 // Accessors and mutators: | 19 // Accessors and mutators: |
| 22 | 20 |
| 23 @synthesize type = type_; | 21 @synthesize type = type_; |
| 24 | 22 |
| 25 // Own methods: | 23 // Own methods: |
| 26 | 24 |
| 27 - (id)initWithBrowser:(Browser*)browser | 25 - (id)initWithBrowser:(Browser*)browser |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 [menu insertItem:[NSMenuItem separatorItem] | 62 [menu insertItem:[NSMenuItem separatorItem] |
| 65 atIndex:(menuID + 1)]; | 63 atIndex:(menuID + 1)]; |
| 66 } else { | 64 } else { |
| 67 // Create a menu item with the right label. | 65 // Create a menu item with the right label. |
| 68 NSMenuItem* menuItem = [[NSMenuItem alloc] | 66 NSMenuItem* menuItem = [[NSMenuItem alloc] |
| 69 initWithTitle:SysUTF16ToNSString(model_->GetLabelAt(menuID)) | 67 initWithTitle:SysUTF16ToNSString(model_->GetLabelAt(menuID)) |
| 70 action:nil | 68 action:nil |
| 71 keyEquivalent:@""]; | 69 keyEquivalent:@""]; |
| 72 [menuItem autorelease]; | 70 [menuItem autorelease]; |
| 73 | 71 |
| 74 gfx::ImageSkia icon; | 72 gfx::Image icon; |
| 75 // Icon (if it has one). | 73 // Icon (if it has one). |
| 76 if (model_->GetIconAt(menuID, &icon)) | 74 if (model_->GetIconAt(menuID, &icon)) |
| 77 [menuItem setImage:NSImageFromImageSkia(icon)]; | 75 [menuItem setImage:icon.ToNSImage()]; |
| 78 | 76 |
| 79 // This will make it call our |-executeMenuItem:| method. We store the | 77 // This will make it call our |-executeMenuItem:| method. We store the |
| 80 // |menuID| (or |menu_id|) in the tag. | 78 // |menuID| (or |menu_id|) in the tag. |
| 81 [menuItem setTag:menuID]; | 79 [menuItem setTag:menuID]; |
| 82 [menuItem setTarget:self]; | 80 [menuItem setTarget:self]; |
| 83 [menuItem setAction:@selector(executeMenuItem:)]; | 81 [menuItem setAction:@selector(executeMenuItem:)]; |
| 84 | 82 |
| 85 // Put it in the menu! | 83 // Put it in the menu! |
| 86 [menu insertItem:menuItem | 84 [menu insertItem:menuItem |
| 87 atIndex:(menuID + 1)]; | 85 atIndex:(menuID + 1)]; |
| 88 } | 86 } |
| 89 } | 87 } |
| 90 } | 88 } |
| 91 | 89 |
| 92 // Action methods: | 90 // Action methods: |
| 93 | 91 |
| 94 - (void)executeMenuItem:(id)sender { | 92 - (void)executeMenuItem:(id)sender { |
| 95 DCHECK([sender isKindOfClass:[NSMenuItem class]]); | 93 DCHECK([sender isKindOfClass:[NSMenuItem class]]); |
| 96 int menuID = [sender tag]; | 94 int menuID = [sender tag]; |
| 97 int event_flags = event_utils::EventFlagsFromNSEvent([NSApp currentEvent]); | 95 int event_flags = event_utils::EventFlagsFromNSEvent([NSApp currentEvent]); |
| 98 model_->ActivatedAt(menuID, event_flags); | 96 model_->ActivatedAt(menuID, event_flags); |
| 99 } | 97 } |
| 100 | 98 |
| 101 @end // @implementation BackForwardMenuController | 99 @end // @implementation BackForwardMenuController |
| OLD | NEW |