<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[260869] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/260869">260869</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2020-04-28 22:29:28 -0700 (Tue, 28 Apr 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK4] Add support for key events
https://bugs.webkit.org/show_bug.cgi?id=211128

Reviewed by Adrian Perez de Castro.

Source/WebCore:

* platform/gtk/GtkVersioning.h:
(gdk_event_get_keyval):
(gdk_event_get_keycode):

Source/WebKit:

Handle key-pressed and key-released events using a GtkEventControllerKey. To receive key events the widget needs
to be focused, so also implement GtkWidgetClass::grab_focus and handle enter and leave focus events. GTK4 needs
the widget used by the key bindings translator to be added to a parent to be able to forward key events, so it's
now added as a child internal widget of the WebKitWeViewBase.

* Shared/gtk/WebEventFactory.cpp:
(WebKit::WebEventFactory::createWebKeyboardEvent):
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewChildIsInternalWidget):
(webkitWebViewBaseContainerRemove):
(webkitWebViewBaseContainerForall):
(webkitWebViewBaseFocusEnter):
(webkitWebViewBaseFocusLeave):
(webkitWebViewBaseKeyPressed):
(webkitWebViewBaseKeyReleased):
(webkitWebViewBaseGrabFocus):
(webkitWebViewBaseConstructed):
(webkit_web_view_base_class_init):
* UIProcess/gtk/KeyBindingTranslator.cpp:
(WebKit::KeyBindingTranslator::KeyBindingTranslator):
(WebKit::KeyBindingTranslator::~KeyBindingTranslator):
(WebKit::handleCustomKeyBindings):
(WebKit::KeyBindingTranslator::commandsForKeyEvent):
* UIProcess/gtk/KeyBindingTranslator.h:
(WebKit::KeyBindingTranslator::widget const):
(WebKit::KeyBindingTranslator::destroyed):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgtkGtkVersioningh">trunk/Source/WebCore/platform/gtk/GtkVersioning.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitSharedgtkWebEventFactorycpp">trunk/Source/WebKit/Shared/gtk/WebEventFactory.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPIgtkWebKitWebViewBasecpp">trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessgtkKeyBindingTranslatorcpp">trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessgtkKeyBindingTranslatorh">trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (260868 => 260869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2020-04-29 05:28:02 UTC (rev 260868)
+++ trunk/Source/WebCore/ChangeLog      2020-04-29 05:29:28 UTC (rev 260869)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2020-04-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK4] Add support for key events
+        https://bugs.webkit.org/show_bug.cgi?id=211128
+
+        Reviewed by Adrian Perez de Castro.
+
+        * platform/gtk/GtkVersioning.h:
+        (gdk_event_get_keyval):
+        (gdk_event_get_keycode):
+
</ins><span class="cx"> 2020-04-28  Wenson Hsieh  <wenson_hsieh@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [Text manipulation] Add a userInfo dictionary to _WKTextManipulationToken
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkGtkVersioningh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/GtkVersioning.h (260868 => 260869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/GtkVersioning.h        2020-04-29 05:28:02 UTC (rev 260868)
+++ trunk/Source/WebCore/platform/gtk/GtkVersioning.h   2020-04-29 05:29:28 UTC (rev 260869)
</span><span class="lines">@@ -135,4 +135,20 @@
</span><span class="cx">         *button = gdk_button_event_get_button(const_cast<GdkEvent*>(event));
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><ins>+
+static inline gboolean
+gdk_event_get_keyval(const GdkEvent* event, guint* keyval)
+{
+    if (keyval)
+        *keyval = gdk_key_event_get_keyval(const_cast<GdkEvent*>(event));
+    return TRUE;
+}
+
+static inline gboolean
+gdk_event_get_keycode(const GdkEvent* event, guint16* keycode)
+{
+    if (keycode)
+        *keycode = gdk_key_event_get_keycode(const_cast<GdkEvent*>(event));
+    return TRUE;
+}
</ins><span class="cx"> #endif // USE(GTK4)
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (260868 => 260869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2020-04-29 05:28:02 UTC (rev 260868)
+++ trunk/Source/WebKit/ChangeLog       2020-04-29 05:29:28 UTC (rev 260869)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+2020-04-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK4] Add support for key events
+        https://bugs.webkit.org/show_bug.cgi?id=211128
+
+        Reviewed by Adrian Perez de Castro.
+
+        Handle key-pressed and key-released events using a GtkEventControllerKey. To receive key events the widget needs
+        to be focused, so also implement GtkWidgetClass::grab_focus and handle enter and leave focus events. GTK4 needs
+        the widget used by the key bindings translator to be added to a parent to be able to forward key events, so it's
+        now added as a child internal widget of the WebKitWeViewBase.
+
+        * Shared/gtk/WebEventFactory.cpp:
+        (WebKit::WebEventFactory::createWebKeyboardEvent):
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewChildIsInternalWidget):
+        (webkitWebViewBaseContainerRemove):
+        (webkitWebViewBaseContainerForall):
+        (webkitWebViewBaseFocusEnter):
+        (webkitWebViewBaseFocusLeave):
+        (webkitWebViewBaseKeyPressed):
+        (webkitWebViewBaseKeyReleased):
+        (webkitWebViewBaseGrabFocus):
+        (webkitWebViewBaseConstructed):
+        (webkit_web_view_base_class_init):
+        * UIProcess/gtk/KeyBindingTranslator.cpp:
+        (WebKit::KeyBindingTranslator::KeyBindingTranslator):
+        (WebKit::KeyBindingTranslator::~KeyBindingTranslator):
+        (WebKit::handleCustomKeyBindings):
+        (WebKit::KeyBindingTranslator::commandsForKeyEvent):
+        * UIProcess/gtk/KeyBindingTranslator.h:
+        (WebKit::KeyBindingTranslator::widget const):
+        (WebKit::KeyBindingTranslator::destroyed):
+
</ins><span class="cx"> 2020-04-28  Wenson Hsieh  <wenson_hsieh@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [Text manipulation] Add a userInfo dictionary to _WKTextManipulationToken
</span></span></pre></div>
<a id="trunkSourceWebKitSharedgtkWebEventFactorycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/gtk/WebEventFactory.cpp (260868 => 260869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/gtk/WebEventFactory.cpp       2020-04-29 05:28:02 UTC (rev 260868)
+++ trunk/Source/WebKit/Shared/gtk/WebEventFactory.cpp  2020-04-29 05:29:28 UTC (rev 260869)
</span><span class="lines">@@ -281,15 +281,10 @@
</span><span class="cx"> 
</span><span class="cx"> WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(const GdkEvent* event, const String& text, bool handledByInputMethod, Optional<Vector<CompositionUnderline>>&& preeditUnderlines, Optional<EditingRange>&& preeditSelectionRange, Vector<String>&& commands)
</span><span class="cx"> {
</span><del>-#if USE(GTK4)
-    guint keyval = 0;
-    guint16 keycode = 0;
-#else
</del><span class="cx">     guint keyval;
</span><span class="cx">     gdk_event_get_keyval(event, &keyval);
</span><span class="cx">     guint16 keycode;
</span><span class="cx">     gdk_event_get_keycode(event, &keycode);
</span><del>-#endif
</del><span class="cx">     GdkEventType type = gdk_event_get_event_type(const_cast<GdkEvent*>(event));
</span><span class="cx"> 
</span><span class="cx">     return WebKeyboardEvent(
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPIgtkWebKitWebViewBasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp (260868 => 260869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp      2020-04-29 05:28:02 UTC (rev 260868)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp 2020-04-29 05:29:28 UTC (rev 260869)
</span><span class="lines">@@ -466,7 +466,7 @@
</span><span class="cx"> static bool webkitWebViewChildIsInternalWidget(WebKitWebViewBase* webViewBase, GtkWidget* widget)
</span><span class="cx"> {
</span><span class="cx">     WebKitWebViewBasePrivate* priv = webViewBase->priv;
</span><del>-    return widget == priv->inspectorView || widget == priv->dialog;
</del><ins>+    return widget == priv->inspectorView || widget == priv->dialog || widget == priv->keyBindingTranslator.widget();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void webkitWebViewBaseContainerAdd(GtkContainer* container, GtkWidget* widget)
</span><span class="lines">@@ -528,7 +528,9 @@
</span><span class="cx">         priv->dialog = nullptr;
</span><span class="cx">         if (gtk_widget_get_visible(widgetContainer))
</span><span class="cx">             gtk_widget_grab_focus(widgetContainer);
</span><del>-    } else {
</del><ins>+    } else if (priv->keyBindingTranslator.widget() == widget)
+        priv->keyBindingTranslator.destroyed();
+    else {
</ins><span class="cx">         ASSERT(priv->children.contains(widget));
</span><span class="cx">         priv->children.remove(widget);
</span><span class="cx">     }
</span><span class="lines">@@ -553,6 +555,9 @@
</span><span class="cx">             (*callback)(child, callbackData);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    if (includeInternals && priv->keyBindingTranslator.widget())
+        (*callback)(priv->keyBindingTranslator.widget(), callbackData);
+
</ins><span class="cx">     if (includeInternals && priv->inspectorView)
</span><span class="cx">         (*callback)(priv->inspectorView, callbackData);
</span><span class="cx"> 
</span><span class="lines">@@ -876,7 +881,71 @@
</span><span class="cx"> 
</span><span class="cx">     return GDK_EVENT_STOP;
</span><span class="cx"> }
</span><ins>+#endif
</ins><span class="cx"> 
</span><ins>+#if USE(GTK4)
+static void webkitWebViewBaseFocusEnter(WebKitWebViewBase* webViewBase, GtkEventController*)
+{
+    webkitWebViewBaseSetFocus(webViewBase, true);
+}
+
+static void webkitWebViewBaseFocusLeave(WebKitWebViewBase* webViewBase, GtkEventController*)
+{
+    webkitWebViewBaseSetFocus(webViewBase, false);
+}
+
+static gboolean webkitWebViewBaseKeyPressed(WebKitWebViewBase* webViewBase, unsigned keyval, unsigned, GdkModifierType state, GtkEventController* controller)
+{
+    WebKitWebViewBasePrivate* priv = webViewBase->priv;
+
+#if ENABLE(DEVELOPER_MODE) && OS(LINUX)
+    if ((state & GDK_CONTROL_MASK) && (state & GDK_SHIFT_MASK) && keyval == GDK_KEY_G) {
+        auto& preferences = priv->pageProxy->preferences();
+        preferences.setResourceUsageOverlayVisible(!preferences.resourceUsageOverlayVisible());
+        return GDK_EVENT_STOP;
+    }
+#endif
+
+    if (priv->dialog)
+        return gtk_event_controller_key_forward(GTK_EVENT_CONTROLLER_KEY(controller), priv->dialog);
+
+#if ENABLE(FULLSCREEN_API)
+    if (priv->fullScreenModeActive) {
+        switch (keyval) {
+        case GDK_KEY_Escape:
+        case GDK_KEY_f:
+        case GDK_KEY_F:
+            priv->pageProxy->fullScreenManager()->requestExitFullScreen();
+            return GDK_EVENT_STOP;
+        default:
+            break;
+        }
+    }
+#endif
+
+    auto* event = gtk_event_controller_get_current_event(controller);
+    auto filterResult = priv->inputMethodFilter.filterKeyEvent(event);
+    if (!filterResult.handled) {
+        priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(event, filterResult.keyText,
+            NativeWebKeyboardEvent::HandledByInputMethod::No, WTF::nullopt, WTF::nullopt, priv->keyBindingTranslator.commandsForKeyEvent(GTK_EVENT_CONTROLLER_KEY(controller))));
+    }
+
+    return GDK_EVENT_STOP;
+}
+
+static void webkitWebViewBaseKeyReleased(WebKitWebViewBase* webViewBase, unsigned, unsigned, GdkModifierType, GtkEventController* controller)
+{
+    WebKitWebViewBasePrivate* priv = webViewBase->priv;
+
+    auto* event = gtk_event_controller_get_current_event(controller);
+    if (!priv->inputMethodFilter.filterKeyEvent(event).handled) {
+        priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(event, { },
+            NativeWebKeyboardEvent::HandledByInputMethod::No, WTF::nullopt, WTF::nullopt, { }));
+    }
+}
+#endif
+
+#if !USE(GTK4)
</ins><span class="cx"> static void webkitWebViewBaseHandleMouseEvent(WebKitWebViewBase* webViewBase, GdkEvent* event)
</span><span class="cx"> {
</span><span class="cx">     WebKitWebViewBasePrivate* priv = webViewBase->priv;
</span><span class="lines">@@ -1524,6 +1593,14 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(GTK4)
+static gboolean webkitWebViewBaseGrabFocus(GtkWidget* widget)
+{
+    gtk_root_set_focus(gtk_widget_get_root(widget), widget);
+    return TRUE;
+}
+#endif
+
</ins><span class="cx"> static gboolean webkitWebViewBaseFocus(GtkWidget* widget, GtkDirectionType direction)
</span><span class="cx"> {
</span><span class="cx">     // If a dialog is active, we need to forward focus events there. This
</span><span class="lines">@@ -1553,6 +1630,11 @@
</span><span class="cx"> 
</span><span class="cx">     GtkWidget* viewWidget = GTK_WIDGET(object);
</span><span class="cx">     gtk_widget_set_can_focus(viewWidget, TRUE);
</span><ins>+
+    WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(object)->priv;
+    priv->pageClient = makeUnique<PageClientImpl>(viewWidget);
+    gtk_container_add(GTK_CONTAINER(viewWidget), priv->keyBindingTranslator.widget());
+
</ins><span class="cx"> #if !USE(GTK4)
</span><span class="cx">     gtk_drag_dest_set(viewWidget, static_cast<GtkDestDefaults>(0), nullptr, 0,
</span><span class="cx">         static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE));
</span><span class="lines">@@ -1559,9 +1641,6 @@
</span><span class="cx">     gtk_drag_dest_set_target_list(viewWidget, PasteboardHelper::singleton().targetList());
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(object)->priv;
-    priv->pageClient = makeUnique<PageClientImpl>(viewWidget);
-
</del><span class="cx"> #if USE(GTK4)
</span><span class="cx">     auto* controller = gtk_event_controller_scroll_new(GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES);
</span><span class="cx">     g_signal_connect_object(controller, "scroll", G_CALLBACK(webkitWebViewBaseScroll), viewWidget, G_CONNECT_SWAPPED);
</span><span class="lines">@@ -1572,6 +1651,16 @@
</span><span class="cx">     g_signal_connect_object(controller, "motion", G_CALLBACK(webkitWebViewBaseMotion), viewWidget, G_CONNECT_SWAPPED);
</span><span class="cx">     g_signal_connect_object(controller, "leave", G_CALLBACK(webkitWebViewBaseLeave), viewWidget, G_CONNECT_SWAPPED);
</span><span class="cx">     gtk_widget_add_controller(viewWidget, controller);
</span><ins>+
+    controller = gtk_event_controller_focus_new();
+    g_signal_connect_object(controller, "enter", G_CALLBACK(webkitWebViewBaseFocusEnter), viewWidget, G_CONNECT_SWAPPED);
+    g_signal_connect_object(controller, "leave", G_CALLBACK(webkitWebViewBaseFocusLeave), viewWidget, G_CONNECT_SWAPPED);
+    gtk_widget_add_controller(viewWidget, controller);
+
+    controller = gtk_event_controller_key_new();
+    g_signal_connect_object(controller, "key-pressed", G_CALLBACK(webkitWebViewBaseKeyPressed), viewWidget, G_CONNECT_SWAPPED);
+    g_signal_connect_object(controller, "key-released", G_CALLBACK(webkitWebViewBaseKeyReleased), viewWidget, G_CONNECT_SWAPPED);
+    gtk_widget_add_controller(viewWidget, controller);
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1594,8 +1683,10 @@
</span><span class="cx"> #endif
</span><span class="cx">     widgetClass->map = webkitWebViewBaseMap;
</span><span class="cx">     widgetClass->unmap = webkitWebViewBaseUnmap;
</span><del>-#if !USE(GTK4)
</del><ins>+#if USE(GTK4)
+    widgetClass->grab_focus = webkitWebViewBaseGrabFocus;
</ins><span class="cx">     widgetClass->focus = webkitWebViewBaseFocus;
</span><ins>+#else
</ins><span class="cx">     widgetClass->focus_in_event = webkitWebViewBaseFocusInEvent;
</span><span class="cx">     widgetClass->focus_out_event = webkitWebViewBaseFocusOutEvent;
</span><span class="cx">     widgetClass->key_press_event = webkitWebViewBaseKeyPressEvent;
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessgtkKeyBindingTranslatorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.cpp (260868 => 260869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.cpp       2020-04-29 05:28:02 UTC (rev 260868)
+++ trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.cpp  2020-04-29 05:29:28 UTC (rev 260869)
</span><span class="lines">@@ -173,23 +173,28 @@
</span><span class="cx"> KeyBindingTranslator::KeyBindingTranslator()
</span><span class="cx">     : m_nativeWidget(gtk_text_view_new())
</span><span class="cx"> {
</span><del>-    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);
</del><ins>+    g_signal_connect(m_nativeWidget, "backspace", G_CALLBACK(backspaceCallback), this);
+    g_signal_connect(m_nativeWidget, "cut-clipboard", G_CALLBACK(cutClipboardCallback), this);
+    g_signal_connect(m_nativeWidget, "copy-clipboard", G_CALLBACK(copyClipboardCallback), this);
+    g_signal_connect(m_nativeWidget, "paste-clipboard", G_CALLBACK(pasteClipboardCallback), this);
+    g_signal_connect(m_nativeWidget, "select-all", G_CALLBACK(selectAllCallback), this);
+    g_signal_connect(m_nativeWidget, "move-cursor", G_CALLBACK(moveCursorCallback), this);
+    g_signal_connect(m_nativeWidget, "delete-from-cursor", G_CALLBACK(deleteFromCursorCallback), this);
+    g_signal_connect(m_nativeWidget, "toggle-overwrite", G_CALLBACK(toggleOverwriteCallback), this);
</ins><span class="cx"> #if !USE(GTK4)
</span><del>-    g_signal_connect(m_nativeWidget.get(), "popup-menu", G_CALLBACK(popupMenuCallback), this);
-    g_signal_connect(m_nativeWidget.get(), "show-help", G_CALLBACK(showHelpCallback), this);
</del><ins>+    g_signal_connect(m_nativeWidget, "popup-menu", G_CALLBACK(popupMenuCallback), this);
+    g_signal_connect(m_nativeWidget, "show-help", G_CALLBACK(showHelpCallback), this);
</ins><span class="cx"> #endif
</span><span class="cx"> #if GTK_CHECK_VERSION(3, 24, 0)
</span><del>-    g_signal_connect(m_nativeWidget.get(), "insert-emoji", G_CALLBACK(insertEmojiCallback), this);
</del><ins>+    g_signal_connect(m_nativeWidget, "insert-emoji", G_CALLBACK(insertEmojiCallback), this);
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+KeyBindingTranslator::~KeyBindingTranslator()
+{
+    ASSERT(!m_nativeWidget);
+}
+
</ins><span class="cx"> struct KeyCombinationEntry {
</span><span class="cx">     unsigned gdkKeyCode;
</span><span class="cx">     unsigned state;
</span><span class="lines">@@ -211,24 +216,8 @@
</span><span class="cx">     { GDK_KEY_ISO_Enter, GDK_SHIFT_MASK,   "InsertLineBreak" },
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-Vector<String> KeyBindingTranslator::commandsForKeyEvent(GdkEventKey* event)
</del><ins>+static Vector<String> handleCustomKeyBindings(unsigned keyval, GdkModifierType state)
</ins><span class="cx"> {
</span><del>-    ASSERT(m_pendingEditorCommands.isEmpty());
-
-    guint keyval;
-    GdkModifierType state;
-#if USE(GTK4)
-    keyval = 0;
-    state = static_cast<GdkModifierType>(0);
-#else
-    gdk_event_get_keyval(reinterpret_cast<GdkEvent*>(event), &keyval);
-    gdk_event_get_state(reinterpret_cast<GdkEvent*>(event), &state);
-
-    gtk_bindings_activate_event(G_OBJECT(m_nativeWidget.get()), event);
-#endif
-    if (!m_pendingEditorCommands.isEmpty())
-        return WTFMove(m_pendingEditorCommands);
-
</del><span class="cx">     // For keypress events, we want charCode(), but keyCode() does that.
</span><span class="cx">     unsigned mapKey = (state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) << 16 | keyval;
</span><span class="cx">     if (!mapKey)
</span><span class="lines">@@ -242,4 +231,33 @@
</span><span class="cx">     return { };
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if USE(GTK4)
+Vector<String> KeyBindingTranslator::commandsForKeyEvent(GtkEventControllerKey* controller)
+{
+    ASSERT(m_pendingEditorCommands.isEmpty());
+
+    gtk_event_controller_key_forward(GTK_EVENT_CONTROLLER_KEY(controller), m_nativeWidget);
+    if (!m_pendingEditorCommands.isEmpty())
+        return WTFMove(m_pendingEditorCommands);
+
+    auto* event = gtk_event_controller_get_current_event(GTK_EVENT_CONTROLLER(controller));
+    return handleCustomKeyBindings(gdk_key_event_get_keyval(event), gdk_event_get_modifier_state(event));
+}
+#else
+Vector<String> KeyBindingTranslator::commandsForKeyEvent(GdkEventKey* event)
+{
+    ASSERT(m_pendingEditorCommands.isEmpty());
+
+    gtk_bindings_activate_event(G_OBJECT(m_nativeWidget), event);
+    if (!m_pendingEditorCommands.isEmpty())
+        return WTFMove(m_pendingEditorCommands);
+
+    guint keyval;
+    gdk_event_get_keyval(reinterpret_cast<GdkEvent*>(event), &keyval);
+    GdkModifierType state;
+    gdk_event_get_state(reinterpret_cast<GdkEvent*>(event), &state);
+    return handleCustomKeyBindings(keyval, state);
+}
+#endif
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessgtkKeyBindingTranslatorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.h (260868 => 260869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.h 2020-04-29 05:28:02 UTC (rev 260868)
+++ trunk/Source/WebKit/UIProcess/gtk/KeyBindingTranslator.h    2020-04-29 05:29:28 UTC (rev 260869)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010, 2011 Igalia S.L.
</del><ins>+ * Copyright (C) 2010, 2011, 2020 Igalia S.L.
</ins><span class="cx">  *
</span><span class="cx">  *  This library is free software; you can redistribute it and/or
</span><span class="cx">  *  modify it under the terms of the GNU Lesser General Public
</span><span class="lines">@@ -16,16 +16,15 @@
</span><span class="cx">  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef KeyBindingTranslator_h
-#define KeyBindingTranslator_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><del>-#include <WebCore/GRefPtrGtk.h>
</del><span class="cx"> #include <wtf/Vector.h>
</span><span class="cx"> #include <wtf/text/WTFString.h>
</span><span class="cx"> 
</span><ins>+typedef struct _GtkWidget GtkWidget;
+
</ins><span class="cx"> #if USE(GTK4)
</span><del>-typedef struct _GdkKeyEvent GdkKeyEvent;
-typedef GdkKeyEvent GdkEventKey;
</del><ins>+typedef struct _GtkEventControllerKey GtkEventControllerKey;
</ins><span class="cx"> #else
</span><span class="cx"> typedef struct _GdkEventKey GdkEventKey;
</span><span class="cx"> #endif
</span><span class="lines">@@ -35,17 +34,22 @@
</span><span class="cx"> class KeyBindingTranslator {
</span><span class="cx"> public:
</span><span class="cx">     KeyBindingTranslator();
</span><ins>+    ~KeyBindingTranslator();
</ins><span class="cx"> 
</span><ins>+    GtkWidget* widget() const { return m_nativeWidget; }
+    void destroyed() { m_nativeWidget = nullptr; }
+
+#if USE(GTK4)
+    Vector<String> commandsForKeyEvent(GtkEventControllerKey*);
+#else
</ins><span class="cx">     Vector<String> commandsForKeyEvent(GdkEventKey*);
</span><ins>+#endif
</ins><span class="cx">     void addPendingEditorCommand(const char* command) { m_pendingEditorCommands.append(command); }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    GRefPtr<GtkWidget> m_nativeWidget;
</del><ins>+    GtkWidget* m_nativeWidget;
</ins><span class="cx">     Vector<String> m_pendingEditorCommands;
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><del>-#endif
-
-
</del></span></pre>
</div>
</div>

</body>
</html>