Diff
Modified: trunk/Source/WebCore/ChangeLog (185415 => 185416)
--- trunk/Source/WebCore/ChangeLog 2015-06-10 13:32:22 UTC (rev 185415)
+++ trunk/Source/WebCore/ChangeLog 2015-06-10 15:17:53 UTC (rev 185416)
@@ -1,5 +1,17 @@
2015-06-10 Carlos Garcia Campos <[email protected]>
+ [GTK] Move KeyBindingTranslator from platform to WebKit2 layer
+ https://bugs.webkit.org/show_bug.cgi?id=145840
+
+ Reviewed by Martin Robinson.
+
+ It's currently used only by WebKit2 in the UI process and it's
+ another file built twice because of the GTK2 plugin process.
+
+ * PlatformGTK.cmake:
+
+2015-06-10 Carlos Garcia Campos <[email protected]>
+
[GTK] Get rid of GetEditorCommandsForKeyEvent sync message
https://bugs.webkit.org/show_bug.cgi?id=145598
Modified: trunk/Source/WebCore/PlatformGTK.cmake (185415 => 185416)
--- trunk/Source/WebCore/PlatformGTK.cmake 2015-06-10 13:32:22 UTC (rev 185415)
+++ trunk/Source/WebCore/PlatformGTK.cmake 2015-06-10 15:17:53 UTC (rev 185416)
@@ -220,7 +220,6 @@
platform/gtk/GRefPtrGtk.cpp
platform/gtk/GtkUtilities.cpp
platform/gtk/GtkVersioning.c
- platform/gtk/KeyBindingTranslator.cpp
platform/gtk/LocalizedStringsGtk.cpp
platform/gtk/PasteboardGtk.cpp
platform/gtk/PasteboardHelper.cpp
Deleted: trunk/Source/WebCore/platform/gtk/KeyBindingTranslator.cpp (185415 => 185416)
--- trunk/Source/WebCore/platform/gtk/KeyBindingTranslator.cpp 2015-06-10 13:32:22 UTC (rev 185415)
+++ trunk/Source/WebCore/platform/gtk/KeyBindingTranslator.cpp 2015-06-10 15:17:53 UTC (rev 185416)
@@ -1,227 +0,0 @@
-/*
- * Copyright (C) 2010, 2011 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "config.h"
-#include "KeyBindingTranslator.h"
-
-#include "GtkVersioning.h"
-#include <gdk/gdkkeysyms.h>
-#include <wtf/HashMap.h>
-
-namespace WebCore {
-
-typedef HashMap<int, const char*> IntConstCharHashMap;
-
-static void backspaceCallback(GtkWidget* widget, KeyBindingTranslator* translator)
-{
- g_signal_stop_emission_by_name(widget, "backspace");
- translator->addPendingEditorCommand("DeleteBackward");
-}
-
-static void selectAllCallback(GtkWidget* widget, gboolean select, KeyBindingTranslator* translator)
-{
- g_signal_stop_emission_by_name(widget, "select-all");
- translator->addPendingEditorCommand(select ? "SelectAll" : "Unselect");
-}
-
-static void cutClipboardCallback(GtkWidget* widget, KeyBindingTranslator* translator)
-{
- g_signal_stop_emission_by_name(widget, "cut-clipboard");
- translator->addPendingEditorCommand("Cut");
-}
-
-static void copyClipboardCallback(GtkWidget* widget, KeyBindingTranslator* translator)
-{
- g_signal_stop_emission_by_name(widget, "copy-clipboard");
- translator->addPendingEditorCommand("Copy");
-}
-
-static void pasteClipboardCallback(GtkWidget* widget, KeyBindingTranslator* translator)
-{
- g_signal_stop_emission_by_name(widget, "paste-clipboard");
- translator->addPendingEditorCommand("Paste");
-}
-
-static void toggleOverwriteCallback(GtkWidget* widget, KeyBindingTranslator* translator)
-{
- g_signal_stop_emission_by_name(widget, "toggle-overwrite");
- translator->addPendingEditorCommand("OverWrite");
-}
-
-// GTK+ will still send these signals to the web view. So we can safely stop signal
-// emission without breaking accessibility.
-static void popupMenuCallback(GtkWidget* widget, KeyBindingTranslator*)
-{
- g_signal_stop_emission_by_name(widget, "popup-menu");
-}
-
-static void showHelpCallback(GtkWidget* widget, KeyBindingTranslator*)
-{
- g_signal_stop_emission_by_name(widget, "show-help");
-}
-
-static const char* const gtkDeleteCommands[][2] = {
- { "DeleteBackward", "DeleteForward" }, // Characters
- { "DeleteWordBackward", "DeleteWordForward" }, // Word ends
- { "DeleteWordBackward", "DeleteWordForward" }, // Words
- { "DeleteToBeginningOfLine", "DeleteToEndOfLine" }, // Lines
- { "DeleteToBeginningOfLine", "DeleteToEndOfLine" }, // Line ends
- { "DeleteToBeginningOfParagraph", "DeleteToEndOfParagraph" }, // Paragraph ends
- { "DeleteToBeginningOfParagraph", "DeleteToEndOfParagraph" }, // Paragraphs
- { 0, 0 } // Whitespace (M-\ in Emacs)
-};
-
-static void deleteFromCursorCallback(GtkWidget* widget, GtkDeleteType deleteType, gint count, KeyBindingTranslator* translator)
-{
- g_signal_stop_emission_by_name(widget, "delete-from-cursor");
- int direction = count > 0 ? 1 : 0;
-
- // Ensuring that deleteType <= G_N_ELEMENTS here results in a compiler warning
- // that the condition is always true.
-
- if (deleteType == GTK_DELETE_WORDS) {
- if (!direction) {
- translator->addPendingEditorCommand("MoveWordForward");
- translator->addPendingEditorCommand("MoveWordBackward");
- } else {
- translator->addPendingEditorCommand("MoveWordBackward");
- translator->addPendingEditorCommand("MoveWordForward");
- }
- } else if (deleteType == GTK_DELETE_DISPLAY_LINES) {
- if (!direction)
- translator->addPendingEditorCommand("MoveToBeginningOfLine");
- else
- translator->addPendingEditorCommand("MoveToEndOfLine");
- } else if (deleteType == GTK_DELETE_PARAGRAPHS) {
- if (!direction)
- translator->addPendingEditorCommand("MoveToBeginningOfParagraph");
- else
- translator->addPendingEditorCommand("MoveToEndOfParagraph");
- }
-
- const char* rawCommand = gtkDeleteCommands[deleteType][direction];
- if (!rawCommand)
- return;
-
- for (int i = 0; i < abs(count); i++)
- translator->addPendingEditorCommand(rawCommand);
-}
-
-static const char* const gtkMoveCommands[][4] = {
- { "MoveBackward", "MoveForward",
- "MoveBackwardAndModifySelection", "MoveForwardAndModifySelection" }, // Forward/backward grapheme
- { "MoveLeft", "MoveRight",
- "MoveBackwardAndModifySelection", "MoveForwardAndModifySelection" }, // Left/right grapheme
- { "MoveWordBackward", "MoveWordForward",
- "MoveWordBackwardAndModifySelection", "MoveWordForwardAndModifySelection" }, // Forward/backward word
- { "MoveUp", "MoveDown",
- "MoveUpAndModifySelection", "MoveDownAndModifySelection" }, // Up/down line
- { "MoveToBeginningOfLine", "MoveToEndOfLine",
- "MoveToBeginningOfLineAndModifySelection", "MoveToEndOfLineAndModifySelection" }, // Up/down line ends
- { "MoveParagraphBackward", "MoveParagraphForward",
- "MoveParagraphBackwardAndModifySelection", "MoveParagraphForwardAndModifySelection" }, // Up/down paragraphs
- { "MoveToBeginningOfParagraph", "MoveToEndOfParagraph",
- "MoveToBeginningOfParagraphAndModifySelection", "MoveToEndOfParagraphAndModifySelection" }, // Up/down paragraph ends.
- { "MovePageUp", "MovePageDown",
- "MovePageUpAndModifySelection", "MovePageDownAndModifySelection" }, // Up/down page
- { "MoveToBeginningOfDocument", "MoveToEndOfDocument",
- "MoveToBeginningOfDocumentAndModifySelection", "MoveToEndOfDocumentAndModifySelection" }, // Begin/end of buffer
- { 0, 0,
- 0, 0 } // Horizontal page movement
-};
-
-static void moveCursorCallback(GtkWidget* widget, GtkMovementStep step, gint count, gboolean extendSelection, KeyBindingTranslator* translator)
-{
- g_signal_stop_emission_by_name(widget, "move-cursor");
- int direction = count > 0 ? 1 : 0;
- if (extendSelection)
- direction += 2;
-
- if (static_cast<unsigned>(step) >= G_N_ELEMENTS(gtkMoveCommands))
- return;
-
- const char* rawCommand = gtkMoveCommands[step][direction];
- if (!rawCommand)
- return;
-
- for (int i = 0; i < abs(count); i++)
- translator->addPendingEditorCommand(rawCommand);
-}
-
-KeyBindingTranslator::KeyBindingTranslator()
- : m_nativeWidget(gtk_text_view_new())
-{
- g_signal_connect(m_nativeWidget.get(), "backspace", G_CALLBACK(backspaceCallback), this);
- g_signal_connect(m_nativeWidget.get(), "cut-clipboard", G_CALLBACK(cutClipboardCallback), this);
- g_signal_connect(m_nativeWidget.get(), "copy-clipboard", G_CALLBACK(copyClipboardCallback), this);
- g_signal_connect(m_nativeWidget.get(), "paste-clipboard", G_CALLBACK(pasteClipboardCallback), this);
- g_signal_connect(m_nativeWidget.get(), "select-all", G_CALLBACK(selectAllCallback), this);
- g_signal_connect(m_nativeWidget.get(), "move-cursor", G_CALLBACK(moveCursorCallback), this);
- g_signal_connect(m_nativeWidget.get(), "delete-from-cursor", G_CALLBACK(deleteFromCursorCallback), this);
- g_signal_connect(m_nativeWidget.get(), "toggle-overwrite", G_CALLBACK(toggleOverwriteCallback), this);
- g_signal_connect(m_nativeWidget.get(), "popup-menu", G_CALLBACK(popupMenuCallback), this);
- g_signal_connect(m_nativeWidget.get(), "show-help", G_CALLBACK(showHelpCallback), this);
-}
-
-struct KeyCombinationEntry {
- unsigned gdkKeyCode;
- unsigned state;
- const char* name;
-};
-
-static const KeyCombinationEntry customKeyBindings[] = {
- { GDK_b, GDK_CONTROL_MASK, "ToggleBold" },
- { GDK_i, GDK_CONTROL_MASK, "ToggleItalic" },
- { GDK_Escape, 0, "Cancel" },
- { GDK_greater, GDK_CONTROL_MASK, "Cancel" },
- { GDK_Tab, 0, "InsertTab" },
- { GDK_Tab, GDK_SHIFT_MASK, "InsertBacktab" },
-};
-
-Vector<String> KeyBindingTranslator::commandsForKeyEvent(GdkEventKey* event)
-{
- ASSERT(m_pendingEditorCommands.isEmpty());
-
- // FIXME: Move KeyBindingTranslator to WebKit layer and remove the GTK2 code.
-#ifdef GTK_API_VERSION_2
- gtk_bindings_activate_event(GTK_OBJECT(m_nativeWidget.get()), event);
-#else
- gtk_bindings_activate_event(G_OBJECT(m_nativeWidget.get()), event);
-#endif
-
- if (!m_pendingEditorCommands.isEmpty())
- return WTF::move(m_pendingEditorCommands);
-
- // Special-case enter keys for we want them to work regardless of modifier.
- if ((event->keyval == GDK_Return || event->keyval == GDK_KP_Enter || event->keyval == GDK_ISO_Enter))
- return { "InsertNewLine" };
-
- // For keypress events, we want charCode(), but keyCode() does that.
- unsigned mapKey = event->state << 16 | event->keyval;
- if (!mapKey)
- return { };
-
- for (unsigned i = 0; i < G_N_ELEMENTS(customKeyBindings); ++i) {
- if (mapKey == (customKeyBindings[i].state << 16 | customKeyBindings[i].gdkKeyCode))
- return { customKeyBindings[i].name };
- }
-
- return { };
-}
-
-} // namespace WebCore
Deleted: trunk/Source/WebCore/platform/gtk/KeyBindingTranslator.h (185415 => 185416)
--- trunk/Source/WebCore/platform/gtk/KeyBindingTranslator.h 2015-06-10 13:32:22 UTC (rev 185415)
+++ trunk/Source/WebCore/platform/gtk/KeyBindingTranslator.h 2015-06-10 15:17:53 UTC (rev 185416)
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2010, 2011 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef KeyBindingTranslator_h
-#define KeyBindingTranslator_h
-
-#include "GRefPtrGtk.h"
-#include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
-
-typedef struct _GdkEventKey GdkEventKey;
-
-namespace WebCore {
-
-class KeyBindingTranslator {
-public:
- KeyBindingTranslator();
-
- Vector<String> commandsForKeyEvent(GdkEventKey*);
- void addPendingEditorCommand(const char* command) { m_pendingEditorCommands.append(command); }
-
-private:
- GRefPtr<GtkWidget> m_nativeWidget;
- Vector<String> m_pendingEditorCommands;
-};
-
-} // namespace WebCore
-
-#endif
-
-
Modified: trunk/Source/WebKit2/ChangeLog (185415 => 185416)
--- trunk/Source/WebKit2/ChangeLog 2015-06-10 13:32:22 UTC (rev 185415)
+++ trunk/Source/WebKit2/ChangeLog 2015-06-10 15:17:53 UTC (rev 185416)
@@ -1,5 +1,33 @@
2015-06-10 Carlos Garcia Campos <[email protected]>
+ [GTK] Move KeyBindingTranslator from platform to WebKit2 layer
+ https://bugs.webkit.org/show_bug.cgi?id=145840
+
+ Reviewed by Martin Robinson.
+
+ It's currently used only by WebKit2 in the UI process and it's
+ another file built twice because of the GTK2 plugin process.
+
+ * PlatformGTK.cmake:
+ * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+ * UIProcess/gtk/KeyBindingTranslator.cpp: Renamed from Source/WebCore/platform/gtk/KeyBindingTranslator.cpp.
+ (WebKit::backspaceCallback):
+ (WebKit::selectAllCallback):
+ (WebKit::cutClipboardCallback):
+ (WebKit::copyClipboardCallback):
+ (WebKit::pasteClipboardCallback):
+ (WebKit::toggleOverwriteCallback):
+ (WebKit::popupMenuCallback):
+ (WebKit::showHelpCallback):
+ (WebKit::deleteFromCursorCallback):
+ (WebKit::moveCursorCallback):
+ (WebKit::KeyBindingTranslator::KeyBindingTranslator):
+ (WebKit::KeyBindingTranslator::commandsForKeyEvent):
+ * UIProcess/gtk/KeyBindingTranslator.h: Renamed from Source/WebCore/platform/gtk/KeyBindingTranslator.h.
+ (WebKit::KeyBindingTranslator::addPendingEditorCommand):
+
+2015-06-10 Carlos Garcia Campos <[email protected]>
+
[GTK] Get rid of GetEditorCommandsForKeyEvent sync message
https://bugs.webkit.org/show_bug.cgi?id=145598
Modified: trunk/Source/WebKit2/PlatformGTK.cmake (185415 => 185416)
--- trunk/Source/WebKit2/PlatformGTK.cmake 2015-06-10 13:32:22 UTC (rev 185415)
+++ trunk/Source/WebKit2/PlatformGTK.cmake 2015-06-10 15:17:53 UTC (rev 185416)
@@ -282,6 +282,7 @@
UIProcess/gtk/ExperimentalFeatures.cpp
UIProcess/gtk/GestureController.cpp
UIProcess/gtk/InputMethodFilter.cpp
+ UIProcess/gtk/KeyBindingTranslator.cpp
UIProcess/gtk/RedirectedXCompositeWindow.cpp
UIProcess/gtk/TextCheckerGtk.cpp
UIProcess/gtk/WebColorPickerGtk.cpp
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp (185415 => 185416)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp 2015-06-10 13:32:22 UTC (rev 185415)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp 2015-06-10 15:17:53 UTC (rev 185416)
@@ -31,6 +31,7 @@
#include "DrawingAreaProxyImpl.h"
#include "InputMethodFilter.h"
+#include "KeyBindingTranslator.h"
#include "NativeWebKeyboardEvent.h"
#include "NativeWebMouseEvent.h"
#include "NativeWebWheelEvent.h"
@@ -53,7 +54,6 @@
#include <WebCore/GUniquePtrGtk.h>
#include <WebCore/GtkUtilities.h>
#include <WebCore/GtkVersioning.h>
-#include <WebCore/KeyBindingTranslator.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/PasteboardHelper.h>
#include <WebCore/PlatformDisplay.h>
Copied: trunk/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.cpp (from rev 185415, trunk/Source/WebCore/platform/gtk/KeyBindingTranslator.cpp) (0 => 185416)
--- trunk/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.cpp (rev 0)
+++ trunk/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.cpp 2015-06-10 15:17:53 UTC (rev 185416)
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2010, 2011 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "KeyBindingTranslator.h"
+
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
+
+namespace WebKit {
+
+static void backspaceCallback(GtkWidget* widget, KeyBindingTranslator* translator)
+{
+ g_signal_stop_emission_by_name(widget, "backspace");
+ translator->addPendingEditorCommand("DeleteBackward");
+}
+
+static void selectAllCallback(GtkWidget* widget, gboolean select, KeyBindingTranslator* translator)
+{
+ g_signal_stop_emission_by_name(widget, "select-all");
+ translator->addPendingEditorCommand(select ? "SelectAll" : "Unselect");
+}
+
+static void cutClipboardCallback(GtkWidget* widget, KeyBindingTranslator* translator)
+{
+ g_signal_stop_emission_by_name(widget, "cut-clipboard");
+ translator->addPendingEditorCommand("Cut");
+}
+
+static void copyClipboardCallback(GtkWidget* widget, KeyBindingTranslator* translator)
+{
+ g_signal_stop_emission_by_name(widget, "copy-clipboard");
+ translator->addPendingEditorCommand("Copy");
+}
+
+static void pasteClipboardCallback(GtkWidget* widget, KeyBindingTranslator* translator)
+{
+ g_signal_stop_emission_by_name(widget, "paste-clipboard");
+ translator->addPendingEditorCommand("Paste");
+}
+
+static void toggleOverwriteCallback(GtkWidget* widget, KeyBindingTranslator* translator)
+{
+ g_signal_stop_emission_by_name(widget, "toggle-overwrite");
+ translator->addPendingEditorCommand("OverWrite");
+}
+
+// GTK+ will still send these signals to the web view. So we can safely stop signal
+// emission without breaking accessibility.
+static void popupMenuCallback(GtkWidget* widget, KeyBindingTranslator*)
+{
+ g_signal_stop_emission_by_name(widget, "popup-menu");
+}
+
+static void showHelpCallback(GtkWidget* widget, KeyBindingTranslator*)
+{
+ g_signal_stop_emission_by_name(widget, "show-help");
+}
+
+static const char* const gtkDeleteCommands[][2] = {
+ { "DeleteBackward", "DeleteForward" }, // Characters
+ { "DeleteWordBackward", "DeleteWordForward" }, // Word ends
+ { "DeleteWordBackward", "DeleteWordForward" }, // Words
+ { "DeleteToBeginningOfLine", "DeleteToEndOfLine" }, // Lines
+ { "DeleteToBeginningOfLine", "DeleteToEndOfLine" }, // Line ends
+ { "DeleteToBeginningOfParagraph", "DeleteToEndOfParagraph" }, // Paragraph ends
+ { "DeleteToBeginningOfParagraph", "DeleteToEndOfParagraph" }, // Paragraphs
+ { 0, 0 } // Whitespace (M-\ in Emacs)
+};
+
+static void deleteFromCursorCallback(GtkWidget* widget, GtkDeleteType deleteType, gint count, KeyBindingTranslator* translator)
+{
+ g_signal_stop_emission_by_name(widget, "delete-from-cursor");
+ int direction = count > 0 ? 1 : 0;
+
+ // Ensuring that deleteType <= G_N_ELEMENTS here results in a compiler warning
+ // that the condition is always true.
+
+ if (deleteType == GTK_DELETE_WORDS) {
+ if (!direction) {
+ translator->addPendingEditorCommand("MoveWordForward");
+ translator->addPendingEditorCommand("MoveWordBackward");
+ } else {
+ translator->addPendingEditorCommand("MoveWordBackward");
+ translator->addPendingEditorCommand("MoveWordForward");
+ }
+ } else if (deleteType == GTK_DELETE_DISPLAY_LINES) {
+ if (!direction)
+ translator->addPendingEditorCommand("MoveToBeginningOfLine");
+ else
+ translator->addPendingEditorCommand("MoveToEndOfLine");
+ } else if (deleteType == GTK_DELETE_PARAGRAPHS) {
+ if (!direction)
+ translator->addPendingEditorCommand("MoveToBeginningOfParagraph");
+ else
+ translator->addPendingEditorCommand("MoveToEndOfParagraph");
+ }
+
+ const char* rawCommand = gtkDeleteCommands[deleteType][direction];
+ if (!rawCommand)
+ return;
+
+ for (int i = 0; i < abs(count); i++)
+ translator->addPendingEditorCommand(rawCommand);
+}
+
+static const char* const gtkMoveCommands[][4] = {
+ { "MoveBackward", "MoveForward",
+ "MoveBackwardAndModifySelection", "MoveForwardAndModifySelection" }, // Forward/backward grapheme
+ { "MoveLeft", "MoveRight",
+ "MoveBackwardAndModifySelection", "MoveForwardAndModifySelection" }, // Left/right grapheme
+ { "MoveWordBackward", "MoveWordForward",
+ "MoveWordBackwardAndModifySelection", "MoveWordForwardAndModifySelection" }, // Forward/backward word
+ { "MoveUp", "MoveDown",
+ "MoveUpAndModifySelection", "MoveDownAndModifySelection" }, // Up/down line
+ { "MoveToBeginningOfLine", "MoveToEndOfLine",
+ "MoveToBeginningOfLineAndModifySelection", "MoveToEndOfLineAndModifySelection" }, // Up/down line ends
+ { "MoveParagraphBackward", "MoveParagraphForward",
+ "MoveParagraphBackwardAndModifySelection", "MoveParagraphForwardAndModifySelection" }, // Up/down paragraphs
+ { "MoveToBeginningOfParagraph", "MoveToEndOfParagraph",
+ "MoveToBeginningOfParagraphAndModifySelection", "MoveToEndOfParagraphAndModifySelection" }, // Up/down paragraph ends.
+ { "MovePageUp", "MovePageDown",
+ "MovePageUpAndModifySelection", "MovePageDownAndModifySelection" }, // Up/down page
+ { "MoveToBeginningOfDocument", "MoveToEndOfDocument",
+ "MoveToBeginningOfDocumentAndModifySelection", "MoveToEndOfDocumentAndModifySelection" }, // Begin/end of buffer
+ { 0, 0,
+ 0, 0 } // Horizontal page movement
+};
+
+static void moveCursorCallback(GtkWidget* widget, GtkMovementStep step, gint count, gboolean extendSelection, KeyBindingTranslator* translator)
+{
+ g_signal_stop_emission_by_name(widget, "move-cursor");
+ int direction = count > 0 ? 1 : 0;
+ if (extendSelection)
+ direction += 2;
+
+ if (static_cast<unsigned>(step) >= G_N_ELEMENTS(gtkMoveCommands))
+ return;
+
+ const char* rawCommand = gtkMoveCommands[step][direction];
+ if (!rawCommand)
+ return;
+
+ for (int i = 0; i < abs(count); i++)
+ translator->addPendingEditorCommand(rawCommand);
+}
+
+KeyBindingTranslator::KeyBindingTranslator()
+ : m_nativeWidget(gtk_text_view_new())
+{
+ g_signal_connect(m_nativeWidget.get(), "backspace", G_CALLBACK(backspaceCallback), this);
+ g_signal_connect(m_nativeWidget.get(), "cut-clipboard", G_CALLBACK(cutClipboardCallback), this);
+ g_signal_connect(m_nativeWidget.get(), "copy-clipboard", G_CALLBACK(copyClipboardCallback), this);
+ g_signal_connect(m_nativeWidget.get(), "paste-clipboard", G_CALLBACK(pasteClipboardCallback), this);
+ g_signal_connect(m_nativeWidget.get(), "select-all", G_CALLBACK(selectAllCallback), this);
+ g_signal_connect(m_nativeWidget.get(), "move-cursor", G_CALLBACK(moveCursorCallback), this);
+ g_signal_connect(m_nativeWidget.get(), "delete-from-cursor", G_CALLBACK(deleteFromCursorCallback), this);
+ g_signal_connect(m_nativeWidget.get(), "toggle-overwrite", G_CALLBACK(toggleOverwriteCallback), this);
+ g_signal_connect(m_nativeWidget.get(), "popup-menu", G_CALLBACK(popupMenuCallback), this);
+ g_signal_connect(m_nativeWidget.get(), "show-help", G_CALLBACK(showHelpCallback), this);
+}
+
+struct KeyCombinationEntry {
+ unsigned gdkKeyCode;
+ unsigned state;
+ const char* name;
+};
+
+static const KeyCombinationEntry customKeyBindings[] = {
+ { GDK_KEY_b, GDK_CONTROL_MASK, "ToggleBold" },
+ { GDK_KEY_i, GDK_CONTROL_MASK, "ToggleItalic" },
+ { GDK_KEY_Escape, 0, "Cancel" },
+ { GDK_KEY_greater, GDK_CONTROL_MASK, "Cancel" },
+ { GDK_KEY_Tab, 0, "InsertTab" },
+ { GDK_KEY_Tab, GDK_SHIFT_MASK, "InsertBacktab" },
+};
+
+Vector<String> KeyBindingTranslator::commandsForKeyEvent(GdkEventKey* event)
+{
+ ASSERT(m_pendingEditorCommands.isEmpty());
+
+ gtk_bindings_activate_event(G_OBJECT(m_nativeWidget.get()), event);
+ if (!m_pendingEditorCommands.isEmpty())
+ return WTF::move(m_pendingEditorCommands);
+
+ // Special-case enter keys for we want them to work regardless of modifier.
+ if ((event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter || event->keyval == GDK_KEY_ISO_Enter))
+ return { "InsertNewLine" };
+
+ // For keypress events, we want charCode(), but keyCode() does that.
+ unsigned mapKey = event->state << 16 | event->keyval;
+ if (!mapKey)
+ return { };
+
+ for (unsigned i = 0; i < G_N_ELEMENTS(customKeyBindings); ++i) {
+ if (mapKey == (customKeyBindings[i].state << 16 | customKeyBindings[i].gdkKeyCode))
+ return { customKeyBindings[i].name };
+ }
+
+ return { };
+}
+
+} // namespace WebKit
Copied: trunk/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.h (from rev 185415, trunk/Source/WebCore/platform/gtk/KeyBindingTranslator.h) (0 => 185416)
--- trunk/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/gtk/KeyBindingTranslator.h 2015-06-10 15:17:53 UTC (rev 185416)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2010, 2011 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef KeyBindingTranslator_h
+#define KeyBindingTranslator_h
+
+#include <WebCore/GRefPtrGtk.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+typedef struct _GdkEventKey GdkEventKey;
+
+namespace WebKit {
+
+class KeyBindingTranslator {
+public:
+ KeyBindingTranslator();
+
+ Vector<String> commandsForKeyEvent(GdkEventKey*);
+ void addPendingEditorCommand(const char* command) { m_pendingEditorCommands.append(command); }
+
+private:
+ GRefPtr<GtkWidget> m_nativeWidget;
+ Vector<String> m_pendingEditorCommands;
+};
+
+} // namespace WebKit
+
+#endif
+
+