[epiphany/pgriffis/web-extension-beastify: 1/6] webextensions: Dynamically create popup action
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/pgriffis/web-extension-beastify: 1/6] webextensions: Dynamically create popup action
- Date: Sat, 21 May 2022 01:43:03 +0000 (UTC)
commit 68a3764cfe3a060c85f46f49166475118851b2cb
Author: Patrick Griffis <pgriffis igalia com>
Date: Fri May 13 12:32:00 2022 -0500
webextensions: Dynamically create popup action
This is not intended to be a long lived web view.
src/webextension/ephy-web-extension-manager.c | 32 ++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/src/webextension/ephy-web-extension-manager.c b/src/webextension/ephy-web-extension-manager.c
index 128206d40..9babbec6c 100644
--- a/src/webextension/ephy-web-extension-manager.c
+++ b/src/webextension/ephy-web-extension-manager.c
@@ -693,23 +693,23 @@ static GtkWidget *
create_browser_popup (EphyWebExtension *web_extension)
{
GtkWidget *web_view;
- GtkWidget *popover;
g_autofree char *data = NULL;
g_autofree char *base_uri = NULL;
const char *popup;
- popover = gtk_popover_new (NULL);
-
+ popup = ephy_web_extension_get_browser_popup (web_extension);
+ data = ephy_web_extension_get_resource_as_string (web_extension, popup);
+ if (!data)
+ return NULL;
web_view = create_web_extensions_webview (web_extension);
popup = ephy_web_extension_get_browser_popup (web_extension);
base_uri = create_base_uri_for_resource_path (web_extension, popup);
data = ephy_web_extension_get_resource_as_string (web_extension, popup);
webkit_web_view_load_html (WEBKIT_WEB_VIEW (web_view), (char *)data, base_uri);
- gtk_container_add (GTK_CONTAINER (popover), web_view);
gtk_widget_show_all (web_view);
- return popover;
+ return web_view;
}
static gboolean
@@ -732,6 +732,25 @@ on_browser_action_clicked (GtkWidget *event_box,
return GDK_EVENT_STOP;
}
+static void
+on_browser_action_visible_changed (GtkWidget *popover,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ EphyWebExtension *web_extension = EPHY_WEB_EXTENSION(user_data);
+ GtkWidget *child;
+
+ if (gtk_widget_get_visible (popover)) {
+ child = create_browser_popup (web_extension);
+ gtk_container_add (GTK_CONTAINER (popover), child);
+ /* FIXME: We need to dynamically resize the popover.
+ * However the webview never emits "ready-to-show" and the window-properties geometry is always 0. */
+ gtk_widget_set_size_request (child, 800, 600);
+ } else {
+ child = gtk_bin_get_child (GTK_BIN (popover));
+ gtk_container_remove (GTK_CONTAINER (popover), child);
+ }
+}
GtkWidget *
create_browser_action (EphyWebExtension *web_extension)
@@ -743,7 +762,8 @@ create_browser_action (EphyWebExtension *web_extension)
if (ephy_web_extension_get_browser_popup (web_extension)) {
button = gtk_menu_button_new ();
image = gtk_image_new_from_pixbuf (ephy_web_extension_browser_action_get_icon (web_extension, 16));
- popover = create_browser_popup (web_extension);
+ popover = gtk_popover_new (NULL);
+ g_signal_connect (popover, "notify::visible", G_CALLBACK (on_browser_action_visible_changed),
web_extension);
gtk_menu_button_set_popover (GTK_MENU_BUTTON (button), popover);
gtk_button_set_image (GTK_BUTTON (button), image);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]