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

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: Applied review comments. 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/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/autocomplete_text_field.h"
Scott Hess - ex-Googler 2012/08/08 15:00:14 Duplicate import.
beaudoin 2012/08/08 21:38:08 Done.
15 #import "chrome/browser/ui/cocoa/menu_controller.h"
10 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
11 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
12 #include "ui/base/l10n/l10n_util_mac.h" 18 #include "ui/base/l10n/l10n_util_mac.h"
19 #include "ui/base/models/simple_menu_model.h"
20 #include "ui/gfx/image/image_skia_util_mac.h"
13 21
14 PlusDecoration::PlusDecoration(CommandUpdater* command_updater) 22 namespace {
15 : command_updater_(command_updater) { 23 // The offset to apply to the menu so that it displays at a reasonable distance
24 // below the omnibox.
25 // TODO(beaudoin): Most likely wont work in High DPI.
26 const CGFloat kOmniboxYOffset = 3.0;
27 } // namespace
28
29 PlusDecoration::PlusDecoration(LocationBarViewMac* owner,
30 CommandUpdater* command_updater, Browser* browser)
31 : owner_(owner),
32 command_updater_(command_updater),
33 browser_(browser) {
16 SetVisible(true); 34 SetVisible(true);
17 35
18 const int image_id = IDR_ACTION_BOX_BUTTON; 36 const int image_id = IDR_ACTION_BOX_BUTTON;
19 SetImage(OmniboxViewMac::ImageForResource(image_id)); 37 SetImage(OmniboxViewMac::ImageForResource(image_id));
20 const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON; 38 const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON;
21 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); 39 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]);
22 } 40 }
23 41
24 PlusDecoration::~PlusDecoration() { 42 PlusDecoration::~PlusDecoration() {
25 } 43 }
26 44
27 bool PlusDecoration::AcceptsMousePress() { 45 bool PlusDecoration::AcceptsMousePress() {
28 return true; 46 return true;
29 } 47 }
30 48
31 bool PlusDecoration::OnMousePressed(NSRect frame) { 49 bool PlusDecoration::OnMousePressed(NSRect frame) {
32 // TODO(macourteau): trigger the menu when caitkp@ and beaudoin@'s CL is 50 CreateMenuController();
33 // ready. 51 NSMenu* menu = [menuController_ menu];
52
53 AutocompleteTextField* field = owner_->GetAutocompleteTextField();
54 NSRect popupFrame = [field bounds];
55 popupFrame.origin.x = NSMaxX(popupFrame) - menu.size.width;
56 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
57 popupFrame.size.width = menu.size.width;
58
59 if (!popUpCell_.get()) {
60 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.
61 pullsDown:YES]);
62 }
63 DCHECK(popUpCell_.get());
64 [popUpCell_ setMenu:menu];
65 [popUpCell_ selectItem:nil];
66 [popUpCell_ attachPopUpWithFrame:popupFrame inView:field];
67 [popUpCell_ performClickWithFrame:popupFrame inView:field];
34 return true; 68 return true;
35 } 69 }
36 70
37 NSString* PlusDecoration::GetToolTip() { 71 NSString* PlusDecoration::GetToolTip() {
38 return tooltip_.get(); 72 return tooltip_.get();
39 } 73 }
74
75 void PlusDecoration::CreateMenuController() {
76 menu_model_.reset(new ui::SimpleMenuModel(NULL));
77
78 menu_model_->InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE,
79 IDS_CHROME_TO_MOBILE);
80 menu_model_->InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE,
81 IDS_BOOKMARK_STAR);
82 menu_model_->SetIcon(0, gfx::ImageSkiaFromNSImage(
83 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.
84 menu_model_->SetIcon(1, gfx::ImageSkiaFromNSImage(
85 OmniboxViewMac::ImageForResource(IDR_STAR)));
86
87 menuController_.reset(
88 [[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.
89 useWithPopUpButtonCell:YES]);
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698