[GTK] Get rid of GetEditorCommandsForKeyEvent sync message
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Jun 2015 13:32:22 +0000 (13:32 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Jun 2015 13:32:22 +0000 (13:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145598

Reviewed by Žan Doberšek.

Source/WebCore:

* platform/PlatformKeyboardEvent.h:
(WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
(WebCore::PlatformKeyboardEvent::commands):
* platform/gtk/KeyBindingTranslator.cpp: Use a single list of
custom key bindings. We don't need to distinguish between key down and
key press commands, since the web editor client already does that
when executing the commands.
(WebCore::KeyBindingTranslator::commandsForKeyEvent): This is
getEditorCommandsForKeyEvent() renamed as commandsForKeyEvent(),
since it now returns the list of commands to simplify the
code. Also simplify the custom key bindings handling, by using the
global list instead of moving it to a HashMap.
(WebCore::KeyBindingTranslator::getEditorCommandsForKeyEvent): Deleted.
* platform/gtk/KeyBindingTranslator.h:

Source/WebKit2:

We are sending GetEditorCommandsForKeyEvent sync message from web
process to the UI process for every key pressed. And if the
keydown event doesn't handle the key, the message is sent again
for the keypress event, so in many cases it happens twice per
keypress. We can get the list of commands when the key press event
happens in the web view, and send it to the web process as part of
the keyboard event like mac port does. In the web process,
commands not inserting text will be handled by keydown and the
rest in keypress without having to use any other IPC message for that.

* Shared/NativeWebKeyboardEvent.h: Add command list parameter to
the constructor.
* Shared/WebEvent.h: Add GTK specific constructor that receives a
list of commands and whether the event was handled by input methods.
(WebKit::WebKeyboardEvent::commands): Returns the list of commands.
* Shared/WebEventConversion.cpp:
(WebKit::WebKit2PlatformKeyboardEvent::WebKit2PlatformKeyboardEvent):
Also copy the commands and handledByInputMethod member.
* Shared/WebKeyboardEvent.cpp:
(WebKit::WebKeyboardEvent::WebKeyboardEvent): Implement GTK
specific constructor that receives a list of commands and whether
the event was handled by input methods.
(WebKit::WebKeyboardEvent::encode): Encode commands and handledByInputMethod.
(WebKit::WebKeyboardEvent::decode): Decode commands and handledByInputMethod.
* Shared/gtk/NativeWebKeyboardEventGtk.cpp:
(WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent): Add
command list parameter to the constructor.
* Shared/gtk/WebEventFactory.cpp:
(WebKit::WebEventFactory::createWebKeyboardEvent): Use the new
WebKeyboardEvent constructor and simplify the code. We don't need
to explicitly set VK_PROCESSKEY as windows virtual key code when
the event was handled by input methods. The WebCore event handler
already does that.
* Shared/gtk/WebEventFactory.h:
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::getEditorCommandsForKeyEvent): Deleted.
* UIProcess/API/gtk/PageClientImpl.h:
* UIProcess/API/gtk/WebKitWebViewBase.cpp: Add a
KeyBindingTranslator member.
(webkitWebViewBaseKeyPressEvent): Use the new
InputMethodFilter::filterKeyEvent() API and get the list of
commands for the key when events was not handled by input methods.
(webkitWebViewBaseKeyReleaseEvent): Use the new
InputMethodFilter::filterKeyEvent() API.
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.messages.in: Remove GetEditorCommandsForKeyEvent message.
* UIProcess/gtk/InputMethodFilter.cpp:
(WebKit::InputMethodFilter::handleKeyboardEvent): Call the
completation handler.
(WebKit::InputMethodFilter::handleKeyboardEventWithCompositionResults): Ditto.
(WebKit::InputMethodFilter::filterKeyEvent): Use a completion
handler for the task, so that the caller (the web view) can handle
the keyboard event.
* UIProcess/gtk/InputMethodFilter.h:
* UIProcess/gtk/WebPageProxyGtk.cpp:
(WebKit::WebPageProxy::getEditorCommandsForKeyEvent): Deleted.
* WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
(WebKit::WebEditorClient::handleKeyboardEvent): Return earlier if
the event was handled by input methods. And get the list of
commands from the PlatformKeyboardEvent instead of sending a sync
message to the UI process.
(WebKit::WebEditorClient::handleInputMethodKeydown): If the event
was handled by inpout methods, set the event as default handled so
that the WebCore event handler sets VK_PROCESSKEY as windows
virtual key code.
(WebKit::WebEditorClient::getEditorCommandsForKeyEvent): Deleted.

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

21 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/PlatformKeyboardEvent.h
Source/WebCore/platform/gtk/KeyBindingTranslator.cpp
Source/WebCore/platform/gtk/KeyBindingTranslator.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/NativeWebKeyboardEvent.h
Source/WebKit2/Shared/WebEvent.h
Source/WebKit2/Shared/WebEventConversion.cpp
Source/WebKit2/Shared/WebKeyboardEvent.cpp
Source/WebKit2/Shared/gtk/NativeWebKeyboardEventGtk.cpp
Source/WebKit2/Shared/gtk/WebEventFactory.cpp
Source/WebKit2/Shared/gtk/WebEventFactory.h
Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h
Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/gtk/InputMethodFilter.cpp
Source/WebKit2/UIProcess/gtk/InputMethodFilter.h
Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp
Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp

index d6f884e..117b341 100644 (file)
@@ -1,3 +1,25 @@
+2015-06-10  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Get rid of GetEditorCommandsForKeyEvent sync message
+        https://bugs.webkit.org/show_bug.cgi?id=145598
+
+        Reviewed by Žan Doberšek.
+
+        * platform/PlatformKeyboardEvent.h:
+        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
+        (WebCore::PlatformKeyboardEvent::commands):
+        * platform/gtk/KeyBindingTranslator.cpp: Use a single list of
+        custom key bindings. We don't need to distinguish between key down and
+        key press commands, since the web editor client already does that
+        when executing the commands.
+        (WebCore::KeyBindingTranslator::commandsForKeyEvent): This is
+        getEditorCommandsForKeyEvent() renamed as commandsForKeyEvent(),
+        since it now returns the list of commands to simplify the
+        code. Also simplify the custom key bindings handling, by using the
+        global list instead of moving it to a HashMap.
+        (WebCore::KeyBindingTranslator::getEditorCommandsForKeyEvent): Deleted.
+        * platform/gtk/KeyBindingTranslator.h:
+
 2015-06-10  Per Arne Vollan  <peavo@outlook.com>
 
         [WinCairo] Crash on exit when terminating egl
index 4b32a0b..5785266 100644 (file)
@@ -61,7 +61,7 @@ namespace WebCore {
             , m_windowsVirtualKeyCode(0)
             , m_nativeVirtualKeyCode(0)
             , m_macCharCode(0)
-#if USE(APPKIT)
+#if USE(APPKIT) || PLATFORM(GTK)
             , m_handledByInputMethod(false)
 #endif
             , m_autoRepeat(false)
@@ -81,7 +81,7 @@ namespace WebCore {
             , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
             , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
             , m_macCharCode(macCharCode)
-#if USE(APPKIT)
+#if USE(APPKIT) || PLATFORM(GTK)
             , m_handledByInputMethod(false)
 #endif
             , m_autoRepeat(isAutoRepeat)
@@ -115,9 +115,13 @@ namespace WebCore {
         int nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; }
         int macCharCode() const { return m_macCharCode; }
 
-#if USE(APPKIT)
+#if USE(APPKIT) || PLATFORM(GTK)
         bool handledByInputMethod() const { return m_handledByInputMethod; }
+#endif
+#if USE(APPKIT)
         const Vector<KeypressCommand>& commands() const { return m_commands; }
+#elif PLATFORM(GTK)
+        const Vector<String>& commands() const { return m_commands; }
 #endif
 
         bool isAutoRepeat() const { return m_autoRepeat; }
@@ -162,9 +166,13 @@ namespace WebCore {
         int m_windowsVirtualKeyCode;
         int m_nativeVirtualKeyCode;
         int m_macCharCode;
-#if USE(APPKIT)
+#if USE(APPKIT) || PLATFORM(GTK)
         bool m_handledByInputMethod;
+#endif
+#if USE(APPKIT)
         Vector<KeypressCommand> m_commands;
+#elif PLATFORM(GTK)
+        Vector<String> m_commands;
 #endif
         bool m_autoRepeat;
         bool m_isKeypad;
index 7a1c44e..89b1d6e 100644 (file)
@@ -184,61 +184,44 @@ struct KeyCombinationEntry {
     const char* name;
 };
 
-static const KeyCombinationEntry keyDownEntries[] = {
+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"        },
-};
-
-// These commands are text insertion commands, so should take place
-// while handling the KeyPress event.
-static const KeyCombinationEntry keyPressEntries[] = {
     { GDK_Tab,       0,                              "InsertTab"     },
     { GDK_Tab,       GDK_SHIFT_MASK,                 "InsertBacktab" },
 };
 
-void KeyBindingTranslator::getEditorCommandsForKeyEvent(GdkEventKey* event, EventType type, Vector<WTF::String>& commandList)
+Vector<String> KeyBindingTranslator::commandsForKeyEvent(GdkEventKey* event)
 {
-    m_pendingEditorCommands.clear();
+    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()) {
-        commandList.appendVector(m_pendingEditorCommands);
-        return;
-    }
-
-    DEPRECATED_DEFINE_STATIC_LOCAL(IntConstCharHashMap, keyDownCommandsMap, ());
-    DEPRECATED_DEFINE_STATIC_LOCAL(IntConstCharHashMap, keyPressCommandsMap, ());
-
-    if (keyDownCommandsMap.isEmpty()) {
-        for (unsigned i = 0; i < G_N_ELEMENTS(keyDownEntries); i++)
-            keyDownCommandsMap.set(keyDownEntries[i].state << 16 | keyDownEntries[i].gdkKeyCode, keyDownEntries[i].name);
-
-        for (unsigned i = 0; i < G_N_ELEMENTS(keyPressEntries); i++)
-            keyPressCommandsMap.set(keyPressEntries[i].state << 16 | keyPressEntries[i].gdkKeyCode, keyPressEntries[i].name);
-    }
+    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) && type == KeyPress) {
-        commandList.append("InsertNewLine");
-        return;
-    }
+    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.
-    int mapKey = event->state << 16 | event->keyval;
-    if (mapKey) {
-        HashMap<int, const char*>* commandMap = type == KeyDown ?  &keyDownCommandsMap : &keyPressCommandsMap;
-        if (const char* commandString = commandMap->get(mapKey)) {
-            commandList.append(commandString);
-            return;
-        }
+    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
index c6436de..702aaa8 100644 (file)
@@ -31,13 +31,12 @@ class KeyBindingTranslator {
 public:
     KeyBindingTranslator();
 
-    enum EventType { KeyDown, KeyPress };
-    void getEditorCommandsForKeyEvent(GdkEventKey*, EventType, Vector<WTF::String>&);
+    Vector<String> commandsForKeyEvent(GdkEventKey*);
     void addPendingEditorCommand(const char* command) { m_pendingEditorCommands.append(command); }
 
 private:
     GRefPtr<GtkWidget> m_nativeWidget;
-    Vector<WTF::String> m_pendingEditorCommands;
+    Vector<String> m_pendingEditorCommands;
 };
 
 } // namespace WebCore
index 52e8fdb..b558ad0 100644 (file)
@@ -1,5 +1,79 @@
 2015-06-10  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] Get rid of GetEditorCommandsForKeyEvent sync message
+        https://bugs.webkit.org/show_bug.cgi?id=145598
+
+        Reviewed by Žan Doberšek.
+
+        We are sending GetEditorCommandsForKeyEvent sync message from web
+        process to the UI process for every key pressed. And if the
+        keydown event doesn't handle the key, the message is sent again
+        for the keypress event, so in many cases it happens twice per
+        keypress. We can get the list of commands when the key press event
+        happens in the web view, and send it to the web process as part of
+        the keyboard event like mac port does. In the web process,
+        commands not inserting text will be handled by keydown and the
+        rest in keypress without having to use any other IPC message for that.
+
+        * Shared/NativeWebKeyboardEvent.h: Add command list parameter to
+        the constructor.
+        * Shared/WebEvent.h: Add GTK specific constructor that receives a
+        list of commands and whether the event was handled by input methods.
+        (WebKit::WebKeyboardEvent::commands): Returns the list of commands.
+        * Shared/WebEventConversion.cpp:
+        (WebKit::WebKit2PlatformKeyboardEvent::WebKit2PlatformKeyboardEvent):
+        Also copy the commands and handledByInputMethod member.
+        * Shared/WebKeyboardEvent.cpp:
+        (WebKit::WebKeyboardEvent::WebKeyboardEvent): Implement GTK
+        specific constructor that receives a list of commands and whether
+        the event was handled by input methods.
+        (WebKit::WebKeyboardEvent::encode): Encode commands and handledByInputMethod.
+        (WebKit::WebKeyboardEvent::decode): Decode commands and handledByInputMethod.
+        * Shared/gtk/NativeWebKeyboardEventGtk.cpp:
+        (WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent): Add
+        command list parameter to the constructor.
+        * Shared/gtk/WebEventFactory.cpp:
+        (WebKit::WebEventFactory::createWebKeyboardEvent): Use the new
+        WebKeyboardEvent constructor and simplify the code. We don't need
+        to explicitly set VK_PROCESSKEY as windows virtual key code when
+        the event was handled by input methods. The WebCore event handler
+        already does that.
+        * Shared/gtk/WebEventFactory.h:
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::getEditorCommandsForKeyEvent): Deleted.
+        * UIProcess/API/gtk/PageClientImpl.h:
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp: Add a
+        KeyBindingTranslator member.
+        (webkitWebViewBaseKeyPressEvent): Use the new
+        InputMethodFilter::filterKeyEvent() API and get the list of
+        commands for the key when events was not handled by input methods.
+        (webkitWebViewBaseKeyReleaseEvent): Use the new
+        InputMethodFilter::filterKeyEvent() API.
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.messages.in: Remove GetEditorCommandsForKeyEvent message.
+        * UIProcess/gtk/InputMethodFilter.cpp:
+        (WebKit::InputMethodFilter::handleKeyboardEvent): Call the
+        completation handler.
+        (WebKit::InputMethodFilter::handleKeyboardEventWithCompositionResults): Ditto.
+        (WebKit::InputMethodFilter::filterKeyEvent): Use a completion
+        handler for the task, so that the caller (the web view) can handle
+        the keyboard event.
+        * UIProcess/gtk/InputMethodFilter.h:
+        * UIProcess/gtk/WebPageProxyGtk.cpp:
+        (WebKit::WebPageProxy::getEditorCommandsForKeyEvent): Deleted.
+        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
+        (WebKit::WebEditorClient::handleKeyboardEvent): Return earlier if
+        the event was handled by input methods. And get the list of
+        commands from the PlatformKeyboardEvent instead of sending a sync
+        message to the UI process.
+        (WebKit::WebEditorClient::handleInputMethodKeydown): If the event
+        was handled by inpout methods, set the event as default handled so
+        that the WebCore event handler sets VK_PROCESSKEY as windows
+        virtual key code.
+        (WebKit::WebEditorClient::getEditorCommandsForKeyEvent): Deleted.
+
+2015-06-10  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         Unreviewed. Fix GTK build after r185412.
 
         Add missing include.
index 00597d3..23cc74a 100644 (file)
@@ -63,7 +63,7 @@ public:
     NativeWebKeyboardEvent(NSEvent *, bool handledByInputMethod, const Vector<WebCore::KeypressCommand>&);
 #elif PLATFORM(GTK)
     NativeWebKeyboardEvent(const NativeWebKeyboardEvent&);
-    NativeWebKeyboardEvent(GdkEvent*, const WebCore::CompositionResults&, InputMethodFilter::EventFakedForComposition);
+    NativeWebKeyboardEvent(GdkEvent*, const WebCore::CompositionResults&, InputMethodFilter::EventFakedForComposition, Vector<String>&& commands);
 #elif PLATFORM(EFL)
     NativeWebKeyboardEvent(const Evas_Event_Key_Down*, bool);
     NativeWebKeyboardEvent(const Evas_Event_Key_Up*);
index 39637e4..c004714 100644 (file)
@@ -235,6 +235,8 @@ public:
 
 #if USE(APPKIT)
     WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool handledByInputMethod, const Vector<WebCore::KeypressCommand>&, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers, double timestamp);
