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 @@
#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/extensions/extension_system.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/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 "chrome/browser/ui/toolbar/action_box_menu_model.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.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 {
// The offset to apply to the menu so that it clears the bottom border of the
......@@ -45,18 +44,9 @@ bool PlusDecoration::AcceptsMousePress() {
}
bool PlusDecoration::OnMousePressed(NSRect frame) {
ui::SimpleMenuModel menu_model(NULL);
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));
ExtensionService* extension_service = extensions::ExtensionSystem::Get(
browser_->profile())->extension_service();
ActionBoxMenuModel menu_model(browser_, extension_service);
// Controller for the menu attached to the plus decoration.
scoped_nsobject<MenuController> menu_controller(
......
......@@ -5,30 +5,72 @@
#include "chrome/browser/ui/toolbar/action_box_menu_model.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.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
// that show before extensions. Like "Bookmark this page", "Send tab to device"
// and so on. They could have any IDs < kFirstExtensionCommandId.
static const int kFirstExtensionCommandId = 1000;
namespace {
// Extensions get command IDs that are beyond the maximal valid extension ID
// (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(ExtensionService* extension_service)
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(NULL)),
ActionBoxMenuModel::ActionBoxMenuModel(Browser* browser,
ExtensionService* extension_service)
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
browser_(browser),
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.
int command_id = kFirstExtensionCommandId;
const extensions::ExtensionList& action_box_items = action_box_menu_items();
if (!action_box_items.empty()) {
AddSeparator();
for (size_t i = 0; i < action_box_items.size(); ++i) {
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() {
// 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,
......
......@@ -9,17 +9,21 @@
#include "content/public/browser/notification_observer.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/ui/browser_commands.h"
#include "ui/base/models/simple_menu_model.h"
class Browser;
namespace extensions {
class Extension;
}
// A menu model that builds the contents of the action box menu.
class ActionBoxMenuModel : public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate,
public content::NotificationObserver {
public:
explicit ActionBoxMenuModel(ExtensionService* extension_service);
ActionBoxMenuModel(Browser* browser, ExtensionService* extension_service);
virtual ~ActionBoxMenuModel();
const extensions::ExtensionList& action_box_menu_items() {
......@@ -29,11 +33,20 @@ class ActionBoxMenuModel : public ui::SimpleMenuModel,
private:
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:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
Browser* browser_;
ExtensionService* extension_service_;
IdToEntensionIdMap id_to_extension_id_map_;
......
......@@ -81,7 +81,7 @@ void ActionBoxButtonView::OnMenuButtonClicked(View* source,
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
ActionBoxMenuModel model(extension_service);
ActionBoxMenuModel model(browser_, extension_service);
ActionBoxMenu action_box_menu(browser_, &model, starred_);
action_box_menu.Init();
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