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 ? |
bryeung
2011/12/02 16:22:28
I'd rather not duplicate the logic of IsPassword h
benrg
2011/12/02 18:21:41
I did it that way to avoid calling a method while
| |
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 { | 101 bool Textfield::IsPassword() const { |
103 return style_ & STYLE_PASSWORD; | 102 return style_ & STYLE_PASSWORD; |
104 } | 103 } |
105 | 104 |
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 { | 105 ui::TextInputType Textfield::GetTextInputType() const { |
120 if (read_only() || !IsEnabled()) | 106 if (read_only() || !IsEnabled()) |
121 return ui::TEXT_INPUT_TYPE_NONE; | 107 return ui::TEXT_INPUT_TYPE_NONE; |
122 return text_input_type_; | 108 return text_input_type_; |
123 } | 109 } |
124 | 110 |
125 void Textfield::SetTextInputType(ui::TextInputType type) { | 111 void Textfield::SetTextInputType(ui::TextInputType type) { |
112 bool was_password = IsPassword(); | |
113 bool will_be_password = type == ui::TEXT_INPUT_TYPE_PASSWORD; | |
126 text_input_type_ = type; | 114 text_input_type_ = type; |
127 bool should_be_password = type == ui::TEXT_INPUT_TYPE_PASSWORD; | 115 if (was_password != will_be_password) { |
128 if (IsPassword() != should_be_password) | 116 style_ = static_cast<StyleFlags>(style_ ^ STYLE_PASSWORD); |
129 SetPassword(should_be_password); | 117 if (native_wrapper_) |
118 native_wrapper_->UpdateIsPassword(); | |
119 } | |
130 } | 120 } |
131 | 121 |
132 void Textfield::SetText(const string16& text) { | 122 void Textfield::SetText(const string16& text) { |
133 text_ = text; | 123 text_ = text; |
134 if (native_wrapper_) | 124 if (native_wrapper_) |
135 native_wrapper_->UpdateText(); | 125 native_wrapper_->UpdateText(); |
136 } | 126 } |
137 | 127 |
138 void Textfield::AppendText(const string16& text) { | 128 void Textfield::AppendText(const string16& text) { |
139 text_ += text; | 129 text_ += text; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 } | 434 } |
445 #endif | 435 #endif |
446 } | 436 } |
447 } | 437 } |
448 | 438 |
449 std::string Textfield::GetClassName() const { | 439 std::string Textfield::GetClassName() const { |
450 return kViewClassName; | 440 return kViewClassName; |
451 } | 441 } |
452 | 442 |
453 } // namespace views | 443 } // namespace views |
OLD | NEW |