OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_GTK2_KEY_BINDINGS_HANDLER_H_ | |
6 #define CHROME_BROWSER_UI_LIBGTKUI_GTK2_KEY_BINDINGS_HANDLER_H_ | |
7 | |
8 #include <gtk/gtk.h> | |
9 | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/event_types.h" | |
14 #include "ui/base/ime/linux/text_edit_command_auralinux.h" | |
15 | |
16 namespace content { | |
17 struct NativeWebKeyboardEvent; | |
18 } | |
19 | |
20 namespace ui { | |
21 class Event; | |
22 } | |
23 | |
24 namespace libgtkui { | |
25 | |
26 // This class is a convenience class for handling editor key bindings defined | |
27 // in gtk keyboard theme. | |
28 // In gtk, only GtkEntry and GtkTextView support customizing editor key bindings | |
29 // through keyboard theme. And in gtk keyboard theme definition file, each key | |
30 // binding must be bound to a specific class or object. So existing keyboard | |
31 // themes only define editor key bindings exactly for GtkEntry and GtkTextView. | |
32 // Then, the only way for us to intercept editor key bindings defined in | |
33 // keyboard theme, is to create a GtkEntry or GtkTextView object and call | |
34 // gtk_bindings_activate_event() against it for the key events. If a key event | |
35 // matches a predefined key binding, corresponding signal will be emitted. | |
36 // GtkTextView is used here because it supports more key bindings than GtkEntry, | |
37 // but in order to minimize the side effect of using a GtkTextView object, a new | |
38 // class derived from GtkTextView is used, which overrides all signals related | |
39 // to key bindings, to make sure GtkTextView won't receive them. | |
40 // | |
41 // See third_party/WebKit/Source/WebCore/editing/EditorCommand.cpp for detailed | |
42 // definition of webkit edit commands. | |
43 // See webkit/glue/editor_client_impl.cc for key bindings predefined in our | |
44 // webkit glue. | |
45 class Gtk2KeyBindingsHandler { | |
46 public: | |
47 Gtk2KeyBindingsHandler(); | |
48 virtual ~Gtk2KeyBindingsHandler(); | |
49 | |
50 // Matches a key event against predefined gtk key bindings, false will be | |
51 // returned if the key event doesn't correspond to a predefined key binding. | |
52 // Edit commands matched with |event| will be stored in |edit_commands|, if | |
53 // non-NULL. | |
54 bool MatchEvent(const ui::Event& event, | |
55 std::vector<ui::TextEditCommandAuraLinux>* commands); | |
56 | |
57 private: | |
58 // Object structure of Handler class, which is derived from GtkTextView. | |
59 struct Handler { | |
60 GtkTextView parent_object; | |
61 Gtk2KeyBindingsHandler *owner; | |
62 }; | |
63 | |
64 // Class structure of Handler class. | |
65 struct HandlerClass { | |
66 GtkTextViewClass parent_class; | |
67 }; | |
68 | |
69 // Creates a new instance of Handler class. | |
70 GtkWidget* CreateNewHandler(); | |
71 | |
72 // Adds an edit command to the key event. | |
73 void EditCommandMatched(ui::TextEditCommand command, | |
74 const std::string& value); | |
75 | |
76 // Builds a fake GdkEventKey from an XEvent. | |
77 void BuildGdkEventKeyFromXEvent(const base::NativeEvent& xevent, | |
78 GdkEventKey* gdk_event); | |
79 | |
80 // Initializes Handler structure. | |
81 static void HandlerInit(Handler *self); | |
82 | |
83 // Initializes HandlerClass structure. | |
84 static void HandlerClassInit(HandlerClass *klass); | |
85 | |
86 // Registeres Handler class to GObject type system and return its type id. | |
87 static GType HandlerGetType(); | |
88 | |
89 // Gets the Gtk2KeyBindingsHandler object which owns the Handler object. | |
90 static Gtk2KeyBindingsHandler* GetHandlerOwner(GtkTextView* text_view); | |
91 | |
92 // Handler of "backspace" signal. | |
93 static void BackSpace(GtkTextView* text_view); | |
94 | |
95 // Handler of "copy-clipboard" signal. | |
96 static void CopyClipboard(GtkTextView* text_view); | |
97 | |
98 // Handler of "cut-clipboard" signal. | |
99 static void CutClipboard(GtkTextView* text_view); | |
100 | |
101 // Handler of "delete-from-cursor" signal. | |
102 static void DeleteFromCursor(GtkTextView* text_view, GtkDeleteType type, | |
103 gint count); | |
104 | |
105 // Handler of "insert-at-cursor" signal. | |
106 static void InsertAtCursor(GtkTextView* text_view, const gchar* str); | |
107 | |
108 // Handler of "move-cursor" signal. | |
109 static void MoveCursor(GtkTextView* text_view, GtkMovementStep step, | |
110 gint count, gboolean extend_selection); | |
111 | |
112 // Handler of "move-viewport" signal. | |
113 static void MoveViewport(GtkTextView* text_view, GtkScrollStep step, | |
114 gint count); | |
115 | |
116 // Handler of "paste-clipboard" signal. | |
117 static void PasteClipboard(GtkTextView* text_view); | |
118 | |
119 // Handler of "select-all" signal. | |
120 static void SelectAll(GtkTextView* text_view, gboolean select); | |
121 | |
122 // Handler of "set-anchor" signal. | |
123 static void SetAnchor(GtkTextView* text_view); | |
124 | |
125 // Handler of "toggle-cursor-visible" signal. | |
126 static void ToggleCursorVisible(GtkTextView* text_view); | |
127 | |
128 // Handler of "toggle-overwrite" signal. | |
129 static void ToggleOverwrite(GtkTextView* text_view); | |
130 | |
131 // Handler of "show-help" signal. | |
132 static gboolean ShowHelp(GtkWidget* widget, GtkWidgetHelpType arg1); | |
133 | |
134 // Handler of "move-focus" signal. | |
135 static void MoveFocus(GtkWidget* widget, GtkDirectionType arg1); | |
136 | |
137 GtkWidget* fake_window_; | |
138 GtkWidget* handler_; | |
139 | |
140 // Buffer to store the match results. | |
141 std::vector<ui::TextEditCommandAuraLinux> edit_commands_; | |
142 | |
143 // Whether the current X server has the XKeyboard extension. | |
144 bool has_xkb_; | |
145 }; | |
146 | |
147 } // namespace libgtkui | |
148 | |
149 #endif // CHROME_BROWSER_UI_LIBGTKUI_GTK2_KEY_BINDINGS_HANDLER_H_ | |
OLD | NEW |