| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyight (c) 2009 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 #ifndef VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_ | 5 #ifndef VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_ |
| 6 #define VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_ | 6 #define VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_ |
| 7 | 7 |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "views/controls/button/text_button.h" | 9 #include "views/controls/button/text_button.h" |
| 10 #include "views/controls/label.h" | 10 #include "views/controls/label.h" |
| 11 #include "views/controls/tabbed_pane/tabbed_pane.h" | 11 #include "views/controls/tabbed_pane/tabbed_pane.h" |
| 12 #include "views/controls/textfield/textfield.h" | 12 #include "views/controls/textfield/textfield.h" |
| 13 #include "views/examples/example_base.h" | 13 #include "views/examples/example_base.h" |
| 14 | 14 |
| 15 namespace examples { | 15 namespace examples { |
| 16 | 16 |
| 17 using views::Textfield; | 17 using views::Textfield; |
| 18 | 18 |
| 19 // TextfieldExample mimics login screen. | 19 // TextfieldExample mimics login screen. |
| 20 class TextfieldExample : protected ExampleBase, | 20 class TextfieldExample : public ExampleBase, |
| 21 private Textfield::Controller, | 21 public Textfield::Controller, |
| 22 private views::ButtonListener { | 22 public views::ButtonListener { |
| 23 public: | 23 public: |
| 24 explicit TextfieldExample(ExamplesMain* main) : ExampleBase(main) { | 24 explicit TextfieldExample(ExamplesMain* main) : ExampleBase(main) {} |
| 25 |
| 26 virtual ~TextfieldExample() {} |
| 27 |
| 28 virtual std::wstring GetExampleTitle() { |
| 29 return L"Textfield"; |
| 30 } |
| 31 |
| 32 virtual void CreateExampleView(views::View* container) { |
| 25 name_ = new Textfield(); | 33 name_ = new Textfield(); |
| 26 password_ = new Textfield(Textfield::STYLE_PASSWORD); | 34 password_ = new Textfield(Textfield::STYLE_PASSWORD); |
| 27 show_password_ = new views::TextButton(this, L"Show password"); | 35 show_password_ = new views::TextButton(this, L"Show password"); |
| 28 clear_all_ = new views::TextButton(this, L"Clear All"); | 36 clear_all_ = new views::TextButton(this, L"Clear All"); |
| 29 append_ = new views::TextButton(this, L"Append"); | 37 append_ = new views::TextButton(this, L"Append"); |
| 30 name_->SetController(this); | 38 name_->SetController(this); |
| 31 password_->SetController(this); | 39 password_->SetController(this); |
| 32 | 40 |
| 33 container_ = new views::View(); | 41 views::GridLayout* layout = new views::GridLayout(container); |
| 34 views::GridLayout* layout = new views::GridLayout(container_); | 42 container->SetLayoutManager(layout); |
| 35 container_->SetLayoutManager(layout); | |
| 36 | 43 |
| 37 views::ColumnSet* column_set = layout->AddColumnSet(0); | 44 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 38 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, | 45 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, |
| 39 0.2f, views::GridLayout::USE_PREF, 0, 0); | 46 0.2f, views::GridLayout::USE_PREF, 0, 0); |
| 40 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 47 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 41 0.8f, views::GridLayout::USE_PREF, 0, 0); | 48 0.8f, views::GridLayout::USE_PREF, 0, 0); |
| 42 layout->StartRow(0, 0); | 49 layout->StartRow(0, 0); |
| 43 layout->AddView(new views::Label(L"Name:")); | 50 layout->AddView(new views::Label(L"Name:")); |
| 44 layout->AddView(name_); | 51 layout->AddView(name_); |
| 45 layout->StartRow(0, 0); | 52 layout->StartRow(0, 0); |
| 46 layout->AddView(new views::Label(L"Password:")); | 53 layout->AddView(new views::Label(L"Password:")); |
| 47 layout->AddView(password_); | 54 layout->AddView(password_); |
| 48 layout->StartRow(0, 0); | 55 layout->StartRow(0, 0); |
| 49 layout->AddView(show_password_); | 56 layout->AddView(show_password_); |
| 50 layout->StartRow(0, 0); | 57 layout->StartRow(0, 0); |
| 51 layout->AddView(clear_all_); | 58 layout->AddView(clear_all_); |
| 52 layout->StartRow(0, 0); | 59 layout->StartRow(0, 0); |
| 53 layout->AddView(append_); | 60 layout->AddView(append_); |
| 54 } | 61 } |
| 55 | 62 |
| 56 virtual ~TextfieldExample() {} | |
| 57 | |
| 58 virtual std::wstring GetExampleTitle() { | |
| 59 return L"Textfield"; | |
| 60 } | |
| 61 | |
| 62 virtual views::View* GetExampleView() { | |
| 63 return container_; | |
| 64 } | |
| 65 | |
| 66 private: | 63 private: |
| 67 // Textfield::Controller implementations: | 64 // Textfield::Controller implementations: |
| 68 // This method is called whenever the text in the field changes. | 65 // This method is called whenever the text in the field changes. |
| 69 virtual void ContentsChanged(Textfield* sender, | 66 virtual void ContentsChanged(Textfield* sender, |
| 70 const string16& new_contents) { | 67 const string16& new_contents) { |
| 71 if (sender == name_) { | 68 if (sender == name_) { |
| 72 PrintStatus(L"Name [%ls]", UTF16ToWideHack(new_contents).c_str()); | 69 PrintStatus(L"Name [%ls]", UTF16ToWideHack(new_contents).c_str()); |
| 73 } else if (sender == password_) { | 70 } else if (sender == password_) { |
| 74 PrintStatus(L"Password [%ls]", UTF16ToWideHack(new_contents).c_str()); | 71 PrintStatus(L"Password [%ls]", UTF16ToWideHack(new_contents).c_str()); |
| 75 } | 72 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 88 UTF16ToWideHack(password_->text()).c_str()); | 85 UTF16ToWideHack(password_->text()).c_str()); |
| 89 } else if (sender == clear_all_) { | 86 } else if (sender == clear_all_) { |
| 90 string16 empty; | 87 string16 empty; |
| 91 name_->SetText(empty); | 88 name_->SetText(empty); |
| 92 password_->SetText(empty); | 89 password_->SetText(empty); |
| 93 } else if (sender == append_) { | 90 } else if (sender == append_) { |
| 94 name_->AppendText(WideToUTF16(L"[append]")); | 91 name_->AppendText(WideToUTF16(L"[append]")); |
| 95 } | 92 } |
| 96 } | 93 } |
| 97 | 94 |
| 98 // The view containing this test's controls. | |
| 99 views::View* container_; | |
| 100 | |
| 101 // Textfields for name and password. | 95 // Textfields for name and password. |
| 102 views::Textfield* name_; | 96 views::Textfield* name_; |
| 103 views::Textfield* password_; | 97 views::Textfield* password_; |
| 104 | 98 |
| 105 // Buttons to show password text and to clear the textfields. | 99 // Buttons to show password text and to clear the textfields. |
| 106 views::TextButton* show_password_; | 100 views::TextButton* show_password_; |
| 107 views::TextButton* clear_all_; | 101 views::TextButton* clear_all_; |
| 108 views::TextButton* append_; | 102 views::TextButton* append_; |
| 109 | 103 |
| 110 DISALLOW_COPY_AND_ASSIGN(TextfieldExample); | 104 DISALLOW_COPY_AND_ASSIGN(TextfieldExample); |
| 111 }; | 105 }; |
| 112 | 106 |
| 113 } // namespace examples | 107 } // namespace examples |
| 114 | 108 |
| 115 #endif // VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_ | 109 #endif // VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_ |
| 110 |
| OLD | NEW |