[GTK] Simplify the Input Method implementation
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Oct 2019 09:24:57 +0000 (09:24 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Oct 2019 09:24:57 +0000 (09:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=203149

Reviewed by Adrian Perez de Castro.

Source/WebCore:

Remove CompositionResults and remove dead code in PlatformKeyboardEventGtk.

* PlatformGTK.cmake:
* platform/PlatformKeyboardEvent.h:
(WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
* platform/gtk/CompositionResults.h: Removed.
* platform/gtk/PlatformKeyboardEventGtk.cpp:
(WebCore::PlatformKeyboardEvent::disambiguateKeyDownEvent):

Source/WebKit:

* Shared/NativeWebKeyboardEvent.h: Stop using WebCore::CompositionResults.
(WebKit::NativeWebKeyboardEvent::text const):
(WebKit::NativeWebKeyboardEvent::handledByInputMethod const):
(WebKit::NativeWebKeyboardEvent::fakedForComposition const):
* Shared/gtk/NativeWebKeyboardEventGtk.cpp: Ditto.
(WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent):
* Shared/gtk/WebEventFactory.cpp:
(WebKit::WebEventFactory::createWebKeyboardEvent): Ditto.
* Shared/gtk/WebEventFactory.h:
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::doneWithKeyEvent): Updated to use the new name.
* UIProcess/API/gtk/WebKitWebViewBase.cpp: Stop using WebCore::CompositionResults.
(webkitWebViewBaseKeyPressEvent):
(webkitWebViewBaseKeyReleaseEvent):
* UIProcess/API/gtk/WebKitWebViewBasePrivate.h: Remove unused function.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setComposition): Use EditingRange instead of two integers and remove replacement range
that is unused.
(WebKit::WebPageProxy::confirmComposition): Remove unused selection range parameters.
* UIProcess/WebPageProxy.h:
* UIProcess/gtk/InputMethodFilter.cpp:
(WebKit::InputMethodFilter::handleKeyboardEvent):
(WebKit::InputMethodFilter::handleKeyboardEventWithCompositionResults):
(WebKit::InputMethodFilter::confirmComposition):
(WebKit::InputMethodFilter::updatePreedit):
(WebKit::InputMethodFilter::confirmCurrentComposition):
(WebKit::InputMethodFilter::sendCompositionAndPreeditWithFakeKeyEvents):
(WebKit::InputMethodFilter::logHandleKeyboardEventForTesting):
(WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting):
* UIProcess/gtk/InputMethodFilter.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::targetFrameForEditing): Receive a reference instead of a pointer.
(WebKit::WebPage::confirmComposition): Remove the unused code to handle the selection range.
(WebKit::WebPage::setComposition): Remove the unused code to handle the replacement range.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

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

20 files changed:
Source/WebCore/ChangeLog
Source/WebCore/PlatformGTK.cmake
Source/WebCore/platform/PlatformKeyboardEvent.h
Source/WebCore/platform/gtk/CompositionResults.h [deleted file]
Source/WebCore/platform/gtk/PlatformKeyboardEventGtk.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/NativeWebKeyboardEvent.h
Source/WebKit/Shared/gtk/NativeWebKeyboardEventGtk.cpp
Source/WebKit/Shared/gtk/WebEventFactory.cpp
Source/WebKit/Shared/gtk/WebEventFactory.h
Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/gtk/InputMethodFilter.cpp
Source/WebKit/UIProcess/gtk/InputMethodFilter.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in

index d917b76..b57a58c 100644 (file)
@@ -1,3 +1,19 @@
+2019-10-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Simplify the Input Method implementation
+        https://bugs.webkit.org/show_bug.cgi?id=203149
+
+        Reviewed by Adrian Perez de Castro.
+
+        Remove CompositionResults and remove dead code in PlatformKeyboardEventGtk.
+
+        * PlatformGTK.cmake:
+        * platform/PlatformKeyboardEvent.h:
+        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
+        * platform/gtk/CompositionResults.h: Removed.
+        * platform/gtk/PlatformKeyboardEventGtk.cpp:
+        (WebCore::PlatformKeyboardEvent::disambiguateKeyDownEvent):
+
 2019-10-27  Antoine Quint  <graouts@apple.com>
 
         [Web Animations] getKeyframes() doesn't return the right timing function for declarative animations
index 2f0da5b..787f49c 100644 (file)
@@ -48,7 +48,6 @@ list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
     platform/graphics/x11/XUniquePtr.h
     platform/graphics/x11/XUniqueResource.h
 
-    platform/gtk/CompositionResults.h
     platform/gtk/GRefPtrGtk.h
     platform/gtk/GUniquePtrGtk.h
     platform/gtk/GtkUtilities.h
index 1a386cc..4aaf5bd 100644 (file)
@@ -40,11 +40,6 @@ OBJC_CLASS NSEvent;
 OBJC_CLASS WebEvent;
 #endif
 
