| 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 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_X11_INPUT_METHOD_CONTEXT_IMPL_GTK2_H_ | 5 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_X11_INPUT_METHOD_CONTEXT_IMPL_GTK2_H_ |
| 6 #define CHROME_BROWSER_UI_LIBGTK2UI_X11_INPUT_METHOD_CONTEXT_IMPL_GTK2_H_ | 6 #define CHROME_BROWSER_UI_LIBGTK2UI_X11_INPUT_METHOD_CONTEXT_IMPL_GTK2_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/event_types.h" | 11 #include "base/event_types.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "ui/base/glib/glib_integers.h" | 14 #include "ui/base/glib/glib_integers.h" |
| 15 #include "ui/base/glib/glib_signal.h" | 15 #include "ui/base/glib/glib_signal.h" |
| 16 #include "ui/base/ime/linux/linux_input_method_context.h" | 16 #include "ui/base/ime/linux/linux_input_method_context.h" |
| 17 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 18 | 18 |
| 19 typedef union _GdkEvent GdkEvent; | 19 typedef union _GdkEvent GdkEvent; |
| 20 typedef struct _GdkDrawable GdkWindow; | 20 typedef struct _GdkDrawable GdkWindow; |
| 21 typedef struct _GtkIMContext GtkIMContext; | 21 typedef struct _GtkIMContext GtkIMContext; |
| 22 | 22 |
| 23 namespace libgtk2ui { | 23 namespace libgtk2ui { |
| 24 | 24 |
| 25 // An implementation of LinuxInputMethodContext which is based on X11 event loop | 25 // An implementation of LinuxInputMethodContext which is based on X11 event loop |
| 26 // and uses GtkIMContext(gtk-immodule) as a bridge from/to underlying IMEs. | 26 // and uses GtkIMContext(gtk-immodule) as a bridge from/to underlying IMEs. |
| 27 class X11InputMethodContextImplGtk2 : public ui::LinuxInputMethodContext { | 27 class X11InputMethodContextImplGtk2 : public ui::LinuxInputMethodContext { |
| 28 public: | 28 public: |
| 29 explicit X11InputMethodContextImplGtk2( | 29 X11InputMethodContextImplGtk2(ui::LinuxInputMethodContextDelegate* delegate, |
| 30 ui::LinuxInputMethodContextDelegate* delegate); | 30 bool is_simple); |
| 31 ~X11InputMethodContextImplGtk2() override; | 31 ~X11InputMethodContextImplGtk2() override; |
| 32 | 32 |
| 33 // Overriden from ui::LinuxInputMethodContext | 33 // Overriden from ui::LinuxInputMethodContext |
| 34 bool DispatchKeyEvent(const ui::KeyEvent& key_event) override; | 34 bool DispatchKeyEvent(const ui::KeyEvent& key_event) override; |
| 35 void SetCursorLocation(const gfx::Rect& rect) override; |
| 35 void Reset() override; | 36 void Reset() override; |
| 36 void OnTextInputTypeChanged(ui::TextInputType text_input_type) override; | 37 void Focus() override; |
| 37 void OnCaretBoundsChanged(const gfx::Rect& caret_bounds) override; | 38 void Blur() override; |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 // Resets the cache of X modifier keycodes. | 41 // Resets the cache of X modifier keycodes. |
| 41 // TODO(yukishiino): We should call this method whenever X keyboard mapping | 42 // TODO(yukishiino): We should call this method whenever X keyboard mapping |
| 42 // changes, for example when a user switched to another keyboard layout. | 43 // changes, for example when a user switched to another keyboard layout. |
| 43 void ResetXModifierKeycodesCache(); | 44 void ResetXModifierKeycodesCache(); |
| 44 | 45 |
| 45 // Constructs a GdkEventKey from a XKeyEvent and returns it. Otherwise, | 46 // Constructs a GdkEventKey from a XKeyEvent and returns it. Otherwise, |
| 46 // returns NULL. The returned GdkEvent must be freed by gdk_event_free. | 47 // returns NULL. The returned GdkEvent must be freed by gdk_event_free. |
| 47 GdkEvent* GdkEventFromNativeEvent(const base::NativeEvent& native_event); | 48 GdkEvent* GdkEventFromNativeEvent(const base::NativeEvent& native_event); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 63 CHROMEG_CALLBACK_0(X11InputMethodContextImplGtk2, void, OnPreeditChanged, | 64 CHROMEG_CALLBACK_0(X11InputMethodContextImplGtk2, void, OnPreeditChanged, |
| 64 GtkIMContext*); | 65 GtkIMContext*); |
| 65 CHROMEG_CALLBACK_0(X11InputMethodContextImplGtk2, void, OnPreeditEnd, | 66 CHROMEG_CALLBACK_0(X11InputMethodContextImplGtk2, void, OnPreeditEnd, |
| 66 GtkIMContext*); | 67 GtkIMContext*); |
| 67 CHROMEG_CALLBACK_0(X11InputMethodContextImplGtk2, void, OnPreeditStart, | 68 CHROMEG_CALLBACK_0(X11InputMethodContextImplGtk2, void, OnPreeditStart, |
| 68 GtkIMContext*); | 69 GtkIMContext*); |
| 69 | 70 |
| 70 // A set of callback functions. Must not be NULL. | 71 // A set of callback functions. Must not be NULL. |
| 71 ui::LinuxInputMethodContextDelegate* delegate_; | 72 ui::LinuxInputMethodContextDelegate* delegate_; |
| 72 | 73 |
| 73 // IME's input context used for TEXT_INPUT_TYPE_NONE and | 74 // IME's input GTK context. |
| 74 // TEXT_INPUT_TYPE_PASSWORD. | |
| 75 GtkIMContext* gtk_context_simple_; | |
| 76 // IME's input context used for the other text input types. | |
| 77 GtkIMContext* gtk_multicontext_; | |
| 78 | |
| 79 // An alias to |gtk_context_simple_| or |gtk_multicontext_| depending on the | |
| 80 // text input type. Can be NULL when it's not focused. | |
| 81 GtkIMContext* gtk_context_; | 75 GtkIMContext* gtk_context_; |
| 82 | 76 |
| 83 // Last set client window. | |
| 84 GdkWindow* gdk_last_set_client_window_; | 77 GdkWindow* gdk_last_set_client_window_; |
| 85 | 78 |
| 86 // Last known caret bounds relative to the screen coordinates. | 79 // Last known caret bounds relative to the screen coordinates. |
| 87 gfx::Rect last_caret_bounds_; | 80 gfx::Rect last_caret_bounds_; |
| 88 | 81 |
| 89 // A set of hardware keycodes of modifier keys. | 82 // A set of hardware keycodes of modifier keys. |
| 90 base::hash_set<unsigned int> modifier_keycodes_; | 83 base::hash_set<unsigned int> modifier_keycodes_; |
| 91 | 84 |
| 92 // A list of keycodes of each modifier key. | 85 // A list of keycodes of each modifier key. |
| 93 std::vector<int> meta_keycodes_; | 86 std::vector<int> meta_keycodes_; |
| 94 std::vector<int> super_keycodes_; | 87 std::vector<int> super_keycodes_; |
| 95 std::vector<int> hyper_keycodes_; | 88 std::vector<int> hyper_keycodes_; |
| 96 | 89 |
| 97 // The helper class to trap GTK+'s "commit" signal for direct input key | |
| 98 // events. | |
| 99 // | |
| 100 // gtk_im_context_filter_keypress() emits "commit" signal in order to insert | |
| 101 // a character which is not actually processed by a IME. This behavior seems, | |
| 102 // in Javascript world, that a keydown event with keycode = VKEY_PROCESSKEY | |
| 103 // (= 229) is fired. So we have to trap such "commit" signal for direct input | |
| 104 // key events. This class helps to trap such events. | |
| 105 class GtkCommitSignalTrap { | |
| 106 public: | |
| 107 GtkCommitSignalTrap(); | |
| 108 | |
| 109 // Enables the trap which monitors a direct input key event of |keyval|. | |
| 110 void StartTrap(guint keyval); | |
| 111 | |
| 112 // Disables the trap. | |
| 113 void StopTrap(); | |
| 114 | |
| 115 // Checks if the committed |text| has come from a direct input key event, | |
| 116 // and returns true in that case. Once it's trapped, IsSignalCaught() | |
| 117 // returns true. | |
| 118 // Must be called at most once between StartTrap() and StopTrap(). | |
| 119 bool Trap(const base::string16& text); | |
| 120 | |
| 121 // Returns true if a direct input key event is detected. | |
| 122 bool IsSignalCaught() const { return is_signal_caught_; } | |
| 123 | |
| 124 private: | |
| 125 bool is_trap_enabled_; | |
| 126 guint gdk_event_key_keyval_; | |
| 127 bool is_signal_caught_; | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(GtkCommitSignalTrap); | |
| 130 }; | |
| 131 | |
| 132 GtkCommitSignalTrap commit_signal_trap_; | |
| 133 | |
| 134 FRIEND_TEST_ALL_PREFIXES(X11InputMethodContextImplGtk2FriendTest, | |
| 135 GtkCommitSignalTrap); | |
| 136 | |
| 137 DISALLOW_COPY_AND_ASSIGN(X11InputMethodContextImplGtk2); | 90 DISALLOW_COPY_AND_ASSIGN(X11InputMethodContextImplGtk2); |
| 138 }; | 91 }; |
| 139 | 92 |
| 140 } // namespace libgtk2ui | 93 } // namespace libgtk2ui |
| 141 | 94 |
| 142 #endif // CHROME_BROWSER_UI_LIBGTK2UI_X11_INPUT_METHOD_CONTEXT_IMPL_GTK2_H_ | 95 #endif // CHROME_BROWSER_UI_LIBGTK2UI_X11_INPUT_METHOD_CONTEXT_IMPL_GTK2_H_ |
| OLD | NEW |