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