OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "content/common/edit_command.h" | 13 #include "content/common/edit_command.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "ui/base/gtk/owned_widget_gtk.h" | 15 #include "ui/base/gtk/owned_widget_gtk.h" |
16 | 16 |
| 17 namespace content { |
17 struct NativeWebKeyboardEvent; | 18 struct NativeWebKeyboardEvent; |
| 19 } |
18 | 20 |
19 // This class is a convenience class for handling editor key bindings defined | 21 // This class is a convenience class for handling editor key bindings defined |
20 // in gtk keyboard theme. | 22 // in gtk keyboard theme. |
21 // In gtk, only GtkEntry and GtkTextView support customizing editor key bindings | 23 // In gtk, only GtkEntry and GtkTextView support customizing editor key bindings |
22 // through keyboard theme. And in gtk keyboard theme definition file, each key | 24 // 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 | 25 // 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. | 26 // 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 | 27 // 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 | 28 // 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 | 29 // 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. | 30 // matches a predefined key binding, corresponding signal will be emitted. |
29 // GtkTextView is used here because it supports more key bindings than GtkEntry, | 31 // 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 | 32 // 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 | 33 // class derived from GtkTextView is used, which overrides all signals related |
32 // to key bindings, to make sure GtkTextView won't receive them. | 34 // to key bindings, to make sure GtkTextView won't receive them. |
33 // | 35 // |
34 // See third_party/WebKit/Source/WebCore/editing/EditorCommand.cpp for detailed | 36 // See third_party/WebKit/Source/WebCore/editing/EditorCommand.cpp for detailed |
35 // definition of webkit edit commands. | 37 // definition of webkit edit commands. |
36 // See webkit/glue/editor_client_impl.cc for key bindings predefined in our | 38 // See webkit/glue/editor_client_impl.cc for key bindings predefined in our |
37 // webkit glue. | 39 // webkit glue. |
38 class CONTENT_EXPORT GtkKeyBindingsHandler { | 40 class CONTENT_EXPORT GtkKeyBindingsHandler { |
39 public: | 41 public: |
40 explicit GtkKeyBindingsHandler(GtkWidget* parent_widget); | 42 explicit GtkKeyBindingsHandler(GtkWidget* parent_widget); |
41 ~GtkKeyBindingsHandler(); | 43 ~GtkKeyBindingsHandler(); |
42 | 44 |
43 // Matches a key event against predefined gtk key bindings, false will be | 45 // 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. | 46 // 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|. | 47 // Edit commands matched with |wke| will be stored in |edit_commands|. |
46 bool Match(const NativeWebKeyboardEvent& wke, EditCommands* edit_commands); | 48 bool Match(const content::NativeWebKeyboardEvent& wke, |
| 49 EditCommands* edit_commands); |
47 | 50 |
48 private: | 51 private: |
49 // Object structure of Handler class, which is derived from GtkTextView. | 52 // Object structure of Handler class, which is derived from GtkTextView. |
50 struct Handler { | 53 struct Handler { |
51 GtkTextView parent_object; | 54 GtkTextView parent_object; |
52 GtkKeyBindingsHandler *owner; | 55 GtkKeyBindingsHandler *owner; |
53 }; | 56 }; |
54 | 57 |
55 // Class structure of Handler class. | 58 // Class structure of Handler class. |
56 struct HandlerClass { | 59 struct HandlerClass { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // Handler of "move-focus" signal. | 123 // Handler of "move-focus" signal. |
121 static void MoveFocus(GtkWidget* widget, GtkDirectionType arg1); | 124 static void MoveFocus(GtkWidget* widget, GtkDirectionType arg1); |
122 | 125 |
123 ui::OwnedWidgetGtk handler_; | 126 ui::OwnedWidgetGtk handler_; |
124 | 127 |
125 // Buffer to store the match results. | 128 // Buffer to store the match results. |
126 EditCommands edit_commands_; | 129 EditCommands edit_commands_; |
127 }; | 130 }; |
128 | 131 |
129 #endif // CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ | 132 #endif // CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_ |
OLD | NEW |