~midori/midori/trunk

« back to all changes in this revision

Viewing changes to midori/midori-view.c

  • Committer: Tarmac
  • Author(s): Christian Dywan
  • Date: 2013-06-26 18:40:31 UTC
  • mfrom: (6228.2.1 midori.halfnail2)
  • Revision ID: tarmac-20130626184031-h6tt0nlx1tqknvxs
Improve and unify thumbnail generation

Show diffs side-by-side

added added

removed removed

Lines of Context:
5452
5452
 * Returns: a newly allocated #GdkPixbuf
5453
5453
 *
5454
5454
 * Since: 0.2.1
 
5455
 * Deprecated: 0.5.3
5455
5456
 **/
5456
5457
GdkPixbuf*
5457
5458
midori_view_get_snapshot (MidoriView* view,
5460
5461
{
5461
5462
    g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
5462
5463
 
5463
 
    GdkPixbuf* pixbuf;
5464
 
    #ifdef HAVE_WEBKIT2_A
5465
 
    webkit_web_view_get_snapshot (WEBKIT_WEB_VIEW (view->web_view),
5466
 
        WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE,
5467
 
        NULL, midori_view_get_snapshot_cb, view);
5468
 
    #else
5469
 
    GtkAllocation allocation;
5470
 
    gint x, y;
5471
 
    GdkRectangle rect;
5472
 
    #if !GTK_CHECK_VERSION (3, 0, 0)
5473
 
    gint w, h;
5474
 
    GdkWindow* window;
5475
 
    GdkPixmap* pixmap;
5476
 
    GdkEvent event;
5477
 
    gboolean result;
5478
 
    GdkColormap* colormap;
5479
 
    #else
5480
 
    cairo_surface_t* surface;
5481
 
    cairo_t* cr;
5482
 
    #endif
5483
 
 
5484
 
    gtk_widget_get_allocation (view->web_view, &allocation);
5485
 
    x = allocation.x;
5486
 
    y = allocation.y;
5487
 
 
5488
 
    #if GTK_CHECK_VERSION (3, 0, 0)
5489
 
    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
5490
 
                                          allocation.width, allocation.height);
5491
 
    cr = cairo_create (surface);
5492
 
    cairo_rectangle (cr, x, y, width, height);
5493
 
    cairo_clip (cr);
5494
 
    gtk_widget_draw (view->web_view, cr);
5495
 
    pixbuf = gdk_pixbuf_get_from_surface (surface, x, y, width, height);
5496
 
    cairo_surface_destroy (surface);
5497
 
    cairo_destroy (cr);
5498
 
    #else
5499
 
    w = allocation.width;
5500
 
    h = allocation.height;
5501
 
    rect.x = x;
5502
 
    rect.y = y;
5503
 
    rect.width = w;
5504
 
    rect.height = h;
5505
 
 
5506
 
    window = gtk_widget_get_window (view->web_view);
5507
 
    g_return_val_if_fail (window != NULL, NULL);
5508
 
 
5509
 
    pixmap = gdk_pixmap_new (window, w, h, gdk_drawable_get_depth (window));
5510
 
    event.expose.type = GDK_EXPOSE;
5511
 
    event.expose.window = pixmap;
5512
 
    event.expose.send_event = FALSE;
5513
 
    event.expose.count = 0;
5514
 
    event.expose.area.x = 0;
5515
 
    event.expose.area.y = 0;
5516
 
    gdk_drawable_get_size (GDK_DRAWABLE (window),
5517
 
        &event.expose.area.width, &event.expose.area.height);
5518
 
    event.expose.region = gdk_region_rectangle (&event.expose.area);
5519
 
 
5520
 
    g_signal_emit_by_name (view->web_view, "expose-event", &event, &result);
5521
 
 
5522
 
    colormap = gdk_drawable_get_colormap (pixmap);
5523
 
    pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap, 0, 0,
5524
 
                                           0, 0, rect.width, rect.height);
5525
 
    g_object_unref (pixmap);
5526
 
    #endif
5527
 
    #endif
5528
 
 
5529
 
    GdkPixbuf* scaled = gdk_pixbuf_scale_simple (pixbuf, width, height,
5530
 
        GDK_INTERP_TILES);
5531
 
    g_object_unref (pixbuf);
5532
 
    return scaled;
 
5464
    return view->icon ? g_object_ref (view->icon) : NULL;
5533
5465
}
5534
5466
 
5535
5467
/**