diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-12 20:44:28 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-12 20:44:28 +0000 |
commit | cdb4266b62202b44eb1fb36877398c2cb5504917 (patch) | |
tree | 60f5de9c0460d67cd7150ba5f2e33499892c38b2 /chrome/browser/tab_contents | |
parent | f148ed7a47e14416efd1cc2666ea331fbcf5aa42 (diff) | |
download | chromium_src-cdb4266b62202b44eb1fb36877398c2cb5504917.zip chromium_src-cdb4266b62202b44eb1fb36877398c2cb5504917.tar.gz chromium_src-cdb4266b62202b44eb1fb36877398c2cb5504917.tar.bz2 |
Remove the Menu object, converting all the remaining callers to use Menu2. I'll rename Menu2->Menu afterwards.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/122027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
6 files changed, 113 insertions, 98 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu_external_win.cc b/chrome/browser/tab_contents/render_view_context_menu_external_win.cc index 0c19f94..a9667c9 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_external_win.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_external_win.cc @@ -9,9 +9,8 @@ RenderViewContextMenuExternalWin::RenderViewContextMenuExternalWin( TabContents* tab_contents, const ContextMenuParams& params, - HWND owner, const std::vector<int> disabled_ids) - : RenderViewContextMenuWin(tab_contents, params, owner), + : RenderViewContextMenuWin(tab_contents, params), disabled_menu_ids_(disabled_ids) { } diff --git a/chrome/browser/tab_contents/render_view_context_menu_external_win.h b/chrome/browser/tab_contents/render_view_context_menu_external_win.h index 3c31e44..0bd6f24 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_external_win.h +++ b/chrome/browser/tab_contents/render_view_context_menu_external_win.h @@ -15,7 +15,6 @@ class RenderViewContextMenuExternalWin : public RenderViewContextMenuWin { public: RenderViewContextMenuExternalWin(TabContents* tab_contents, const ContextMenuParams& params, - HWND window, const std::vector<int> disabled_menu_ids); ~RenderViewContextMenuExternalWin() {} diff --git a/chrome/browser/tab_contents/render_view_context_menu_win.cc b/chrome/browser/tab_contents/render_view_context_menu_win.cc index 952993f..66a923c 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_win.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_win.cc @@ -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); -} - -void RenderViewContextMenuWin::AppendMenuItem(int id) { - AppendItem(id, l10n_util::GetString(id), views::Menu::NORMAL); -} - -void RenderViewContextMenuWin::AppendMenuItem(int id, - const std::wstring& label) { - AppendItem(id, label, views::Menu::NORMAL); -} - -void RenderViewContextMenuWin::AppendRadioMenuItem(int id, - const std::wstring& label) { - AppendItem(id, label, views::Menu::RADIO); -} - -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); + menu_->RunContextMenuAt(gfx::Point(x, y)); } -bool RenderViewContextMenuWin::IsCommandEnabled(int id) const { - return IsItemCommandEnabled(id); -} +//////////////////////////////////////////////////////////////////////////////// +// RenderViewContextMenuWin, views::SimpleMenuModel::Delegate implementation: -bool RenderViewContextMenuWin::IsItemChecked(int id) const { - return ItemIsChecked(id); +bool RenderViewContextMenuWin::IsCommandIdChecked(int command_id) const { + return ItemIsChecked(command_id); } -void RenderViewContextMenuWin::ExecuteCommand(int id) { - ExecuteItemCommand(id); +bool RenderViewContextMenuWin::IsCommandIdEnabled(int command_id) const { + return IsItemCommandEnabled(command_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 @@ bool RenderViewContextMenuWin::GetAcceleratorInfo( 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(); +} diff --git a/chrome/browser/tab_contents/render_view_context_menu_win.h b/chrome/browser/tab_contents/render_view_context_menu_win.h index 3488d59..e188533 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_win.h +++ b/chrome/browser/tab_contents/render_view_context_menu_win.h @@ -6,34 +6,30 @@ #define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_WIN_H_ #include "base/scoped_ptr.h" +#include "base/scoped_vector.h" #include "chrome/browser/tab_contents/render_view_context_menu.h" #include "views/accelerator.h" -#include "views/controls/menu/menu_win.h" +#include "views/controls/menu/simple_menu_model.h" class RenderViewContextMenuWin : public RenderViewContextMenu, - public views::Menu::Delegate { + public views::SimpleMenuModel::Delegate { public: RenderViewContextMenuWin(TabContents* tab_contents, - const ContextMenuParams& params, - HWND window); + const ContextMenuParams& params); ~RenderViewContextMenuWin(); void RunMenuAt(int x, int y); - // Menu::Delegate implementation --------------------------------------------- - virtual bool IsCommandEnabled(int id) const; - virtual bool IsItemChecked(int id) const; - virtual void ExecuteCommand(int id); - // TODO(port): move the logic in this function to RenderViewContextMenu. - virtual bool GetAcceleratorInfo(int id, views::Accelerator* accel); + // Overridden from SimpleMenuModel::Delegate: + virtual bool IsCommandIdChecked(int command_id) const; + virtual bool IsCommandIdEnabled(int command_id) const; + virtual bool GetAcceleratorForCommandId(int command_id, + views::Accelerator* accelerator); + virtual void ExecuteCommand(int command_id); HMENU GetMenuHandle() const { - return (menu_.get() ? menu_->GetMenuHandle() : NULL); - } - - unsigned int GetTPMAlignFlags() const { - return (menu_.get() ? menu_->GetTPMAlignFlags() : 0); + return (menu_.get() ? menu_->GetNativeMenu() : NULL); } protected: @@ -47,13 +43,21 @@ class RenderViewContextMenuWin : public RenderViewContextMenu, virtual void FinishSubMenu(); private: - // Append the item to |sub_menu_| if it exists, or |menu_| otherwise. - void AppendItem(int id, - const std::wstring& label, - views::Menu::MenuItemType type); + // Gets the target model to append items to. This is either the main context + // menu, or a submenu if we've descended into one. + views::SimpleMenuModel* GetTargetModel() const; + + // The current radio group for radio menu items. + int current_radio_group_id_; - scoped_ptr<views::MenuWin> menu_; - views::Menu* sub_menu_; + // The context menu itself and its contents. + scoped_ptr<views::SimpleMenuModel> menu_contents_; + scoped_ptr<views::Menu2> menu_; + // TODO(beng): This way of building submenus is kind of retarded, but it + // hasn't hurt us yet. It's just a bit awkward. + views::SimpleMenuModel* sub_menu_contents_; + // We own submenu models that we create, so we store them here. + ScopedVector<views::SimpleMenuModel> submenu_models_; HWND owner_; }; diff --git a/chrome/browser/tab_contents/tab_contents_view_win.cc b/chrome/browser/tab_contents/tab_contents_view_win.cc index 341eb50..9452737 100644 --- a/chrome/browser/tab_contents/tab_contents_view_win.cc +++ b/chrome/browser/tab_contents/tab_contents_view_win.cc @@ -394,15 +394,10 @@ void TabContentsViewWin::HandleKeyboardEvent( void TabContentsViewWin::ShowContextMenu(const ContextMenuParams& params) { // Allow delegates to handle the context menu operation first. - if (tab_contents()->delegate()->HandleContextMenu(params)) { + if (tab_contents()->delegate()->HandleContextMenu(params)) return; - } - - RenderViewContextMenuWin menu(tab_contents(), - params, - GetNativeView()); - menu.Init(); + context_menu_.reset(new RenderViewContextMenuWin(tab_contents(), params)); POINT screen_pt = { params.x, params.y }; MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1); @@ -411,7 +406,7 @@ void TabContentsViewWin::ShowContextMenu(const ContextMenuParams& params) { // the context menu is being displayed. bool old_state = MessageLoop::current()->NestableTasksAllowed(); MessageLoop::current()->SetNestableTasksAllowed(true); - menu.RunMenuAt(screen_pt.x, screen_pt.y); + context_menu_->RunMenuAt(screen_pt.x, screen_pt.y); MessageLoop::current()->SetNestableTasksAllowed(old_state); } diff --git a/chrome/browser/tab_contents/tab_contents_view_win.h b/chrome/browser/tab_contents/tab_contents_view_win.h index 07bd545..6af85a1 100644 --- a/chrome/browser/tab_contents/tab_contents_view_win.h +++ b/chrome/browser/tab_contents/tab_contents_view_win.h @@ -10,11 +10,11 @@ #include "chrome/browser/tab_contents/tab_contents_view.h" #include "views/widget/widget_win.h" +class RenderViewContextMenuWin; class SadTabView; struct WebDropData; class WebDropTarget; - // Windows-specific implementation of the TabContentsView. It is a HWND that // contains all of the contents of the tab and associated child views. class TabContentsViewWin : public TabContentsView, @@ -101,6 +101,9 @@ class TabContentsViewWin : public TabContentsView, // The id used in the ViewStorage to store the last focused view. int last_focused_view_storage_id_; + // The context menu. Callbacks are asynchronous so we need to keep it around. + scoped_ptr<RenderViewContextMenuWin> context_menu_; + DISALLOW_COPY_AND_ASSIGN(TabContentsViewWin); }; |