[webkit-help] webview failed to be transparent
Jianhua Shao
alex.sjh at gmail.com
Wed Apr 24 00:53:12 PDT 2013
After I replace the following:
GdkPixbuf * pixbuf;
pixbuf = gdk_pixbuf_get_from_drawable( NULL, GTK_WIDGET(view)->window,
rgba, 0, 0, 0, 0, 600, 400 );
gdk_pixbuf_save(pixbuf, "/home/meego/dump.png", "png", NULL, NULL);
with:
cairo_surface_t* surface = webkit_web_view_get_snapshot(view);
cairo_surface_write_to_png(surface, "/home/meego/dump.png");
I got a transparent dump.png...
I am confused, maybe I need to configure some thing in gtk side to achieve
the transparent effect?
On Wed, Apr 24, 2013 at 3:32 PM, Jianhua Shao <alex.sjh at gmail.com> wrote:
>
> I build webkitgtk 1.9.92 by below configuration
> ./configure --prefix=/usr --enable-accelerated-compositing
> --enable-fast-mobile-scrolling --enable-jit --disable-webkit2
> --disable-plugin-process --disable-gtk-doc-html --with-gtk=2.0
> --with-acceleration-backend=opengl
>
> After that, I write a simple app to make the content of webview
> transparent by calling webkit_web_view_set_transparent(). But it failed.
> I tryied version 1.11.5, it also does not work.
> The same app source code works in a old version of gtk-webkit, AFAIK, it
> was about gtk-webkit 1.3.
>
> Why I want to a build a new version of gtk-webkit, is to use the
> compositing accelerating feature.
>
> Anyone know something about this problem?
>
> The test code is here:
> -----------app code---------
> #include <gtk/gtk.h>
> #include <gdk/gdkx.h>
> #include <webkit/webkit.h>
> #include <stdlib.h>
> #include <string.h>
> static void destroy_cb(GtkWidget* widget, gpointer data) {
> gtk_main_quit();
> }
>
> bool transparent = true;
> bool decorate = false;
> int width = 800;
> int height = 480;
> gchar * url = "/home/meego/httproot/htdocs/hmi/hmi/index.html";
> char *window_name = "HMI";
> WebKitWebView* view;
> GdkColormap* rgba;
> GdkScreen* screen;
>
> gint key_press_cb(GtkWidget *widget, GdkEventKey *kevent, gpointer data) {
> GtkWidget *btn = (GtkWidget *)data;
>
> if(kevent->type == GDK_KEY_PRESS && kevent->keyval == 'p') {
>
> GdkPixbuf * pixbuf;
> pixbuf = gdk_pixbuf_get_from_drawable( NULL,
> GTK_WIDGET(view)->window, rgba, 0, 0, 0, 0, 600, 400 );
> gdk_pixbuf_save(pixbuf, "/home/meego/dump.png", "png", NULL, NULL);
> printf("colormap is %s\n", rgba ? "not NULL" : "NULL");
> printf("screen %s compoisted\n", gdk_screen_is_composited(screen)?
> "is" : "is not");
> printf("webview %s transparent\n",
> webkit_web_view_get_transparent(view) ? "is" : "is not");
> }
> return TRUE;
> }
>
> static gboolean window_delete_event(GtkWidget *widget, GdkEvent *event,
> gpointer user_data)
> {
> gtk_widget_destroy(widget);
> gtk_main_quit();
> return TRUE;
> }
>
> int main(int argc, char* argv[]) {
> int ret;
>
> if(argc >= 2) {
> url = argv[1];
> }
> gtk_init(&argc, &argv);
>
> // Create a Window, set colormap to RGBA
> GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> screen = gtk_widget_get_screen(window);
> rgba = gdk_screen_get_rgba_colormap (screen);
>
> gtk_window_set_title(GTK_WINDOW(window), (const gchar*)window_name);
> if (rgba && gdk_screen_is_composited (screen)) {
> gtk_widget_set_default_colormap(rgba);
> gtk_widget_set_colormap(GTK_WIDGET(window), rgba);
> }
>
> gtk_widget_set_size_request(window, width, height);
>
> if(!decorate)
> {
> gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
> }
>
> view = WEBKIT_WEB_VIEW(webkit_web_view_new());
> gtk_widget_set_colormap(GTK_WIDGET(view), rgba);
> if(transparent) {
> if(gdk_screen_is_composited(screen)) {
> printf("set transparent\n");
> webkit_web_view_set_transparent(view, TRUE);
> }
> }
>
> WebKitWebSettings *settings = webkit_web_settings_new();
>
> if(NULL == settings) {
> return -1;
> } else {
> g_object_set (G_OBJECT(settings),
> "enable-file-access-from-file-uris", TRUE, NULL);
> g_object_set (G_OBJECT(settings), "enable-default-context-menu",
> FALSE, NULL);
> webkit_web_view_set_settings (WEBKIT_WEB_VIEW(view), settings);
> }
> gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(view));
>
>
> g_signal_connect(window, "delete-event",
> G_CALLBACK(window_delete_event), NULL);
> g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);
>
> g_signal_connect(G_OBJECT(window), "key_press_event",
> G_CALLBACK(key_press_cb), window);
> //g_signal_emit_by_name(G_OBJECT(window), "activate", NULL);
>
> // Load a default page
> if (g_str_has_prefix(url, "http://")
> || g_str_has_prefix(url, "https://")
> || g_str_has_prefix(url, "file://"))
> {
> webkit_web_view_open(WEBKIT_WEB_VIEW(view), url);
> } else {
> gchar *t_url = NULL;
> if (g_path_is_absolute(url)) {
> t_url = g_strjoin("", "file://", url, NULL);
> } else {
> gchar *pwd = g_get_current_dir();
> t_url = g_strjoin("/", "file://", pwd, url, NULL);
> g_free(pwd);
> }
> webkit_web_view_open(WEBKIT_WEB_VIEW(view), t_url);
> g_free(t_url);
> }
>
> gtk_widget_show_all(window);
> gtk_main();
> return 0;
> }
>
>
> -----------html code-----------
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml"><head>
> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
> <title>Transparency Test</title>
> <style type="text/css">
> /*<![CDATA[*/
> body { background: rgba(220, 220, 0, .5); }
> /*]]>*/
> </style>
> </head>
> <body>
> <p>
> Text on a yellowish, semi-transparent background.
> </p>
>
>
> </body></html>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-help/attachments/20130424/b2bcbf6f/attachment.html>
More information about the webkit-help
mailing list