| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_GTK2_KEY_BINDINGS_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_LIBGTK2UI_GTK2_KEY_BINDINGS_HANDLER_H_ |
| 7 | 7 |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "content/common/edit_command.h" | 12 #include "base/event_types.h" |
| 13 #include "content/common/content_export.h" | 13 #include "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h" |
| 14 #include "ui/base/gtk/owned_widget_gtk.h" | 14 #include "content/public/browser/keybinding_handler_aurax11.h" |
| 15 #include "content/public/common/edit_command.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 struct NativeWebKeyboardEvent; | 18 struct NativeWebKeyboardEvent; |
| 19 } |
| 20 |
| 21 namespace libgtk2ui { |
| 18 | 22 |
| 19 // This class is a convenience class for handling editor key bindings defined | 23 // This class is a convenience class for handling editor key bindings defined |
| 20 // in gtk keyboard theme. | 24 // in gtk keyboard theme. |
| 21 // In gtk, only GtkEntry and GtkTextView support customizing editor key bindings | 25 // In gtk, only GtkEntry and GtkTextView support customizing editor key bindings |
| 22 // through keyboard theme. And in gtk keyboard theme definition file, each key | 26 // 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 | 27 // 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. | 28 // 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 | 29 // 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 | 30 // 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 | 31 // 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. | 32 // matches a predefined key binding, corresponding signal will be emitted. |
| 29 // GtkTextView is used here because it supports more key bindings than GtkEntry, | 33 // 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 | 34 // 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 | 35 // class derived from GtkTextView is used, which overrides all signals related |
| 32 // to key bindings, to make sure GtkTextView won't receive them. | 36 // to key bindings, to make sure GtkTextView won't receive them. |
| 33 // | 37 // |
| 34 // See third_party/WebKit/Source/WebCore/editing/EditorCommand.cpp for detailed | 38 // See third_party/WebKit/Source/WebCore/editing/EditorCommand.cpp for detailed |
| 35 // definition of webkit edit commands. | 39 // definition of webkit edit commands. |
| 36 // See webkit/glue/editor_client_impl.cc for key bindings predefined in our | 40 // See webkit/glue/editor_client_impl.cc for key bindings predefined in our |
| 37 // webkit glue. | 41 // webkit glue. |
| 38 class CONTENT_EXPORT GtkKeyBindingsHandler { | 42 class Gtk2KeyBindingsHandler : public content::KeybindingHandlerAuraX11 { |
| 39 public: | 43 public: |
| 40 explicit GtkKeyBindingsHandler(GtkWidget* parent_widget); | 44 Gtk2KeyBindingsHandler(); |
| 41 ~GtkKeyBindingsHandler(); | 45 virtual ~Gtk2KeyBindingsHandler(); |
| 42 | 46 |
| 43 // Matches a key event against predefined gtk key bindings, false will be | 47 // Overridden from content::KeybindingHandlerAuraX11: |
| 44 // returned if the key event doesn't correspond to a predefined key binding. | 48 virtual bool Match(const content::NativeWebKeyboardEvent& wke, |
| 45 // Edit commands matched with |wke| will be stored in |edit_commands|. | 49 content::EditCommands* edit_commands) OVERRIDE; |
| 46 bool Match(const NativeWebKeyboardEvent& wke, | |
| 47 EditCommands* edit_commands); | |
| 48 | 50 |
| 49 private: | 51 private: |
| 50 // Object structure of Handler class, which is derived from GtkTextView. | 52 // Object structure of Handler class, which is derived from GtkTextView. |
| 51 struct Handler { | 53 struct Handler { |
| 52 GtkTextView parent_object; | 54 GtkTextView parent_object; |
| 53 GtkKeyBindingsHandler *owner; | 55 Gtk2KeyBindingsHandler *owner; |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 // Class structure of Handler class. | 58 // Class structure of Handler class. |
| 57 struct HandlerClass { | 59 struct HandlerClass { |
| 58 GtkTextViewClass parent_class; | 60 GtkTextViewClass parent_class; |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 // Creates a new instance of Handler class. | 63 // Creates a new instance of Handler class. |
| 62 GtkWidget* CreateNewHandler(); | 64 GtkWidget* CreateNewHandler(); |
| 63 | 65 |
| 64 // Adds an edit command to the key event. | 66 // Adds an edit command to the key event. |
| 65 void EditCommandMatched(const std::string& name, const std::string& value); | 67 void EditCommandMatched(const std::string& name, const std::string& value); |
| 66 | 68 |
| 69 // Builds a fake GdkEventKey from an XEvent. |
| 70 void BuildGdkEventKeyFromXEvent(const base::NativeEvent& xevent, |
| 71 GdkEventKey* gdk_event); |
| 72 |
| 67 // Initializes Handler structure. | 73 // Initializes Handler structure. |
| 68 static void HandlerInit(Handler *self); | 74 static void HandlerInit(Handler *self); |
| 69 | 75 |
| 70 // Initializes HandlerClass structure. | 76 // Initializes HandlerClass structure. |
| 71 static void HandlerClassInit(HandlerClass *klass); | 77 static void HandlerClassInit(HandlerClass *klass); |
| 72 | 78 |
| 73 // Registeres Handler class to GObject type system and return its type id. | 79 // Registeres Handler class to GObject type system and return its type id. |
| 74 static GType HandlerGetType(); | 80 static GType HandlerGetType(); |
| 75 | 81 |
| 76 // Gets the GtkKeyBindingsHandler object which owns the Handler object. | 82 // Gets the Gtk2KeyBindingsHandler object which owns the Handler object. |
| 77 static GtkKeyBindingsHandler* GetHandlerOwner(GtkTextView* text_view); | 83 static Gtk2KeyBindingsHandler* GetHandlerOwner(GtkTextView* text_view); |
| 78 | 84 |
| 79 // Handler of "backspace" signal. | 85 // Handler of "backspace" signal. |
| 80 static void BackSpace(GtkTextView* text_view); | 86 static void BackSpace(GtkTextView* text_view); |
| 81 | 87 |
| 82 // Handler of "copy-clipboard" signal. | 88 // Handler of "copy-clipboard" signal. |
| 83 static void CopyClipboard(GtkTextView* text_view); | 89 static void CopyClipboard(GtkTextView* text_view); |
| 84 | 90 |
| 85 // Handler of "cut-clipboard" signal. | 91 // Handler of "cut-clipboard" signal. |
| 86 static void CutClipboard(GtkTextView* text_view); | 92 static void CutClipboard(GtkTextView* text_view); |
| 87 | 93 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 114 | 120 |
| 115 // Handler of "toggle-overwrite" signal. | 121 // Handler of "toggle-overwrite" signal. |
| 116 static void ToggleOverwrite(GtkTextView* text_view); | 122 static void ToggleOverwrite(GtkTextView* text_view); |
| 117 | 123 |
| 118 // Handler of "show-help" signal. | 124 // Handler of "show-help" signal. |
| 119 static gboolean ShowHelp(GtkWidget* widget, GtkWidgetHelpType arg1); | 125 static gboolean ShowHelp(GtkWidget* widget, GtkWidgetHelpType arg1); |
| 120 | 126 |
| 121 // Handler of "move-focus" signal. | 127 // Handler of "move-focus" signal. |
| 122 static void MoveFocus(GtkWidget* widget, GtkDirectionType arg1); | 128 static void MoveFocus(GtkWidget* widget, GtkDirectionType arg1); |
| 123 | 129 |
| 124 ui::OwnedWidgetGtk handler_; | 130 GtkWidget* fake_window_; |
| 131 |
| 132 libgtk2ui::OwnedWidgetGtk handler_; |
| 125 | 133 |
| 126 // Buffer to store the match results. | 134 // Buffer to store the match results. |
| 127 EditCommands edit_commands_; | 135 content::EditCommands edit_commands_; |
| 136 |
| 137 // Whether the current X server has the XKeyboard extension. |
| 138 bool has_xkb_; |
| 128 }; | 139 }; |
| 129 | 140 |
| 130 } // namespace content | 141 } // namespace libgtk2ui |
| 131 | 142 |
| 132 #endif // CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ | 143 #endif // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_KEY_BINDINGS_HANDLER_H_ |
| OLD | NEW |