summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/cocoa/download_item_controller.mm20
-rw-r--r--chrome/browser/download/download_shelf.cc65
-rw-r--r--chrome/browser/download/download_shelf.h23
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc32
-rw-r--r--chrome/browser/views/download_item_view.cc42
5 files changed, 60 insertions, 122 deletions
diff --git a/chrome/browser/cocoa/download_item_controller.mm b/chrome/browser/cocoa/download_item_controller.mm
index 7b32994..f20c548 100644
--- a/chrome/browser/cocoa/download_item_controller.mm
+++ b/chrome/browser/cocoa/download_item_controller.mm
@@ -57,9 +57,9 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu {
DownloadShelfContextMenuMac(BaseDownloadItemModel* model)
: DownloadShelfContextMenu(model) { }
- using DownloadShelfContextMenu::ExecuteItemCommand;
- using DownloadShelfContextMenu::ItemIsChecked;
- using DownloadShelfContextMenu::IsItemCommandEnabled;
+ using DownloadShelfContextMenu::ExecuteCommand;
+ using DownloadShelfContextMenu::IsCommandIdChecked;
+ using DownloadShelfContextMenu::IsCommandIdEnabled;
using DownloadShelfContextMenu::SHOW_IN_FOLDER;
using DownloadShelfContextMenu::OPEN_WHEN_COMPLETE;
@@ -297,30 +297,30 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu {
return YES;
}
- if (menuBridge_->ItemIsChecked(actionId))
+ if (menuBridge_->IsCommandIdChecked(actionId))
[item setState:NSOnState];
else
[item setState:NSOffState];
- return menuBridge_->IsItemCommandEnabled(actionId) ? YES : NO;
+ return menuBridge_->IsCommandIdEnabled(actionId) ? YES : NO;
}
- (IBAction)handleOpen:(id)sender {
- menuBridge_->ExecuteItemCommand(
+ menuBridge_->ExecuteCommand(
DownloadShelfContextMenuMac::OPEN_WHEN_COMPLETE);
}
- (IBAction)handleAlwaysOpen:(id)sender {
- menuBridge_->ExecuteItemCommand(
+ menuBridge_->ExecuteCommand(
DownloadShelfContextMenuMac::ALWAYS_OPEN_TYPE);
}
- (IBAction)handleReveal:(id)sender {
- menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::SHOW_IN_FOLDER);
+ menuBridge_->ExecuteCommand(DownloadShelfContextMenuMac::SHOW_IN_FOLDER);
}
- (IBAction)handleCancel:(id)sender {
- menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL);
+ menuBridge_->ExecuteCommand(DownloadShelfContextMenuMac::CANCEL);
}
- (IBAction)handleTogglePause:(id)sender {
@@ -331,7 +331,7 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu {
[sender setTitle:l10n_util::GetNSStringWithFixup(
IDS_DOWNLOAD_MENU_RESUME_ITEM)];
}
- menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::TOGGLE_PAUSE);
+ menuBridge_->ExecuteCommand(DownloadShelfContextMenuMac::TOGGLE_PAUSE);
}
@end
diff --git a/chrome/browser/download/download_shelf.cc b/chrome/browser/download/download_shelf.cc
index 1cb94b0..ec67f0e 100644
--- a/chrome/browser/download/download_shelf.cc
+++ b/chrome/browser/download/download_shelf.cc
@@ -26,8 +26,8 @@ DownloadShelfContextMenu::DownloadShelfContextMenu(
DownloadShelfContextMenu::~DownloadShelfContextMenu() {
}
-bool DownloadShelfContextMenu::ItemIsChecked(int id) const {
- switch (id) {
+bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const {
+ switch (command_id) {
case OPEN_WHEN_COMPLETE: {
return download_->open_when_complete();
}
@@ -35,43 +35,36 @@ bool DownloadShelfContextMenu::ItemIsChecked(int id) const {
return download_->manager()->ShouldOpenFileBasedOnExtension(
download_->full_path());
}
- case TOGGLE_PAUSE: {
- return download_->is_paused();
- }
}
return false;
}
-bool DownloadShelfContextMenu::ItemIsDefault(int id) const {
- return id == OPEN_WHEN_COMPLETE;
-}
-
-std::wstring DownloadShelfContextMenu::GetItemLabel(int id) const {
- switch (id) {
+string16 DownloadShelfContextMenu::GetLabelForCommandId(int command_id) const {
+ switch (command_id) {
case SHOW_IN_FOLDER:
- return l10n_util::GetString(IDS_DOWNLOAD_MENU_SHOW);
+ return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW);
case OPEN_WHEN_COMPLETE:
if (download_->state() == DownloadItem::IN_PROGRESS)
- return l10n_util::GetString(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE);
- return l10n_util::GetString(IDS_DOWNLOAD_MENU_OPEN);
+ return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE);
+ return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN);
case ALWAYS_OPEN_TYPE:
- return l10n_util::GetString(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE);
+ return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE);
case CANCEL:
- return l10n_util::GetString(IDS_DOWNLOAD_MENU_CANCEL);
+ return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL);
case TOGGLE_PAUSE: {
if (download_->is_paused())
- return l10n_util::GetString(IDS_DOWNLOAD_MENU_RESUME_ITEM);
+ return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM);
else
- return l10n_util::GetString(IDS_DOWNLOAD_MENU_PAUSE_ITEM);
+ return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM);
}
default:
NOTREACHED();
}
- return std::wstring();
+ return string16();
}
-bool DownloadShelfContextMenu::IsItemCommandEnabled(int id) const {
- switch (id) {
+bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const {
+ switch (command_id) {
case SHOW_IN_FOLDER:
case OPEN_WHEN_COMPLETE:
return download_->state() != DownloadItem::CANCELLED;
@@ -82,12 +75,12 @@ bool DownloadShelfContextMenu::IsItemCommandEnabled(int id) const {
case TOGGLE_PAUSE:
return download_->state() == DownloadItem::IN_PROGRESS;
default:
- return id > 0 && id < MENU_LAST;
+ return command_id > 0 && command_id < MENU_LAST;
}
}
-void DownloadShelfContextMenu::ExecuteItemCommand(int id) {
- switch (id) {
+void DownloadShelfContextMenu::ExecuteCommand(int command_id) {
+ switch (command_id) {
case SHOW_IN_FOLDER:
download_->manager()->ShowDownloadInShell(download_);
break;
@@ -96,7 +89,7 @@ void DownloadShelfContextMenu::ExecuteItemCommand(int id) {
break;
case ALWAYS_OPEN_TYPE: {
download_->manager()->OpenFilesBasedOnExtension(
- download_->full_path(), !ItemIsChecked(ALWAYS_OPEN_TYPE));
+ download_->full_path(), !IsCommandIdChecked(ALWAYS_OPEN_TYPE));
break;
}
case CANCEL:
@@ -114,19 +107,28 @@ void DownloadShelfContextMenu::ExecuteItemCommand(int id) {
}
}
-menus::SimpleMenuModel* DownloadShelfContextMenu::GetInProgressMenuModel(
- menus::SimpleMenuModel::Delegate* delegate) {
+bool DownloadShelfContextMenu::GetAcceleratorForCommandId(
+ int command_id, menus::Accelerator* accelerator) {
+ return false;
+}
+
+bool DownloadShelfContextMenu::IsLabelForCommandIdDynamic(
+ int command_id) const {
+ return command_id == TOGGLE_PAUSE;
+}
+
+menus::SimpleMenuModel* DownloadShelfContextMenu::GetInProgressMenuModel() {
if (in_progress_download_menu_model_.get())
return in_progress_download_menu_model_.get();
- in_progress_download_menu_model_.reset(new menus::SimpleMenuModel(delegate));
+ in_progress_download_menu_model_.reset(new menus::SimpleMenuModel(this));
in_progress_download_menu_model_->AddCheckItemWithStringId(
OPEN_WHEN_COMPLETE, IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE);
in_progress_download_menu_model_->AddCheckItemWithStringId(
ALWAYS_OPEN_TYPE, IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE);
in_progress_download_menu_model_->AddSeparator();
- in_progress_download_menu_model_->AddCheckItemWithStringId(
+ in_progress_download_menu_model_->AddItemWithStringId(
TOGGLE_PAUSE, IDS_DOWNLOAD_MENU_PAUSE_ITEM);
in_progress_download_menu_model_->AddItemWithStringId(
SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW);
@@ -137,12 +139,11 @@ menus::SimpleMenuModel* DownloadShelfContextMenu::GetInProgressMenuModel(
return in_progress_download_menu_model_.get();
}
-menus::SimpleMenuModel* DownloadShelfContextMenu::GetFinishedMenuModel(
- menus::SimpleMenuModel::Delegate* delegate) {
+menus::SimpleMenuModel* DownloadShelfContextMenu::GetFinishedMenuModel() {
if (finished_download_menu_model_.get())
return finished_download_menu_model_.get();
- finished_download_menu_model_.reset(new menus::SimpleMenuModel(delegate));
+ finished_download_menu_model_.reset(new menus::SimpleMenuModel(this));
finished_download_menu_model_->AddItemWithStringId(
OPEN_WHEN_COMPLETE, IDS_DOWNLOAD_MENU_OPEN);
diff --git a/chrome/browser/download/download_shelf.h b/chrome/browser/download/download_shelf.h
index ec8a9cb..c9fdaa9 100644
--- a/chrome/browser/download/download_shelf.h
+++ b/chrome/browser/download/download_shelf.h
@@ -45,7 +45,7 @@ class DownloadShelf {
// Logic for the download shelf context menu. Platform specific subclasses are
// responsible for creating and running the menu.
-class DownloadShelfContextMenu {
+class DownloadShelfContextMenu : public menus::SimpleMenuModel::Delegate {
public:
virtual ~DownloadShelfContextMenu();
@@ -63,19 +63,20 @@ class DownloadShelfContextMenu {
protected:
explicit DownloadShelfContextMenu(BaseDownloadItemModel* download_model);
- bool ItemIsChecked(int id) const;
- bool ItemIsDefault(int id) const;
- std::wstring GetItemLabel(int id) const;
- bool IsItemCommandEnabled(int id) const;
- void ExecuteItemCommand(int id);
-
- menus::SimpleMenuModel* GetInProgressMenuModel(
- menus::SimpleMenuModel::Delegate* delegate);
- menus::SimpleMenuModel* GetFinishedMenuModel(
- menus::SimpleMenuModel::Delegate* delegate);
+ menus::SimpleMenuModel* GetInProgressMenuModel();
+ menus::SimpleMenuModel* GetFinishedMenuModel();
// Information source.
DownloadItem* download_;
+ // menus::SimpleMenuModel::Delegate implementation:
+ virtual bool IsCommandIdEnabled(int command_id) const;
+ virtual bool IsCommandIdChecked(int command_id) const;
+ virtual void ExecuteCommand(int command_id);
+ virtual bool GetAcceleratorForCommandId(int command_id,
+ menus::Accelerator* accelerator);
+ virtual bool IsLabelForCommandIdDynamic(int command_id) const;
+ virtual string16 GetLabelForCommandId(int command_id) const;
+
// A model to control the cancel behavior.
BaseDownloadItemModel* model_;
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
index 47c8f86..a71374b 100644
--- a/chrome/browser/gtk/download_item_gtk.cc
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -77,7 +77,6 @@ static const double kDownloadItemLuminanceMod = 0.8;
// DownloadShelfContextMenuGtk -------------------------------------------------
class DownloadShelfContextMenuGtk : public DownloadShelfContextMenu,
- public menus::SimpleMenuModel::Delegate,
public MenuGtk::Delegate {
public:
// The constructor creates the menu and immediately pops it up.
@@ -98,39 +97,12 @@ class DownloadShelfContextMenuGtk : public DownloadShelfContextMenu,
// Create the menu if we have not created it yet or we created it for
// an in-progress download that has since completed.
if (download_->state() == DownloadItem::COMPLETE)
- menu_.reset(new MenuGtk(this, GetFinishedMenuModel(this)));
+ menu_.reset(new MenuGtk(this, GetFinishedMenuModel()));
else
- menu_.reset(new MenuGtk(this, GetInProgressMenuModel(this)));
+ menu_.reset(new MenuGtk(this, GetInProgressMenuModel()));
menu_->Popup(widget, event);
}
- // menus::SimpleMenuModel::Delegate implementation:
- virtual bool IsCommandIdEnabled(int command_id) const {
- return IsItemCommandEnabled(command_id);
- }
-
- virtual bool IsCommandIdChecked(int command_id) const {
- return ItemIsChecked(command_id);
- }
-
- virtual void ExecuteCommand(int command_id) {
- ExecuteItemCommand(command_id);
- }
-
- virtual bool GetAcceleratorForCommandId(int command_id,
- menus::Accelerator* accelerator) {
- return false;
- }
-
- bool IsLabelForCommandIdDynamic(int command_id) const {
- return command_id == TOGGLE_PAUSE;
- }
-
- string16 GetLabelForCommandId(int command_id) const {
- DCHECK(command_id == TOGGLE_PAUSE);
- return WideToUTF16(GetItemLabel(command_id));
- }
-
// MenuGtk::Delegate implementation:
virtual void StoppedShowing() {
download_item_->menu_showing_ = false;
diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc
index af57050..12877c8 100644
--- a/chrome/browser/views/download_item_view.cc
+++ b/chrome/browser/views/download_item_view.cc
@@ -75,8 +75,7 @@ static const double kDownloadItemLuminanceMod = 0.8;
// DownloadShelfContextMenuWin -------------------------------------------------
-class DownloadShelfContextMenuWin : public DownloadShelfContextMenu,
- public menus::SimpleMenuModel::Delegate {
+class DownloadShelfContextMenuWin : public DownloadShelfContextMenu {
public:
explicit DownloadShelfContextMenuWin(BaseDownloadItemModel* model)
: DownloadShelfContextMenu(model) {
@@ -85,9 +84,9 @@ class DownloadShelfContextMenuWin : public DownloadShelfContextMenu,
void Run(const gfx::Point& point) {
if (download_->state() == DownloadItem::COMPLETE)
- menu_.reset(new views::Menu2(GetFinishedMenuModel(this)));
+ menu_.reset(new views::Menu2(GetFinishedMenuModel()));
else
- menu_.reset(new views::Menu2(GetInProgressMenuModel(this)));
+ menu_.reset(new views::Menu2(GetInProgressMenuModel()));
// The menu's alignment is determined based on the UI layout.
views::Menu2::Alignment alignment;
@@ -102,41 +101,6 @@ class DownloadShelfContextMenuWin : public DownloadShelfContextMenu,
// to access |download_|.
void Stop() {
download_ = NULL;
- model_ = NULL;
- }
-
- // Overriden from menus::SimpleMenuModel::Delegate:
-
- virtual bool IsCommandIdChecked(int command_id) const {
- if (!download_)
- return false;
- return ItemIsChecked(command_id);
- }
-
- virtual bool IsCommandIdEnabled(int command_id) const {
- if (!download_)
- return false;
- return IsItemCommandEnabled(command_id);
- }
-
- virtual bool GetAcceleratorForCommandId(
- int command_id,
- menus::Accelerator* accelerator) {
- return false;
- }
-
- bool IsLabelForCommandIdDynamic(int command_id) const {
- return command_id == TOGGLE_PAUSE;
- }
-
- string16 GetLabelForCommandId(int command_id) const {
- DCHECK(command_id == TOGGLE_PAUSE);
- return WideToUTF16(GetItemLabel(command_id));
- }
-
- virtual void ExecuteCommand(int command_id) {
- if (download_)
- ExecuteItemCommand(command_id);
}
private: