Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Unified Diff: chrome/browser/ui/cocoa/location_bar/plus_decoration.mm

Issue 10833056: Add a menu to the Action Box Button. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0933b06c530bff689f787fd1663d61644207d4a8 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/location_bar_view_mac.h"
+#import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.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/gfx/image/image_skia_util_mac.h"
-PlusDecoration::PlusDecoration(CommandUpdater* command_updater)
- : command_updater_(command_updater) {
+namespace {
+// The offset to reach the end of the omnibox from the plus decoration icon.
+// TODO(beaudoin): Most likely wont work in High DPI.
+const CGFloat kOmniboxXOffset = 10.0;
+} // namespace
+
+PlusDecoration::PlusDecoration(LocationBarViewMac* owner,
+ CommandUpdater* command_updater, Browser* browser)
+ :owner_(owner),
Scott Hess - ex-Googler 2012/07/27 20:31:06 Either this line is indented wrong, or the others
beaudoin 2012/08/01 02:23:26 Done.
+ command_updater_(command_updater),
+ browser_(browser) {
Scott Hess - ex-Googler 2012/07/27 20:31:06 You aren't actually using browser_ at this time, A
beaudoin 2012/08/01 02:23:26 If you don't mind I'll keep browser_ here as I hav
SetVisible(true);
const int image_id = IDR_ACTION_BOX_BUTTON;
@@ -22,6 +38,7 @@ PlusDecoration::PlusDecoration(CommandUpdater* command_updater)
}
PlusDecoration::~PlusDecoration() {
+ popUpCell_.reset(nil);
Scott Hess - ex-Googler 2012/07/27 20:31:06 Sorry, I may have made an assumption, here. Usual
beaudoin 2012/08/01 02:23:26 Done.
}
bool PlusDecoration::AcceptsMousePress() {
@@ -29,8 +46,36 @@ bool PlusDecoration::AcceptsMousePress() {
}
bool PlusDecoration::OnMousePressed(NSRect frame) {
- // TODO(macourteau): trigger the menu when caitkp@ and beaudoin@'s CL is
- // ready.
+ 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)));
+ menu_model_->SetIcon(1, gfx::ImageSkiaFromNSImage(
+ OmniboxViewMac::ImageForResource(IDR_STAR)));
+
+ menuController_.reset(
+ [[MenuController alloc] initWithModel:menu_model_.get()
+ useWithPopUpButtonCell:YES]);
Scott Hess - ex-Googler 2012/07/27 20:31:06 I think you should pull the menu_model_, menuContr
beaudoin 2012/08/01 02:23:26 At some point the menu model will be dynamic. Sinc
Scott Hess - ex-Googler 2012/08/08 15:00:14 To be clear - there's two parts, here, there's set
beaudoin 2012/08/08 21:38:08 On the windows side of things the menu model is cr
Scott Hess - ex-Googler 2012/08/08 22:04:00 OK, follow Windows, then.
beaudoin 2012/08/09 16:05:49 Made model and controller method-scoped. It works
+
+ NSMenu* menu = [menuController_ menu];
+
+ frame.origin.x -= (menu.size.width - frame.size.width) - kOmniboxXOffset;
+ frame.size.height += 10.0;
Scott Hess - ex-Googler 2012/07/27 20:31:06 This magic constant could use some explaining. Ac
beaudoin 2012/08/01 02:23:26 Done.
+
+ if (!popUpCell_.get()) {
+ popUpCell_ .reset([[NSPopUpButtonCell alloc] initTextCell:@""
+ pullsDown:YES]);
Scott Hess - ex-Googler 2012/07/27 20:31:06 Auto-magic alignment is sometimes sketchy with Obj
beaudoin 2012/08/01 02:23:26 Copied the height adjustment from somewhere where
+ }
+ DCHECK(popUpCell_.get());
+ AutocompleteTextField* field = owner_->GetAutocompleteTextField();
+ [popUpCell_ setMenu:menu];
+ [popUpCell_ selectItem:nil];
+ [popUpCell_ attachPopUpWithFrame:frame inView:field];
+ [popUpCell_ performClickWithFrame:frame inView:field];
return true;
}

Powered by Google App Engine
This is Rietveld 408576698