是否可以使用 WebKit 在清晰的背景上呈现 Web 内容? [英] Is it possible to render web content over a clear background using WebKit?

查看:27
本文介绍了是否可以使用 WebKit 在清晰的背景上呈现 Web 内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试评估 WebKit 补丁的可能性,该补丁将允许所有渲染的图形渲染到完全透明的背景上.

想要的效果是渲染没有任何背景的网页内容,它应该看起来漂浮在桌面上(或任何显示在浏览器窗口后面的东西).

有人见过这样的应用吗?(我可以想到一些可以的终端模拟器.)如果有人在 WebKit 内部工作过(或者可能是 Gecko?),您认为有可能这样做吗?

<小时>

更新:我开始意识到 Mac OSX 仪表板小部件正是使用了这种技术.所以,这一定是可能的.

<小时>

更新 2:我在 linux 上编译了 WebKit,并注意到配置选项包括:

--enable-dashboard-support启用仪表板支持 default=yes

我越来越近了.有人可以帮忙吗?

<小时>

更新 3:我继续在各种相关邮件列表的帖子中找到对此的引用.

  • I'm trying to gauge the possibility of a patch to WebKit which would allow all rendered graphics to be rendered onto a fully transparent background.

    The desired effect is to render web content without any background at all, it should appear to float over the desktop (or whatever is displayed behind the browser window).

    Has anyone seen an app do this? (I can think of some terminal emulators that can.) If anyone has worked inside of WebKit (or possibly Gecko?) do you think it would be possible to do this?


    Update: I've come to realize that Mac OSX dashboard widgets use this exact technique. So, this must be possible.


    Update 2: I've compiled WebKit on linux and noticed the configure options include:

    --enable-dashboard-support
    enable Dashboard support default=yes
    

    I'm getting closer. Can anyone help?


    Update 3: I continue to find references to this in posts on various related mailing lists.

    解决方案

    Solved!

    Through ongoing research, scouring forums and source code repositories, I peiced together the necessary steps to accomplish this using only libwebkit and a standard compiz desktop (any Xorg desktop with compositing should do).

    For a current libwebkit (1.1.10-SVN), there is an Ubuntu PPA:

    deb http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main
    deb-src http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main
    

    As far as the code goes, the key is calling webkit_web_view_set_transparent.

    And of course the system you're running it on should have a capable graphics card (intel, radeon, or nvidia) and be running a compositing window manager (like Compiz).

    And finally, to actually see transparency, the content you're viewing must set a transparent background using CSS3, otherwise it's still completely opaque.

    It's as simple as:

    BODY { background-color: rgba(0,0,0,0); }
    

    Here' is the full sample for the simplest possible webkit browser app, with transparency support:

    #include <gtk/gtk.h>
    #include <webkit/webkit.h>
    
    static void destroy_cb(GtkWidget* widget, gpointer data) {
      gtk_main_quit();
    }
    
    int main(int argc, char* argv[]) {
      gtk_init(&argc, &argv);
    
      if(!g_thread_supported())
        g_thread_init(NULL);
    
      // Create a Window, set colormap to RGBA
      GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      GdkScreen *screen = gtk_widget_get_screen(window);
      GdkColormap *rgba = gdk_screen_get_rgba_colormap (screen);
    
      if (rgba && gdk_screen_is_composited (screen)) {
        gtk_widget_set_default_colormap(rgba);
        gtk_widget_set_colormap(GTK_WIDGET(window), rgba);
      }
    
      gtk_window_set_default_size(GTK_WINDOW(window), 800, 800);
      g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);
    
      // Optional: for dashboard style borderless windows
      gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
    
    
      // Create a WebView, set it transparent, add it to the window
      WebKitWebView* web_view = web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
      webkit_web_view_set_transparent(web_view, TRUE);
      gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(web_view));
    
      // Load a default page
      webkit_web_view_load_uri(web_view, "http://stackoverflow.com/");
    
      // Show it and continue running until the window closes
      gtk_widget_grab_focus(GTK_WIDGET(web_view));
      gtk_widget_show_all(window);
      gtk_main();
      return 0;
    }
    

    这篇关于是否可以使用 WebKit 在清晰的背景上呈现 Web 内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