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 #include "ui/views/examples/menu_example.h" | 5 #include "ui/views/examples/menu_example.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "ui/base/models/simple_menu_model.h" | 10 #include "ui/base/models/simple_menu_model.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace examples { | 21 namespace examples { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 class ExampleMenuModel : public ui::SimpleMenuModel, | 25 class ExampleMenuModel : public ui::SimpleMenuModel, |
26 public ui::SimpleMenuModel::Delegate { | 26 public ui::SimpleMenuModel::Delegate { |
27 public: | 27 public: |
28 ExampleMenuModel(); | 28 ExampleMenuModel(); |
29 | 29 |
30 // ui::SimpleMenuModel::Delegate: | 30 // ui::SimpleMenuModel::Delegate: |
31 virtual bool IsCommandIdChecked(int command_id) const override; | 31 bool IsCommandIdChecked(int command_id) const override; |
32 virtual bool IsCommandIdEnabled(int command_id) const override; | 32 bool IsCommandIdEnabled(int command_id) const override; |
33 virtual bool GetAcceleratorForCommandId( | 33 bool GetAcceleratorForCommandId(int command_id, |
34 int command_id, | 34 ui::Accelerator* accelerator) override; |
35 ui::Accelerator* accelerator) override; | 35 void ExecuteCommand(int command_id, int event_flags) override; |
36 virtual void ExecuteCommand(int command_id, int event_flags) override; | |
37 | 36 |
38 private: | 37 private: |
39 enum GroupID { | 38 enum GroupID { |
40 GROUP_MAKE_DECISION, | 39 GROUP_MAKE_DECISION, |
41 }; | 40 }; |
42 | 41 |
43 enum CommandID { | 42 enum CommandID { |
44 COMMAND_DO_SOMETHING, | 43 COMMAND_DO_SOMETHING, |
45 COMMAND_SELECT_ASCII, | 44 COMMAND_SELECT_ASCII, |
46 COMMAND_SELECT_UTF8, | 45 COMMAND_SELECT_UTF8, |
47 COMMAND_SELECT_UTF16, | 46 COMMAND_SELECT_UTF16, |
48 COMMAND_CHECK_APPLE, | 47 COMMAND_CHECK_APPLE, |
49 COMMAND_CHECK_ORANGE, | 48 COMMAND_CHECK_ORANGE, |
50 COMMAND_CHECK_KIWI, | 49 COMMAND_CHECK_KIWI, |
51 COMMAND_GO_HOME, | 50 COMMAND_GO_HOME, |
52 }; | 51 }; |
53 | 52 |
54 scoped_ptr<ui::SimpleMenuModel> submenu_; | 53 scoped_ptr<ui::SimpleMenuModel> submenu_; |
55 std::set<int> checked_fruits_; | 54 std::set<int> checked_fruits_; |
56 int current_encoding_command_id_; | 55 int current_encoding_command_id_; |
57 | 56 |
58 DISALLOW_COPY_AND_ASSIGN(ExampleMenuModel); | 57 DISALLOW_COPY_AND_ASSIGN(ExampleMenuModel); |
59 }; | 58 }; |
60 | 59 |
61 class ExampleMenuButton : public MenuButton, public MenuButtonListener { | 60 class ExampleMenuButton : public MenuButton, public MenuButtonListener { |
62 public: | 61 public: |
63 explicit ExampleMenuButton(const base::string16& test); | 62 explicit ExampleMenuButton(const base::string16& test); |
64 virtual ~ExampleMenuButton(); | 63 ~ExampleMenuButton() override; |
65 | 64 |
66 private: | 65 private: |
67 // MenuButtonListener: | 66 // MenuButtonListener: |
68 virtual void OnMenuButtonClicked(View* source, | 67 void OnMenuButtonClicked(View* source, const gfx::Point& point) override; |
69 const gfx::Point& point) override; | |
70 | 68 |
71 ui::SimpleMenuModel* GetMenuModel(); | 69 ui::SimpleMenuModel* GetMenuModel(); |
72 | 70 |
73 scoped_ptr<ExampleMenuModel> menu_model_; | 71 scoped_ptr<ExampleMenuModel> menu_model_; |
74 scoped_ptr<MenuRunner> menu_runner_; | 72 scoped_ptr<MenuRunner> menu_runner_; |
75 | 73 |
76 DISALLOW_COPY_AND_ASSIGN(ExampleMenuButton); | 74 DISALLOW_COPY_AND_ASSIGN(ExampleMenuButton); |
77 }; | 75 }; |
78 | 76 |
79 // ExampleMenuModel --------------------------------------------------------- | 77 // ExampleMenuModel --------------------------------------------------------- |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 void MenuExample::CreateExampleView(View* container) { | 214 void MenuExample::CreateExampleView(View* container) { |
217 // We add a button to open a menu. | 215 // We add a button to open a menu. |
218 ExampleMenuButton* menu_button = new ExampleMenuButton( | 216 ExampleMenuButton* menu_button = new ExampleMenuButton( |
219 ASCIIToUTF16("Open a menu")); | 217 ASCIIToUTF16("Open a menu")); |
220 container->SetLayoutManager(new FillLayout); | 218 container->SetLayoutManager(new FillLayout); |
221 container->AddChildView(menu_button); | 219 container->AddChildView(menu_button); |
222 } | 220 } |
223 | 221 |
224 } // namespace examples | 222 } // namespace examples |
225 } // namespace views | 223 } // namespace views |
OLD | NEW |