| 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/base/ime/input_method_chromeos.h" | 5 #include "ui/base/ime/input_method_chromeos.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 const chromeos::CompositionText& text, | 489 const chromeos::CompositionText& text, |
| 490 uint32 cursor_pos, | 490 uint32 cursor_pos, |
| 491 bool visible) { | 491 bool visible) { |
| 492 if (IsTextInputTypeNone()) | 492 if (IsTextInputTypeNone()) |
| 493 return; | 493 return; |
| 494 | 494 |
| 495 if (!CanComposeInline()) { | 495 if (!CanComposeInline()) { |
| 496 chromeos::IBusPanelCandidateWindowHandlerInterface* candidate_window = | 496 chromeos::IBusPanelCandidateWindowHandlerInterface* candidate_window = |
| 497 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); | 497 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); |
| 498 if (candidate_window) | 498 if (candidate_window) |
| 499 candidate_window->UpdatePreeditText( | 499 candidate_window->UpdatePreeditText(text.text(), cursor_pos, visible); |
| 500 base::UTF8ToUTF16(text.text()), cursor_pos, visible); | |
| 501 } | 500 } |
| 502 | 501 |
| 503 // |visible| argument is very confusing. For example, what's the correct | 502 // |visible| argument is very confusing. For example, what's the correct |
| 504 // behavior when: | 503 // behavior when: |
| 505 // 1. OnUpdatePreeditText() is called with a text and visible == false, then | 504 // 1. OnUpdatePreeditText() is called with a text and visible == false, then |
| 506 // 2. OnShowPreeditText() is called afterwards. | 505 // 2. OnShowPreeditText() is called afterwards. |
| 507 // | 506 // |
| 508 // If it's only for clearing the current preedit text, then why not just use | 507 // If it's only for clearing the current preedit text, then why not just use |
| 509 // OnHidePreeditText()? | 508 // OnHidePreeditText()? |
| 510 if (!visible) { | 509 if (!visible) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 if (GetTextInputClient()) | 552 if (GetTextInputClient()) |
| 554 GetTextInputClient()->ExtendSelectionAndDelete(length, 0U); | 553 GetTextInputClient()->ExtendSelectionAndDelete(length, 0U); |
| 555 } | 554 } |
| 556 | 555 |
| 557 bool InputMethodChromeOS::ExecuteCharacterComposer(const ui::KeyEvent& event) { | 556 bool InputMethodChromeOS::ExecuteCharacterComposer(const ui::KeyEvent& event) { |
| 558 if (!character_composer_.FilterKeyPress(event)) | 557 if (!character_composer_.FilterKeyPress(event)) |
| 559 return false; | 558 return false; |
| 560 | 559 |
| 561 // CharacterComposer consumed the key event. Update the composition text. | 560 // CharacterComposer consumed the key event. Update the composition text. |
| 562 chromeos::CompositionText preedit; | 561 chromeos::CompositionText preedit; |
| 563 preedit.set_text( | 562 preedit.set_text(character_composer_.preedit_string()); |
| 564 base::UTF16ToUTF8(character_composer_.preedit_string())); | |
| 565 UpdateCompositionText(preedit, preedit.text().size(), | 563 UpdateCompositionText(preedit, preedit.text().size(), |
| 566 !preedit.text().empty()); | 564 !preedit.text().empty()); |
| 567 std::string commit_text = | 565 std::string commit_text = |
| 568 base::UTF16ToUTF8(character_composer_.composed_character()); | 566 base::UTF16ToUTF8(character_composer_.composed_character()); |
| 569 if (!commit_text.empty()) { | 567 if (!commit_text.empty()) { |
| 570 CommitText(commit_text); | 568 CommitText(commit_text); |
| 571 } | 569 } |
| 572 return true; | 570 return true; |
| 573 } | 571 } |
| 574 | 572 |
| 575 void InputMethodChromeOS::ExtractCompositionText( | 573 void InputMethodChromeOS::ExtractCompositionText( |
| 576 const chromeos::CompositionText& text, | 574 const chromeos::CompositionText& text, |
| 577 uint32 cursor_position, | 575 uint32 cursor_position, |
| 578 CompositionText* out_composition) const { | 576 CompositionText* out_composition) const { |
| 579 out_composition->Clear(); | 577 out_composition->Clear(); |
| 580 out_composition->text = base::UTF8ToUTF16(text.text()); | 578 out_composition->text = text.text(); |
| 581 | 579 |
| 582 if (out_composition->text.empty()) | 580 if (out_composition->text.empty()) |
| 583 return; | 581 return; |
| 584 | 582 |
| 585 // ibus uses character index for cursor position and attribute range, but we | 583 // ibus uses character index for cursor position and attribute range, but we |
| 586 // use char16 offset for them. So we need to do conversion here. | 584 // use char16 offset for them. So we need to do conversion here. |
| 587 std::vector<size_t> char16_offsets; | 585 std::vector<size_t> char16_offsets; |
| 588 size_t length = out_composition->text.length(); | 586 size_t length = out_composition->text.length(); |
| 589 base::i18n::UTF16CharIterator char_iterator(&out_composition->text); | 587 base::i18n::UTF16CharIterator char_iterator(&out_composition->text); |
| 590 do { | 588 do { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 } | 642 } |
| 645 | 643 |
| 646 // Use a black thin underline by default. | 644 // Use a black thin underline by default. |
| 647 if (out_composition->underlines.empty()) { | 645 if (out_composition->underlines.empty()) { |
| 648 out_composition->underlines.push_back(CompositionUnderline( | 646 out_composition->underlines.push_back(CompositionUnderline( |
| 649 0, length, SK_ColorBLACK, false /* thick */)); | 647 0, length, SK_ColorBLACK, false /* thick */)); |
| 650 } | 648 } |
| 651 } | 649 } |
| 652 | 650 |
| 653 } // namespace ui | 651 } // namespace ui |
| OLD | NEW |