+#elif PLATFORM(GTK)
+    WebKeyboardEvent(Type, const String& text, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool handledByInputMethod, Vector<String>&& commands, bool isKeypad, Modifiers, double timestamp);
 #else
     WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers, double timestamp);
 #endif
@@ -245,9 +247,13 @@ public:
     int32_t windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; }
     int32_t nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; }
     int32_t macCharCode() const { return m_macCharCode; }
-#if USE(APPKIT)
+#if USE(APPKIT) || PLATFORM(GTK)
     bool handledByInputMethod() const { return m_handledByInputMethod; }
+#endif
+#if USE(APPKIT)
     const Vector<WebCore::KeypressCommand>& commands() const { return m_commands; }
+#elif PLATFORM(GTK)
+    const Vector<String>& commands() const { return m_commands; }
 #endif
     bool isAutoRepeat() const { return m_isAutoRepeat; }
     bool isKeypad() const { return m_isKeypad; }
@@ -265,9 +271,13 @@ private:
     int32_t m_windowsVirtualKeyCode;
     int32_t m_nativeVirtualKeyCode;
     int32_t m_macCharCode;
-#if USE(APPKIT)
+#if USE(APPKIT) || PLATFORM(GTK)
     bool m_handledByInputMethod;
+#endif
+#if USE(APPKIT)
     Vector<WebCore::KeypressCommand> m_commands;
+#elif PLATFORM(GTK)
+    Vector<String> m_commands;
 #endif
     bool m_isAutoRepeat;
     bool m_isKeypad;
index 60a0be9..451dec6 100644 (file)
@@ -204,7 +204,7 @@ public:
         m_windowsVirtualKeyCode = webEvent.windowsVirtualKeyCode();
         m_nativeVirtualKeyCode = webEvent.nativeVirtualKeyCode();
         m_macCharCode = webEvent.macCharCode();
-#if USE(APPKIT)
+#if USE(APPKIT) || PLATFORM(GTK)
         m_handledByInputMethod = webEvent.handledByInputMethod();
         m_commands = webEvent.commands();
 #endif
index 0ac67e3..80de50b 100644 (file)
@@ -54,6 +54,25 @@ WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String&
     ASSERT(isKeyboardEventType(type));
 }
 
+#elif PLATFORM(GTK)
+
+WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool handledByInputMethod, Vector<String>&& commands, bool isKeypad, Modifiers modifiers, double timestamp)
+    : WebEvent(type, modifiers, timestamp)
+    , m_text(text)
+    , m_unmodifiedText(text)
+    , m_keyIdentifier(keyIdentifier)
+    , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
+    , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
+    , m_macCharCode(0)
+    , m_handledByInputMethod(handledByInputMethod)
+    , m_commands(WTF::move(commands))
+    , m_isAutoRepeat(false)
+    , m_isKeypad(isKeypad)
+    , m_isSystemKey(false)
+{
+    ASSERT(isKeyboardEventType(type));
+}
+
 #else
 
 WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers modifiers, double timestamp)
