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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/plus_decoration.mm

Issue 10823289: Adding "send to mobile" and "add bookmark" to the action box menu and wiring to their respective ac… (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"
8 #include "chrome/browser/command_updater.h" 7 #include "chrome/browser/command_updater.h"
8 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h" 11 #include "chrome/browser/ui/browser_commands.h"
11 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 12 #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/autocomplete_text_field.h"
13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
14 #import "chrome/browser/ui/cocoa/menu_controller.h" 15 #import "chrome/browser/ui/cocoa/menu_controller.h"
16 #include "chrome/browser/ui/toolbar/action_box_menu_model.h"
15 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
17 #include "ui/base/l10n/l10n_util_mac.h" 19 #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"
20 20
21 namespace { 21 namespace {
22 // The offset to apply to the menu so that it clears the bottom border of the 22 // The offset to apply to the menu so that it clears the bottom border of the
23 // omnibox. 23 // omnibox.
24 const CGFloat kOmniboxYOffset = 7.0; 24 const CGFloat kOmniboxYOffset = 7.0;
25 } // namespace 25 } // namespace
26 26
27 PlusDecoration::PlusDecoration(LocationBarViewMac* owner, 27 PlusDecoration::PlusDecoration(LocationBarViewMac* owner,
28 CommandUpdater* command_updater, Browser* browser) 28 CommandUpdater* command_updater, Browser* browser, Profile* profile)
29 : owner_(owner), 29 : owner_(owner),
30 command_updater_(command_updater), 30 command_updater_(command_updater),
31 browser_(browser) { 31 browser_(browser),
32 profile_(profile) {
32 SetVisible(true); 33 SetVisible(true);
33 34
34 const int image_id = IDR_ACTION_BOX_BUTTON; 35 const int image_id = IDR_ACTION_BOX_BUTTON;
35 SetImage(OmniboxViewMac::ImageForResource(image_id)); 36 SetImage(OmniboxViewMac::ImageForResource(image_id));
36 const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON; 37 const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON;
37 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); 38 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]);
38 } 39 }
39 40
40 PlusDecoration::~PlusDecoration() { 41 PlusDecoration::~PlusDecoration() {
41 } 42 }
42 43
43 bool PlusDecoration::AcceptsMousePress() { 44 bool PlusDecoration::AcceptsMousePress() {
44 return true; 45 return true;
45 } 46 }
46 47
47 bool PlusDecoration::OnMousePressed(NSRect frame) { 48 bool PlusDecoration::OnMousePressed(NSRect frame) {
48 ui::SimpleMenuModel menu_model(NULL); 49 ExtensionService* extension_service =
49 50 extensions::ExtensionSystem::Get(profile_)->extension_service();
50 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 51 ActionBoxMenuModel menu_model(browser_, extension_service);
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 52
61 // Controller for the menu attached to the plus decoration. 53 // Controller for the menu attached to the plus decoration.
62 scoped_nsobject<MenuController> menu_controller( 54 scoped_nsobject<MenuController> menu_controller(
63 [[MenuController alloc] initWithModel:&menu_model 55 [[MenuController alloc] initWithModel:&menu_model
64 useWithPopUpButtonCell:YES]); 56 useWithPopUpButtonCell:YES]);
65 57
66 NSMenu* menu = [menu_controller menu]; 58 NSMenu* menu = [menu_controller menu];
67 59
68 // Align the menu popup to that its top-right corner matches the bottom-right 60 // Align the menu popup to that its top-right corner matches the bottom-right
69 // corner of the omnibox. 61 // corner of the omnibox.
(...skipping 13 matching lines...) Expand all
83 [pop_up_cell setMenu:menu]; 75 [pop_up_cell setMenu:menu];
84 [pop_up_cell selectItem:nil]; 76 [pop_up_cell selectItem:nil];
85 [pop_up_cell attachPopUpWithFrame:popUpFrame inView:field]; 77 [pop_up_cell attachPopUpWithFrame:popUpFrame inView:field];
86 [pop_up_cell performClickWithFrame:popUpFrame inView:field]; 78 [pop_up_cell performClickWithFrame:popUpFrame inView:field];
87 return true; 79 return true;
88 } 80 }
89 81
90 NSString* PlusDecoration::GetToolTip() { 82 NSString* PlusDecoration::GetToolTip() {
91 return tooltip_.get(); 83 return tooltip_.get();
92 } 84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698