| 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 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 void Textfield::OnPaint(gfx::Canvas* canvas) { | 976 void Textfield::OnPaint(gfx::Canvas* canvas) { |
| 977 OnPaintBackground(canvas); | 977 OnPaintBackground(canvas); |
| 978 PaintTextAndCursor(canvas); | 978 PaintTextAndCursor(canvas); |
| 979 OnPaintBorder(canvas); | 979 OnPaintBorder(canvas); |
| 980 } | 980 } |
| 981 | 981 |
| 982 void Textfield::OnFocus() { | 982 void Textfield::OnFocus() { |
| 983 GetRenderText()->set_focused(true); | 983 GetRenderText()->set_focused(true); |
| 984 if (ShouldShowCursor()) | 984 if (ShouldShowCursor()) |
| 985 GetRenderText()->set_cursor_visible(true); | 985 GetRenderText()->set_cursor_visible(true); |
| 986 SchedulePaint(); | |
| 987 if (GetInputMethod()) | 986 if (GetInputMethod()) |
| 988 GetInputMethod()->SetFocusedTextInputClient(this); | 987 GetInputMethod()->SetFocusedTextInputClient(this); |
| 989 OnCaretBoundsChanged(); | 988 OnCaretBoundsChanged(); |
| 990 if (ShouldBlinkCursor()) | 989 if (ShouldBlinkCursor()) |
| 991 StartBlinkingCursor(); | 990 StartBlinkingCursor(); |
| 991 // Pre Harmony, the border typically draws focus indicator. If there's no |
| 992 // border, there should be no focus indicator (e.g. in the omnibox). |
| 993 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && |
| 994 border() && border()->ShouldAddFocusRing()) { |
| 995 FocusRing::Install(this); |
| 996 } |
| 997 SchedulePaint(); |
| 992 View::OnFocus(); | 998 View::OnFocus(); |
| 993 SchedulePaint(); | |
| 994 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) | |
| 995 FocusRing::Install(this); | |
| 996 } | 999 } |
| 997 | 1000 |
| 998 void Textfield::OnBlur() { | 1001 void Textfield::OnBlur() { |
| 999 gfx::RenderText* render_text = GetRenderText(); | 1002 gfx::RenderText* render_text = GetRenderText(); |
| 1000 render_text->set_focused(false); | 1003 render_text->set_focused(false); |
| 1001 if (GetInputMethod()) | 1004 if (GetInputMethod()) |
| 1002 GetInputMethod()->DetachTextInputClient(this); | 1005 GetInputMethod()->DetachTextInputClient(this); |
| 1003 StopBlinkingCursor(); | 1006 StopBlinkingCursor(); |
| 1004 if (render_text->cursor_visible()) { | 1007 if (render_text->cursor_visible()) { |
| 1005 render_text->set_cursor_visible(false); | 1008 render_text->set_cursor_visible(false); |
| 1006 RepaintCursor(); | 1009 RepaintCursor(); |
| 1007 } | 1010 } |
| 1008 | 1011 |
| 1009 DestroyTouchSelection(); | 1012 DestroyTouchSelection(); |
| 1010 | 1013 |
| 1011 // Border typically draws focus indicator. | 1014 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && |
| 1015 border() && border()->ShouldAddFocusRing()) { |
| 1016 FocusRing::Uninstall(this); |
| 1017 } |
| 1012 SchedulePaint(); | 1018 SchedulePaint(); |
| 1013 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) | 1019 View::OnBlur(); |
| 1014 FocusRing::Uninstall(this); | |
| 1015 } | 1020 } |
| 1016 | 1021 |
| 1017 gfx::Point Textfield::GetKeyboardContextMenuLocation() { | 1022 gfx::Point Textfield::GetKeyboardContextMenuLocation() { |
| 1018 return GetCaretBounds().bottom_right(); | 1023 return GetCaretBounds().bottom_right(); |
| 1019 } | 1024 } |
| 1020 | 1025 |
| 1021 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 1026 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 1022 gfx::RenderText* render_text = GetRenderText(); | 1027 gfx::RenderText* render_text = GetRenderText(); |
| 1023 render_text->SetColor(GetTextColor()); | 1028 render_text->SetColor(GetTextColor()); |
| 1024 UpdateBackgroundColor(); | 1029 UpdateBackgroundColor(); |
| (...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 } | 2069 } |
| 2065 | 2070 |
| 2066 void Textfield::OnCursorBlinkTimerFired() { | 2071 void Textfield::OnCursorBlinkTimerFired() { |
| 2067 DCHECK(ShouldBlinkCursor()); | 2072 DCHECK(ShouldBlinkCursor()); |
| 2068 gfx::RenderText* render_text = GetRenderText(); | 2073 gfx::RenderText* render_text = GetRenderText(); |
| 2069 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2074 render_text->set_cursor_visible(!render_text->cursor_visible()); |
| 2070 RepaintCursor(); | 2075 RepaintCursor(); |
| 2071 } | 2076 } |
| 2072 | 2077 |
| 2073 } // namespace views | 2078 } // namespace views |
| OLD | NEW |