@@ -87,7 +106,7 @@ void WebKeyboardEvent::encode(IPC::ArgumentEncoder& encoder) const
     encoder << m_windowsVirtualKeyCode;
     encoder << m_nativeVirtualKeyCode;
     encoder << m_macCharCode;
-#if USE(APPKIT)
+#if USE(APPKIT) || PLATFORM(GTK)
     encoder << m_handledByInputMethod;
     encoder << m_commands;
 #endif
@@ -113,7 +132,7 @@ bool WebKeyboardEvent::decode(IPC::ArgumentDecoder& decoder, WebKeyboardEvent& r
         return false;
     if (!decoder.decode(result.m_macCharCode))
         return false;
-#if USE(APPKIT)
+#if USE(APPKIT) || PLATFORM(GTK)
     if (!decoder.decode(result.m_handledByInputMethod))
         return false;
     if (!decoder.decode(result.m_commands))
index 7fdacd2..b8ed211 100644 (file)
@@ -35,8 +35,8 @@ using namespace WebCore;
 
 namespace WebKit {
 
-NativeWebKeyboardEvent::NativeWebKeyboardEvent(GdkEvent* event, const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked)
-    : WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(event, compositionResults))
+NativeWebKeyboardEvent::NativeWebKeyboardEvent(GdkEvent* event, const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked, Vector<String>&& commands)
+    : WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(event, compositionResults, WTF::move(commands)))
     , m_nativeEvent(gdk_event_copy(event))
     , m_compositionResults(compositionResults)
     , m_fakeEventForComposition(faked == InputMethodFilter::EventFaked)
