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