-#if PLATFORM(GTK)
-typedef struct _GdkEventKey GdkEventKey;
-#include "CompositionResults.h"
-#endif
-
 namespace WebCore {
 
     class PlatformKeyboardEvent : public PlatformEvent {
@@ -56,9 +51,6 @@ namespace WebCore {
             , m_autoRepeat(false)
             , m_isKeypad(false)
             , m_isSystemKey(false)
-#if PLATFORM(GTK)
-            , m_gdkEventKey(0)
-#endif
         {
         }
 
@@ -150,10 +142,6 @@ namespace WebCore {
 #endif
 
 #if PLATFORM(GTK)
-        PlatformKeyboardEvent(GdkEventKey*, const CompositionResults&);
-        GdkEventKey* gdkEventKey() const { return m_gdkEventKey; }
-        const CompositionResults& compositionResults() const { return m_compositionResults; }
-
         // Used by WebKit2
         static String keyValueForGdkKeyCode(unsigned);
         static String keyCodeForHardwareKeyCode(unsigned);
@@ -203,11 +191,6 @@ namespace WebCore {
         RetainPtr<::WebEvent> m_Event;
 #endif
 #endif
-#if PLATFORM(GTK)
-        GdkEventKey* m_gdkEventKey;
-        CompositionResults m_compositionResults;
-#endif
-        
         // The modifier state is optional, since it is not needed in the UI process or in legacy WebKit.
         static Optional<OptionSet<Modifier>> s_currentModifiers;
     };
diff --git a/Source/WebCore/platform/gtk/CompositionResults.h b/Source/WebCore/platform/gtk/CompositionResults.h
deleted file mode 100644 (file)
index e436cc3..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2012 Igalia S.L.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#ifndef CompositionResults_h
-#define CompositionResults_h
-
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-
-struct CompositionResults {
-    CompositionResults()
-        : associatedWithPendingCompositionUpdate(false)
-    {
-    }
-
-    CompositionResults(String simpleString)
-        : simpleString(simpleString)
-        , associatedWithPendingCompositionUpdate(false)
-    {
-    }
-
-    enum ResultsIndicator { WillSendCompositionResultsSoon };
-    CompositionResults(ResultsIndicator)
-        : associatedWithPendingCompositionUpdate(true)
-    {
-    }
-
-    bool compositionUpdated() const
-    {
-        return associatedWithPendingCompositionUpdate;
-    }
-
-    // Some simple input methods return a string for all keyboard events. This
-    // value should be treated as the string representation of the keycode.
-    String simpleString;
-
-    bool associatedWithPendingCompositionUpdate;
-};
-
-}
-
-#endif // CompositionResults_h
index 5c52dfd..356b09f 100644 (file)
@@ -1321,59 +1321,6 @@ String PlatformKeyboardEvent::singleCharacterString(unsigned val)
     }
 }
 
-static PlatformEvent::Type eventTypeForGdkKeyEvent(GdkEventKey* event)
-{
-    return gdk_event_get_event_type(reinterpret_cast<GdkEvent*>(event)) == GDK_KEY_RELEASE ? PlatformEvent::KeyUp : PlatformEvent::KeyDown;
-}
-
-static OptionSet<PlatformEvent::Modifier> modifiersForGdkKeyEvent(GdkEventKey* event)
-{
-    GdkModifierType state;
-    gdk_event_get_state(reinterpret_cast<GdkEvent*>(event), &state);
-    guint keyval;
-    gdk_event_get_keyval(reinterpret_cast<GdkEvent*>(event), &keyval);
-
-    OptionSet<PlatformEvent::Modifier> modifiers;
-    if (state & GDK_SHIFT_MASK || keyval == GDK_KEY_3270_BackTab)
-        modifiers.add(PlatformEvent::Modifier::ShiftKey);
-    if (state & GDK_CONTROL_MASK)
-        modifiers.add(PlatformEvent::Modifier::ControlKey);
-    if (state & GDK_MOD1_MASK)
-        modifiers.add(PlatformEvent::Modifier::AltKey);
-    if (state & GDK_META_MASK)
-        modifiers.add(PlatformEvent::Modifier::MetaKey);
-    if (state & GDK_LOCK_MASK)
-        modifiers.add(PlatformEvent::Modifier::CapsLockKey);
-    return modifiers;
-}
-
-// Keep this in sync with the other platform event constructors
-PlatformKeyboardEvent::PlatformKeyboardEvent(GdkEventKey* event, const CompositionResults& compositionResults)
-    : PlatformEvent(eventTypeForGdkKeyEvent(event), modifiersForGdkKeyEvent(event), wallTimeForEvent(event))
-    , m_handledByInputMethod(false)
-    , m_autoRepeat(false)
-    , m_isSystemKey(false)
-    , m_gdkEventKey(event)
-    , m_compositionResults(compositionResults)
-{
-    guint keyval;
-    gdk_event_get_keyval(reinterpret_cast<GdkEvent*>(event), &keyval);
-    guint16 keycode;
-    gdk_event_get_keycode(reinterpret_cast<GdkEvent*>(event), &keycode);
-
-    m_text = compositionResults.simpleString.length() ? compositionResults.simpleString : singleCharacterString(keyval);
-    m_unmodifiedText = m_text;
-    m_key = keyValueForGdkKeyCode(keyval);
-    m_code = keyCodeForHardwareKeyCode(keycode);
-    m_keyIdentifier = keyIdentifierForGdkKeyCode(keyval);
-    m_windowsVirtualKeyCode = windowsKeyCodeForGdkKeyCode(keyval);
-    m_isKeypad = keyval >= GDK_KEY_KP_Space && keyval <= GDK_KEY_KP_9;
-
-    // To match the behavior of IE, we return VK_PROCESSKEY for keys that triggered composition results.
-    if (compositionResults.compositionUpdated())
-        m_windowsVirtualKeyCode = VK_PROCESSKEY;
-}
-
 void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type, bool backwardCompatibilityMode)
 {
     // Can only change type from KeyDown to RawKeyDown or Char, as we lack information for other conversions.
@@ -1386,7 +1333,7 @@ void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type, bool backwardCom
     if (type == PlatformEvent::RawKeyDown) {
         m_text = String();
         m_unmodifiedText = String();
-    } else if (type == PlatformEvent::Char && m_compositionResults.compositionUpdated()) {
+    } else if (type == PlatformEvent::Char && m_handledByInputMethod) {
         // Having empty text, prevents this Char (which is a DOM keypress) event
         // from going to the DOM. Keys that trigger composition events should not
         // fire keypress.
index 8745fdf..c77584c 100644 (file)
@@ -1,3 +1,47 @@
+2019-10-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Simplify the Input Method implementation
+        https://bugs.webkit.org/show_bug.cgi?id=203149
+
+        Reviewed by Adrian Perez de Castro.
+
+        * Shared/NativeWebKeyboardEvent.h: Stop using WebCore::CompositionResults.
+        (WebKit::NativeWebKeyboardEvent::text const):
+        (WebKit::NativeWebKeyboardEvent::handledByInputMethod const):
+        (WebKit::NativeWebKeyboardEvent::fakedForComposition const):
+        * Shared/gtk/NativeWebKeyboardEventGtk.cpp: Ditto.
+        (WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent):
+        * Shared/gtk/WebEventFactory.cpp:
+        (WebKit::WebEventFactory::createWebKeyboardEvent): Ditto.
+        * Shared/gtk/WebEventFactory.h:
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::doneWithKeyEvent): Updated to use the new name.
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp: Stop using WebCore::CompositionResults.
+        (webkitWebViewBaseKeyPressEvent):
+        (webkitWebViewBaseKeyReleaseEvent):
+        * UIProcess/API/gtk/WebKitWebViewBasePrivate.h: Remove unused function.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::setComposition): Use EditingRange instead of two integers and remove replacement range
+        that is unused.
+        (WebKit::WebPageProxy::confirmComposition): Remove unused selection range parameters.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/gtk/InputMethodFilter.cpp:
+        (WebKit::InputMethodFilter::handleKeyboardEvent):
+        (WebKit::InputMethodFilter::handleKeyboardEventWithCompositionResults):
+        (WebKit::InputMethodFilter::confirmComposition):
+        (WebKit::InputMethodFilter::updatePreedit):
+        (WebKit::InputMethodFilter::confirmCurrentComposition):
+        (WebKit::InputMethodFilter::sendCompositionAndPreeditWithFakeKeyEvents):
+        (WebKit::InputMethodFilter::logHandleKeyboardEventForTesting):
+        (WebKit::InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting):
+        * UIProcess/gtk/InputMethodFilter.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::targetFrameForEditing): Receive a reference instead of a pointer.
+        (WebKit::WebPage::confirmComposition): Remove the unused code to handle the selection range.
+        (WebKit::WebPage::setComposition): Remove the unused code to handle the replacement range.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2019-10-27  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         Unreviewed build fix for !ENABLE(MEDIA_STREAM) builds
index c0a64e3..6f4e29b 100644 (file)
@@ -41,8 +41,6 @@ struct KeypressCommand;
 #endif
 
 #if PLATFORM(GTK)
