Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: ui/views/controls/textfield/textfield_model.cc

Issue 558913003: Remove clipboard argument from ScopedClipboardWriter constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't leak a clipboard on Windows Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 current_edit_ ++; 478 current_edit_ ++;
479 base::string16 old = text(); 479 base::string16 old = text();
480 size_t old_cursor = GetCursorPosition(); 480 size_t old_cursor = GetCursorPosition();
481 (*current_edit_)->Redo(this); 481 (*current_edit_)->Redo(this);
482 return old != text() || old_cursor != GetCursorPosition(); 482 return old != text() || old_cursor != GetCursorPosition();
483 } 483 }
484 484
485 bool TextfieldModel::Cut() { 485 bool TextfieldModel::Cut() {
486 if (!HasCompositionText() && HasSelection() && !render_text_->obscured()) { 486 if (!HasCompositionText() && HasSelection() && !render_text_->obscured()) {
487 ui::ScopedClipboardWriter( 487 ui::ScopedClipboardWriter(
488 ui::Clipboard::GetForCurrentThread(),
489 ui::CLIPBOARD_TYPE_COPY_PASTE).WriteText(GetSelectedText()); 488 ui::CLIPBOARD_TYPE_COPY_PASTE).WriteText(GetSelectedText());
490 // A trick to let undo/redo handle cursor correctly. 489 // A trick to let undo/redo handle cursor correctly.
491 // Undoing CUT moves the cursor to the end of the change rather 490 // Undoing CUT moves the cursor to the end of the change rather
492 // than beginning, unlike Delete/Backspace. 491 // than beginning, unlike Delete/Backspace.
493 // TODO(oshima): Change Delete/Backspace to use DeleteSelection, 492 // TODO(oshima): Change Delete/Backspace to use DeleteSelection,
494 // update DeleteEdit and remove this trick. 493 // update DeleteEdit and remove this trick.
495 const gfx::Range& selection = render_text_->selection(); 494 const gfx::Range& selection = render_text_->selection();
496 render_text_->SelectRange(gfx::Range(selection.end(), selection.start())); 495 render_text_->SelectRange(gfx::Range(selection.end(), selection.start()));
497 DeleteSelection(); 496 DeleteSelection();
498 return true; 497 return true;
499 } 498 }
500 return false; 499 return false;
501 } 500 }
502 501
503 bool TextfieldModel::Copy() { 502 bool TextfieldModel::Copy() {
504 if (!HasCompositionText() && HasSelection() && !render_text_->obscured()) { 503 if (!HasCompositionText() && HasSelection() && !render_text_->obscured()) {
505 ui::ScopedClipboardWriter( 504 ui::ScopedClipboardWriter(
506 ui::Clipboard::GetForCurrentThread(),
507 ui::CLIPBOARD_TYPE_COPY_PASTE).WriteText(GetSelectedText()); 505 ui::CLIPBOARD_TYPE_COPY_PASTE).WriteText(GetSelectedText());
508 return true; 506 return true;
509 } 507 }
510 return false; 508 return false;
511 } 509 }
512 510
513 bool TextfieldModel::Paste() { 511 bool TextfieldModel::Paste() {
514 base::string16 result; 512 base::string16 result;
515 ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, 513 ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE,
516 &result); 514 &result);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 ClearComposition(); 760 ClearComposition();
763 if (delete_from != delete_to) 761 if (delete_from != delete_to)
764 render_text_->SetText(old_text.erase(delete_from, delete_to - delete_from)); 762 render_text_->SetText(old_text.erase(delete_from, delete_to - delete_from));
765 if (!new_text.empty()) 763 if (!new_text.empty())
766 render_text_->SetText(old_text.insert(new_text_insert_at, new_text)); 764 render_text_->SetText(old_text.insert(new_text_insert_at, new_text));
767 render_text_->SetCursorPosition(new_cursor_pos); 765 render_text_->SetCursorPosition(new_cursor_pos);
768 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). 766 // TODO(oshima): Select text that was just undone, like Mac (but not GTK).
769 } 767 }
770 768
771 } // namespace views 769 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/controls/textfield/textfield_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698