[evince] libview: Reduce the pages to scan for selections when selection starts and ends at the same point



commit e92c98f93ce7404025dc90983289c8042d318a63
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Sat Jul 20 10:56:52 2013 +0200

    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.

 libview/ev-view.c |   88 ++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 60 insertions(+), 28 deletions(-)
---
diff --git a/libview/ev-view.c b/libview/ev-view.c
index d454825..4f51f66 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -7418,56 +7418,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) || 
+               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);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]