-#include "InputMethodFilter.h"
-#include <WebCore/CompositionResults.h>
 #include <WebCore/GUniquePtrGtk.h>
 typedef union _GdkEvent GdkEvent;
 #endif
@@ -69,7 +67,9 @@ public:
     NativeWebKeyboardEvent(NSEvent *, bool handledByInputMethod, bool replacesSoftSpace, const Vector<WebCore::KeypressCommand>&);
 #elif PLATFORM(GTK)
     NativeWebKeyboardEvent(const NativeWebKeyboardEvent&);
-    NativeWebKeyboardEvent(GdkEvent*, const WebCore::CompositionResults&, InputMethodFilter::EventFakedForComposition, Vector<String>&& commands);
+    enum class HandledByInputMethod : bool { No, Yes };
+    enum class FakedForComposition : bool { No, Yes };
+    NativeWebKeyboardEvent(GdkEvent*, const String&, HandledByInputMethod, FakedForComposition, Vector<String>&& commands);
 #elif PLATFORM(IOS_FAMILY)
     enum class HandledByInputMethod : bool { No, Yes };
     NativeWebKeyboardEvent(::WebEvent *, HandledByInputMethod);
@@ -83,8 +83,9 @@ public:
     NSEvent *nativeEvent() const { return m_nativeEvent.get(); }
 #elif PLATFORM(GTK)
     GdkEvent* nativeEvent() const { return m_nativeEvent.get(); }
-    const WebCore::CompositionResults& compositionResults() const  { return m_compositionResults; }
-    bool isFakeEventForComposition() const { return m_fakeEventForComposition; }
+    const String& text() const { return m_text; }
+    bool handledByInputMethod() const { return m_handledByInputMethod == HandledByInputMethod::Yes; }
+    bool fakedForComposition() const { return m_fakedForComposition == FakedForComposition::Yes; }
 #elif PLATFORM(IOS_FAMILY)
     ::WebEvent* nativeEvent() const { return m_nativeEvent.get(); }
 #elif PLATFORM(WIN)
