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