@@ -44,7 +44,7 @@ NativeWebKeyboardEvent::NativeWebKeyboardEvent(GdkEvent* event, const WebCore::C
 }
 
 NativeWebKeyboardEvent::NativeWebKeyboardEvent(const NativeWebKeyboardEvent& event)
-    : WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(event.nativeEvent(), event.compositionResults()))
+    : WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(event.nativeEvent(), event.compositionResults(), Vector<String>(event.commands())))
     , m_nativeEvent(gdk_event_copy(event.nativeEvent()))
     , m_compositionResults(event.compositionResults())
     , m_fakeEventForComposition(event.isFakeEventForComposition())
index 55992d4..8699b5e 100644 (file)
@@ -181,27 +181,19 @@ WebWheelEvent WebEventFactory::createWebWheelEvent(const GdkEvent* event)
                          gdk_event_get_time(event));
 }
 
-WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(const GdkEvent* event, const WebCore::CompositionResults& compositionResults)
+WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(const GdkEvent* event, const WebCore::CompositionResults& compositionResults, Vector<String>&& commands)
 {
-    unsigned int keyValue = event->key.keyval;
-    String text = compositionResults.simpleString.length() ?
-         compositionResults.simpleString : PlatformKeyboardEvent::singleCharacterString(keyValue);
-
-    int windowsVirtualKeyCode = compositionResults.compositionUpdated() ?
-         VK_PROCESSKEY : PlatformKeyboardEvent::windowsKeyCodeForGdkKeyCode(event->key.keyval);
-
-    return WebKeyboardEvent((event->type == GDK_KEY_RELEASE) ? WebEvent::KeyUp : WebEvent::KeyDown,
-                            text,
-                            text,
-                            PlatformKeyboardEvent::keyIdentifierForGdkKeyCode(keyValue),
-                            windowsVirtualKeyCode,
-                            static_cast<int>(keyValue),
-                            0 /* macCharCode */,
-                            false /* isAutoRepeat */,
-                            isGdkKeyCodeFromKeyPad(keyValue),
-                            false /* isSystemKey */,
-                            modifiersForEvent(event),
-                            gdk_event_get_time(event));
+    return WebKeyboardEvent(
+        event->type == GDK_KEY_RELEASE ? WebEvent::KeyUp : WebEvent::KeyDown,
+        compositionResults.simpleString.length() ? compositionResults.simpleString : PlatformKeyboardEvent::singleCharacterString(event->key.keyval),
+        PlatformKeyboardEvent::keyIdentifierForGdkKeyCode(event->key.keyval),
+        PlatformKeyboardEvent::windowsKeyCodeForGdkKeyCode(event->key.keyval),
+        static_cast<int>(event->key.keyval),
+        compositionResults.compositionUpdated(),
+        WTF::move(commands),
+        isGdkKeyCodeFromKeyPad(event->key.keyval),
+        modifiersForEvent(event),
+        gdk_event_get_time(event));
 }
 
 WebTouchEvent WebEventFactory::createWebTouchEvent(const GdkEvent* event, Vector<WebPlatformTouchPoint>&& touchPoints)