@@ -98,8 +99,9 @@ private:
     RetainPtr<NSEvent> m_nativeEvent;
 #elif PLATFORM(GTK)
     GUniquePtr<GdkEvent> m_nativeEvent;
-    WebCore::CompositionResults m_compositionResults;
-    bool m_fakeEventForComposition;
+    String m_text;
+    HandledByInputMethod m_handledByInputMethod;
+    FakedForComposition m_fakedForComposition;
 #elif PLATFORM(IOS_FAMILY)
     RetainPtr<::WebEvent> m_nativeEvent;
 #elif PLATFORM(WIN)
index 970ba4c..45aa449 100644 (file)
 #include <gdk/gdk.h>
 
 namespace WebKit {
-using namespace WebCore;
 
-NativeWebKeyboardEvent::NativeWebKeyboardEvent(GdkEvent* event, const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked, Vector<String>&& commands)
-    : WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(event, compositionResults, WTFMove(commands)))
+NativeWebKeyboardEvent::NativeWebKeyboardEvent(GdkEvent* event, const String& text, HandledByInputMethod handledByInputMethod, FakedForComposition fakedForComposition, Vector<String>&& commands)
+    : WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(event, text, handledByInputMethod == HandledByInputMethod::Yes, WTFMove(commands)))
     , m_nativeEvent(gdk_event_copy(event))
-    , m_compositionResults(compositionResults)
-    , m_fakeEventForComposition(faked == InputMethodFilter::EventFaked)
+    , m_text(text)
+    , m_handledByInputMethod(handledByInputMethod)
+    , m_fakedForComposition(fakedForComposition)
 {
 }
 
 NativeWebKeyboardEvent::NativeWebKeyboardEvent(const NativeWebKeyboardEvent& event)
-    : WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(event.nativeEvent(), event.compositionResults(), Vector<String>(event.commands())))
+    : WebKeyboardEvent(WebEventFactory::createWebKeyboardEvent(event.nativeEvent(), event.text(), event.handledByInputMethod(), Vector<String>(event.commands())))
     , m_nativeEvent(gdk_event_copy(event.nativeEvent()))
-    , m_compositionResults(event.compositionResults())
-    , m_fakeEventForComposition(event.isFakeEventForComposition())
+    , m_text(event.text())
+    , m_handledByInputMethod(event.handledByInputMethod() ? HandledByInputMethod::Yes : HandledByInputMethod::No)
+    , m_fakedForComposition(event.fakedForComposition() ? FakedForComposition::Yes : FakedForComposition::No)
 {
 }
 
index 2cabab1..04048ce 100644 (file)
@@ -249,7 +249,7 @@ WebWheelEvent WebEventFactory::createWebWheelEvent(const GdkEvent* event, WebWhe
         wallTimeForEvent(event));
 }
 
-WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(const GdkEvent* event, const WebCore::CompositionResults& compositionResults, Vector<String>&& commands)
+WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(const GdkEvent* event, const String& text, bool handledByInputMethod, Vector<String>&& commands)
 {
     guint keyval;
     gdk_event_get_keyval(event, &keyval);
@@ -259,13 +259,13 @@ WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(const GdkEvent* event,
 
     return WebKeyboardEvent(
         type == GDK_KEY_RELEASE ? WebEvent::KeyUp : WebEvent::KeyDown,
-        compositionResults.simpleString.length() ? compositionResults.simpleString : PlatformKeyboardEvent::singleCharacterString(keyval),
+        text.isNull() ? PlatformKeyboardEvent::singleCharacterString(keyval) : text,
         PlatformKeyboardEvent::keyValueForGdkKeyCode(keyval),
         PlatformKeyboardEvent::keyCodeForHardwareKeyCode(keycode),
         PlatformKeyboardEvent::keyIdentifierForGdkKeyCode(keyval),
         PlatformKeyboardEvent::windowsKeyCodeForGdkKeyCode(keyval),
         static_cast<int>(keyval),
-        compositionResults.compositionUpdated(),
+        handledByInputMethod,
         WTFMove(commands),
         isGdkKeyCodeFromKeyPad(keyval),
         modifiersForEvent(event),
index 8fe7cdc..8008ff2 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebEventFactory_h
-#define WebEventFactory_h
+#pragma once
 
 #include "WebEvent.h"
-#include <WebCore/CompositionResults.h>
 
 typedef union _GdkEvent GdkEvent;
 
@@ -39,12 +37,10 @@ public:
     static WebMouseEvent createWebMouseEvent(const GdkEvent*, int);
     static WebWheelEvent createWebWheelEvent(const GdkEvent*);
     static WebWheelEvent createWebWheelEvent(const GdkEvent*, WebWheelEvent::Phase, WebWheelEvent::Phase momentumPhase);
-    static WebKeyboardEvent createWebKeyboardEvent(const GdkEvent*, const WebCore::CompositionResults&, Vector<String>&& commands);
+    static WebKeyboardEvent createWebKeyboardEvent(const GdkEvent*, const String&, bool handledByInputMethod, Vector<String>&& commands);
 #if ENABLE(TOUCH_EVENTS)
     static WebTouchEvent createWebTouchEvent(const GdkEvent*, Vector<WebPlatformTouchPoint>&&);
 #endif
 };
 
 } // namespace WebKit
-
-#endif // WebEventFactory_h
index 22e069a..00b7c6b 100644 (file)
@@ -224,7 +224,7 @@ void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent& event, bool
 {
     if (wasEventHandled)
         return;
-    if (event.isFakeEventForComposition())
+    if (event.fakedForComposition())
         return;
 
     WebKitWebViewBase* webkitWebViewBase = WEBKIT_WEB_VIEW_BASE(m_viewWidget);
index 27d1d18..a9d49d5 100644 (file)
@@ -784,9 +784,11 @@ static gboolean webkitWebViewBaseKeyPressEvent(GtkWidget* widget, GdkEventKey* k
 
     // We need to copy the event as otherwise it could be destroyed before we reach the lambda body.
     GUniquePtr<GdkEvent> event(gdk_event_copy(reinterpret_cast<GdkEvent*>(keyEvent)));
-    priv->inputMethodFilter.filterKeyEvent(keyEvent, [priv, event = WTFMove(event)](const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked) {
-        priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(event.get(), compositionResults, faked,
-            !compositionResults.compositionUpdated() ? priv->keyBindingTranslator.commandsForKeyEvent(&event->key) : Vector<String>()));
+    priv->inputMethodFilter.filterKeyEvent(keyEvent, [priv, event = WTFMove(event)](const String& text, InputMethodFilter::EventHandledByInputMethod handled, InputMethodFilter::EventFakedForComposition faked) {
+        auto handledByInputMethod = handled == InputMethodFilter::EventHandledByInputMethod::Yes ? NativeWebKeyboardEvent::HandledByInputMethod::Yes : NativeWebKeyboardEvent::HandledByInputMethod::No;
+        auto fakedForComposition = faked == InputMethodFilter::EventFakedForComposition::Yes ? NativeWebKeyboardEvent::FakedForComposition::Yes : NativeWebKeyboardEvent::FakedForComposition::No;
+        auto commands = handled == InputMethodFilter::EventHandledByInputMethod::Yes ? Vector<String>() : priv->keyBindingTranslator.commandsForKeyEvent(&event->key);
+        priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(event.get(), text, handledByInputMethod, fakedForComposition, WTFMove(commands)));
     });
 
     return GDK_EVENT_STOP;
@@ -804,8 +806,10 @@ static gboolean webkitWebViewBaseKeyReleaseEvent(GtkWidget* widget, GdkEventKey*
 
     // We need to copy the event as otherwise it could be destroyed before we reach the lambda body.
     GUniquePtr<GdkEvent> event(gdk_event_copy(reinterpret_cast<GdkEvent*>(keyEvent)));
-    priv->inputMethodFilter.filterKeyEvent(keyEvent, [priv, event = WTFMove(event)](const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked) {
-        priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(event.get(), compositionResults, faked, { }));
+    priv->inputMethodFilter.filterKeyEvent(keyEvent, [priv, event = WTFMove(event)](const String& text, InputMethodFilter::EventHandledByInputMethod handled, InputMethodFilter::EventFakedForComposition faked) {
+        auto handledByInputMethod = handled == InputMethodFilter::EventHandledByInputMethod::Yes ? NativeWebKeyboardEvent::HandledByInputMethod::Yes : NativeWebKeyboardEvent::HandledByInputMethod::No;
+        auto fakedForComposition = faked == InputMethodFilter::EventFakedForComposition::Yes ? NativeWebKeyboardEvent::FakedForComposition::Yes : NativeWebKeyboardEvent::FakedForComposition::No;
+        priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(event.get(), text, handledByInputMethod, fakedForComposition, { }));
     });
 
     return GDK_EVENT_STOP;
@@ -1455,11 +1459,6 @@ WebKitWebViewBase* webkitWebViewBaseCreate(const API::PageConfiguration& configu
     return webkitWebViewBase;
 }
 
-GtkIMContext* webkitWebViewBaseGetIMContext(WebKitWebViewBase* webkitWebViewBase)
-{
-    return webkitWebViewBase->priv->inputMethodFilter.context();
-}
-
 WebPageProxy* webkitWebViewBaseGetPage(WebKitWebViewBase* webkitWebViewBase)
 {
     return webkitWebViewBase->priv->pageProxy.get();
index c6bed3e..f84a3ab 100644 (file)
@@ -39,7 +39,6 @@
 #include "WebPageProxy.h"
 
 WebKitWebViewBase* webkitWebViewBaseCreate(const API::PageConfiguration&);
-GtkIMContext* webkitWebViewBaseGetIMContext(WebKitWebViewBase*);
 WebKit::WebPageProxy* webkitWebViewBaseGetPage(WebKitWebViewBase*);
 void webkitWebViewBaseCreateWebPage(WebKitWebViewBase*, Ref<API::PageConfiguration>&&);
 void webkitWebViewBaseSetTooltipText(WebKitWebViewBase*, const char*);
index 7df55dd..272fcaa 100644 (file)
@@ -8020,29 +8020,21 @@ RefPtr<ViewSnapshot> WebPageProxy::takeViewSnapshot()
 #endif
 
 #if PLATFORM(GTK)
-void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
+void WebPageProxy::setComposition(const String& text, const Vector<CompositionUnderline>& underlines, const EditingRange& selectionRange)
 {
     // FIXME: We need to find out how to proper handle the crashes case.
     if (!hasRunningProcess())
         return;
 
-    process().send(Messages::WebPage::SetComposition(text, underlines, selectionStart, selectionEnd, replacementRangeStart, replacementRangeEnd), m_webPageID);
+    process().send(Messages::WebPage::SetComposition(text, underlines, selectionRange), m_webPageID);
 }
 
-void WebPageProxy::confirmComposition(const String& compositionString, int64_t selectionStart, int64_t selectionLength)
+void WebPageProxy::confirmComposition(const String& compositionString)
 {
     if (!hasRunningProcess())
         return;
 
-    process().send(Messages::WebPage::ConfirmComposition(compositionString, selectionStart, selectionLength), m_webPageID);
-}
-
-void WebPageProxy::cancelComposition()
-{
-    if (!hasRunningProcess())
-        return;
-
-    process().send(Messages::WebPage::CancelComposition(), m_webPageID);
+    process().send(Messages::WebPage::ConfirmComposition(compositionString), m_webPageID);
 }
 #endif // PLATFORM(GTK)
 
index 5a99d13..a71d28f 100644 (file)
@@ -787,9 +787,8 @@ public:
     bool updateLayoutViewportParameters(const WebKit::RemoteLayerTreeTransaction&);
 
 #if PLATFORM(GTK)
-    void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd);
-    void confirmComposition(const String& compositionString, int64_t selectionStart, int64_t selectionLength);
-    void cancelComposition();
+    void setComposition(const String&, const Vector<WebCore::CompositionUnderline>&, const EditingRange& selectionRange);
+    void confirmComposition(const String& compositionString);
 
     void setInputMethodState(bool enabled);
 
index 4847e60..fe6af73 100644 (file)
@@ -23,7 +23,6 @@
 #include "NativeWebKeyboardEvent.h"
 #include "WebPageProxy.h"
 #include <WebCore/Color.h>
-#include <WebCore/CompositionResults.h>
 #include <WebCore/Editor.h>
 #include <WebCore/GUniquePtrGtk.h>
 #include <WebCore/IntRect.h>
@@ -145,10 +144,12 @@ void InputMethodFilter::handleKeyboardEvent(GdkEventKey* event, const String& si
 #endif
 
     if (m_filterKeyEventCompletionHandler) {
-        m_filterKeyEventCompletionHandler(CompositionResults(simpleString), faked);
+        m_filterKeyEventCompletionHandler(simpleString, EventHandledByInputMethod::No, faked);
         m_filterKeyEventCompletionHandler = nullptr;
-    } else
-        m_page->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), CompositionResults(simpleString), faked, Vector<String>()));
+    } else {
+        auto fakedForComposition = faked == InputMethodFilter::EventFakedForComposition::Yes ? NativeWebKeyboardEvent::FakedForComposition::Yes : NativeWebKeyboardEvent::FakedForComposition::No;
+        m_page->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), simpleString, NativeWebKeyboardEvent::HandledByInputMethod::No, fakedForComposition, Vector<String>()));
+    }
 }
 
 void InputMethodFilter::handleKeyboardEventWithCompositionResults(GdkEventKey* event, ResultsToSend resultsToSend, EventFakedForComposition faked)
