<!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>[194886] trunk/Source/WebKit2</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/194886">194886</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2016-01-11 23:16:04 -0800 (Mon, 11 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>REGRESSION(<a href="http://trac.webkit.org/projects/webkit/changeset/190717">r190717</a>): [GTK] Popup menus stop working after being dismissed without selecting an item
https://bugs.webkit.org/show_bug.cgi?id=152977

Reviewed by Michael Catanzaro.

This happens since <a href="http://trac.webkit.org/projects/webkit/changeset/190717">r190717</a> when you open a popup menu and without
selecting any option it's dismissed (press ESC or click somewhere
else). This is because I removed the code to track when the menu
is unmapped, thinking that it was no longer necessary. But we need
to send the DidChangeSelectedIndexForActivePopupMenu to the
WebProcess with -1 as index to keep the web process in sync.

* UIProcess/gtk/WebPopupMenuProxyGtk.cpp:
(WebKit::WebPopupMenuProxyGtk::WebPopupMenuProxyGtk):
(WebKit::WebPopupMenuProxyGtk::showPopupMenu):
(WebKit::WebPopupMenuProxyGtk::cancelTracking):
(WebKit::WebPopupMenuProxyGtk::menuItemActivated):
(WebKit::WebPopupMenuProxyGtk::dismissMenuTimerFired):
(WebKit::WebPopupMenuProxyGtk::menuUnmappedCallback):
* UIProcess/gtk/WebPopupMenuProxyGtk.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkWebPopupMenuProxyGtkcpp">trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkWebPopupMenuProxyGtkh">trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (194885 => 194886)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-01-12 04:40:44 UTC (rev 194885)
+++ trunk/Source/WebKit2/ChangeLog        2016-01-12 07:16:04 UTC (rev 194886)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2016-01-11  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        REGRESSION(r190717): [GTK] Popup menus stop working after being dismissed without selecting an item
+        https://bugs.webkit.org/show_bug.cgi?id=152977
+
+        Reviewed by Michael Catanzaro.
+
+        This happens since r190717 when you open a popup menu and without
+        selecting any option it's dismissed (press ESC or click somewhere
+        else). This is because I removed the code to track when the menu
+        is unmapped, thinking that it was no longer necessary. But we need
+        to send the DidChangeSelectedIndexForActivePopupMenu to the
+        WebProcess with -1 as index to keep the web process in sync.
+
+        * UIProcess/gtk/WebPopupMenuProxyGtk.cpp:
+        (WebKit::WebPopupMenuProxyGtk::WebPopupMenuProxyGtk):
+        (WebKit::WebPopupMenuProxyGtk::showPopupMenu):
+        (WebKit::WebPopupMenuProxyGtk::cancelTracking):
+        (WebKit::WebPopupMenuProxyGtk::menuItemActivated):
+        (WebKit::WebPopupMenuProxyGtk::dismissMenuTimerFired):
+        (WebKit::WebPopupMenuProxyGtk::menuUnmappedCallback):
+        * UIProcess/gtk/WebPopupMenuProxyGtk.h:
+
</ins><span class="cx"> 2016-01-09  Andy Estes  &lt;aestes@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] Add SPI to opt out a URL scheme from the memory cache
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkWebPopupMenuProxyGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp (194885 => 194886)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp        2016-01-12 04:40:44 UTC (rev 194885)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp        2016-01-12 07:16:04 UTC (rev 194886)
</span><span class="lines">@@ -42,11 +42,10 @@
</span><span class="cx">     : WebPopupMenuProxy(client)
</span><span class="cx">     , m_webView(webView)
</span><span class="cx">     , m_popup(gtk_menu_new())
</span><del>-    , m_previousKeyEventCharacter(0)
-    , m_previousKeyEventTimestamp(0)
-    , m_currentlySelectedMenuItem(nullptr)
</del><ins>+    , m_dismissMenuTimer(RunLoop::main(), this, &amp;WebPopupMenuProxyGtk::dismissMenuTimerFired)
</ins><span class="cx"> {
</span><span class="cx">     g_signal_connect(m_popup, &quot;key-press-event&quot;, G_CALLBACK(keyPressEventCallback), this);
</span><ins>+    g_signal_connect(m_popup, &quot;unmap&quot;, G_CALLBACK(menuUnmappedCallback), this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebPopupMenuProxyGtk::~WebPopupMenuProxyGtk()
</span><span class="lines">@@ -89,12 +88,13 @@
</span><span class="cx"> 
</span><span class="cx"> void WebPopupMenuProxyGtk::showPopupMenu(const IntRect&amp; rect, TextDirection, double /* pageScaleFactor */, const Vector&lt;WebPopupItem&gt;&amp; items, const PlatformPopupMenuData&amp;, int32_t selectedIndex)
</span><span class="cx"> {
</span><ins>+    m_dismissMenuTimer.stop();
+
</ins><span class="cx">     populatePopupMenu(items);
</span><span class="cx">     gtk_menu_set_active(GTK_MENU(m_popup), selectedIndex);
</span><span class="cx"> 
</span><span class="cx">     resetTypeAheadFindState();
</span><span class="cx"> 
</span><del>-
</del><span class="cx">     IntPoint menuPosition = convertWidgetPointToScreenPoint(m_webView, rect.location());
</span><span class="cx">     menuPosition.move(0, rect.height());
</span><span class="cx"> 
</span><span class="lines">@@ -155,6 +155,7 @@
</span><span class="cx">     if (!m_popup)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    m_dismissMenuTimer.stop();
</ins><span class="cx">     g_signal_handlers_disconnect_matched(m_popup, G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
</span><span class="cx">     hidePopupMenu();
</span><span class="cx">     gtk_widget_destroy(m_popup);
</span><span class="lines">@@ -241,10 +242,28 @@
</span><span class="cx"> 
</span><span class="cx"> void WebPopupMenuProxyGtk::menuItemActivated(GtkAction* action, WebPopupMenuProxyGtk* popupMenu)
</span><span class="cx"> {
</span><ins>+    popupMenu-&gt;m_dismissMenuTimer.stop();
</ins><span class="cx">     if (popupMenu-&gt;m_client)
</span><span class="cx">         popupMenu-&gt;m_client-&gt;valueChangedForPopupMenu(popupMenu, GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), &quot;popup-menu-action-index&quot;)));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPopupMenuProxyGtk::dismissMenuTimerFired()
+{
+    if (m_client)
+        m_client-&gt;valueChangedForPopupMenu(this, -1);
+}
+
+void WebPopupMenuProxyGtk::menuUnmappedCallback(GtkWidget*, WebPopupMenuProxyGtk* popupMenu)
+{
+    if (!popupMenu-&gt;m_client)
+        return;
+
+    // When an item is activated, the menu is first hidden and then activate signal is emitted, so at this point we don't know
+    // if the menu has been hidden because an item has been selected or because the menu has been dismissed. Wait until the next
+    // main loop iteration to dismiss the menu, if an item is activated the timer will be cancelled.
+    popupMenu-&gt;m_dismissMenuTimer.startOneShot(0);
+}
+
</ins><span class="cx"> void WebPopupMenuProxyGtk::selectItemCallback(GtkWidget* item, WebPopupMenuProxyGtk* popupMenu)
</span><span class="cx"> {
</span><span class="cx">     popupMenu-&gt;setCurrentlySelectedMenuItem(item);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkWebPopupMenuProxyGtkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.h (194885 => 194886)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.h        2016-01-12 04:40:44 UTC (rev 194885)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.h        2016-01-12 07:16:04 UTC (rev 194886)
</span><span class="lines">@@ -21,6 +21,7 @@
</span><span class="cx"> #define WebPopupMenuProxyGtk_h
</span><span class="cx"> 
</span><span class="cx"> #include &quot;WebPopupMenuProxy.h&quot;
</span><ins>+#include &lt;wtf/RunLoop.h&gt;
</ins><span class="cx"> #include &lt;wtf/glib/GRefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -53,6 +54,7 @@
</span><span class="cx">     void setCurrentlySelectedMenuItem(GtkWidget* item) { m_currentlySelectedMenuItem = item; }
</span><span class="cx">     GtkAction* createGtkActionForMenuItem(const WebPopupItem&amp;, int itemIndex);
</span><span class="cx">     void populatePopupMenu(const Vector&lt;WebPopupItem&gt;&amp;);
</span><ins>+    void dismissMenuTimerFired();
</ins><span class="cx"> 
</span><span class="cx">     bool typeAheadFind(GdkEventKey*);
</span><span class="cx">     void resetTypeAheadFindState();
</span><span class="lines">@@ -60,14 +62,17 @@
</span><span class="cx">     static void menuItemActivated(GtkAction*, WebPopupMenuProxyGtk*);
</span><span class="cx">     static void selectItemCallback(GtkWidget*, WebPopupMenuProxyGtk*);
</span><span class="cx">     static gboolean keyPressEventCallback(GtkWidget*, GdkEventKey*, WebPopupMenuProxyGtk*);
</span><ins>+    static void menuUnmappedCallback(GtkWidget*, WebPopupMenuProxyGtk*);
</ins><span class="cx"> 
</span><del>-    GtkWidget* m_webView;
-    GtkWidget* m_popup;
</del><ins>+    GtkWidget* m_webView { nullptr };
+    GtkWidget* m_popup { nullptr };
</ins><span class="cx"> 
</span><ins>+    RunLoop::Timer&lt;WebPopupMenuProxyGtk&gt; m_dismissMenuTimer;
+
</ins><span class="cx">     // Typeahead find.
</span><del>-    unsigned m_previousKeyEventCharacter;
-    uint32_t m_previousKeyEventTimestamp;
-    GtkWidget* m_currentlySelectedMenuItem;
</del><ins>+    unsigned m_previousKeyEventCharacter { 0 };
+    uint32_t m_previousKeyEventTimestamp { 0 };
+    GtkWidget* m_currentlySelectedMenuItem { nullptr };
</ins><span class="cx">     String m_currentSearchString;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>