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

Unified Diff: chrome/browser/ui/views/wrench_menu.h

Issue 26350003: OLD: reland "views: change WrenchMenu to use each model's command ID's when creating MenuItemView's" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix integer overflow w/ kint32max, add test Created 7 years, 2 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/ui/views/wrench_menu.h
diff --git a/chrome/browser/ui/views/wrench_menu.h b/chrome/browser/ui/views/wrench_menu.h
index 44613be2ebf90da6962c8d98b608babbf08aace2..ca0d62832738e2e92fd142873de6861a0fc0468c 100644
--- a/chrome/browser/ui/views/wrench_menu.h
+++ b/chrome/browser/ui/views/wrench_menu.h
@@ -59,11 +59,12 @@ class WrenchMenu : public views::MenuDelegate,
void RemoveObserver(WrenchMenuObserver* observer);
// MenuDelegate overrides:
- virtual const gfx::Font* GetLabelFont(int index) const OVERRIDE;
+ virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE;
virtual bool GetForegroundColor(int command_id,
bool is_hovered,
SkColor* override_color) const OVERRIDE;
- virtual string16 GetTooltipText(int id, const gfx::Point& p) const OVERRIDE;
+ virtual string16 GetTooltipText(int command_id,
+ const gfx::Point& p) const OVERRIDE;
virtual bool IsTriggerableEvent(views::MenuItemView* menu,
const ui::Event& e) OVERRIDE;
virtual bool GetDropFormats(
@@ -80,7 +81,7 @@ class WrenchMenu : public views::MenuDelegate,
DropPosition position,
const ui::DropTargetEvent& event) OVERRIDE;
virtual bool ShowContextMenu(views::MenuItemView* source,
- int id,
+ int command_id,
const gfx::Point& p,
ui::MenuSourceType source_type) OVERRIDE;
virtual bool CanDrag(views::MenuItemView* menu) OVERRIDE;
@@ -88,10 +89,11 @@ class WrenchMenu : public views::MenuDelegate,
ui::OSExchangeData* data) OVERRIDE;
virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE;
virtual int GetMaxWidthForMenu(views::MenuItemView* menu) OVERRIDE;
- virtual bool IsItemChecked(int id) const OVERRIDE;
- virtual bool IsCommandEnabled(int id) const OVERRIDE;
- virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE;
- virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE;
+ virtual bool IsItemChecked(int command_id) const OVERRIDE;
+ virtual bool IsCommandEnabled(int command_id) const OVERRIDE;
+ virtual void ExecuteCommand(int command_id, int mouse_event_flags) OVERRIDE;
+ virtual bool GetAccelerator(int command_id,
+ ui::Accelerator* accelerator) OVERRIDE;
virtual void WillShowMenu(views::MenuItemView* menu) OVERRIDE;
virtual void WillHideMenu(views::MenuItemView* menu) OVERRIDE;
@@ -109,26 +111,24 @@ class WrenchMenu : public views::MenuDelegate,
class ZoomView;
typedef std::pair<ui::MenuModel*,int> Entry;
- typedef std::map<int,Entry> IDToEntry;
+ typedef std::map<int,Entry> CommandIDToEntry;
const ui::NativeTheme* GetNativeTheme() const;
// 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.
+ // |PopulateMenu| for any submenu.
void PopulateMenu(views::MenuItemView* parent,
- ui::MenuModel* model,
- int* next_id);
+ ui::MenuModel* model);
// Adds a new menu to |parent| to represent the MenuModel/index pair passed
- // in.
+ // in. The returned item's MenuItemView::GetCommand() is the same as that of
+ // |model|->GetCommandIdAt(|index|).
// Fur button containing menu items a |height| override can be specified with
// a number bigger then 0.
views::MenuItemView* AppendMenuItem(views::MenuItemView* parent,
ui::MenuModel* model,
int index,
ui::MenuModel::ItemType menu_type,
- int* next_id,
int height);
// Invoked from the cut/copy/paste menus. Cancels the current active menu and
@@ -139,26 +139,18 @@ class WrenchMenu : public views::MenuDelegate,
// the bookmark model isn't loaded.
void CreateBookmarkMenu();
- // Returns true if |id| identifies a bookmark menu item.
- bool is_bookmark_command(int id) const {
- return bookmark_menu_delegate_.get() && id >= first_bookmark_command_id_;
- }
-
- // Returns true if |id| identifies a recent tabs menu item.
- bool is_recent_tabs_command(int id) const {
- return (recent_tabs_menu_model_delegate_.get() &&
- id >= first_recent_tabs_command_id_ &&
- id <= last_recent_tabs_command_id_);
- }
+ // Returns the index of the MenuModel/index pair representing the |command_id|
+ // in |command_id_to_entry_|.
+ int ModelIndexFromCommandId(int command_id) const;
// The views menu. Owned by |menu_runner_|.
views::MenuItemView* root_;
scoped_ptr<views::MenuRunner> menu_runner_;
- // Maps from the ID as understood by MenuItemView to the model/index pair the
- // item came from.
- IDToEntry id_to_entry_;
+ // Maps from the command ID in model to the model/index pair the item came
+ // from.
+ CommandIDToEntry command_id_to_entry_;
// Browser the menu is being shown for.
Browser* browser_;
@@ -182,13 +174,6 @@ class WrenchMenu : public views::MenuDelegate,
// Used for managing "Recent tabs" menu items.
scoped_ptr<RecentTabsMenuModelDelegate> recent_tabs_menu_model_delegate_;
- // First ID to use for the items representing bookmarks in the bookmark menu.
- int first_bookmark_command_id_;
-
- // First/last IDs to use for the items of the recent tabs sub-menu.
- int first_recent_tabs_command_id_;
- int last_recent_tabs_command_id_;
-
content::NotificationRegistrar registrar_;
const bool use_new_menu_;

Powered by Google App Engine
This is Rietveld 408576698