Index: ui/views/controls/textfield/textfield.cc |
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc |
index 3a417b19029a1274367a2506e6d39bf139e9d010..430f782cebcdc15a4adabb5251045305f05adec6 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); |
@@ -955,7 +959,7 @@ void Textfield::OnPaint(gfx::Canvas* canvas) { |
void Textfield::OnFocus() { |
GetRenderText()->set_focused(true); |
if (ShouldShowCursor()) |
- GetRenderText()->set_cursor_visible(true); |
+ cursor_view_.SetVisible(true); |
sadrul
2017/02/07 04:19:35
Call UpdateCursorView() before calling SetVisible(
yiyix
2017/02/08 19:47:40
Good Call! Cursor should show at the correct posit
|
if (GetInputMethod()) |
GetInputMethod()->SetFocusedTextInputClient(this); |
OnCaretBoundsChanged(); |
@@ -966,6 +970,7 @@ void Textfield::OnFocus() { |
? ui::NativeTheme::kColorId_AlertSeverityHigh |
: ui::NativeTheme::kColorId_NumColors); |
} |
+ UpdateCursorView(); |
SchedulePaint(); |
View::OnFocus(); |
} |
@@ -976,9 +981,9 @@ 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()) { |
+ cursor_view_.SetVisible(false); |
+ UpdateCursorView(); |
sadrul
2017/02/07 04:19:35
We don't need to call UpdateCursorView() since it'
yiyix
2017/02/08 19:47:40
Right. It doesn't matter where the cursor is as it
|
} |
DestroyTouchSelection(); |
@@ -1001,6 +1006,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()); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -1878,8 +1884,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 |
@@ -1896,10 +1902,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) { |
@@ -1919,6 +1923,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. |
if (drop_cursor_visible_) |
render_text->DrawCursor(canvas, drop_cursor_position_); |
@@ -2058,9 +2063,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 |