Commit 30d1c3f4 authored by William Jon McCann's avatar William Jon McCann Committed by Carlos Garcia Campos
Browse files

libdocument: Allow sidebar thumbnails to be styled with CSS

https://bugzilla.gnome.org/show_bug.cgi?id=653294
parent bb65a882
......@@ -110,6 +110,78 @@ ev_document_misc_get_loading_thumbnail (int width,
return create_thumbnail_frame (width, height, NULL, !inverted_colors);
}
static GdkPixbuf *
ev_document_misc_render_thumbnail_frame (GtkWidget *widget,
int width,
int height,
gboolean inverted_colors,
GdkPixbuf *source_pixbuf)
{
GtkStyleContext *context = gtk_widget_get_style_context (widget);
GtkStateFlags state = gtk_widget_get_state_flags (widget);
int width_r, height_r;
int width_f, height_f;
cairo_surface_t *surface;
cairo_t *cr;
GtkBorder border = {0, };
GdkPixbuf *retval;
if (source_pixbuf) {
g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
width_r = gdk_pixbuf_get_width (source_pixbuf);
height_r = gdk_pixbuf_get_height (source_pixbuf);
} else {
width_r = width;
height_r = height;
}
gtk_style_context_save (context);
gtk_style_context_add_class (context, "page-thumbnail");
if (inverted_colors)
gtk_style_context_add_class (context, "inverted");
gtk_style_context_get_border (context, state, &border);
width_f = width_r + border.left + border.right;
height_f = height_r + border.top + border.bottom;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
width_f, height_f);
cr = cairo_create (surface);
if (source_pixbuf) {
gdk_cairo_set_source_pixbuf (cr, source_pixbuf, border.left, border.top);
cairo_paint (cr);
} else {
gtk_render_background (context, cr, 0, 0, width_f, height_f);
}
gtk_render_frame (context, cr, 0, 0, width_f, height_f);
cairo_destroy (cr);
gtk_style_context_restore (context);
retval = gdk_pixbuf_get_from_surface (surface, 0, 0, width_f, height_f);
cairo_surface_destroy (surface);
return retval;
}
GdkPixbuf *
ev_document_misc_render_loading_thumbnail (GtkWidget *widget,
int width,
int height,
gboolean inverted_colors)
{
return ev_document_misc_render_thumbnail_frame (widget, width, height, inverted_colors, NULL);
}
GdkPixbuf *
ev_document_misc_render_thumbnail_with_frame (GtkWidget *widget,
GdkPixbuf *source_pixbuf)
{
return ev_document_misc_render_thumbnail_frame (widget, -1, -1, FALSE, source_pixbuf);
}
void
ev_document_misc_get_page_border_size (gint page_width,
gint page_height,
......
......@@ -34,12 +34,22 @@
G_BEGIN_DECLS
EV_DEPRECATED
GdkPixbuf *ev_document_misc_get_thumbnail_frame (int width,
int height,
GdkPixbuf *source_pixbuf);
EV_DEPRECATED
GdkPixbuf *ev_document_misc_get_loading_thumbnail (int width,
int height,
gboolean inverted_colors);
GdkPixbuf *ev_document_misc_render_loading_thumbnail (GtkWidget *widget,
int width,
int height,
gboolean inverted_colors);
GdkPixbuf *ev_document_misc_render_thumbnail_with_frame (GtkWidget *widget,
GdkPixbuf *source_pixbuf);
EV_DEPRECATED
void ev_document_misc_get_page_border_size (gint page_width,
gint page_height,
......
......@@ -314,7 +314,8 @@ ev_sidebar_thumbnails_get_loading_icon (EvSidebarThumbnails *sidebar_thumbnails,
gboolean inverted_colors;
inverted_colors = ev_document_model_get_inverted_colors (priv->model);
icon = ev_document_misc_get_loading_thumbnail (width, height, inverted_colors);
icon = ev_document_misc_render_loading_thumbnail (GTK_WIDGET (sidebar_thumbnails),
width, height, inverted_colors);
g_hash_table_insert (priv->loading_icons, key, icon);
} else {
g_free (key);
......@@ -418,6 +419,7 @@ add_range (EvSidebarThumbnails *sidebar_thumbnails,
job = ev_job_thumbnail_new (priv->document,
page, priv->rotation,
get_scale_for_page (sidebar_thumbnails, page));
ev_job_thumbnail_set_has_frame (EV_JOB_THUMBNAIL (job), FALSE);
ev_job_scheduler_push_job (EV_JOB (job), EV_JOB_PRIORITY_HIGH);
g_object_set_data_full (G_OBJECT (job), "tree_iter",
......@@ -814,17 +816,21 @@ thumbnail_job_completed_callback (EvJobThumbnail *job,
EvSidebarThumbnails *sidebar_thumbnails)
{
EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
GtkTreeIter *iter;
GtkTreeIter *iter;
GdkPixbuf *pixbuf;
pixbuf = ev_document_misc_render_thumbnail_with_frame (GTK_WIDGET (sidebar_thumbnails), job->thumbnail);
iter = (GtkTreeIter *) g_object_get_data (G_OBJECT (job), "tree_iter");
if (priv->inverted_colors)
ev_document_misc_invert_pixbuf (job->thumbnail);
ev_document_misc_invert_pixbuf (pixbuf);
gtk_list_store_set (priv->list_store,
iter,
COLUMN_PIXBUF, job->thumbnail,
COLUMN_PIXBUF, pixbuf,
COLUMN_THUMBNAIL_SET, TRUE,
COLUMN_JOB, NULL,
-1);
g_object_unref (pixbuf);
}
static void
......
......@@ -40,3 +40,17 @@ EvView.document-page:active {
EvView.document-page.inverted {
background-color: black;
}
EvSidebarThumbnails.page-thumbnail {
background-color: white;
border-color: black;
border-style: solid;
border-width: 1px;
border-radius: 0px;
border-image: none;
padding: 0;
}
EvSidebarThumbnails.page-thumbnail.inverted {
background-color: black;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment