summaryrefslogtreecommitdiff
path: root/libview/ev-view.c
diff options
context:
space:
mode:
authorMarek Kasik <[email protected]>2016-05-09 12:57:20 +0200
committerraveit65 <[email protected]>2017-08-18 21:18:30 +0200
commit67fccc6b5f7f8007ecbfaa98c4284ef9a2643b3b (patch)
tree1266deb37d01fbffbc728102c8fcade8f54a3fe7 /libview/ev-view.c
parentab44eb6f7808eaf9fddbf6a248cd227122593d5b (diff)
downloadatril-67fccc6b5f7f8007ecbfaa98c4284ef9a2643b3b.tar.bz2
atril-67fccc6b5f7f8007ecbfaa98c4284ef9a2643b3b.tar.xz
libview: Scroll small pages in non-continuous mode
Check whether currently shown page fits actual view and allow user to scroll to previous/next page in that case (also in Dual page mode). Allow also scrolling if only one axis fits the view and the event happenned in the same axis. https://bugzilla.gnome.org/show_bug.cgi?id=562257 origin commit links: https://git.gnome.org/browse/evince/commit/?id=077bab6 https://git.gnome.org/browse/evince/commit/?id=45f527e
Diffstat (limited to 'libview/ev-view.c')
-rw-r--r--libview/ev-view.c96
1 files changed, 82 insertions, 14 deletions
diff --git a/libview/ev-view.c b/libview/ev-view.c
index b7a5335e..2007dd56 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -247,6 +247,8 @@ static void ev_view_zoom_for_size_dual_page (EvView *view,
static void ev_view_zoom_for_size_single_page (EvView *view,
int width,
int height);
+static gboolean ev_view_page_fits (EvView *view,
+ GtkOrientation orientation);
/*** Cursors ***/
static void ev_view_set_cursor (EvView *view,
EvViewCursor new_cursor);
@@ -884,7 +886,8 @@ ev_view_scroll (EvView *view,
view->jump_to_find_result = FALSE;
- if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ if ((!horizontal && ev_view_page_fits (view, GTK_ORIENTATION_VERTICAL)) ||
+ (horizontal && ev_view_page_fits (view, GTK_ORIENTATION_HORIZONTAL))) {
switch (scroll) {
case GTK_SCROLL_PAGE_BACKWARD:
case GTK_SCROLL_STEP_BACKWARD:
@@ -3286,6 +3289,7 @@ ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
{
EvView *view = EV_VIEW (widget);
guint state;
+ gboolean fit_width, fit_height;
state = event->state & gtk_accelerator_get_default_mod_mask ();
@@ -3342,34 +3346,57 @@ ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
state &= ~GDK_SHIFT_MASK;
}
- if (state == 0 && view->sizing_mode == EV_SIZING_BEST_FIT && !view->continuous) {
+ fit_width = ev_view_page_fits (view, GTK_ORIENTATION_HORIZONTAL);
+ fit_height = ev_view_page_fits (view, GTK_ORIENTATION_VERTICAL);
+ if (state == 0 && !view->continuous && (fit_width || fit_height)) {
switch (event->direction) {
case GDK_SCROLL_DOWN:
+ if (fit_height) {
+ ev_view_next_page (view);
+ return TRUE;
+ }
+ break;
case GDK_SCROLL_RIGHT:
- ev_view_next_page (view);
+ if (fit_width) {
+ ev_view_next_page (view);
+ return TRUE;
+ }
break;
case GDK_SCROLL_UP:
+ if (fit_height) {
+ ev_view_previous_page (view);
+ return TRUE;
+ }
+ break;
case GDK_SCROLL_LEFT:
- ev_view_previous_page (view);
+ if (fit_width) {
+ ev_view_previous_page (view);
+ return TRUE;
+ }
break;
case GDK_SCROLL_SMOOTH: {
gdouble decrement;
+ if ((fit_width && fit_height) ||
+ ((fit_height && event->delta_x == 0.0) ||
+ (fit_width && event->delta_y == 0.0))) {
+ /* Emulate normal scrolling by summing the deltas */
+ view->total_delta += event->delta_x + event->delta_y;
+
+ decrement = view->total_delta < 0 ? -1.0 : 1.0;
+ for (; fabs (view->total_delta) >= 1.0; view->total_delta -= decrement) {
+ if (decrement < 0)
+ ev_view_previous_page (view);
+ else
+ ev_view_next_page (view);
+ }
- /* Emulate normal scrolling by summing the deltas */
- view->total_delta += event->delta_x + event->delta_y;
-
- decrement = view->total_delta < 0 ? -1.0 : 1.0;
- for (; fabs (view->total_delta) >= 1.0; view->total_delta -= decrement) {
- if (decrement < 0)
- ev_view_previous_page (view);
- else
- ev_view_next_page (view);
+ return TRUE;
}
}
break;
}
- return TRUE;
+ return FALSE;
}
return FALSE;
@@ -5846,6 +5873,47 @@ ev_view_zoom_for_size (EvView *view,
ev_view_zoom_for_size_single_page (view, width, height);
}
+static gboolean
+ev_view_page_fits (EvView *view,
+ GtkOrientation orientation)
+{
+ GtkRequisition requisition;
+ GtkAllocation allocation;
+ double size;
+
+ if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ return TRUE;
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL &&
+ (view->sizing_mode == EV_SIZING_FIT_WIDTH))
+ return TRUE;
+
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
+ ev_view_size_request (GTK_WIDGET (view), &requisition);
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
+ if (requisition.width == 1) {
+ size = 1.0;
+ } else {
+ if (allocation.width > 0.0)
+ size = (double) requisition.width / allocation.width;
+ else
+ size = 1.0;
+ }
+ } else {
+ if (requisition.height == 1) {
+ size = 1.0;
+ } else {
+ if (allocation.height > 0.0)
+ size = (double) requisition.height / allocation.height;
+ else
+ size = 1.0;
+ }
+ }
+
+ return size <= 1.0;
+}
+
/*** Find ***/
static gint
ev_view_find_get_n_results (EvView *view, gint page)