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 "views/examples/textfield_example.h" | 5 #include "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 "views/controls/label.h" | 10 #include "views/controls/label.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 PrintStatus(L"Password [%ls]", UTF16ToWideHack(password_->text()).c_str()); | 83 PrintStatus(L"Password [%ls]", UTF16ToWideHack(password_->text()).c_str()); |
84 } else if (sender == clear_all_) { | 84 } else if (sender == clear_all_) { |
85 string16 empty; | 85 string16 empty; |
86 name_->SetText(empty); | 86 name_->SetText(empty); |
87 password_->SetText(empty); | 87 password_->SetText(empty); |
88 } else if (sender == append_) { | 88 } else if (sender == append_) { |
89 name_->AppendText(WideToUTF16(L"[append]")); | 89 name_->AppendText(WideToUTF16(L"[append]")); |
90 } else if (sender == set_) { | 90 } else if (sender == set_) { |
91 name_->SetText(WideToUTF16(L"[set]")); | 91 name_->SetText(WideToUTF16(L"[set]")); |
92 } else if (sender == set_style_) { | 92 } else if (sender == set_style_) { |
93 gfx::StyleRange color; | 93 if (!name_->text().empty()) { |
94 color.foreground = SK_ColorYELLOW; | 94 gfx::StyleRange color; |
95 color.range = ui::Range(0, 11); | 95 color.foreground = SK_ColorYELLOW; |
96 name_->ApplyStyleRange(color); | 96 color.range = ui::Range(0, name_->text().length()); |
| 97 name_->ApplyStyleRange(color); |
97 | 98 |
98 gfx::StyleRange underline; | 99 if (name_->text().length() >= 5) { |
99 underline.underline = true; | 100 size_t fifth = name_->text().length() / 5; |
100 underline.foreground = SK_ColorBLUE; | 101 gfx::StyleRange underline; |
101 underline.range = ui::Range(1, 7); | 102 underline.underline = true; |
102 name_->ApplyStyleRange(underline); | 103 underline.foreground = SK_ColorBLUE; |
| 104 underline.range = ui::Range(1 * fifth, 4 * fifth); |
| 105 name_->ApplyStyleRange(underline); |
103 | 106 |
104 gfx::StyleRange strike; | 107 gfx::StyleRange strike; |
105 strike.strike = true; | 108 strike.strike = true; |
106 strike.foreground = SK_ColorRED; | 109 strike.foreground = SK_ColorRED; |
107 strike.range = ui::Range(6, 9); | 110 strike.range = ui::Range(2 * fifth, 3 * fifth); |
108 name_->ApplyStyleRange(strike); | 111 name_->ApplyStyleRange(strike); |
| 112 } |
| 113 } |
109 } | 114 } |
110 } | 115 } |
111 | 116 |
112 } // namespace examples | 117 } // namespace examples |
OLD | NEW |