summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 00:43:44 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 00:43:44 +0000
commit8e3a815d1cf67f0e14a1b33431c9c9961b43fa79 (patch)
tree7947a494bc26dff0213b2b44cbbed131bb08e04f /chrome/browser/views
parent94f923b86617c2c6e7fda321256a7523096e3c51 (diff)
downloadchromium_src-8e3a815d1cf67f0e14a1b33431c9c9961b43fa79.zip
chromium_src-8e3a815d1cf67f0e14a1b33431c9c9961b43fa79.tar.gz
chromium_src-8e3a815d1cf67f0e14a1b33431c9c9961b43fa79.tar.bz2
Refactor the download shelf context menu in preparation for porting.
* Delete DownloadDestinationContextMenu, which is not used anywhere. * Delete the unused download menu item types from the ContextMenuCommands enum. * Merge BaseContextMenu and DownloadShelfContextMenu, move them from download_util.{h,cc} to download_shelf.{h,cc} * Take the windows-specific code from the new DownloadShelfContextMenu and put it in DownloadShelfContextMenuWin in download_item_view.cc (the only place it's used). DownloadShelfContextMenuWin extends DownloadShelfContextMenu and Menu::Delegate. Review URL: http://codereview.chromium.org/40184 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11068 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/download_item_view.cc67
1 files changed, 63 insertions, 4 deletions
diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc
index 8b08a3f..a0f83ec 100644
--- a/chrome/browser/views/download_item_view.cc
+++ b/chrome/browser/views/download_item_view.cc
@@ -17,6 +17,7 @@
#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/common/win_util.h"
+#include "chrome/views/menu.h"
#include "chrome/views/native_button.h"
#include "chrome/views/root_view.h"
#include "chrome/views/widget.h"
@@ -56,6 +57,65 @@ static const SkColor kStatusColor = SkColorSetRGB(123, 141, 174);
// How long the 'download complete' animation should last for.
static const int kCompleteAnimationDurationMs = 2500;
+// DownloadShelfContextMenuWin -------------------------------------------------
+
+class DownloadShelfContextMenuWin : public DownloadShelfContextMenu,
+ public Menu::Delegate {
+ public:
+ DownloadShelfContextMenuWin::DownloadShelfContextMenuWin(
+ BaseDownloadItemModel* model,
+ HWND window,
+ const gfx::Point& point)
+ : DownloadShelfContextMenu(model) {
+ DCHECK(model);
+
+ // The menu's anchor point is determined based on the UI layout.
+ Menu::AnchorPoint anchor_point;
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
+ anchor_point = Menu::TOPRIGHT;
+ else
+ anchor_point = Menu::TOPLEFT;
+
+ Menu context_menu(this, anchor_point, window);
+ if (download_->state() == DownloadItem::COMPLETE)
+ context_menu.AppendMenuItem(OPEN_WHEN_COMPLETE, L"", Menu::NORMAL);
+ else
+ context_menu.AppendMenuItem(OPEN_WHEN_COMPLETE, L"", Menu::CHECKBOX);
+ context_menu.AppendMenuItem(ALWAYS_OPEN_TYPE, L"", Menu::CHECKBOX);
+ context_menu.AppendSeparator();
+ context_menu.AppendMenuItem(SHOW_IN_FOLDER, L"", Menu::NORMAL);
+ context_menu.AppendSeparator();
+ context_menu.AppendMenuItem(CANCEL, L"", Menu::NORMAL);
+ context_menu.RunMenuAt(point.x(), point.y());
+ }
+
+ // Menu::Delegate implementation ---------------------------------------------
+
+ virtual bool IsItemChecked(int id) const {
+ return ItemIsChecked(id);
+ }
+
+ virtual bool IsItemDefault(int id) const {
+ return ItemIsDefault(id);
+ }
+
+ virtual std::wstring GetLabel(int id) const {
+ return GetItemLabel(id);
+ }
+
+ virtual bool SupportsCommand(int id) const {
+ return id > 0 && id < MENU_LAST;
+ }
+
+ virtual bool IsCommandEnabled(int id) const {
+ return IsItemCommandEnabled(id);
+ }
+
+ virtual void ExecuteCommand(int id) {
+ return ExecuteItemCommand(id);
+ }
+};
+
// DownloadItemView ------------------------------------------------------------
DownloadItemView::DownloadItemView(DownloadItem* download,
@@ -658,10 +718,9 @@ bool DownloadItemView::OnMousePressed(const views::MouseEvent& event) {
}
views::View::ConvertPointToScreen(this, &point);
- download_util::DownloadShelfContextMenu menu(download_,
- GetWidget()->GetHWND(),
- model_.get(),
- point.ToPOINT());
+ DownloadShelfContextMenuWin menu(model_.get(),
+ GetWidget()->GetHWND(),
+ point);
drop_down_pressed_ = false;
// Showing the menu blocks. Here we revert the state.
SetState(NORMAL, NORMAL);