]> spindle.queued.net Git - midori/commitdiff
Implement midori_view_web_view_get_snapshot for GTK+ 3
authorChristian Dywan <christian@twotoasts.de>
Sun, 20 Nov 2011 21:36:55 +0000 (22:36 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sun, 20 Nov 2011 21:36:55 +0000 (22:36 +0100)
midori/midori-view.c

index 5cdeb4dd7badb3b6283b56c5cb920f32f5d30b6f..1c2ef629803f8555e5b46b95f418d6f630b7ef68 100644 (file)
@@ -5217,22 +5217,23 @@ midori_view_web_view_get_snapshot (GtkWidget* web_view,
                                    gint       width,
                                    gint       height)
 {
-    GdkWindow* window;
     GtkAllocation allocation;
     gboolean fast;
     gint x, y, w, h;
     GdkRectangle rect;
     #if !GTK_CHECK_VERSION (3, 0, 0)
+    GdkWindow* window;
     GdkPixmap* pixmap;
     GdkEvent event;
     gboolean result;
     GdkColormap* colormap;
+    #else
+    cairo_surface_t* surface;
+    cairo_t* cr;
     #endif
     GdkPixbuf* pixbuf;
 
     g_return_val_if_fail (WEBKIT_IS_WEB_VIEW (web_view), NULL);
-    window = gtk_widget_get_window (web_view);
-    g_return_val_if_fail (window != NULL, NULL);
 
     gtk_widget_get_allocation (web_view, &allocation);
     x = allocation.x;
@@ -5254,9 +5255,14 @@ midori_view_web_view_get_snapshot (GtkWidget* web_view,
     }
 
     #if GTK_CHECK_VERSION (3, 0, 0)
-    cairo_t* cr = gdk_cairo_create (window);
+    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
+                                          allocation.width, allocation.height);
+    cr = cairo_create (surface);
+    cairo_rectangle (cr, x, y, width, height);
+    cairo_clip (cr);
     gtk_widget_draw (web_view, cr);
-    pixbuf = NULL; /* TODO */
+    pixbuf = gdk_pixbuf_get_from_surface (surface, x, y, width, height);
+    cairo_surface_destroy (surface);
     cairo_destroy (cr);
     #else
     rect.x = x;
@@ -5264,6 +5270,9 @@ midori_view_web_view_get_snapshot (GtkWidget* web_view,
     rect.width = w;
     rect.height = h;
 
+    window = gtk_widget_get_window (web_view);
+    g_return_val_if_fail (window != NULL, NULL);
+
     pixmap = gdk_pixmap_new (window, w, h, gdk_drawable_get_depth (window));
     event.expose.type = GDK_EXPOSE;
     event.expose.window = pixmap;