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

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

Issue 10916214: Try 2 - Change how ui::Clipboard is accessed so there's only one per thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved to BrowserThreadsStarted Created 8 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 | Annotate | Revision Log
OLDNEW
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"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "ui/base/clipboard/clipboard.h" 13 #include "ui/base/clipboard/clipboard.h"
14 #include "ui/base/clipboard/scoped_clipboard_writer.h" 14 #include "ui/base/clipboard/scoped_clipboard_writer.h"
15 #include "ui/base/native_theme/native_theme.h" 15 #include "ui/base/native_theme/native_theme.h"
16 #include "ui/base/range/range.h" 16 #include "ui/base/range/range.h"
17 #include "ui/base/text/utf16_indexing.h" 17 #include "ui/base/text/utf16_indexing.h"
18 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/font.h" 19 #include "ui/gfx/font.h"
20 #include "ui/gfx/render_text.h" 20 #include "ui/gfx/render_text.h"
21 #include "ui/gfx/text_constants.h" 21 #include "ui/gfx/text_constants.h"
22 #include "ui/views/controls/textfield/textfield.h" 22 #include "ui/views/controls/textfield/textfield.h"
23 #include "ui/views/views_delegate.h"
24 23
25 namespace views { 24 namespace views {
26 25
27 namespace internal { 26 namespace internal {
28 27
29 // An edit object holds enough information/state to undo/redo the 28 // An edit object holds enough information/state to undo/redo the
30 // change. Two edits are merged when possible, for example, when 29 // change. Two edits are merged when possible, for example, when
31 // you type new characters in sequence. |Commit()| can be used to 30 // you type new characters in sequence. |Commit()| can be used to
32 // mark an edit as an independent edit and it shouldn't be merged. 31 // mark an edit as an independent edit and it shouldn't be merged.
33 // (For example, when you did undo/redo, or a text is appended via 32 // (For example, when you did undo/redo, or a text is appended via
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 current_edit_ ++; 503 current_edit_ ++;
505 string16 old = GetText(); 504 string16 old = GetText();
506 size_t old_cursor = GetCursorPosition(); 505 size_t old_cursor = GetCursorPosition();
507 (*current_edit_)->Redo(this); 506 (*current_edit_)->Redo(this);
508 return old != GetText() || old_cursor != GetCursorPosition(); 507 return old != GetText() || old_cursor != GetCursorPosition();
509 } 508 }
510 509
511 bool TextfieldViewsModel::Cut() { 510 bool TextfieldViewsModel::Cut() {
512 if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) { 511 if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) {
513 ui::ScopedClipboardWriter( 512 ui::ScopedClipboardWriter(
514 views::ViewsDelegate::views_delegate->GetClipboard(), 513 ui::Clipboard::GetForCurrentThread(),
515 ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText()); 514 ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText());
516 // A trick to let undo/redo handle cursor correctly. 515 // A trick to let undo/redo handle cursor correctly.
517 // Undoing CUT moves the cursor to the end of the change rather 516 // Undoing CUT moves the cursor to the end of the change rather
518 // than beginning, unlike Delete/Backspace. 517 // than beginning, unlike Delete/Backspace.
519 // TODO(oshima): Change Delete/Backspace to use DeleteSelection, 518 // TODO(oshima): Change Delete/Backspace to use DeleteSelection,
520 // update DeleteEdit and remove this trick. 519 // update DeleteEdit and remove this trick.
521 const ui::Range& selection = render_text_->selection(); 520 const ui::Range& selection = render_text_->selection();
522 render_text_->SelectRange(ui::Range(selection.end(), selection.start())); 521 render_text_->SelectRange(ui::Range(selection.end(), selection.start()));
523 DeleteSelection(); 522 DeleteSelection();
524 return true; 523 return true;
525 } 524 }
526 return false; 525 return false;
527 } 526 }
528 527
529 bool TextfieldViewsModel::Copy() { 528 bool TextfieldViewsModel::Copy() {
530 if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) { 529 if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) {
531 ui::ScopedClipboardWriter( 530 ui::ScopedClipboardWriter(
532 views::ViewsDelegate::views_delegate->GetClipboard(), 531 ui::Clipboard::GetForCurrentThread(),
533 ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText()); 532 ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText());
534 return true; 533 return true;
535 } 534 }
536 return false; 535 return false;
537 } 536 }
538 537
539 bool TextfieldViewsModel::Paste() { 538 bool TextfieldViewsModel::Paste() {
540 string16 result; 539 string16 result;
541 views::ViewsDelegate::views_delegate->GetClipboard() 540 ui::Clipboard::GetForCurrentThread()
542 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result); 541 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
543 if (!result.empty()) { 542 if (!result.empty()) {
544 InsertTextInternal(result, false); 543 InsertTextInternal(result, false);
545 return true; 544 return true;
546 } 545 }
547 return false; 546 return false;
548 } 547 }
549 548
550 bool TextfieldViewsModel::HasSelection() const { 549 bool TextfieldViewsModel::HasSelection() const {
551 return !render_text_->selection().is_empty(); 550 return !render_text_->selection().is_empty();
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 if (delete_from != delete_to) 780 if (delete_from != delete_to)
782 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); 781 render_text_->SetText(text.erase(delete_from, delete_to - delete_from));
783 if (!new_text.empty()) 782 if (!new_text.empty())
784 render_text_->SetText(text.insert(new_text_insert_at, new_text)); 783 render_text_->SetText(text.insert(new_text_insert_at, new_text));
785 render_text_->SetCursorPosition(new_cursor_pos); 784 render_text_->SetCursorPosition(new_cursor_pos);
786 // 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).
787 // 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.
788 } 787 }
789 788
790 } // namespace views 789 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/native_textfield_win.cc ('k') | ui/views/controls/textfield/textfield_views_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698