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/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace { | 24 namespace { |
25 | 25 |
26 class ExampleMenuModel : public ui::SimpleMenuModel, | 26 class ExampleMenuModel : public ui::SimpleMenuModel, |
27 public ui::SimpleMenuModel::Delegate { | 27 public ui::SimpleMenuModel::Delegate { |
28 public: | 28 public: |
29 ExampleMenuModel(); | 29 ExampleMenuModel(); |
30 | 30 |
31 // ui::SimpleMenuModel::Delegate: | 31 // ui::SimpleMenuModel::Delegate: |
32 bool IsCommandIdChecked(int command_id) const override; | 32 bool IsCommandIdChecked(int command_id) const override; |
33 bool IsCommandIdEnabled(int command_id) const override; | 33 bool IsCommandIdEnabled(int command_id) const override; |
34 bool GetAcceleratorForCommandId(int command_id, | |
35 ui::Accelerator* accelerator) const override; | |
36 void ExecuteCommand(int command_id, int event_flags) override; | 34 void ExecuteCommand(int command_id, int event_flags) override; |
37 | 35 |
38 private: | 36 private: |
39 enum GroupID { | 37 enum GroupID { |
40 GROUP_MAKE_DECISION, | 38 GROUP_MAKE_DECISION, |
41 }; | 39 }; |
42 | 40 |
43 enum CommandID { | 41 enum CommandID { |
44 COMMAND_DO_SOMETHING, | 42 COMMAND_DO_SOMETHING, |
45 COMMAND_SELECT_ASCII, | 43 COMMAND_SELECT_ASCII, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 return true; | 110 return true; |
113 | 111 |
114 return false; | 112 return false; |
115 } | 113 } |
116 | 114 |
117 bool ExampleMenuModel::IsCommandIdEnabled(int command_id) const { | 115 bool ExampleMenuModel::IsCommandIdEnabled(int command_id) const { |
118 // All commands are enabled except for COMMAND_GO_HOME. | 116 // All commands are enabled except for COMMAND_GO_HOME. |
119 return command_id != COMMAND_GO_HOME; | 117 return command_id != COMMAND_GO_HOME; |
120 } | 118 } |
121 | 119 |
122 bool ExampleMenuModel::GetAcceleratorForCommandId( | |
123 int command_id, | |
124 ui::Accelerator* accelerator) const { | |
125 // We don't use this in the example. | |
126 return false; | |
127 } | |
128 | |
129 void ExampleMenuModel::ExecuteCommand(int command_id, int event_flags) { | 120 void ExampleMenuModel::ExecuteCommand(int command_id, int event_flags) { |
130 switch (command_id) { | 121 switch (command_id) { |
131 case COMMAND_DO_SOMETHING: { | 122 case COMMAND_DO_SOMETHING: { |
132 VLOG(0) << "Done something"; | 123 VLOG(0) << "Done something"; |
133 break; | 124 break; |
134 } | 125 } |
135 | 126 |
136 // Radio items. | 127 // Radio items. |
137 case COMMAND_SELECT_ASCII: { | 128 case COMMAND_SELECT_ASCII: { |
138 current_encoding_command_id_ = COMMAND_SELECT_ASCII; | 129 current_encoding_command_id_ = COMMAND_SELECT_ASCII; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 void MenuExample::CreateExampleView(View* container) { | 208 void MenuExample::CreateExampleView(View* container) { |
218 // We add a button to open a menu. | 209 // We add a button to open a menu. |
219 ExampleMenuButton* menu_button = new ExampleMenuButton( | 210 ExampleMenuButton* menu_button = new ExampleMenuButton( |
220 ASCIIToUTF16("Open a menu")); | 211 ASCIIToUTF16("Open a menu")); |
221 container->SetLayoutManager(new FillLayout); | 212 container->SetLayoutManager(new FillLayout); |
222 container->AddChildView(menu_button); | 213 container->AddChildView(menu_button); |
223 } | 214 } |
224 | 215 |
225 } // namespace examples | 216 } // namespace examples |
226 } // namespace views | 217 } // namespace views |
OLD | NEW |