index 2511b5d..2909209 100644 (file)
@@ -38,7 +38,7 @@ class WebEventFactory {
 public:
     static WebMouseEvent createWebMouseEvent(const GdkEvent*, int);
     static WebWheelEvent createWebWheelEvent(const GdkEvent*);
-    static WebKeyboardEvent createWebKeyboardEvent(const GdkEvent*, const WebCore::CompositionResults&);
+    static WebKeyboardEvent createWebKeyboardEvent(const GdkEvent*, const WebCore::CompositionResults&, Vector<String>&& commands);
     static WebTouchEvent createWebTouchEvent(const GdkEvent*, Vector<WebPlatformTouchPoint>&&);
 };
 
index b31d8ab..33cece6 100644 (file)
@@ -56,15 +56,6 @@ PageClientImpl::PageClientImpl(GtkWidget* viewWidget)
 {
 }
 
-void PageClientImpl::getEditorCommandsForKeyEvent(const NativeWebKeyboardEvent& event, const AtomicString& eventType, Vector<WTF::String>& commandList)
-{
-    ASSERT(eventType == eventNames().keydownEvent || eventType == eventNames().keypressEvent);
-
-    KeyBindingTranslator::EventType type = eventType == eventNames().keydownEvent ?
-        KeyBindingTranslator::KeyDown : KeyBindingTranslator::KeyPress;
-    m_keyBindingTranslator.getEditorCommandsForKeyEvent(const_cast<GdkEventKey*>(&event.nativeEvent()->key), type, commandList);
-}
-
 // PageClient's pure virtual functions
 std::unique_ptr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy()
 {
index 5c2c27a..2adb966 100644 (file)
 #define PageClientImpl_h
 
 #include "DefaultUndoController.h"
-#include "KeyBindingTranslator.h"
 #include "PageClient.h"
 #include "WebFullScreenManagerProxy.h"
 #include "WebPageProxy.h"
-#include "WindowsKeyboardCodes.h"
 #include <WebCore/IntSize.h>
 #include <gtk/gtk.h>
 #include <memory>
@@ -91,7 +89,6 @@ private:
     virtual void setTextIndicator(Ref<WebCore::TextIndicator>, WebCore::TextIndicatorLifetime = WebCore::TextIndicatorLifetime::Permanent) override;
     virtual void clearTextIndicator(WebCore::TextIndicatorDismissalAnimation = WebCore::TextIndicatorDismissalAnimation::FadeOut) override;
     virtual void setTextIndicatorAnimationProgress(float) override;
-    virtual void getEditorCommandsForKeyEvent(const NativeWebKeyboardEvent&, const AtomicString&, Vector<WTF::String>&) override;
     virtual void updateTextInputState() override;
 #if ENABLE(DRAG_SUPPORT)
     virtual void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage) override;
@@ -138,7 +135,6 @@ private:
     // Members of PageClientImpl class
     GtkWidget* m_viewWidget;
     DefaultUndoController m_undoController;
-    WebCore::KeyBindingTranslator m_keyBindingTranslator;
 };
 
 } // namespace WebKit
index 1d7301f..d710a41 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "DrawingAreaProxyImpl.h"
 #include "InputMethodFilter.h"
+#include "NativeWebKeyboardEvent.h"
 #include "NativeWebMouseEvent.h"
 #include "NativeWebWheelEvent.h"
 #include "PageClientImpl.h"
@@ -52,6 +53,7 @@
 #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>
@@ -163,6 +165,7 @@ struct _WebKitWebViewBasePrivate {
     GUniquePtr<GdkEvent> contextMenuEvent;
     WebContextMenuProxyGtk* activeContextMenuProxy;
     InputMethodFilter inputMethodFilter;
+    KeyBindingTranslator keyBindingTranslator;
     TouchEventsMap touchEvents;
 
     GtkWindow* toplevelOnScreenWindow;
@@ -749,7 +752,12 @@ static gboolean webkitWebViewBaseKeyPressEvent(GtkWidget* widget, GdkEventKey* e
         priv->shouldForwardNextKeyEvent = FALSE;
         return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_press_event(widget, event);
     }
-    priv->inputMethodFilter.filterKeyEvent(event);
+
+    priv->inputMethodFilter.filterKeyEvent(event, [priv, event](const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked) {
+        priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), compositionResults, faked,
+            !compositionResults.compositionUpdated() ? priv->keyBindingTranslator.commandsForKeyEvent(event) : Vector<String>()));
+    });
+
     return TRUE;
 }
 
