Chromium Code Reviews| Index: ui/views/controls/textfield/textfield.cc |
| diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc |
| index 107bea8e0249824f2ad2639d1bceadab55bd6502..1c6f1401d8026b6db5e8e14cdfae4c88835ba6cd 100644 |
| --- a/ui/views/controls/textfield/textfield.cc |
| +++ b/ui/views/controls/textfield/textfield.cc |
| @@ -252,6 +252,7 @@ Textfield::Textfield() |
| selection_text_color_(SK_ColorWHITE), |
| selection_background_color_(SK_ColorBLUE), |
| placeholder_text_color_(kDefaultPlaceholderTextColor), |
| + invalid_(false), |
| text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), |
| text_input_flags_(0), |
| performing_user_action_(false), |
| @@ -523,6 +524,20 @@ void Textfield::ApplyStyle(gfx::TextStyle style, |
| SchedulePaint(); |
| } |
| +void Textfield::SetInvalid(bool invalid) { |
| + if (invalid == invalid_) |
| + return; |
| + invalid_ = invalid; |
| + UpdateBorder(); |
| + |
| + if (HasFocus() && use_focus_ring_) { |
| + base::Optional<ui::NativeTheme::ColorId> color_id; |
| + if (invalid_) |
| + color_id = ui::NativeTheme::kColorId_AlertSeverityHigh; |
| + FocusRing::SetColorId(this, color_id); |
| + } |
| +} |
| + |
| void Textfield::ClearEditHistory() { |
| model_->ClearEditHistory(); |
| } |
| @@ -996,8 +1011,11 @@ void Textfield::OnFocus() { |
| OnCaretBoundsChanged(); |
| if (ShouldBlinkCursor()) |
| StartBlinkingCursor(); |
| - if (use_focus_ring_) |
| + if (use_focus_ring_) { |
| FocusRing::Install(this); |
| + if (invalid_) |
| + FocusRing::SetColorId(this, ui::NativeTheme::kColorId_AlertSeverityHigh); |
| + } |
| SchedulePaint(); |
| View::OnFocus(); |
| } |
| @@ -1815,6 +1833,13 @@ void Textfield::UpdateBackgroundColor() { |
| SchedulePaint(); |
| } |
| +void Textfield::UpdateBorder() { |
| + std::unique_ptr<views::FocusableBorder> border(new views::FocusableBorder()); |
|
sky
2016/10/11 23:59:18
MakeUnique
Evan Stade
2016/10/12 00:36:39
Done.
|
| + if (invalid_) |
| + border->SetColorId(ui::NativeTheme::kColorId_AlertSeverityHigh); |
| + View::SetBorder(std::move(border)); |
| +} |
| + |
| void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { |
| if (text_changed) { |
| if (controller_) |