| 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 <X11/X.h> | 7 #include <X11/X.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 #include <X11/Xutil.h> | 9 #include <X11/Xutil.h> |
| 10 #undef FocusIn | 10 #undef FocusIn |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool InputMethodIBus::OnUntranslatedIMEMessage(const base::NativeEvent& event, | 83 bool InputMethodIBus::OnUntranslatedIMEMessage(const base::NativeEvent& event, |
| 84 NativeEventResult* result) { | 84 NativeEventResult* result) { |
| 85 return false; | 85 return false; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void InputMethodIBus::ProcessKeyEventDone(uint32 id, | 88 void InputMethodIBus::ProcessKeyEventDone(uint32 id, |
| 89 ui::KeyEvent* event, | 89 ui::KeyEvent* event, |
| 90 bool is_handled) { | 90 bool is_handled) { |
| 91 DCHECK(event); | 91 if (pending_key_events_.find(id) == pending_key_events_.end()) |
| 92 | |
| 93 // TODO(komatsu): Support fabricated key events. | |
| 94 if (!event->HasNativeEvent()) | |
| 95 return; | |
| 96 | |
| 97 std::set<uint32>::iterator it = pending_key_events_.find(id); | |
| 98 | |
| 99 if (it == pending_key_events_.end()) | |
| 100 return; // Abandoned key event. | 92 return; // Abandoned key event. |
| 101 | 93 |
| 94 DCHECK(event); |
| 102 if (event->type() == ET_KEY_PRESSED) { | 95 if (event->type() == ET_KEY_PRESSED) { |
| 103 if (is_handled) { | 96 if (is_handled) { |
| 104 // IME event has a priority to be handled, so that character composer | 97 // IME event has a priority to be handled, so that character composer |
| 105 // should be reset. | 98 // should be reset. |
| 106 character_composer_.Reset(); | 99 character_composer_.Reset(); |
| 107 } else { | 100 } else { |
| 108 // If IME does not handle key event, passes keyevent to character composer | 101 // If IME does not handle key event, passes keyevent to character composer |
| 109 // to be able to compose complex characters. | 102 // to be able to compose complex characters. |
| 110 is_handled = ExecuteCharacterComposer(*event); | 103 is_handled = ExecuteCharacterComposer(*event); |
| 111 } | 104 } |
| 112 } | 105 } |
| 113 | 106 |
| 114 if (event->type() == ET_KEY_PRESSED || event->type() == ET_KEY_RELEASED) | 107 if (event->type() == ET_KEY_PRESSED || event->type() == ET_KEY_RELEASED) |
| 115 ProcessKeyEventPostIME(*event, is_handled); | 108 ProcessKeyEventPostIME(*event, is_handled); |
| 116 | 109 |
| 117 // Do not use |it| for erasing, ProcessKeyEventPostIME may change the | 110 // ProcessKeyEventPostIME may change the |pending_key_events_|. |
| 118 // |pending_key_events_|. | |
| 119 pending_key_events_.erase(id); | 111 pending_key_events_.erase(id); |
| 120 } | 112 } |
| 121 | 113 |
| 122 bool InputMethodIBus::DispatchKeyEvent(const ui::KeyEvent& event) { | 114 bool InputMethodIBus::DispatchKeyEvent(const ui::KeyEvent& event) { |
| 123 DCHECK(event.type() == ET_KEY_PRESSED || event.type() == ET_KEY_RELEASED); | 115 DCHECK(event.type() == ET_KEY_PRESSED || event.type() == ET_KEY_RELEASED); |
| 124 DCHECK(system_toplevel_window_focused()); | 116 DCHECK(system_toplevel_window_focused()); |
| 125 | 117 |
| 126 // If |context_| is not usable, then we can only dispatch the key event as is. | 118 // If |context_| is not usable, then we can only dispatch the key event as is. |
| 127 // We also dispatch the key event directly if the current text input type is | 119 // We also dispatch the key event directly if the current text input type is |
| 128 // TEXT_INPUT_TYPE_PASSWORD, to bypass the input method. | 120 // TEXT_INPUT_TYPE_PASSWORD, to bypass the input method. |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 chromeos::IBusEngineHandlerInterface::InputContext context( | 347 chromeos::IBusEngineHandlerInterface::InputContext context( |
| 356 current_text_input_type, GetTextInputMode()); | 348 current_text_input_type, GetTextInputMode()); |
| 357 GetEngine()->FocusIn(context); | 349 GetEngine()->FocusIn(context); |
| 358 OnCaretBoundsChanged(GetTextInputClient()); | 350 OnCaretBoundsChanged(GetTextInputClient()); |
| 359 } | 351 } |
| 360 } | 352 } |
| 361 | 353 |
| 362 void InputMethodIBus::ProcessKeyEventPostIME( | 354 void InputMethodIBus::ProcessKeyEventPostIME( |
| 363 const ui::KeyEvent& event, | 355 const ui::KeyEvent& event, |
| 364 bool handled) { | 356 bool handled) { |
| 365 // TODO(komatsu): Support fabricated key events. | |
| 366 if (!event.HasNativeEvent()) | |
| 367 return; | |
| 368 | |
| 369 TextInputClient* client = GetTextInputClient(); | 357 TextInputClient* client = GetTextInputClient(); |
| 370 | |
| 371 if (!client) { | 358 if (!client) { |
| 372 // As ibus works asynchronously, there is a chance that the focused client | 359 // As ibus works asynchronously, there is a chance that the focused client |
| 373 // loses focus before this method gets called. | 360 // loses focus before this method gets called. |
| 374 DispatchKeyEventPostIME(event); | 361 DispatchKeyEventPostIME(event); |
| 375 return; | 362 return; |
| 376 } | 363 } |
| 377 | 364 |
| 378 if (event.type() == ET_KEY_PRESSED && handled) | 365 if (event.type() == ET_KEY_PRESSED && handled) |
| 379 ProcessFilteredKeyPressEvent(event); | 366 ProcessFilteredKeyPressEvent(event); |
| 380 | 367 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 } | 678 } |
| 692 | 679 |
| 693 // Use a black thin underline by default. | 680 // Use a black thin underline by default. |
| 694 if (out_composition->underlines.empty()) { | 681 if (out_composition->underlines.empty()) { |
| 695 out_composition->underlines.push_back(CompositionUnderline( | 682 out_composition->underlines.push_back(CompositionUnderline( |
| 696 0, length, SK_ColorBLACK, false /* thick */)); | 683 0, length, SK_ColorBLACK, false /* thick */)); |
| 697 } | 684 } |
| 698 } | 685 } |
| 699 | 686 |
| 700 } // namespace ui | 687 } // namespace ui |
| OLD | NEW |