| 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/location_bar/plus_decoration.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | |
| 8 #include "chrome/browser/command_updater.h" | 7 #include "chrome/browser/command_updater.h" |
| 8 #include "chrome/browser/extensions/extension_system.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 11 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 14 #import "chrome/browser/ui/cocoa/menu_controller.h" | 14 #import "chrome/browser/ui/cocoa/menu_controller.h" |
| 15 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" |
| 15 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 17 #include "ui/base/l10n/l10n_util_mac.h" | 18 #include "ui/base/l10n/l10n_util_mac.h" |
| 18 #include "ui/base/models/simple_menu_model.h" | |
| 19 #include "ui/base/resource/resource_bundle.h" | |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 // The offset to apply to the menu so that it clears the bottom border of the | 21 // The offset to apply to the menu so that it clears the bottom border of the |
| 23 // omnibox. | 22 // omnibox. |
| 24 const CGFloat kOmniboxYOffset = 7.0; | 23 const CGFloat kOmniboxYOffset = 7.0; |
| 25 } // namespace | 24 } // namespace |
| 26 | 25 |
| 27 PlusDecoration::PlusDecoration(LocationBarViewMac* owner, | 26 PlusDecoration::PlusDecoration(LocationBarViewMac* owner, |
| 28 CommandUpdater* command_updater, Browser* browser) | 27 CommandUpdater* command_updater, Browser* browser) |
| 29 : owner_(owner), | 28 : owner_(owner), |
| 30 command_updater_(command_updater), | 29 command_updater_(command_updater), |
| 31 browser_(browser) { | 30 browser_(browser) { |
| 32 SetVisible(true); | 31 SetVisible(true); |
| 33 | 32 |
| 34 const int image_id = IDR_ACTION_BOX_BUTTON; | 33 const int image_id = IDR_ACTION_BOX_BUTTON; |
| 35 SetImage(OmniboxViewMac::ImageForResource(image_id)); | 34 SetImage(OmniboxViewMac::ImageForResource(image_id)); |
| 36 const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON; | 35 const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON; |
| 37 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); | 36 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); |
| 38 } | 37 } |
| 39 | 38 |
| 40 PlusDecoration::~PlusDecoration() { | 39 PlusDecoration::~PlusDecoration() { |
| 41 } | 40 } |
| 42 | 41 |
| 43 bool PlusDecoration::AcceptsMousePress() { | 42 bool PlusDecoration::AcceptsMousePress() { |
| 44 return true; | 43 return true; |
| 45 } | 44 } |
| 46 | 45 |
| 47 bool PlusDecoration::OnMousePressed(NSRect frame) { | 46 bool PlusDecoration::OnMousePressed(NSRect frame) { |
| 48 ui::SimpleMenuModel menu_model(NULL); | 47 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
| 49 | 48 browser_->profile())->extension_service(); |
| 50 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 49 ActionBoxMenuModel menu_model(browser_, extension_service); |
| 51 | |
| 52 // TODO(beaudoin): Use a platform-independent menu model once the Windows | |
| 53 // patch introducing it lands. See: http://codereview.chromium.org/10533086/ | |
| 54 menu_model.InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE, | |
| 55 IDS_CHROME_TO_MOBILE); | |
| 56 menu_model.SetIcon(0, *rb.GetImageSkiaNamed(IDR_MOBILE)); | |
| 57 menu_model.InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE, | |
| 58 IDS_BOOKMARK_STAR); | |
| 59 menu_model.SetIcon(1, *rb.GetImageSkiaNamed(IDR_STAR)); | |
| 60 | 50 |
| 61 // Controller for the menu attached to the plus decoration. | 51 // Controller for the menu attached to the plus decoration. |
| 62 scoped_nsobject<MenuController> menu_controller( | 52 scoped_nsobject<MenuController> menu_controller( |
| 63 [[MenuController alloc] initWithModel:&menu_model | 53 [[MenuController alloc] initWithModel:&menu_model |
| 64 useWithPopUpButtonCell:YES]); | 54 useWithPopUpButtonCell:YES]); |
| 65 | 55 |
| 66 NSMenu* menu = [menu_controller menu]; | 56 NSMenu* menu = [menu_controller menu]; |
| 67 | 57 |
| 68 // Align the menu popup to that its top-right corner matches the bottom-right | 58 // Align the menu popup to that its top-right corner matches the bottom-right |
| 69 // corner of the omnibox. | 59 // corner of the omnibox. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 83 [pop_up_cell setMenu:menu]; | 73 [pop_up_cell setMenu:menu]; |
| 84 [pop_up_cell selectItem:nil]; | 74 [pop_up_cell selectItem:nil]; |
| 85 [pop_up_cell attachPopUpWithFrame:popUpFrame inView:field]; | 75 [pop_up_cell attachPopUpWithFrame:popUpFrame inView:field]; |
| 86 [pop_up_cell performClickWithFrame:popUpFrame inView:field]; | 76 [pop_up_cell performClickWithFrame:popUpFrame inView:field]; |
| 87 return true; | 77 return true; |
| 88 } | 78 } |
| 89 | 79 |
| 90 NSString* PlusDecoration::GetToolTip() { | 80 NSString* PlusDecoration::GetToolTip() { |
| 91 return tooltip_.get(); | 81 return tooltip_.get(); |
| 92 } | 82 } |
| OLD | NEW |