2007-12-04 Luca Bruno <lethalman88@gmail.com>
authoralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Dec 2007 13:14:40 +0000 (13:14 +0000)
committeralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Dec 2007 13:14:40 +0000 (13:14 +0000)
        Reviewed by Alp Toker.

        http://bugs.webkit.org/show_bug.cgi?id=15911
        [GTK] Use GtkBindingSet to make key bindings user-configurable

        This patch doesn't cover the full range of bindings, only the ones
        that seem obviously correct and have clear public API.

        * WebCoreSupport/EditorClientGtk.cpp:
        (WebKit::EditorClient::handleKeypress): do not handle clipboard operations and select-all
        * WebView/webkitwebview.cpp: add cut, copy, paste and select-all signals and allow binding sets (issue #15911 and #16144)
        * WebView/webkitwebview.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28386 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/gtk/ChangeLog
WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp
WebKit/gtk/WebView/webkitwebview.cpp
WebKit/gtk/WebView/webkitwebview.h

index 21819d57ee8359a9cc3cea1adf359ee707ee796d..94275bb292759798718362ef080c573611315cde 100644 (file)
@@ -1,3 +1,18 @@
+2007-12-04  Luca Bruno  <lethalman88@gmail.com>
+
+        Reviewed by Alp Toker.
+
+        http://bugs.webkit.org/show_bug.cgi?id=15911
+        [GTK] Use GtkBindingSet to make key bindings user-configurable
+
+        This patch doesn't cover the full range of bindings, only the ones
+        that seem obviously correct and have clear public API.
+
+        * WebCoreSupport/EditorClientGtk.cpp:
+        (WebKit::EditorClient::handleKeypress): do not handle clipboard operations and select-all
+        * WebView/webkitwebview.cpp: add cut, copy, paste and select-all signals and allow binding sets (issue #15911 and #16144)
+        * WebView/webkitwebview.h:
+
 2007-12-04  Xan Lopez  <xan@gnome.org>
 
         Reviewed by Alp Toker.
index 2f7cddca280fcc367926bc0e15918e537ea6d3ba..44786ebbe55cce1a3483dab6574a8de1cf9f28f8 100644 (file)
@@ -285,24 +285,12 @@ void EditorClient::handleKeypress(KeyboardEvent* event)
                     frame->editor()->insertText(kevent->text(), event);
                 } else if (kevent->ctrlKey()) {
                     switch (kevent->WindowsKeyCode()) {
-                        case VK_A:
-                            frame->editor()->execCommand("SelectAll");
-                            break;
                         case VK_B:
                             frame->editor()->execCommand("ToggleBold");
                             break;
-                        case VK_C:
-                            frame->editor()->execCommand("Copy");
-                            break;
                         case VK_I:
                             frame->editor()->execCommand("ToggleItalic");
                             break;
-                        case VK_V:
-                            frame->editor()->execCommand("Paste");
-                            break;
-                        case VK_X:
-                            frame->editor()->execCommand("Cut");
-                            break;
                         case VK_Y:
                             frame->editor()->execCommand("Redo");
                             break;
@@ -337,18 +325,7 @@ void EditorClient::handleKeypress(KeyboardEvent* event)
                     frame->editor()->execCommand("MoveToEndOfDocument");
                 break;
             default:
-                if (kevent->ctrlKey()) {
-                    switch(kevent->WindowsKeyCode()) {
-                        case VK_A:
-                            frame->editor()->execCommand("SelectAll");
-                            break;
-                        case VK_C: case VK_X:
-                            frame->editor()->execCommand("Copy");
-                            break;
-                        default:
-                            return;
-                    }
-                } else return;
+                return;
         }
     }
     event->setDefaultHandled();
index f3b12745ca899e52e02a8ec46b964d4affdc5f86..7feb2efe4e21858a8c6b71fe3d9afa3a9a931c09 100644 (file)
@@ -47,6 +47,7 @@
 #include "InspectorClientGtk.h"
 #include "FrameLoader.h"
 #include "FrameView.h"
+#include "Editor.h"
 #include "PlatformKeyboardEvent.h"
 #include "PlatformWheelEvent.h"
 #include "SubstituteData.h"
@@ -74,6 +75,10 @@ enum {
     SCRIPT_ALERT,
     SCRIPT_CONFIRM,
     SCRIPT_PROMPT,
+    SELECT_ALL,
+    COPY_CLIPBOARD,
+    PASTE_CLIPBOARD,
+    CUT_CLIPBOARD,
     LAST_SIGNAL
 };
 
@@ -103,36 +108,33 @@ static gboolean webkit_web_view_key_event(GtkWidget* widget, GdkEventKey* event)
     Frame* frame = core(getFrameFromView(WEBKIT_WEB_VIEW(widget)));
     PlatformKeyboardEvent keyboardEvent(event);
 
-    if (frame->eventHandler()->keyEvent(keyboardEvent))
-        return TRUE;
-
-    if (event->type != GDK_KEY_PRESS)
-        return FALSE;
-
-    FrameView* view = frame->view();
-
-    /* FIXME: at the very least we should be using the same code than the
-       Windows port here, but our ScrollView file diverges enough to make
-       that impossible. A short term solution would be to unify ScrollViewWin
-       and ScrollViewGtk. Long-term ScrollView and FrameView should be
-       unified and used everywhere for scrollbars */
-
-    switch (event->keyval) {
-    case (GDK_Down):
-        view->scrollBy(0, LINE_STEP);
-        return TRUE;
-    case (GDK_Up):
-        view->scrollBy(0, -LINE_STEP);
-        return TRUE;
-    case (GDK_Right):
-        view->scrollBy(LINE_STEP, 0);
-        return TRUE;
-    case (GDK_Left):
-        view->scrollBy(-LINE_STEP, 0);
-        return TRUE;
-    }
-
-    return FALSE;
+    if (!frame->eventHandler()->keyEvent(keyboardEvent) && event->type == GDK_KEY_PRESS)
+      {
+          FrameView* view = frame->view();
+
+          /* FIXME: at the very least we should be using the same code than the
+             Windows port here, but our ScrollView file diverges enough to make
+             that impossible. A short term solution would be to unify ScrollViewWin
+             and ScrollViewGtk. Long-term ScrollView and FrameView should be
+             unified and used everywhere for scrollbars */
+
+          switch (event->keyval) {
+          case GDK_Down:
+              view->scrollBy(0, LINE_STEP);
+              return TRUE;
+          case GDK_Up:
+              view->scrollBy(0, -LINE_STEP);
+              return TRUE;
+          case GDK_Right:
+              view->scrollBy(LINE_STEP, 0);
+              return TRUE;
+          case GDK_Left:
+              view->scrollBy(-LINE_STEP, 0);
+              return TRUE;
+          }
+      }
+
+    return gtk_bindings_activate_event(GTK_OBJECT(widget), event);
 }
 
 static gboolean webkit_web_view_button_event(GtkWidget* widget, GdkEventButton* event)
