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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 else | 492 else |
493 current_edit_ ++; | 493 current_edit_ ++; |
494 string16 old = GetText(); | 494 string16 old = GetText(); |
495 size_t old_cursor = GetCursorPosition(); | 495 size_t old_cursor = GetCursorPosition(); |
496 (*current_edit_)->Redo(this); | 496 (*current_edit_)->Redo(this); |
497 return old != GetText() || old_cursor != GetCursorPosition(); | 497 return old != GetText() || old_cursor != GetCursorPosition(); |
498 } | 498 } |
499 | 499 |
500 bool TextfieldViewsModel::Cut() { | 500 bool TextfieldViewsModel::Cut() { |
501 if (!HasCompositionText() && HasSelection()) { | 501 if (!HasCompositionText() && HasSelection()) { |
502 ui::ScopedClipboardWriter(views::ViewsDelegate::views_delegate | 502 ui::ScopedClipboardWriter( |
503 ->GetClipboard()).WriteText(GetSelectedText()); | 503 views::ViewsDelegate::views_delegate->GetClipboard(), |
| 504 ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText()); |
504 // A trick to let undo/redo handle cursor correctly. | 505 // A trick to let undo/redo handle cursor correctly. |
505 // Undoing CUT moves the cursor to the end of the change rather | 506 // Undoing CUT moves the cursor to the end of the change rather |
506 // than beginning, unlike Delete/Backspace. | 507 // than beginning, unlike Delete/Backspace. |
507 // TODO(oshima): Change Delete/Backspace to use DeleteSelection, | 508 // TODO(oshima): Change Delete/Backspace to use DeleteSelection, |
508 // update DeleteEdit and remove this trick. | 509 // update DeleteEdit and remove this trick. |
509 render_text_->SelectRange(ui::Range(render_text_->GetCursorPosition(), | 510 render_text_->SelectRange(ui::Range(render_text_->GetCursorPosition(), |
510 render_text_->GetSelectionStart())); | 511 render_text_->GetSelectionStart())); |
511 DeleteSelection(); | 512 DeleteSelection(); |
512 return true; | 513 return true; |
513 } | 514 } |
514 return false; | 515 return false; |
515 } | 516 } |
516 | 517 |
517 bool TextfieldViewsModel::Copy() { | 518 bool TextfieldViewsModel::Copy() { |
518 if (!HasCompositionText() && HasSelection()) { | 519 if (!HasCompositionText() && HasSelection()) { |
519 ui::ScopedClipboardWriter(views::ViewsDelegate::views_delegate | 520 ui::ScopedClipboardWriter( |
520 ->GetClipboard()).WriteText(GetSelectedText()); | 521 views::ViewsDelegate::views_delegate->GetClipboard(), |
| 522 ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText()); |
521 return true; | 523 return true; |
522 } | 524 } |
523 return false; | 525 return false; |
524 } | 526 } |
525 | 527 |
526 bool TextfieldViewsModel::Paste() { | 528 bool TextfieldViewsModel::Paste() { |
527 string16 result; | 529 string16 result; |
528 views::ViewsDelegate::views_delegate->GetClipboard() | 530 views::ViewsDelegate::views_delegate->GetClipboard() |
529 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result); | 531 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result); |
530 if (!result.empty()) { | 532 if (!result.empty()) { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 if (delete_from != delete_to) | 776 if (delete_from != delete_to) |
775 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); | 777 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); |
776 if (!new_text.empty()) | 778 if (!new_text.empty()) |
777 render_text_->SetText(text.insert(new_text_insert_at, new_text)); | 779 render_text_->SetText(text.insert(new_text_insert_at, new_text)); |
778 render_text_->SetCursorPosition(new_cursor_pos); | 780 render_text_->SetCursorPosition(new_cursor_pos); |
779 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). | 781 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). |
780 // This looks fine feature and we may want to do the same. | 782 // This looks fine feature and we may want to do the same. |
781 } | 783 } |
782 | 784 |
783 } // namespace views | 785 } // namespace views |
OLD | NEW |