| 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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 current_edit_ ++; | 504 current_edit_ ++; |
| 505 string16 old = GetText(); | 505 string16 old = GetText(); |
| 506 size_t old_cursor = GetCursorPosition(); | 506 size_t old_cursor = GetCursorPosition(); |
| 507 (*current_edit_)->Redo(this); | 507 (*current_edit_)->Redo(this); |
| 508 return old != GetText() || old_cursor != GetCursorPosition(); | 508 return old != GetText() || old_cursor != GetCursorPosition(); |
| 509 } | 509 } |
| 510 | 510 |
| 511 bool TextfieldViewsModel::Cut() { | 511 bool TextfieldViewsModel::Cut() { |
| 512 if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) { | 512 if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) { |
| 513 ui::ScopedClipboardWriter( | 513 ui::ScopedClipboardWriter( |
| 514 views::ViewsDelegate::views_delegate->GetClipboard(), | 514 ui::Clipboard::GetForCurrentThread(), |
| 515 ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText()); | 515 ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText()); |
| 516 // A trick to let undo/redo handle cursor correctly. | 516 // A trick to let undo/redo handle cursor correctly. |
| 517 // Undoing CUT moves the cursor to the end of the change rather | 517 // Undoing CUT moves the cursor to the end of the change rather |
| 518 // than beginning, unlike Delete/Backspace. | 518 // than beginning, unlike Delete/Backspace. |
| 519 // TODO(oshima): Change Delete/Backspace to use DeleteSelection, | 519 // TODO(oshima): Change Delete/Backspace to use DeleteSelection, |
| 520 // update DeleteEdit and remove this trick. | 520 // update DeleteEdit and remove this trick. |
| 521 const ui::Range& selection = render_text_->selection(); | 521 const ui::Range& selection = render_text_->selection(); |
| 522 render_text_->SelectRange(ui::Range(selection.end(), selection.start())); | 522 render_text_->SelectRange(ui::Range(selection.end(), selection.start())); |
| 523 DeleteSelection(); | 523 DeleteSelection(); |
| 524 return true; | 524 return true; |
| 525 } | 525 } |
| 526 return false; | 526 return false; |
| 527 } | 527 } |
| 528 | 528 |
| 529 bool TextfieldViewsModel::Copy() { | 529 bool TextfieldViewsModel::Copy() { |
| 530 if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) { | 530 if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) { |
| 531 ui::ScopedClipboardWriter( | 531 ui::ScopedClipboardWriter( |
| 532 views::ViewsDelegate::views_delegate->GetClipboard(), | 532 ui::Clipboard::GetForCurrentThread(), |
| 533 ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText()); | 533 ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText()); |
| 534 return true; | 534 return true; |
| 535 } | 535 } |
| 536 return false; | 536 return false; |
| 537 } | 537 } |
| 538 | 538 |
| 539 bool TextfieldViewsModel::Paste() { | 539 bool TextfieldViewsModel::Paste() { |
| 540 string16 result; | 540 string16 result; |
| 541 views::ViewsDelegate::views_delegate->GetClipboard() | 541 ui::Clipboard::GetForCurrentThread() |
| 542 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result); | 542 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result); |
| 543 if (!result.empty()) { | 543 if (!result.empty()) { |
| 544 InsertTextInternal(result, false); | 544 InsertTextInternal(result, false); |
| 545 return true; | 545 return true; |
| 546 } | 546 } |
| 547 return false; | 547 return false; |
| 548 } | 548 } |
| 549 | 549 |
| 550 bool TextfieldViewsModel::HasSelection() const { | 550 bool TextfieldViewsModel::HasSelection() const { |
| 551 return !render_text_->selection().is_empty(); | 551 return !render_text_->selection().is_empty(); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 if (delete_from != delete_to) | 781 if (delete_from != delete_to) |
| 782 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); | 782 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); |
| 783 if (!new_text.empty()) | 783 if (!new_text.empty()) |
| 784 render_text_->SetText(text.insert(new_text_insert_at, new_text)); | 784 render_text_->SetText(text.insert(new_text_insert_at, new_text)); |
| 785 render_text_->SetCursorPosition(new_cursor_pos); | 785 render_text_->SetCursorPosition(new_cursor_pos); |
| 786 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). | 786 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). |
| 787 // This looks fine feature and we may want to do the same. | 787 // This looks fine feature and we may want to do the same. |
| 788 } | 788 } |
| 789 | 789 |
| 790 } // namespace views | 790 } // namespace views |
| OLD | NEW |