| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 default_width_in_chars_(0), | 82 default_width_in_chars_(0), |
| 83 draw_border_(true), | 83 draw_border_(true), |
| 84 text_color_(SK_ColorBLACK), | 84 text_color_(SK_ColorBLACK), |
| 85 use_default_text_color_(true), | 85 use_default_text_color_(true), |
| 86 background_color_(SK_ColorWHITE), | 86 background_color_(SK_ColorWHITE), |
| 87 use_default_background_color_(true), | 87 use_default_background_color_(true), |
| 88 horizontal_margins_were_set_(false), | 88 horizontal_margins_were_set_(false), |
| 89 vertical_margins_were_set_(false), | 89 vertical_margins_were_set_(false), |
| 90 vertical_alignment_(gfx::ALIGN_VCENTER), | 90 vertical_alignment_(gfx::ALIGN_VCENTER), |
| 91 placeholder_text_color_(kDefaultPlaceholderTextColor), | 91 placeholder_text_color_(kDefaultPlaceholderTextColor), |
| 92 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT) { | 92 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), |
| 93 weak_ptr_factory_(this) { |
| 93 set_focusable(true); | 94 set_focusable(true); |
| 94 | 95 |
| 95 if (ViewsDelegate::views_delegate) { | 96 if (ViewsDelegate::views_delegate) { |
| 96 obscured_reveal_duration_ = ViewsDelegate::views_delegate-> | 97 obscured_reveal_duration_ = ViewsDelegate::views_delegate-> |
| 97 GetDefaultTextfieldObscuredRevealDuration(); | 98 GetDefaultTextfieldObscuredRevealDuration(); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 Textfield::Textfield(StyleFlags style) | 102 Textfield::Textfield(StyleFlags style) |
| 102 : native_wrapper_(NULL), | 103 : native_wrapper_(NULL), |
| 103 controller_(NULL), | 104 controller_(NULL), |
| 104 style_(style), | 105 style_(style), |
| 105 font_list_(GetDefaultFontList()), | 106 font_list_(GetDefaultFontList()), |
| 106 read_only_(false), | 107 read_only_(false), |
| 107 default_width_in_chars_(0), | 108 default_width_in_chars_(0), |
| 108 draw_border_(true), | 109 draw_border_(true), |
| 109 text_color_(SK_ColorBLACK), | 110 text_color_(SK_ColorBLACK), |
| 110 use_default_text_color_(true), | 111 use_default_text_color_(true), |
| 111 background_color_(SK_ColorWHITE), | 112 background_color_(SK_ColorWHITE), |
| 112 use_default_background_color_(true), | 113 use_default_background_color_(true), |
| 113 horizontal_margins_were_set_(false), | 114 horizontal_margins_were_set_(false), |
| 114 vertical_margins_were_set_(false), | 115 vertical_margins_were_set_(false), |
| 115 vertical_alignment_(gfx::ALIGN_VCENTER), | 116 vertical_alignment_(gfx::ALIGN_VCENTER), |
| 116 placeholder_text_color_(kDefaultPlaceholderTextColor), | 117 placeholder_text_color_(kDefaultPlaceholderTextColor), |
| 117 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT) { | 118 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), |
| 119 weak_ptr_factory_(this) { |
| 118 set_focusable(true); | 120 set_focusable(true); |
| 119 if (IsObscured()) | 121 if (IsObscured()) |
| 120 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 122 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 121 | 123 |
| 122 if (ViewsDelegate::views_delegate) { | 124 if (ViewsDelegate::views_delegate) { |
| 123 obscured_reveal_duration_ = ViewsDelegate::views_delegate-> | 125 obscured_reveal_duration_ = ViewsDelegate::views_delegate-> |
| 124 GetDefaultTextfieldObscuredRevealDuration(); | 126 GetDefaultTextfieldObscuredRevealDuration(); |
| 125 } | 127 } |
| 126 } | 128 } |
| 127 | 129 |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 state->name = accessible_name_; | 501 state->name = accessible_name_; |
| 500 if (read_only()) | 502 if (read_only()) |
| 501 state->state |= ui::AccessibilityTypes::STATE_READONLY; | 503 state->state |= ui::AccessibilityTypes::STATE_READONLY; |
| 502 if (IsObscured()) | 504 if (IsObscured()) |
| 503 state->state |= ui::AccessibilityTypes::STATE_PROTECTED; | 505 state->state |= ui::AccessibilityTypes::STATE_PROTECTED; |
| 504 state->value = text_; | 506 state->value = text_; |
| 505 | 507 |
| 506 const ui::Range range = native_wrapper_->GetSelectedRange(); | 508 const ui::Range range = native_wrapper_->GetSelectedRange(); |
| 507 state->selection_start = range.start(); | 509 state->selection_start = range.start(); |
| 508 state->selection_end = range.end(); | 510 state->selection_end = range.end(); |
| 511 |
| 512 if (!read_only()) { |
| 513 state->set_value_callback = |
| 514 base::Bind(&Textfield::AccessibilitySetValue, |
| 515 weak_ptr_factory_.GetWeakPtr()); |
| 516 } |
| 509 } | 517 } |
| 510 | 518 |
| 511 ui::TextInputClient* Textfield::GetTextInputClient() { | 519 ui::TextInputClient* Textfield::GetTextInputClient() { |
| 512 return native_wrapper_ ? native_wrapper_->GetTextInputClient() : NULL; | 520 return native_wrapper_ ? native_wrapper_->GetTextInputClient() : NULL; |
| 513 } | 521 } |
| 514 | 522 |
| 515 void Textfield::OnEnabledChanged() { | 523 void Textfield::OnEnabledChanged() { |
| 516 View::OnEnabledChanged(); | 524 View::OnEnabledChanged(); |
| 517 if (native_wrapper_) | 525 if (native_wrapper_) |
| 518 native_wrapper_->UpdateEnabled(); | 526 native_wrapper_->UpdateEnabled(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 540 if (!IsViewsTextfieldEnabled()) | 548 if (!IsViewsTextfieldEnabled()) |
| 541 static_cast<NativeTextfieldWin*>(native_wrapper_)->AttachHack(); | 549 static_cast<NativeTextfieldWin*>(native_wrapper_)->AttachHack(); |
| 542 #endif | 550 #endif |
| 543 } | 551 } |
| 544 } | 552 } |
| 545 | 553 |
| 546 const char* Textfield::GetClassName() const { | 554 const char* Textfield::GetClassName() const { |
| 547 return kViewClassName; | 555 return kViewClassName; |
| 548 } | 556 } |
| 549 | 557 |
| 558 //////////////////////////////////////////////////////////////////////////////// |
| 559 // Textfield, private: |
| 560 |
| 550 gfx::Insets Textfield::GetTextInsets() const { | 561 gfx::Insets Textfield::GetTextInsets() const { |
| 551 gfx::Insets insets = GetInsets(); | 562 gfx::Insets insets = GetInsets(); |
| 552 if (draw_border_ && native_wrapper_) | 563 if (draw_border_ && native_wrapper_) |
| 553 insets += native_wrapper_->CalculateInsets(); | 564 insets += native_wrapper_->CalculateInsets(); |
| 554 return insets; | 565 return insets; |
| 555 } | 566 } |
| 556 | 567 |
| 568 void Textfield::AccessibilitySetValue(const string16& new_value) { |
| 569 if (!read_only()) { |
| 570 SetText(new_value); |
| 571 ClearSelection(); |
| 572 } |
| 573 } |
| 574 |
| 557 //////////////////////////////////////////////////////////////////////////////// | 575 //////////////////////////////////////////////////////////////////////////////// |
| 558 // NativeTextfieldWrapper, public: | 576 // NativeTextfieldWrapper, public: |
| 559 | 577 |
| 560 // static | 578 // static |
| 561 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 579 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 562 Textfield* field) { | 580 Textfield* field) { |
| 563 #if defined(OS_WIN) && !defined(USE_AURA) | 581 #if defined(OS_WIN) && !defined(USE_AURA) |
| 564 if (!Textfield::IsViewsTextfieldEnabled()) | 582 if (!Textfield::IsViewsTextfieldEnabled()) |
| 565 return new NativeTextfieldWin(field); | 583 return new NativeTextfieldWin(field); |
| 566 #endif | 584 #endif |
| 567 return new NativeTextfieldViews(field); | 585 return new NativeTextfieldViews(field); |
| 568 } | 586 } |
| 569 | 587 |
| 570 } // namespace views | 588 } // namespace views |
| OLD | NEW |