@@ -161,16 +162,19 @@ void InputMethodFilter::handleKeyboardEventWithCompositionResults(GdkEventKey* e
 #endif
 
     if (m_filterKeyEventCompletionHandler) {
-        m_filterKeyEventCompletionHandler(CompositionResults(CompositionResults::WillSendCompositionResultsSoon), faked);
+        m_filterKeyEventCompletionHandler({ }, EventHandledByInputMethod::Yes, faked);
         m_filterKeyEventCompletionHandler = nullptr;
-    } else
-        m_page->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), CompositionResults(CompositionResults::WillSendCompositionResultsSoon), faked, Vector<String>()));
+    } else {
+        auto fakedForComposition = faked == InputMethodFilter::EventFakedForComposition::Yes ? NativeWebKeyboardEvent::FakedForComposition::Yes : NativeWebKeyboardEvent::FakedForComposition::No;
+        m_page->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), { }, NativeWebKeyboardEvent::HandledByInputMethod::Yes, fakedForComposition, Vector<String>()));
+    }
+
     if (resultsToSend & Composition && !m_confirmedComposition.isNull())
-        m_page->confirmComposition(m_confirmedComposition, -1, 0);
+        m_page->confirmComposition(m_confirmedComposition);
 
     if (resultsToSend & Preedit && !m_preedit.isNull()) {
         m_page->setComposition(m_preedit, Vector<CompositionUnderline> { CompositionUnderline(0, m_preedit.length(), CompositionUnderlineColor::TextColor, Color(Color::black), false) },
-            m_cursorOffset, m_cursorOffset, 0 /* replacement start */, 0 /* replacement end */);
+            EditingRange(m_cursorOffset, 1));
     }
 }
 
@@ -267,7 +271,7 @@ void InputMethodFilter::confirmComposition()
         return;
     }
 #endif
-    m_page->confirmComposition(m_confirmedComposition, -1, 0);
+    m_page->confirmComposition(m_confirmedComposition);
     m_confirmedComposition = String();
 }
 
@@ -281,7 +285,7 @@ void InputMethodFilter::updatePreedit()
 #endif
     // FIXME: We should parse the PangoAttrList that we get from the IM context here.
     m_page->setComposition(m_preedit, Vector<CompositionUnderline> { CompositionUnderline(0, m_preedit.length(), CompositionUnderlineColor::TextColor, Color(Color::black), false) },
-        m_cursorOffset, m_cursorOffset, 0 /* replacement start */, 0 /* replacement end */);
+        EditingRange(m_cursorOffset, 1));
     m_preeditChanged = false;
 }
 
