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

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

Issue 120503005: Merge NativeTextfieldViews into views::Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix touch drag and drop unit test. Created 6 years, 11 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"
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 645 }
646 646
647 void TextfieldViewsModel::GetCompositionTextRange(gfx::Range* range) const { 647 void TextfieldViewsModel::GetCompositionTextRange(gfx::Range* range) const {
648 *range = gfx::Range(render_text_->GetCompositionRange()); 648 *range = gfx::Range(render_text_->GetCompositionRange());
649 } 649 }
650 650
651 bool TextfieldViewsModel::HasCompositionText() const { 651 bool TextfieldViewsModel::HasCompositionText() const {
652 return !render_text_->GetCompositionRange().is_empty(); 652 return !render_text_->GetCompositionRange().is_empty();
653 } 653 }
654 654
655 void TextfieldViewsModel::ClearEditHistory() {
656 STLDeleteElements(&edit_history_);
657 current_edit_ = edit_history_.end();
658 }
659
655 ///////////////////////////////////////////////////////////////// 660 /////////////////////////////////////////////////////////////////
656 // TextfieldViewsModel: private 661 // TextfieldViewsModel: private
657 662
658 void TextfieldViewsModel::InsertTextInternal(const base::string16& text, 663 void TextfieldViewsModel::InsertTextInternal(const base::string16& text,
659 bool mergeable) { 664 bool mergeable) {
660 if (HasCompositionText()) { 665 if (HasCompositionText()) {
661 CancelCompositionText(); 666 CancelCompositionText();
662 ExecuteAndRecordInsert(text, mergeable); 667 ExecuteAndRecordInsert(text, mergeable);
663 } else if (HasSelection()) { 668 } else if (HasSelection()) {
664 ExecuteAndRecordReplaceSelection(mergeable ? MERGEABLE : DO_NOT_MERGE, 669 ExecuteAndRecordReplaceSelection(mergeable ? MERGEABLE : DO_NOT_MERGE,
(...skipping 16 matching lines...) Expand all
681 render_text_->IndexOfAdjacentGrapheme(cursor, gfx::CURSOR_FORWARD); 686 render_text_->IndexOfAdjacentGrapheme(cursor, gfx::CURSOR_FORWARD);
682 if (next == model.caret_pos()) 687 if (next == model.caret_pos())
683 render_text_->MoveCursorTo(model); 688 render_text_->MoveCursorTo(model);
684 else 689 else
685 render_text_->SelectRange(gfx::Range(next, model.caret_pos())); 690 render_text_->SelectRange(gfx::Range(next, model.caret_pos()));
686 } 691 }
687 // Edit history is recorded in InsertText. 692 // Edit history is recorded in InsertText.
688 InsertTextInternal(text, mergeable); 693 InsertTextInternal(text, mergeable);
689 } 694 }
690 695
691 void TextfieldViewsModel::ClearEditHistory() {
692 STLDeleteElements(&edit_history_);
693 current_edit_ = edit_history_.end();
694 }
695
696 void TextfieldViewsModel::ClearRedoHistory() { 696 void TextfieldViewsModel::ClearRedoHistory() {
697 if (edit_history_.begin() == edit_history_.end()) 697 if (edit_history_.begin() == edit_history_.end())
698 return; 698 return;
699 if (current_edit_ == edit_history_.end()) { 699 if (current_edit_ == edit_history_.end()) {
700 ClearEditHistory(); 700 ClearEditHistory();
701 return; 701 return;
702 } 702 }
703 EditHistory::iterator delete_start = current_edit_; 703 EditHistory::iterator delete_start = current_edit_;
704 delete_start++; 704 delete_start++;
705 STLDeleteContainerPointers(delete_start, edit_history_.end()); 705 STLDeleteContainerPointers(delete_start, edit_history_.end());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 if (delete_from != delete_to) 792 if (delete_from != delete_to)
793 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); 793 render_text_->SetText(text.erase(delete_from, delete_to - delete_from));
794 if (!new_text.empty()) 794 if (!new_text.empty())
795 render_text_->SetText(text.insert(new_text_insert_at, new_text)); 795 render_text_->SetText(text.insert(new_text_insert_at, new_text));
796 render_text_->SetCursorPosition(new_cursor_pos); 796 render_text_->SetCursorPosition(new_cursor_pos);
797 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). 797 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't).
798 // This looks fine feature and we may want to do the same. 798 // This looks fine feature and we may want to do the same.
799 } 799 }
800 800
801 } // namespace views 801 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698