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