@@ -762,7 +770,11 @@ static gboolean webkitWebViewBaseKeyReleaseEvent(GtkWidget* widget, GdkEventKey*
         priv->shouldForwardNextKeyEvent = FALSE;
         return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_release_event(widget, event);
     }
-    priv->inputMethodFilter.filterKeyEvent(event);
+
+    priv->inputMethodFilter.filterKeyEvent(event, [priv, event](const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked) {
+        priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), compositionResults, faked, { }));
+    });
+
     return TRUE;
 }
 
index 60ef7b2..de24d30 100644 (file)
@@ -196,9 +196,6 @@ public:
 #endif
 #endif
 
-#if PLATFORM(GTK)
-    virtual void getEditorCommandsForKeyEvent(const NativeWebKeyboardEvent&, const AtomicString&, Vector<WTF::String>&) = 0;
-#endif
     virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&) = 0;
     virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&) = 0;
     virtual WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) = 0;
index a85c2d6..9db9755 100644 (file)
@@ -204,9 +204,6 @@ messages -> WebPageProxy {
     PluginZoomFactorDidChange(double zoomFactor)
 
 #if PLATFORM(GTK)
-    # Support for GTK+ platform keybindings
-    GetEditorCommandsForKeyEvent(AtomicString eventType) -> (Vector<String> commandsList)
-
     # Support for connecting the Accessibility worlds of the UI and the Web processes
     BindAccessibilityTree(String plugID)
 
index 696b864..0489255 100644 (file)
@@ -20,7 +20,6 @@
 #include "config.h"
 #include "InputMethodFilter.h"
 
-#include "NativeWebKeyboardEvent.h"
 #include "WebPageProxy.h"
 #include <WebCore/Color.h>
 #include <WebCore/CompositionResults.h>
@@ -122,7 +121,10 @@ void InputMethodFilter::handleKeyboardEvent(GdkEventKey* event, const String& si
         return;
     }
 #endif
-    m_page->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), CompositionResults(simpleString), faked));
+
+    ASSERT(m_filterKeyEventCompletionHandler);
+    m_filterKeyEventCompletionHandler(CompositionResults(simpleString), faked);
+    m_filterKeyEventCompletionHandler = nullptr;
 }
 
 void InputMethodFilter::handleKeyboardEventWithCompositionResults(GdkEventKey* event, ResultsToSend resultsToSend, EventFakedForComposition faked)
@@ -133,7 +135,10 @@ void InputMethodFilter::handleKeyboardEventWithCompositionResults(GdkEventKey* e
         return;
     }
 #endif
-    m_page->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), CompositionResults(CompositionResults::WillSendCompositionResultsSoon), faked));
+
+    ASSERT(m_filterKeyEventCompletionHandler);
+    m_filterKeyEventCompletionHandler(CompositionResults(CompositionResults::WillSendCompositionResultsSoon), faked);
+    m_filterKeyEventCompletionHandler = nullptr;
 
     if (resultsToSend & Composition && !m_confirmedComposition.isNull())
         m_page->confirmComposition(m_confirmedComposition, -1, 0);
@@ -144,13 +149,14 @@ void InputMethodFilter::handleKeyboardEventWithCompositionResults(GdkEventKey* e
     }
 }
 
