| OLD | NEW |
| 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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
| 9 #include "ui/gfx/range/range.h" | 9 #include "ui/gfx/range/range.h" |
| 10 #include "ui/gfx/render_text.h" | 10 #include "ui/gfx/render_text.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool TextfieldExample::HandleMouseEvent(Textfield* sender, | 98 bool TextfieldExample::HandleMouseEvent(Textfield* sender, |
| 99 const ui::MouseEvent& mouse_event) { | 99 const ui::MouseEvent& mouse_event) { |
| 100 PrintStatus("HandleMouseEvent click count=%d", mouse_event.GetClickCount()); | 100 PrintStatus("HandleMouseEvent click count=%d", mouse_event.GetClickCount()); |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 | 103 |
| 104 void TextfieldExample::ButtonPressed(Button* sender, const ui::Event& event) { | 104 void TextfieldExample::ButtonPressed(Button* sender, const ui::Event& event) { |
| 105 if (sender == show_password_) { | 105 if (sender == show_password_) { |
| 106 PrintStatus("Password [%s]", UTF16ToUTF8(password_->text()).c_str()); | 106 PrintStatus("Password [%s]", UTF16ToUTF8(password_->GetText()).c_str()); |
| 107 } else if (sender == clear_all_) { | 107 } else if (sender == clear_all_) { |
| 108 base::string16 empty; | 108 base::string16 empty; |
| 109 name_->SetText(empty); | 109 name_->SetText(empty); |
| 110 password_->SetText(empty); | 110 password_->SetText(empty); |
| 111 read_only_->SetText(empty); | 111 read_only_->SetText(empty); |
| 112 } else if (sender == append_) { | 112 } else if (sender == append_) { |
| 113 name_->AppendText(ASCIIToUTF16("[append]")); | 113 name_->AppendText(ASCIIToUTF16("[append]")); |
| 114 password_->AppendText(ASCIIToUTF16("[append]")); | 114 password_->AppendText(ASCIIToUTF16("[append]")); |
| 115 read_only_->AppendText(ASCIIToUTF16("[append]")); | 115 read_only_->AppendText(ASCIIToUTF16("[append]")); |
| 116 } else if (sender == set_) { | 116 } else if (sender == set_) { |
| 117 name_->SetText(ASCIIToUTF16("[set]")); | 117 name_->SetText(ASCIIToUTF16("[set]")); |
| 118 password_->SetText(ASCIIToUTF16("[set]")); | 118 password_->SetText(ASCIIToUTF16("[set]")); |
| 119 read_only_->SetText(ASCIIToUTF16("[set]")); | 119 read_only_->SetText(ASCIIToUTF16("[set]")); |
| 120 } else if (sender == set_style_) { | 120 } else if (sender == set_style_) { |
| 121 if (!name_->text().empty()) { | 121 if (!name_->GetText().empty()) { |
| 122 name_->SetColor(SK_ColorGREEN); | 122 name_->SetColor(SK_ColorGREEN); |
| 123 name_->SetStyle(gfx::BOLD, true); | 123 name_->SetStyle(gfx::BOLD, true); |
| 124 | 124 |
| 125 if (name_->text().length() >= 5) { | 125 if (name_->GetText().length() >= 5) { |
| 126 size_t fifth = name_->text().length() / 5; | 126 size_t fifth = name_->GetText().length() / 5; |
| 127 const gfx::Range big_range(1 * fifth, 4 * fifth); | 127 const gfx::Range big_range(1 * fifth, 4 * fifth); |
| 128 name_->ApplyStyle(gfx::BOLD, false, big_range); | 128 name_->ApplyStyle(gfx::BOLD, false, big_range); |
| 129 name_->ApplyStyle(gfx::UNDERLINE, true, big_range); | 129 name_->ApplyStyle(gfx::UNDERLINE, true, big_range); |
| 130 name_->ApplyColor(SK_ColorBLUE, big_range); | 130 name_->ApplyColor(SK_ColorBLUE, big_range); |
| 131 | 131 |
| 132 const gfx::Range small_range(2 * fifth, 3 * fifth); | 132 const gfx::Range small_range(2 * fifth, 3 * fifth); |
| 133 name_->ApplyStyle(gfx::ITALIC, true, small_range); | 133 name_->ApplyStyle(gfx::ITALIC, true, small_range); |
| 134 name_->ApplyStyle(gfx::UNDERLINE, false, small_range); | 134 name_->ApplyStyle(gfx::UNDERLINE, false, small_range); |
| 135 name_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, small_range); | 135 name_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, small_range); |
| 136 name_->ApplyColor(SK_ColorRED, small_range); | 136 name_->ApplyColor(SK_ColorRED, small_range); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace examples | 142 } // namespace examples |
| 143 } // namespace views | 143 } // namespace views |
| OLD | NEW |