|
25 | 25 | #include "WebKitContextMenuItem.h" |
26 | 26 | #include "WebKitContextMenuItemPrivate.h" |
27 | 27 | #include "WebKitContextMenuPrivate.h" |
| 28 | +#include <WebCore/IntPoint.h> |
28 | 29 | #include <wtf/glib/GRefPtr.h> |
29 | 30 | #include <wtf/glib/WTFGType.h> |
30 | 31 |
|
@@ -67,6 +68,7 @@ struct _WebKitContextMenuPrivate { |
67 | 68 | GUniquePtr<GdkEvent> event; |
68 | 69 | #endif |
69 | 70 | #endif |
| 71 | + std::optional<WebCore::IntPoint> position; |
70 | 72 | }; |
71 | 73 |
|
72 | 74 | WEBKIT_DEFINE_FINAL_TYPE(WebKitContextMenu, webkit_context_menu, G_TYPE_OBJECT, GObject) |
@@ -130,6 +132,11 @@ WebKitContextMenuItem* webkitContextMenuGetParentItem(WebKitContextMenu* menu) |
130 | 132 | { |
131 | 133 | return menu->priv->parentItem; |
132 | 134 | } |
| 135 | + |
| 136 | +void webkitContextMenuSetPosition(WebKitContextMenu* menu, const WebCore::IntPoint& position) |
| 137 | +{ |
| 138 | + menu->priv->position = position; |
| 139 | +} |
133 | 140 | #endif // ENABLE(CONTEXT_MENUS) |
134 | 141 |
|
135 | 142 | /** |
@@ -434,3 +441,33 @@ GdkEvent* webkit_context_menu_get_event(WebKitContextMenu* menu) |
434 | 441 | return menu->priv->event.get(); |
435 | 442 | } |
436 | 443 | #endif |
| 444 | + |
| 445 | +/** |
| 446 | + * webkit_context_menu_get_position: |
| 447 | + * @menu: a #WebKitContextMenu |
| 448 | + * @x: (out) (optional): return location for the x coordinate |
| 449 | + * @y: (out) (optional): return location for the y coordinate |
| 450 | + * |
| 451 | + * Gets the position in view coordinates where the context menu was triggered. |
| 452 | + * |
| 453 | + * This function only returns valid coordinates when called for a #WebKitContextMenu |
| 454 | + * passed to #WebKitWebView::context-menu signal. |
| 455 | + * |
| 456 | + * Returns: %TRUE if valid position coordinates are available, %FALSE otherwise |
| 457 | + * |
| 458 | + * Since: 2.52 |
| 459 | + */ |
| 460 | +gboolean webkit_context_menu_get_position(WebKitContextMenu* menu, gint* x, gint* y) |
| 461 | +{ |
| 462 | + g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU(menu), FALSE); |
| 463 | + |
| 464 | + if (!menu->priv->position) |
| 465 | + return FALSE; |
| 466 | + |
| 467 | + if (x) |
| 468 | + *x = menu->priv->position->x(); |
| 469 | + if (y) |
| 470 | + *y = menu->priv->position->y(); |
| 471 | + |
| 472 | + return TRUE; |
| 473 | +} |
0 commit comments