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

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

Issue 2406363003: Update appearance of invalid textfields in Harmony. (Closed)
Patch Set: combine install with setcolorid Created 4 years, 2 months 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
« no previous file with comments | « ui/views/examples/textfield_example.h ('k') | no next file » | 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) 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/textfield_example.h" 5 #include "ui/views/examples/textfield_example.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/events/event.h" 10 #include "ui/events/event.h"
11 #include "ui/gfx/color_palette.h" 11 #include "ui/gfx/color_palette.h"
12 #include "ui/gfx/range/range.h" 12 #include "ui/gfx/range/range.h"
13 #include "ui/gfx/render_text.h" 13 #include "ui/gfx/render_text.h"
14 #include "ui/views/controls/button/label_button.h" 14 #include "ui/views/controls/button/label_button.h"
15 #include "ui/views/controls/label.h" 15 #include "ui/views/controls/label.h"
16 #include "ui/views/controls/textfield/textfield.h" 16 #include "ui/views/controls/textfield/textfield.h"
17 #include "ui/views/layout/grid_layout.h" 17 #include "ui/views/layout/grid_layout.h"
18 #include "ui/views/view.h" 18 #include "ui/views/view.h"
19 19
20 using base::ASCIIToUTF16; 20 using base::ASCIIToUTF16;
21 using base::UTF16ToUTF8; 21 using base::UTF16ToUTF8;
22 22
23 namespace views { 23 namespace views {
24 namespace examples { 24 namespace examples {
25 25
26 TextfieldExample::TextfieldExample() 26 TextfieldExample::TextfieldExample()
27 : ExampleBase("Textfield"), 27 : ExampleBase("Textfield"),
28 name_(nullptr), 28 name_(nullptr),
29 password_(nullptr), 29 password_(nullptr),
30 disabled_(nullptr), 30 disabled_(nullptr),
31 read_only_(nullptr), 31 read_only_(nullptr),
32 show_password_(nullptr), 32 invalid_(nullptr),
33 clear_all_(nullptr), 33 show_password_(nullptr),
34 append_(nullptr), 34 clear_all_(nullptr),
35 set_(nullptr), 35 append_(nullptr),
36 set_style_(nullptr) { 36 set_(nullptr),
37 } 37 set_style_(nullptr) {}
38 38
39 TextfieldExample::~TextfieldExample() { 39 TextfieldExample::~TextfieldExample() {}
40 }
41 40
42 void TextfieldExample::CreateExampleView(View* container) { 41 void TextfieldExample::CreateExampleView(View* container) {
43 name_ = new Textfield(); 42 name_ = new Textfield();
44 password_ = new Textfield(); 43 password_ = new Textfield();
45 password_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 44 password_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
46 password_->set_placeholder_text(ASCIIToUTF16("password")); 45 password_->set_placeholder_text(ASCIIToUTF16("password"));
47 disabled_ = new Textfield(); 46 disabled_ = new Textfield();
48 disabled_->SetEnabled(false); 47 disabled_->SetEnabled(false);
49 disabled_->SetText(ASCIIToUTF16("disabled")); 48 disabled_->SetText(ASCIIToUTF16("disabled"));
50 read_only_ = new Textfield(); 49 read_only_ = new Textfield();
51 read_only_->SetReadOnly(true); 50 read_only_->SetReadOnly(true);
52 read_only_->SetText(ASCIIToUTF16("read only")); 51 read_only_->SetText(ASCIIToUTF16("read only"));
52 invalid_ = new Textfield();
53 invalid_->SetInvalid(true);
53 show_password_ = new LabelButton(this, ASCIIToUTF16("Show password")); 54 show_password_ = new LabelButton(this, ASCIIToUTF16("Show password"));
54 set_background_ = 55 set_background_ =
55 new LabelButton(this, ASCIIToUTF16("Set non-default background")); 56 new LabelButton(this, ASCIIToUTF16("Set non-default background"));
56 clear_all_ = new LabelButton(this, ASCIIToUTF16("Clear All")); 57 clear_all_ = new LabelButton(this, ASCIIToUTF16("Clear All"));
57 append_ = new LabelButton(this, ASCIIToUTF16("Append")); 58 append_ = new LabelButton(this, ASCIIToUTF16("Append"));
58 set_ = new LabelButton(this, ASCIIToUTF16("Set")); 59 set_ = new LabelButton(this, ASCIIToUTF16("Set"));
59 set_style_ = new LabelButton(this, ASCIIToUTF16("Set Styles")); 60 set_style_ = new LabelButton(this, ASCIIToUTF16("Set Styles"));
60 name_->set_controller(this); 61 name_->set_controller(this);
61 password_->set_controller(this); 62 password_->set_controller(this);
62 63
63 GridLayout* layout = new GridLayout(container); 64 GridLayout* layout = new GridLayout(container);
64 container->SetLayoutManager(layout); 65 container->SetLayoutManager(layout);
65 66
66 ColumnSet* column_set = layout->AddColumnSet(0); 67 ColumnSet* column_set = layout->AddColumnSet(0);
67 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 68 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL,
68 0.2f, GridLayout::USE_PREF, 0, 0); 69 0.2f, GridLayout::USE_PREF, 0, 0);
69 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 70 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
70 0.8f, GridLayout::USE_PREF, 0, 0); 71 0.8f, GridLayout::USE_PREF, 0, 0);
71 72
72 auto MakeRow = [layout](View* view1, View* view2) { 73 auto MakeRow = [layout](View* view1, View* view2) {
73 layout->StartRowWithPadding(0, 0, 0, 5); 74 layout->StartRowWithPadding(0, 0, 0, 5);
74 layout->AddView(view1); 75 layout->AddView(view1);
75 if (view2) 76 if (view2)
76 layout->AddView(view2); 77 layout->AddView(view2);
77 }; 78 };
78 MakeRow(new Label(ASCIIToUTF16("Name:")), name_); 79 MakeRow(new Label(ASCIIToUTF16("Name:")), name_);
79 MakeRow(new Label(ASCIIToUTF16("Password:")), password_); 80 MakeRow(new Label(ASCIIToUTF16("Password:")), password_);
80 MakeRow(new Label(ASCIIToUTF16("Disabled:")), disabled_); 81 MakeRow(new Label(ASCIIToUTF16("Disabled:")), disabled_);
81 MakeRow(new Label(ASCIIToUTF16("Read Only:")), read_only_); 82 MakeRow(new Label(ASCIIToUTF16("Read Only:")), read_only_);
83 MakeRow(new Label(ASCIIToUTF16("Invalid:")), invalid_);
82 MakeRow(new Label(ASCIIToUTF16("Name:")), nullptr); 84 MakeRow(new Label(ASCIIToUTF16("Name:")), nullptr);
83 MakeRow(show_password_, nullptr); 85 MakeRow(show_password_, nullptr);
84 MakeRow(set_background_, nullptr); 86 MakeRow(set_background_, nullptr);
85 MakeRow(clear_all_, nullptr); 87 MakeRow(clear_all_, nullptr);
86 MakeRow(append_, nullptr); 88 MakeRow(append_, nullptr);
87 MakeRow(set_, nullptr); 89 MakeRow(set_, nullptr);
88 MakeRow(set_style_, nullptr); 90 MakeRow(set_style_, nullptr);
89 } 91 }
90 92
91 void TextfieldExample::ContentsChanged(Textfield* sender, 93 void TextfieldExample::ContentsChanged(Textfield* sender,
(...skipping 22 matching lines...) Expand all
114 if (sender == show_password_) { 116 if (sender == show_password_) {
115 PrintStatus("Password [%s]", UTF16ToUTF8(password_->text()).c_str()); 117 PrintStatus("Password [%s]", UTF16ToUTF8(password_->text()).c_str());
116 } else if (sender == set_background_) { 118 } else if (sender == set_background_) {
117 password_->SetBackgroundColor(gfx::kGoogleRed300); 119 password_->SetBackgroundColor(gfx::kGoogleRed300);
118 } else if (sender == clear_all_) { 120 } else if (sender == clear_all_) {
119 base::string16 empty; 121 base::string16 empty;
120 name_->SetText(empty); 122 name_->SetText(empty);
121 password_->SetText(empty); 123 password_->SetText(empty);
122 disabled_->SetText(empty); 124 disabled_->SetText(empty);
123 read_only_->SetText(empty); 125 read_only_->SetText(empty);
126 invalid_->SetText(empty);
124 } else if (sender == append_) { 127 } else if (sender == append_) {
125 name_->AppendText(ASCIIToUTF16("[append]")); 128 name_->AppendText(ASCIIToUTF16("[append]"));
126 password_->AppendText(ASCIIToUTF16("[append]")); 129 password_->AppendText(ASCIIToUTF16("[append]"));
127 disabled_->SetText(ASCIIToUTF16("[append]")); 130 disabled_->SetText(ASCIIToUTF16("[append]"));
128 read_only_->AppendText(ASCIIToUTF16("[append]")); 131 read_only_->AppendText(ASCIIToUTF16("[append]"));
132 invalid_->AppendText(ASCIIToUTF16("[append]"));
129 } else if (sender == set_) { 133 } else if (sender == set_) {
130 name_->SetText(ASCIIToUTF16("[set]")); 134 name_->SetText(ASCIIToUTF16("[set]"));
131 password_->SetText(ASCIIToUTF16("[set]")); 135 password_->SetText(ASCIIToUTF16("[set]"));
132 disabled_->SetText(ASCIIToUTF16("[set]")); 136 disabled_->SetText(ASCIIToUTF16("[set]"));
133 read_only_->SetText(ASCIIToUTF16("[set]")); 137 read_only_->SetText(ASCIIToUTF16("[set]"));
138 invalid_->SetText(ASCIIToUTF16("[set]"));
134 } else if (sender == set_style_) { 139 } else if (sender == set_style_) {
135 if (!name_->text().empty()) { 140 if (!name_->text().empty()) {
136 name_->SetColor(SK_ColorGREEN); 141 name_->SetColor(SK_ColorGREEN);
137 142
138 if (name_->text().length() >= 5) { 143 if (name_->text().length() >= 5) {
139 size_t fifth = name_->text().length() / 5; 144 size_t fifth = name_->text().length() / 5;
140 const gfx::Range big_range(1 * fifth, 4 * fifth); 145 const gfx::Range big_range(1 * fifth, 4 * fifth);
141 name_->ApplyStyle(gfx::UNDERLINE, true, big_range); 146 name_->ApplyStyle(gfx::UNDERLINE, true, big_range);
142 name_->ApplyColor(SK_ColorBLUE, big_range); 147 name_->ApplyColor(SK_ColorBLUE, big_range);
143 148
144 const gfx::Range small_range(2 * fifth, 3 * fifth); 149 const gfx::Range small_range(2 * fifth, 3 * fifth);
145 name_->ApplyStyle(gfx::ITALIC, true, small_range); 150 name_->ApplyStyle(gfx::ITALIC, true, small_range);
146 name_->ApplyStyle(gfx::UNDERLINE, false, small_range); 151 name_->ApplyStyle(gfx::UNDERLINE, false, small_range);
147 name_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, small_range); 152 name_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, small_range);
148 name_->ApplyColor(SK_ColorRED, small_range); 153 name_->ApplyColor(SK_ColorRED, small_range);
149 } 154 }
150 } 155 }
151 } 156 }
152 } 157 }
153 158
154 } // namespace examples 159 } // namespace examples
155 } // namespace views 160 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/textfield_example.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698