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..8c5a8118a454eeba891239436610ab15c6592fc3 100644 |
--- a/chrome/browser/ui/cocoa/location_bar/plus_decoration.mm |
+++ b/chrome/browser/ui/cocoa/location_bar/plus_decoration.mm |
@@ -6,13 +6,29 @@ |
#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; |
@@ -29,8 +45,45 @@ 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; |
+ |
+ scoped_nsobject<NSPopUpButtonCell> pop_up_cell( |
+ [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES]); |
+ DCHECK(pop_up_cell.get()); |
+ |
+ [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; |
} |