Chromium Code Reviews| Index: chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.cc |
| diff --git a/chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.cc b/chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.cc |
| index c6b517d51e5fe1b0ef89e002103a1a335a4a24d3..0a0b081530fb0d8f41b256e89ce087576519e979 100644 |
| --- a/chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.cc |
| +++ b/chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.cc |
| @@ -25,44 +25,36 @@ |
| namespace libgtk2ui { |
| X11InputMethodContextImplGtk2::X11InputMethodContextImplGtk2( |
| - ui::LinuxInputMethodContextDelegate* delegate) |
| + ui::LinuxInputMethodContextDelegate* delegate, |
| + bool is_simple) |
| : delegate_(delegate), |
| - gtk_context_simple_(NULL), |
| - gtk_multicontext_(NULL), |
| gtk_context_(NULL), |
| gdk_last_set_client_window_(NULL) { |
| CHECK(delegate_); |
| ResetXModifierKeycodesCache(); |
| - gtk_context_simple_ = gtk_im_context_simple_new(); |
| - gtk_multicontext_ = gtk_im_multicontext_new(); |
| - |
| - GtkIMContext* contexts[] = {gtk_context_simple_, gtk_multicontext_}; |
| - for (size_t i = 0; i < arraysize(contexts); ++i) { |
| - g_signal_connect(contexts[i], "commit", |
| - G_CALLBACK(OnCommitThunk), this); |
| - g_signal_connect(contexts[i], "preedit-changed", |
| - G_CALLBACK(OnPreeditChangedThunk), this); |
| - g_signal_connect(contexts[i], "preedit-end", |
| - G_CALLBACK(OnPreeditEndThunk), this); |
| - g_signal_connect(contexts[i], "preedit-start", |
| - G_CALLBACK(OnPreeditStartThunk), this); |
| - // TODO(yukishiino): Handle operations on surrounding text. |
| - // "delete-surrounding" and "retrieve-surrounding" signals should be |
| - // handled. |
| - } |
| + if (is_simple) |
| + gtk_context_ = gtk_im_context_simple_new(); |
| + else |
| + gtk_context_ = gtk_im_multicontext_new(); |
|
James Su
2015/04/09 08:40:02
nit: gtk_context_ = is_simple ? gtk_im_context_sim
Shu Chen
2015/04/10 05:26:52
Done.
|
| + |
| + g_signal_connect(gtk_context_, "commit", G_CALLBACK(OnCommitThunk), this); |
| + g_signal_connect(gtk_context_, "preedit-changed", |
| + G_CALLBACK(OnPreeditChangedThunk), this); |
| + g_signal_connect(gtk_context_, "preedit-end", G_CALLBACK(OnPreeditEndThunk), |
| + this); |
| + g_signal_connect(gtk_context_, "preedit-start", |
| + G_CALLBACK(OnPreeditStartThunk), this); |
| + // TODO(yukishiino): Handle operations on surrounding text. |
|
James Su
2015/04/09 08:40:02
change this to TODO(shuchen) ?
Shu Chen
2015/04/10 05:26:52
Done.
|
| + // "delete-surrounding" and "retrieve-surrounding" signals should be |
| + // handled. |
| } |
| X11InputMethodContextImplGtk2::~X11InputMethodContextImplGtk2() { |
| - gtk_context_ = NULL; |
| - if (gtk_context_simple_) { |
| - g_object_unref(gtk_context_simple_); |
| - gtk_context_simple_ = NULL; |
| - } |
| - if (gtk_multicontext_) { |
| - g_object_unref(gtk_multicontext_); |
| - gtk_multicontext_ = NULL; |
| + if (gtk_context_) { |
| + g_object_unref(gtk_context_); |
| + gtk_context_ = NULL; |
| } |
| } |
| @@ -70,11 +62,7 @@ X11InputMethodContextImplGtk2::~X11InputMethodContextImplGtk2() { |
| bool X11InputMethodContextImplGtk2::DispatchKeyEvent( |
| const ui::KeyEvent& key_event) { |
| - if (!key_event.HasNativeEvent()) |
| - return false; |
| - |
| - // The caller must call Focus() first. |
| - if (!gtk_context_) |
| + if (!key_event.HasNativeEvent() || !gtk_context_) |
| return false; |
| // Translate a XKeyEvent to a GdkEventKey. |
| @@ -84,11 +72,11 @@ bool X11InputMethodContextImplGtk2::DispatchKeyEvent( |
| return false; |
| } |
| - // Set the client window and cursor location. |
| if (event->key.window != gdk_last_set_client_window_) { |
| gtk_im_context_set_client_window(gtk_context_, event->key.window); |
| gdk_last_set_client_window_ = event->key.window; |
| } |
| + |
| // Convert the last known caret bounds relative to the screen coordinates |
| // to a GdkRectangle relative to the client window. |
| gint x = 0; |
| @@ -100,48 +88,31 @@ bool X11InputMethodContextImplGtk2::DispatchKeyEvent( |
| last_caret_bounds_.height()}; |
| gtk_im_context_set_cursor_location(gtk_context_, &rect); |
| - // Let an IME handle the key event. |
| - commit_signal_trap_.StartTrap(event->key.keyval); |
| - const gboolean handled = gtk_im_context_filter_keypress(gtk_context_, |
| - &event->key); |
| - commit_signal_trap_.StopTrap(); |
| + const bool handled = |
| + gtk_im_context_filter_keypress(gtk_context_, &event->key); |
| gdk_event_free(event); |
| - |
| - return handled && !commit_signal_trap_.IsSignalCaught(); |
| + return handled; |
| } |
| void X11InputMethodContextImplGtk2::Reset() { |
| - // Reset all the states of the context, not only preedit, caret but also |
| - // focus. |
| - gtk_context_ = NULL; |
| - gtk_im_context_reset(gtk_context_simple_); |
| - gtk_im_context_reset(gtk_multicontext_); |
| - gtk_im_context_focus_out(gtk_context_simple_); |
| - gtk_im_context_focus_out(gtk_multicontext_); |
| - gdk_last_set_client_window_ = NULL; |
| + gtk_im_context_reset(gtk_context_); |
| } |
| -void X11InputMethodContextImplGtk2::OnTextInputTypeChanged( |
| - ui::TextInputType text_input_type) { |
| - switch (text_input_type) { |
| - case ui::TEXT_INPUT_TYPE_NONE: |
| - case ui::TEXT_INPUT_TYPE_PASSWORD: |
| - gtk_context_ = gtk_context_simple_; |
| - break; |
| - default: |
| - gtk_context_ = gtk_multicontext_; |
| - } |
| +void X11InputMethodContextImplGtk2::Focus() { |
| gtk_im_context_focus_in(gtk_context_); |
| } |
| -void X11InputMethodContextImplGtk2::OnCaretBoundsChanged( |
| - const gfx::Rect& caret_bounds) { |
| +void X11InputMethodContextImplGtk2::Blur() { |
| + gtk_im_context_focus_out(gtk_context_); |
| +} |
| + |
| +void X11InputMethodContextImplGtk2::SetCursorLocation(const gfx::Rect& rect) { |
| // Remember the caret bounds so that we can set the cursor location later. |
| // gtk_im_context_set_cursor_location() takes the location relative to the |
| // client window, which is unknown at this point. So we'll call |
| // gtk_im_context_set_cursor_location() later in ProcessKeyEvent() where |
| // (and only where) we know the client window. |
| - last_caret_bounds_ = caret_bounds; |
| + last_caret_bounds_ = rect; |
| } |
| // private: |
| @@ -309,16 +280,7 @@ void X11InputMethodContextImplGtk2::OnCommit(GtkIMContext* context, |
| if (context != gtk_context_) |
| return; |
| - const base::string16& text_in_utf16 = base::UTF8ToUTF16(text); |
| - // If an underlying IME is emitting the "commit" signal to insert a character |
| - // for a direct input key event, ignores the insertion of the character at |
| - // this point, because we have to call DispatchKeyEventPostIME() for direct |
| - // input key events. DispatchKeyEvent() takes care of the trapped character |
| - // and calls DispatchKeyEventPostIME(). |
| - if (commit_signal_trap_.Trap(text_in_utf16)) |
| - return; |
| - |
| - delegate_->OnCommit(text_in_utf16); |
| + delegate_->OnCommit(base::UTF8ToUTF16(text)); |
| } |
| void X11InputMethodContextImplGtk2::OnPreeditChanged(GtkIMContext* context) { |
| @@ -352,39 +314,4 @@ void X11InputMethodContextImplGtk2::OnPreeditStart(GtkIMContext* context) { |
| delegate_->OnPreeditStart(); |
| } |
| -// GtkCommitSignalTrap |
| - |
| -X11InputMethodContextImplGtk2::GtkCommitSignalTrap::GtkCommitSignalTrap() |
| - : is_trap_enabled_(false), |
| -#if GTK_CHECK_VERSION (2,22,0) |
| - gdk_event_key_keyval_(GDK_KEY_VoidSymbol), |
| -#else |
| - gdk_event_key_keyval_(GDK_VoidSymbol), |
| -#endif |
| - is_signal_caught_(false) {} |
| - |
| -void X11InputMethodContextImplGtk2::GtkCommitSignalTrap::StartTrap( |
| - guint keyval) { |
| - is_signal_caught_ = false; |
| - gdk_event_key_keyval_ = keyval; |
| - is_trap_enabled_ = true; |
| -} |
| - |
| -void X11InputMethodContextImplGtk2::GtkCommitSignalTrap::StopTrap() { |
| - is_trap_enabled_ = false; |
| -} |
| - |
| -bool X11InputMethodContextImplGtk2::GtkCommitSignalTrap::Trap( |
| - const base::string16& text) { |
| - DCHECK(!is_signal_caught_); |
| - if (is_trap_enabled_ && |
| - text.length() == 1 && |
| - text[0] == gdk_keyval_to_unicode(gdk_event_key_keyval_)) { |
| - is_signal_caught_ = true; |
| - return true; |
| - } else { |
| - return false; |
| - } |
| -} |
| - |
| } // namespace libgtk2ui |