| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/textfield/textfield_views_model.h" | 5 #include "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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 bool TextfieldViewsModel::Cut() { | 493 bool TextfieldViewsModel::Cut() { |
| 494 if (!HasCompositionText() && HasSelection()) { | 494 if (!HasCompositionText() && HasSelection()) { |
| 495 ui::ScopedClipboardWriter(views::ViewsDelegate::views_delegate | 495 ui::ScopedClipboardWriter(views::ViewsDelegate::views_delegate |
| 496 ->GetClipboard()).WriteText(GetSelectedText()); | 496 ->GetClipboard()).WriteText(GetSelectedText()); |
| 497 // A trick to let undo/redo handle cursor correctly. | 497 // A trick to let undo/redo handle cursor correctly. |
| 498 // Undoing CUT moves the cursor to the end of the change rather | 498 // Undoing CUT moves the cursor to the end of the change rather |
| 499 // than beginning, unlike Delete/Backspace. | 499 // than beginning, unlike Delete/Backspace. |
| 500 // TODO(oshima): Change Delete/Backspace to use DeleteSelection, | 500 // TODO(oshima): Change Delete/Backspace to use DeleteSelection, |
| 501 // update DeleteEdit and remove this trick. | 501 // update DeleteEdit and remove this trick. |
| 502 gfx::SelectionModel sel(render_text_->GetCursorPosition(), | 502 gfx::SelectionModel sel(render_text_->GetCursorPosition(), |
| 503 render_text_->GetSelectionStart(), | 503 render_text_->GetSelectionStart()); |
| 504 render_text_->GetSelectionStart(), | |
| 505 gfx::SelectionModel::LEADING); | |
| 506 render_text_->MoveCursorTo(sel); | 504 render_text_->MoveCursorTo(sel); |
| 507 DeleteSelection(); | 505 DeleteSelection(); |
| 508 return true; | 506 return true; |
| 509 } | 507 } |
| 510 return false; | 508 return false; |
| 511 } | 509 } |
| 512 | 510 |
| 513 void TextfieldViewsModel::Copy() { | 511 void TextfieldViewsModel::Copy() { |
| 514 if (!HasCompositionText() && HasSelection()) { | 512 if (!HasCompositionText() && HasSelection()) { |
| 515 ui::ScopedClipboardWriter(views::ViewsDelegate::views_delegate | 513 ui::ScopedClipboardWriter(views::ViewsDelegate::views_delegate |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 if (delete_from != delete_to) | 768 if (delete_from != delete_to) |
| 771 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); | 769 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); |
| 772 if (!new_text.empty()) | 770 if (!new_text.empty()) |
| 773 render_text_->SetText(text.insert(new_text_insert_at, new_text)); | 771 render_text_->SetText(text.insert(new_text_insert_at, new_text)); |
| 774 render_text_->SetCursorPosition(new_cursor_pos); | 772 render_text_->SetCursorPosition(new_cursor_pos); |
| 775 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). | 773 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). |
| 776 // This looks fine feature and we may want to do the same. | 774 // This looks fine feature and we may want to do the same. |
| 777 } | 775 } |
| 778 | 776 |
| 779 } // namespace views | 777 } // namespace views |
| OLD | NEW |