Hi all,

I'm working on a program that embeds a somewhat complex widget inside of a WebView, using the create-plugin-widget signal. Everything seems to be working fine, except that the UI isn't updated when widgets are added or removed from the plugin container. Only when the plugin container is resized is everything updated.

Attached is some test-case code. It creates a Window that contains a WebView which contains an <embed> into which goes the rest of the GUI. There are two buttons. The top one adds a label directly below it. However, clicking on it appears to do nothing. Only when the window is resized does the label appear. (And this only happens because the <embed> is set to a percentage size, so it resizes with the window.) The bottom one alternately shows and hides the label below itself. The visibility of the label is immediately updated with clicks, but the space for the label isn't removed/added until the window is resized.

I don't think I'm doing anything wrong GTK-wise. (Please point it out if I am.) This works as expected when the widgets are put directly in the GtkWindow, instead of the WebView. Is this a bug in webkitgtk? Or are additional method calls needed when adding or removing widgets from a plugin? If matters, I'm using webkitgtk 1.10.2 and Gtk 3.4.2.

Thanks,
Robert


// Cleaned up from vala-generated C.  Apologies if it's not idiomatic.

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <webkit/webkit.h>

GtkBox* widget = NULL;
GtkLabel* label = NULL;
gboolean hidden = FALSE;

static void on_destroy (GtkWidget* sender, gpointer self) {
	gtk_main_quit ();
}

static void on_add (GtkButton* sender, gpointer self) {
	GtkLabel* new_label = (GtkLabel*) gtk_label_new ("Peek-a-boo!");
	gtk_box_pack_start (widget, (GtkWidget*) new_label, FALSE, FALSE, (guint) 0);
	gtk_widget_show ((GtkWidget*) new_label);
}

static void on_hide (GtkButton* sender, gpointer self) {
	if (hidden) {
		gtk_widget_show ((GtkWidget*) label);
	} else {
		gtk_widget_hide ((GtkWidget*) label);
	}
	hidden = !hidden;
}

static GtkWidget* on_create_plugin (WebKitWebView* view, const gchar* mime_type, const gchar* uri, GHashTable* param, gpointer self) {
	GtkButton* add;
	GtkButton* hide;
	
	widget = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	add = (GtkButton*) gtk_button_new_from_stock ("gtk-add");
	gtk_box_pack_start (widget, (GtkWidget*) add, FALSE, FALSE, (guint) 0);
	g_signal_connect (add, "clicked", (GCallback) on_add, NULL);
	
	label = (GtkLabel*) gtk_label_new ("Now you see me...");
	gtk_box_pack_end (widget, (GtkWidget*) label, FALSE, FALSE, (guint) 0);
	hide = (GtkButton*) gtk_button_new_with_label ("Toggle hidden");
	gtk_box_pack_end (widget, (GtkWidget*) hide, FALSE, FALSE, (guint) 0);
	g_signal_connect (hide, "clicked", (GCallback) on_hide, NULL);
	gtk_widget_show_all ((GtkWidget*) widget);
	return (GtkWidget*) widget;
}

int main (int argc, char** argv) {
	gchar* HTML;
	GtkWindow* window;
	GtkScrolledWindow* sw;
	WebKitWebView* view;
	
	g_type_init ();
	gtk_init (&argc, &argv);
	
	HTML = g_strdup ("<html><body><embed width='100%' height='90%' type='type' " \
	                 "src='source' style='background: #eee' /></body></html>");
	window = (GtkWindow*) gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect ((GtkWidget*) window, "destroy", (GCallback) on_destroy, NULL);
	gtk_window_set_default_size (window, 300, 400);
	sw = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	view = (WebKitWebView*) webkit_web_view_new ();
	gtk_container_add ((GtkContainer*) sw, (GtkWidget*) view);
	gtk_container_add ((GtkContainer*) window, (GtkWidget*) sw);
	gtk_widget_show_all ((GtkWidget*) window);
	g_signal_connect (view, "create-plugin-widget", (GCallback) on_create_plugin, NULL);
	webkit_web_view_load_string (view, HTML, "text/html", "UTF-8", "");
	gtk_main ();
	return 0;
}
_______________________________________________
webkit-gtk mailing list
webkit-gtk@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-gtk

Reply via email to