| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.h" | 5 #include "chrome/browser/ui/libgtk2ui/x11_input_method_context_impl_gtk2.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #include <gdk/gdkx.h> | 9 #include <gdk/gdkx.h> |
| 10 | 10 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 } // namespace | 93 } // namespace |
| 94 | 94 |
| 95 namespace libgtk2ui { | 95 namespace libgtk2ui { |
| 96 | 96 |
| 97 X11InputMethodContextImplGtk2::X11InputMethodContextImplGtk2( | 97 X11InputMethodContextImplGtk2::X11InputMethodContextImplGtk2( |
| 98 ui::LinuxInputMethodContextDelegate* delegate) | 98 ui::LinuxInputMethodContextDelegate* delegate) |
| 99 : delegate_(delegate), | 99 : delegate_(delegate), |
| 100 gtk_context_simple_(NULL), | 100 gtk_context_simple_(NULL), |
| 101 gtk_multicontext_(NULL), | 101 gtk_multicontext_(NULL), |
| 102 gtk_context_(NULL), | 102 gtk_context_(NULL) { |
| 103 gdk_last_set_client_window_(NULL) { | |
| 104 CHECK(delegate_); | 103 CHECK(delegate_); |
| 105 | 104 |
| 106 { | 105 { |
| 107 XModifierKeymap* keymap = XGetModifierMapping( | 106 XModifierKeymap* keymap = XGetModifierMapping( |
| 108 base::MessagePumpForUI::GetDefaultXDisplay()); | 107 base::MessagePumpForUI::GetDefaultXDisplay()); |
| 109 for (int i = 0; i < 8 * keymap->max_keypermod; ++i) { | 108 for (int i = 0; i < 8 * keymap->max_keypermod; ++i) { |
| 110 if (keymap->modifiermap[i]) | 109 if (keymap->modifiermap[i]) |
| 111 modifier_keycodes_.insert(keymap->modifiermap[i]); | 110 modifier_keycodes_.insert(keymap->modifiermap[i]); |
| 112 } | 111 } |
| 113 XFreeModifiermap(keymap); | 112 XFreeModifiermap(keymap); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 const base::NativeEvent& native_key_event = key_event.native_event(); | 158 const base::NativeEvent& native_key_event = key_event.native_event(); |
| 160 GdkEvent* event = GdkEventFromXKeyEvent( | 159 GdkEvent* event = GdkEventFromXKeyEvent( |
| 161 native_key_event->xkey, | 160 native_key_event->xkey, |
| 162 IsKeycodeModifierKey(native_key_event->xkey.keycode)); | 161 IsKeycodeModifierKey(native_key_event->xkey.keycode)); |
| 163 if (!event) { | 162 if (!event) { |
| 164 LOG(ERROR) << "Cannot translate a XKeyEvent to a GdkEvent."; | 163 LOG(ERROR) << "Cannot translate a XKeyEvent to a GdkEvent."; |
| 165 return false; | 164 return false; |
| 166 } | 165 } |
| 167 | 166 |
| 168 // Set the client window and cursor location. | 167 // Set the client window and cursor location. |
| 169 if (event->key.window != gdk_last_set_client_window_) { | 168 gtk_im_context_set_client_window(gtk_context_, event->key.window); |
| 170 gtk_im_context_set_client_window(gtk_context_, event->key.window); | |
| 171 gdk_last_set_client_window_ = event->key.window; | |
| 172 } | |
| 173 // Convert the last known caret bounds relative to the screen coordinates | 169 // Convert the last known caret bounds relative to the screen coordinates |
| 174 // to a GdkRectangle relative to the client window. | 170 // to a GdkRectangle relative to the client window. |
| 175 gint x = 0; | 171 gint x = 0; |
| 176 gint y = 0; | 172 gint y = 0; |
| 177 gdk_window_get_origin(event->key.window, &x, &y); | 173 gdk_window_get_origin(event->key.window, &x, &y); |
| 178 GdkRectangle rect = {last_caret_bounds_.x() - x, | 174 GdkRectangle rect = {last_caret_bounds_.x() - x, |
| 179 last_caret_bounds_.y() - y, | 175 last_caret_bounds_.y() - y, |
| 180 last_caret_bounds_.width(), | 176 last_caret_bounds_.width(), |
| 181 last_caret_bounds_.height()}; | 177 last_caret_bounds_.height()}; |
| 182 gtk_im_context_set_cursor_location(gtk_context_, &rect); | 178 gtk_im_context_set_cursor_location(gtk_context_, &rect); |
| 183 | 179 |
| 184 // Let an IME handle the key event. | 180 // Let an IME handle the key event. |
| 185 commit_signal_trap_.StartTrap(event->key.keyval); | 181 commit_signal_trap_.StartTrap(event->key.keyval); |
| 186 const gboolean handled = gtk_im_context_filter_keypress(gtk_context_, | 182 const gboolean handled = gtk_im_context_filter_keypress(gtk_context_, |
| 187 &event->key); | 183 &event->key); |
| 188 commit_signal_trap_.StopTrap(); | 184 commit_signal_trap_.StopTrap(); |
| 189 gdk_event_free(event); | 185 gdk_event_free(event); |
| 190 | 186 |
| 191 return handled && !commit_signal_trap_.IsSignalCaught(); | 187 return handled && !commit_signal_trap_.IsSignalCaught(); |
| 192 } | 188 } |
| 193 | 189 |
| 194 void X11InputMethodContextImplGtk2::Reset() { | 190 void X11InputMethodContextImplGtk2::Reset() { |
| 195 // Reset all the states of the context, not only preedit, caret but also | 191 // Reset all the states of the context, not only preedit, caret but also |
| 196 // focus. | 192 // focus. |
| 197 gtk_context_ = NULL; | 193 gtk_context_ = NULL; |
| 198 gtk_im_context_reset(gtk_context_simple_); | 194 gtk_im_context_reset(gtk_context_simple_); |
| 199 gtk_im_context_reset(gtk_multicontext_); | 195 gtk_im_context_reset(gtk_multicontext_); |
| 200 gtk_im_context_focus_out(gtk_context_simple_); | 196 gtk_im_context_focus_out(gtk_context_simple_); |
| 201 gtk_im_context_focus_out(gtk_multicontext_); | 197 gtk_im_context_focus_out(gtk_multicontext_); |
| 202 gdk_last_set_client_window_ = NULL; | |
| 203 } | 198 } |
| 204 | 199 |
| 205 void X11InputMethodContextImplGtk2::OnTextInputTypeChanged( | 200 void X11InputMethodContextImplGtk2::OnTextInputTypeChanged( |
| 206 ui::TextInputType text_input_type) { | 201 ui::TextInputType text_input_type) { |
| 207 switch (text_input_type) { | 202 switch (text_input_type) { |
| 208 case ui::TEXT_INPUT_TYPE_NONE: | 203 case ui::TEXT_INPUT_TYPE_NONE: |
| 209 case ui::TEXT_INPUT_TYPE_PASSWORD: | 204 case ui::TEXT_INPUT_TYPE_PASSWORD: |
| 210 gtk_context_ = gtk_context_simple_; | 205 gtk_context_ = gtk_context_simple_; |
| 211 break; | 206 break; |
| 212 default: | 207 default: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 text.length() == 1 && | 302 text.length() == 1 && |
| 308 text[0] == gdk_keyval_to_unicode(gdk_event_key_keyval_)) { | 303 text[0] == gdk_keyval_to_unicode(gdk_event_key_keyval_)) { |
| 309 is_signal_caught_ = true; | 304 is_signal_caught_ = true; |
| 310 return true; | 305 return true; |
| 311 } else { | 306 } else { |
| 312 return false; | 307 return false; |
| 313 } | 308 } |
| 314 } | 309 } |
| 315 | 310 |
| 316 } // namespace libgtk2ui | 311 } // namespace libgtk2ui |
| OLD | NEW |