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..dabe523cb8de523ee8bb51006d09ad6218209281 100644 |
--- a/chrome/browser/ui/cocoa/location_bar/plus_decoration.mm |
+++ b/chrome/browser/ui/cocoa/location_bar/plus_decoration.mm |
@@ -6,13 +6,31 @@ |
#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/location_bar/autocomplete_text_field.h" |
Scott Hess - ex-Googler
2012/08/08 15:00:14
Duplicate import.
beaudoin
2012/08/08 21:38:08
Done.
|
+#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/gfx/image/image_skia_util_mac.h" |
-PlusDecoration::PlusDecoration(CommandUpdater* command_updater) |
- : command_updater_(command_updater) { |
+namespace { |
+// The offset to apply to the menu so that it displays at a reasonable distance |
+// below the omnibox. |
+// TODO(beaudoin): Most likely wont work in High DPI. |
+const CGFloat kOmniboxYOffset = 3.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,11 +47,44 @@ bool PlusDecoration::AcceptsMousePress() { |
} |
bool PlusDecoration::OnMousePressed(NSRect frame) { |
- // TODO(macourteau): trigger the menu when caitkp@ and beaudoin@'s CL is |
- // ready. |
+ CreateMenuController(); |
+ NSMenu* menu = [menuController_ menu]; |
+ |
+ AutocompleteTextField* field = owner_->GetAutocompleteTextField(); |
+ NSRect popupFrame = [field bounds]; |
+ popupFrame.origin.x = NSMaxX(popupFrame) - menu.size.width; |
+ popupFrame.origin.y += kOmniboxYOffset; |
Scott Hess - ex-Googler
2012/08/08 15:00:14
Is there any possibility that this ends up at NSMi
beaudoin
2012/08/09 16:05:50
Dug a bit deeper here. Using the field height lead
|
+ popupFrame.size.width = menu.size.width; |
+ |
+ if (!popUpCell_.get()) { |
+ popUpCell_ .reset([[NSPopUpButtonCell alloc] initTextCell:@"" |
Scott Hess - ex-Googler
2012/08/08 15:00:14
odd space before .reset().
Also, I'd prefer you j
beaudoin
2012/08/08 21:38:08
Done.
|
+ pullsDown:YES]); |
+ } |
+ DCHECK(popUpCell_.get()); |
+ [popUpCell_ setMenu:menu]; |
+ [popUpCell_ selectItem:nil]; |
+ [popUpCell_ attachPopUpWithFrame:popupFrame inView:field]; |
+ [popUpCell_ performClickWithFrame:popupFrame inView:field]; |
return true; |
} |
NSString* PlusDecoration::GetToolTip() { |
return tooltip_.get(); |
} |
+ |
+void PlusDecoration::CreateMenuController() { |
+ menu_model_.reset(new ui::SimpleMenuModel(NULL)); |
+ |
+ menu_model_->InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE, |
+ IDS_CHROME_TO_MOBILE); |
+ menu_model_->InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE, |
+ IDS_BOOKMARK_STAR); |
+ menu_model_->SetIcon(0, gfx::ImageSkiaFromNSImage( |
+ OmniboxViewMac::ImageForResource(IDR_MOBILE))); |
Scott Hess - ex-Googler
2012/08/08 15:00:14
Group the InsertItem() and SetIcon() calls for a g
beaudoin
2012/08/08 21:38:08
Done.
|
+ menu_model_->SetIcon(1, gfx::ImageSkiaFromNSImage( |
+ OmniboxViewMac::ImageForResource(IDR_STAR))); |
+ |
+ menuController_.reset( |
+ [[MenuController alloc] initWithModel:menu_model_.get() |
Scott Hess - ex-Googler
2012/08/08 15:00:14
Did you try it without the .get()? If you don't n
beaudoin
2012/08/08 21:38:08
Seems needed.
|
+ useWithPopUpButtonCell:YES]); |
+} |