| 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/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 Loading... |
| 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 set_focusable(!read_only); | 95 set_focusable(!read_only); |
| 96 if (native_wrapper_) { | 96 if (native_wrapper_) { |
| 97 native_wrapper_->UpdateReadOnly(); | 97 native_wrapper_->UpdateReadOnly(); |
| 98 native_wrapper_->UpdateTextColor(); | 98 native_wrapper_->UpdateTextColor(); |
| 99 native_wrapper_->UpdateBackgroundColor(); | 99 native_wrapper_->UpdateBackgroundColor(); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool Textfield::IsPassword() const { | 103 bool Textfield::IsObscured() const { |
| 104 return style_ & STYLE_PASSWORD; | 104 return style_ & STYLE_OBSCURED; |
| 105 } | 105 } |
| 106 | 106 |
| 107 void Textfield::SetPassword(bool password) { | 107 void Textfield::SetObscured(bool obscured) { |
| 108 if (password) { | 108 if (obscured) { |
| 109 style_ = static_cast<StyleFlags>(style_ | STYLE_PASSWORD); | 109 style_ = static_cast<StyleFlags>(style_ | STYLE_OBSCURED); |
| 110 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 110 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 111 } else { | 111 } else { |
| 112 style_ = static_cast<StyleFlags>(style_ & ~STYLE_PASSWORD); | 112 style_ = static_cast<StyleFlags>(style_ & ~STYLE_OBSCURED); |
| 113 SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); | 113 SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); |
| 114 } | 114 } |
| 115 if (native_wrapper_) | 115 if (native_wrapper_) |
| 116 native_wrapper_->UpdateIsPassword(); | 116 native_wrapper_->UpdateIsObscured(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 | 119 |
| 120 ui::TextInputType Textfield::GetTextInputType() const { | 120 ui::TextInputType Textfield::GetTextInputType() const { |
| 121 if (read_only() || !enabled()) | 121 if (read_only() || !enabled()) |
| 122 return ui::TEXT_INPUT_TYPE_NONE; | 122 return ui::TEXT_INPUT_TYPE_NONE; |
| 123 return text_input_type_; | 123 return text_input_type_; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void Textfield::SetTextInputType(ui::TextInputType type) { | 126 void Textfield::SetTextInputType(ui::TextInputType type) { |
| 127 text_input_type_ = type; | 127 text_input_type_ = type; |
| 128 bool should_be_password = type == ui::TEXT_INPUT_TYPE_PASSWORD; | 128 bool should_be_obscured = type == ui::TEXT_INPUT_TYPE_PASSWORD; |
| 129 if (IsPassword() != should_be_password) | 129 if (IsObscured() != should_be_obscured) |
| 130 SetPassword(should_be_password); | 130 SetObscured(should_be_obscured); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void Textfield::SetText(const string16& text) { | 133 void Textfield::SetText(const string16& text) { |
| 134 text_ = text; | 134 text_ = text; |
| 135 if (native_wrapper_) | 135 if (native_wrapper_) |
| 136 native_wrapper_->UpdateText(); | 136 native_wrapper_->UpdateText(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void Textfield::AppendText(const string16& text) { | 139 void Textfield::AppendText(const string16& text) { |
| 140 text_ += text; | 140 text_ += text; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 241 |
| 242 void Textfield::UpdateAllProperties() { | 242 void Textfield::UpdateAllProperties() { |
| 243 if (native_wrapper_) { | 243 if (native_wrapper_) { |
| 244 native_wrapper_->UpdateText(); | 244 native_wrapper_->UpdateText(); |
| 245 native_wrapper_->UpdateTextColor(); | 245 native_wrapper_->UpdateTextColor(); |
| 246 native_wrapper_->UpdateBackgroundColor(); | 246 native_wrapper_->UpdateBackgroundColor(); |
| 247 native_wrapper_->UpdateReadOnly(); | 247 native_wrapper_->UpdateReadOnly(); |
| 248 native_wrapper_->UpdateFont(); | 248 native_wrapper_->UpdateFont(); |
| 249 native_wrapper_->UpdateEnabled(); | 249 native_wrapper_->UpdateEnabled(); |
| 250 native_wrapper_->UpdateBorder(); | 250 native_wrapper_->UpdateBorder(); |
| 251 native_wrapper_->UpdateIsPassword(); | 251 native_wrapper_->UpdateIsObscured(); |
| 252 native_wrapper_->UpdateHorizontalMargins(); | 252 native_wrapper_->UpdateHorizontalMargins(); |
| 253 native_wrapper_->UpdateVerticalMargins(); | 253 native_wrapper_->UpdateVerticalMargins(); |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 void Textfield::SyncText() { | 257 void Textfield::SyncText() { |
| 258 if (native_wrapper_) { | 258 if (native_wrapper_) { |
| 259 string16 new_text = native_wrapper_->GetText(); | 259 string16 new_text = native_wrapper_->GetText(); |
| 260 if (new_text != text_) { | 260 if (new_text != text_) { |
| 261 text_ = new_text; | 261 text_ = new_text; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 void Textfield::OnBlur() { | 396 void Textfield::OnBlur() { |
| 397 if (native_wrapper_) | 397 if (native_wrapper_) |
| 398 native_wrapper_->HandleBlur(); | 398 native_wrapper_->HandleBlur(); |
| 399 } | 399 } |
| 400 | 400 |
| 401 void Textfield::GetAccessibleState(ui::AccessibleViewState* state) { | 401 void Textfield::GetAccessibleState(ui::AccessibleViewState* state) { |
| 402 state->role = ui::AccessibilityTypes::ROLE_TEXT; | 402 state->role = ui::AccessibilityTypes::ROLE_TEXT; |
| 403 state->name = accessible_name_; | 403 state->name = accessible_name_; |
| 404 if (read_only()) | 404 if (read_only()) |
| 405 state->state |= ui::AccessibilityTypes::STATE_READONLY; | 405 state->state |= ui::AccessibilityTypes::STATE_READONLY; |
| 406 if (IsPassword()) | 406 if (IsObscured()) |
| 407 state->state |= ui::AccessibilityTypes::STATE_PROTECTED; | 407 state->state |= ui::AccessibilityTypes::STATE_PROTECTED; |
| 408 state->value = text_; | 408 state->value = text_; |
| 409 | 409 |
| 410 DCHECK(native_wrapper_); | 410 DCHECK(native_wrapper_); |
| 411 ui::Range range; | 411 ui::Range range; |
| 412 native_wrapper_->GetSelectedRange(&range); | 412 native_wrapper_->GetSelectedRange(&range); |
| 413 state->selection_start = range.start(); | 413 state->selection_start = range.start(); |
| 414 state->selection_end = range.end(); | 414 state->selection_end = range.end(); |
| 415 } | 415 } |
| 416 | 416 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } | 448 } |
| 449 #endif | 449 #endif |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 | 452 |
| 453 std::string Textfield::GetClassName() const { | 453 std::string Textfield::GetClassName() const { |
| 454 return kViewClassName; | 454 return kViewClassName; |
| 455 } | 455 } |
| 456 | 456 |
| 457 } // namespace views | 457 } // namespace views |
| OLD | NEW |