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

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

Issue 1492633004: Ensure that text with leading, trailing and interspersed tabs pasted into the textfield (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the TextfieldModelTest.Clipboard test Created 5 years 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
« no previous file with comments | « no previous file | ui/views/controls/textfield/textfield_model_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h"
11 #include "ui/base/clipboard/clipboard.h" 13 #include "ui/base/clipboard/clipboard.h"
12 #include "ui/base/clipboard/scoped_clipboard_writer.h" 14 #include "ui/base/clipboard/scoped_clipboard_writer.h"
13 #include "ui/gfx/range/range.h" 15 #include "ui/gfx/range/range.h"
14 #include "ui/gfx/utf16_indexing.h" 16 #include "ui/gfx/utf16_indexing.h"
15 17
16 namespace views { 18 namespace views {
17 19
18 namespace internal { 20 namespace internal {
19 21
20 // Edit holds state information to undo/redo editing changes. Editing operations 22 // Edit holds state information to undo/redo editing changes. Editing operations
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 bool TextfieldModel::Copy() { 504 bool TextfieldModel::Copy() {
503 if (!HasCompositionText() && HasSelection() && !render_text_->obscured()) { 505 if (!HasCompositionText() && HasSelection() && !render_text_->obscured()) {
504 ui::ScopedClipboardWriter( 506 ui::ScopedClipboardWriter(
505 ui::CLIPBOARD_TYPE_COPY_PASTE).WriteText(GetSelectedText()); 507 ui::CLIPBOARD_TYPE_COPY_PASTE).WriteText(GetSelectedText());
506 return true; 508 return true;
507 } 509 }
508 return false; 510 return false;
509 } 511 }
510 512
511 bool TextfieldModel::Paste() { 513 bool TextfieldModel::Paste() {
512 base::string16 result; 514 base::string16 text;
513 ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, 515 ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE,
514 &result); 516 &text);
515 if (result.empty()) 517 if (text.empty())
516 return false; 518 return false;
517 519
518 InsertTextInternal(result, false); 520 base::string16 actual_text = base::CollapseWhitespace(text, false);
521 // If the clipboard contains all whitespaces then paste a single space.
522 if (actual_text.empty())
523 actual_text = base::ASCIIToUTF16(" ");
524
525 InsertTextInternal(actual_text, false);
519 return true; 526 return true;
520 } 527 }
521 528
522 bool TextfieldModel::HasSelection() const { 529 bool TextfieldModel::HasSelection() const {
523 return !render_text_->selection().is_empty(); 530 return !render_text_->selection().is_empty();
524 } 531 }
525 532
526 void TextfieldModel::DeleteSelection() { 533 void TextfieldModel::DeleteSelection() {
527 DCHECK(!HasCompositionText()); 534 DCHECK(!HasCompositionText());
528 DCHECK(HasSelection()); 535 DCHECK(HasSelection());
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 ClearComposition(); 773 ClearComposition();
767 if (delete_from != delete_to) 774 if (delete_from != delete_to)
768 render_text_->SetText(old_text.erase(delete_from, delete_to - delete_from)); 775 render_text_->SetText(old_text.erase(delete_from, delete_to - delete_from));
769 if (!new_text.empty()) 776 if (!new_text.empty())
770 render_text_->SetText(old_text.insert(new_text_insert_at, new_text)); 777 render_text_->SetText(old_text.insert(new_text_insert_at, new_text));
771 render_text_->SetCursorPosition(new_cursor_pos); 778 render_text_->SetCursorPosition(new_cursor_pos);
772 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). 779 // TODO(oshima): Select text that was just undone, like Mac (but not GTK).
773 } 780 }
774 781
775 } // namespace views 782 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/textfield/textfield_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698