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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 void InputMethodChromeOS::ProcessKeyEventPostIME(const ui::KeyEvent& event, | 338 void InputMethodChromeOS::ProcessKeyEventPostIME(const ui::KeyEvent& event, |
339 bool handled) { | 339 bool handled) { |
340 TextInputClient* client = GetTextInputClient(); | 340 TextInputClient* client = GetTextInputClient(); |
341 if (!client) { | 341 if (!client) { |
342 // As ibus works asynchronously, there is a chance that the focused client | 342 // As ibus works asynchronously, there is a chance that the focused client |
343 // loses focus before this method gets called. | 343 // loses focus before this method gets called. |
344 DispatchKeyEventPostIME(event); | 344 DispatchKeyEventPostIME(event); |
345 return; | 345 return; |
346 } | 346 } |
347 | 347 |
| 348 bool post_ime_result = false; |
348 if (event.type() == ET_KEY_PRESSED && handled) | 349 if (event.type() == ET_KEY_PRESSED && handled) |
349 ProcessFilteredKeyPressEvent(event); | 350 post_ime_result = ProcessFilteredKeyPressEvent(event); |
350 | 351 |
351 // In case the focus was changed by the key event. The |context_| should have | 352 // In case the focus was changed by the key event. The |context_| should have |
352 // been reset when the focused window changed. | 353 // been reset when the focused window changed. |
353 if (client != GetTextInputClient()) | 354 if (client != GetTextInputClient()) |
354 return; | 355 return; |
355 | 356 |
356 if (HasInputMethodResult()) | 357 if (HasInputMethodResult() && !post_ime_result) |
357 ProcessInputMethodResult(event, handled); | 358 ProcessInputMethodResult(event, handled); |
358 | 359 |
359 // In case the focus was changed when sending input method results to the | 360 // In case the focus was changed when sending input method results to the |
360 // focused window. | 361 // focused window. |
361 if (client != GetTextInputClient()) | 362 if (client != GetTextInputClient()) |
362 return; | 363 return; |
363 | 364 |
364 if (handled) | 365 if (handled) |
365 return; // IME handled the key event. do not forward. | 366 return; // IME handled the key event. do not forward. |
366 | 367 |
367 if (event.type() == ET_KEY_PRESSED) | 368 if (event.type() == ET_KEY_PRESSED) |
368 ProcessUnfilteredKeyPressEvent(event); | 369 ProcessUnfilteredKeyPressEvent(event); |
369 else if (event.type() == ET_KEY_RELEASED) | 370 else if (event.type() == ET_KEY_RELEASED) |
370 DispatchKeyEventPostIME(event); | 371 DispatchKeyEventPostIME(event); |
371 } | 372 } |
372 | 373 |
373 void InputMethodChromeOS::ProcessFilteredKeyPressEvent( | 374 bool InputMethodChromeOS::ProcessFilteredKeyPressEvent( |
374 const ui::KeyEvent& event) { | 375 const ui::KeyEvent& event) { |
375 if (NeedInsertChar()) { | 376 if (NeedInsertChar()) |
376 DispatchKeyEventPostIME(event); | 377 return DispatchKeyEventPostIME(event); |
377 } else { | 378 const ui::KeyEvent fabricated_event(ET_KEY_PRESSED, |
378 const ui::KeyEvent fabricated_event(ET_KEY_PRESSED, | 379 VKEY_PROCESSKEY, |
379 VKEY_PROCESSKEY, | 380 event.flags()); |
380 event.flags()); | 381 return DispatchKeyEventPostIME(fabricated_event); |
381 DispatchKeyEventPostIME(fabricated_event); | |
382 } | |
383 } | 382 } |
384 | 383 |
385 void InputMethodChromeOS::ProcessUnfilteredKeyPressEvent( | 384 void InputMethodChromeOS::ProcessUnfilteredKeyPressEvent( |
386 const ui::KeyEvent& event) { | 385 const ui::KeyEvent& event) { |
387 const TextInputClient* prev_client = GetTextInputClient(); | 386 TextInputClient* prev_client = GetTextInputClient(); |
388 DispatchKeyEventPostIME(event); | 387 if (DispatchKeyEventPostIME(event)) |
| 388 return; |
389 | 389 |
390 // We shouldn't dispatch the character anymore if the key event dispatch | 390 // We shouldn't dispatch the character anymore if the key event dispatch |
391 // caused focus change. For example, in the following scenario, | 391 // caused focus change. For example, in the following scenario, |
392 // 1. visit a web page which has a <textarea>. | 392 // 1. visit a web page which has a <textarea>. |
393 // 2. click Omnibox. | 393 // 2. click Omnibox. |
394 // 3. enable Korean IME, press A, then press Tab to move the focus to the web | 394 // 3. enable Korean IME, press A, then press Tab to move the focus to the web |
395 // page. | 395 // page. |
396 // We should return here not to send the Tab key event to RWHV. | 396 // We should return here not to send the Tab key event to RWHV. |
397 TextInputClient* client = GetTextInputClient(); | 397 TextInputClient* client = GetTextInputClient(); |
398 if (!client || client != prev_client) | 398 if (!client || client != prev_client) |
399 return; | 399 return; |
400 | 400 |
401 // If a key event was not filtered by |context_| and |character_composer_|, | 401 // If a key event was not filtered by |context_| and |character_composer_|, |
402 // then it means the key event didn't generate any result text. So we need | 402 // then it means the key event didn't generate any result text. So we need |
403 // to send corresponding character to the focused text input client. | 403 // to send corresponding character to the focused text input client. |
404 uint16 ch = event.GetCharacter(); | 404 uint16 ch = event.GetCharacter(); |
405 if (ch) | 405 if (ch) |
406 client->InsertChar(ch, event.flags()); | 406 prev_client->InsertChar(ch, event.flags()); |
407 } | 407 } |
408 | 408 |
409 void InputMethodChromeOS::ProcessInputMethodResult(const ui::KeyEvent& event, | 409 void InputMethodChromeOS::ProcessInputMethodResult(const ui::KeyEvent& event, |
410 bool handled) { | 410 bool handled) { |
411 TextInputClient* client = GetTextInputClient(); | 411 TextInputClient* client = GetTextInputClient(); |
412 DCHECK(client); | 412 DCHECK(client); |
413 | 413 |
414 if (result_text_.length()) { | 414 if (result_text_.length()) { |
415 if (handled && NeedInsertChar()) { | 415 if (handled && NeedInsertChar()) { |
416 for (base::string16::const_iterator i = result_text_.begin(); | 416 for (base::string16::const_iterator i = result_text_.begin(); |
417 i != result_text_.end(); ++i) { | 417 i != result_text_.end(); ++i) { |
418 client->InsertChar(*i, event.flags()); | 418 client->InsertChar(*i, event.flags()); |
419 } | 419 } |
420 } else { | 420 } else { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 bool InputMethodChromeOS::IsNonPasswordInputFieldFocused() { | 664 bool InputMethodChromeOS::IsNonPasswordInputFieldFocused() { |
665 TextInputType type = GetTextInputType(); | 665 TextInputType type = GetTextInputType(); |
666 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); | 666 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); |
667 } | 667 } |
668 | 668 |
669 bool InputMethodChromeOS::IsInputFieldFocused() { | 669 bool InputMethodChromeOS::IsInputFieldFocused() { |
670 return GetTextInputType() != TEXT_INPUT_TYPE_NONE; | 670 return GetTextInputType() != TEXT_INPUT_TYPE_NONE; |
671 } | 671 } |
672 | 672 |
673 } // namespace ui | 673 } // namespace ui |
OLD | NEW |