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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/command_updater.h" 8 #include "chrome/browser/command_updater.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h"
9 #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/location_bar_view_mac.h"
13 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
14 #import "chrome/browser/ui/cocoa/menu_controller.h"
10 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
11 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
12 #include "ui/base/l10n/l10n_util_mac.h" 17 #include "ui/base/l10n/l10n_util_mac.h"
18 #include "ui/base/models/simple_menu_model.h"
19 #include "ui/gfx/image/image_skia_util_mac.h"
13 20
14 PlusDecoration::PlusDecoration(CommandUpdater* command_updater) 21 namespace {
15 : command_updater_(command_updater) { 22 // The offset to reach the end of the omnibox from the plus decoration icon.
23 // TODO(beaudoin): Most likely wont work in High DPI.
24 const CGFloat kOmniboxXOffset = 10.0;
25 } // namespace
26
27 PlusDecoration::PlusDecoration(LocationBarViewMac* owner,
28 CommandUpdater* command_updater, Browser* browser)
29 :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.
30 command_updater_(command_updater),
31 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
16 SetVisible(true); 32 SetVisible(true);
17 33
18 const int image_id = IDR_ACTION_BOX_BUTTON; 34 const int image_id = IDR_ACTION_BOX_BUTTON;
19 SetImage(OmniboxViewMac::ImageForResource(image_id)); 35 SetImage(OmniboxViewMac::ImageForResource(image_id));
20 const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON; 36 const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON;
21 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); 37 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]);
22 } 38 }
23 39
24 PlusDecoration::~PlusDecoration() { 40 PlusDecoration::~PlusDecoration() {
41 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.
25 } 42 }
26 43
27 bool PlusDecoration::AcceptsMousePress() { 44 bool PlusDecoration::AcceptsMousePress() {
28 return true; 45 return true;
29 } 46 }
30 47
31 bool PlusDecoration::OnMousePressed(NSRect frame) { 48 bool PlusDecoration::OnMousePressed(NSRect frame) {
32 // TODO(macourteau): trigger the menu when caitkp@ and beaudoin@'s CL is 49 menu_model_.reset(new ui::SimpleMenuModel(NULL));
33 // ready. 50
51 menu_model_->InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE,
52 IDS_CHROME_TO_MOBILE);
53 menu_model_->InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE,
54 IDS_BOOKMARK_STAR);
55 menu_model_->SetIcon(0, gfx::ImageSkiaFromNSImage(
56 OmniboxViewMac::ImageForResource(IDR_MOBILE)));
57 menu_model_->SetIcon(1, gfx::ImageSkiaFromNSImage(
58 OmniboxViewMac::ImageForResource(IDR_STAR)));
59
60 menuController_.reset(
61 [[MenuController alloc] initWithModel:menu_model_.get()
62 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
63
64 NSMenu* menu = [menuController_ menu];
65
66 frame.origin.x -= (menu.size.width - frame.size.width) - kOmniboxXOffset;
67 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.
68
69 if (!popUpCell_.get()) {
70 popUpCell_ .reset([[NSPopUpButtonCell alloc] initTextCell:@""
71 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
72 }
73 DCHECK(popUpCell_.get());
74 AutocompleteTextField* field = owner_->GetAutocompleteTextField();
75 [popUpCell_ setMenu:menu];
76 [popUpCell_ selectItem:nil];
77 [popUpCell_ attachPopUpWithFrame:frame inView:field];
78 [popUpCell_ performClickWithFrame:frame inView:field];
34 return true; 79 return true;
35 } 80 }
36 81
37 NSString* PlusDecoration::GetToolTip() { 82 NSString* PlusDecoration::GetToolTip() {
38 return tooltip_.get(); 83 return tooltip_.get();
39 } 84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698