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

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

Issue 2228593002: Implement Harmony textfield border (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tapted to the resuce Created 4 years, 4 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/range/range.h" 12 #include "ui/gfx/range/range.h"
12 #include "ui/gfx/render_text.h" 13 #include "ui/gfx/render_text.h"
13 #include "ui/views/controls/button/label_button.h" 14 #include "ui/views/controls/button/label_button.h"
14 #include "ui/views/controls/label.h" 15 #include "ui/views/controls/label.h"
15 #include "ui/views/controls/textfield/textfield.h" 16 #include "ui/views/controls/textfield/textfield.h"
16 #include "ui/views/layout/grid_layout.h" 17 #include "ui/views/layout/grid_layout.h"
17 #include "ui/views/view.h" 18 #include "ui/views/view.h"
18 19
19 using base::ASCIIToUTF16; 20 using base::ASCIIToUTF16;
20 using base::UTF16ToUTF8; 21 using base::UTF16ToUTF8;
(...skipping 18 matching lines...) Expand all
39 40
40 void TextfieldExample::CreateExampleView(View* container) { 41 void TextfieldExample::CreateExampleView(View* container) {
41 name_ = new Textfield(); 42 name_ = new Textfield();
42 password_ = new Textfield(); 43 password_ = new Textfield();
43 password_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 44 password_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
44 password_->set_placeholder_text(ASCIIToUTF16("password")); 45 password_->set_placeholder_text(ASCIIToUTF16("password"));
45 read_only_ = new Textfield(); 46 read_only_ = new Textfield();
46 read_only_->SetReadOnly(true); 47 read_only_->SetReadOnly(true);
47 read_only_->SetText(ASCIIToUTF16("read only")); 48 read_only_->SetText(ASCIIToUTF16("read only"));
48 show_password_ = new LabelButton(this, ASCIIToUTF16("Show password")); 49 show_password_ = new LabelButton(this, ASCIIToUTF16("Show password"));
50 set_background_ =
51 new LabelButton(this, ASCIIToUTF16("Set non-default background"));
49 clear_all_ = new LabelButton(this, ASCIIToUTF16("Clear All")); 52 clear_all_ = new LabelButton(this, ASCIIToUTF16("Clear All"));
50 append_ = new LabelButton(this, ASCIIToUTF16("Append")); 53 append_ = new LabelButton(this, ASCIIToUTF16("Append"));
51 set_ = new LabelButton(this, ASCIIToUTF16("Set")); 54 set_ = new LabelButton(this, ASCIIToUTF16("Set"));
52 set_style_ = new LabelButton(this, ASCIIToUTF16("Set Styles")); 55 set_style_ = new LabelButton(this, ASCIIToUTF16("Set Styles"));
53 name_->set_controller(this); 56 name_->set_controller(this);
54 password_->set_controller(this); 57 password_->set_controller(this);
55 58
56 GridLayout* layout = new GridLayout(container); 59 GridLayout* layout = new GridLayout(container);
57 container->SetLayoutManager(layout); 60 container->SetLayoutManager(layout);
58 61
59 ColumnSet* column_set = layout->AddColumnSet(0); 62 ColumnSet* column_set = layout->AddColumnSet(0);
60 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 63 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL,
61 0.2f, GridLayout::USE_PREF, 0, 0); 64 0.2f, GridLayout::USE_PREF, 0, 0);
62 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 65 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
63 0.8f, GridLayout::USE_PREF, 0, 0); 66 0.8f, GridLayout::USE_PREF, 0, 0);
64 layout->StartRow(0, 0); 67
65 layout->AddView(new Label(ASCIIToUTF16("Name:"))); 68 auto MakeRow = [layout](View* view1, View* view2) {
66 layout->AddView(name_); 69 layout->StartRowWithPadding(0, 0, 0, 5);
67 layout->StartRow(0, 0); 70 layout->AddView(view1);
68 layout->AddView(new Label(ASCIIToUTF16("Password:"))); 71 if (view2)
69 layout->AddView(password_); 72 layout->AddView(view2);
70 layout->StartRow(0, 0); 73 };
71 layout->AddView(new Label(ASCIIToUTF16("Read Only:"))); 74 MakeRow(new Label(ASCIIToUTF16("Name:")), name_);
72 layout->AddView(read_only_); 75 MakeRow(new Label(ASCIIToUTF16("Password:")), password_);
73 layout->StartRow(0, 0); 76 MakeRow(new Label(ASCIIToUTF16("Read Only:")), read_only_);
74 layout->AddView(show_password_); 77 MakeRow(new Label(ASCIIToUTF16("Name:")), nullptr);
75 layout->StartRow(0, 0); 78 MakeRow(show_password_, nullptr);
76 layout->AddView(clear_all_); 79 MakeRow(set_background_, nullptr);
77 layout->StartRow(0, 0); 80 MakeRow(clear_all_, nullptr);
78 layout->AddView(append_); 81 MakeRow(append_, nullptr);
79 layout->StartRow(0, 0); 82 MakeRow(set_, nullptr);
80 layout->AddView(set_); 83 MakeRow(set_style_, nullptr);
81 layout->StartRow(0, 0);
82 layout->AddView(set_style_);
83 } 84 }
84 85
85 void TextfieldExample::ContentsChanged(Textfield* sender, 86 void TextfieldExample::ContentsChanged(Textfield* sender,
86 const base::string16& new_contents) { 87 const base::string16& new_contents) {
87 if (sender == name_) { 88 if (sender == name_) {
88 PrintStatus("Name [%s]", UTF16ToUTF8(new_contents).c_str()); 89 PrintStatus("Name [%s]", UTF16ToUTF8(new_contents).c_str());
89 } else if (sender == password_) { 90 } else if (sender == password_) {
90 PrintStatus("Password [%s]", UTF16ToUTF8(new_contents).c_str()); 91 PrintStatus("Password [%s]", UTF16ToUTF8(new_contents).c_str());
91 } else if (sender == read_only_) { 92 } else if (sender == read_only_) {
92 PrintStatus("Read Only [%s]", UTF16ToUTF8(new_contents).c_str()); 93 PrintStatus("Read Only [%s]", UTF16ToUTF8(new_contents).c_str());
93 } 94 }
94 } 95 }
95 96
96 bool TextfieldExample::HandleKeyEvent(Textfield* sender, 97 bool TextfieldExample::HandleKeyEvent(Textfield* sender,
97 const ui::KeyEvent& key_event) { 98 const ui::KeyEvent& key_event) {
98 return false; 99 return false;
99 } 100 }
100 101
101 bool TextfieldExample::HandleMouseEvent(Textfield* sender, 102 bool TextfieldExample::HandleMouseEvent(Textfield* sender,
102 const ui::MouseEvent& mouse_event) { 103 const ui::MouseEvent& mouse_event) {
103 PrintStatus("HandleMouseEvent click count=%d", mouse_event.GetClickCount()); 104 PrintStatus("HandleMouseEvent click count=%d", mouse_event.GetClickCount());
104 return false; 105 return false;
105 } 106 }
106 107
107 void TextfieldExample::ButtonPressed(Button* sender, const ui::Event& event) { 108 void TextfieldExample::ButtonPressed(Button* sender, const ui::Event& event) {
108 if (sender == show_password_) { 109 if (sender == show_password_) {
109 PrintStatus("Password [%s]", UTF16ToUTF8(password_->text()).c_str()); 110 PrintStatus("Password [%s]", UTF16ToUTF8(password_->text()).c_str());
111 } else if (sender == set_background_) {
112 password_->SetBackgroundColor(gfx::kGoogleRed300);
110 } else if (sender == clear_all_) { 113 } else if (sender == clear_all_) {
111 base::string16 empty; 114 base::string16 empty;
112 name_->SetText(empty); 115 name_->SetText(empty);
113 password_->SetText(empty); 116 password_->SetText(empty);
114 read_only_->SetText(empty); 117 read_only_->SetText(empty);
115 } else if (sender == append_) { 118 } else if (sender == append_) {
116 name_->AppendText(ASCIIToUTF16("[append]")); 119 name_->AppendText(ASCIIToUTF16("[append]"));
117 password_->AppendText(ASCIIToUTF16("[append]")); 120 password_->AppendText(ASCIIToUTF16("[append]"));
118 read_only_->AppendText(ASCIIToUTF16("[append]")); 121 read_only_->AppendText(ASCIIToUTF16("[append]"));
119 } else if (sender == set_) { 122 } else if (sender == set_) {
(...skipping 15 matching lines...) Expand all
135 name_->ApplyStyle(gfx::UNDERLINE, false, small_range); 138 name_->ApplyStyle(gfx::UNDERLINE, false, small_range);
136 name_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, small_range); 139 name_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, small_range);
137 name_->ApplyColor(SK_ColorRED, small_range); 140 name_->ApplyColor(SK_ColorRED, small_range);
138 } 141 }
139 } 142 }
140 } 143 }
141 } 144 }
142 145
143 } // namespace examples 146 } // namespace examples
144 } // namespace views 147 } // 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