|
|
d6c6b3 |
From 511ab26917ed9e856ebbc8f764a5b68613ebc1cd Mon Sep 17 00:00:00 2001
|
|
|
d6c6b3 |
From: Marek Kasik <mkasik@redhat.com>
|
|
|
d6c6b3 |
Date: Mon, 9 May 2016 12:57:20 +0200
|
|
|
d6c6b3 |
Subject: [PATCH] libview: Scroll small pages in non-continuous mode
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
Check whether currently shown page fits actual view and allow user to scroll
|
|
|
d6c6b3 |
to previous/next page in that case (also in Dual page mode).
|
|
|
d6c6b3 |
Allow also scrolling if only one axis fits the view and the event
|
|
|
d6c6b3 |
happenned in the same axis.
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
https://bugzilla.gnome.org/show_bug.cgi?id=562257
|
|
|
d6c6b3 |
---
|
|
|
d6c6b3 |
libview/ev-view.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++--------
|
|
|
d6c6b3 |
1 file changed, 83 insertions(+), 14 deletions(-)
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
diff --git a/libview/ev-view.c b/libview/ev-view.c
|
|
|
d6c6b3 |
index f76eca8..f96ad4b 100644
|
|
|
d6c6b3 |
--- a/libview/ev-view.c
|
|
|
d6c6b3 |
+++ b/libview/ev-view.c
|
|
|
d6c6b3 |
@@ -247,6 +247,8 @@ static void ev_view_zoom_for_size_dual_page (EvView *view,
|
|
|
d6c6b3 |
static void ev_view_zoom_for_size_single_page (EvView *view,
|
|
|
d6c6b3 |
int width,
|
|
|
d6c6b3 |
int height);
|
|
|
d6c6b3 |
+static gboolean ev_view_page_fits (EvView *view,
|
|
|
d6c6b3 |
+ GtkOrientation orientation);
|
|
|
d6c6b3 |
/*** Cursors ***/
|
|
|
d6c6b3 |
static void ev_view_set_cursor (EvView *view,
|
|
|
d6c6b3 |
EvViewCursor new_cursor);
|
|
|
d6c6b3 |
@@ -973,7 +998,8 @@ ev_view_scroll (EvView *view,
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
view->jump_to_find_result = FALSE;
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
- if (view->sizing_mode == EV_SIZING_FIT_PAGE) {
|
|
|
d6c6b3 |
+ if ((!horizontal && ev_view_page_fits (view, GTK_ORIENTATION_VERTICAL)) ||
|
|
|
d6c6b3 |
+ (horizontal && ev_view_page_fits (view, GTK_ORIENTATION_HORIZONTAL))) {
|
|
|
d6c6b3 |
switch (scroll) {
|
|
|
d6c6b3 |
case GTK_SCROLL_PAGE_BACKWARD:
|
|
|
d6c6b3 |
case GTK_SCROLL_STEP_BACKWARD:
|
|
|
d6c6b3 |
@@ -3972,6 +4116,7 @@ ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
|
|
|
d6c6b3 |
{
|
|
|
d6c6b3 |
EvView *view = EV_VIEW (widget);
|
|
|
d6c6b3 |
guint state;
|
|
|
d6c6b3 |
+ gboolean fit_width, fit_height;
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
state = event->state & gtk_accelerator_get_default_mod_mask ();
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
@@ -4026,34 +4174,57 @@ ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
|
|
|
d6c6b3 |
state &= ~GDK_SHIFT_MASK;
|
|
|
d6c6b3 |
}
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
- if (state == 0 && view->sizing_mode == EV_SIZING_FIT_PAGE && !view->continuous) {
|
|
|
d6c6b3 |
+ fit_width = ev_view_page_fits (view, GTK_ORIENTATION_HORIZONTAL);
|
|
|
d6c6b3 |
+ fit_height = ev_view_page_fits (view, GTK_ORIENTATION_VERTICAL);
|
|
|
d6c6b3 |
+ if (state == 0 && !view->continuous && (fit_width || fit_height)) {
|
|
|
d6c6b3 |
switch (event->direction) {
|
|
|
d6c6b3 |
case GDK_SCROLL_DOWN:
|
|
|
d6c6b3 |
+ if (fit_height) {
|
|
|
d6c6b3 |
+ ev_view_next_page (view);
|
|
|
d6c6b3 |
+ return TRUE;
|
|
|
d6c6b3 |
+ }
|
|
|
d6c6b3 |
+ break;
|
|
|
d6c6b3 |
case GDK_SCROLL_RIGHT:
|
|
|
d6c6b3 |
- ev_view_next_page (view);
|
|
|
d6c6b3 |
+ if (fit_width) {
|
|
|
d6c6b3 |
+ ev_view_next_page (view);
|
|
|
d6c6b3 |
+ return TRUE;
|
|
|
d6c6b3 |
+ }
|
|
|
d6c6b3 |
break;
|
|
|
d6c6b3 |
case GDK_SCROLL_UP:
|
|
|
d6c6b3 |
+ if (fit_height) {
|
|
|
d6c6b3 |
+ ev_view_previous_page (view);
|
|
|
d6c6b3 |
+ return TRUE;
|
|
|
d6c6b3 |
+ }
|
|
|
d6c6b3 |
+ break;
|
|
|
d6c6b3 |
case GDK_SCROLL_LEFT:
|
|
|
d6c6b3 |
- ev_view_previous_page (view);
|
|
|
d6c6b3 |
+ if (fit_width) {
|
|
|
d6c6b3 |
+ ev_view_previous_page (view);
|
|
|
d6c6b3 |
+ return TRUE;
|
|
|
d6c6b3 |
+ }
|
|
|
d6c6b3 |
break;
|
|
|
d6c6b3 |
case GDK_SCROLL_SMOOTH: {
|
|
|
d6c6b3 |
gdouble decrement;
|
|
|
d6c6b3 |
+ if ((fit_width && fit_height) ||
|
|
|
d6c6b3 |
+ ((fit_height && event->delta_x == 0.0) ||
|
|
|
d6c6b3 |
+ (fit_width && event->delta_y == 0.0))) {
|
|
|
d6c6b3 |
+ /* Emulate normal scrolling by summing the deltas */
|
|
|
d6c6b3 |
+ view->total_delta += event->delta_x + event->delta_y;
|
|
|
d6c6b3 |
+
|
|
|
d6c6b3 |
+ decrement = view->total_delta < 0 ? -1.0 : 1.0;
|
|
|
d6c6b3 |
+ for (; fabs (view->total_delta) >= 1.0; view->total_delta -= decrement) {
|
|
|
d6c6b3 |
+ if (decrement < 0)
|
|
|
d6c6b3 |
+ ev_view_previous_page (view);
|
|
|
d6c6b3 |
+ else
|
|
|
d6c6b3 |
+ ev_view_next_page (view);
|
|
|
d6c6b3 |
+ }
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
- /* Emulate normal scrolling by summing the deltas */
|
|
|
d6c6b3 |
- view->total_delta += event->delta_x + event->delta_y;
|
|
|
d6c6b3 |
-
|
|
|
d6c6b3 |
- decrement = view->total_delta < 0 ? -1.0 : 1.0;
|
|
|
d6c6b3 |
- for (; fabs (view->total_delta) >= 1.0; view->total_delta -= decrement) {
|
|
|
d6c6b3 |
- if (decrement < 0)
|
|
|
d6c6b3 |
- ev_view_previous_page (view);
|
|
|
d6c6b3 |
- else
|
|
|
d6c6b3 |
- ev_view_next_page (view);
|
|
|
d6c6b3 |
+ return TRUE;
|
|
|
d6c6b3 |
}
|
|
|
d6c6b3 |
}
|
|
|
d6c6b3 |
break;
|
|
|
d6c6b3 |
}
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
- return TRUE;
|
|
|
d6c6b3 |
+ return FALSE;
|
|
|
d6c6b3 |
}
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
return FALSE;
|
|
|
d6c6b3 |
@@ -8111,6 +8571,48 @@ ev_view_zoom_for_size (EvView *view,
|
|
|
d6c6b3 |
ev_view_zoom_for_size_single_page (view, width, height);
|
|
|
d6c6b3 |
}
|
|
|
d6c6b3 |
|
|
|
d6c6b3 |
+static gboolean
|
|
|
d6c6b3 |
+ev_view_page_fits (EvView *view,
|
|
|
d6c6b3 |
+ GtkOrientation orientation)
|
|
|
d6c6b3 |
+{
|
|
|
d6c6b3 |
+ GtkRequisition requisition;
|
|
|
d6c6b3 |
+ GtkAllocation allocation;
|
|
|
d6c6b3 |
+ double size;
|
|
|
d6c6b3 |
+
|
|
|
d6c6b3 |
+ if (view->sizing_mode == EV_SIZING_FIT_PAGE)
|
|
|
d6c6b3 |
+ return TRUE;
|
|
|
d6c6b3 |
+
|
|
|
d6c6b3 |
+ if (orientation == GTK_ORIENTATION_HORIZONTAL &&
|
|
|
d6c6b3 |
+ (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
|
|
|
d6c6b3 |
+ view->sizing_mode == EV_SIZING_AUTOMATIC))
|
|
|
d6c6b3 |
+ return TRUE;
|
|
|
d6c6b3 |
+
|
|
|
d6c6b3 |
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
|
|
|
d6c6b3 |
+ ev_view_size_request (GTK_WIDGET (view), &requisition);
|
|
|
d6c6b3 |
+
|
|
|
d6c6b3 |
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
|
|
|
d6c6b3 |
+ if (requisition.width == 1) {
|
|
|
d6c6b3 |
+ size = 1.0;
|
|
|
d6c6b3 |
+ } else {
|
|
|
d6c6b3 |
+ if (allocation.width > 0.0)
|
|
|
d6c6b3 |
+ size = (double) requisition.width / allocation.width;
|
|
|
d6c6b3 |
+ else
|
|
|
d6c6b3 |
+ size = 1.0;
|
|
|
d6c6b3 |
+ }
|
|
|
d6c6b3 |
+ } else {
|
|
|
d6c6b3 |
+ if (requisition.height == 1) {
|
|
|
d6c6b3 |
+ size = 1.0;
|
|
|
d6c6b3 |
+ } else {
|
|
|
d6c6b3 |
+ if (allocation.height > 0.0)
|
|
|
d6c6b3 |
+ size = (double) requisition.height / allocation.height;
|
|
|
d6c6b3 |
+ else
|
|
|
d6c6b3 |
+ size = 1.0;
|
|
|
d6c6b3 |
+ }
|
|
|
d6c6b3 |
+ }
|
|
|
d6c6b3 |
+
|
|
|
d6c6b3 |
+ return size <= 1.0;
|
|
|
d6c6b3 |
+}
|
|
|
d6c6b3 |
+
|
|
|
d6c6b3 |
/*** Find ***/
|
|
|
d6c6b3 |
static gint
|
|
|
d6c6b3 |
ev_view_find_get_n_results (EvView *view, gint page)
|
|
|
d6c6b3 |
--
|
|
|
d6c6b3 |
2.7.4
|
|
|
d6c6b3 |
|