OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/textfield/textfield_views_model.h" | 5 #include "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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 return GetText().substr(render_text_->MinOfSelection(), | 407 return GetText().substr(render_text_->MinOfSelection(), |
408 (render_text_->MaxOfSelection() - render_text_->MinOfSelection())); | 408 (render_text_->MaxOfSelection() - render_text_->MinOfSelection())); |
409 } | 409 } |
410 | 410 |
411 void TextfieldViewsModel::GetSelectedRange(ui::Range* range) const { | 411 void TextfieldViewsModel::GetSelectedRange(ui::Range* range) const { |
412 range->set_start(render_text_->GetSelectionStart()); | 412 range->set_start(render_text_->GetSelectionStart()); |
413 range->set_end(render_text_->GetCursorPosition()); | 413 range->set_end(render_text_->GetCursorPosition()); |
414 } | 414 } |
415 | 415 |
416 void TextfieldViewsModel::SelectRange(const ui::Range& range) { | 416 void TextfieldViewsModel::SelectRange(const ui::Range& range) { |
417 gfx::SelectionModel selection(range.start(), range.end(), | 417 gfx::SelectionModel selection(range.start(), range.end()); |
418 range.end(), gfx::SelectionModel::PREVIOUS_GRAPHEME_TRAILING); | |
419 SelectSelectionModel(selection); | 418 SelectSelectionModel(selection); |
420 } | 419 } |
421 | 420 |
422 void TextfieldViewsModel::SelectSelectionModel(const gfx::SelectionModel& sel) { | 421 void TextfieldViewsModel::SelectSelectionModel(const gfx::SelectionModel& sel) { |
423 if (HasCompositionText()) | 422 if (HasCompositionText()) |
424 ConfirmCompositionText(); | 423 ConfirmCompositionText(); |
425 render_text_->SetSelectionModel(sel); | 424 render_text_->SetSelectionModel(sel); |
426 } | 425 } |
427 | 426 |
428 void TextfieldViewsModel::SelectAll() { | 427 void TextfieldViewsModel::SelectAll() { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 render_text_->SetText(new_text.insert(cursor, composition.text)); | 581 render_text_->SetText(new_text.insert(cursor, composition.text)); |
583 ui::Range range(cursor, cursor + composition.text.length()); | 582 ui::Range range(cursor, cursor + composition.text.length()); |
584 render_text_->SetCompositionRange(range); | 583 render_text_->SetCompositionRange(range); |
585 // TODO(msw): Support multiple composition underline ranges. | 584 // TODO(msw): Support multiple composition underline ranges. |
586 | 585 |
587 if (composition.selection.IsValid()) { | 586 if (composition.selection.IsValid()) { |
588 size_t start = | 587 size_t start = |
589 std::min(range.start() + composition.selection.start(), range.end()); | 588 std::min(range.start() + composition.selection.start(), range.end()); |
590 size_t end = | 589 size_t end = |
591 std::min(range.start() + composition.selection.end(), range.end()); | 590 std::min(range.start() + composition.selection.end(), range.end()); |
592 gfx::SelectionModel sel(start, end, end, | 591 gfx::SelectionModel sel(start, end); |
593 gfx::SelectionModel::PREVIOUS_GRAPHEME_TRAILING); | |
594 render_text_->SetSelectionModel(sel); | 592 render_text_->SetSelectionModel(sel); |
595 } else { | 593 } else { |
596 render_text_->SetCursorPosition(range.end()); | 594 render_text_->SetCursorPosition(range.end()); |
597 } | 595 } |
598 } | 596 } |
599 | 597 |
600 void TextfieldViewsModel::ConfirmCompositionText() { | 598 void TextfieldViewsModel::ConfirmCompositionText() { |
601 DCHECK(HasCompositionText()); | 599 DCHECK(HasCompositionText()); |
602 ui::Range range = render_text_->GetCompositionRange(); | 600 ui::Range range = render_text_->GetCompositionRange(); |
603 string16 text = GetText().substr(range.start(), range.length()); | 601 string16 text = GetText().substr(range.start(), range.length()); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 if (delete_from != delete_to) | 775 if (delete_from != delete_to) |
778 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); | 776 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); |
779 if (!new_text.empty()) | 777 if (!new_text.empty()) |
780 render_text_->SetText(text.insert(new_text_insert_at, new_text)); | 778 render_text_->SetText(text.insert(new_text_insert_at, new_text)); |
781 render_text_->SetCursorPosition(new_cursor_pos); | 779 render_text_->SetCursorPosition(new_cursor_pos); |
782 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). | 780 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). |
783 // This looks fine feature and we may want to do the same. | 781 // This looks fine feature and we may want to do the same. |
784 } | 782 } |
785 | 783 |
786 } // namespace views | 784 } // namespace views |
OLD | NEW |