- Revision
- 215190
- Author
- commit-qu...@webkit.org
- Date
- 2017-04-10 11:06:32 -0700 (Mon, 10 Apr 2017)
Log Message
[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 <ape...@igalia.com> 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().
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (215189 => 215190)
--- 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)
@@ -1,5 +1,24 @@
2017-04-10 Adrian Perez de Castro <ape...@igalia.com>
+ [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 <ape...@igalia.com>
+
[GTK] Opening a popup menu does not pre-select the active item
https://bugs.webkit.org/show_bug.cgi?id=170680
Modified: trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp (215189 => 215190)
--- 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)
@@ -167,8 +167,13 @@
NativeWebMouseEvent* mouseEvent = m_page->currentlyProcessedMouseDownEvent();
const GdkEvent* event = mouseEvent ? mouseEvent->nativeEvent() : 0;
gtk_menu_attach_to_widget(m_menu, GTK_WIDGET(m_webView), nullptr);
+
+#if GTK_CHECK_VERSION(3, 22, 0)
+ gtk_menu_popup_at_pointer(m_menu, event);
+#else
gtk_menu_popup(m_menu, nullptr, nullptr, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this,
event ? event->button.button : 3, event ? event->button.time : GDK_CURRENT_TIME);
+#endif
}
void WebContextMenuProxyGtk::showContextMenuWithItems(const Vector<WebContextMenuItemData>& items)
@@ -204,6 +209,7 @@
gtk_widget_destroy(GTK_WIDGET(m_menu));
}
+#if !GTK_CHECK_VERSION(3, 22, 0)
void WebContextMenuProxyGtk::menuPositionFunction(GtkMenu* menu, gint* x, gint* y, gboolean* pushIn, WebContextMenuProxyGtk* popupMenu)
{
GtkRequisition menuSize;
@@ -220,6 +226,7 @@
*pushIn = FALSE;
}
+#endif
} // namespace WebKit
#endif // ENABLE(CONTEXT_MENUS)
Modified: trunk/Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp (215189 => 215190)
--- 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)
@@ -95,9 +95,6 @@
resetTypeAheadFindState();
- IntPoint menuPosition = convertWidgetPointToScreenPoint(m_webView, rect.location());
- menuPosition.move(0, rect.height());
-
// This approach follows the one in gtkcombobox.c.
GtkRequisition requisition;
gtk_widget_set_size_request(m_popup, -1, -1);
@@ -104,13 +101,33 @@
gtk_widget_get_preferred_size(m_popup, &requisition, nullptr);
gtk_widget_set_size_request(m_popup, std::max(rect.width(), requisition.width), -1);
+ // 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 "rect-anchor-dy" 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
+
if (int itemCount = items.size()) {
GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(m_popup)));
int i;
GList* child;
for (i = 0, child = children.get(); i < itemCount; i++, child = g_list_next(child)) {
+#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 >= selectedIndex)
+ break;
+#else
if (i > selectedIndex)
break;
+#endif
GtkWidget* item = GTK_WIDGET(child->data);
GtkRequisition itemRequisition;
@@ -123,6 +140,12 @@
}
const GdkEvent* event = m_client->currentlyProcessedMouseDownEvent() ? m_client->currentlyProcessedMouseDownEvent()->nativeEvent() : nullptr;
+#if GTK_CHECK_VERSION(3, 22, 0)
+ // Set the same properties that GTK+ uses itself for combo box popups.
+ g_object_set(m_popup, "menu-type-hint", GDK_WINDOW_TYPE_HINT_COMBO, "rect-anchor-dy", menuPosition.y(), "anchor-hints", 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), &referenceRect, GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST, event);
+#else
gtk_menu_popup_for_device(GTK_MENU(m_popup), event ? gdk_event_get_device(event) : nullptr, nullptr, nullptr,
[](GtkMenu*, gint* x, gint* y, gboolean* pushIn, gpointer userData) {
// We can pass a pointer to the menuPosition local variable because the nested main loop ensures this is called in the function context.
@@ -132,6 +155,7 @@
*pushIn = menuPosition->y() < 0;
}, &menuPosition, nullptr, event && event->type == GDK_BUTTON_PRESS ? event->button.button : 1,
event ? gdk_event_get_time(event) : GDK_CURRENT_TIME);
+#endif
// Now that the menu has a position, schedule a resize to make sure it's resized to fit vertically in the work area.
gtk_widget_queue_resize(m_popup);
Modified: trunk/Tools/ChangeLog (215189 => 215190)
--- trunk/Tools/ChangeLog 2017-04-10 17:58:58 UTC (rev 215189)
+++ trunk/Tools/ChangeLog 2017-04-10 18:06:32 UTC (rev 215190)
@@ -1,3 +1,19 @@
+2017-04-10 Adrian Perez de Castro <ape...@igalia.com>
+
+ [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().
+
2017-04-10 Wenson Hsieh <wenson_hs...@apple.com>
REGRESSION (r214403): fast/events/drag-to-navigate.html and fast/events/only-valid-drop-targets-receive-file-drop.html failing
Modified: trunk/Tools/MiniBrowser/gtk/BrowserSearchBar.c (215189 => 215190)
--- 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)
@@ -93,8 +93,12 @@
static void searchEntryMenuIconPressedCallback(BrowserSearchBar *searchBar, GtkEntryIconPosition iconPosition, GdkEvent *event)
{
if (iconPosition == GTK_ENTRY_ICON_PRIMARY) {
+#if GTK_CHECK_VERSION(3, 22, 0)
+ gtk_menu_popup_at_pointer(GTK_MENU(searchBar->optionsMenu), event);
+#else
GdkEventButton *eventButton = (GdkEventButton *)event;
gtk_menu_popup(GTK_MENU(searchBar->optionsMenu), NULL, NULL, NULL, NULL, eventButton->button, eventButton->time);
+#endif
}
}