Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4792)

Unified Diff: chrome/browser/tab_contents/render_view_context_menu_win.cc

Issue 122027: Remove the Menu object, converting all the remaining callers to use Menu2. I'... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/tab_contents/render_view_context_menu_win.cc
===================================================================
--- chrome/browser/tab_contents/render_view_context_menu_win.cc (revision 18306)
+++ chrome/browser/tab_contents/render_view_context_menu_win.cc (working copy)
@@ -9,90 +9,44 @@
#include "chrome/browser/profile.h"
#include "grit/generated_resources.h"
+////////////////////////////////////////////////////////////////////////////////
+// RenderViewContextMenuWin, public:
+
RenderViewContextMenuWin::RenderViewContextMenuWin(
TabContents* tab_contents,
- const ContextMenuParams& params,
- HWND owner)
+ const ContextMenuParams& params)
: RenderViewContextMenu(tab_contents, params),
- sub_menu_(NULL),
- owner_(owner) {
- // anchor_position set per http://crbug.com/10827.
- views::Menu::AnchorPoint anchor_position = views::Menu::TOPLEFT;
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
- anchor_position = views::Menu::TOPRIGHT;
- menu_.reset(new views::MenuWin(this, anchor_position, owner_));
+ current_radio_group_id_(-1),
+ sub_menu_contents_(NULL) {
+ menu_contents_.reset(new views::SimpleMenuModel(this));
+ InitMenu(params.node);
+ menu_.reset(new views::Menu2(menu_contents_.get()));
}
RenderViewContextMenuWin::~RenderViewContextMenuWin() {
}
void RenderViewContextMenuWin::RunMenuAt(int x, int y) {
- menu_->RunMenuAt(x, y);
+ menu_->RunContextMenuAt(gfx::Point(x, y));
}
-void RenderViewContextMenuWin::AppendMenuItem(int id) {
- AppendItem(id, l10n_util::GetString(id), views::Menu::NORMAL);
-}
+////////////////////////////////////////////////////////////////////////////////
+// RenderViewContextMenuWin, views::SimpleMenuModel::Delegate implementation:
-void RenderViewContextMenuWin::AppendMenuItem(int id,
- const std::wstring& label) {
- AppendItem(id, label, views::Menu::NORMAL);
+bool RenderViewContextMenuWin::IsCommandIdChecked(int command_id) const {
+ return ItemIsChecked(command_id);
}
-void RenderViewContextMenuWin::AppendRadioMenuItem(int id,
- const std::wstring& label) {
- AppendItem(id, label, views::Menu::RADIO);
+bool RenderViewContextMenuWin::IsCommandIdEnabled(int command_id) const {
+ return IsItemCommandEnabled(command_id);
}
-void RenderViewContextMenuWin::AppendCheckboxMenuItem(int id,
- const std::wstring& label) {
- AppendItem(id, label, views::Menu::CHECKBOX);
-}
-
-void RenderViewContextMenuWin::AppendSeparator() {
- views::Menu* menu = sub_menu_ ? sub_menu_ : menu_.get();
- menu->AppendSeparator();
-}
-
-void RenderViewContextMenuWin::StartSubMenu(int id, const std::wstring& label) {
- if (sub_menu_) {
- NOTREACHED();
- return;
- }
- sub_menu_ = menu_->AppendSubMenu(id, label);
-}
-
-void RenderViewContextMenuWin::FinishSubMenu() {
- DCHECK(sub_menu_);
- sub_menu_ = NULL;
-}
-
-void RenderViewContextMenuWin::AppendItem(
- int id,
- const std::wstring& label,
- views::Menu::MenuItemType type) {
- views::Menu* menu = sub_menu_ ? sub_menu_ : menu_.get();
- menu->AppendMenuItem(id, label, type);
-}
-
-bool RenderViewContextMenuWin::IsCommandEnabled(int id) const {
- return IsItemCommandEnabled(id);
-}
-
-bool RenderViewContextMenuWin::IsItemChecked(int id) const {
- return ItemIsChecked(id);
-}
-
-void RenderViewContextMenuWin::ExecuteCommand(int id) {
- ExecuteItemCommand(id);
-}
-
-bool RenderViewContextMenuWin::GetAcceleratorInfo(
- int id,
+bool RenderViewContextMenuWin::GetAcceleratorForCommandId(
+ int command_id,
views::Accelerator* accel) {
// There are no formally defined accelerators we can query so we assume
// that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do.
- switch (id) {
+ switch (command_id) {
case IDS_CONTENT_CONTEXT_UNDO:
*accel = views::Accelerator(L'Z', false, true, false);
return true;
@@ -121,3 +75,64 @@
return false;
}
}
+
+void RenderViewContextMenuWin::ExecuteCommand(int command_id) {
+ ExecuteItemCommand(command_id);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// RenderViewContextMenuWin, protected:
+
+void RenderViewContextMenuWin::AppendMenuItem(int id) {
+ current_radio_group_id_ = -1;
+ GetTargetModel()->AddItemWithStringId(id, id);
+}
+
+void RenderViewContextMenuWin::AppendMenuItem(int id,
+ const std::wstring& label) {
+ current_radio_group_id_ = -1;
+ GetTargetModel()->AddItem(id, label);
+}
+
+void RenderViewContextMenuWin::AppendRadioMenuItem(int id,
+ const std::wstring& label) {
+ if (current_radio_group_id_ < 0)
+ current_radio_group_id_ = id;
+ GetTargetModel()->AddRadioItem(id, label, current_radio_group_id_);
+}
+
+void RenderViewContextMenuWin::AppendCheckboxMenuItem(
+ int id,
+ const std::wstring& label) {
+ current_radio_group_id_ = -1;
+ GetTargetModel()->AddCheckItem(id, label);
+}
+
+void RenderViewContextMenuWin::AppendSeparator() {
+ current_radio_group_id_ = -1;
+ GetTargetModel()->AddSeparator();
+}
+
+void RenderViewContextMenuWin::StartSubMenu(int id, const std::wstring& label) {
+ if (sub_menu_contents_) {
+ NOTREACHED() << "nested submenus not supported yet";
+ return;
+ }
+ current_radio_group_id_ = -1;
+ sub_menu_contents_ = new views::SimpleMenuModel(this);
+ menu_contents_->AddSubMenu(label, sub_menu_contents_);
+ submenu_models_.push_back(sub_menu_contents_);
+}
+
+void RenderViewContextMenuWin::FinishSubMenu() {
+ DCHECK(sub_menu_contents_);
+ current_radio_group_id_ = -1;
+ sub_menu_contents_ = NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// RenderViewContextMenuWin, private:
+
+views::SimpleMenuModel* RenderViewContextMenuWin::GetTargetModel() const {
+ return sub_menu_contents_ ? sub_menu_contents_ : menu_contents_.get();
+}
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu_win.h ('k') | chrome/browser/tab_contents/tab_contents_view_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698