Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/textfield/textfield_model.h" | 5 #include "ui/views/controls/textfield/textfield_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 | 394 |
| 395 bool TextfieldModel::MoveCursorTo(const gfx::Point& point, bool select) { | 395 bool TextfieldModel::MoveCursorTo(const gfx::Point& point, bool select) { |
| 396 if (HasCompositionText()) | 396 if (HasCompositionText()) |
| 397 ConfirmCompositionText(); | 397 ConfirmCompositionText(); |
| 398 gfx::SelectionModel cursor = render_text_->FindCursorPosition(point); | 398 gfx::SelectionModel cursor = render_text_->FindCursorPosition(point); |
| 399 if (select) | 399 if (select) |
| 400 cursor.set_selection_start(render_text_->selection().start()); | 400 cursor.set_selection_start(render_text_->selection().start()); |
| 401 return render_text_->MoveCursorTo(cursor); | 401 return render_text_->MoveCursorTo(cursor); |
| 402 } | 402 } |
| 403 | 403 |
| 404 void TextfieldModel::MoveCursorToStart(bool select) { | |
|
tapted
2016/04/06 23:29:38
I think these are misleading "Start" could be left
Elly Fong-Jones
2016/04/07 17:43:47
Okay, done and removed, and I added a unit test.
| |
| 405 MoveCursor(gfx::BreakType::LINE_BREAK, | |
| 406 gfx::VisualCursorDirection::CURSOR_LEFT, | |
| 407 select); | |
| 408 } | |
| 409 | |
| 410 void TextfieldModel::MoveCursorToEnd(bool select) { | |
| 411 MoveCursor(gfx::BreakType::LINE_BREAK, | |
| 412 gfx::VisualCursorDirection::CURSOR_RIGHT, | |
| 413 select); | |
| 414 } | |
| 415 | |
| 404 base::string16 TextfieldModel::GetSelectedText() const { | 416 base::string16 TextfieldModel::GetSelectedText() const { |
| 405 return text().substr(render_text_->selection().GetMin(), | 417 return text().substr(render_text_->selection().GetMin(), |
| 406 render_text_->selection().length()); | 418 render_text_->selection().length()); |
| 407 } | 419 } |
| 408 | 420 |
| 409 void TextfieldModel::SelectRange(const gfx::Range& range) { | 421 void TextfieldModel::SelectRange(const gfx::Range& range) { |
| 410 if (HasCompositionText()) | 422 if (HasCompositionText()) |
| 411 ConfirmCompositionText(); | 423 ConfirmCompositionText(); |
| 412 render_text_->SelectRange(range); | 424 render_text_->SelectRange(range); |
| 413 } | 425 } |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 774 ClearComposition(); | 786 ClearComposition(); |
| 775 if (delete_from != delete_to) | 787 if (delete_from != delete_to) |
| 776 render_text_->SetText(old_text.erase(delete_from, delete_to - delete_from)); | 788 render_text_->SetText(old_text.erase(delete_from, delete_to - delete_from)); |
| 777 if (!new_text.empty()) | 789 if (!new_text.empty()) |
| 778 render_text_->SetText(old_text.insert(new_text_insert_at, new_text)); | 790 render_text_->SetText(old_text.insert(new_text_insert_at, new_text)); |
| 779 render_text_->SetCursorPosition(new_cursor_pos); | 791 render_text_->SetCursorPosition(new_cursor_pos); |
| 780 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). | 792 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). |
| 781 } | 793 } |
| 782 | 794 |
| 783 } // namespace views | 795 } // namespace views |
| OLD | NEW |