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/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/views/controls/button/checkbox.h" | 10 #include "ui/views/controls/button/checkbox.h" |
11 #include "ui/views/controls/combobox/combobox.h" | 11 #include "ui/views/controls/combobox/combobox.h" |
12 #include "ui/views/controls/label.h" | 12 #include "ui/views/controls/label.h" |
13 #include "ui/views/examples/example_combobox_model.h" | 13 #include "ui/views/examples/example_combobox_model.h" |
14 #include "ui/views/layout/grid_layout.h" | 14 #include "ui/views/layout/grid_layout.h" |
15 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
16 | 16 |
| 17 namespace views { |
| 18 namespace examples { |
| 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 // Number of columns in the view layout. | 22 // Number of columns in the view layout. |
20 const int kNumColumns = 10; | 23 const int kNumColumns = 10; |
21 | 24 |
22 const char kShortText[] = "Batman"; | 25 const char kShortText[] = "Batman"; |
23 const char kMediumText[] = "The quick brown fox jumps over the lazy dog."; | 26 const char kMediumText[] = "The quick brown fox jumps over the lazy dog."; |
24 const char kLongText[] = | 27 const char kLongText[] = |
25 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod " | 28 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod " |
26 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " | 29 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 }; | 69 }; |
67 | 70 |
68 const char* kVerticalAlignments[] = { | 71 const char* kVerticalAlignments[] = { |
69 "Default", | 72 "Default", |
70 "Top", | 73 "Top", |
71 "Middle", | 74 "Middle", |
72 "Bottom", | 75 "Bottom", |
73 }; | 76 }; |
74 | 77 |
75 // Toggles bit |flag| on |flags| based on state of |checkbox|. | 78 // Toggles bit |flag| on |flags| based on state of |checkbox|. |
76 void SetFlagFromCheckbox(views::Checkbox* checkbox, int* flags, int flag) { | 79 void SetFlagFromCheckbox(Checkbox* checkbox, int* flags, int flag) { |
77 if (checkbox->checked()) | 80 if (checkbox->checked()) |
78 *flags |= flag; | 81 *flags |= flag; |
79 else | 82 else |
80 *flags &= ~flag; | 83 *flags &= ~flag; |
81 } | 84 } |
82 | 85 |
83 } // namespace | 86 } // namespace |
84 | 87 |
85 namespace views { | |
86 namespace examples { | |
87 | |
88 // TextExample's content view, which is responsible for drawing a string with | 88 // TextExample's content view, which is responsible for drawing a string with |
89 // the specified style. | 89 // the specified style. |
90 class TextExample::TextExampleView : public View { | 90 class TextExample::TextExampleView : public View { |
91 public: | 91 public: |
92 TextExampleView() | 92 TextExampleView() |
93 : font_(ResourceBundle::GetSharedInstance().GetFont( | 93 : font_(ResourceBundle::GetSharedInstance().GetFont( |
94 ResourceBundle::BaseFont)), | 94 ResourceBundle::BaseFont)), |
95 text_(ASCIIToUTF16(kShortText)), | 95 text_(ASCIIToUTF16(kShortText)), |
96 text_flags_(0), | 96 text_flags_(0), |
97 halo_(false), | 97 halo_(false), |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 example_combobox_model_.push_back(combobox_model); | 195 example_combobox_model_.push_back(combobox_model); |
196 Combobox* combobox = new Combobox(combobox_model); | 196 Combobox* combobox = new Combobox(combobox_model); |
197 combobox->SetSelectedIndex(0); | 197 combobox->SetSelectedIndex(0); |
198 combobox->set_listener(this); | 198 combobox->set_listener(this); |
199 layout->AddView(combobox, kNumColumns - 1, 1); | 199 layout->AddView(combobox, kNumColumns - 1, 1); |
200 return combobox; | 200 return combobox; |
201 } | 201 } |
202 | 202 |
203 void TextExample::CreateExampleView(View* container) { | 203 void TextExample::CreateExampleView(View* container) { |
204 text_view_ = new TextExampleView; | 204 text_view_ = new TextExampleView; |
205 text_view_->set_border(views::Border::CreateSolidBorder(1, SK_ColorGRAY)); | 205 text_view_->set_border(Border::CreateSolidBorder(1, SK_ColorGRAY)); |
206 | 206 |
207 GridLayout* layout = new GridLayout(container); | 207 GridLayout* layout = new GridLayout(container); |
208 container->SetLayoutManager(layout); | 208 container->SetLayoutManager(layout); |
209 | 209 |
210 layout->AddPaddingRow(0, 8); | 210 layout->AddPaddingRow(0, 8); |
211 | 211 |
212 ColumnSet* column_set = layout->AddColumnSet(0); | 212 ColumnSet* column_set = layout->AddColumnSet(0); |
213 column_set->AddPaddingColumn(0, 8); | 213 column_set->AddPaddingColumn(0, 8); |
214 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, | 214 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, |
215 0.1f, GridLayout::USE_PREF, 0, 0); | 215 0.1f, GridLayout::USE_PREF, 0, 0); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 text_flags |= gfx::Canvas::HIDE_PREFIX; | 366 text_flags |= gfx::Canvas::HIDE_PREFIX; |
367 break; | 367 break; |
368 } | 368 } |
369 } | 369 } |
370 text_view_->set_text_flags(text_flags); | 370 text_view_->set_text_flags(text_flags); |
371 text_view_->SchedulePaint(); | 371 text_view_->SchedulePaint(); |
372 } | 372 } |
373 | 373 |
374 } // namespace examples | 374 } // namespace examples |
375 } // namespace views | 375 } // namespace views |
OLD | NEW |