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 3a417b19029a1274367a2506e6d39bf139e9d010..98664182f5e246d083c7340659b48b0d56a0d2b5 100644 |
| --- a/ui/views/controls/textfield/textfield.cc |
| +++ b/ui/views/controls/textfield/textfield.cc |
| @@ -262,6 +262,11 @@ Textfield::Textfield() |
| weak_ptr_factory_(this) { |
| set_context_menu_controller(this); |
| set_drag_controller(this); |
| + cursor_view_.reset(new views::View()); |
| + cursor_view_->SetPaintToLayer(ui::LAYER_SOLID_COLOR); |
| + cursor_view_->layer()->SetColor(GetTextColor()); |
| + cursor_view_->set_owned_by_client(); |
| + AddChildView(cursor_view_.get()); |
| GetRenderText()->SetFontList(GetDefaultFontList()); |
| View::SetBorder(std::unique_ptr<Border>(new FocusableBorder())); |
| SetFocusBehavior(FocusBehavior::ALWAYS); |
| @@ -955,7 +960,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); |
| if (GetInputMethod()) |
| GetInputMethod()->SetFocusedTextInputClient(this); |
| OnCaretBoundsChanged(); |
| @@ -966,6 +971,7 @@ void Textfield::OnFocus() { |
| ? ui::NativeTheme::kColorId_AlertSeverityHigh |
| : ui::NativeTheme::kColorId_NumColors); |
| } |
| + RepaintCursor(); |
| SchedulePaint(); |
| View::OnFocus(); |
| } |
| @@ -976,8 +982,8 @@ void Textfield::OnBlur() { |
| if (GetInputMethod()) |
| GetInputMethod()->DetachTextInputClient(this); |
| StopBlinkingCursor(); |
| - if (render_text->cursor_visible()) { |
| - render_text->set_cursor_visible(false); |
| + if (cursor_view_->visible()) { |
| + cursor_view_->SetVisible(false); |
| RepaintCursor(); |
| } |
| @@ -1001,6 +1007,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,7 +1885,7 @@ void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { |
| NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); |
| } |
| if (cursor_changed) { |
| - GetRenderText()->set_cursor_visible(ShouldShowCursor()); |
| + cursor_view_->SetVisible(ShouldShowCursor()); |
| RepaintCursor(); |
| if (ShouldBlinkCursor()) |
| StartBlinkingCursor(); |
| @@ -1897,9 +1904,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); |
| + cursor_view_->SetBoundsRect(GetRenderText()->GetUpdatedCursorBounds()); |
| + SchedulePaint(); |
|
sadrul
2017/02/02 17:15:32
You shouldn't reschedule a paint here, because the
yiyix
2017/02/06 21:36:17
Done.
|
| } |
| void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) { |
| @@ -2058,8 +2064,7 @@ void Textfield::StopBlinkingCursor() { |
| void Textfield::OnCursorBlinkTimerFired() { |
| DCHECK(ShouldBlinkCursor()); |
| - gfx::RenderText* render_text = GetRenderText(); |
| - render_text->set_cursor_visible(!render_text->cursor_visible()); |
| + cursor_view_->SetVisible(!cursor_view_->visible()); |
|
sadrul
2017/02/02 17:15:32
If you update the visibility in UpdateCursorView()
yiyix
2017/02/06 21:36:17
As we have discussed offline, keep the set visibil
|
| RepaintCursor(); |
| } |