Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / gtk_key_bindings_handler.h
blob9006f5d0727163882f7305a24abc0f5295703c66
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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_
8 #include <gtk/gtk.h>
10 #include <string>
12 #include "content/common/edit_command.h"
13 #include "content/common/content_export.h"
14 #include "ui/base/gtk/owned_widget_gtk.h"
16 namespace content {
17 struct NativeWebKeyboardEvent;
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.
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();
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);
49 private:
50 // Object structure of Handler class, which is derived from GtkTextView.
51 struct Handler {
52 GtkTextView parent_object;
53 GtkKeyBindingsHandler *owner;
56 // Class structure of Handler class.
57 struct HandlerClass {
58 GtkTextViewClass parent_class;
61 // Creates a new instance of Handler class.
62 GtkWidget* CreateNewHandler();
64 // Adds an edit command to the key event.
65 void EditCommandMatched(const std::string& name, const std::string& value);
67 // Initializes Handler structure.
68 static void HandlerInit(Handler *self);
70 // Initializes HandlerClass structure.
71 static void HandlerClassInit(HandlerClass *klass);
73 // Registeres Handler class to GObject type system and return its type id.
74 static GType HandlerGetType();
76 // Gets the GtkKeyBindingsHandler object which owns the Handler object.
77 static GtkKeyBindingsHandler* GetHandlerOwner(GtkTextView* text_view);
79 // Handler of "backspace" signal.
80 static void BackSpace(GtkTextView* text_view);
82 // Handler of "copy-clipboard" signal.
83 static void CopyClipboard(GtkTextView* text_view);
85 // Handler of "cut-clipboard" signal.
86 static void CutClipboard(GtkTextView* text_view);
88 // Handler of "delete-from-cursor" signal.
89 static void DeleteFromCursor(GtkTextView* text_view, GtkDeleteType type,
90 gint count);
92 // Handler of "insert-at-cursor" signal.
93 static void InsertAtCursor(GtkTextView* text_view, const gchar* str);
95 // Handler of "move-cursor" signal.
96 static void MoveCursor(GtkTextView* text_view, GtkMovementStep step,
97 gint count, gboolean extend_selection);
99 // Handler of "move-viewport" signal.
100 static void MoveViewport(GtkTextView* text_view, GtkScrollStep step,
101 gint count);
103 // Handler of "paste-clipboard" signal.
104 static void PasteClipboard(GtkTextView* text_view);
106 // Handler of "select-all" signal.
107 static void SelectAll(GtkTextView* text_view, gboolean select);
109 // Handler of "set-anchor" signal.
110 static void SetAnchor(GtkTextView* text_view);
112 // Handler of "toggle-cursor-visible" signal.
113 static void ToggleCursorVisible(GtkTextView* text_view);
115 // Handler of "toggle-overwrite" signal.
116 static void ToggleOverwrite(GtkTextView* text_view);
118 // Handler of "show-help" signal.
119 static gboolean ShowHelp(GtkWidget* widget, GtkWidgetHelpType arg1);
121 // Handler of "move-focus" signal.
122 static void MoveFocus(GtkWidget* widget, GtkDirectionType arg1);
124 ui::OwnedWidgetGtk handler_;
126 // Buffer to store the match results.
127 EditCommands edit_commands_;
130 } // namespace content
132 #endif // CONTENT_BROWSER_RENDERER_HOST_GTK_KEY_BINDINGS_HANDLER_H_