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

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: Final changes! 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
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/plus_decoration.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/autocomplete_text_field.h"
13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.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/base/resource/resource_bundle.h"
13 20
14 PlusDecoration::PlusDecoration(CommandUpdater* command_updater) 21 namespace {
15 : command_updater_(command_updater) { 22 // The offset to apply to the menu so that it clears the bottom border of the
23 // omnibox.
24 const CGFloat kOmniboxYOffset = 7.0;
25 } // namespace
26
27 PlusDecoration::PlusDecoration(LocationBarViewMac* owner,
28 CommandUpdater* command_updater, Browser* browser)
29 : owner_(owner),
30 command_updater_(command_updater),
31 browser_(browser) {
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() {
25 } 41 }
26 42
27 bool PlusDecoration::AcceptsMousePress() { 43 bool PlusDecoration::AcceptsMousePress() {
28 return true; 44 return true;
29 } 45 }
30 46
31 bool PlusDecoration::OnMousePressed(NSRect frame) { 47 bool PlusDecoration::OnMousePressed(NSRect frame) {
32 // TODO(macourteau): trigger the menu when caitkp@ and beaudoin@'s CL is 48 ui::SimpleMenuModel menu_model(NULL);
33 // ready. 49
50 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
51
52 // TODO(beaudoin): Use a platform-independent menu model once the Windows
53 // patch introducing it lands. See: http://codereview.chromium.org/10533086/
54 menu_model.InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE,
55 IDS_CHROME_TO_MOBILE);
56 menu_model.SetIcon(0, *rb.GetImageSkiaNamed(IDR_MOBILE));
57 menu_model.InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE,
58 IDS_BOOKMARK_STAR);
59 menu_model.SetIcon(1, *rb.GetImageSkiaNamed(IDR_STAR));
60
61 // Controller for the menu attached to the plus decoration.
62 scoped_nsobject<MenuController> menu_controller(
63 [[MenuController alloc] initWithModel:&menu_model
64 useWithPopUpButtonCell:YES]);
65
66 NSMenu* menu = [menu_controller menu];
67
68 // Align the menu popup to that its top-right corner matches the bottom-right
69 // corner of the omnibox.
70 AutocompleteTextField* field = owner_->GetAutocompleteTextField();
71
72 NSRect popUpFrame = [field bounds];
73 popUpFrame.origin.x = NSMaxX([field bounds]) - menu.size.width;
74 popUpFrame.size.width = menu.size.width;
75
76 // Attach the menu to a slightly higher box, to clear the omnibox border.
77 popUpFrame.size.height += kOmniboxYOffset;
78
79 scoped_nsobject<NSPopUpButtonCell> pop_up_cell(
80 [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES]);
81 DCHECK(pop_up_cell.get());
82
83 [pop_up_cell setMenu:menu];
84 [pop_up_cell selectItem:nil];
85 [pop_up_cell attachPopUpWithFrame:popUpFrame inView:field];
86 [pop_up_cell performClickWithFrame:popUpFrame inView:field];
34 return true; 87 return true;
35 } 88 }
36 89
37 NSString* PlusDecoration::GetToolTip() { 90 NSString* PlusDecoration::GetToolTip() {
38 return tooltip_.get(); 91 return tooltip_.get();
39 } 92 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/plus_decoration.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698