| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_views_model.h" | 5 #include "ui/views/controls/textfield/textfield_views_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 if (HasCompositionText()) { | 310 if (HasCompositionText()) { |
| 311 ConfirmCompositionText(); | 311 ConfirmCompositionText(); |
| 312 changed = true; | 312 changed = true; |
| 313 } | 313 } |
| 314 if (GetText() != text) { | 314 if (GetText() != text) { |
| 315 if (changed) // No need to remember composition. | 315 if (changed) // No need to remember composition. |
| 316 Undo(); | 316 Undo(); |
| 317 size_t old_cursor = GetCursorPosition(); | 317 size_t old_cursor = GetCursorPosition(); |
| 318 // SetText moves the cursor to the end. | 318 // SetText moves the cursor to the end. |
| 319 size_t new_cursor = text.length(); | 319 size_t new_cursor = text.length(); |
| 320 SelectAll(); | 320 SelectAll(false); |
| 321 // If there is a composition text, don't merge with previous edit. | 321 // If there is a composition text, don't merge with previous edit. |
| 322 // Otherwise, force merge the edits. | 322 // Otherwise, force merge the edits. |
| 323 ExecuteAndRecordReplace( | 323 ExecuteAndRecordReplace( |
| 324 changed ? DO_NOT_MERGE : MERGE_WITH_PREVIOUS, | 324 changed ? DO_NOT_MERGE : MERGE_WITH_PREVIOUS, |
| 325 old_cursor, | 325 old_cursor, |
| 326 new_cursor, | 326 new_cursor, |
| 327 text, | 327 text, |
| 328 0U); | 328 0U); |
| 329 render_text_->SetCursorPosition(new_cursor); | 329 render_text_->SetCursorPosition(new_cursor); |
| 330 } | 330 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 void TextfieldViewsModel::GetSelectionModel(gfx::SelectionModel* sel) const { | 432 void TextfieldViewsModel::GetSelectionModel(gfx::SelectionModel* sel) const { |
| 433 *sel = render_text_->selection_model(); | 433 *sel = render_text_->selection_model(); |
| 434 } | 434 } |
| 435 | 435 |
| 436 void TextfieldViewsModel::SelectSelectionModel(const gfx::SelectionModel& sel) { | 436 void TextfieldViewsModel::SelectSelectionModel(const gfx::SelectionModel& sel) { |
| 437 if (HasCompositionText()) | 437 if (HasCompositionText()) |
| 438 ConfirmCompositionText(); | 438 ConfirmCompositionText(); |
| 439 render_text_->MoveCursorTo(sel); | 439 render_text_->MoveCursorTo(sel); |
| 440 } | 440 } |
| 441 | 441 |
| 442 void TextfieldViewsModel::SelectAll() { | 442 void TextfieldViewsModel::SelectAll(bool reversed) { |
| 443 if (HasCompositionText()) | 443 if (HasCompositionText()) |
| 444 ConfirmCompositionText(); | 444 ConfirmCompositionText(); |
| 445 render_text_->SelectAll(); | 445 render_text_->SelectAll(reversed); |
| 446 } | 446 } |
| 447 | 447 |
| 448 void TextfieldViewsModel::SelectWord() { | 448 void TextfieldViewsModel::SelectWord() { |
| 449 if (HasCompositionText()) | 449 if (HasCompositionText()) |
| 450 ConfirmCompositionText(); | 450 ConfirmCompositionText(); |
| 451 render_text_->SelectWord(); | 451 render_text_->SelectWord(); |
| 452 } | 452 } |
| 453 | 453 |
| 454 void TextfieldViewsModel::ClearSelection() { | 454 void TextfieldViewsModel::ClearSelection() { |
| 455 if (HasCompositionText()) | 455 if (HasCompositionText()) |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 if (delete_from != delete_to) | 780 if (delete_from != delete_to) |
| 781 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); | 781 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); |
| 782 if (!new_text.empty()) | 782 if (!new_text.empty()) |
| 783 render_text_->SetText(text.insert(new_text_insert_at, new_text)); | 783 render_text_->SetText(text.insert(new_text_insert_at, new_text)); |
| 784 render_text_->SetCursorPosition(new_cursor_pos); | 784 render_text_->SetCursorPosition(new_cursor_pos); |
| 785 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). | 785 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). |
| 786 // This looks fine feature and we may want to do the same. | 786 // This looks fine feature and we may want to do the same. |
| 787 } | 787 } |
| 788 | 788 |
| 789 } // namespace views | 789 } // namespace views |
| OLD | NEW |