| 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 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 font_list_(GetDefaultFontList()), | 84 font_list_(GetDefaultFontList()), |
| 85 read_only_(false), | 85 read_only_(false), |
| 86 default_width_in_chars_(0), | 86 default_width_in_chars_(0), |
| 87 draw_border_(true), | 87 draw_border_(true), |
| 88 text_color_(SK_ColorBLACK), | 88 text_color_(SK_ColorBLACK), |
| 89 use_default_text_color_(true), | 89 use_default_text_color_(true), |
| 90 background_color_(SK_ColorWHITE), | 90 background_color_(SK_ColorWHITE), |
| 91 use_default_background_color_(true), | 91 use_default_background_color_(true), |
| 92 horizontal_margins_were_set_(false), | 92 horizontal_margins_were_set_(false), |
| 93 vertical_margins_were_set_(false), | 93 vertical_margins_were_set_(false), |
| 94 vertical_alignment_(gfx::ALIGN_VCENTER), | |
| 95 placeholder_text_color_(kDefaultPlaceholderTextColor), | 94 placeholder_text_color_(kDefaultPlaceholderTextColor), |
| 96 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), | 95 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), |
| 97 weak_ptr_factory_(this) { | 96 weak_ptr_factory_(this) { |
| 98 set_focusable(true); | 97 set_focusable(true); |
| 99 | 98 |
| 100 if (ViewsDelegate::views_delegate) { | 99 if (ViewsDelegate::views_delegate) { |
| 101 obscured_reveal_duration_ = ViewsDelegate::views_delegate-> | 100 obscured_reveal_duration_ = ViewsDelegate::views_delegate-> |
| 102 GetDefaultTextfieldObscuredRevealDuration(); | 101 GetDefaultTextfieldObscuredRevealDuration(); |
| 103 } | 102 } |
| 104 } | 103 } |
| 105 | 104 |
| 106 Textfield::Textfield(StyleFlags style) | 105 Textfield::Textfield(StyleFlags style) |
| 107 : native_wrapper_(NULL), | 106 : native_wrapper_(NULL), |
| 108 controller_(NULL), | 107 controller_(NULL), |
| 109 style_(style), | 108 style_(style), |
| 110 font_list_(GetDefaultFontList()), | 109 font_list_(GetDefaultFontList()), |
| 111 read_only_(false), | 110 read_only_(false), |
| 112 default_width_in_chars_(0), | 111 default_width_in_chars_(0), |
| 113 draw_border_(true), | 112 draw_border_(true), |
| 114 text_color_(SK_ColorBLACK), | 113 text_color_(SK_ColorBLACK), |
| 115 use_default_text_color_(true), | 114 use_default_text_color_(true), |
| 116 background_color_(SK_ColorWHITE), | 115 background_color_(SK_ColorWHITE), |
| 117 use_default_background_color_(true), | 116 use_default_background_color_(true), |
| 118 horizontal_margins_were_set_(false), | 117 horizontal_margins_were_set_(false), |
| 119 vertical_margins_were_set_(false), | 118 vertical_margins_were_set_(false), |
| 120 vertical_alignment_(gfx::ALIGN_VCENTER), | |
| 121 placeholder_text_color_(kDefaultPlaceholderTextColor), | 119 placeholder_text_color_(kDefaultPlaceholderTextColor), |
| 122 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), | 120 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), |
| 123 weak_ptr_factory_(this) { | 121 weak_ptr_factory_(this) { |
| 124 set_focusable(true); | 122 set_focusable(true); |
| 125 if (IsObscured()) | 123 if (IsObscured()) |
| 126 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 124 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 127 | 125 |
| 128 if (ViewsDelegate::views_delegate) { | 126 if (ViewsDelegate::views_delegate) { |
| 129 obscured_reveal_duration_ = ViewsDelegate::views_delegate-> | 127 obscured_reveal_duration_ = ViewsDelegate::views_delegate-> |
| 130 GetDefaultTextfieldObscuredRevealDuration(); | 128 GetDefaultTextfieldObscuredRevealDuration(); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 298 } |
| 301 | 299 |
| 302 void Textfield::SetVerticalMargins(int top, int bottom) { | 300 void Textfield::SetVerticalMargins(int top, int bottom) { |
| 303 margins_.Set(top, margins_.left(), bottom, margins_.right()); | 301 margins_.Set(top, margins_.left(), bottom, margins_.right()); |
| 304 vertical_margins_were_set_ = true; | 302 vertical_margins_were_set_ = true; |
| 305 if (native_wrapper_) | 303 if (native_wrapper_) |
| 306 native_wrapper_->UpdateVerticalMargins(); | 304 native_wrapper_->UpdateVerticalMargins(); |
| 307 PreferredSizeChanged(); | 305 PreferredSizeChanged(); |
| 308 } | 306 } |
| 309 | 307 |
| 310 void Textfield::SetVerticalAlignment(gfx::VerticalAlignment alignment) { | |
| 311 vertical_alignment_ = alignment; | |
| 312 if (native_wrapper_) | |
| 313 native_wrapper_->UpdateVerticalAlignment(); | |
| 314 } | |
| 315 | |
| 316 void Textfield::RemoveBorder() { | 308 void Textfield::RemoveBorder() { |
| 317 if (!draw_border_) | 309 if (!draw_border_) |
| 318 return; | 310 return; |
| 319 | 311 |
| 320 draw_border_ = false; | 312 draw_border_ = false; |
| 321 if (native_wrapper_) | 313 if (native_wrapper_) |
| 322 native_wrapper_->UpdateBorder(); | 314 native_wrapper_->UpdateBorder(); |
| 323 } | 315 } |
| 324 | 316 |
| 325 bool Textfield::GetHorizontalMargins(int* left, int* right) { | 317 bool Textfield::GetHorizontalMargins(int* left, int* right) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 345 native_wrapper_->UpdateText(); | 337 native_wrapper_->UpdateText(); |
| 346 native_wrapper_->UpdateTextColor(); | 338 native_wrapper_->UpdateTextColor(); |
| 347 native_wrapper_->UpdateBackgroundColor(); | 339 native_wrapper_->UpdateBackgroundColor(); |
| 348 native_wrapper_->UpdateReadOnly(); | 340 native_wrapper_->UpdateReadOnly(); |
| 349 native_wrapper_->UpdateFont(); | 341 native_wrapper_->UpdateFont(); |
| 350 native_wrapper_->UpdateEnabled(); | 342 native_wrapper_->UpdateEnabled(); |
| 351 native_wrapper_->UpdateBorder(); | 343 native_wrapper_->UpdateBorder(); |
| 352 native_wrapper_->UpdateIsObscured(); | 344 native_wrapper_->UpdateIsObscured(); |
| 353 native_wrapper_->UpdateHorizontalMargins(); | 345 native_wrapper_->UpdateHorizontalMargins(); |
| 354 native_wrapper_->UpdateVerticalMargins(); | 346 native_wrapper_->UpdateVerticalMargins(); |
| 355 native_wrapper_->UpdateVerticalAlignment(); | |
| 356 } | 347 } |
| 357 } | 348 } |
| 358 | 349 |
| 359 void Textfield::SyncText() { | 350 void Textfield::SyncText() { |
| 360 if (native_wrapper_) { | 351 if (native_wrapper_) { |
| 361 string16 new_text = native_wrapper_->GetText(); | 352 string16 new_text = native_wrapper_->GetText(); |
| 362 if (new_text != text_) { | 353 if (new_text != text_) { |
| 363 text_ = new_text; | 354 text_ = new_text; |
| 364 if (controller_) | 355 if (controller_) |
| 365 controller_->ContentsChanged(this, text_); | 356 controller_->ContentsChanged(this, text_); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 579 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 589 Textfield* field) { | 580 Textfield* field) { |
| 590 #if defined(OS_WIN) && !defined(USE_AURA) | 581 #if defined(OS_WIN) && !defined(USE_AURA) |
| 591 if (!Textfield::IsViewsTextfieldEnabled()) | 582 if (!Textfield::IsViewsTextfieldEnabled()) |
| 592 return new NativeTextfieldWin(field); | 583 return new NativeTextfieldWin(field); |
| 593 #endif | 584 #endif |
| 594 return new NativeTextfieldViews(field); | 585 return new NativeTextfieldViews(field); |
| 595 } | 586 } |
| 596 | 587 |
| 597 } // namespace views | 588 } // namespace views |
| OLD | NEW |