Index: chrome/browser/ui/cocoa/location_bar/plus_decoration.mm |
diff --git a/chrome/browser/ui/cocoa/location_bar/plus_decoration.mm b/chrome/browser/ui/cocoa/location_bar/plus_decoration.mm |
index 67822e5266f9563158b23091ccc86d16e8dc58fd..e3da16e9e102a7b6fd6253619f5fd10d89ee4d31 100644 |
--- a/chrome/browser/ui/cocoa/location_bar/plus_decoration.mm |
+++ b/chrome/browser/ui/cocoa/location_bar/plus_decoration.mm |
@@ -6,19 +6,41 @@ |
#include "chrome/app/chrome_command_ids.h" |
#include "chrome/browser/command_updater.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_commands.h" |
#import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
+#import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
+#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
+#import "chrome/browser/ui/cocoa/menu_controller.h" |
#include "grit/generated_resources.h" |
#include "grit/theme_resources.h" |
#include "ui/base/l10n/l10n_util_mac.h" |
+#include "ui/base/models/simple_menu_model.h" |
+#include "ui/base/resource/resource_bundle.h" |
-PlusDecoration::PlusDecoration(CommandUpdater* command_updater) |
- : command_updater_(command_updater) { |
+namespace { |
+// The offset to apply to the menu so that it clears the bottom border of the |
+// omnibox. |
+const CGFloat kOmniboxYOffset = 7.0; |
+} // namespace |
+ |
+PlusDecoration::PlusDecoration(LocationBarViewMac* owner, |
+ CommandUpdater* command_updater, Browser* browser) |
+ : owner_(owner), |
+ command_updater_(command_updater), |
+ browser_(browser) { |
SetVisible(true); |
const int image_id = IDR_ACTION_BOX_BUTTON; |
SetImage(OmniboxViewMac::ImageForResource(image_id)); |
const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON; |
tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); |
+ |
+ if (!pop_up_cell_.get()) { |
+ pop_up_cell_.reset([[NSPopUpButtonCell alloc] initTextCell:@"" |
+ pullsDown:YES]); |
+ } |
+ DCHECK(pop_up_cell_.get()); |
Scott Hess - ex-Googler
2012/08/09 22:59:10
Guess what! Now that the model and controller are
beaudoin
2012/08/10 15:56:10
Done.
|
} |
PlusDecoration::~PlusDecoration() { |
@@ -29,8 +51,41 @@ bool PlusDecoration::AcceptsMousePress() { |
} |
bool PlusDecoration::OnMousePressed(NSRect frame) { |
- // TODO(macourteau): trigger the menu when caitkp@ and beaudoin@'s CL is |
- // ready. |
+ ui::SimpleMenuModel menu_model(NULL); |
+ |
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
+ |
+ // TODO(beaudoin): Use a platform-independent menu model once the Windows |
+ // patch introducing it lands. See: http://codereview.chromium.org/10533086/ |
+ menu_model.InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE, |
+ IDS_CHROME_TO_MOBILE); |
+ menu_model.SetIcon(0, *rb.GetImageSkiaNamed(IDR_MOBILE)); |
+ menu_model.InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE, |
+ IDS_BOOKMARK_STAR); |
+ menu_model.SetIcon(1, *rb.GetImageSkiaNamed(IDR_STAR)); |
+ |
+ // Controller for the menu attached to the plus decoration. |
+ scoped_nsobject<MenuController> menu_controller( |
+ [[MenuController alloc] initWithModel:&menu_model |
+ useWithPopUpButtonCell:YES]); |
+ |
+ NSMenu* menu = [menu_controller menu]; |
+ |
+ // Align the menu popup to that its top-right corner matches the bottom-right |
+ // corner of the omnibox. |
+ AutocompleteTextField* field = owner_->GetAutocompleteTextField(); |
+ |
+ NSRect popUpFrame = [field bounds]; |
+ popUpFrame.origin.x = NSMaxX([field bounds]) - menu.size.width; |
+ popUpFrame.size.width = menu.size.width; |
+ |
+ // Attach the menu to a slightly higher box, to clear the omnibox border. |
+ popUpFrame.size.height += kOmniboxYOffset; |
+ |
+ [pop_up_cell_ setMenu:menu]; |
+ [pop_up_cell_ selectItem:nil]; |
+ [pop_up_cell_ attachPopUpWithFrame:popUpFrame inView:field]; |
+ [pop_up_cell_ performClickWithFrame:popUpFrame inView:field]; |
return true; |
} |