| 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 "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #if defined(TOOLKIT_USES_GTK) | 7 #if defined(TOOLKIT_USES_GTK) |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 read_only_(false), | 66 read_only_(false), |
| 67 default_width_in_chars_(0), | 67 default_width_in_chars_(0), |
| 68 draw_border_(true), | 68 draw_border_(true), |
| 69 text_color_(SK_ColorBLACK), | 69 text_color_(SK_ColorBLACK), |
| 70 use_default_text_color_(true), | 70 use_default_text_color_(true), |
| 71 background_color_(SK_ColorWHITE), | 71 background_color_(SK_ColorWHITE), |
| 72 use_default_background_color_(true), | 72 use_default_background_color_(true), |
| 73 initialized_(false), | 73 initialized_(false), |
| 74 horizontal_margins_were_set_(false), | 74 horizontal_margins_were_set_(false), |
| 75 vertical_margins_were_set_(false), | 75 vertical_margins_were_set_(false), |
| 76 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT) { | 76 text_input_type_(style & STYLE_PASSWORD ? |
| 77 ui::TEXT_INPUT_TYPE_PASSWORD : ui::TEXT_INPUT_TYPE_TEXT) { |
| 77 set_focusable(true); | 78 set_focusable(true); |
| 78 if (IsPassword()) | |
| 79 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
| 80 } | 79 } |
| 81 | 80 |
| 82 Textfield::~Textfield() { | 81 Textfield::~Textfield() { |
| 83 } | 82 } |
| 84 | 83 |
| 85 void Textfield::SetController(TextfieldController* controller) { | 84 void Textfield::SetController(TextfieldController* controller) { |
| 86 controller_ = controller; | 85 controller_ = controller; |
| 87 } | 86 } |
| 88 | 87 |
| 89 TextfieldController* Textfield::GetController() const { | 88 TextfieldController* Textfield::GetController() const { |
| 90 return controller_; | 89 return controller_; |
| 91 } | 90 } |
| 92 | 91 |
| 93 void Textfield::SetReadOnly(bool read_only) { | 92 void Textfield::SetReadOnly(bool read_only) { |
| 94 read_only_ = read_only; | 93 read_only_ = read_only; |
| 95 if (native_wrapper_) { | 94 if (native_wrapper_) { |
| 96 native_wrapper_->UpdateReadOnly(); | 95 native_wrapper_->UpdateReadOnly(); |
| 97 native_wrapper_->UpdateTextColor(); | 96 native_wrapper_->UpdateTextColor(); |
| 98 native_wrapper_->UpdateBackgroundColor(); | 97 native_wrapper_->UpdateBackgroundColor(); |
| 99 } | 98 } |
| 100 } | 99 } |
| 101 | 100 |
| 102 bool Textfield::IsPassword() const { | |
| 103 return style_ & STYLE_PASSWORD; | |
| 104 } | |
| 105 | |
| 106 void Textfield::SetPassword(bool password) { | |
| 107 if (password) { | |
| 108 style_ = static_cast<StyleFlags>(style_ | STYLE_PASSWORD); | |
| 109 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
| 110 } else { | |
| 111 style_ = static_cast<StyleFlags>(style_ & ~STYLE_PASSWORD); | |
| 112 SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); | |
| 113 } | |
| 114 if (native_wrapper_) | |
| 115 native_wrapper_->UpdateIsPassword(); | |
| 116 } | |
| 117 | |
| 118 | |
| 119 ui::TextInputType Textfield::GetTextInputType() const { | 101 ui::TextInputType Textfield::GetTextInputType() const { |
| 120 if (read_only() || !IsEnabled()) | 102 if (read_only() || !IsEnabled()) |
| 121 return ui::TEXT_INPUT_TYPE_NONE; | 103 return ui::TEXT_INPUT_TYPE_NONE; |
| 122 return text_input_type_; | 104 return text_input_type_; |
| 123 } | 105 } |
| 124 | 106 |
| 125 void Textfield::SetTextInputType(ui::TextInputType type) { | 107 void Textfield::SetTextInputType(ui::TextInputType type) { |
| 108 bool was_password = IsPassword(); |
| 109 bool will_be_password = type == ui::TEXT_INPUT_TYPE_PASSWORD; |
| 126 text_input_type_ = type; | 110 text_input_type_ = type; |
| 127 bool should_be_password = type == ui::TEXT_INPUT_TYPE_PASSWORD; | 111 if (was_password != will_be_password) { |
| 128 if (IsPassword() != should_be_password) | 112 style_ = static_cast<StyleFlags>(style_ ^ STYLE_PASSWORD); |
| 129 SetPassword(should_be_password); | 113 if (native_wrapper_) |
| 114 native_wrapper_->UpdateIsPassword(); |
| 115 } |
| 130 } | 116 } |
| 131 | 117 |
| 132 void Textfield::SetText(const string16& text) { | 118 void Textfield::SetText(const string16& text) { |
| 133 text_ = text; | 119 text_ = text; |
| 134 if (native_wrapper_) | 120 if (native_wrapper_) |
| 135 native_wrapper_->UpdateText(); | 121 native_wrapper_->UpdateText(); |
| 136 } | 122 } |
| 137 | 123 |
| 138 void Textfield::AppendText(const string16& text) { | 124 void Textfield::AppendText(const string16& text) { |
| 139 text_ += text; | 125 text_ += text; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 } | 430 } |
| 445 #endif | 431 #endif |
| 446 } | 432 } |
| 447 } | 433 } |
| 448 | 434 |
| 449 std::string Textfield::GetClassName() const { | 435 std::string Textfield::GetClassName() const { |
| 450 return kViewClassName; | 436 return kViewClassName; |
| 451 } | 437 } |
| 452 | 438 |
| 453 } // namespace views | 439 } // namespace views |
| OLD | NEW |