| Index: ui/views/controls/textfield/textfield.cc
|
| diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
|
| index 14736697771bda755ab2e7e08f2ad70cc1fee919..c9e02514e30be4347eb0e19a6dd81195b2168fa2 100644
|
| --- a/ui/views/controls/textfield/textfield.cc
|
| +++ b/ui/views/controls/textfield/textfield.cc
|
| @@ -255,7 +255,6 @@ Textfield::Textfield()
|
| text_input_flags_(0),
|
| performing_user_action_(false),
|
| skip_input_method_cancel_composition_(false),
|
| - cursor_visible_(false),
|
| drop_cursor_visible_(false),
|
| initiating_drag_(false),
|
| aggregated_clicks_(0),
|
| @@ -852,6 +851,8 @@ int Textfield::OnDragUpdated(const ui::DropTargetEvent& event) {
|
| OnCaretBoundsChanged();
|
| SchedulePaint();
|
|
|
| + StopBlinkingCursor();
|
| +
|
| if (initiating_drag_) {
|
| if (in_selection)
|
| return ui::DragDropTypes::DRAG_NONE;
|
| @@ -863,6 +864,8 @@ int Textfield::OnDragUpdated(const ui::DropTargetEvent& event) {
|
|
|
| void Textfield::OnDragExited() {
|
| drop_cursor_visible_ = false;
|
| + if (ShouldBlinkCursor())
|
| + StartBlinkingCursor();
|
| SchedulePaint();
|
| }
|
|
|
| @@ -974,30 +977,26 @@ void Textfield::OnPaint(gfx::Canvas* canvas) {
|
|
|
| void Textfield::OnFocus() {
|
| GetRenderText()->set_focused(true);
|
| - cursor_visible_ = true;
|
| + if (ShouldShowCursor())
|
| + GetRenderText()->set_cursor_visible(true);
|
| SchedulePaint();
|
| if (GetInputMethod())
|
| GetInputMethod()->SetFocusedTextInputClient(this);
|
| OnCaretBoundsChanged();
|
| -
|
| - const size_t caret_blink_ms = Textfield::GetCaretBlinkMs();
|
| - if (caret_blink_ms != 0) {
|
| - cursor_repaint_timer_.Start(FROM_HERE,
|
| - base::TimeDelta::FromMilliseconds(caret_blink_ms), this,
|
| - &Textfield::UpdateCursor);
|
| - }
|
| -
|
| + if (ShouldBlinkCursor())
|
| + StartBlinkingCursor();
|
| View::OnFocus();
|
| SchedulePaint();
|
| }
|
|
|
| void Textfield::OnBlur() {
|
| - GetRenderText()->set_focused(false);
|
| + gfx::RenderText* render_text = GetRenderText();
|
| + render_text->set_focused(false);
|
| if (GetInputMethod())
|
| GetInputMethod()->DetachTextInputClient(this);
|
| - cursor_repaint_timer_.Stop();
|
| - if (cursor_visible_) {
|
| - cursor_visible_ = false;
|
| + StopBlinkingCursor();
|
| + if (render_text->cursor_visible()) {
|
| + render_text->set_cursor_visible(false);
|
| RepaintCursor();
|
| }
|
|
|
| @@ -1787,16 +1786,19 @@ void Textfield::UpdateBackgroundColor() {
|
| }
|
|
|
| void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) {
|
| + DCHECK(HasFocus());
|
| if (text_changed) {
|
| if (controller_)
|
| controller_->ContentsChanged(this, text());
|
| NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true);
|
| }
|
| if (cursor_changed) {
|
| - cursor_visible_ = true;
|
| + GetRenderText()->set_cursor_visible(ShouldShowCursor());
|
| RepaintCursor();
|
| - if (cursor_repaint_timer_.IsRunning())
|
| - cursor_repaint_timer_.Reset();
|
| + if (ShouldBlinkCursor())
|
| + StartBlinkingCursor();
|
| + else
|
| + StopBlinkingCursor();
|
| if (!text_changed) {
|
| // TEXT_CHANGED implies TEXT_SELECTION_CHANGED, so we only need to fire
|
| // this if only the selection changed.
|
| @@ -1809,12 +1811,6 @@ void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) {
|
| }
|
| }
|
|
|
| -void Textfield::UpdateCursor() {
|
| - const size_t caret_blink_ms = Textfield::GetCaretBlinkMs();
|
| - cursor_visible_ = !cursor_visible_ || (caret_blink_ms == 0);
|
| - RepaintCursor();
|
| -}
|
| -
|
| void Textfield::RepaintCursor() {
|
| gfx::Rect r(GetRenderText()->GetUpdatedCursorBounds());
|
| r.Inset(-1, -1, -1, -1);
|
| @@ -1835,9 +1831,6 @@ void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) {
|
| render_text->display_rect());
|
| }
|
|
|
| - // Draw the text, cursor, and selection.
|
| - render_text->set_cursor_visible(cursor_visible_ && !drop_cursor_visible_ &&
|
| - !HasSelection());
|
| render_text->Draw(canvas);
|
|
|
| // Draw the detached drop cursor that marks where the text will be dropped.
|
| @@ -2033,4 +2026,31 @@ void Textfield::PasteSelectionClipboard(const ui::MouseEvent& event) {
|
| OnAfterUserAction();
|
| }
|
|
|
| +bool Textfield::ShouldShowCursor() const {
|
| + return HasFocus() && !HasSelection() && enabled() && !read_only() &&
|
| + !drop_cursor_visible_;
|
| +}
|
| +
|
| +bool Textfield::ShouldBlinkCursor() const {
|
| + return ShouldShowCursor() && Textfield::GetCaretBlinkMs() != 0;
|
| +}
|
| +
|
| +void Textfield::StartBlinkingCursor() {
|
| + DCHECK(ShouldBlinkCursor());
|
| + cursor_blink_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(
|
| + Textfield::GetCaretBlinkMs()),
|
| + this, &Textfield::BlinkCursor);
|
| +}
|
| +
|
| +void Textfield::StopBlinkingCursor() {
|
| + cursor_blink_timer_.Stop();
|
| +}
|
| +
|
| +void Textfield::BlinkCursor() {
|
| + DCHECK(ShouldBlinkCursor());
|
| + gfx::RenderText* render_text = GetRenderText();
|
| + render_text->set_cursor_visible(!render_text->cursor_visible());
|
| + RepaintCursor();
|
| +}
|
| +
|
| } // namespace views
|
|
|