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 68aa01ec3bd832958bcc74db80c22734a5f3398c..057c7536cd39468dce99b0339dd5556a2d557fcd 100644 |
| --- a/ui/views/controls/textfield/textfield.cc |
| +++ b/ui/views/controls/textfield/textfield.cc |
| @@ -312,16 +312,16 @@ base::i18n::TextDirection Textfield::GetTextDirection() const { |
| return GetRenderText()->GetTextDirection(); |
| } |
| +base::string16 Textfield::GetSelectedText() const { |
| + return model_->GetSelectedText(); |
| +} |
| + |
| void Textfield::SelectAll(bool reversed) { |
| model_->SelectAll(reversed); |
| UpdateSelectionClipboard(); |
| UpdateAfterChange(false, true); |
| } |
| -base::string16 Textfield::GetSelectedText() const { |
| - return model_->GetSelectedText(); |
| -} |
| - |
| void Textfield::ClearSelection() { |
| model_->ClearSelection(); |
| UpdateAfterChange(false, true); |
| @@ -552,35 +552,31 @@ bool Textfield::OnMousePressed(const ui::MouseEvent& event) { |
| } |
| bool Textfield::OnMouseDragged(const ui::MouseEvent& event) { |
| + last_drag_location_ = event.location(); |
| + |
| // Don't adjust the cursor on a potential drag and drop, or if the mouse |
| // movement from the last mouse click does not exceed the drag threshold. |
| if (initiating_drag_ || !event.IsOnlyLeftMouseButton() || |
| - !ExceededDragThreshold(event.location() - last_click_location_)) { |
| + !ExceededDragThreshold(last_drag_location_ - last_click_location_)) { |
| return true; |
| } |
| - OnBeforeUserAction(); |
| - model_->MoveCursorTo(event.location(), true); |
| - if (aggregated_clicks_ == 1) { |
| - model_->SelectWord(); |
| - // Expand the selection so the initially selected word remains selected. |
| - gfx::Range selection = GetRenderText()->selection(); |
| - const size_t min = std::min(selection.GetMin(), |
| - double_click_word_.GetMin()); |
| - const size_t max = std::max(selection.GetMax(), |
| - double_click_word_.GetMax()); |
| - const bool reversed = selection.is_reversed(); |
| - selection.set_start(reversed ? max : min); |
| - selection.set_end(reversed ? min : max); |
| - model_->SelectRange(selection); |
| + // A timer is used to continuously scroll while selecting beyond side edges. |
| + if (last_drag_location_.x() > 0 && last_drag_location_.x() < size().width()) { |
| + drag_selection_timer_.Stop(); |
| + SelectThroughLastDragLocation(); |
| + } else if (!drag_selection_timer_.IsRunning()) { |
| + drag_selection_timer_.Start( |
| + FROM_HERE, base::TimeDelta::FromMilliseconds(100), this, |
| + &Textfield::SelectThroughLastDragLocation); |
| } |
| - UpdateAfterChange(false, true); |
| - OnAfterUserAction(); |
| + |
| return true; |
| } |
| void Textfield::OnMouseReleased(const ui::MouseEvent& event) { |
| OnBeforeUserAction(); |
| + drag_selection_timer_.Stop(); |
| // Cancel suspected drag initiations, the user was clicking in the selection. |
| if (initiating_drag_) |
| MoveCursorTo(event.location(), false); |
| @@ -1542,6 +1538,26 @@ void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { |
| UpdateAfterChange(false, true); |
| } |
| +void Textfield::SelectThroughLastDragLocation() { |
| + OnBeforeUserAction(); |
| + model_->MoveCursorTo(last_drag_location_, true); |
|
Peter Kasting
2014/05/21 22:44:28
How does this work with off-Textfield cursor locat
msw
2014/05/21 23:15:10
Yes, that's how it works currently, and I think it
|
| + if (aggregated_clicks_ == 1) { |
| + model_->SelectWord(); |
| + // Expand the selection so the initially selected word remains selected. |
| + gfx::Range selection = GetRenderText()->selection(); |
| + const size_t min = std::min(selection.GetMin(), |
| + double_click_word_.GetMin()); |
| + const size_t max = std::max(selection.GetMax(), |
| + double_click_word_.GetMax()); |
| + const bool reversed = selection.is_reversed(); |
| + selection.set_start(reversed ? max : min); |
| + selection.set_end(reversed ? min : max); |
| + model_->SelectRange(selection); |
| + } |
| + UpdateAfterChange(false, true); |
| + OnAfterUserAction(); |
| +} |
| + |
| void Textfield::OnCaretBoundsChanged() { |
| if (GetInputMethod()) |
| GetInputMethod()->OnCaretBoundsChanged(this); |