OLD | NEW |
---|---|
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/macros.h" | 10 #include "base/macros.h" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 if (HasCompositionText()) | 434 if (HasCompositionText()) |
435 ConfirmCompositionText(); | 435 ConfirmCompositionText(); |
436 render_text_->ClearSelection(); | 436 render_text_->ClearSelection(); |
437 } | 437 } |
438 | 438 |
439 bool TextfieldModel::CanUndo() { | 439 bool TextfieldModel::CanUndo() { |
440 return edit_history_.size() && current_edit_ != edit_history_.end(); | 440 return edit_history_.size() && current_edit_ != edit_history_.end(); |
441 } | 441 } |
442 | 442 |
443 bool TextfieldModel::CanRedo() { | 443 bool TextfieldModel::CanRedo() { |
444 if (!edit_history_.size()) | 444 if (edit_history_.empty()) |
445 return false; | 445 return false; |
446 // There is no redo iff the current edit is the last element in the history. | 446 // There is no redo iff the current edit is the last element in the history. |
447 EditHistory::iterator iter = current_edit_; | 447 EditHistory::iterator iter = current_edit_; |
448 return iter == edit_history_.end() || // at the top. | 448 return iter == edit_history_.end() || // at the top. |
449 ++iter != edit_history_.end(); | 449 ++iter != edit_history_.end(); |
450 } | 450 } |
451 | 451 |
452 bool TextfieldModel::Undo() { | 452 bool TextfieldModel::Undo() { |
453 if (!CanUndo()) | 453 if (!CanUndo()) |
454 return false; | 454 return false; |
(...skipping 16 matching lines...) Expand all Loading... | |
471 bool TextfieldModel::Redo() { | 471 bool TextfieldModel::Redo() { |
472 if (!CanRedo()) | 472 if (!CanRedo()) |
473 return false; | 473 return false; |
474 DCHECK(!HasCompositionText()); | 474 DCHECK(!HasCompositionText()); |
475 if (HasCompositionText()) | 475 if (HasCompositionText()) |
476 CancelCompositionText(); | 476 CancelCompositionText(); |
477 | 477 |
478 if (current_edit_ == edit_history_.end()) | 478 if (current_edit_ == edit_history_.end()) |
479 current_edit_ = edit_history_.begin(); | 479 current_edit_ = edit_history_.begin(); |
480 else | 480 else |
481 current_edit_ ++; | 481 current_edit_++; |
Nico
2016/07/13 16:23:27
O_o
| |
482 base::string16 old = text(); | 482 base::string16 old = text(); |
483 size_t old_cursor = GetCursorPosition(); | 483 size_t old_cursor = GetCursorPosition(); |
484 (*current_edit_)->Redo(this); | 484 (*current_edit_)->Redo(this); |
485 return old != text() || old_cursor != GetCursorPosition(); | 485 return old != text() || old_cursor != GetCursorPosition(); |
486 } | 486 } |
487 | 487 |
488 bool TextfieldModel::Cut() { | 488 bool TextfieldModel::Cut() { |
489 if (!HasCompositionText() && HasSelection() && !render_text_->obscured()) { | 489 if (!HasCompositionText() && HasSelection() && !render_text_->obscured()) { |
490 ui::ScopedClipboardWriter( | 490 ui::ScopedClipboardWriter( |
491 ui::CLIPBOARD_TYPE_COPY_PASTE).WriteText(GetSelectedText()); | 491 ui::CLIPBOARD_TYPE_COPY_PASTE).WriteText(GetSelectedText()); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 ClearComposition(); | 804 ClearComposition(); |
805 if (delete_from != delete_to) | 805 if (delete_from != delete_to) |
806 render_text_->SetText(old_text.erase(delete_from, delete_to - delete_from)); | 806 render_text_->SetText(old_text.erase(delete_from, delete_to - delete_from)); |
807 if (!new_text.empty()) | 807 if (!new_text.empty()) |
808 render_text_->SetText(old_text.insert(new_text_insert_at, new_text)); | 808 render_text_->SetText(old_text.insert(new_text_insert_at, new_text)); |
809 render_text_->SetCursorPosition(new_cursor_pos); | 809 render_text_->SetCursorPosition(new_cursor_pos); |
810 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). | 810 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). |
811 } | 811 } |
812 | 812 |
813 } // namespace views | 813 } // namespace views |
OLD | NEW |