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 1f4a7f63bc1d107b5229858a8ff76f843f06aac1..a8e058ca263925b5c338998369f62c5e4f22c55c 100644 |
| --- a/ui/views/controls/textfield/textfield.cc |
| +++ b/ui/views/controls/textfield/textfield.cc |
| @@ -262,6 +262,10 @@ Textfield::Textfield() |
| weak_ptr_factory_(this) { |
| set_context_menu_controller(this); |
| set_drag_controller(this); |
| + cursor_view_.SetPaintToLayer(ui::LAYER_SOLID_COLOR); |
| + cursor_view_.layer()->SetColor(GetTextColor()); |
| + cursor_view_.set_owned_by_client(); |
| + AddChildView(&cursor_view_); |
| GetRenderText()->SetFontList(GetDefaultFontList()); |
| View::SetBorder(std::unique_ptr<Border>(new FocusableBorder())); |
| SetFocusBehavior(FocusBehavior::ALWAYS); |
| @@ -963,8 +967,10 @@ void Textfield::OnPaint(gfx::Canvas* canvas) { |
| void Textfield::OnFocus() { |
| GetRenderText()->set_focused(true); |
| - if (ShouldShowCursor()) |
| - GetRenderText()->set_cursor_visible(true); |
| + if (ShouldShowCursor()) { |
| + UpdateCursorView(); |
| + cursor_view_.SetVisible(true); |
| + } |
| if (GetInputMethod()) |
| GetInputMethod()->SetFocusedTextInputClient(this); |
| OnCaretBoundsChanged(); |
| @@ -985,10 +991,8 @@ void Textfield::OnBlur() { |
| if (GetInputMethod()) |
| GetInputMethod()->DetachTextInputClient(this); |
| StopBlinkingCursor(); |
| - if (render_text->cursor_visible()) { |
| - render_text->set_cursor_visible(false); |
| - RepaintCursor(); |
| - } |
| + if (cursor_view_.visible()) |
|
msw
2017/02/13 21:27:12
nit: maybe this check isn't really needed? (always
yiyix
2017/02/15 16:56:32
Right, it checks if the visibility changes in SetV
|
| + cursor_view_.SetVisible(false); |
| DestroyTouchSelection(); |
| @@ -1010,6 +1014,7 @@ void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| render_text->set_selection_color(GetSelectionTextColor()); |
| render_text->set_selection_background_focused_color( |
| GetSelectionBackgroundColor()); |
| + cursor_view_.layer()->SetColor(GetTextColor()); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -1887,8 +1892,8 @@ void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { |
| NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); |
| } |
| if (cursor_changed) { |
| - GetRenderText()->set_cursor_visible(ShouldShowCursor()); |
| - RepaintCursor(); |
| + cursor_view_.SetVisible(ShouldShowCursor()); |
| + UpdateCursorView(); |
| if (ShouldBlinkCursor()) |
| StartBlinkingCursor(); |
| else |
| @@ -1901,10 +1906,8 @@ void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { |
| } |
| } |
| -void Textfield::RepaintCursor() { |
| - gfx::Rect r(GetRenderText()->GetUpdatedCursorBounds()); |
| - r.Inset(-1, -1, -1, -1); |
| - SchedulePaintInRect(r); |
| +void Textfield::UpdateCursorView() { |
| + cursor_view_.SetBoundsRect(GetRenderText()->GetUpdatedCursorBounds()); |
| } |
| void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) { |
| @@ -1924,6 +1927,7 @@ void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) { |
| render_text->Draw(canvas); |
| // Draw the detached drop cursor that marks where the text will be dropped. |
| + // TODO(yiyix): Use UpdateCursorView to draw drop_cursor instead. |
|
msw
2017/02/13 21:27:12
Please fix this now or prepare a dependent patch s
yiyix
2017/02/15 16:56:32
By adding DrawCursor inline, it is also fixed.
|
| if (drop_cursor_visible_) |
| render_text->DrawCursor(canvas, drop_cursor_position_); |
| @@ -2063,9 +2067,8 @@ void Textfield::StopBlinkingCursor() { |
| void Textfield::OnCursorBlinkTimerFired() { |
| DCHECK(ShouldBlinkCursor()); |
| - gfx::RenderText* render_text = GetRenderText(); |
| - render_text->set_cursor_visible(!render_text->cursor_visible()); |
| - RepaintCursor(); |
| + cursor_view_.SetVisible(!cursor_view_.visible()); |
| + UpdateCursorView(); |
| } |
| } // namespace views |