<!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>[215190] trunk</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/215190">215190</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-04-10 11:06:32 -0700 (Mon, 10 Apr 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] Misplaced right click menu on web page due to deprecated gtk_menu_popup()
https://bugs.webkit.org/show_bug.cgi?id=170553

Patch by Adrian Perez de Castro &lt;aperez@igalia.com&gt; on 2017-04-10
Reviewed by Michael Catanzaro.

Source/WebKit2:

Use gtk_menu_popup_at_pointer() and gtk_menu_popup_at_rect() when building with GTK+ 3.22 or
newer. This allows the Wayland GTK+ backend to properly position popup menus, and also avoids
using functions which were deprecated starting at that GTK+ release.

* UIProcess/gtk/WebContextMenuProxyGtk.cpp:
(WebKit::WebContextMenuProxyGtk::show): Use gtk_menu_popup_at_pointer() as there is always a
pointer event that can be passed to it.
* UIProcess/gtk/WebPopupMenuProxyGtk.cpp:
(WebKit::WebPopupMenuProxyGtk::showPopupMenu): Use gtk_menu_popup_at_rect(), using the coordinates
of the control passed as reference rectangle. Some conditional code is needed because with newer
GTK+ versions a relative offset instead of an absolute position is needed.

Tools:

Use gtk_menu_popup_at_pointer() and gtk_menu_popup_at_rect() when
building with GTK+ 3.22 or newer. This allows the Wayland GTK+ backend
to properly position popup menus, and also avoids using functions
which were deprecated starting at that GTK+ release.

