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

Side by Side Diff: chrome/browser/ui/views/wrench_menu.h

Issue 7054020: Refactors code for showing bookmark menus so that it can be used by (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_
6 #define CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ 6 #define CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
14 #include "ui/base/models/menu_model.h" 15 #include "ui/base/models/menu_model.h"
15 #include "views/controls/menu/menu_delegate.h" 16 #include "views/controls/menu/menu_delegate.h"
16 17
18 class BookmarkMenuDelegate;
17 class Browser; 19 class Browser;
18 20
19 namespace views { 21 namespace views {
20 class MenuButton; 22 class MenuButton;
21 class MenuItemView; 23 class MenuItemView;
22 class View; 24 class View;
23 } // namespace views 25 } // namespace views
24 26
25 // WrenchMenu adapts the WrenchMenuModel to view's menu related classes. 27 // WrenchMenu adapts the WrenchMenuModel to view's menu related classes.
26 class WrenchMenu : public base::RefCounted<WrenchMenu>, 28 class WrenchMenu : public base::RefCounted<WrenchMenu>,
27 public views::MenuDelegate { 29 public views::MenuDelegate,
30 public BaseBookmarkModelObserver {
28 public: 31 public:
29 explicit WrenchMenu(Browser* browser); 32 explicit WrenchMenu(Browser* browser);
30 33
31 void Init(ui::MenuModel* model); 34 void Init(ui::MenuModel* model);
32 35
33 // Shows the menu relative to the specified view. 36 // Shows the menu relative to the specified view.
34 void RunMenu(views::MenuButton* host); 37 void RunMenu(views::MenuButton* host);
35 38
36 // MenuDelegate overrides: 39 // MenuDelegate overrides:
37 virtual bool IsItemChecked(int id) const; 40 virtual std::wstring GetTooltipText(int id, const gfx::Point& p) OVERRIDE;
38 virtual bool IsCommandEnabled(int id) const; 41 virtual bool IsTriggerableEvent(views::MenuItemView* menu,
39 virtual void ExecuteCommand(int id); 42 const views::MouseEvent& e) OVERRIDE;
40 virtual bool GetAccelerator(int id, views::Accelerator* accelerator); 43 virtual bool GetDropFormats(
44 views::MenuItemView* menu,
45 int* formats,
46 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
47 virtual bool AreDropTypesRequired(views::MenuItemView* menu) OVERRIDE;
48 virtual bool CanDrop(views::MenuItemView* menu,
49 const ui::OSExchangeData& data) OVERRIDE;
50 virtual int GetDropOperation(views::MenuItemView* item,
51 const views::DropTargetEvent& event,
52 DropPosition* position) OVERRIDE;
53 virtual int OnPerformDrop(views::MenuItemView* menu,
54 DropPosition position,
55 const views::DropTargetEvent& event) OVERRIDE;
56 virtual bool ShowContextMenu(views::MenuItemView* source,
57 int id,
58 const gfx::Point& p,
59 bool is_mouse_gesture) OVERRIDE;
60 virtual bool CanDrag(views::MenuItemView* menu) OVERRIDE;
61 virtual void WriteDragData(views::MenuItemView* sender,
62 ui::OSExchangeData* data) OVERRIDE;
63 virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE;
64 virtual int GetMaxWidthForMenu(views::MenuItemView* menu) OVERRIDE;
65 virtual bool IsItemChecked(int id) const OVERRIDE;
66 virtual bool IsCommandEnabled(int id) const OVERRIDE;
67 virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE;
68 virtual bool GetAccelerator(int id, views::Accelerator* accelerator) OVERRIDE;
69 virtual void WillShowMenu(views::MenuItemView* menu) OVERRIDE;
70
71 // BaseBookmarkModelObserver overrides:
72 virtual void BookmarkModelChanged() OVERRIDE;
41 73
42 private: 74 private:
43 friend class base::RefCounted<WrenchMenu>; 75 friend class base::RefCounted<WrenchMenu>;
44 76
45 class CutCopyPasteView; 77 class CutCopyPasteView;
46 class ZoomView; 78 class ZoomView;
47 79
48 typedef std::pair<ui::MenuModel*,int> Entry; 80 typedef std::pair<ui::MenuModel*,int> Entry;
49 typedef std::map<int,Entry> IDToEntry; 81 typedef std::map<int,Entry> IDToEntry;
50 82
(...skipping 11 matching lines...) Expand all
62 views::MenuItemView* AppendMenuItem(views::MenuItemView* parent, 94 views::MenuItemView* AppendMenuItem(views::MenuItemView* parent,
63 ui::MenuModel* model, 95 ui::MenuModel* model,
64 int index, 96 int index,
65 ui::MenuModel::ItemType menu_type, 97 ui::MenuModel::ItemType menu_type,
66 int* next_id); 98 int* next_id);
67 99
68 // Invoked from the cut/copy/paste menus. Cancels the current active menu and 100 // Invoked from the cut/copy/paste menus. Cancels the current active menu and
69 // activates the menu item in |model| at |index|. 101 // activates the menu item in |model| at |index|.
70 void CancelAndEvaluate(ui::MenuModel* model, int index); 102 void CancelAndEvaluate(ui::MenuModel* model, int index);
71 103
104 // Creates the bookmark menu if necessary. Does nothing if already created or
105 // the bookmark model isn't loaded.
106 void CreateBookmarkMenu();
107
108 // Returns true if |id| identifies a bookmark menu item.
109 bool is_bookmark_command(int id) const {
110 return bookmark_menu_delegate_.get() && id >= first_bookmark_command_id_;
111 }
112
72 // The views menu. 113 // The views menu.
73 scoped_ptr<views::MenuItemView> root_; 114 scoped_ptr<views::MenuItemView> root_;
74 115
75 // Maps from the ID as understood by MenuItemView to the model/index pair the 116 // Maps from the ID as understood by MenuItemView to the model/index pair the
76 // item came from. 117 // item came from.
77 IDToEntry id_to_entry_; 118 IDToEntry id_to_entry_;
78 119
79 // Browser the menu is being shown for. 120 // Browser the menu is being shown for.
80 Browser* browser_; 121 Browser* browser_;
81 122
82 // |CancelAndEvaluate| sets |selected_menu_model_| and |selected_index_|. 123 // |CancelAndEvaluate| sets |selected_menu_model_| and |selected_index_|.
83 // If |selected_menu_model_| is non-null after the menu completes 124 // If |selected_menu_model_| is non-null after the menu completes
84 // ActivatedAt is invoked. This is done so that ActivatedAt isn't invoked 125 // ActivatedAt is invoked. This is done so that ActivatedAt isn't invoked
85 // while the message loop is nested. 126 // while the message loop is nested.
86 ui::MenuModel* selected_menu_model_; 127 ui::MenuModel* selected_menu_model_;
87 int selected_index_; 128 int selected_index_;
88 129
130 // Used for managing the bookmark menu items.
131 scoped_ptr<BookmarkMenuDelegate> bookmark_menu_delegate_;
132
133 // Menu corresponding to IDC_BOOKMARKS_MENU.
134 views::MenuItemView* bookmark_menu_;
135
136 // ID to use for the items representing bookmarks in the bookmark menu.
137 int first_bookmark_command_id_;
138
89 DISALLOW_COPY_AND_ASSIGN(WrenchMenu); 139 DISALLOW_COPY_AND_ASSIGN(WrenchMenu);
90 }; 140 };
91 141
92 #endif // CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ 142 #endif // CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc ('k') | chrome/browser/ui/views/wrench_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698