summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <[email protected]>2013-07-20 10:56:52 +0200
committerraveit65 <[email protected]>2017-09-06 18:25:34 +0200
commit518e7e86554b74e9562e1c7801fc5ca42bdf45c2 (patch)
tree203393b29fc98e57821b177f1b51a9ee323643a0
parente4d427349a63af1a0d37687ef5f3012312e955e2 (diff)
downloadatril-518e7e86554b74e9562e1c7801fc5ca42bdf45c2.tar.bz2
atril-518e7e86554b74e9562e1c7801fc5ca42bdf45c2.tar.xz
libview: Reduce the pages to scan for selections
when selection starts and ends at the same point We can use the current page range in this case, since this will only happen when starting a new word/line selection. origin commit: https://git.gnome.org/browse/evince/commit/?h=gnome-3-10&id=e92c98f
-rw-r--r--libview/ev-view.c84
1 files changed, 58 insertions, 26 deletions
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 2109af11..36286614 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -7538,56 +7538,88 @@ gdk_rectangle_point_in (GdkRectangle *rectangle,
point->y < rectangle->y + rectangle->height;
}
-static GList *
-compute_new_selection (EvView *view,
- EvSelectionStyle style,
- GdkPoint *start,
- GdkPoint *stop)
+static inline gboolean
+gdk_point_equal (GdkPoint *a,
+ GdkPoint *b)
{
- int n_pages, i, first, last;
- GList *list = NULL;
- EvViewSelection *selection;
- gdouble width, height;
- int start_page, end_page;
+ return a->x == b->x && a->y == b->y;
+}
+
+static gboolean
+get_selection_page_range (EvView *view,
+ EvSelectionStyle style,
+ GdkPoint *start,
+ GdkPoint *stop,
+ gint *first_page,
+ gint *last_page)
+{
+ gint start_page, end_page;
+ gint first, last;
+ gint i, n_pages;
n_pages = ev_document_get_n_pages (view->document);
- /* First figure out the range of pages the selection
- * affects. */
- first = n_pages;
- last = 0;
- if (view->continuous) {
+ if (gdk_point_equal (start, stop)) {
+ start_page = view->start_page;
+ end_page = view->end_page;
+ } else if (view->continuous) {
start_page = 0;
- end_page = n_pages;
+ end_page = n_pages - 1;
} else if (is_dual_page (view, NULL)) {
start_page = view->start_page;
- end_page = view->end_page + 1;
+ end_page = view->end_page;
} else {
start_page = view->current_page;
- end_page = view->current_page + 1;
+ end_page = view->current_page;
}
- for (i = start_page; i < end_page; i++) {
+ first = -1;
+ last = -1;
+ for (i = start_page; i <= end_page; i++) {
GdkRectangle page_area;
- GtkBorder border;
+ GtkBorder border;
ev_view_get_page_extents (view, i, &page_area, &border);
if (gdk_rectangle_point_in (&page_area, start) ||
gdk_rectangle_point_in (&page_area, stop)) {
- if (first == n_pages)
+ if (first == -1)
first = i;
last = i;
}
+ }
+
+ if (first != -1 && last != -1) {
+ *first_page = first;
+ *last_page = last;
+ return TRUE;
}
+ return FALSE;
+}
+
+static GList *
+compute_new_selection (EvView *view,
+ EvSelectionStyle style,
+ GdkPoint *start,
+ GdkPoint *stop)
+{
+ int i, first, last;
+ GList *list = NULL;
+
+ /* First figure out the range of pages the selection affects. */
+ if (!get_selection_page_range (view, style, start, stop, &first, &last))
+ return list;
+
/* Now create a list of EvViewSelection's for the affected
- * pages. This could be an empty list, a list of just one
+ * pages. This could be an empty list, a list of just one
* page or a number of pages.*/
- for (i = first; i < last + 1; i++) {
- GdkRectangle page_area;
- GtkBorder border;
- GdkPoint *point;
+ for (i = first; i <= last; i++) {
+ EvViewSelection *selection;
+ GdkRectangle page_area;
+ GtkBorder border;
+ GdkPoint *point;
+ gdouble width, height;
get_doc_page_size (view, i, &width, &height);