[nautilus/antonioffix-menus-and-popovers: 10/14] list-view: Share common code for rectangle computation



commit 4c4f51bace2d306bdfe24699254577598f5832df
Author: António Fernandes <antoniof gnome org>
Date:   Sun Jan 28 12:17:13 2018 +0000

    list-view: Share common code for rectangle computation
    
    Make internal function for both _reveal_rectangle_for_context_menu()
    and _compute_rename_popover_pointing_to() to avoid code duplication.

 src/nautilus-list-view.c | 86 ++++++++++++++++++++----------------------------
 1 file changed, 35 insertions(+), 51 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index a4bf8bfc2..59aec9a1f 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -3641,20 +3641,12 @@ nautilus_list_view_get_id (NautilusFilesView *view)
 }
 
 static GdkRectangle *
-nautilus_list_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
+get_rectangle_for_path (NautilusListView *list_view,
+                        GtkTreePath      *path)
 {
-    NautilusListView *list_view;
-    GtkTreeView *tree_view;
-    GtkTreeSelection *selection;
-    GList *list;
-    GtkTreePath *path;
+    GtkTreeView *tree_view = list_view->details->tree_view;
     GdkRectangle *rect = g_malloc0 (sizeof (GdkRectangle));
 
-    list_view = NAUTILUS_LIST_VIEW (view);
-    tree_view = list_view->details->tree_view;
-    selection = gtk_tree_view_get_selection (tree_view);
-    list = gtk_tree_selection_get_selected_rows (selection, NULL);
-    path = list->data;
     gtk_tree_view_get_cell_area (tree_view,
                                  path,
                                  list_view->details->file_name_column,
@@ -3663,16 +3655,7 @@ nautilus_list_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
                                                        rect->x, rect->y,
                                                        &rect->x, &rect->y);
 
-    if (list_view->details->last_event_button_x > 0)
-    {
-        /* Point to the position in the row where it was clicked. */
-        rect->x = list_view->details->last_event_button_x;
-        rect->width = 0; /* This makes sure popovers point to rect->x.*/
-    }
-
-    g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
-
-    /* FIXME Due to smooth scrolling, we get the cell area while the view is
+    /* FIXME Due to smooth scrolling, we may get the cell area while the view is
      * still scrolling (and still outside the view), not at the final position
      * of the cell after scrolling.
      * https://bugzilla.gnome.org/show_bug.cgi?id=746773
@@ -3690,9 +3673,38 @@ nautilus_list_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
 
         rect->y = CLAMP (rect->y,
                          header_height,
-                         gtk_widget_get_allocated_height (GTK_WIDGET (view)) - rect->height);
+                         gtk_widget_get_allocated_height (GTK_WIDGET (list_view)) - rect->height);
+    }
+
+    return rect;
+}
+
+static GdkRectangle *
+nautilus_list_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
+{
+    NautilusListView *list_view;
+    GtkTreeView *tree_view;
+    GtkTreeSelection *selection;
+    GList *list;
+    GtkTreePath *path;
+    GdkRectangle *rect;
+
+    list_view = NAUTILUS_LIST_VIEW (view);
+    tree_view = list_view->details->tree_view;
+    selection = gtk_tree_view_get_selection (tree_view);
+    list = gtk_tree_selection_get_selected_rows (selection, NULL);
+    path = list->data;
+    rect = get_rectangle_for_path (list_view, path);
+
+    if (list_view->details->last_event_button_x > 0)
+    {
+        /* Point to the position in the row where it was clicked. */
+        rect->x = list_view->details->last_event_button_x;
+        rect->width = 0; /* This makes sure popovers point to rect->x.*/
     }
 
+    g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
+
     return rect;
 }
 
@@ -3729,35 +3741,7 @@ nautilus_list_view_reveal_rectangle_for_context_menu (NautilusFilesView *view)
 
     gtk_tree_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
 
-    rect = g_malloc0 (sizeof (GdkRectangle));
-    gtk_tree_view_get_cell_area (tree_view,
-                                 path,
-                                 list_view->details->file_name_column,
-                                 rect);
-    gtk_tree_view_convert_bin_window_to_widget_coords (tree_view,
-                                                       rect->x, rect->y,
-                                                       &rect->x, &rect->y);
-
-    /* FIXME Due to smooth scrolling, we may get the cell area while the view is
-     * still scrolling (and still outside the view), not at the final position
-     * of the cell after scrolling.
-     * https://bugzilla.gnome.org/show_bug.cgi?id=746773
-     * The following workaround guesses the final "y" coordinate by clamping it
-     * to the widget edge. Note that the top edge has got columns header, which
-     * is private, so first guess the header height from the difference between
-     * widget coordinates and bin cooridinates.
-     */
-    {
-        int header_height;
-
-        gtk_tree_view_convert_bin_window_to_widget_coords (tree_view,
-                                                           0, 0,
-                                                           NULL, &header_height);
-
-        rect->y = CLAMP (rect->y,
-                         header_height,
-                         gtk_widget_get_allocated_height (GTK_WIDGET (list_view)) - rect->height);
-    }
+    rect = get_rectangle_for_path (list_view, path);
 
     gtk_tree_path_free (path);
 


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