@@ -340,7 +344,7 @@ void InputMethodFilter::confirmCurrentComposition()
     }
 #endif
 
-    m_page->confirmComposition(String(), -1, 0);
+    m_page->confirmComposition({ });
     m_composingTextCurrently = false;
 }
 
@@ -368,14 +372,14 @@ void InputMethodFilter::sendCompositionAndPreeditWithFakeKeyEvents(ResultsToSend
     GUniquePtr<GdkEvent> event(gdk_event_new(GDK_KEY_PRESS));
     event->key.time = GDK_CURRENT_TIME;
     event->key.keyval = compositionEventKeyCode;
-    handleKeyboardEventWithCompositionResults(&event->key, resultsToSend, EventFaked);
+    handleKeyboardEventWithCompositionResults(&event->key, resultsToSend, EventFakedForComposition::Yes);
 
     m_confirmedComposition = String();
     if (resultsToSend & Composition)
         m_composingTextCurrently = false;
 
     event->type = GDK_KEY_RELEASE;
-    handleKeyboardEvent(&event->key, String(), EventFaked);
+    handleKeyboardEvent(&event->key, String(), EventFakedForComposition::Yes);
     m_justSentFakeKeyUp = true;
 }
 
@@ -450,7 +454,7 @@ void InputMethodFilter::logHandleKeyboardEventForTesting(GdkEventKey* event, con
     guint keyval;
     gdk_event_get_keyval(reinterpret_cast<GdkEvent*>(event), &keyval);
     const char* eventType = gdk_event_get_event_type(reinterpret_cast<GdkEvent*>(event)) == GDK_KEY_RELEASE ? "release" : "press";
-    const char* fakedString = faked == EventFaked ? " (faked)" : "";
+    const char* fakedString = faked == EventFakedForComposition::Yes ? " (faked)" : "";
     if (!eventString.isNull())
         m_events.append(makeString("sendSimpleKeyEvent type=", eventType, " keycode=", hex(keyval), " text='", eventString, '\'', fakedString));
     else
@@ -462,7 +466,7 @@ void InputMethodFilter::logHandleKeyboardEventWithCompositionResultsForTesting(G
     guint keyval;
     gdk_event_get_keyval(reinterpret_cast<GdkEvent*>(event), &keyval);
     const char* eventType = gdk_event_get_event_type(reinterpret_cast<GdkEvent*>(event)) == GDK_KEY_RELEASE ? "release" : "press";
-    const char* fakedString = faked == EventFaked ? " (faked)" : "";
+    const char* fakedString = faked == EventFakedForComposition::Yes ? " (faked)" : "";
     m_events.append(makeString("sendKeyEventWithCompositionResults type=", eventType, " keycode=", hex(keyval), fakedString));
 
     if (resultsToSend & Composition && !m_confirmedComposition.isNull())
index 2a4af6a..afa6497 100644 (file)
@@ -17,8 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef InputMethodFilter_h
-#define InputMethodFilter_h
+#pragma once
 
 #include <WebCore/IntPoint.h>
 #include <wtf/Function.h>
@@ -30,7 +29,6 @@ typedef struct _GdkEventKey GdkEventKey;
 typedef struct _GtkIMContext GtkIMContext;
 
 namespace WebCore {
-struct CompositionResults;
 class IntRect;
 }
 
@@ -41,9 +39,13 @@ class WebPageProxy;
 class InputMethodFilter {
     WTF_MAKE_NONCOPYABLE(InputMethodFilter);
 public:
-    enum EventFakedForComposition {
-        EventFaked,
-        EventNotFaked
+    enum class EventFakedForComposition {
+        No,
+        Yes
+    };
+    enum class EventHandledByInputMethod {
+        No,
+        Yes
     };
 
     InputMethodFilter();
@@ -56,7 +58,7 @@ public:
     void setEnabled(bool);
     void setCursorRect(const WebCore::IntRect&);
 
-    using FilterKeyEventCompletionHandler = Function<void(const WebCore::CompositionResults&, InputMethodFilter::EventFakedForComposition)>;
+    using FilterKeyEventCompletionHandler = Function<void(const String&, EventHandledByInputMethod, EventFakedForComposition)>;
     void filterKeyEvent(GdkEventKey*, FilterKeyEventCompletionHandler&& = nullptr);
     void notifyFocusedIn();
     void notifyFocusedOut();
@@ -84,8 +86,8 @@ private:
     void handlePreeditStart();
     void handlePreeditEnd();
 
-    void handleKeyboardEvent(GdkEventKey*, const String& eventString = String(), EventFakedForComposition = EventNotFaked);
-    void handleKeyboardEventWithCompositionResults(GdkEventKey*, ResultsToSend = PreeditAndComposition, EventFakedForComposition = EventNotFaked);
+    void handleKeyboardEvent(GdkEventKey*, const String& eventString = String(), EventFakedForComposition = EventFakedForComposition::No);
+    void handleKeyboardEventWithCompositionResults(GdkEventKey*, ResultsToSend = PreeditAndComposition, EventFakedForComposition = EventFakedForComposition::No);
 
     void sendCompositionAndPreeditWithFakeKeyEvents(ResultsToSend);
     void confirmComposition();
@@ -126,4 +128,3 @@ private:
 
 } // namespace WebKit
 
-#endif // InputMethodFilter_h
index a15e1d4..ff8f204 100644 (file)
@@ -5291,9 +5291,9 @@ void WebPage::confirmCompositionAsync()
 #endif // PLATFORM(COCOA)
 
 #if PLATFORM(GTK)
-static Frame* targetFrameForEditing(WebPage* page)
+static Frame* targetFrameForEditing(WebPage& page)
 {
-    Frame& targetFrame = page->corePage()->focusController().focusedOrMainFrame();
+    Frame& targetFrame = page.corePage()->focusController().focusedOrMainFrame();
 
     Editor& editor = targetFrame.editor();
     if (!editor.canEdit())
@@ -5312,62 +5312,20 @@ static Frame* targetFrameForEditing(WebPage* page)
     return &targetFrame;
 }
 
-void WebPage::confirmComposition(const String& compositionString, int64_t selectionStart, int64_t selectionLength)
+void WebPage::confirmComposition(const String& compositionString)
 {
-    Frame* targetFrame = targetFrameForEditing(this);
-    if (!targetFrame) {
-        send(Messages::WebPageProxy::EditorStateChanged(editorState()));
-        return;
-    }
-
-    targetFrame->editor().confirmComposition(compositionString);
-
-    if (selectionStart == -1) {
-        send(Messages::WebPageProxy::EditorStateChanged(editorState()));
-        return;
-    }
-
-    Element* scope = targetFrame->selection().selection().rootEditableElement();
-    RefPtr<Range> selectionRange = TextIterator::rangeFromLocationAndLength(scope, selectionStart, selectionLength);
-    ASSERT_WITH_MESSAGE(selectionRange, "Invalid selection: [%lld:%lld] in text of length %d", static_cast<long long>(selectionStart), static_cast<long long>(selectionLength), scope->innerText().length());
-
-    if (selectionRange) {
-        VisibleSelection selection(*selectionRange, SEL_DEFAULT_AFFINITY);
-        targetFrame->selection().setSelection(selection);
-    }
-    send(Messages::WebPageProxy::EditorStateChanged(editorState()));
+    if (auto* targetFrame = targetFrameForEditing(*this))
+        targetFrame->editor().confirmComposition(compositionString);
 }
 
-void WebPage::setComposition(const String& text, const Vector<CompositionUnderline>& underlines, uint64_t selectionStart, uint64_t selectionLength, uint64_t replacementStart, uint64_t replacementLength)
+void WebPage::setComposition(const String& text, const Vector<CompositionUnderline>& underlines, const EditingRange& selectionRange)
 {
-    Frame* targetFrame = targetFrameForEditing(this);
-    if (!targetFrame || !targetFrame->selection().selection().isContentEditable()) {
-        send(Messages::WebPageProxy::EditorStateChanged(editorState()));
+    Frame* targetFrame = targetFrameForEditing(*this);
+    if (!targetFrame || !targetFrame->selection().selection().isContentEditable())
         return;
-    }
 
     Ref<Frame> protector(*targetFrame);
-
-    if (replacementLength > 0) {
-        // The layout needs to be uptodate before setting a selection
-        targetFrame->document()->updateLayout();
-
-        Element* scope = targetFrame->selection().selection().rootEditableElement();
-        RefPtr<Range> replacementRange = TextIterator::rangeFromLocationAndLength(scope, replacementStart, replacementLength);
-        targetFrame->editor().setIgnoreSelectionChanges(true);
-        targetFrame->selection().setSelection(VisibleSelection(*replacementRange, SEL_DEFAULT_AFFINITY));
-        targetFrame->editor().setIgnoreSelectionChanges(false);
-    }
-
-    targetFrame->editor().setComposition(text, underlines, selectionStart, selectionStart + selectionLength);
-    send(Messages::WebPageProxy::EditorStateChanged(editorState()));
-}
-
-void WebPage::cancelComposition()
-{
-    if (Frame* targetFrame = targetFrameForEditing(this))
-        targetFrame->editor().cancelComposition();
-    send(Messages::WebPageProxy::EditorStateChanged(editorState()));
+    targetFrame->editor().setComposition(text, underlines, selectionRange.location, selectionRange.location + selectionRange.length);
 }
 #endif
 
index 72bb562..5c2a62a 100644 (file)
@@ -773,9 +773,8 @@ public:
     SandboxExtensionTracker& sandboxExtensionTracker() { return m_sandboxExtensionTracker; }
 
 #if PLATFORM(GTK)
-    void setComposition(const String& text, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeLength);
-    void confirmComposition(const String& text, int64_t selectionStart, int64_t selectionLength);
-    void cancelComposition();
+    void setComposition(const String&, const Vector<WebCore::CompositionUnderline>&, const EditingRange& selectionRange);
+    void confirmComposition(const String& text);
 
     void collapseSelectionInFrame(WebCore::FrameIdentifier);
     void showEmojiPicker(WebCore::Frame&);
index 198028a..dc25d90 100644 (file)
@@ -411,9 +411,8 @@ GenerateSyntheticEditingCommand(enum:uint8_t WebKit::SyntheticEditingCommandType
     SetCanRunModal(bool canRunModal)
 
 #if PLATFORM(GTK)
-    SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
-    ConfirmComposition(String text, int64_t selectionStart, int64_t selectionLength)
-    CancelComposition()
+    SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, struct WebKit::EditingRange selectionRange)
+    ConfirmComposition(String text)
 
     CollapseSelectionInFrame(WebCore::FrameIdentifier frameID)