BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / libgtk2ui / x11_input_method_context_impl_gtk2.h
blobb5128590d629eb5a3695003d2b95f99702f29dff
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.
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_
8 #include <vector>
10 #include "base/containers/hash_tables.h"
11 #include "base/event_types.h"
12 #include "base/gtest_prod_util.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"
19 typedef union _GdkEvent GdkEvent;
20 typedef struct _GtkIMContext GtkIMContext;
22 namespace libgtk2ui {
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;
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;
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();
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);
49 // Returns true if the hardware |keycode| is assigned to a modifier key.
50 bool IsKeycodeModifierKey(unsigned int keycode) const;
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;
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*);
70 // A set of callback functions. Must not be NULL.
71 ui::LinuxInputMethodContextDelegate* delegate_;
73 // IME's input GTK context.
74 GtkIMContext* gtk_context_;
76 gpointer gdk_last_set_client_window_;
78 // Last known caret bounds relative to the screen coordinates.
79 gfx::Rect last_caret_bounds_;
81 // A set of hardware keycodes of modifier keys.
82 base::hash_set<unsigned int> modifier_keycodes_;
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_;
89 DISALLOW_COPY_AND_ASSIGN(X11InputMethodContextImplGtk2);
92 } // namespace libgtk2ui
94 #endif // CHROME_BROWSER_UI_LIBGTK2UI_X11_INPUT_METHOD_CONTEXT_IMPL_GTK2_H_