| OLD | NEW |
| 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/textfield_example.h" | 5 #include "ui/views/examples/textfield_example.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "ui/base/range/range.h" | 8 #include "ui/base/range/range.h" |
| 9 #include "ui/gfx/render_text.h" | 9 #include "ui/gfx/render_text.h" |
| 10 #include "ui/views/controls/textfield/textfield.h" | 10 #include "ui/views/controls/textfield/textfield.h" |
| 11 #include "ui/views/layout/grid_layout.h" | 11 #include "ui/views/layout/grid_layout.h" |
| 12 #include "views/controls/label.h" | 12 #include "views/controls/label.h" |
| 13 #include "views/view.h" | 13 #include "views/view.h" |
| 14 | 14 |
| 15 namespace views { |
| 15 namespace examples { | 16 namespace examples { |
| 16 | 17 |
| 17 TextfieldExample::TextfieldExample(ExamplesMain* main) | 18 TextfieldExample::TextfieldExample() : ExampleBase("Textfield") { |
| 18 : ExampleBase(main, "Textfield") { | |
| 19 } | 19 } |
| 20 | 20 |
| 21 TextfieldExample::~TextfieldExample() { | 21 TextfieldExample::~TextfieldExample() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 void TextfieldExample::CreateExampleView(views::View* container) { | 24 void TextfieldExample::CreateExampleView(View* container) { |
| 25 name_ = new views::Textfield(); | 25 name_ = new Textfield(); |
| 26 password_ = new views::Textfield(views::Textfield::STYLE_PASSWORD); | 26 password_ = new Textfield(Textfield::STYLE_PASSWORD); |
| 27 password_->set_text_to_display_when_empty(ASCIIToUTF16("password")); | 27 password_->set_text_to_display_when_empty(ASCIIToUTF16("password")); |
| 28 show_password_ = new views::TextButton(this, ASCIIToUTF16("Show password")); | 28 show_password_ = new TextButton(this, ASCIIToUTF16("Show password")); |
| 29 clear_all_ = new views::TextButton(this, ASCIIToUTF16("Clear All")); | 29 clear_all_ = new TextButton(this, ASCIIToUTF16("Clear All")); |
| 30 append_ = new views::TextButton(this, ASCIIToUTF16("Append")); | 30 append_ = new TextButton(this, ASCIIToUTF16("Append")); |
| 31 set_ = new views::TextButton(this, ASCIIToUTF16("Set")); | 31 set_ = new TextButton(this, ASCIIToUTF16("Set")); |
| 32 set_style_ = new views::TextButton(this, ASCIIToUTF16("Set Styles")); | 32 set_style_ = new TextButton(this, ASCIIToUTF16("Set Styles")); |
| 33 name_->SetController(this); | 33 name_->SetController(this); |
| 34 password_->SetController(this); | 34 password_->SetController(this); |
| 35 | 35 |
| 36 views::GridLayout* layout = new views::GridLayout(container); | 36 GridLayout* layout = new GridLayout(container); |
| 37 container->SetLayoutManager(layout); | 37 container->SetLayoutManager(layout); |
| 38 | 38 |
| 39 views::ColumnSet* column_set = layout->AddColumnSet(0); | 39 ColumnSet* column_set = layout->AddColumnSet(0); |
| 40 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, | 40 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, |
| 41 0.2f, views::GridLayout::USE_PREF, 0, 0); | 41 0.2f, GridLayout::USE_PREF, 0, 0); |
| 42 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 42 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 43 0.8f, views::GridLayout::USE_PREF, 0, 0); | 43 0.8f, GridLayout::USE_PREF, 0, 0); |
| 44 layout->StartRow(0, 0); | 44 layout->StartRow(0, 0); |
| 45 layout->AddView(new views::Label(ASCIIToUTF16("Name:"))); | 45 layout->AddView(new Label(ASCIIToUTF16("Name:"))); |
| 46 layout->AddView(name_); | 46 layout->AddView(name_); |
| 47 layout->StartRow(0, 0); | 47 layout->StartRow(0, 0); |
| 48 layout->AddView(new views::Label(ASCIIToUTF16("Password:"))); | 48 layout->AddView(new Label(ASCIIToUTF16("Password:"))); |
| 49 layout->AddView(password_); | 49 layout->AddView(password_); |
| 50 layout->StartRow(0, 0); | 50 layout->StartRow(0, 0); |
| 51 layout->AddView(show_password_); | 51 layout->AddView(show_password_); |
| 52 layout->StartRow(0, 0); | 52 layout->StartRow(0, 0); |
| 53 layout->AddView(clear_all_); | 53 layout->AddView(clear_all_); |
| 54 layout->StartRow(0, 0); | 54 layout->StartRow(0, 0); |
| 55 layout->AddView(append_); | 55 layout->AddView(append_); |
| 56 layout->StartRow(0, 0); | 56 layout->StartRow(0, 0); |
| 57 layout->AddView(set_); | 57 layout->AddView(set_); |
| 58 layout->StartRow(0, 0); | 58 layout->StartRow(0, 0); |
| 59 layout->AddView(set_style_); | 59 layout->AddView(set_style_); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void TextfieldExample::ContentsChanged(views::Textfield* sender, | 62 void TextfieldExample::ContentsChanged(Textfield* sender, |
| 63 const string16& new_contents) { | 63 const string16& new_contents) { |
| 64 if (sender == name_) { | 64 if (sender == name_) { |
| 65 PrintStatus("Name [%s]", UTF16ToUTF8(new_contents).c_str()); | 65 PrintStatus("Name [%s]", UTF16ToUTF8(new_contents).c_str()); |
| 66 } else if (sender == password_) { | 66 } else if (sender == password_) { |
| 67 PrintStatus("Password [%s]", UTF16ToUTF8(new_contents).c_str()); | 67 PrintStatus("Password [%s]", UTF16ToUTF8(new_contents).c_str()); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool TextfieldExample::HandleKeyEvent(views::Textfield* sender, | 71 bool TextfieldExample::HandleKeyEvent(Textfield* sender, |
| 72 const views::KeyEvent& key_event) { | 72 const KeyEvent& key_event) { |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void TextfieldExample::ButtonPressed(views::Button* sender, | 76 void TextfieldExample::ButtonPressed(Button* sender, |
| 77 const views::Event& event) { | 77 const Event& event) { |
| 78 if (sender == show_password_) { | 78 if (sender == show_password_) { |
| 79 PrintStatus("Password [%s]", UTF16ToUTF8(password_->text()).c_str()); | 79 PrintStatus("Password [%s]", UTF16ToUTF8(password_->text()).c_str()); |
| 80 } else if (sender == clear_all_) { | 80 } else if (sender == clear_all_) { |
| 81 string16 empty; | 81 string16 empty; |
| 82 name_->SetText(empty); | 82 name_->SetText(empty); |
| 83 password_->SetText(empty); | 83 password_->SetText(empty); |
| 84 } else if (sender == append_) { | 84 } else if (sender == append_) { |
| 85 name_->AppendText(WideToUTF16(L"[append]")); | 85 name_->AppendText(WideToUTF16(L"[append]")); |
| 86 } else if (sender == set_) { | 86 } else if (sender == set_) { |
| 87 name_->SetText(WideToUTF16(L"[set]")); | 87 name_->SetText(WideToUTF16(L"[set]")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 104 strike.strike = true; | 104 strike.strike = true; |
| 105 strike.foreground = SK_ColorRED; | 105 strike.foreground = SK_ColorRED; |
| 106 strike.range = ui::Range(2 * fifth, 3 * fifth); | 106 strike.range = ui::Range(2 * fifth, 3 * fifth); |
| 107 name_->ApplyStyleRange(strike); | 107 name_->ApplyStyleRange(strike); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace examples | 113 } // namespace examples |
| 114 } // namespace views |
| OLD | NEW |