<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[178700] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/178700">178700</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2015-01-20 00:29:23 -0800 (Tue, 20 Jan 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] Add an option to create WebKitWebView snapshots with transparent background
https://bugs.webkit.org/show_bug.cgi?id=140617

Reviewed by Gustavo Noronha Silva.

Source/WebKit2:

Add WEBKIT_SNAPSHOT_OPTIONS_TRANSPARENT_BACKGROUND flag to not
fill with white the background before rendering the snapshot.

* UIProcess/API/gtk/WebKitWebView.cpp:
(webkit_web_view_get_snapshot): Pass a TransparentBackground
boolean argument to the WEbProcess.
* UIProcess/API/gtk/WebKitWebView.h:
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
(webkitWebPageDidReceiveMessage): Set the FrameView background as
transparent when TransparentBackground option is True before
rendering the snapshot.

Tools:

* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
(testWebViewSnapshot): Check that the same snapshot with
transparent background is different than the default one filled
with white.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewcpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewh">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessInjectedBundleAPIgtkWebKitWebPagecpp">trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2GtkTestWebKitWebViewcpp">trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (178699 => 178700)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-01-20 08:25:55 UTC (rev 178699)
+++ trunk/Source/WebKit2/ChangeLog        2015-01-20 08:29:23 UTC (rev 178700)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2015-01-20  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [GTK] Add an option to create WebKitWebView snapshots with transparent background
+        https://bugs.webkit.org/show_bug.cgi?id=140617
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Add WEBKIT_SNAPSHOT_OPTIONS_TRANSPARENT_BACKGROUND flag to not
+        fill with white the background before rendering the snapshot.
+
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkit_web_view_get_snapshot): Pass a TransparentBackground
+        boolean argument to the WEbProcess.
+        * UIProcess/API/gtk/WebKitWebView.h:
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
+        (webkitWebPageDidReceiveMessage): Set the FrameView background as
+        transparent when TransparentBackground option is True before
+        rendering the snapshot.
+
</ins><span class="cx"> 2015-01-19  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] Add API to change the WebKitWebView background color
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (178699 => 178700)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp        2015-01-20 08:25:55 UTC (rev 178699)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp        2015-01-20 08:29:23 UTC (rev 178700)
</span><span class="lines">@@ -3475,6 +3475,7 @@
</span><span class="cx">     message.set(String::fromUTF8(&quot;SnapshotOptions&quot;), API::UInt64::create(static_cast&lt;uint64_t&gt;(webKitSnapshotOptionsToSnapshotOptions(options))));
</span><span class="cx">     message.set(String::fromUTF8(&quot;SnapshotRegion&quot;), API::UInt64::create(static_cast&lt;uint64_t&gt;(toSnapshotRegion(region))));
</span><span class="cx">     message.set(String::fromUTF8(&quot;CallbackID&quot;), API::UInt64::create(callbackID));
</span><ins>+    message.set(String::fromUTF8(&quot;TransparentBackground&quot;), API::Boolean::create(options &amp; WEBKIT_SNAPSHOT_OPTIONS_TRANSPARENT_BACKGROUND));
</ins><span class="cx"> 
</span><span class="cx">     webView-&gt;priv-&gt;snapshotResultsMap.set(callbackID, adoptGRef(g_task_new(webView, cancellable, callback, userData)));
</span><span class="cx">     getPage(webView)-&gt;postMessageToInjectedBundle(String::fromUTF8(&quot;GetSnapshot&quot;), API::Dictionary::create(WTF::move(message)).get());
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (178699 => 178700)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h        2015-01-20 08:25:55 UTC (rev 178699)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h        2015-01-20 08:29:23 UTC (rev 178700)
</span><span class="lines">@@ -156,6 +156,8 @@
</span><span class="cx">  * @WEBKIT_SNAPSHOT_OPTIONS_NONE: Do not include any special options.
</span><span class="cx">  * @WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING: Whether to include in the
</span><span class="cx">  * snapshot the highlight of the selected content.
</span><ins>+ * @WEBKIT_SNAPSHOT_OPTIONS_TRANSPARENT_BACKGROUND: Do not fill the background with white before
+ * rendering the snapshot. Since 2.8
</ins><span class="cx">  *
</span><span class="cx">  * Enum values used to specify options when taking a snapshot
</span><span class="cx">  * from a #WebKitWebView.
</span><span class="lines">@@ -163,6 +165,7 @@
</span><span class="cx"> typedef enum {
</span><span class="cx">   WEBKIT_SNAPSHOT_OPTIONS_NONE = 0,
</span><span class="cx">   WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING = 1 &lt;&lt; 0,
</span><ins>+  WEBKIT_SNAPSHOT_OPTIONS_TRANSPARENT_BACKGROUND = 1 &lt;&lt; 1,
</ins><span class="cx"> } WebKitSnapshotOptions;
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessInjectedBundleAPIgtkWebKitWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp (178699 => 178700)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp        2015-01-20 08:25:55 UTC (rev 178699)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp        2015-01-20 08:29:23 UTC (rev 178700)
</span><span class="lines">@@ -454,6 +454,7 @@
</span><span class="cx">         SnapshotOptions snapshotOptions = static_cast&lt;SnapshotOptions&gt;(static_cast&lt;API::UInt64*&gt;(message.get(&quot;SnapshotOptions&quot;))-&gt;value());
</span><span class="cx">         uint64_t callbackID = static_cast&lt;API::UInt64*&gt;(message.get(&quot;CallbackID&quot;))-&gt;value();
</span><span class="cx">         SnapshotRegion region = static_cast&lt;SnapshotRegion&gt;(static_cast&lt;API::UInt64*&gt;(message.get(&quot;SnapshotRegion&quot;))-&gt;value());
</span><ins>+        bool transparentBackground = static_cast&lt;API::Boolean*&gt;(message.get(&quot;TransparentBackground&quot;))-&gt;value();
</ins><span class="cx"> 
</span><span class="cx">         RefPtr&lt;WebImage&gt; snapshotImage;
</span><span class="cx">         WebPage* webPage = page-&gt;priv-&gt;webPage;
</span><span class="lines">@@ -469,8 +470,16 @@
</span><span class="cx">             default:
</span><span class="cx">                 ASSERT_NOT_REACHED();
</span><span class="cx">             }
</span><del>-            if (!snapshotRect.isEmpty())
</del><ins>+            if (!snapshotRect.isEmpty()) {
+                Color savedBackgroundColor;
+                if (transparentBackground) {
+                    savedBackgroundColor = frameView-&gt;baseBackgroundColor();
+                    frameView-&gt;setBaseBackgroundColor(Color::transparent);
+                }
</ins><span class="cx">                 snapshotImage = webPage-&gt;scaledSnapshotWithOptions(snapshotRect, 1, snapshotOptions | SnapshotOptionsShareable);
</span><ins>+                if (transparentBackground)
+                    frameView-&gt;setBaseBackgroundColor(savedBackgroundColor);
+            }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         API::Dictionary::MapType messageReply;
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (178699 => 178700)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-01-20 08:25:55 UTC (rev 178699)
+++ trunk/Tools/ChangeLog        2015-01-20 08:29:23 UTC (rev 178700)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2015-01-20  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [GTK] Add an option to create WebKitWebView snapshots with transparent background
+        https://bugs.webkit.org/show_bug.cgi?id=140617
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
+        (testWebViewSnapshot): Check that the same snapshot with
+        transparent background is different than the default one filled
+        with white.
+
</ins><span class="cx"> 2015-01-19  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] Add API to change the WebKitWebView background color
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2GtkTestWebKitWebViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp (178699 => 178700)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp        2015-01-20 08:25:55 UTC (rev 178699)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp        2015-01-20 08:29:23 UTC (rev 178700)
</span><span class="lines">@@ -581,6 +581,13 @@
</span><span class="cx">     g_assert_cmpint(cairo_image_surface_get_width(surface1), ==, cairo_image_surface_get_width(surface2));
</span><span class="cx">     g_assert_cmpint(cairo_image_surface_get_height(surface1), ==, cairo_image_surface_get_height(surface2));
</span><span class="cx">     g_assert(!Test::cairoSurfacesEqual(surface1, surface2));
</span><ins>+
+    // Get a snpashot with a transparent background, the result must be different.
+    surface2 = test-&gt;getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_TRANSPARENT_BACKGROUND);
+    g_assert_cmpuint(cairo_surface_get_type(surface2), ==, CAIRO_SURFACE_TYPE_IMAGE);
+    g_assert_cmpint(cairo_image_surface_get_width(surface1), ==, cairo_image_surface_get_width(surface2));
+    g_assert_cmpint(cairo_image_surface_get_height(surface1), ==, cairo_image_surface_get_height(surface2));
+    g_assert(!Test::cairoSurfacesEqual(surface1, surface2));
</ins><span class="cx">     cairo_surface_destroy(surface1);
</span><span class="cx"> 
</span><span class="cx">     // Test that cancellation works.
</span></span></pre>
</div>
</div>

</body>
</html>