Chromium Code Reviews| 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 base::Optional<ui::NativeTheme::ColorId> color_id; | |
| 535 if (invalid_) | |
| 536 color_id = ui::NativeTheme::kColorId_AlertSeverityHigh; | |
| 537 FocusRing::SetColorId(this, color_id); | |
| 538 } | |
| 539 } | |
| 540 | |
| 526 void Textfield::ClearEditHistory() { | 541 void Textfield::ClearEditHistory() { |
| 527 model_->ClearEditHistory(); | 542 model_->ClearEditHistory(); |
| 528 } | 543 } |
| 529 | 544 |
| 530 void Textfield::SetAccessibleName(const base::string16& name) { | 545 void Textfield::SetAccessibleName(const base::string16& name) { |
| 531 accessible_name_ = name; | 546 accessible_name_ = name; |
| 532 } | 547 } |
| 533 | 548 |
| 534 bool Textfield::HasTextBeingDragged() { | 549 bool Textfield::HasTextBeingDragged() { |
| 535 return initiating_drag_; | 550 return initiating_drag_; |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 989 | 1004 |
| 990 void Textfield::OnFocus() { | 1005 void Textfield::OnFocus() { |
| 991 GetRenderText()->set_focused(true); | 1006 GetRenderText()->set_focused(true); |
| 992 if (ShouldShowCursor()) | 1007 if (ShouldShowCursor()) |
| 993 GetRenderText()->set_cursor_visible(true); | 1008 GetRenderText()->set_cursor_visible(true); |
| 994 if (GetInputMethod()) | 1009 if (GetInputMethod()) |
| 995 GetInputMethod()->SetFocusedTextInputClient(this); | 1010 GetInputMethod()->SetFocusedTextInputClient(this); |
| 996 OnCaretBoundsChanged(); | 1011 OnCaretBoundsChanged(); |
| 997 if (ShouldBlinkCursor()) | 1012 if (ShouldBlinkCursor()) |
| 998 StartBlinkingCursor(); | 1013 StartBlinkingCursor(); |
| 999 if (use_focus_ring_) | 1014 if (use_focus_ring_) { |
| 1000 FocusRing::Install(this); | 1015 FocusRing::Install(this); |
| 1016 if (invalid_) | |
| 1017 FocusRing::SetColorId(this, ui::NativeTheme::kColorId_AlertSeverityHigh); | |
| 1018 } | |
| 1001 SchedulePaint(); | 1019 SchedulePaint(); |
| 1002 View::OnFocus(); | 1020 View::OnFocus(); |
| 1003 } | 1021 } |
| 1004 | 1022 |
| 1005 void Textfield::OnBlur() { | 1023 void Textfield::OnBlur() { |
| 1006 gfx::RenderText* render_text = GetRenderText(); | 1024 gfx::RenderText* render_text = GetRenderText(); |
| 1007 render_text->set_focused(false); | 1025 render_text->set_focused(false); |
| 1008 if (GetInputMethod()) | 1026 if (GetInputMethod()) |
| 1009 GetInputMethod()->DetachTextInputClient(this); | 1027 GetInputMethod()->DetachTextInputClient(this); |
| 1010 StopBlinkingCursor(); | 1028 StopBlinkingCursor(); |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1808 set_background(Background::CreateSolidBackground(color)); | 1826 set_background(Background::CreateSolidBackground(color)); |
| 1809 } | 1827 } |
| 1810 // Disable subpixel rendering when the background color is transparent | 1828 // Disable subpixel rendering when the background color is transparent |
| 1811 // because it draws incorrect colors around the glyphs in that case. | 1829 // because it draws incorrect colors around the glyphs in that case. |
| 1812 // See crbug.com/115198 | 1830 // See crbug.com/115198 |
| 1813 GetRenderText()->set_subpixel_rendering_suppressed( | 1831 GetRenderText()->set_subpixel_rendering_suppressed( |
| 1814 SkColorGetA(color) != SK_AlphaOPAQUE); | 1832 SkColorGetA(color) != SK_AlphaOPAQUE); |
| 1815 SchedulePaint(); | 1833 SchedulePaint(); |
| 1816 } | 1834 } |
| 1817 | 1835 |
| 1836 void Textfield::UpdateBorder() { | |
| 1837 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.
| |
| 1838 if (invalid_) | |
| 1839 border->SetColorId(ui::NativeTheme::kColorId_AlertSeverityHigh); | |
| 1840 View::SetBorder(std::move(border)); | |
| 1841 } | |
| 1842 | |
| 1818 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { | 1843 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { |
| 1819 if (text_changed) { | 1844 if (text_changed) { |
| 1820 if (controller_) | 1845 if (controller_) |
| 1821 controller_->ContentsChanged(this, text()); | 1846 controller_->ContentsChanged(this, text()); |
| 1822 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); | 1847 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); |
| 1823 } | 1848 } |
| 1824 if (cursor_changed) { | 1849 if (cursor_changed) { |
| 1825 GetRenderText()->set_cursor_visible(ShouldShowCursor()); | 1850 GetRenderText()->set_cursor_visible(ShouldShowCursor()); |
| 1826 RepaintCursor(); | 1851 RepaintCursor(); |
| 1827 if (ShouldBlinkCursor()) | 1852 if (ShouldBlinkCursor()) |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2081 } | 2106 } |
| 2082 | 2107 |
| 2083 void Textfield::OnCursorBlinkTimerFired() { | 2108 void Textfield::OnCursorBlinkTimerFired() { |
| 2084 DCHECK(ShouldBlinkCursor()); | 2109 DCHECK(ShouldBlinkCursor()); |
| 2085 gfx::RenderText* render_text = GetRenderText(); | 2110 gfx::RenderText* render_text = GetRenderText(); |
| 2086 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2111 render_text->set_cursor_visible(!render_text->cursor_visible()); |
| 2087 RepaintCursor(); | 2112 RepaintCursor(); |
| 2088 } | 2113 } |
| 2089 | 2114 |
| 2090 } // namespace views | 2115 } // namespace views |
| OLD | NEW |