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