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

Side by Side Diff: ui/views/examples/text_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/text_example.h ('k') | ui/views/examples/textfield_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/text_example.h" 5 #include "ui/views/examples/text_example.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/canvas_skia.h" 10 #include "ui/gfx/canvas_skia.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 const char* kVerticalAlignments[] = { 63 const char* kVerticalAlignments[] = {
64 "Default", 64 "Default",
65 "Top", 65 "Top",
66 "Middle", 66 "Middle",
67 "Bottom", 67 "Bottom",
68 }; 68 };
69 69
70 } // namespace 70 } // namespace
71 71
72 namespace views {
72 namespace examples { 73 namespace examples {
73 74
74 // TextExample's content view, which is responsible for drawing a string with 75 // TextExample's content view, which is responsible for drawing a string with
75 // the specified style. 76 // the specified style.
76 class TextExample::TextExampleView : public views::View { 77 class TextExample::TextExampleView : public View {
77 public: 78 public:
78 TextExampleView() 79 TextExampleView()
79 : font_(ResourceBundle::GetSharedInstance().GetFont( 80 : font_(ResourceBundle::GetSharedInstance().GetFont(
80 ResourceBundle::BaseFont)), 81 ResourceBundle::BaseFont)),
81 text_(ASCIIToUTF16(kShortText)), 82 text_(ASCIIToUTF16(kShortText)),
82 text_flags_(0), 83 text_flags_(0),
83 fade_(false), 84 fade_(false),
84 fade_mode_(gfx::CanvasSkia::TruncateFadeTail) { 85 fade_mode_(gfx::CanvasSkia::TruncateFadeTail) {
85 } 86 }
86 87
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // If |true|, specifies to call |DrawFadeTruncatingString()| instead of 128 // If |true|, specifies to call |DrawFadeTruncatingString()| instead of
128 // |DrawStringInt()|. 129 // |DrawStringInt()|.
129 bool fade_; 130 bool fade_;
130 131
131 // If |fade_| is |true|, fade mode parameter to |DrawFadeTruncatingString()|. 132 // If |fade_| is |true|, fade mode parameter to |DrawFadeTruncatingString()|.
132 gfx::CanvasSkia::TruncateFadeMode fade_mode_; 133 gfx::CanvasSkia::TruncateFadeMode fade_mode_;
133 134
134 DISALLOW_COPY_AND_ASSIGN(TextExampleView); 135 DISALLOW_COPY_AND_ASSIGN(TextExampleView);
135 }; 136 };
136 137
137 TextExample::TextExample(ExamplesMain* main) 138 TextExample::TextExample() : ExampleBase("Text Styles") {
138 : ExampleBase(main, "Text Styles") {
139 } 139 }
140 140
141 TextExample::~TextExample() { 141 TextExample::~TextExample() {
142 } 142 }
143 143
144 views::Combobox* TextExample::AddCombobox(views::GridLayout* layout, 144 Combobox* TextExample::AddCombobox(GridLayout* layout,
145 const char* name, 145 const char* name,
146 const char** strings, 146 const char** strings,
147 int count) { 147 int count) {
148 layout->StartRow(0, 0); 148 layout->StartRow(0, 0);
149 layout->AddView(new views::Label(ASCIIToUTF16(name))); 149 layout->AddView(new Label(ASCIIToUTF16(name)));
150 views::Combobox* combo_box = 150 Combobox* combo_box = new Combobox(new ExampleComboboxModel(strings, count));
151 new views::Combobox(new ExampleComboboxModel(strings, count));
152 combo_box->SetSelectedItem(0); 151 combo_box->SetSelectedItem(0);
153 combo_box->set_listener(this); 152 combo_box->set_listener(this);
154 layout->AddView(combo_box); 153 layout->AddView(combo_box);
155 return combo_box; 154 return combo_box;
156 } 155 }
157 156
158 void TextExample::CreateExampleView(views::View* container) { 157 void TextExample::CreateExampleView(View* container) {
159 text_view_ = new TextExampleView; 158 text_view_ = new TextExampleView;
160 159
161 views::GridLayout* layout = new views::GridLayout(container); 160 GridLayout* layout = new GridLayout(container);
162 container->SetLayoutManager(layout); 161 container->SetLayoutManager(layout);
163 162
164 layout->AddPaddingRow(0, 8); 163 layout->AddPaddingRow(0, 8);
165 164
166 views::ColumnSet* column_set = layout->AddColumnSet(0); 165 ColumnSet* column_set = layout->AddColumnSet(0);
167 column_set->AddPaddingColumn(0, 8); 166 column_set->AddPaddingColumn(0, 8);
168 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 167 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL,
169 0.1f, views::GridLayout::USE_PREF, 0, 0); 168 0.1f, GridLayout::USE_PREF, 0, 0);
170 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 169 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
171 0.9f, views::GridLayout::USE_PREF, 0, 0); 170 0.9f, GridLayout::USE_PREF, 0, 0);
172 column_set->AddPaddingColumn(0, 8); 171 column_set->AddPaddingColumn(0, 8);
173 172
174 h_align_cb_ = AddCombobox(layout, 173 h_align_cb_ = AddCombobox(layout,
175 "H-Align", 174 "H-Align",
176 kHorizontalAligments, 175 kHorizontalAligments,
177 arraysize(kHorizontalAligments)); 176 arraysize(kHorizontalAligments));
178 v_align_cb_ = AddCombobox(layout, 177 v_align_cb_ = AddCombobox(layout,
179 "V-Align", 178 "V-Align",
180 kVerticalAlignments, 179 kVerticalAlignments,
181 arraysize(kVerticalAlignments)); 180 arraysize(kVerticalAlignments));
182 eliding_cb_ = AddCombobox(layout, 181 eliding_cb_ = AddCombobox(layout,
183 "Eliding", 182 "Eliding",
184 kElidingBehaviors, 183 kElidingBehaviors,
185 arraysize(kElidingBehaviors)); 184 arraysize(kElidingBehaviors));
186 prefix_cb_ = AddCombobox(layout, 185 prefix_cb_ = AddCombobox(layout,
187 "Prefix", 186 "Prefix",
188 kPrefixOptions, 187 kPrefixOptions,
189 arraysize(kPrefixOptions)); 188 arraysize(kPrefixOptions));
190 text_cb_ = AddCombobox(layout, 189 text_cb_ = AddCombobox(layout,
191 "Example Text", 190 "Example Text",
192 kTextExamples, 191 kTextExamples,
193 arraysize(kTextExamples)); 192 arraysize(kTextExamples));
194 193
195 layout->StartRow(0, 0); 194 layout->StartRow(0, 0);
196 multiline_checkbox_ = new views::Checkbox(ASCIIToUTF16("Multiline")); 195 multiline_checkbox_ = new Checkbox(ASCIIToUTF16("Multiline"));
197 multiline_checkbox_->set_listener(this); 196 multiline_checkbox_->set_listener(this);
198 layout->AddView(multiline_checkbox_); 197 layout->AddView(multiline_checkbox_);
199 break_checkbox_ = new views::Checkbox(ASCIIToUTF16("Character Break")); 198 break_checkbox_ = new Checkbox(ASCIIToUTF16("Character Break"));
200 break_checkbox_->set_listener(this); 199 break_checkbox_->set_listener(this);
201 layout->AddView(break_checkbox_); 200 layout->AddView(break_checkbox_);
202 201
203 layout->AddPaddingRow(0, 32); 202 layout->AddPaddingRow(0, 32);
204 203
205 column_set = layout->AddColumnSet(1); 204 column_set = layout->AddColumnSet(1);
206 column_set->AddPaddingColumn(0, 16); 205 column_set->AddPaddingColumn(0, 16);
207 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 206 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
208 1, views::GridLayout::USE_PREF, 0, 0); 207 1, GridLayout::USE_PREF, 0, 0);
209 column_set->AddPaddingColumn(0, 16); 208 column_set->AddPaddingColumn(0, 16);
210 layout->StartRow(1, 1); 209 layout->StartRow(1, 1);
211 layout->AddView(text_view_); 210 layout->AddView(text_view_);
212 211
213 layout->AddPaddingRow(0, 8); 212 layout->AddPaddingRow(0, 8);
214 } 213 }
215 214
216 void TextExample::ButtonPressed(views::Button* button, 215 void TextExample::ButtonPressed(Button* button,
217 const views::Event& event) { 216 const Event& event) {
218 int text_flags = text_view_->text_flags(); 217 int text_flags = text_view_->text_flags();
219 if (button == multiline_checkbox_) { 218 if (button == multiline_checkbox_) {
220 if (multiline_checkbox_->checked()) 219 if (multiline_checkbox_->checked())
221 text_flags |= gfx::Canvas::MULTI_LINE; 220 text_flags |= gfx::Canvas::MULTI_LINE;
222 else 221 else
223 text_flags &= ~gfx::Canvas::MULTI_LINE; 222 text_flags &= ~gfx::Canvas::MULTI_LINE;
224 } else if (button == break_checkbox_) { 223 } else if (button == break_checkbox_) {
225 if (break_checkbox_->checked()) 224 if (break_checkbox_->checked())
226 text_flags |= gfx::Canvas::CHARACTER_BREAK; 225 text_flags |= gfx::Canvas::CHARACTER_BREAK;
227 else 226 else
228 text_flags &= ~gfx::Canvas::CHARACTER_BREAK; 227 text_flags &= ~gfx::Canvas::CHARACTER_BREAK;
229 } 228 }
230 text_view_->set_text_flags(text_flags); 229 text_view_->set_text_flags(text_flags);
231 text_view_->SchedulePaint(); 230 text_view_->SchedulePaint();
232 } 231 }
233 232
234 void TextExample::ItemChanged(views::Combobox* combo_box, 233 void TextExample::ItemChanged(Combobox* combo_box,
235 int prev_index, 234 int prev_index,
236 int new_index) { 235 int new_index) {
237 int text_flags = text_view_->text_flags(); 236 int text_flags = text_view_->text_flags();
238 if (combo_box == h_align_cb_) { 237 if (combo_box == h_align_cb_) {
239 text_flags &= ~(gfx::Canvas::TEXT_ALIGN_LEFT | 238 text_flags &= ~(gfx::Canvas::TEXT_ALIGN_LEFT |
240 gfx::Canvas::TEXT_ALIGN_CENTER | 239 gfx::Canvas::TEXT_ALIGN_CENTER |
241 gfx::Canvas::TEXT_ALIGN_RIGHT); 240 gfx::Canvas::TEXT_ALIGN_RIGHT);
242 switch (new_index) { 241 switch (new_index) {
243 case 0: 242 case 0:
244 break; 243 break;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 case 2: 319 case 2:
321 text_flags |= gfx::Canvas::HIDE_PREFIX; 320 text_flags |= gfx::Canvas::HIDE_PREFIX;
322 break; 321 break;
323 } 322 }
324 } 323 }
325 text_view_->set_text_flags(text_flags); 324 text_view_->set_text_flags(text_flags);
326 text_view_->SchedulePaint(); 325 text_view_->SchedulePaint();
327 } 326 }
328 327
329 } // namespace examples 328 } // namespace examples
329 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/text_example.h ('k') | ui/views/examples/textfield_example.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698