| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/i18n/char_iterator.h" | 14 #include "base/i18n/char_iterator.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/third_party/icu/icu_utf.h" | 18 #include "base/third_party/icu/icu_utf.h" |
| 19 #include "chromeos/ime/composition_text.h" | 19 #include "chromeos/ime/composition_text.h" |
| 20 #include "ui/base/ime/text_input_client.h" | 20 #include "ui/base/ime/text_input_client.h" |
| 21 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
| 22 #include "ui/events/event_constants.h" | |
| 23 #include "ui/events/event_utils.h" | |
| 24 #include "ui/events/keycodes/keyboard_code_conversion.h" | |
| 25 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | |
| 26 #include "ui/events/keycodes/keyboard_codes.h" | |
| 27 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
| 28 | 23 |
| 29 namespace { | 24 namespace { |
| 30 chromeos::IMEEngineHandlerInterface* GetEngine() { | 25 chromeos::IMEEngineHandlerInterface* GetEngine() { |
| 31 return chromeos::IMEBridge::Get()->GetCurrentEngineHandler(); | 26 return chromeos::IMEBridge::Get()->GetCurrentEngineHandler(); |
| 32 } | 27 } |
| 33 } // namespace | 28 } // namespace |
| 34 | 29 |
| 35 namespace ui { | 30 namespace ui { |
| 36 | 31 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // 3. enable Korean IME, press A, then press Tab to move the focus to the web | 365 // 3. enable Korean IME, press A, then press Tab to move the focus to the web |
| 371 // page. | 366 // page. |
| 372 // We should return here not to send the Tab key event to RWHV. | 367 // We should return here not to send the Tab key event to RWHV. |
| 373 TextInputClient* client = GetTextInputClient(); | 368 TextInputClient* client = GetTextInputClient(); |
| 374 if (!client || client != prev_client) | 369 if (!client || client != prev_client) |
| 375 return; | 370 return; |
| 376 | 371 |
| 377 // If a key event was not filtered by |context_| and |character_composer_|, | 372 // If a key event was not filtered by |context_| and |character_composer_|, |
| 378 // then it means the key event didn't generate any result text. So we need | 373 // then it means the key event didn't generate any result text. So we need |
| 379 // to send corresponding character to the focused text input client. | 374 // to send corresponding character to the focused text input client. |
| 380 const uint32 event_flags = event.flags(); | 375 uint16 ch = event.GetCharacter(); |
| 381 uint16 ch = 0; | |
| 382 if (event.HasNativeEvent()) { | |
| 383 const base::NativeEvent& native_event = event.native_event(); | |
| 384 | |
| 385 if (!(event_flags & ui::EF_CONTROL_DOWN)) | |
| 386 ch = ui::GetCharacterFromXEvent(native_event); | |
| 387 if (!ch) { | |
| 388 ch = ui::GetCharacterFromKeyCode( | |
| 389 ui::KeyboardCodeFromNative(native_event), event_flags); | |
| 390 } | |
| 391 } else { | |
| 392 ch = ui::GetCharacterFromKeyCode(event.key_code(), event_flags); | |
| 393 } | |
| 394 | |
| 395 if (ch) | 376 if (ch) |
| 396 client->InsertChar(ch, event_flags); | 377 client->InsertChar(ch, event.flags()); |
| 397 } | 378 } |
| 398 | 379 |
| 399 void InputMethodChromeOS::ProcessInputMethodResult(const ui::KeyEvent& event, | 380 void InputMethodChromeOS::ProcessInputMethodResult(const ui::KeyEvent& event, |
| 400 bool handled) { | 381 bool handled) { |
| 401 TextInputClient* client = GetTextInputClient(); | 382 TextInputClient* client = GetTextInputClient(); |
| 402 DCHECK(client); | 383 DCHECK(client); |
| 403 | 384 |
| 404 if (result_text_.length()) { | 385 if (result_text_.length()) { |
| 405 if (handled && NeedInsertChar()) { | 386 if (handled && NeedInsertChar()) { |
| 406 for (base::string16::const_iterator i = result_text_.begin(); | 387 for (base::string16::const_iterator i = result_text_.begin(); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 0, length, SK_ColorBLACK, false /* thick */)); | 628 0, length, SK_ColorBLACK, false /* thick */)); |
| 648 } | 629 } |
| 649 } | 630 } |
| 650 | 631 |
| 651 bool InputMethodChromeOS::IsInputFieldFocused() { | 632 bool InputMethodChromeOS::IsInputFieldFocused() { |
| 652 TextInputType type = GetTextInputType(); | 633 TextInputType type = GetTextInputType(); |
| 653 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); | 634 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); |
| 654 } | 635 } |
| 655 | 636 |
| 656 } // namespace ui | 637 } // namespace ui |
| OLD | NEW |