* MiniBrowser/gtk/BrowserSearchBar.c:
(searchEntryMenuIconPressedCallback):
Update MiniBrowser to use gtk_menu_popup_at_pointer().</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkWebContextMenuProxyGtkcpp">trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkWebPopupMenuProxyGtkcpp">trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsMiniBrowsergtkBrowserSearchBarc">trunk/Tools/MiniBrowser/gtk/BrowserSearchBar.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (215189 => 215190)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-04-10 17:58:58 UTC (rev 215189)
+++ trunk/Source/WebKit2/ChangeLog        2017-04-10 18:06:32 UTC (rev 215190)
</span><span class="lines">@@ -1,5 +1,24 @@
</span><span class="cx"> 2017-04-10  Adrian Perez de Castro  &lt;aperez@igalia.com&gt;
</span><span class="cx"> 
</span><ins>+        [GTK] Misplaced right click menu on web page due to deprecated gtk_menu_popup()
+        https://bugs.webkit.org/show_bug.cgi?id=170553
+
+        Reviewed by Michael Catanzaro.
+
+        Use gtk_menu_popup_at_pointer() and gtk_menu_popup_at_rect() when building with GTK+ 3.22 or
+        newer. This allows the Wayland GTK+ backend to properly position popup menus, and also avoids
+        using functions which were deprecated starting at that GTK+ release.
+
+        * UIProcess/gtk/WebContextMenuProxyGtk.cpp:
+        (WebKit::WebContextMenuProxyGtk::show): Use gtk_menu_popup_at_pointer() as there is always a
+        pointer event that can be passed to it.
+        * UIProcess/gtk/WebPopupMenuProxyGtk.cpp:
+        (WebKit::WebPopupMenuProxyGtk::showPopupMenu): Use gtk_menu_popup_at_rect(), using the coordinates
+        of the control passed as reference rectangle. Some conditional code is needed because with newer
+        GTK+ versions a relative offset instead of an absolute position is needed.
+
+2017-04-10  Adrian Perez de Castro  &lt;aperez@igalia.com&gt;
+
</ins><span class="cx">         [GTK] Opening a popup menu does not pre-select the active item
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=170680
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkWebContextMenuProxyGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp (215189 => 215190)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp        2017-04-10 17:58:58 UTC (rev 215189)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp        2017-04-10 18:06:32 UTC (rev 215190)
</span><span class="lines">@@ -167,8 +167,13 @@
</span><span class="cx">     NativeWebMouseEvent* mouseEvent = m_page-&gt;currentlyProcessedMouseDownEvent();
</span><span class="cx">     const GdkEvent* event = mouseEvent ? mouseEvent-&gt;nativeEvent() : 0;
</span><span class="cx">     gtk_menu_attach_to_widget(m_menu, GTK_WIDGET(m_webView), nullptr);
</span><ins>+
+#if GTK_CHECK_VERSION(3, 22, 0)
+    gtk_menu_popup_at_pointer(m_menu, event);
+#else
</ins><span class="cx">     gtk_menu_popup(m_menu, nullptr, nullptr, reinterpret_cast&lt;GtkMenuPositionFunc&gt;(menuPositionFunction), this,
</span><span class="cx">                    event ? event-&gt;button.button : 3, event ? event-&gt;button.time : GDK_CURRENT_TIME);
</span><ins>+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebContextMenuProxyGtk::showContextMenuWithItems(const Vector&lt;WebContextMenuItemData&gt;&amp; items)
</span><span class="lines">@@ -204,6 +209,7 @@
</span><span class="cx">     gtk_widget_destroy(GTK_WIDGET(m_menu));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if !GTK_CHECK_VERSION(3, 22, 0)
</ins><span class="cx"> void WebContextMenuProxyGtk::menuPositionFunction(GtkMenu* menu, gint* x, gint* y, gboolean* pushIn, WebContextMenuProxyGtk* popupMenu)
</span><span class="cx"> {
</span><span class="cx">     GtkRequisition menuSize;
</span><span class="lines">@@ -220,6 +226,7 @@
</span><span class="cx"> 
</span><span class="cx">     *pushIn = FALSE;
</span><span class="cx"> }
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span><span class="cx"> #endif // ENABLE(CONTEXT_MENUS)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkWebPopupMenuProxyGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp (215189 => 215190)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp        2017-04-10 17:58:58 UTC (rev 215189)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp        2017-04-10 18:06:32 UTC (rev 215190)
</span><span class="lines">@@ -95,9 +95,6 @@
</span><span class="cx"> 
</span><span class="cx">     resetTypeAheadFindState();
</span><span class="cx"> 
</span><del>-    IntPoint menuPosition = convertWidgetPointToScreenPoint(m_webView, rect.location());
-    menuPosition.move(0, rect.height());
-
</del><span class="cx">     // This approach follows the one in gtkcombobox.c.
</span><span class="cx">     GtkRequisition requisition;
</span><span class="cx">     gtk_widget_set_size_request(m_popup, -1, -1);
</span><span class="lines">@@ -104,13 +101,33 @@
</span><span class="cx">     gtk_widget_get_preferred_size(m_popup, &amp;requisition, nullptr);
</span><span class="cx">     gtk_widget_set_size_request(m_popup, std::max(rect.width(), requisition.width), -1);
</span><span class="cx"> 
</span><ins>+    // Reposition the menu after giving it a new width.
+    gtk_menu_reposition(GTK_MENU(m_popup));
+
+#if GTK_CHECK_VERSION(3, 22, 0)
+    // With a recent GTK+ we calculate an offset from the position where the menu would
+    // be normally popped up, and use it as value of the &quot;rect-anchor-dy&quot; property.
+    // The code in gtkcombobox.c starts with the offset hardcoded as -2 as well.
+    IntPoint menuPosition { 0, -2 };
+#else
+    IntPoint menuPosition = convertWidgetPointToScreenPoint(m_webView, rect.location());
+    menuPosition.move(0, rect.height());
+#endif
+
</ins><span class="cx">     if (int itemCount = items.size()) {
</span><span class="cx">         GUniquePtr&lt;GList&gt; children(gtk_container_get_children(GTK_CONTAINER(m_popup)));
</span><span class="cx">         int i;
</span><span class="cx">         GList* child;
</span><span class="cx">         for (i = 0, child = children.get(); i &lt; itemCount; i++, child = g_list_next(child)) {
</span><ins>+#if GTK_CHECK_VERSION(3, 22, 0)
+            // Do not count the last one: we are using the top-left corner of the
+            // item (GDK_GRAVITY_NORTH_WEST) as reference point of the popup.
+            if (i &gt;= selectedIndex)
+                break;
+#else
</ins><span class="cx">             if (i &gt; selectedIndex)
</span><span class="cx">                 break;
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx">             GtkWidget* item = GTK_WIDGET(child-&gt;data);
</span><span class="cx">             GtkRequisition itemRequisition;
</span><span class="lines">@@ -123,6 +140,12 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     const GdkEvent* event = m_client-&gt;currentlyProcessedMouseDownEvent() ? m_client-&gt;currentlyProcessedMouseDownEvent()-&gt;nativeEvent() : nullptr;
</span><ins>+#if GTK_CHECK_VERSION(3, 22, 0)
+    // Set the same properties that GTK+ uses itself for combo box popups.
+    g_object_set(m_popup, &quot;menu-type-hint&quot;, GDK_WINDOW_TYPE_HINT_COMBO, &quot;rect-anchor-dy&quot;, menuPosition.y(), &quot;anchor-hints&quot;, GDK_ANCHOR_SLIDE | GDK_ANCHOR_RESIZE, nullptr);
+    const GdkRectangle referenceRect = { rect.x(), rect.y(), rect.width(), rect.height() };
+    gtk_menu_popup_at_rect(GTK_MENU(m_popup), gtk_widget_get_window(m_webView), &amp;referenceRect, GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST, event);
+#else
</ins><span class="cx">     gtk_menu_popup_for_device(GTK_MENU(m_popup), event ? gdk_event_get_device(event) : nullptr, nullptr, nullptr,
</span><span class="cx">         [](GtkMenu*, gint* x, gint* y, gboolean* pushIn, gpointer userData) {
</span><span class="cx">             // We can pass a pointer to the menuPosition local variable because the nested main loop ensures this is called in the function context.
</span><span class="lines">@@ -132,6 +155,7 @@
</span><span class="cx">             *pushIn = menuPosition-&gt;y() &lt; 0;
</span><span class="cx">         }, &amp;menuPosition, nullptr, event &amp;&amp; event-&gt;type == GDK_BUTTON_PRESS ? event-&gt;button.button : 1,
</span><span class="cx">         event ? gdk_event_get_time(event) : GDK_CURRENT_TIME);
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx">     // Now that the menu has a position, schedule a resize to make sure it's resized to fit vertically in the work area.
</span><span class="cx">     gtk_widget_queue_resize(m_popup);
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (215189 => 215190)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-04-10 17:58:58 UTC (rev 215189)
+++ trunk/Tools/ChangeLog        2017-04-10 18:06:32 UTC (rev 215190)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2017-04-10  Adrian Perez de Castro  &lt;aperez@igalia.com&gt;
+
+        [GTK] Misplaced right click menu on web page due to deprecated gtk_menu_popup()
+        https://bugs.webkit.org/show_bug.cgi?id=170553
+
+        Reviewed by Michael Catanzaro.
+
+        Use gtk_menu_popup_at_pointer() and gtk_menu_popup_at_rect() when
+        building with GTK+ 3.22 or newer. This allows the Wayland GTK+ backend
+        to properly position popup menus, and also avoids using functions
+        which were deprecated starting at that GTK+ release.
+
+        * MiniBrowser/gtk/BrowserSearchBar.c:
+        (searchEntryMenuIconPressedCallback):
+        Update MiniBrowser to use gtk_menu_popup_at_pointer().
+
</ins><span class="cx"> 2017-04-10  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r214403): fast/events/drag-to-navigate.html and fast/events/only-valid-drop-targets-receive-file-drop.html failing
</span></span></pre></div>
<a id="trunkToolsMiniBrowsergtkBrowserSearchBarc"></a>
<div class="modfile"><h4>Modified: trunk/Tools/MiniBrowser/gtk/BrowserSearchBar.c (215189 => 215190)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/MiniBrowser/gtk/BrowserSearchBar.c        2017-04-10 17:58:58 UTC (rev 215189)
+++ trunk/Tools/MiniBrowser/gtk/BrowserSearchBar.c        2017-04-10 18:06:32 UTC (rev 215190)
</span><span class="lines">@@ -93,8 +93,12 @@
</span><span class="cx"> static void searchEntryMenuIconPressedCallback(BrowserSearchBar *searchBar, GtkEntryIconPosition iconPosition, GdkEvent *event)
</span><span class="cx"> {
</span><span class="cx">     if (iconPosition == GTK_ENTRY_ICON_PRIMARY) {
</span><ins>+#if GTK_CHECK_VERSION(3, 22, 0)
+        gtk_menu_popup_at_pointer(GTK_MENU(searchBar-&gt;optionsMenu), event);
+#else
</ins><span class="cx">         GdkEventButton *eventButton = (GdkEventButton *)event;
</span><span class="cx">         gtk_menu_popup(GTK_MENU(searchBar-&gt;optionsMenu), NULL, NULL, NULL, NULL, eventButton-&gt;button, eventButton-&gt;time);
</span><ins>+#endif
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>