diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-09 07:35:32 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-09 07:35:32 +0000 |
commit | 213dac2f0bff9162502fe325b6ebb85a255efcb2 (patch) | |
tree | 3640cb1f19976e38677b8632537d2d41f8444d0f /chrome/browser/ui/views/wrench_menu.h | |
parent | 6de53d401aa8dc6c7e0a9874c71a95ce88ade50d (diff) | |
download | chromium_src-213dac2f0bff9162502fe325b6ebb85a255efcb2.zip chromium_src-213dac2f0bff9162502fe325b6ebb85a255efcb2.tar.gz chromium_src-213dac2f0bff9162502fe325b6ebb85a255efcb2.tar.bz2 |
Move browser/views to browser/ui/views
TBR=brettw
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/4694005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65508 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/views/wrench_menu.h')
-rw-r--r-- | chrome/browser/ui/views/wrench_menu.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/chrome/browser/ui/views/wrench_menu.h b/chrome/browser/ui/views/wrench_menu.h new file mode 100644 index 0000000..6efaaa8 --- /dev/null +++ b/chrome/browser/ui/views/wrench_menu.h @@ -0,0 +1,92 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ +#define CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ +#pragma once + +#include <map> +#include <utility> + +#include "app/menus/menu_model.h" +#include "base/ref_counted.h" +#include "base/scoped_ptr.h" +#include "views/controls/menu/menu_delegate.h" + +class Browser; + +namespace views { +class MenuButton; +class MenuItemView; +class View; +} // namespace views + +// WrenchMenu adapts the WrenchMenuModel to view's menu related classes. +class WrenchMenu : public base::RefCounted<WrenchMenu>, + public views::MenuDelegate { + public: + explicit WrenchMenu(Browser* browser); + + void Init(menus::MenuModel* model); + + // Shows the menu relative to the specified view. + void RunMenu(views::MenuButton* host); + + // MenuDelegate overrides: + virtual bool IsItemChecked(int id) const; + virtual bool IsCommandEnabled(int id) const; + virtual void ExecuteCommand(int id); + virtual bool GetAccelerator(int id, views::Accelerator* accelerator); + + private: + friend class base::RefCounted<WrenchMenu>; + + class CutCopyPasteView; + class ZoomView; + + typedef std::pair<menus::MenuModel*,int> Entry; + typedef std::map<int,Entry> IDToEntry; + + ~WrenchMenu(); + + // Populates |parent| with all the child menus in |model|. Recursively invokes + // |PopulateMenu| for any submenu. |next_id| is incremented for every menu + // that is created. + void PopulateMenu(views::MenuItemView* parent, + menus::MenuModel* model, + int* next_id); + + // Adds a new menu to |parent| to represent the MenuModel/index pair passed + // in. + views::MenuItemView* AppendMenuItem(views::MenuItemView* parent, + menus::MenuModel* model, + int index, + menus::MenuModel::ItemType menu_type, + int* next_id); + + // Invoked from the cut/copy/paste menus. Cancels the current active menu and + // activates the menu item in |model| at |index|. + void CancelAndEvaluate(menus::MenuModel* model, int index); + + // The views menu. + scoped_ptr<views::MenuItemView> root_; + + // Maps from the ID as understood by MenuItemView to the model/index pair the + // item came from. + IDToEntry id_to_entry_; + + // Browser the menu is being shown for. + Browser* browser_; + + // |CancelAndEvaluate| sets |selected_menu_model_| and |selected_index_|. + // If |selected_menu_model_| is non-null after the menu completes + // ActivatedAt is invoked. This is done so that ActivatedAt isn't invoked + // while the message loop is nested. + menus::MenuModel* selected_menu_model_; + int selected_index_; + + DISALLOW_COPY_AND_ASSIGN(WrenchMenu); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ |