Chromium Code Reviews| 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 DCHECK(base::MessageLoopForUI::IsCurrent()); | 275 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 276 return &kill_buffer; | 276 return &kill_buffer; |
| 277 } | 277 } |
| 278 | 278 |
| 279 // Helper method to set the kill buffer. | 279 // Helper method to set the kill buffer. |
| 280 void SetKillBuffer(const base::string16& buffer) { | 280 void SetKillBuffer(const base::string16& buffer) { |
| 281 base::string16* kill_buffer = GetKillBuffer(); | 281 base::string16* kill_buffer = GetKillBuffer(); |
| 282 *kill_buffer = buffer; | 282 *kill_buffer = buffer; |
| 283 } | 283 } |
| 284 | 284 |
| 285 void SelectRangeInCompositionText(gfx::RenderText* render_text, | |
| 286 size_t cursor, | |
| 287 const gfx::Range& range) { | |
| 288 DCHECK(render_text); | |
| 289 DCHECK(range.IsValid()); | |
| 290 uint32_t start = range.GetMin(); | |
| 291 uint32_t end = range.GetMax(); | |
| 292 #if defined(OS_CHROMEOS) | |
| 293 // Swap |start| and |end| so that GetCaretBounds() can always return the same | |
| 294 // value during conversion. | |
| 295 // TODO(yusukes): Check if this works for other platforms. If it is, use this | |
| 296 // on all platforms. | |
| 297 std::swap(start, end); | |
| 298 #endif | |
| 299 render_text->SelectRange(gfx::Range(cursor + start, cursor + end)); | |
|
oshima
2017/05/22 09:55:21
what's the reason why we don't change the UI side
Yusuke Sato
2017/05/22 16:55:02
That's another option, but strictly speaking, if w
| |
| 300 } | |
| 301 | |
| 285 } // namespace | 302 } // namespace |
| 286 | 303 |
| 287 using internal::Edit; | 304 using internal::Edit; |
| 288 using internal::DeleteEdit; | 305 using internal::DeleteEdit; |
| 289 using internal::InsertEdit; | 306 using internal::InsertEdit; |
| 290 using internal::ReplaceEdit; | 307 using internal::ReplaceEdit; |
| 291 using internal::MergeType; | 308 using internal::MergeType; |
| 292 using internal::DO_NOT_MERGE; | 309 using internal::DO_NOT_MERGE; |
| 293 using internal::FORCE_MERGE; | 310 using internal::FORCE_MERGE; |
| 294 using internal::MERGEABLE; | 311 using internal::MERGEABLE; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 render_text_->SetCompositionRange(gfx::Range::InvalidRange()); | 666 render_text_->SetCompositionRange(gfx::Range::InvalidRange()); |
| 650 gfx::Range emphasized_range = GetFirstEmphasizedRange(composition); | 667 gfx::Range emphasized_range = GetFirstEmphasizedRange(composition); |
| 651 if (emphasized_range.IsValid()) { | 668 if (emphasized_range.IsValid()) { |
| 652 // This is a workaround due to the lack of support in RenderText to draw | 669 // This is a workaround due to the lack of support in RenderText to draw |
| 653 // a thick underline. In a composition returned from an IME, the segment | 670 // a thick underline. In a composition returned from an IME, the segment |
| 654 // emphasized by a thick underline usually represents the target clause. | 671 // emphasized by a thick underline usually represents the target clause. |
| 655 // Because the target clause is more important than the actual selection | 672 // Because the target clause is more important than the actual selection |
| 656 // range (or caret position) in the composition here we use a selection-like | 673 // range (or caret position) in the composition here we use a selection-like |
| 657 // marker instead to show this range. | 674 // marker instead to show this range. |
| 658 // TODO(yukawa, msw): Support thick underlines and remove this workaround. | 675 // TODO(yukawa, msw): Support thick underlines and remove this workaround. |
| 659 render_text_->SelectRange(gfx::Range( | 676 SelectRangeInCompositionText(render_text_.get(), cursor, emphasized_range); |
| 660 cursor + emphasized_range.GetMin(), | |
| 661 cursor + emphasized_range.GetMax())); | |
| 662 } else if (!composition.selection.is_empty()) { | 677 } else if (!composition.selection.is_empty()) { |
| 663 render_text_->SelectRange(gfx::Range( | 678 SelectRangeInCompositionText(render_text_.get(), cursor, |
| 664 cursor + composition.selection.GetMin(), | 679 composition.selection); |
| 665 cursor + composition.selection.GetMax())); | |
| 666 } else { | 680 } else { |
| 667 render_text_->SetCursorPosition(cursor + composition.selection.end()); | 681 render_text_->SetCursorPosition(cursor + composition.selection.end()); |
| 668 } | 682 } |
| 669 } | 683 } |
| 670 | 684 |
| 671 void TextfieldModel::ConfirmCompositionText() { | 685 void TextfieldModel::ConfirmCompositionText() { |
| 672 DCHECK(HasCompositionText()); | 686 DCHECK(HasCompositionText()); |
| 673 base::string16 composition = text().substr( | 687 base::string16 composition = text().substr( |
| 674 composition_range_.start(), composition_range_.length()); | 688 composition_range_.start(), composition_range_.length()); |
| 675 // TODO(oshima): current behavior on ChromeOS is a bit weird and not | 689 // TODO(oshima): current behavior on ChromeOS is a bit weird and not |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 render_text_->SetCursorPosition(new_cursor_pos); | 852 render_text_->SetCursorPosition(new_cursor_pos); |
| 839 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). | 853 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). |
| 840 } | 854 } |
| 841 | 855 |
| 842 // static | 856 // static |
| 843 void TextfieldModel::ClearKillBuffer() { | 857 void TextfieldModel::ClearKillBuffer() { |
| 844 SetKillBuffer(base::string16()); | 858 SetKillBuffer(base::string16()); |
| 845 } | 859 } |
| 846 | 860 |
| 847 } // namespace views | 861 } // namespace views |
| OLD | NEW |