| OLD | NEW |
| 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/base/ime/input_method_ibus.h" | 5 #include "ui/base/ime/input_method_ibus.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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 175 } |
| 176 | 176 |
| 177 chromeos::IBusPanelCandidateWindowHandlerInterface* candidate_window = | 177 chromeos::IBusPanelCandidateWindowHandlerInterface* candidate_window = |
| 178 chromeos::IBusBridge::Get()->GetCandidateWindowHandler(); | 178 chromeos::IBusBridge::Get()->GetCandidateWindowHandler(); |
| 179 if (!candidate_window) | 179 if (!candidate_window) |
| 180 return; | 180 return; |
| 181 candidate_window->SetCursorBounds(rect, composition_head); | 181 candidate_window->SetCursorBounds(rect, composition_head); |
| 182 | 182 |
| 183 gfx::Range text_range; | 183 gfx::Range text_range; |
| 184 gfx::Range selection_range; | 184 gfx::Range selection_range; |
| 185 string16 surrounding_text; | 185 base::string16 surrounding_text; |
| 186 if (!GetTextInputClient()->GetTextRange(&text_range) || | 186 if (!GetTextInputClient()->GetTextRange(&text_range) || |
| 187 !GetTextInputClient()->GetTextFromRange(text_range, &surrounding_text) || | 187 !GetTextInputClient()->GetTextFromRange(text_range, &surrounding_text) || |
| 188 !GetTextInputClient()->GetSelectionRange(&selection_range)) { | 188 !GetTextInputClient()->GetSelectionRange(&selection_range)) { |
| 189 previous_surrounding_text_.clear(); | 189 previous_surrounding_text_.clear(); |
| 190 previous_selection_range_ = gfx::Range::InvalidRange(); | 190 previous_selection_range_ = gfx::Range::InvalidRange(); |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 | 193 |
| 194 if (previous_selection_range_ == selection_range && | 194 if (previous_selection_range_ == selection_range && |
| 195 previous_surrounding_text_ == surrounding_text) | 195 previous_surrounding_text_ == surrounding_text) |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 client->InsertChar(ch, event_flags); | 428 client->InsertChar(ch, event_flags); |
| 429 } | 429 } |
| 430 | 430 |
| 431 void InputMethodIBus::ProcessInputMethodResult(const ui::KeyEvent& event, | 431 void InputMethodIBus::ProcessInputMethodResult(const ui::KeyEvent& event, |
| 432 bool handled) { | 432 bool handled) { |
| 433 TextInputClient* client = GetTextInputClient(); | 433 TextInputClient* client = GetTextInputClient(); |
| 434 DCHECK(client); | 434 DCHECK(client); |
| 435 | 435 |
| 436 if (result_text_.length()) { | 436 if (result_text_.length()) { |
| 437 if (handled && NeedInsertChar()) { | 437 if (handled && NeedInsertChar()) { |
| 438 for (string16::const_iterator i = result_text_.begin(); | 438 for (base::string16::const_iterator i = result_text_.begin(); |
| 439 i != result_text_.end(); ++i) { | 439 i != result_text_.end(); ++i) { |
| 440 client->InsertChar(*i, event.flags()); | 440 client->InsertChar(*i, event.flags()); |
| 441 } | 441 } |
| 442 } else { | 442 } else { |
| 443 client->InsertText(result_text_); | 443 client->InsertText(result_text_); |
| 444 composing_text_ = false; | 444 composing_text_ = false; |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 | 447 |
| 448 if (composition_changed_ && !IsTextInputTypeNone()) { | 448 if (composition_changed_ && !IsTextInputTypeNone()) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 477 void InputMethodIBus::CommitText(const std::string& text) { | 477 void InputMethodIBus::CommitText(const std::string& text) { |
| 478 if (suppress_next_result_ || text.empty()) | 478 if (suppress_next_result_ || text.empty()) |
| 479 return; | 479 return; |
| 480 | 480 |
| 481 // We need to receive input method result even if the text input type is | 481 // We need to receive input method result even if the text input type is |
| 482 // TEXT_INPUT_TYPE_NONE, to make sure we can always send correct | 482 // TEXT_INPUT_TYPE_NONE, to make sure we can always send correct |
| 483 // character for each key event to the focused text input client. | 483 // character for each key event to the focused text input client. |
| 484 if (!GetTextInputClient()) | 484 if (!GetTextInputClient()) |
| 485 return; | 485 return; |
| 486 | 486 |
| 487 const string16 utf16_text = UTF8ToUTF16(text); | 487 const base::string16 utf16_text = UTF8ToUTF16(text); |
| 488 if (utf16_text.empty()) | 488 if (utf16_text.empty()) |
| 489 return; | 489 return; |
| 490 | 490 |
| 491 // Append the text to the buffer, because commit signal might be fired | 491 // Append the text to the buffer, because commit signal might be fired |
| 492 // multiple times when processing a key event. | 492 // multiple times when processing a key event. |
| 493 result_text_.append(utf16_text); | 493 result_text_.append(utf16_text); |
| 494 | 494 |
| 495 // If we are not handling key event, do not bother sending text result if the | 495 // If we are not handling key event, do not bother sending text result if the |
| 496 // focused text input client does not support text input. | 496 // focused text input client does not support text input. |
| 497 if (pending_key_events_.empty() && !IsTextInputTypeNone()) { | 497 if (pending_key_events_.empty() && !IsTextInputTypeNone()) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 } | 656 } |
| 657 | 657 |
| 658 // Use a black thin underline by default. | 658 // Use a black thin underline by default. |
| 659 if (out_composition->underlines.empty()) { | 659 if (out_composition->underlines.empty()) { |
| 660 out_composition->underlines.push_back(CompositionUnderline( | 660 out_composition->underlines.push_back(CompositionUnderline( |
| 661 0, length, SK_ColorBLACK, false /* thick */)); | 661 0, length, SK_ColorBLACK, false /* thick */)); |
| 662 } | 662 } |
| 663 } | 663 } |
| 664 | 664 |
| 665 } // namespace ui | 665 } // namespace ui |
| OLD | NEW |