Commit a5e00a11 authored by beaudoin@chromium.org's avatar beaudoin@chromium.org

Adding "send to mobile" and "add bookmark" to the action box menu and wiring...

Adding "send to mobile" and "add bookmark" to the action box menu and wiring to their respective action on Mac.

BUG=138118 125307


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152416 0039d316-1c4b-4281-b951-d872f2087c98
parent f88a8d8d
...@@ -4,19 +4,18 @@ ...@@ -4,19 +4,18 @@
#import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/command_updater.h" #include "chrome/browser/command_updater.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.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/autocomplete_text_field.h"
#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#import "chrome/browser/ui/cocoa/menu_controller.h" #import "chrome/browser/ui/cocoa/menu_controller.h"
#include "chrome/browser/ui/toolbar/action_box_menu_model.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"
namespace { namespace {
// The offset to apply to the menu so that it clears the bottom border of the // The offset to apply to the menu so that it clears the bottom border of the
...@@ -45,18 +44,9 @@ bool PlusDecoration::AcceptsMousePress() { ...@@ -45,18 +44,9 @@ bool PlusDecoration::AcceptsMousePress() {
} }
bool PlusDecoration::OnMousePressed(NSRect frame) { bool PlusDecoration::OnMousePressed(NSRect frame) {
ui::SimpleMenuModel menu_model(NULL); ExtensionService* extension_service = extensions::ExtensionSystem::Get(
browser_->profile())->extension_service();
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ActionBoxMenuModel menu_model(browser_, extension_service);
// 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. // Controller for the menu attached to the plus decoration.
scoped_nsobject<MenuController> menu_controller( scoped_nsobject<MenuController> menu_controller(
......
...@@ -5,30 +5,72 @@ ...@@ -5,30 +5,72 @@
#include "chrome/browser/ui/toolbar/action_box_menu_model.h" #include "chrome/browser/ui/toolbar/action_box_menu_model.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/extension_toolbar_model.h" #include "chrome/browser/extensions/extension_toolbar_model.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
// Arbitrary number just to leave enough space for menu IDs namespace {
// that show before extensions. Like "Bookmark this page", "Send tab to device"
// and so on. They could have any IDs < kFirstExtensionCommandId. // Extensions get command IDs that are beyond the maximal valid extension ID
static const int kFirstExtensionCommandId = 1000; // (0xDFFF) so that they are not confused with actual commands that appear in
// the menu. For more details see: chrome/app/chrome_command_ids.h
//
const int kFirstExtensionCommandId = 0xE000;
} // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ActionBoxMenuModel // ActionBoxMenuModel
ActionBoxMenuModel::ActionBoxMenuModel(ExtensionService* extension_service) ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser,
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(NULL)), ExtensionService* extension_service)
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
browser_(browser),
extension_service_(extension_service) { extension_service_(extension_service) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
InsertItemWithStringIdAt(0, IDC_CHROME_TO_MOBILE_PAGE,
IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP);
SetIcon(0, *rb.GetImageSkiaNamed(IDR_MOBILE));
InsertItemWithStringIdAt(1, IDC_BOOKMARK_PAGE, IDS_BOOKMARK_STAR);
SetIcon(1, *rb.GetImageSkiaNamed(IDR_STAR));
// Adds extensions to the model. // Adds extensions to the model.
int command_id = kFirstExtensionCommandId; int command_id = kFirstExtensionCommandId;
const extensions::ExtensionList& action_box_items = action_box_menu_items(); const extensions::ExtensionList& action_box_items = action_box_menu_items();
for (size_t i = 0; i < action_box_items.size(); ++i) { if (!action_box_items.empty()) {
const extensions::Extension* extension = action_box_items[i]; AddSeparator();
AddItem(command_id, UTF8ToUTF16(extension->name())); for (size_t i = 0; i < action_box_items.size(); ++i) {
id_to_extension_id_map_[command_id++] = extension->id(); const extensions::Extension* extension = action_box_items[i];
AddItem(command_id, UTF8ToUTF16(extension->name()));
id_to_extension_id_map_[command_id++] = extension->id();
}
} }
} }
ActionBoxMenuModel::~ActionBoxMenuModel() { ActionBoxMenuModel::~ActionBoxMenuModel() {
// Ensures parent destructor does not use a partially destroyed delegate.
set_delegate(NULL);
}
bool ActionBoxMenuModel::IsCommandIdChecked(int command_id) const {
return false;
}
bool ActionBoxMenuModel::IsCommandIdEnabled(int command_id) const {
return true;
}
bool ActionBoxMenuModel::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) {
return false;
}
void ActionBoxMenuModel::ExecuteCommand(int command_id) {
if (command_id < kFirstExtensionCommandId)
chrome::ExecuteCommand(browser_, command_id);
} }
void ActionBoxMenuModel::Observe(int type, void ActionBoxMenuModel::Observe(int type,
......
...@@ -9,17 +9,21 @@ ...@@ -9,17 +9,21 @@
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/ui/browser_commands.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
class Browser;
namespace extensions { namespace extensions {
class Extension; class Extension;
} }
// A menu model that builds the contents of the action box menu. // A menu model that builds the contents of the action box menu.
class ActionBoxMenuModel : public ui::SimpleMenuModel, class ActionBoxMenuModel : public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate,
public content::NotificationObserver { public content::NotificationObserver {
public: public:
explicit ActionBoxMenuModel(ExtensionService* extension_service); ActionBoxMenuModel(Browser* browser, ExtensionService* extension_service);
virtual ~ActionBoxMenuModel(); virtual ~ActionBoxMenuModel();
const extensions::ExtensionList& action_box_menu_items() { const extensions::ExtensionList& action_box_menu_items() {
...@@ -29,11 +33,20 @@ class ActionBoxMenuModel : public ui::SimpleMenuModel, ...@@ -29,11 +33,20 @@ class ActionBoxMenuModel : public ui::SimpleMenuModel,
private: private:
typedef std::map<int, std::string> IdToEntensionIdMap; typedef std::map<int, std::string> IdToEntensionIdMap;
// Overridden from ui::SimpleMenuModel::Delegate:
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE;
virtual void ExecuteCommand(int command_id) OVERRIDE;
// Overridden from content::NotificationObserver: // Overridden from content::NotificationObserver:
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
Browser* browser_;
ExtensionService* extension_service_; ExtensionService* extension_service_;
IdToEntensionIdMap id_to_extension_id_map_; IdToEntensionIdMap id_to_extension_id_map_;
......
...@@ -81,7 +81,7 @@ void ActionBoxButtonView::OnMenuButtonClicked(View* source, ...@@ -81,7 +81,7 @@ void ActionBoxButtonView::OnMenuButtonClicked(View* source,
ExtensionService* extension_service = ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile_)->extension_service(); extensions::ExtensionSystem::Get(profile_)->extension_service();
ActionBoxMenuModel model(extension_service); ActionBoxMenuModel model(browser_, extension_service);
ActionBoxMenu action_box_menu(browser_, &model, starred_); ActionBoxMenu action_box_menu(browser_, &model, starred_);
action_box_menu.Init(); action_box_menu.Init();
action_box_menu.RunMenu(this); action_box_menu.RunMenu(this);
......
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