| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 UI_VIEWS_CONTROLS_MENU_MENU_MODEL_ADAPTER_H_ | 5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_MODEL_ADAPTER_H_ |
| 6 #define UI_VIEWS_CONTROLS_MENU_MENU_MODEL_ADAPTER_H_ | 6 #define UI_VIEWS_CONTROLS_MENU_MENU_MODEL_ADAPTER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "ui/views/controls/menu/menu_delegate.h" | 10 #include "ui/views/controls/menu/menu_delegate.h" |
| 11 | 11 |
| 12 namespace ui { | 12 namespace ui { |
| 13 class MenuModel; | 13 class MenuModel; |
| 14 } | 14 } |
| 15 | 15 |
| 16 namespace views { | 16 namespace views { |
| 17 class MenuItemView; | 17 class MenuItemView; |
| 18 | 18 |
| 19 // This class wraps an instance of ui::MenuModel with the | 19 // This class wraps an instance of ui::MenuModel with the |
| 20 // views::MenuDelegate interface required by views::MenuItemView. | 20 // views::MenuDelegate interface required by views::MenuItemView. |
| 21 class VIEWS_EXPORT MenuModelAdapter : public MenuDelegate { | 21 class VIEWS_EXPORT MenuModelAdapter : public MenuDelegate { |
| 22 public: | 22 public: |
| 23 // The caller retains ownership of the ui::MenuModel instance and | 23 // The caller retains ownership of the ui::MenuModel instance and |
| 24 // must ensure it exists for the lifetime of the adapter. | 24 // must ensure it exists for the lifetime of the adapter. |
| 25 explicit MenuModelAdapter(ui::MenuModel* menu_model); | 25 explicit MenuModelAdapter(ui::MenuModel* menu_model); |
| 26 virtual ~MenuModelAdapter(); | 26 ~MenuModelAdapter() override; |
| 27 | 27 |
| 28 // Populate a MenuItemView menu with the ui::MenuModel items | 28 // Populate a MenuItemView menu with the ui::MenuModel items |
| 29 // (including submenus). | 29 // (including submenus). |
| 30 virtual void BuildMenu(MenuItemView* menu); | 30 virtual void BuildMenu(MenuItemView* menu); |
| 31 | 31 |
| 32 // Convenience for creating and populating a menu. The caller owns the | 32 // Convenience for creating and populating a menu. The caller owns the |
| 33 // returned MenuItemView. | 33 // returned MenuItemView. |
| 34 MenuItemView* CreateMenu(); | 34 MenuItemView* CreateMenu(); |
| 35 | 35 |
| 36 void set_triggerable_event_flags(int triggerable_event_flags) { | 36 void set_triggerable_event_flags(int triggerable_event_flags) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 55 | 55 |
| 56 protected: | 56 protected: |
| 57 // Create and add a menu item to |menu| for the item at index |index| in | 57 // Create and add a menu item to |menu| for the item at index |index| in |
| 58 // |model|. Subclasses override this to allow custom items to be added to the | 58 // |model|. Subclasses override this to allow custom items to be added to the |
| 59 // menu. | 59 // menu. |
| 60 virtual MenuItemView* AppendMenuItem(MenuItemView* menu, | 60 virtual MenuItemView* AppendMenuItem(MenuItemView* menu, |
| 61 ui::MenuModel* model, | 61 ui::MenuModel* model, |
| 62 int index); | 62 int index); |
| 63 | 63 |
| 64 // views::MenuDelegate implementation. | 64 // views::MenuDelegate implementation. |
| 65 virtual void ExecuteCommand(int id) override; | 65 void ExecuteCommand(int id) override; |
| 66 virtual void ExecuteCommand(int id, int mouse_event_flags) override; | 66 void ExecuteCommand(int id, int mouse_event_flags) override; |
| 67 virtual bool IsTriggerableEvent(MenuItemView* source, | 67 bool IsTriggerableEvent(MenuItemView* source, const ui::Event& e) override; |
| 68 const ui::Event& e) override; | 68 bool GetAccelerator(int id, ui::Accelerator* accelerator) const override; |
| 69 virtual bool GetAccelerator(int id, | 69 base::string16 GetLabel(int id) const override; |
| 70 ui::Accelerator* accelerator) const override; | 70 const gfx::FontList* GetLabelFontList(int id) const override; |
| 71 virtual base::string16 GetLabel(int id) const override; | 71 bool IsCommandEnabled(int id) const override; |
| 72 virtual const gfx::FontList* GetLabelFontList(int id) const override; | 72 bool IsCommandVisible(int id) const override; |
| 73 virtual bool IsCommandEnabled(int id) const override; | 73 bool IsItemChecked(int id) const override; |
| 74 virtual bool IsCommandVisible(int id) const override; | 74 void SelectionChanged(MenuItemView* menu) override; |
| 75 virtual bool IsItemChecked(int id) const override; | 75 void WillShowMenu(MenuItemView* menu) override; |
| 76 virtual void SelectionChanged(MenuItemView* menu) override; | 76 void WillHideMenu(MenuItemView* menu) override; |
| 77 virtual void WillShowMenu(MenuItemView* menu) override; | |
| 78 virtual void WillHideMenu(MenuItemView* menu) override; | |
| 79 | 77 |
| 80 private: | 78 private: |
| 81 // Implementation of BuildMenu(). | 79 // Implementation of BuildMenu(). |
| 82 void BuildMenuImpl(MenuItemView* menu, ui::MenuModel* model); | 80 void BuildMenuImpl(MenuItemView* menu, ui::MenuModel* model); |
| 83 | 81 |
| 84 // Container of ui::MenuModel pointers as encountered by preorder | 82 // Container of ui::MenuModel pointers as encountered by preorder |
| 85 // traversal. The first element is always the top-level model | 83 // traversal. The first element is always the top-level model |
| 86 // passed to the constructor. | 84 // passed to the constructor. |
| 87 ui::MenuModel* menu_model_; | 85 ui::MenuModel* menu_model_; |
| 88 | 86 |
| 89 // Mouse event flags which can trigger menu actions. | 87 // Mouse event flags which can trigger menu actions. |
| 90 int triggerable_event_flags_; | 88 int triggerable_event_flags_; |
| 91 | 89 |
| 92 // Map MenuItems to MenuModels. Used to implement WillShowMenu(). | 90 // Map MenuItems to MenuModels. Used to implement WillShowMenu(). |
| 93 std::map<MenuItemView*, ui::MenuModel*> menu_map_; | 91 std::map<MenuItemView*, ui::MenuModel*> menu_map_; |
| 94 | 92 |
| 95 DISALLOW_COPY_AND_ASSIGN(MenuModelAdapter); | 93 DISALLOW_COPY_AND_ASSIGN(MenuModelAdapter); |
| 96 }; | 94 }; |
| 97 | 95 |
| 98 } // namespace views | 96 } // namespace views |
| 99 | 97 |
| 100 #endif // UI_VIEWS_CONTROLS_MENU_MENU_MODEL_ADAPTER_H_ | 98 #endif // UI_VIEWS_CONTROLS_MENU_MENU_MODEL_ADAPTER_H_ |
| OLD | NEW |