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

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 8748001: Make text input type and password visibility bit independent in Textfield (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Textfield(STYLE_OBSCURED) sets TEXT_INPUT_TYPE_PASSWORD Created 9 years 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 | Annotate | Revision Log
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_(ui::TEXT_INPUT_TYPE_TEXT) {
77 set_focusable(true); 77 set_focusable(true);
78 if (IsPassword()) 78 if (IsObscured())
79 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 79 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
80 } 80 }
81 81
82 Textfield::~Textfield() { 82 Textfield::~Textfield() {
83 } 83 }
84 84
85 void Textfield::SetController(TextfieldController* controller) { 85 void Textfield::SetController(TextfieldController* controller) {
86 controller_ = controller; 86 controller_ = controller;
87 } 87 }
88 88
89 TextfieldController* Textfield::GetController() const { 89 TextfieldController* Textfield::GetController() const {
90 return controller_; 90 return controller_;
91 } 91 }
92 92
93 void Textfield::SetReadOnly(bool read_only) { 93 void Textfield::SetReadOnly(bool read_only) {
94 read_only_ = read_only; 94 read_only_ = read_only;
95 if (native_wrapper_) { 95 if (native_wrapper_) {
96 native_wrapper_->UpdateReadOnly(); 96 native_wrapper_->UpdateReadOnly();
97 native_wrapper_->UpdateTextColor(); 97 native_wrapper_->UpdateTextColor();
98 native_wrapper_->UpdateBackgroundColor(); 98 native_wrapper_->UpdateBackgroundColor();
99 } 99 }
100 } 100 }
101 101
102 bool Textfield::IsPassword() const { 102 bool Textfield::IsObscured() const {
103 return style_ & STYLE_PASSWORD; 103 return style_ & STYLE_OBSCURED;
104 } 104 }
105 105
106 void Textfield::SetPassword(bool password) { 106 void Textfield::SetObscured(bool obscure) {
107 if (password) { 107 if (obscure != IsObscured()) {
108 style_ = static_cast<StyleFlags>(style_ | STYLE_PASSWORD); 108 style_ = static_cast<StyleFlags>(style_ ^ STYLE_OBSCURED);
109 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 109 if (native_wrapper_)
110 } else { 110 native_wrapper_->UpdateIsObscured();
111 style_ = static_cast<StyleFlags>(style_ & ~STYLE_PASSWORD);
112 SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT);
113 } 111 }
114 if (native_wrapper_)
115 native_wrapper_->UpdateIsPassword();
116 } 112 }
117 113
118
119 ui::TextInputType Textfield::GetTextInputType() const { 114 ui::TextInputType Textfield::GetTextInputType() const {
120 if (read_only() || !IsEnabled()) 115 if (read_only() || !IsEnabled())
121 return ui::TEXT_INPUT_TYPE_NONE; 116 return ui::TEXT_INPUT_TYPE_NONE;
122 return text_input_type_; 117 return text_input_type_;
123 } 118 }
124 119
125 void Textfield::SetTextInputType(ui::TextInputType type) { 120 void Textfield::SetTextInputType(ui::TextInputType type) {
126 text_input_type_ = type; 121 text_input_type_ = type;
127 bool should_be_password = type == ui::TEXT_INPUT_TYPE_PASSWORD;
128 if (IsPassword() != should_be_password)
129 SetPassword(should_be_password);
130 } 122 }
131 123
132 void Textfield::SetText(const string16& text) { 124 void Textfield::SetText(const string16& text) {
133 text_ = text; 125 text_ = text;
134 if (native_wrapper_) 126 if (native_wrapper_)
135 native_wrapper_->UpdateText(); 127 native_wrapper_->UpdateText();
136 } 128 }
137 129
138 void Textfield::AppendText(const string16& text) { 130 void Textfield::AppendText(const string16& text) {
139 text_ += text; 131 text_ += text;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 232
241 void Textfield::UpdateAllProperties() { 233 void Textfield::UpdateAllProperties() {
242 if (native_wrapper_) { 234 if (native_wrapper_) {
243 native_wrapper_->UpdateText(); 235 native_wrapper_->UpdateText();
244 native_wrapper_->UpdateTextColor(); 236 native_wrapper_->UpdateTextColor();
245 native_wrapper_->UpdateBackgroundColor(); 237 native_wrapper_->UpdateBackgroundColor();
246 native_wrapper_->UpdateReadOnly(); 238 native_wrapper_->UpdateReadOnly();
247 native_wrapper_->UpdateFont(); 239 native_wrapper_->UpdateFont();
248 native_wrapper_->UpdateEnabled(); 240 native_wrapper_->UpdateEnabled();
249 native_wrapper_->UpdateBorder(); 241 native_wrapper_->UpdateBorder();
250 native_wrapper_->UpdateIsPassword(); 242 native_wrapper_->UpdateIsObscured();
251 native_wrapper_->UpdateHorizontalMargins(); 243 native_wrapper_->UpdateHorizontalMargins();
252 native_wrapper_->UpdateVerticalMargins(); 244 native_wrapper_->UpdateVerticalMargins();
253 } 245 }
254 } 246 }
255 247
256 void Textfield::SyncText() { 248 void Textfield::SyncText() {
257 if (native_wrapper_) { 249 if (native_wrapper_) {
258 string16 new_text = native_wrapper_->GetText(); 250 string16 new_text = native_wrapper_->GetText();
259 if (new_text != text_) { 251 if (new_text != text_) {
260 text_ = new_text; 252 text_ = new_text;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 void Textfield::OnBlur() { 384 void Textfield::OnBlur() {
393 if (native_wrapper_) 385 if (native_wrapper_)
394 native_wrapper_->HandleBlur(); 386 native_wrapper_->HandleBlur();
395 } 387 }
396 388
397 void Textfield::GetAccessibleState(ui::AccessibleViewState* state) { 389 void Textfield::GetAccessibleState(ui::AccessibleViewState* state) {
398 state->role = ui::AccessibilityTypes::ROLE_TEXT; 390 state->role = ui::AccessibilityTypes::ROLE_TEXT;
399 state->name = accessible_name_; 391 state->name = accessible_name_;
400 if (read_only()) 392 if (read_only())
401 state->state |= ui::AccessibilityTypes::STATE_READONLY; 393 state->state |= ui::AccessibilityTypes::STATE_READONLY;
402 if (IsPassword()) 394 if (IsObscured())
403 state->state |= ui::AccessibilityTypes::STATE_PROTECTED; 395 state->state |= ui::AccessibilityTypes::STATE_PROTECTED;
404 state->value = text_; 396 state->value = text_;
405 397
406 DCHECK(native_wrapper_); 398 DCHECK(native_wrapper_);
407 ui::Range range; 399 ui::Range range;
408 native_wrapper_->GetSelectedRange(&range); 400 native_wrapper_->GetSelectedRange(&range);
409 state->selection_start = range.start(); 401 state->selection_start = range.start();
410 state->selection_end = range.end(); 402 state->selection_end = range.end();
411 } 403 }
412 404
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 436 }
445 #endif 437 #endif
446 } 438 }
447 } 439 }
448 440
449 std::string Textfield::GetClassName() const { 441 std::string Textfield::GetClassName() const {
450 return kViewClassName; 442 return kViewClassName;
451 } 443 }
452 444
453 } // namespace views 445 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698