Commit 3f11011b authored by beaudoin@chromium.org's avatar beaudoin@chromium.org

Add a menu (with placeholder items) to the Action Box Button.

Supersedes CL 10825003 (owner change).

BUG=138118
TEST=NONE


Review URL: https://chromiumcodereview.appspot.com/10833056

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151065 0039d316-1c4b-4281-b951-d872f2087c98
parent 451f3142
...@@ -6527,6 +6527,17 @@ Keep your key file in a safe place. You will need it to create new versions of y ...@@ -6527,6 +6527,17 @@ Keep your key file in a safe place. You will need it to create new versions of y
Set to default Set to default
</message> </message>
<!--Action Box menu-->
<message name="IDS_BOOKMARK_STAR" desc="The text for bookmark menu item">
Bookmark this page
</message>
<message name="IDS_BOOKMARK_STAR_LIT" desc="The text for bookmark menu item if page is already bookmarked">
Edit bookmark
</message>
<message name="IDS_CHROME_TO_MOBILE" desc="The text for chrome to mobile menu item">
Send tab to device
</message>
<!--Accessible name/action strings--> <!--Accessible name/action strings-->
<message name="IDS_ACCESSIBLE_INCOGNITO_WINDOW_TITLE_FORMAT" desc="The format for the accessible title of an incognito window"> <message name="IDS_ACCESSIBLE_INCOGNITO_WINDOW_TITLE_FORMAT" desc="The format for the accessible title of an incognito window">
<ph name="WINDOW_TITLE">$1</ph> (Incognito) <ph name="WINDOW_TITLE">$1</ph> (Incognito)
...@@ -238,10 +238,10 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver, ...@@ -238,10 +238,10 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver,
[BrowserActionsController registerUserPrefs:profile_->GetPrefs()]; [BrowserActionsController registerUserPrefs:profile_->GetPrefs()];
observer_.reset(new ExtensionServiceObserverBridge(self, profile_)); observer_.reset(new ExtensionServiceObserverBridge(self, profile_));
ExtensionService* extensionsService = profile_->GetExtensionService(); ExtensionService* extensionService = profile_->GetExtensionService();
// |extensionsService| can be NULL in Incognito. // |extensionService| can be NULL in Incognito.
if (extensionsService) { if (extensionService) {
toolbarModel_ = extensionsService->toolbar_model(); toolbarModel_ = extensionService->toolbar_model();
toolbarModel_->AddObserver(observer_.get()); toolbarModel_->AddObserver(observer_.get());
} }
......
...@@ -98,7 +98,7 @@ LocationBarViewMac::LocationBarViewMac( ...@@ -98,7 +98,7 @@ LocationBarViewMac::LocationBarViewMac(
OmniboxViewMac::GetFieldFont())), OmniboxViewMac::GetFieldFont())),
plus_decoration_(NULL), plus_decoration_(NULL),
star_decoration_(new StarDecoration(command_updater)), star_decoration_(new StarDecoration(command_updater)),
chrome_to_mobile_decoration_(nil), chrome_to_mobile_decoration_(NULL),
keyword_hint_decoration_( keyword_hint_decoration_(
new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())),
profile_(profile), profile_(profile),
...@@ -120,7 +120,7 @@ LocationBarViewMac::LocationBarViewMac( ...@@ -120,7 +120,7 @@ LocationBarViewMac::LocationBarViewMac(
} }
if (extensions::switch_utils::IsActionBoxEnabled()) { if (extensions::switch_utils::IsActionBoxEnabled()) {
plus_decoration_.reset(new PlusDecoration(command_updater)); plus_decoration_.reset(new PlusDecoration(this, command_updater, browser_));
} }
for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
...@@ -500,7 +500,7 @@ NSPoint LocationBarViewMac::GetChromeToMobileBubblePoint() const { ...@@ -500,7 +500,7 @@ NSPoint LocationBarViewMac::GetChromeToMobileBubblePoint() const {
[cell frameForDecoration:chrome_to_mobile_decoration_.get() [cell frameForDecoration:chrome_to_mobile_decoration_.get()
inFrame:[field_ bounds]]; inFrame:[field_ bounds]];
const NSPoint point = const NSPoint point =
chrome_to_mobile_decoration_->GetBubblePointInFrame(frame); chrome_to_mobile_decoration_->GetBubblePointInFrame(frame);
return [field_ convertPoint:point toView:nil]; return [field_ convertPoint:point toView:nil];
} }
......
...@@ -7,16 +7,21 @@ ...@@ -7,16 +7,21 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include "base/memory/scoped_nsobject.h"
#include "chrome/browser/ui/cocoa/location_bar/image_decoration.h" #include "chrome/browser/ui/cocoa/location_bar/image_decoration.h"
class Browser;
class CommandUpdater; class CommandUpdater;
class LocationBarViewMac;
// Note: this file is under development (see crbug.com/138118). // Note: this file is under development (see crbug.com/138118).
// Plus icon on the right side of the location bar. // Plus icon on the right side of the location bar.
class PlusDecoration : public ImageDecoration { class PlusDecoration : public ImageDecoration {
public: public:
explicit PlusDecoration(CommandUpdater* command_updater); PlusDecoration(LocationBarViewMac* owner,
CommandUpdater* command_updater,
Browser* browser);
virtual ~PlusDecoration(); virtual ~PlusDecoration();
// Implement |LocationBarDecoration|. // Implement |LocationBarDecoration|.
...@@ -25,8 +30,13 @@ class PlusDecoration : public ImageDecoration { ...@@ -25,8 +30,13 @@ class PlusDecoration : public ImageDecoration {
virtual NSString* GetToolTip() OVERRIDE; virtual NSString* GetToolTip() OVERRIDE;
private: private:
// Owner of the decoration, used to obtain the menu.
LocationBarViewMac* owner_;
CommandUpdater* command_updater_; // Weak, owned by Browser. CommandUpdater* command_updater_; // Weak, owned by Browser.
Browser* browser_;
// The string to show for a tooltip. // The string to show for a tooltip.
scoped_nsobject<NSString> tooltip_; scoped_nsobject<NSString> tooltip_;
......
...@@ -6,13 +6,29 @@ ...@@ -6,13 +6,29 @@
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/command_updater.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/omnibox/omnibox_view_mac.h"
#import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#import "chrome/browser/ui/cocoa/menu_controller.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "grit/theme_resources.h" #include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/resource/resource_bundle.h"
PlusDecoration::PlusDecoration(CommandUpdater* command_updater) namespace {
: command_updater_(command_updater) { // The offset to apply to the menu so that it clears the bottom border of the
// omnibox.
const CGFloat kOmniboxYOffset = 7.0;
} // namespace
PlusDecoration::PlusDecoration(LocationBarViewMac* owner,
CommandUpdater* command_updater, Browser* browser)
: owner_(owner),
command_updater_(command_updater),
browser_(browser) {
SetVisible(true); SetVisible(true);
const int image_id = IDR_ACTION_BOX_BUTTON; const int image_id = IDR_ACTION_BOX_BUTTON;
...@@ -29,8 +45,45 @@ bool PlusDecoration::AcceptsMousePress() { ...@@ -29,8 +45,45 @@ bool PlusDecoration::AcceptsMousePress() {
} }
bool PlusDecoration::OnMousePressed(NSRect frame) { bool PlusDecoration::OnMousePressed(NSRect frame) {
// TODO(macourteau): trigger the menu when caitkp@ and beaudoin@'s CL is ui::SimpleMenuModel menu_model(NULL);
// ready.
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
// TODO(beaudoin): Use a platform-independent menu model once the Windows
// patch introducing it lands. See: http://codereview.chromium.org/10533086/
menu_model.InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE,
IDS_CHROME_TO_MOBILE);
menu_model.SetIcon(0, *rb.GetImageSkiaNamed(IDR_MOBILE));
menu_model.InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE,
IDS_BOOKMARK_STAR);
menu_model.SetIcon(1, *rb.GetImageSkiaNamed(IDR_STAR));
// Controller for the menu attached to the plus decoration.
scoped_nsobject<MenuController> menu_controller(
[[MenuController alloc] initWithModel:&menu_model
useWithPopUpButtonCell:YES]);
NSMenu* menu = [menu_controller menu];
// Align the menu popup to that its top-right corner matches the bottom-right
// corner of the omnibox.
AutocompleteTextField* field = owner_->GetAutocompleteTextField();
NSRect popUpFrame = [field bounds];
popUpFrame.origin.x = NSMaxX([field bounds]) - menu.size.width;
popUpFrame.size.width = menu.size.width;
// Attach the menu to a slightly higher box, to clear the omnibox border.
popUpFrame.size.height += kOmniboxYOffset;
scoped_nsobject<NSPopUpButtonCell> pop_up_cell(
[[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES]);
DCHECK(pop_up_cell.get());
[pop_up_cell setMenu:menu];
[pop_up_cell selectItem:nil];
[pop_up_cell attachPopUpWithFrame:popUpFrame inView:field];
[pop_up_cell performClickWithFrame:popUpFrame inView:field];
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment