[epiphany] Use GdTwoLinesRenderer to display the location entry completion



commit b4ce44639bb5196b593f71c9c1d0cabbde8af98b
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Mon Dec 21 08:01:55 2015 -0600

    Use GdTwoLinesRenderer to display the location entry completion
    
    Accordingly, we get to remove Carlos's horrible hack adding markup to
    the completion model (which in MVC should only model, not contain
    style), and Claudio's horrible hack adding a bool property to make the
    markup optional (to avoid breaking the search provider, which also uses
    the completion model).
    
    The markup was originally moved to the completion model in order to
    remove the cell data function, which was being run continuously due to
    some bug. Because GdTwoLinesRenderer uses real cell attributes to
    display the title and url separately, we no longer need to worry at all
    about the task it used to perform -- merging the title and url into one
    string, with a newline and formatting markup to control size and color
    of the second line. GdTwoLinesRenderer takes care of this much more
    cleanly.
    
    The only user-visible change is that it is now possible to read URLs in
    the completion when the row is selected, as the gray is darker.
    Apparently some people can read it fine, but the color was too similar to
    the selection blue on the three monitors I tested.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=736364

 .gitmodules                        |    3 +
 Makefile.am                        |    2 +-
 autogen.sh                         |    2 +
 configure.ac                       |    5 ++-
 lib/widgets/Makefile.am            |    4 ++
 lib/widgets/ephy-location-entry.c  |   12 ++++-
 libgd                              |    1 +
 src/ephy-completion-model.c        |   81 ++----------------------------------
 src/ephy-completion-model.h        |    3 +-
 src/ephy-location-controller.c     |    2 +-
 src/ephy-search-provider.c         |    2 +-
 tests/ephy-completion-model-test.c |    4 +-
 12 files changed, 33 insertions(+), 88 deletions(-)
---
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..303eb9b
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "libgd"]
+       path = libgd
+       url = ../libgd
diff --git a/Makefile.am b/Makefile.am
index 2339402..1112691 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = help lib embed src data po doc
+SUBDIRS = help libgd lib embed src data po doc
 
 if ENABLE_TESTS
 SUBDIRS += tests
diff --git a/autogen.sh b/autogen.sh
index ee6c0e0..07df19f 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -21,6 +21,8 @@ if [ "$#" = 0 -a "x$NOCONFIGURE" = "x" ]; then
         echo "" >&2
 fi
 
+git submodule update --init --recursive
+
 aclocal --install || exit 1
 intltoolize --force --copy --automake || exit 1
 autoreconf --verbose --force --install -Wno-portability || exit 1
diff --git a/configure.ac b/configure.ac
index de3153c..aa9b8e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,7 +25,7 @@ AX_IS_RELEASE([git-directory])
 AC_PREREQ([2.59])
 
 AC_CONFIG_AUX_DIR([build-aux])
-AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_MACRO_DIRS([m4, libgd])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_SRCDIR([configure.ac])
 
@@ -93,6 +93,8 @@ AC_MSG_RESULT([$enable_tests])
 
 AM_CONDITIONAL([ENABLE_TESTS],[test "$enable_tests" = "yes"])
 
+LIBGD_INIT([_view-common])
+
 PKG_CHECK_MODULES([DEPENDENCIES], [
                  glib-2.0 >= $GLIB_REQUIRED
                  gthread-2.0
@@ -218,6 +220,7 @@ data/Makefile
 data/pages/Makefile
 doc/Makefile
 help/Makefile
+libgd/Makefile
 lib/Makefile
 lib/egg/Makefile
 lib/history/Makefile
diff --git a/lib/widgets/Makefile.am b/lib/widgets/Makefile.am
index a120ed1..d602717 100644
--- a/lib/widgets/Makefile.am
+++ b/lib/widgets/Makefile.am
@@ -98,6 +98,7 @@ libephywidgets_la_CPPFLAGS = \
        -I$(top_srcdir)/embed           \
        -I$(top_srcdir)/lib/egg         \
        -I$(top_srcdir)/lib/history     \
+       -I$(top_builddir)/libgd         \
        -DSHARE_DIR=\"$(pkgdatadir)\"   \
        $(AM_CPPFLAGS)
 
@@ -106,4 +107,7 @@ libephywidgets_la_CFLAGS = \
        $(CODE_COVERAGE_CFLAGS) \
        $(AM_CFLAGS)
 
+libephywidgets_la_LIBADD = \
+       $(top_builddir)/libgd/libgd.la
+
 -include $(top_srcdir)/git.mk
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 42731b7..6ffd1aa 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -33,6 +33,7 @@
 #include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#include <libgd/gd.h>
 #include <string.h>
 #if 0
 /* FIXME: Refactor the DNS prefetch, this is a layering violation */
@@ -1192,12 +1193,17 @@ ephy_location_entry_set_completion (EphyLocationEntry *entry,
                 ICON_CONTENT_HEIGHT);
        gtk_cell_renderer_set_alignment (cell, 0.0, 0.5);
 
-       cell = gtk_cell_renderer_text_new ();
-       g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+       cell = gd_two_lines_renderer_new ();
+       g_object_set (cell,
+                      "ellipsize", PANGO_ELLIPSIZE_END,
+                      "text-lines", 2,
+                      NULL);
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion),
                                    cell, TRUE);
        gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
-                                      cell, "markup", text_col);
+                                      cell, "text", text_col);
+        gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
+                                       cell, "line-two", url_col);
 
        /* Pixel-perfect aligment with the text in the location entry.
         * See above.
diff --git a/libgd b/libgd
new file mode 160000
index 0000000..56a19ad
--- /dev/null
+++ b/libgd
@@ -0,0 +1 @@
+Subproject commit 56a19ad9b056332ef07e508f1bdb6f03c6cb2590
diff --git a/src/ephy-completion-model.c b/src/ephy-completion-model.c
index bb74587..5b8b1d3 100644
--- a/src/ephy-completion-model.c
+++ b/src/ephy-completion-model.c
@@ -32,7 +32,6 @@ enum {
   PROP_0,
   PROP_HISTORY_SERVICE,
   PROP_BOOKMARKS,
-  PROP_USE_MARKUP,
   LAST_PROP
 };
 
@@ -49,8 +48,6 @@ struct _EphyCompletionModelPrivate {
   EphyNode *bookmarks;
   EphyNode *smart_bookmarks;
   GSList *search_terms;
-
-  gboolean use_markup;
 };
 
 static void
@@ -92,9 +89,6 @@ ephy_completion_model_set_property (GObject *object, guint property_id, const GV
     self->priv->smart_bookmarks = ephy_bookmarks_get_smart_bookmarks (bookmarks);
     }
     break;
-  case PROP_USE_MARKUP:
-    self->priv->use_markup = g_value_get_boolean (value);
-    break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec);
     break;
@@ -140,13 +134,6 @@ ephy_completion_model_class_init (EphyCompletionModelClass *klass)
                           "The bookmarks",
                           G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
 
-  obj_properties[PROP_USE_MARKUP] =
-    g_param_spec_boolean ("use-markup",
-                          "Whether we should be using markup",
-                          "Whether we should be using markup",
-                          TRUE,
-                          G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
-
   g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
 
   g_type_class_add_private (object_class, sizeof (EphyCompletionModelPrivate));
@@ -254,51 +241,25 @@ icon_loaded_cb (GObject *source, GAsyncResult *result, gpointer user_data)
   g_slice_free (IconLoadData, data);
 }
 
-static gchar *
-get_row_text (const gchar *url, const gchar *title, const gchar *subtitle_color)
-{
-  gchar *unescaped_url;
-  gchar *text;
-
-  if (!url)
-    return g_markup_escape_text (title, -1);
-
-  unescaped_url = ephy_uri_safe_unescape (url);
-  if (g_strcmp0 (url, title) == 0)
-    text = g_markup_escape_text (unescaped_url, -1);
-  else
-    text = g_markup_printf_escaped ("%s\n<span font-size=\"small\" color=\"%s\">%s</span>", title, 
subtitle_color, unescaped_url);
-  g_free (unescaped_url);
-
-  return text;
-}
-
 static void
-set_row_in_model (EphyCompletionModel *model, int position, PotentialRow *row, const gchar *subtitle_color)
+set_row_in_model (EphyCompletionModel *model, int position, PotentialRow *row)
 {
   GtkTreeIter iter;
   GtkTreePath *path;
   IconLoadData *data;
   WebKitFaviconDatabase* database;
-  gchar *text;
   EphyEmbedShell *shell = ephy_embed_shell_get_default ();
 
   database = webkit_web_context_get_favicon_database (ephy_embed_shell_get_web_context (shell));
 
-  if (model->priv->use_markup)
-    text = get_row_text (row->location, row->title, subtitle_color);
-  else
-    text = g_strdup (row->title);
-
   gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, position,
-                                     EPHY_COMPLETION_TEXT_COL, text ? text : "",
+                                     EPHY_COMPLETION_TEXT_COL, row->title ? row->title : "",
                                      EPHY_COMPLETION_URL_COL, row->location,
                                      EPHY_COMPLETION_ACTION_COL, row->location,
                                      EPHY_COMPLETION_KEYWORDS_COL, row->keywords ? row->keywords : "",
                                      EPHY_COMPLETION_EXTRA_COL, row->is_bookmark,
                                      EPHY_COMPLETION_RELEVANCE_COL, row->relevance,
                                      -1);
-  g_free (text);
 
   data = g_slice_new (IconLoadData);
   data->model = GTK_LIST_STORE (g_object_ref(model));
@@ -310,56 +271,24 @@ set_row_in_model (EphyCompletionModel *model, int position, PotentialRow *row, c
                                        NULL, icon_loaded_cb, data);
 }
 
-/* FIXME: This should be in the view, not the model. */
-static gchar *
-get_text_column_subtitle_color (void)
-{
-  GtkWidgetPath *path;
-  GtkStyleContext *style_context;
-  GdkRGBA rgba;
-
-  path = gtk_widget_path_new ();
-  gtk_widget_path_prepend_type (path, GTK_TYPE_ENTRY);
-  gtk_widget_path_iter_set_object_name (path, 0, "entry");
-
-  style_context = gtk_style_context_new ();
-  gtk_style_context_set_path (style_context, path);
-  gtk_widget_path_free (path);
-
-  gtk_style_context_set_state (style_context, GTK_STATE_FLAG_INSENSITIVE);
-  gtk_style_context_get_color (style_context, GTK_STATE_FLAG_INSENSITIVE, &rgba);
-  g_object_unref (style_context);
-
-  return g_strdup_printf ("#%04X%04X%04X",
-                          (guint)(rgba.red * (gdouble)65535),
-                          (guint)(rgba.green * (gdouble)65535),
-                          (guint)(rgba.blue * (gdouble)65535));
-}
-
 static void
 replace_rows_in_model (EphyCompletionModel *model, GSList *new_rows)
 {
   /* This is by far the simplest way of doing, and yet it gives
    * basically the same result than the other methods... */
   int i;
-  gchar *subtitle_color = NULL;
 
   gtk_list_store_clear (GTK_LIST_STORE (model));
 
   if (!new_rows)
     return;
 
-  if (model->priv->use_markup)
-    subtitle_color = get_text_column_subtitle_color ();
-
   for (i = 0; new_rows != NULL; i++) {
     PotentialRow *row = (PotentialRow*)new_rows->data;
 
-    set_row_in_model (model, i, row, subtitle_color);
+    set_row_in_model (model, i, row);
     new_rows = new_rows->next;
   }
-
-  g_free (subtitle_color);
 }
 
 static gboolean
@@ -672,8 +601,7 @@ ephy_completion_model_update_for_string (EphyCompletionModel *model,
 
 EphyCompletionModel *
 ephy_completion_model_new (EphyHistoryService *history_service,
-                           EphyBookmarks      *bookmarks,
-                           gboolean            use_markup)
+                           EphyBookmarks      *bookmarks)
 {
   g_return_val_if_fail (EPHY_IS_HISTORY_SERVICE (history_service), NULL);
   g_return_val_if_fail (EPHY_IS_BOOKMARKS (bookmarks), NULL);
@@ -681,6 +609,5 @@ ephy_completion_model_new (EphyHistoryService *history_service,
   return g_object_new (EPHY_TYPE_COMPLETION_MODEL,
                        "history-service", history_service,
                        "bookmarks", bookmarks,
-                       "use-markup", use_markup,
                        NULL);
 }
diff --git a/src/ephy-completion-model.h b/src/ephy-completion-model.h
index a621540..e0340d8 100644
--- a/src/ephy-completion-model.h
+++ b/src/ephy-completion-model.h
@@ -66,8 +66,7 @@ typedef struct
 GType                ephy_completion_model_get_type         (void);
 
 EphyCompletionModel *ephy_completion_model_new              (EphyHistoryService *history_service,
-                                                              EphyBookmarks *bookmarks,
-                                                              gboolean use_markup);
+                                                              EphyBookmarks *bookmarks);
 
 void                 ephy_completion_model_update_for_string (EphyCompletionModel *model,
                                                               const char *string,
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index ad02fad..6a05326 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -436,7 +436,7 @@ ephy_location_controller_constructed (GObject *object)
 
        history_service = EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service 
(ephy_embed_shell_get_default ()));
        bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ());
-       model = ephy_completion_model_new (history_service, bookmarks, TRUE);
+       model = ephy_completion_model_new (history_service, bookmarks);
        ephy_location_entry_set_completion (priv->location_entry,
                                            GTK_TREE_MODEL (model),
                                            EPHY_COMPLETION_TEXT_COL,
diff --git a/src/ephy-search-provider.c b/src/ephy-search-provider.c
index 4a52a52..f1616bd 100644
--- a/src/ephy-search-provider.c
+++ b/src/ephy-search-provider.c
@@ -369,7 +369,7 @@ ephy_search_provider_init (EphySearchProvider *self)
   filename = g_build_filename (ephy_dot_dir (), EPHY_HISTORY_FILE, NULL);
   self->history_service = ephy_history_service_new (filename, TRUE);
   self->bookmarks = ephy_bookmarks_new ();
-  self->model = ephy_completion_model_new (self->history_service, self->bookmarks, FALSE);
+  self->model = ephy_completion_model_new (self->history_service, self->bookmarks);
   g_free (filename);
 
   self->cancellable = g_cancellable_new ();
diff --git a/tests/ephy-completion-model-test.c b/tests/ephy-completion-model-test.c
index d218005..cb0db48 100644
--- a/tests/ephy-completion-model-test.c
+++ b/tests/ephy-completion-model-test.c
@@ -30,7 +30,7 @@ test_ephy_completion_model_create (void)
 {
     EphyCompletionModel *model;
     model = ephy_completion_model_new (EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service 
(ephy_embed_shell_get_default ())),
-                                       ephy_shell_get_bookmarks (ephy_shell_get_default ()), TRUE);
+                                       ephy_shell_get_bookmarks (ephy_shell_get_default ()));
     g_assert (model);
     g_object_unref (model);
 }
@@ -56,7 +56,7 @@ test_ephy_completion_model_update_empty (void)
     GMainLoop *loop = NULL;
 
     model = ephy_completion_model_new (EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service 
(ephy_embed_shell_get_default ())),
-                                       ephy_shell_get_bookmarks (ephy_shell_get_default ()), TRUE);
+                                       ephy_shell_get_bookmarks (ephy_shell_get_default ()));
     g_assert (model);
 
     loop = g_main_loop_new (NULL, FALSE);


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