Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #include "views/controls/menu/menu_delegate.h" | |
|
sky
2011/05/25 15:41:12
newline between 9 and 10
rhashimoto
2011/05/25 16:24:37
Done.
| |
| 11 | |
| 12 namespace ui { | |
| 13 class MenuModel; | |
| 14 } | |
| 15 | |
| 16 namespace views { | |
| 17 class MenuItemView; | |
| 18 | |
| 19 // This class wraps an instance of ui::MenuModel with the | |
| 20 // views::MenuDelegate interface required by views::MenuItemView. | |
| 21 class MenuModelAdapter : public MenuDelegate { | |
| 22 public: | |
| 23 // The caller retains ownership of the ui::MenuModel instance and | |
| 24 // must ensure it exists for the lifetime of the adapter. The | |
| 25 // base_id argument is the command id for the first menu item. | |
| 26 explicit MenuModelAdapter(ui::MenuModel* menu_model); | |
| 27 | |
| 28 // Populate a MenuItemView menu with the ui::MenuModel items | |
| 29 // (including submenus). | |
| 30 virtual void BuildMenu(MenuItemView* menu); | |
| 31 | |
| 32 protected: | |
| 33 // views::MenuDelegate implementation. | |
| 34 virtual void ExecuteCommand(int id) OVERRIDE; | |
| 35 virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE; | |
| 36 virtual bool GetAccelerator(int id, | |
| 37 views::Accelerator* accelerator) OVERRIDE; | |
| 38 virtual std::wstring GetLabel(int id) const OVERRIDE; | |
| 39 virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE; | |
| 40 virtual bool IsCommandEnabled(int id) const OVERRIDE; | |
| 41 virtual bool IsItemChecked(int id) const OVERRIDE; | |
| 42 virtual void SelectionChanged(MenuItemView* menu) OVERRIDE; | |
| 43 virtual void WillShowMenu(MenuItemView* menu) OVERRIDE; | |
| 44 | |
| 45 private: | |
| 46 // Implementation of BuildMenu(). index_offset is both input and output; | |
| 47 // on input it contains the offset from index to command id for the model, | |
| 48 // and on output it contains the offset for the next model. | |
| 49 void BuildMenuImpl(MenuItemView* menu, ui::MenuModel* model); | |
| 50 | |
| 51 // Container of ui::MenuModel pointers as encountered by preorder | |
| 52 // traversal. The first element is always the top-level model | |
| 53 // passed to the constructor. | |
| 54 ui::MenuModel* menu_model_; | |
| 55 | |
| 56 // Map MenuItems to MenuModels. Used to implement WillShowMenu(). | |
| 57 std::map<MenuItemView*, ui::MenuModel*> menu_map_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(MenuModelAdapter); | |
| 60 }; | |
| 61 | |
| 62 } // namespace views | |
| 63 | |
| 64 #endif // VIEWS_CONTROLS_MENU_MENU_MODEL_ADAPTER_H_ | |
| OLD | NEW |