| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 default_width_in_chars_(0), | 245 default_width_in_chars_(0), |
| 246 use_default_text_color_(true), | 246 use_default_text_color_(true), |
| 247 use_default_background_color_(true), | 247 use_default_background_color_(true), |
| 248 use_default_selection_text_color_(true), | 248 use_default_selection_text_color_(true), |
| 249 use_default_selection_background_color_(true), | 249 use_default_selection_background_color_(true), |
| 250 text_color_(SK_ColorBLACK), | 250 text_color_(SK_ColorBLACK), |
| 251 background_color_(SK_ColorWHITE), | 251 background_color_(SK_ColorWHITE), |
| 252 selection_text_color_(SK_ColorWHITE), | 252 selection_text_color_(SK_ColorWHITE), |
| 253 selection_background_color_(SK_ColorBLUE), | 253 selection_background_color_(SK_ColorBLUE), |
| 254 placeholder_text_color_(kDefaultPlaceholderTextColor), | 254 placeholder_text_color_(kDefaultPlaceholderTextColor), |
| 255 invalid_(false), |
| 255 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), | 256 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), |
| 256 text_input_flags_(0), | 257 text_input_flags_(0), |
| 257 performing_user_action_(false), | 258 performing_user_action_(false), |
| 258 skip_input_method_cancel_composition_(false), | 259 skip_input_method_cancel_composition_(false), |
| 259 drop_cursor_visible_(false), | 260 drop_cursor_visible_(false), |
| 260 initiating_drag_(false), | 261 initiating_drag_(false), |
| 261 aggregated_clicks_(0), | 262 aggregated_clicks_(0), |
| 262 drag_start_display_offset_(0), | 263 drag_start_display_offset_(0), |
| 263 touch_handles_hidden_due_to_scroll_(false), | 264 touch_handles_hidden_due_to_scroll_(false), |
| 264 use_focus_ring_(ui::MaterialDesignController::IsSecondaryUiMaterial()), | 265 use_focus_ring_(ui::MaterialDesignController::IsSecondaryUiMaterial()), |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 SchedulePaint(); | 517 SchedulePaint(); |
| 517 } | 518 } |
| 518 | 519 |
| 519 void Textfield::ApplyStyle(gfx::TextStyle style, | 520 void Textfield::ApplyStyle(gfx::TextStyle style, |
| 520 bool value, | 521 bool value, |
| 521 const gfx::Range& range) { | 522 const gfx::Range& range) { |
| 522 GetRenderText()->ApplyStyle(style, value, range); | 523 GetRenderText()->ApplyStyle(style, value, range); |
| 523 SchedulePaint(); | 524 SchedulePaint(); |
| 524 } | 525 } |
| 525 | 526 |
| 527 void Textfield::SetInvalid(bool invalid) { |
| 528 if (invalid == invalid_) |
| 529 return; |
| 530 invalid_ = invalid; |
| 531 UpdateBorder(); |
| 532 |
| 533 if (HasFocus() && use_focus_ring_) { |
| 534 FocusRing::Install(this, invalid_ |
| 535 ? ui::NativeTheme::kColorId_AlertSeverityHigh |
| 536 : ui::NativeTheme::kColorId_NumColors); |
| 537 } |
| 538 } |
| 539 |
| 526 void Textfield::ClearEditHistory() { | 540 void Textfield::ClearEditHistory() { |
| 527 model_->ClearEditHistory(); | 541 model_->ClearEditHistory(); |
| 528 } | 542 } |
| 529 | 543 |
| 530 void Textfield::SetAccessibleName(const base::string16& name) { | 544 void Textfield::SetAccessibleName(const base::string16& name) { |
| 531 accessible_name_ = name; | 545 accessible_name_ = name; |
| 532 } | 546 } |
| 533 | 547 |
| 534 bool Textfield::HasTextBeingDragged() { | 548 bool Textfield::HasTextBeingDragged() { |
| 535 return initiating_drag_; | 549 return initiating_drag_; |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 | 1003 |
| 990 void Textfield::OnFocus() { | 1004 void Textfield::OnFocus() { |
| 991 GetRenderText()->set_focused(true); | 1005 GetRenderText()->set_focused(true); |
| 992 if (ShouldShowCursor()) | 1006 if (ShouldShowCursor()) |
| 993 GetRenderText()->set_cursor_visible(true); | 1007 GetRenderText()->set_cursor_visible(true); |
| 994 if (GetInputMethod()) | 1008 if (GetInputMethod()) |
| 995 GetInputMethod()->SetFocusedTextInputClient(this); | 1009 GetInputMethod()->SetFocusedTextInputClient(this); |
| 996 OnCaretBoundsChanged(); | 1010 OnCaretBoundsChanged(); |
| 997 if (ShouldBlinkCursor()) | 1011 if (ShouldBlinkCursor()) |
| 998 StartBlinkingCursor(); | 1012 StartBlinkingCursor(); |
| 999 if (use_focus_ring_) | 1013 if (use_focus_ring_) { |
| 1000 FocusRing::Install(this); | 1014 FocusRing::Install(this, invalid_ |
| 1015 ? ui::NativeTheme::kColorId_AlertSeverityHigh |
| 1016 : ui::NativeTheme::kColorId_NumColors); |
| 1017 } |
| 1001 SchedulePaint(); | 1018 SchedulePaint(); |
| 1002 View::OnFocus(); | 1019 View::OnFocus(); |
| 1003 } | 1020 } |
| 1004 | 1021 |
| 1005 void Textfield::OnBlur() { | 1022 void Textfield::OnBlur() { |
| 1006 gfx::RenderText* render_text = GetRenderText(); | 1023 gfx::RenderText* render_text = GetRenderText(); |
| 1007 render_text->set_focused(false); | 1024 render_text->set_focused(false); |
| 1008 if (GetInputMethod()) | 1025 if (GetInputMethod()) |
| 1009 GetInputMethod()->DetachTextInputClient(this); | 1026 GetInputMethod()->DetachTextInputClient(this); |
| 1010 StopBlinkingCursor(); | 1027 StopBlinkingCursor(); |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 set_background(Background::CreateSolidBackground(color)); | 1825 set_background(Background::CreateSolidBackground(color)); |
| 1809 } | 1826 } |
| 1810 // Disable subpixel rendering when the background color is transparent | 1827 // Disable subpixel rendering when the background color is transparent |
| 1811 // because it draws incorrect colors around the glyphs in that case. | 1828 // because it draws incorrect colors around the glyphs in that case. |
| 1812 // See crbug.com/115198 | 1829 // See crbug.com/115198 |
| 1813 GetRenderText()->set_subpixel_rendering_suppressed( | 1830 GetRenderText()->set_subpixel_rendering_suppressed( |
| 1814 SkColorGetA(color) != SK_AlphaOPAQUE); | 1831 SkColorGetA(color) != SK_AlphaOPAQUE); |
| 1815 SchedulePaint(); | 1832 SchedulePaint(); |
| 1816 } | 1833 } |
| 1817 | 1834 |
| 1835 void Textfield::UpdateBorder() { |
| 1836 auto border = base::MakeUnique<views::FocusableBorder>(); |
| 1837 if (invalid_) |
| 1838 border->SetColorId(ui::NativeTheme::kColorId_AlertSeverityHigh); |
| 1839 View::SetBorder(std::move(border)); |
| 1840 } |
| 1841 |
| 1818 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { | 1842 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { |
| 1819 if (text_changed) { | 1843 if (text_changed) { |
| 1820 if (controller_) | 1844 if (controller_) |
| 1821 controller_->ContentsChanged(this, text()); | 1845 controller_->ContentsChanged(this, text()); |
| 1822 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); | 1846 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); |
| 1823 } | 1847 } |
| 1824 if (cursor_changed) { | 1848 if (cursor_changed) { |
| 1825 GetRenderText()->set_cursor_visible(ShouldShowCursor()); | 1849 GetRenderText()->set_cursor_visible(ShouldShowCursor()); |
| 1826 RepaintCursor(); | 1850 RepaintCursor(); |
| 1827 if (ShouldBlinkCursor()) | 1851 if (ShouldBlinkCursor()) |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2081 } | 2105 } |
| 2082 | 2106 |
| 2083 void Textfield::OnCursorBlinkTimerFired() { | 2107 void Textfield::OnCursorBlinkTimerFired() { |
| 2084 DCHECK(ShouldBlinkCursor()); | 2108 DCHECK(ShouldBlinkCursor()); |
| 2085 gfx::RenderText* render_text = GetRenderText(); | 2109 gfx::RenderText* render_text = GetRenderText(); |
| 2086 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2110 render_text->set_cursor_visible(!render_text->cursor_visible()); |
| 2087 RepaintCursor(); | 2111 RepaintCursor(); |
| 2088 } | 2112 } |
| 2089 | 2113 |
| 2090 } // namespace views | 2114 } // namespace views |
| OLD | NEW |