| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_LIBGTKUI_X11_INPUT_METHOD_CONTEXT_IMPL_GTK2_H_ | |
| 6 #define CHROME_BROWSER_UI_LIBGTKUI_X11_INPUT_METHOD_CONTEXT_IMPL_GTK2_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/containers/hash_tables.h" | |
| 11 #include "base/event_types.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/strings/string16.h" | |
| 14 #include "ui/base/glib/glib_integers.h" | |
| 15 #include "ui/base/glib/glib_signal.h" | |
| 16 #include "ui/base/ime/linux/linux_input_method_context.h" | |
| 17 #include "ui/gfx/geometry/rect.h" | |
| 18 | |
| 19 typedef union _GdkEvent GdkEvent; | |
| 20 typedef struct _GtkIMContext GtkIMContext; | |
| 21 | |
| 22 namespace libgtkui { | |
| 23 | |
| 24 // An implementation of LinuxInputMethodContext which is based on X11 event loop | |
| 25 // and uses GtkIMContext(gtk-immodule) as a bridge from/to underlying IMEs. | |
| 26 class X11InputMethodContextImplGtk2 : public ui::LinuxInputMethodContext { | |
| 27 public: | |
| 28 X11InputMethodContextImplGtk2(ui::LinuxInputMethodContextDelegate* delegate, | |
| 29 bool is_simple); | |
| 30 ~X11InputMethodContextImplGtk2() override; | |
| 31 | |
| 32 // Overriden from ui::LinuxInputMethodContext | |
| 33 bool DispatchKeyEvent(const ui::KeyEvent& key_event) override; | |
| 34 void SetCursorLocation(const gfx::Rect& rect) override; | |
| 35 void Reset() override; | |
| 36 void Focus() override; | |
| 37 void Blur() override; | |
| 38 | |
| 39 private: | |
| 40 // Resets the cache of X modifier keycodes. | |
| 41 // TODO(yukishiino): We should call this method whenever X keyboard mapping | |
| 42 // changes, for example when a user switched to another keyboard layout. | |
| 43 void ResetXModifierKeycodesCache(); | |
| 44 | |
| 45 // Constructs a GdkEventKey from a XKeyEvent and returns it. Otherwise, | |
| 46 // returns NULL. The returned GdkEvent must be freed by gdk_event_free. | |
| 47 GdkEvent* GdkEventFromNativeEvent(const base::NativeEvent& native_event); | |
| 48 | |
| 49 // Returns true if the hardware |keycode| is assigned to a modifier key. | |
| 50 bool IsKeycodeModifierKey(unsigned int keycode) const; | |
| 51 | |
| 52 // Returns true if one of |keycodes| is pressed. |keybits| is a bit vector | |
| 53 // returned by XQueryKeymap, and |num_keys| is the number of keys in | |
| 54 // |keybits|. | |
| 55 bool IsAnyOfKeycodesPressed(const std::vector<int>& keycodes, | |
| 56 const char* keybits, | |
| 57 int num_keys) const; | |
| 58 | |
| 59 // GtkIMContext event handlers. They are shared among |gtk_context_simple_| | |
| 60 // and |gtk_multicontext_|. | |
| 61 CHROMEG_CALLBACK_1(X11InputMethodContextImplGtk2, void, OnCommit, | |
| 62 GtkIMContext*, gchar*); | |
| 63 CHROMEG_CALLBACK_0(X11InputMethodContextImplGtk2, void, OnPreeditChanged, | |
| 64 GtkIMContext*); | |
| 65 CHROMEG_CALLBACK_0(X11InputMethodContextImplGtk2, void, OnPreeditEnd, | |
| 66 GtkIMContext*); | |
| 67 CHROMEG_CALLBACK_0(X11InputMethodContextImplGtk2, void, OnPreeditStart, | |
| 68 GtkIMContext*); | |
| 69 | |
| 70 // A set of callback functions. Must not be NULL. | |
| 71 ui::LinuxInputMethodContextDelegate* delegate_; | |
| 72 | |
| 73 // IME's input GTK context. | |
| 74 GtkIMContext* gtk_context_; | |
| 75 | |
| 76 gpointer gdk_last_set_client_window_; | |
| 77 | |
| 78 // Last known caret bounds relative to the screen coordinates. | |
| 79 gfx::Rect last_caret_bounds_; | |
| 80 | |
| 81 // A set of hardware keycodes of modifier keys. | |
| 82 base::hash_set<unsigned int> modifier_keycodes_; | |
| 83 | |
| 84 // A list of keycodes of each modifier key. | |
| 85 std::vector<int> meta_keycodes_; | |
| 86 std::vector<int> super_keycodes_; | |
| 87 std::vector<int> hyper_keycodes_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(X11InputMethodContextImplGtk2); | |
| 90 }; | |
| 91 | |
| 92 } // namespace libgtkui | |
| 93 | |
| 94 #endif // CHROME_BROWSER_UI_LIBGTKUI_X11_INPUT_METHOD_CONTEXT_IMPL_GTK2_H_ | |
| OLD | NEW |