Skip to content

Commit

Permalink
view: Use a rendered frame instead of custom border
Browse files Browse the repository at this point in the history
  • Loading branch information
William Jon McCann authored and raveit65 committed Apr 5, 2018
1 parent bc7af60 commit dc1432d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
64 changes: 37 additions & 27 deletions libview/ev-view.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ typedef struct {


#define SCROLL_TIME 150 #define SCROLL_TIME 150


#define EV_STYLE_CLASS_DOCUMENT_PAGE "document-page"

/*** Scrolling ***/ /*** Scrolling ***/
static void view_update_range_and_current_page (EvView *view); static void view_update_range_and_current_page (EvView *view);
static void ensure_rectangle_is_visible (EvView *view, static void ensure_rectangle_is_visible (EvView *view,
GdkRectangle *rect); GdkRectangle *rect);


/*** Geometry computations ***/ /*** Geometry computations ***/
static void compute_border (EvView *view, static void compute_border (EvView *view,
int width,
int height,
GtkBorder *border); GtkBorder *border);
static void get_page_y_offset (EvView *view, static void get_page_y_offset (EvView *view,
int page, int page,
Expand Down Expand Up @@ -1083,9 +1083,16 @@ ensure_rectangle_is_visible (EvView *view, GdkRectangle *rect)
/*** Geometry computations ***/ /*** Geometry computations ***/


static void static void
compute_border (EvView *view, int width, int height, GtkBorder *border) compute_border (EvView *view, GtkBorder *border)
{ {
ev_document_misc_get_page_border_size (width, height, border); GtkWidget *widget = GTK_WIDGET (view);
GtkStyleContext *context = gtk_widget_get_style_context (widget);
GtkStateFlags state = gtk_widget_get_state_flags (widget);

gtk_style_context_save (context);
gtk_style_context_add_class (context, EV_STYLE_CLASS_DOCUMENT_PAGE);
gtk_style_context_get_border (context, state, border);
gtk_style_context_restore (context);
} }


void void
Expand Down Expand Up @@ -1146,14 +1153,13 @@ ev_view_get_max_page_size (EvView *view,
static void static void
get_page_y_offset (EvView *view, int page, int *y_offset) get_page_y_offset (EvView *view, int page, int *y_offset)
{ {
int max_width, offset = 0; int offset = 0;
GtkBorder border; GtkBorder border;
gboolean odd_left; gboolean odd_left;


g_return_if_fail (y_offset != NULL); g_return_if_fail (y_offset != NULL);


ev_view_get_max_page_size (view, &max_width, NULL); compute_border (view, &border);
compute_border (view, max_width, max_width, &border);


if (is_dual_page (view, &odd_left)) { if (is_dual_page (view, &odd_left)) {
ev_view_get_height_to_page (view, page, NULL, &offset); ev_view_get_height_to_page (view, page, NULL, &offset);
Expand Down Expand Up @@ -1183,7 +1189,7 @@ ev_view_get_page_extents (EvView *view,


/* Get the size of the page */ /* Get the size of the page */
ev_view_get_page_size (view, page, &width, &height); ev_view_get_page_size (view, page, &width, &height);
compute_border (view, width, height, border); compute_border (view, border);
page_area->width = width + border->left + border->right; page_area->width = width + border->left + border->right;
page_area->height = height + border->top + border->bottom; page_area->height = height + border->top + border->bottom;


Expand Down Expand Up @@ -1232,7 +1238,7 @@ ev_view_get_page_extents (EvView *view,
if (height_2 > height) if (height_2 > height)
max_height = height_2; max_height = height_2;
} }
compute_border (view, max_width, max_height, &overall_border); compute_border (view, &overall_border);


/* Find the offsets */ /* Find the offsets */
x = view->spacing; x = view->spacing;
Expand Down Expand Up @@ -3533,7 +3539,7 @@ ev_view_size_request_continuous_dual_page (EvView *view,
GtkBorder border; GtkBorder border;


ev_view_get_max_page_size (view, &max_width, NULL); ev_view_get_max_page_size (view, &max_width, NULL);
compute_border (view, max_width, max_width, &border); compute_border (view, &border);
requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3); requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
} }
break; break;
Expand Down Expand Up @@ -3563,7 +3569,7 @@ ev_view_size_request_continuous (EvView *view,
GtkBorder border; GtkBorder border;


ev_view_get_max_page_size (view, &max_width, NULL); ev_view_get_max_page_size (view, &max_width, NULL);
compute_border (view, max_width, max_width, &border); compute_border (view, &border);
requisition->width = max_width + (view->spacing * 2) + border.left + border.right; requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
} }
break; break;
Expand Down Expand Up @@ -3600,7 +3606,7 @@ ev_view_size_request_dual_page (EvView *view,
height = height_2; height = height_2;
} }
} }
compute_border (view, width, height, &border); compute_border (view, &border);


requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 : requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
((width + border.left + border.right) * 2) + (view->spacing * 3); ((width + border.left + border.right) * 2) + (view->spacing * 3);
Expand All @@ -3622,7 +3628,7 @@ ev_view_size_request_single_page (EvView *view,
} }


ev_view_get_page_size (view, view->current_page, &width, &height); ev_view_get_page_size (view, view->current_page, &width, &height);
compute_border (view, width, height, &border); compute_border (view, &border);


requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 : requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
width + border.left + border.right + (2 * view->spacing); width + border.left + border.right + (2 * view->spacing);
Expand Down Expand Up @@ -5771,10 +5777,10 @@ draw_one_page (EvView *view,
GdkRectangle *expose_area, GdkRectangle *expose_area,
gboolean *page_ready) gboolean *page_ready)
{ {
GdkRectangle overlap; GtkStyleContext *context;
GdkRectangle real_page_area; GdkRectangle overlap;
gint current_page; GdkRectangle real_page_area;
gboolean inverted_colors; gint current_page;


g_assert (view->document); g_assert (view->document);


Expand All @@ -5790,13 +5796,17 @@ draw_one_page (EvView *view,
real_page_area.height -= (border->top + border->bottom); real_page_area.height -= (border->top + border->bottom);
*page_ready = TRUE; *page_ready = TRUE;


context = gtk_widget_get_style_context (GTK_WIDGET (view));
current_page = ev_document_model_get_page (view->model); current_page = ev_document_model_get_page (view->model);
inverted_colors = ev_document_model_get_inverted_colors (view->model);
ev_document_misc_paint_one_page (cr, gtk_style_context_save (context);
GTK_WIDGET (view), gtk_style_context_add_class (context, EV_STYLE_CLASS_DOCUMENT_PAGE);
page_area, border,
page == current_page, if (view->continuous && page == current_page)
inverted_colors); gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);

gtk_render_frame (context, cr, page_area->x, page_area->y, page_area->width, page_area->height);
gtk_style_context_restore (context);


if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) { if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) {
gint width, height; gint width, height;
Expand Down Expand Up @@ -7130,7 +7140,7 @@ ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
doc_height = tmp; doc_height = tmp;
} }


