Index: ui/views/controls/textfield/textfield.cc |
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc |
index 4e848c1717beba64ad225ec0582ec434ffb47d5a..c50993256ba4c96cfbec6f059531700185dc95d3 100644 |
--- a/ui/views/controls/textfield/textfield.cc |
+++ b/ui/views/controls/textfield/textfield.cc |
@@ -274,6 +274,11 @@ 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_| is owned by Textfield view. |
+ cursor_view_.set_owned_by_client(); |
+ AddChildView(&cursor_view_); |
GetRenderText()->SetFontList(GetDefaultFontList()); |
View::SetBorder(std::unique_ptr<Border>(new FocusableBorder())); |
SetFocusBehavior(FocusBehavior::ALWAYS); |
@@ -975,8 +980,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(); |
@@ -997,10 +1004,7 @@ void Textfield::OnBlur() { |
if (GetInputMethod()) |
GetInputMethod()->DetachTextInputClient(this); |
StopBlinkingCursor(); |
- if (render_text->cursor_visible()) { |
- render_text->set_cursor_visible(false); |
- RepaintCursor(); |
- } |
+ cursor_view_.SetVisible(false); |
DestroyTouchSelection(); |
@@ -1018,10 +1022,10 @@ void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
gfx::RenderText* render_text = GetRenderText(); |
render_text->SetColor(GetTextColor()); |
UpdateBackgroundColor(); |
- render_text->set_cursor_color(GetTextColor()); |
render_text->set_selection_color(GetSelectionTextColor()); |
render_text->set_selection_background_focused_color( |
GetSelectionBackgroundColor()); |
+ cursor_view_.layer()->SetColor(GetTextColor()); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -1905,8 +1909,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 |
@@ -1919,10 +1923,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) { |
@@ -1942,8 +1944,10 @@ void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) { |
render_text->Draw(canvas); |
// Draw the detached drop cursor that marks where the text will be dropped. |
- if (drop_cursor_visible_) |
- render_text->DrawCursor(canvas, drop_cursor_position_); |
+ if (drop_cursor_visible_) { |
+ canvas->FillRect(render_text->GetCursorBounds(drop_cursor_position_, true), |
+ GetTextColor()); |
+ } |
canvas->Restore(); |
} |
@@ -2081,9 +2085,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 |