2008-02-18 Alp Toker <alp@atoker.com>
authoralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Feb 2008 23:03:57 +0000 (23:03 +0000)
committeralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Feb 2008 23:03:57 +0000 (23:03 +0000)
        Reviewed by Mark Rowe.

        http://bugs.webkit.org/show_bug.cgi?id=17312
        [GTK] Webview Transparent Background

        Add support for WebView background transparency.

        * webkit/webkitprivate.h:
        * webkit/webkitwebview.cpp:
        * webkit/webkitwebview.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@30385 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/gtk/ChangeLog
WebKit/gtk/webkit/webkitprivate.h
WebKit/gtk/webkit/webkitwebview.cpp
WebKit/gtk/webkit/webkitwebview.h

index d685d6619483a4f8a32169980a81c2a6b33170bc..409834cfa3d8568ffe2fb3a4d06960ba240831b7 100644 (file)
@@ -1,3 +1,16 @@
+2008-02-18  Alp Toker  <alp@atoker.com>
+
+        Reviewed by Mark Rowe.
+
+        http://bugs.webkit.org/show_bug.cgi?id=17312
+        [GTK] Webview Transparent Background
+
+        Add support for WebView background transparency.
+
+        * webkit/webkitprivate.h:
+        * webkit/webkitwebview.cpp:
+        * webkit/webkitwebview.h:
+
 2008-02-18  Alp Toker  <alp@atoker.com>
 
         Reviewed by Mark Rowe.
index f40a442868be5ceafa94321642292d7de043eaef..5c759280083ebc0b54b62531de37ba53c8310774 100644 (file)
@@ -84,6 +84,8 @@ extern "C" {
 
         GtkTargetList* copy_target_list;
         GtkTargetList* paste_target_list;
+
+        gboolean transparent;
     };
 
     #define WEBKIT_WEB_FRAME_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_FRAME, WebKitWebFramePrivate))
index f9a6e224fc097929f236077f1094a20125d389db..81b196c1db00faaf6ab8ba641da7bce354f2cad8 100644 (file)
@@ -94,7 +94,8 @@ enum {
     PROP_COPY_TARGET_LIST,
     PROP_PASTE_TARGET_LIST,
     PROP_EDITABLE,
-    PROP_SETTINGS
+    PROP_SETTINGS,
+    PROP_TRANSPARENT
 };
 
 static guint webkit_web_view_signals[LAST_SIGNAL] = { 0, };
@@ -212,6 +213,9 @@ static void webkit_web_view_get_property(GObject* object, guint prop_id, GValue*
     case PROP_SETTINGS:
         g_value_set_object(value, webkit_web_view_get_settings(webView));
         break;
+    case PROP_TRANSPARENT:
+        g_value_set_boolean(value, webkit_web_view_get_transparent(webView));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     }
@@ -228,6 +232,9 @@ static void webkit_web_view_set_property(GObject* object, guint prop_id, const G
     case PROP_SETTINGS:
         webkit_web_view_set_settings(webView, WEBKIT_WEB_SETTINGS(g_value_get_object(value)));
         break;
+    case PROP_TRANSPARENT:
+        webkit_web_view_set_transparent(webView, g_value_get_boolean(value));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     }
@@ -236,6 +243,7 @@ static void webkit_web_view_set_property(GObject* object, guint prop_id, const G
 static gboolean webkit_web_view_expose_event(GtkWidget* widget, GdkEventExpose* event)
 {
     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
+    WebKitWebViewPrivate* priv = webView->priv;
 
     Frame* frame = core(webView)->mainFrame();
     GdkRectangle clip;
@@ -245,6 +253,14 @@ static gboolean webkit_web_view_expose_event(GtkWidget* widget, GdkEventExpose*
     ctx.setGdkExposeEvent(event);
     if (frame->renderer()) {
         frame->view()->layoutIfNeededRecursive();
+
+        if (priv->transparent) {
+            cairo_save(cr);
+            cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
+            cairo_paint(cr);
+            cairo_restore(cr);
+        }
+
         frame->view()->paint(&ctx, clip);
     }
     cairo_destroy(cr);
@@ -1079,6 +1095,13 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
                                                          FALSE,
                                                          WEBKIT_PARAM_READWRITE));
 
+    g_object_class_install_property(objectClass, PROP_TRANSPARENT,
+                                    g_param_spec_boolean("transparent",
+                                                         "Transparent",
+                                                         "Whether content has a transparent background",
+                                                         FALSE,
+                                                         WEBKIT_PARAM_READWRITE));
+
     g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate));
 }
 
@@ -1872,4 +1895,44 @@ GtkTargetList* webkit_web_view_get_paste_target_list(WebKitWebView* webView)
     return priv->paste_target_list;
 }
 
+/**
+ * webkit_web_view_get_transparent:
+ * @web_view: a #WebKitWebView
+ *
+ * Returns whether the #WebKitWebView has a transparent background.
+ *
+ * Return value: %FALSE when the #WebKitWebView draws a solid background
+ * (the default), otherwise %TRUE.
+ */
+gboolean webkit_web_view_get_transparent(WebKitWebView* webView)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
+
+    WebKitWebViewPrivate* priv = webView->priv;
+    return priv->transparent;
+}
+
+/**
+ * webkit_web_view_set_transparent:
+ * @web_view: a #WebKitWebView
+ *
+ * Sets whether the #WebKitWebView has a transparent background.
+ *
+ * Pass %FALSE to have the #WebKitWebView draw a solid background
+ * (the default), otherwise %TRUE.
+ */
+void webkit_web_view_set_transparent(WebKitWebView* webView, gboolean flag)
+{
+    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
+
+    WebKitWebViewPrivate* priv = webView->priv;
+    priv->transparent = flag;
+
+    // TODO: This needs to be made persistent or it could become a problem when
+    // the main frame is replaced.
+    Frame* frame = core(webView)->mainFrame();
+    g_return_if_fail(frame);
+    frame->view()->setTransparent(flag);
+}
+
 }
index e19298b671a6c2346a32f05f357dc5eb8b16a1f6..0c5a67573ed74ebc722ea29f6486fef1530ddb5c 100644 (file)
@@ -211,6 +211,12 @@ webkit_web_view_can_go_backward (WebKitWebView* web_view);
 WEBKIT_OBSOLETE_API void
 webkit_web_view_go_backward (WebKitWebView* web_view);
 
+WEBKIT_API gboolean
+webkit_web_view_get_transparent (WebKitWebView* web_view);
+
+WEBKIT_API void
+webkit_web_view_set_transparent (WebKitWebView* web_view, gboolean flag);
+
 G_END_DECLS
 
 #endif