compute_border (view, doc_width, doc_height, &border); compute_border (view, &border);


doc_width *= 2; doc_width *= 2;
width -= (2 * (border.left + border.right) + 3 * view->spacing); width -= (2 * (border.left + border.right) + 3 * view->spacing);
Expand Down Expand Up @@ -7175,7 +7185,7 @@ ev_view_zoom_for_size_continuous (EvView *view,
doc_height = tmp; doc_height = tmp;
} }


compute_border (view, doc_width, doc_height, &border); compute_border (view, &border);


width -= (border.left + border.right + 2 * view->spacing); width -= (border.left + border.right + 2 * view->spacing);
height -= (border.top + border.bottom + 2 * view->spacing - 1); height -= (border.top + border.bottom + 2 * view->spacing - 1);
Expand Down Expand Up @@ -7224,7 +7234,7 @@ ev_view_zoom_for_size_dual_page (EvView *view,
if (height_2 > doc_height) if (height_2 > doc_height)
doc_height = height_2; doc_height = height_2;
} }
compute_border (view, width, height, &border); compute_border (view, &border);


doc_width = doc_width * 2; doc_width = doc_width * 2;
width -= ((border.left + border.right)* 2 + 3 * view->spacing); width -= ((border.left + border.right)* 2 + 3 * view->spacing);
Expand Down Expand Up @@ -7263,7 +7273,7 @@ ev_view_zoom_for_size_single_page (EvView *view,
get_doc_page_size (view, view->current_page, &doc_width, &doc_height); get_doc_page_size (view, view->current_page, &doc_width, &doc_height);


/* Get an approximate border */ /* Get an approximate border */
compute_border (view, width, height, &border); compute_border (view, &border);


width -= (border.left + border.right + 2 * view->spacing); width -= (border.left + border.right + 2 * view->spacing);
height -= (border.top + border.bottom + 2 * view->spacing); height -= (border.top + border.bottom + 2 * view->spacing);
Expand Down
18 changes: 18 additions & 0 deletions shell/atril.css
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
padding: 8px; padding: 8px;
} }


evview.document-page {
border-color: black;
border-style: solid;
border-width: 1px;
border-radius: 0px;
border-image: none;
padding: 0;
}

evview.document-page:active {
border-color: @theme_selected_bg_color;
border-style: solid;
border-width: 1px;
border-radius: 0px;
border-image: none;
padding: 0;
}

evpresentationview { evpresentationview {
background-color: black; background-color: black;
} }
Expand Down

0 comments on commit dc1432d

Please sign in to comment.