Index: shell/ev-view.c
===================================================================
--- shell/ev-view.c	(revision 3277)
+++ shell/ev-view.c	(working copy)
@@ -593,6 +593,7 @@
 	        GtkScrollType  scroll,
 		gboolean       horizontal)
 {
+	GtkScrollType do_scroll;
 	GtkAdjustment *adjustment;
 	double value, increment;
 	gboolean first_page = FALSE;
@@ -600,8 +601,10 @@
 
 	view->jump_to_find_result = FALSE;
 
+	do_scroll = scroll;
+
 	if (view->presentation || view->sizing_mode == EV_SIZING_BEST_FIT) {
-		switch (scroll) {
+		switch (do_scroll) {
 			case GTK_SCROLL_PAGE_BACKWARD:
 			case GTK_SCROLL_STEP_BACKWARD:
 				ev_view_previous_page (view);
@@ -627,13 +630,42 @@
 	if (view->current_page == ev_page_cache_get_n_pages (view->page_cache) - 1)
 		last_page = TRUE;
 
-	switch (scroll) {
+	/* Deal with small scrolls first */
+        switch (do_scroll) {
+	        case GTK_SCROLL_STEP_BACKWARD:
+			value -= adjustment->step_increment;
+			break;
+	        case GTK_SCROLL_STEP_FORWARD:
+			value += adjustment->step_increment;
+			break;
+        	case GTK_SCROLL_STEP_DOWN:
+			value -= adjustment->step_increment / 10;
+			break;
+        	case GTK_SCROLL_STEP_UP:
+			value += adjustment->step_increment / 10;
+			break;
+		default:
+			break;
+	}
+
+	/* Have we scrolled off the page? Then change the scroll into a page flip. */
+	if (value < (adjustment->lower) && ((do_scroll == GTK_SCROLL_STEP_BACKWARD)
+					 || (do_scroll == GTK_SCROLL_STEP_DOWN))) {
+		do_scroll = GTK_SCROLL_PAGE_BACKWARD;
+	} else if (value > (adjustment->upper - adjustment->page_size) && 
+					   ((do_scroll == GTK_SCROLL_STEP_FORWARD)
+					 || (do_scroll == GTK_SCROLL_STEP_UP))) {
+                do_scroll = GTK_SCROLL_PAGE_FORWARD;
+	}
+
+	/* Deal with page flips. */
+	switch (do_scroll) {
 		case GTK_SCROLL_PAGE_BACKWARD:
 			/* Do not jump backwards if at the first page */
-			if (value == (adjustment->lower) && first_page) {
+			if (value <= (adjustment->lower) && first_page) {
 				/* Do nothing */
 				/* At the top of a page, assign the upper bound limit of previous page */
-			} else if (value == (adjustment->lower)) {
+			} else if (value <= (adjustment->lower)) {
 				value = adjustment->upper - adjustment->page_size;
 				ev_view_previous_page (view);
 				/* Jump to the top */
@@ -643,10 +675,10 @@
 			break;
 		case GTK_SCROLL_PAGE_FORWARD:
 			/* Do not jump forward if at the last page */
-			if (value == (adjustment->upper - adjustment->page_size) && last_page) {
+			if (value >= (adjustment->upper - adjustment->page_size) && last_page) {
 				/* Do nothing */
 			/* At the bottom of a page, assign the lower bound limit of next page */
-			} else if (value == (adjustment->upper - adjustment->page_size)) {
+			} else if (value >= (adjustment->upper - adjustment->page_size)) {
 				value = 0;
 				ev_view_next_page (view);
 			/* Jump to the bottom */
@@ -654,18 +686,6 @@
 				value = MIN (value + increment, adjustment->upper - adjustment->page_size);
 			}
 			break;
-	        case GTK_SCROLL_STEP_BACKWARD:
-			value -= adjustment->step_increment;
-			break;
-	        case GTK_SCROLL_STEP_FORWARD:
-			value += adjustment->step_increment;
-			break;
-        	case GTK_SCROLL_STEP_DOWN:
-			value -= adjustment->step_increment / 10;
-			break;
-        	case GTK_SCROLL_STEP_UP:
-			value += adjustment->step_increment / 10;
-			break;
         	default:
 			break;
 	}
@@ -2323,6 +2343,8 @@
 {
 	EvView *view = EV_VIEW (widget);
 	guint state;
+	GtkAdjustment *adjustment;
+	double value;
 
 	state = event->state & gtk_accelerator_get_default_mod_mask ();
 
@@ -2375,6 +2397,24 @@
 		return TRUE;
 	}
 
+        adjustment = (event->direction==GDK_SCROLL_RIGHT
+                   || event->direction==GDK_SCROLL_LEFT) ? view->hadjustment : view->vadjustment;
+        value = adjustment->value;
+
+	/* flip page if the scrolling exceeds the page size */
+
+	if (((value + adjustment->step_increment) > (adjustment->upper - adjustment->page_size)) && 
+            ((event->direction == GDK_SCROLL_DOWN) || (event->direction == GDK_SCROLL_RIGHT))) {
+		ev_view_next_page (view);
+		return TRUE;
+	}
+
+        if (((value - adjustment->step_increment) < (adjustment->lower)) && 
+            ((event->direction == GDK_SCROLL_UP) || (event->direction == GDK_SCROLL_LEFT))) {
+		ev_view_previous_page (view);
+		return TRUE;
+        }	
+
 	return FALSE;
 }
 
