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 fdfe19b095fc0cdb63d857ba800f0d88b509abf0..8414521dd258ccc1ec46ef855a242c5fc03b3fa8 100644 |
| --- a/ui/views/controls/textfield/textfield.cc |
| +++ b/ui/views/controls/textfield/textfield.cc |
| @@ -455,7 +455,12 @@ bool Textfield::GetCursorEnabled() const { |
| } |
| void Textfield::SetCursorEnabled(bool enabled) { |
| + if (GetRenderText()->cursor_enabled() == enabled) |
| + return; |
| + |
| GetRenderText()->SetCursorEnabled(enabled); |
| + UpdateCursorViewPosition(); |
| + UpdateCursorVisibility(); |
| } |
| const gfx::FontList& Textfield::GetFontList() const { |
| @@ -982,7 +987,7 @@ void Textfield::OnPaint(gfx::Canvas* canvas) { |
| void Textfield::OnFocus() { |
| GetRenderText()->set_focused(true); |
| if (ShouldShowCursor()) { |
| - UpdateCursorView(); |
| + UpdateCursorViewPosition(); |
| cursor_view_.SetVisible(true); |
|
msw
2017/03/10 21:04:30
optional nit: should this pass ShouldShowCursor(),
yiyix
2017/03/13 04:02:16
Since it is a fix of dev block bug, I hesitate to
|
| } |
| if (GetInputMethod()) |
| @@ -1910,12 +1915,8 @@ void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { |
| NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); |
| } |
| if (cursor_changed) { |
| - UpdateCursorView(); |
| - cursor_view_.SetVisible(ShouldShowCursor()); |
| - if (ShouldBlinkCursor()) |
| - StartBlinkingCursor(); |
| - else |
| - StopBlinkingCursor(); |
| + UpdateCursorViewPosition(); |
| + UpdateCursorVisibility(); |
| NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_SELECTION_CHANGED, true); |
| } |
| if (text_changed || cursor_changed) { |
| @@ -1924,7 +1925,15 @@ void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { |
| } |
| } |
| -void Textfield::UpdateCursorView() { |
| +void Textfield::UpdateCursorVisibility() { |
| + cursor_view_.SetVisible(ShouldShowCursor()); |
| + if (ShouldBlinkCursor()) |
| + StartBlinkingCursor(); |
| + else |
| + StopBlinkingCursor(); |
| +} |
| + |
| +void Textfield::UpdateCursorViewPosition() { |
| gfx::Rect location(GetRenderText()->GetUpdatedCursorBounds()); |
| location.set_x(GetMirroredXForRect(location)); |
| cursor_view_.SetBoundsRect(location); |
| @@ -2089,7 +2098,7 @@ void Textfield::StopBlinkingCursor() { |
| void Textfield::OnCursorBlinkTimerFired() { |
| DCHECK(ShouldBlinkCursor()); |
| cursor_view_.SetVisible(!cursor_view_.visible()); |
| - UpdateCursorView(); |
| + UpdateCursorViewPosition(); |
| } |
| } // namespace views |