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

Side by Side Diff: ui/views/examples/menu_example.cc

Issue 8687013: Get the examples to run in aura_shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | « ui/views/examples/menu_example.h ('k') | ui/views/examples/message_box_example.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "ui/base/models/simple_menu_model.h" 10 #include "ui/base/models/simple_menu_model.h"
11 #include "ui/views/controls/button/menu_button.h" 11 #include "ui/views/controls/button/menu_button.h"
12 #include "ui/views/controls/button/text_button.h" 12 #include "ui/views/controls/button/text_button.h"
13 #include "ui/views/controls/menu/menu_2.h" 13 #include "ui/views/controls/menu/menu_2.h"
14 #include "ui/views/controls/menu/view_menu_delegate.h" 14 #include "ui/views/controls/menu/view_menu_delegate.h"
15 #include "ui/views/layout/fill_layout.h" 15 #include "ui/views/layout/fill_layout.h"
16 #include "views/view.h" 16 #include "views/view.h"
17 17
18 namespace views {
19 namespace examples {
20
18 namespace { 21 namespace {
19 22
20 class ExampleMenuModel : public ui::SimpleMenuModel, 23 class ExampleMenuModel : public ui::SimpleMenuModel,
21 public ui::SimpleMenuModel::Delegate { 24 public ui::SimpleMenuModel::Delegate {
22 public: 25 public:
23 ExampleMenuModel(); 26 ExampleMenuModel();
24 27
25 void RunMenuAt(const gfx::Point& point); 28 void RunMenuAt(const gfx::Point& point);
26 29
27 // Overridden from ui::SimpleMenuModel::Delegate: 30 // Overridden from ui::SimpleMenuModel::Delegate:
(...skipping 13 matching lines...) Expand all
41 kCommandDoSomething, 44 kCommandDoSomething,
42 kCommandSelectAscii, 45 kCommandSelectAscii,
43 kCommandSelectUtf8, 46 kCommandSelectUtf8,
44 kCommandSelectUtf16, 47 kCommandSelectUtf16,
45 kCommandCheckApple, 48 kCommandCheckApple,
46 kCommandCheckOrange, 49 kCommandCheckOrange,
47 kCommandCheckKiwi, 50 kCommandCheckKiwi,
48 kCommandGoHome, 51 kCommandGoHome,
49 }; 52 };
50 53
51 scoped_ptr<views::Menu2> menu_; 54 scoped_ptr<Menu2> menu_;
52 scoped_ptr<ui::SimpleMenuModel> submenu_; 55 scoped_ptr<ui::SimpleMenuModel> submenu_;
53 std::set<int> checked_fruits_; 56 std::set<int> checked_fruits_;
54 int current_encoding_command_id_; 57 int current_encoding_command_id_;
55 58
56 DISALLOW_COPY_AND_ASSIGN(ExampleMenuModel); 59 DISALLOW_COPY_AND_ASSIGN(ExampleMenuModel);
57 }; 60 };
58 61
59 class ExampleMenuButton : public views::MenuButton, 62 class ExampleMenuButton : public MenuButton, public ViewMenuDelegate {
60 public views::ViewMenuDelegate {
61 public: 63 public:
62 ExampleMenuButton(const string16& test, bool show_menu_marker); 64 ExampleMenuButton(const string16& test, bool show_menu_marker);
63 virtual ~ExampleMenuButton(); 65 virtual ~ExampleMenuButton();
64 66
65 private: 67 private:
66 // Overridden from views::ViewMenuDelegate: 68 // Overridden from ViewMenuDelegate:
67 virtual void RunMenu(views::View* source, const gfx::Point& point) OVERRIDE; 69 virtual void RunMenu(View* source, const gfx::Point& point) OVERRIDE;
68 70
69 scoped_ptr<ExampleMenuModel> menu_model_; 71 scoped_ptr<ExampleMenuModel> menu_model_;
70 DISALLOW_COPY_AND_ASSIGN(ExampleMenuButton); 72 DISALLOW_COPY_AND_ASSIGN(ExampleMenuButton);
71 }; 73 };
72 74
73 // ExampleMenuModel --------------------------------------------------------- 75 // ExampleMenuModel ---------------------------------------------------------
74 76
75 ExampleMenuModel::ExampleMenuModel() 77 ExampleMenuModel::ExampleMenuModel()
76 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), 78 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
77 current_encoding_command_id_(kCommandSelectAscii) { 79 current_encoding_command_id_(kCommandSelectAscii) {
78 AddItem(kCommandDoSomething, WideToUTF16(L"Do Something")); 80 AddItem(kCommandDoSomething, WideToUTF16(L"Do Something"));
79 AddSeparator(); 81 AddSeparator();
80 AddRadioItem(kCommandSelectAscii, 82 AddRadioItem(kCommandSelectAscii,
81 WideToUTF16(L"ASCII"), kGroupMakeDecision); 83 WideToUTF16(L"ASCII"), kGroupMakeDecision);
82 AddRadioItem(kCommandSelectUtf8, 84 AddRadioItem(kCommandSelectUtf8,
83 WideToUTF16(L"UTF-8"), kGroupMakeDecision); 85 WideToUTF16(L"UTF-8"), kGroupMakeDecision);
84 AddRadioItem(kCommandSelectUtf16, 86 AddRadioItem(kCommandSelectUtf16,
85 WideToUTF16(L"UTF-16"), kGroupMakeDecision); 87 WideToUTF16(L"UTF-16"), kGroupMakeDecision);
86 AddSeparator(); 88 AddSeparator();
87 AddCheckItem(kCommandCheckApple, WideToUTF16(L"Apple")); 89 AddCheckItem(kCommandCheckApple, WideToUTF16(L"Apple"));
88 AddCheckItem(kCommandCheckOrange, WideToUTF16(L"Orange")); 90 AddCheckItem(kCommandCheckOrange, WideToUTF16(L"Orange"));
89 AddCheckItem(kCommandCheckKiwi, WideToUTF16(L"Kiwi")); 91 AddCheckItem(kCommandCheckKiwi, WideToUTF16(L"Kiwi"));
90 AddSeparator(); 92 AddSeparator();
91 AddItem(kCommandGoHome, WideToUTF16(L"Go Home")); 93 AddItem(kCommandGoHome, WideToUTF16(L"Go Home"));
92 94
93 submenu_.reset(new ui::SimpleMenuModel(this)); 95 submenu_.reset(new ui::SimpleMenuModel(this));
94 submenu_->AddItem(kCommandDoSomething, WideToUTF16(L"Do Something 2")); 96 submenu_->AddItem(kCommandDoSomething, WideToUTF16(L"Do Something 2"));
95 AddSubMenu(0, ASCIIToUTF16("Submenu"), submenu_.get()); 97 AddSubMenu(0, ASCIIToUTF16("Submenu"), submenu_.get());
96 menu_.reset(new views::Menu2(this)); 98 menu_.reset(new Menu2(this));
97 } 99 }
98 100
99 void ExampleMenuModel::RunMenuAt(const gfx::Point& point) { 101 void ExampleMenuModel::RunMenuAt(const gfx::Point& point) {
100 menu_->RunMenuAt(point, views::Menu2::ALIGN_TOPRIGHT); 102 menu_->RunMenuAt(point, Menu2::ALIGN_TOPRIGHT);
101 } 103 }
102 104
103 bool ExampleMenuModel::IsCommandIdChecked(int command_id) const { 105 bool ExampleMenuModel::IsCommandIdChecked(int command_id) const {
104 // Radio items. 106 // Radio items.
105 if (command_id == current_encoding_command_id_) 107 if (command_id == current_encoding_command_id_)
106 return true; 108 return true;
107 109
108 // Check items. 110 // Check items.
109 if (checked_fruits_.find(command_id) != checked_fruits_.end()) 111 if (checked_fruits_.find(command_id) != checked_fruits_.end())
110 return true; 112 return true;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 break; 174 break;
173 } 175 }
174 } 176 }
175 } 177 }
176 178
177 // ExampleMenuButton ----------------------------------------------------------- 179 // ExampleMenuButton -----------------------------------------------------------
178 180
179 ExampleMenuButton::ExampleMenuButton(const string16& test, 181 ExampleMenuButton::ExampleMenuButton(const string16& test,
180 bool show_menu_marker) 182 bool show_menu_marker)
181 : ALLOW_THIS_IN_INITIALIZER_LIST( 183 : ALLOW_THIS_IN_INITIALIZER_LIST(
182 views::MenuButton(NULL, test, this, show_menu_marker)) { 184 MenuButton(NULL, test, this, show_menu_marker)) {
183 } 185 }
184 186
185 ExampleMenuButton::~ExampleMenuButton() { 187 ExampleMenuButton::~ExampleMenuButton() {
186 } 188 }
187 189
188 void ExampleMenuButton::RunMenu(views::View* source, const gfx::Point& point) { 190 void ExampleMenuButton::RunMenu(View* source, const gfx::Point& point) {
189 if (!menu_model_.get()) 191 if (!menu_model_.get())
190 menu_model_.reset(new ExampleMenuModel); 192 menu_model_.reset(new ExampleMenuModel);
191 193
192 menu_model_->RunMenuAt(point); 194 menu_model_->RunMenuAt(point);
193 } 195 }
194 196
195 } // namespace 197 } // namespace
196 198
197 namespace examples { 199 MenuExample::MenuExample() : ExampleBase("Menu") {
198
199 MenuExample::MenuExample(ExamplesMain* main)
200 : ExampleBase(main, "Menu") {
201 } 200 }
202 201
203 MenuExample::~MenuExample() { 202 MenuExample::~MenuExample() {
204 } 203 }
205 204
206 void MenuExample::CreateExampleView(views::View* container) { 205 void MenuExample::CreateExampleView(View* container) {
207 // views::Menu2 is not a sub class of View, hence we cannot directly 206 // Menu2 is not a sub class of View, hence we cannot directly
208 // add to the container. Instead, we add a button to open a menu. 207 // add to the container. Instead, we add a button to open a menu.
209 const bool show_menu_marker = true; 208 const bool show_menu_marker = true;
210 ExampleMenuButton* menu_button = new ExampleMenuButton( 209 ExampleMenuButton* menu_button = new ExampleMenuButton(
211 ASCIIToUTF16("Open a menu"), show_menu_marker); 210 ASCIIToUTF16("Open a menu"), show_menu_marker);
212 container->SetLayoutManager(new views::FillLayout); 211 container->SetLayoutManager(new FillLayout);
213 container->AddChildView(menu_button); 212 container->AddChildView(menu_button);
214 } 213 }
215 214
216 } // namespace examples 215 } // namespace examples
216 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/menu_example.h ('k') | ui/views/examples/message_box_example.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698