@@ -360,6 +362,30 @@ static gboolean webkit_web_view_real_console_message(WebKitWebView* webView, con
     return TRUE;
 }
 
+static void webkit_web_view_real_select_all(WebKitWebView* webView)
+{
+    Frame* frame = core(getFrameFromView(webView));
+    frame->editor()->execCommand("SelectAll");
+}
+
+static void webkit_web_view_real_cut_clipboard(WebKitWebView* webView)
+{
+    Frame* frame = core(getFrameFromView(webView));
+    frame->editor()->execCommand("Cut");
+}
+
+static void webkit_web_view_real_copy_clipboard(WebKitWebView* webView)
+{
+    Frame* frame = core(getFrameFromView(webView));
+    frame->editor()->execCommand("Copy");
+}
+
+static void webkit_web_view_real_paste_clipboard(WebKitWebView* webView)
+{
+    Frame* frame = core(getFrameFromView(webView));
+    frame->editor()->execCommand("Paste");
+}
+
 static void webkit_web_view_finalize(GObject* object)
 {
     webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(object));
@@ -375,6 +401,8 @@ static void webkit_web_view_finalize(GObject* object)
 
 static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
 {
+    GtkBindingSet* binding_set;
+
     g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate));
 
     /*
@@ -590,6 +618,73 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
             G_TYPE_BOOLEAN, 4,
             G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
 
+    /**
+     * WebKitWebView::select-all:
+     * @web_view: the object which received the signal
+     *
+     * The ::select-all signal is a keybinding signal which gets emitted to
+     * select the complete contents of the text view.
+     *
+     * The default bindings for this signal is Ctrl-a.
+     */
+    webkit_web_view_signals[SELECT_ALL] = g_signal_new("select_all",
+            G_TYPE_FROM_CLASS(webViewClass),
+            (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
+            G_STRUCT_OFFSET(WebKitWebViewClass, select_all),
+            NULL, NULL,
+            g_cclosure_marshal_VOID__VOID,
+            G_TYPE_NONE, 0);
+
+    /**
+     * WebKitWebView::cut-clipboard:
+     * @web_view: the object which received the signal
+     *
+     * The ::cut-clipboard signal is a keybinding signal which gets emitted to
+     * cut the selection to the clipboard.
+     *
+     * The default bindings for this signal are Ctrl-x and Shift-Delete.
+     */
+    webkit_web_view_signals[CUT_CLIPBOARD] = g_signal_new("cut_clipboard",
+            G_TYPE_FROM_CLASS(webViewClass),
+            (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
+            G_STRUCT_OFFSET(WebKitWebViewClass, cut_clipboard),
+            NULL, NULL,
+            g_cclosure_marshal_VOID__VOID,
+            G_TYPE_NONE, 0);
+
+    /**
+     * WebKitWebView::copy-clipboard:
+     * @web_view: the object which received the signal
+     *
+     * The ::copy-clipboard signal is a keybinding signal which gets emitted to
+     * copy the selection to the clipboard.
+     *
+     * The default bindings for this signal are Ctrl-c and Ctrl-Insert.
+     */
+    webkit_web_view_signals[COPY_CLIPBOARD] = g_signal_new("copy_clipboard",
+            G_TYPE_FROM_CLASS(webViewClass),
+            (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
+            G_STRUCT_OFFSET(WebKitWebViewClass, copy_clipboard),
+            NULL, NULL,
+            g_cclosure_marshal_VOID__VOID,
+            G_TYPE_NONE, 0);
+
+    /**
+     * WebKitWebView::paste-clipboard:
+     * @web_view: the object which received the signal
+     *
+     * The ::paste-clipboard signal is a keybinding signal which gets emitted to
+     * paste the contents of the clipboard into the Web view.
+     *
+     * The default bindings for this signal are Ctrl-v and Shift-Insert.
+     */
+    webkit_web_view_signals[PASTE_CLIPBOARD] = g_signal_new("paste_clipboard",
+            G_TYPE_FROM_CLASS(webViewClass),
+            (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
+            G_STRUCT_OFFSET(WebKitWebViewClass, paste_clipboard),
+            NULL, NULL,
+            g_cclosure_marshal_VOID__VOID,
+            G_TYPE_NONE, 0);
 
     /*
      * implementations of virtual methods
@@ -602,6 +697,10 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
     webViewClass->script_confirm = webkit_web_view_real_script_confirm;
     webViewClass->script_prompt = webkit_web_view_real_script_prompt;
     webViewClass->console_message = webkit_web_view_real_console_message;
+    webViewClass->select_all = webkit_web_view_real_select_all;
+    webViewClass->cut_clipboard = webkit_web_view_real_cut_clipboard;
+    webViewClass->copy_clipboard = webkit_web_view_real_copy_clipboard;
+    webViewClass->paste_clipboard = webkit_web_view_real_paste_clipboard;
 
     G_OBJECT_CLASS(webViewClass)->finalize = webkit_web_view_finalize;
 
@@ -633,6 +732,31 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
             webkit_marshal_VOID__OBJECT_OBJECT,
             G_TYPE_NONE, 2,
             GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
+
+    /*
+     * Key bindings
+     */
+
+    binding_set = gtk_binding_set_by_class(webViewClass);
+
+    gtk_binding_entry_add_signal(binding_set, GDK_a, GDK_CONTROL_MASK,
+                                 "select_all", 0);
+
+    /* Cut/copy/paste */
+
+    gtk_binding_entry_add_signal(binding_set, GDK_x, GDK_CONTROL_MASK,
+                                 "cut_clipboard", 0);
+    gtk_binding_entry_add_signal(binding_set, GDK_c, GDK_CONTROL_MASK,
+                                 "copy_clipboard", 0);
+    gtk_binding_entry_add_signal(binding_set, GDK_v, GDK_CONTROL_MASK,
+                                 "paste_clipboard", 0);
+
+    gtk_binding_entry_add_signal(binding_set, GDK_Delete, GDK_SHIFT_MASK,
+                                 "cut_clipboard", 0);
+    gtk_binding_entry_add_signal(binding_set, GDK_Insert, GDK_CONTROL_MASK,
+                                 "copy_clipboard", 0);
+    gtk_binding_entry_add_signal(binding_set, GDK_Insert, GDK_SHIFT_MASK,
+                                 "paste_clipboard", 0);
 }
 
 static void webkit_web_view_init(WebKitWebView* webView)
@@ -643,6 +767,7 @@ static void webkit_web_view_init(WebKitWebView* webView)
     Settings* settings = webViewData->corePage->settings();
     settings->setLoadsImagesAutomatically(true);
     settings->setMinimumFontSize(5);
+    settings->setDOMPasteAllowed(true);
     settings->setMinimumLogicalFontSize(5);
     settings->setShouldPrintBackgrounds(true);
     settings->setJavaScriptEnabled(true);
index 9708419a4724699597233871ef956a671202c9aa..2af6f3c0fa708fff2c719e00d8a01c8bbe71efb8 100644 (file)
@@ -78,6 +78,10 @@ struct _WebKitWebViewClass {
     gboolean (*script_confirm) (WebKitWebView* web_view, WebKitWebFrame* frame, const gchar* confirm_message, gboolean* did_confirm);
     gboolean (*script_prompt) (WebKitWebView* web_view, WebKitWebFrame* frame, const gchar* message, const gchar* default_value, gchar** value);
     gboolean (*console_message) (WebKitWebView* web_view, const gchar* message, unsigned int line_number, const gchar* source_id);
+    void (*select_all) (WebKitWebView* web_view);
+    void (*cut_clipboard) (WebKitWebView* web_view);
+    void (*copy_clipboard) (WebKitWebView* web_view);
+    void (*paste_clipboard) (WebKitWebView* web_view);
 
     /*
      * internal