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

Side by Side Diff: views/controls/menu/menu_model_adapter.h

Issue 7067032: Add MenuModelAdapter to wrap ui::MenuModel with views::MenuDelegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implemented reviewer recommendations. 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
« no previous file with comments | « views/controls/menu/menu_item_view.cc ('k') | views/controls/menu/menu_model_adapter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef VIEWS_CONTROLS_MENU_MENU_MODEL_ADAPTER_H_
6 #define VIEWS_CONTROLS_MENU_MENU_MODEL_ADAPTER_H_
7 #pragma once
8
9 #include <map>
10
11 #include "views/controls/menu/menu_delegate.h"
12
13 namespace ui {
14 class MenuModel;
15 }
16
17 namespace views {
18 class MenuItemView;
19
20 // This class wraps an instance of ui::MenuModel with the
21 // views::MenuDelegate interface required by views::MenuItemView.
22 class MenuModelAdapter : public MenuDelegate {
23 public:
24 // The caller retains ownership of the ui::MenuModel instance and
25 // must ensure it exists for the lifetime of the adapter. The
26 // base_id argument is the command id for the first menu item.
27 explicit MenuModelAdapter(ui::MenuModel* menu_model);
28
29 // Populate a MenuItemView menu with the ui::MenuModel items
30 // (including submenus).
31 virtual void BuildMenu(MenuItemView* menu);
32
33 protected:
34 // views::MenuDelegate implementation.
35 virtual void ExecuteCommand(int id) OVERRIDE;
36 virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE;
37 virtual bool GetAccelerator(int id,
38 views::Accelerator* accelerator) OVERRIDE;
39 virtual std::wstring GetLabel(int id) const OVERRIDE;
40 virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE;
41 virtual bool IsCommandEnabled(int id) const OVERRIDE;
42 virtual bool IsItemChecked(int id) const OVERRIDE;
43 virtual void SelectionChanged(MenuItemView* menu) OVERRIDE;
44 virtual void WillShowMenu(MenuItemView* menu) OVERRIDE;
45
46 private:
47 // Implementation of BuildMenu(). index_offset is both input and output;
48 // on input it contains the offset from index to command id for the model,
49 // and on output it contains the offset for the next model.
50 void BuildMenuImpl(MenuItemView* menu, ui::MenuModel* model);
51
52 // Container of ui::MenuModel pointers as encountered by preorder
53 // traversal. The first element is always the top-level model
54 // passed to the constructor.
55 ui::MenuModel* menu_model_;
56
57 // Map MenuItems to MenuModels. Used to implement WillShowMenu().
58 std::map<MenuItemView*, ui::MenuModel*> menu_map_;
59
60 DISALLOW_COPY_AND_ASSIGN(MenuModelAdapter);
61 };
62
63 } // namespace views
64
65 #endif // VIEWS_CONTROLS_MENU_MENU_MODEL_ADAPTER_H_
OLDNEW
« no previous file with comments | « views/controls/menu/menu_item_view.cc ('k') | views/controls/menu/menu_model_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698