| Index: chrome/browser/wrench_menu_model.cc
|
| diff --git a/chrome/browser/wrench_menu_model.cc b/chrome/browser/wrench_menu_model.cc
|
| index b1d39d148ceb98933043f2e0cd0fe637bff6b17e..031d0d9627f1ab42927db584658998632c7b4f97 100644
|
| --- a/chrome/browser/wrench_menu_model.cc
|
| +++ b/chrome/browser/wrench_menu_model.cc
|
| @@ -20,7 +20,6 @@
|
| #include "chrome/browser/defaults.h"
|
| #include "chrome/browser/encoding_menu_controller.h"
|
| #include "chrome/browser/host_zoom_map.h"
|
| -#include "chrome/browser/pref_service.h"
|
| #include "chrome/browser/profile.h"
|
| #include "chrome/browser/sync/profile_sync_service.h"
|
| #include "chrome/browser/sync/sync_ui_util.h"
|
| @@ -30,7 +29,6 @@
|
| #include "chrome/common/notification_service.h"
|
| #include "chrome/common/notification_source.h"
|
| #include "chrome/common/notification_type.h"
|
| -#include "chrome/common/pref_names.h"
|
| #include "grit/chromium_strings.h"
|
| #include "grit/generated_resources.h"
|
| #include "grit/theme_resources.h"
|
| @@ -39,10 +37,6 @@
|
| #include <gtk/gtk.h>
|
| #endif
|
|
|
| -#if defined(OS_MACOSX)
|
| -#include "chrome/browser/browser_window.h"
|
| -#endif
|
| -
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // EncodingMenuModel
|
|
|
| @@ -169,10 +163,10 @@ void ToolsMenuModel::Build(Browser* browser) {
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // WrenchMenuModel
|
|
|
| -WrenchMenuModel::WrenchMenuModel(menus::AcceleratorProvider* provider,
|
| +WrenchMenuModel::WrenchMenuModel(menus::SimpleMenuModel::Delegate* delegate,
|
| Browser* browser)
|
| - : ALLOW_THIS_IN_INITIALIZER_LIST(model_(this)),
|
| - provider_(provider),
|
| + : menus::SimpleMenuModel(delegate),
|
| + delegate_(delegate),
|
| browser_(browser),
|
| tabstrip_model_(browser_->tabstrip_model()) {
|
| Build();
|
| @@ -191,64 +185,50 @@ WrenchMenuModel::~WrenchMenuModel() {
|
| tabstrip_model_->RemoveObserver(this);
|
| }
|
|
|
| -bool WrenchMenuModel::IsLabelForCommandIdDynamic(int command_id) const {
|
| - return command_id == IDC_ZOOM_PERCENT_DISPLAY ||
|
| - command_id == IDC_SYNC_BOOKMARKS ||
|
| -#if defined(OS_MACOSX)
|
| - command_id == IDC_FULLSCREEN ||
|
| -#endif
|
| - command_id == IDC_ABOUT;
|
| +bool WrenchMenuModel::IsLabelDynamicAt(int index) const {
|
| + return IsDynamicItem(index) || SimpleMenuModel::IsLabelDynamicAt(index);
|
| }
|
|
|
| -string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const {
|
| +string16 WrenchMenuModel::GetLabelAt(int index) const {
|
| + if (!IsDynamicItem(index))
|
| + return SimpleMenuModel::GetLabelAt(index);
|
| +
|
| + int command_id = GetCommandIdAt(index);
|
| +
|
| switch (command_id) {
|
| case IDC_ABOUT:
|
| return GetAboutEntryMenuLabel();
|
| case IDC_SYNC_BOOKMARKS:
|
| return GetSyncMenuLabel();
|
| - case IDC_ZOOM_PERCENT_DISPLAY:
|
| - return zoom_label_;
|
| -#if defined(OS_MACOSX)
|
| - case IDC_FULLSCREEN: {
|
| - int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter.
|
| - // Note: On startup, |window()| may be NULL.
|
| - if (browser_->window() && browser_->window()->IsFullscreen())
|
| - string_id = IDS_EXIT_FULLSCREEN_MAC;
|
| - return l10n_util::GetStringUTF16(string_id);
|
| - }
|
| -#endif
|
| default:
|
| NOTREACHED();
|
| return string16();
|
| }
|
| }
|
|
|
| -void WrenchMenuModel::ExecuteCommand(int command_id) {
|
| - browser_->ExecuteCommand(command_id);
|
| -}
|
| -
|
| -bool WrenchMenuModel::IsCommandIdChecked(int command_id) const {
|
| -#if defined(OS_CHROMEOS)
|
| - if (command_id == IDC_TOGGLE_VERTICAL_TABS) {
|
| - return browser_->UseVerticalTabs();
|
| - }
|
| -#endif
|
| -
|
| - if (command_id == IDC_SHOW_BOOKMARK_BAR) {
|
| - return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
|
| +bool WrenchMenuModel::GetIconAt(int index, SkBitmap* icon) const {
|
| + if (GetCommandIdAt(index) == IDC_ABOUT &&
|
| + Singleton<UpgradeDetector>::get()->notify_upgrade()) {
|
| + // Show the exclamation point next to the menu item.
|
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| + *icon = *rb.GetBitmapNamed(IDR_UPDATE_AVAILABLE);
|
| + return true;
|
| }
|
| -
|
| return false;
|
| }
|
|
|
| -bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const {
|
| - return browser_->command_updater()->IsCommandEnabled(command_id);
|
| +bool WrenchMenuModel::IsLabelForCommandIdDynamic(int command_id) const {
|
| + return command_id == IDC_ZOOM_PERCENT_DISPLAY;
|
| +}
|
| +
|
| +string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const {
|
| + DCHECK_EQ(IDC_ZOOM_PERCENT_DISPLAY, command_id);
|
| + return zoom_label_;
|
| }
|
|
|
| -bool WrenchMenuModel::GetAcceleratorForCommandId(
|
| - int command_id,
|
| - menus::Accelerator* accelerator) {
|
| - return provider_->GetAcceleratorForCommandId(command_id, accelerator);
|
| +void WrenchMenuModel::ExecuteCommand(int command_id) {
|
| + if (delegate_)
|
| + delegate_->ExecuteCommand(command_id);
|
| }
|
|
|
| void WrenchMenuModel::TabSelectedAt(TabContents* old_contents,
|
| @@ -278,17 +258,12 @@ void WrenchMenuModel::Observe(NotificationType type,
|
| UpdateZoomControls();
|
| }
|
|
|
| -// For testing.
|
| -WrenchMenuModel::WrenchMenuModel() : model_(NULL) {
|
| -}
|
| -
|
| void WrenchMenuModel::Build() {
|
| - model_.AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
|
| - model_.AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW);
|
| - model_.AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW,
|
| - IDS_NEW_INCOGNITO_WINDOW);
|
| + AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
|
| + AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW);
|
| + AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW);
|
|
|
| - model_.AddSeparator();
|
| + AddSeparator();
|
| #if defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS))
|
| // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the
|
| // layout for this menu item in Toolbar.xib. It does, however, use the
|
| @@ -297,13 +272,13 @@ void WrenchMenuModel::Build() {
|
| edit_menu_item_model_->AddGroupItemWithStringId(IDC_CUT, IDS_CUT);
|
| edit_menu_item_model_->AddGroupItemWithStringId(IDC_COPY, IDS_COPY);
|
| edit_menu_item_model_->AddGroupItemWithStringId(IDC_PASTE, IDS_PASTE);
|
| - model_.AddButtonItem(IDC_EDIT_MENU, edit_menu_item_model_.get());
|
| + AddButtonItem(IDC_EDIT_MENU, edit_menu_item_model_.get());
|
| #else
|
| // TODO(port): Move to the above.
|
| CreateCutCopyPaste();
|
| #endif
|
|
|
| - model_.AddSeparator();
|
| + AddSeparator();
|
| #if defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS))
|
| // WARNING: See above comment.
|
| zoom_menu_item_model_.reset(
|
| @@ -317,79 +292,68 @@ void WrenchMenuModel::Build() {
|
| zoom_menu_item_model_->AddSpace();
|
| zoom_menu_item_model_->AddItemWithImage(
|
| IDC_FULLSCREEN, IDR_FULLSCREEN_MENU_BUTTON);
|
| - model_.AddButtonItem(IDC_ZOOM_MENU, zoom_menu_item_model_.get());
|
| + AddButtonItem(IDC_ZOOM_MENU, zoom_menu_item_model_.get());
|
| #else
|
| // TODO(port): Move to the above.
|
| CreateZoomFullscreen();
|
| #endif
|
|
|
| - model_.AddSeparator();
|
| - model_.AddItemWithStringId(IDC_SAVE_PAGE, IDS_SAVE_PAGE);
|
| - model_.AddItemWithStringId(IDC_FIND, IDS_FIND);
|
| - model_.AddItemWithStringId(IDC_PRINT, IDS_PRINT);
|
| + AddSeparator();
|
| + AddItemWithStringId(IDC_SAVE_PAGE, IDS_SAVE_PAGE);
|
| + AddItemWithStringId(IDC_FIND, IDS_FIND);
|
| + AddItemWithStringId(IDC_PRINT, IDS_PRINT);
|
|
|
| - tools_menu_model_.reset(new ToolsMenuModel(this, browser_));
|
| - model_.AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_TOOLS_MENU,
|
| + tools_menu_model_.reset(new ToolsMenuModel(delegate(), browser_));
|
| + AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_TOOLS_MENU,
|
| tools_menu_model_.get());
|
|
|
| - model_.AddSeparator();
|
| + AddSeparator();
|
| #if defined(ENABLE_REMOTING)
|
| if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableRemoting)) {
|
| - model_.AddItem(IDC_REMOTING_SETUP,
|
| + AddItem(IDC_REMOTING_SETUP,
|
| l10n_util::GetStringUTF16(IDS_REMOTING_SETUP_LABEL));
|
| }
|
| #endif
|
| - model_.AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER);
|
| - model_.AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY);
|
| - model_.AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS);
|
| - model_.AddSeparator();
|
| + AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER);
|
| + AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY);
|
| + AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS);
|
| + AddSeparator();
|
|
|
| #if defined(OS_MACOSX)
|
| - model_.AddItemWithStringId(IDC_OPTIONS, IDS_PREFERENCES_MAC);
|
| + AddItemWithStringId(IDC_OPTIONS, IDS_PREFERENCES_MAC);
|
| #elif defined(OS_LINUX)
|
| GtkStockItem stock_item;
|
| if (gtk_stock_lookup(GTK_STOCK_PREFERENCES, &stock_item)) {
|
| const char16 kUnderscore[] = { '_', 0 };
|
| string16 preferences;
|
| RemoveChars(UTF8ToUTF16(stock_item.label), kUnderscore, &preferences);
|
| - model_.AddItem(IDC_OPTIONS, preferences);
|
| - } else {
|
| - model_.AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS);
|
| + AddItem(IDC_OPTIONS, preferences);
|
| }
|
| #else
|
| - model_.AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS);
|
| + AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS);
|
| #endif
|
|
|
| #if defined(OS_CHROMEOS)
|
| - model_.AddCheckItemWithStringId(IDC_TOGGLE_VERTICAL_TABS,
|
| + AddCheckItemWithStringId(IDC_TOGGLE_VERTICAL_TABS,
|
| IDS_TAB_CXMENU_USE_VERTICAL_TABS);
|
| #endif
|
|
|
| - // TODO(erg): This entire section needs to be reworked and is out of scope of
|
| - // the first cleanup patch I'm doing. Part 1 (crbug.com/47320) is moving most
|
| - // of the logic from each platform specific UI code into the model here. Part
|
| - // 2 (crbug.com/46221) is normalizing the about menu item/hidden update menu
|
| - // item behaviour across the three platforms.
|
| -
|
| // On Mac, there is no About item unless it is replaced with the update
|
| // available notification.
|
| if (browser_defaults::kShowAboutMenuItem ||
|
| Singleton<UpgradeDetector>::get()->notify_upgrade()) {
|
| - model_.AddItem(IDC_ABOUT,
|
| + AddItem(IDC_ABOUT,
|
| l10n_util::GetStringFUTF16(
|
| IDS_ABOUT,
|
| l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
|
| - // ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| - // model_.SetIcon(model_.GetIndexOfCommandId(IDC_ABOUT),
|
| - // *rb.GetBitmapNamed(IDR_UPDATE_AVAILABLE));
|
| }
|
| - model_.AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE);
|
| + AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE);
|
| if (browser_defaults::kShowExitMenuItem) {
|
| - model_.AddSeparator();
|
| + AddSeparator();
|
| #if defined(OS_CHROMEOS)
|
| - model_.AddItemWithStringId(IDC_EXIT, IDS_SIGN_OUT);
|
| + AddItemWithStringId(IDC_EXIT, IDS_SIGN_OUT);
|
| #else
|
| - model_.AddItemWithStringId(IDC_EXIT, IDS_EXIT);
|
| + AddItemWithStringId(IDC_EXIT, IDS_EXIT);
|
| #endif
|
| }
|
| }
|
| @@ -397,17 +361,17 @@ void WrenchMenuModel::Build() {
|
| void WrenchMenuModel::CreateCutCopyPaste() {
|
| // WARNING: views/wrench_menu assumes these items are added in this order. If
|
| // you change the order you'll need to update wrench_menu as well.
|
| - model_.AddItemWithStringId(IDC_CUT, IDS_CUT);
|
| - model_.AddItemWithStringId(IDC_COPY, IDS_COPY);
|
| - model_.AddItemWithStringId(IDC_PASTE, IDS_PASTE);
|
| + AddItemWithStringId(IDC_CUT, IDS_CUT);
|
| + AddItemWithStringId(IDC_COPY, IDS_COPY);
|
| + AddItemWithStringId(IDC_PASTE, IDS_PASTE);
|
| }
|
|
|
| void WrenchMenuModel::CreateZoomFullscreen() {
|
| // WARNING: views/wrench_menu assumes these items are added in this order. If
|
| // you change the order you'll need to update wrench_menu as well.
|
| - model_.AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS);
|
| - model_.AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS);
|
| - model_.AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN);
|
| + AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS);
|
| + AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS);
|
| + AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN);
|
| }
|
|
|
| void WrenchMenuModel::UpdateZoomControls() {
|
| @@ -451,3 +415,15 @@ string16 WrenchMenuModel::GetAboutEntryMenuLabel() const {
|
| return l10n_util::GetStringFUTF16(
|
| IDS_ABOUT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
|
| }
|
| +
|
| +bool WrenchMenuModel::IsDynamicItem(int index) const {
|
| + int command_id = GetCommandIdAt(index);
|
| + return command_id == IDC_SYNC_BOOKMARKS ||
|
| + command_id == IDC_ABOUT;
|
| +}
|
| +
|
| +bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const {
|
| + if (delegate_)
|
| + return delegate_->IsCommandIdEnabled(command_id);
|
| + return true;
|
| +}
|
|
|