-void InputMethodFilter::filterKeyEvent(GdkEventKey* event)
+void InputMethodFilter::filterKeyEvent(GdkEventKey* event, FilterKeyEventCompletionHandler&& completionHandler)
 {
 #if ENABLE(API_TESTS)
     ASSERT(m_page || m_testingMode);
 #else
     ASSERT(m_page);
 #endif
+    m_filterKeyEventCompletionHandler = WTF::move(completionHandler);
     if (!m_enabled) {
         handleKeyboardEvent(event);
         return;
index 37de83e..5c5433d 100644 (file)
@@ -29,6 +29,7 @@ typedef struct _GdkEventKey GdkEventKey;
 typedef struct _GtkIMContext GtkIMContext;
 
 namespace WebCore {
+class CompositionResults;
 class IntRect;
 }
 
@@ -54,7 +55,8 @@ public:
     void setEnabled(bool);
     void setCursorRect(const WebCore::IntRect&);
 
-    void filterKeyEvent(GdkEventKey*);
+    using FilterKeyEventCompletionHandler = std::function<void (const WebCore::CompositionResults&, InputMethodFilter::EventFakedForComposition)>;
+    void filterKeyEvent(GdkEventKey*, FilterKeyEventCompletionHandler&& = nullptr);
     void notifyFocusedIn();
     void notifyFocusedOut();
     void notifyMouseButtonPress();
@@ -111,6 +113,8 @@ private:
     String m_confirmedComposition;
     String m_preedit;
 
+    FilterKeyEventCompletionHandler m_filterKeyEventCompletionHandler;
+
 #if ENABLE(API_TESTS)
     bool m_testingMode;
     Vector<String> m_events;
index 4328070..d1b82d2 100644 (file)
@@ -27,7 +27,6 @@
 #include "config.h"
 #include "WebPageProxy.h"
 
-#include "NativeWebKeyboardEvent.h"
 #include "NotImplemented.h"
 #include "PageClientImpl.h"
 #include "WebKitWebViewBasePrivate.h"
@@ -53,14 +52,6 @@ String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent
     return WebCore::standardUserAgent(applicationNameForUserAgent);
 }
 
-void WebPageProxy::getEditorCommandsForKeyEvent(const AtomicString& eventType, Vector<WTF::String>& commandsList)
-{
-    // When the keyboard event is started in the WebProcess side (e.g. from the Inspector)
-    // it will arrive without a GdkEvent associated, so the keyEventQueue will be empty.
-    if (!m_keyEventQueue.isEmpty())
-        m_pageClient.getEditorCommandsForKeyEvent(m_keyEventQueue.first(), eventType, commandsList);
-}
-
 void WebPageProxy::bindAccessibilityTree(const String& plugID)
 {
     m_accessibilityPlugID = plugID;
index 769d78c..2b02e44 100644 (file)
 #include "WebEditorClient.h"
 
 #include "PlatformKeyboardEvent.h"
-#include "WebPage.h"
-#include "WebPageProxyMessages.h"
-#include "WebProcess.h"
 #include <WebCore/DataObjectGtk.h>
 #include <WebCore/Document.h>
+#include <WebCore/Editor.h>
 #include <WebCore/Frame.h>
 #include <WebCore/FrameDestructionObserver.h>
 #include <WebCore/KeyboardEvent.h>
 #include <WebCore/Pasteboard.h>
-#include <WebCore/WindowsKeyboardCodes.h>
 #include <WebCore/markup.h>
 #include <wtf/gobject/GRefPtr.h>
 
@@ -38,17 +35,6 @@ using namespace WebCore;
 
 namespace WebKit {
 
-void WebEditorClient::getEditorCommandsForKeyEvent(const KeyboardEvent* event, Vector<WTF::String>& pendingEditorCommands)
-{
-    ASSERT(event->type() == eventNames().keydownEvent || event->type() == eventNames().keypressEvent);
-
-    /* First try to interpret the command in the UI and get the commands.
-       UI needs to receive event type because only knows current NativeWebKeyboardEvent.*/
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::GetEditorCommandsForKeyEvent(event->type()),
-                                                Messages::WebPageProxy::GetEditorCommandsForKeyEvent::Reply(pendingEditorCommands),
-                                                m_page->pageID(), std::chrono::milliseconds::max());
-}
-
 bool WebEditorClient::executePendingEditorCommands(Frame* frame, const Vector<WTF::String>& pendingEditorCommands, bool allowTextInsertion)
 {
     Vector<Editor::Command> commands;
@@ -70,21 +56,20 @@ bool WebEditorClient::executePendingEditorCommands(Frame* frame, const Vector<WT
 
 void WebEditorClient::handleKeyboardEvent(KeyboardEvent* event)
 {
-    Node* node = event->target()->toNode();
-    ASSERT(node);
-    Frame* frame = node->document().frame();
-    ASSERT(frame);
-
     const PlatformKeyboardEvent* platformEvent = event->keyEvent();
     if (!platformEvent)
         return;
 
     // If this was an IME event don't do anything.
-    if (platformEvent->windowsVirtualKeyCode() == VK_PROCESSKEY)
+    if (platformEvent->handledByInputMethod())
         return;
 
-    Vector<WTF::String> pendingEditorCommands;
-    getEditorCommandsForKeyEvent(event, pendingEditorCommands);
+    Node* node = event->target()->toNode();
+    ASSERT(node);
+    Frame* frame = node->document().frame();
+    ASSERT(frame);
+
+    const Vector<String> pendingEditorCommands = platformEvent->commands();
     if (!pendingEditorCommands.isEmpty()) {
 
         // During RawKeyDown events if an editor command will insert text, defer
@@ -129,8 +114,8 @@ void WebEditorClient::handleKeyboardEvent(KeyboardEvent* event)
 void WebEditorClient::handleInputMethodKeydown(KeyboardEvent* event)
 {
     const PlatformKeyboardEvent* platformEvent = event->keyEvent();
-    if (platformEvent && platformEvent->windowsVirtualKeyCode() == VK_PROCESSKEY)
-        event->preventDefault();
+    if (platformEvent && platformEvent->handledByInputMethod())
+        event->setDefaultHandled();
 }
 
 #if PLATFORM(X11)