[gtk+] separatortoolitem: don't use custom sizing/rendering



commit eff8865ab1332324bbb486b57e60ebd957e5a661
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Dec 29 12:34:16 2015 -0800

    separatortoolitem: don't use custom sizing/rendering
    
    Instead, just rely on the CSS gadget; we can stop using wide-separators,
    separator-height and separator-width, and at the same time deprecate the
    space-size style property of GtkToolbar.

 gtk/gtkseparatortoolitem.c               |   92 ++-------------------------
 gtk/gtktoolbar.c                         |  102 +++---------------------------
 gtk/gtktoolbarprivate.h                  |    5 --
 gtk/theme/Adwaita/_common.scss           |   19 +++++-
 gtk/theme/Adwaita/gtk-contained-dark.css |   13 +++-
 gtk/theme/Adwaita/gtk-contained.css      |   13 +++-
 6 files changed, 48 insertions(+), 196 deletions(-)
---
diff --git a/gtk/gtkseparatortoolitem.c b/gtk/gtkseparatortoolitem.c
index c8ef613..2111439 100644
--- a/gtk/gtkseparatortoolitem.c
+++ b/gtk/gtkseparatortoolitem.c
@@ -83,7 +83,6 @@ static gboolean gtk_separator_tool_item_draw              (GtkWidget
                                                            cairo_t                   *cr);
 static void     gtk_separator_tool_item_add               (GtkContainer              *container,
                                                            GtkWidget                 *child);
-static gint     get_space_size                            (GtkToolItem               *tool_item);
 static void     gtk_separator_tool_item_realize           (GtkWidget                 *widget);
 static void     gtk_separator_tool_item_unrealize         (GtkWidget                 *widget);
 static void     gtk_separator_tool_item_map               (GtkWidget                 *widget);
@@ -93,43 +92,8 @@ static gboolean gtk_separator_tool_item_button_event      (GtkWidget
 static gboolean gtk_separator_tool_item_motion_event      (GtkWidget                 *widget,
                                                            GdkEventMotion            *event);
 
-static void     gtk_separator_tool_item_get_size      (GtkCssGadget        *gadget,
-                                          GtkOrientation       orientation,
-                                          gint                 for_size,
-                                          gint                *minimum_size,
-                                          gint                *natural_size,
-                                          gint                *minimum_baseline,
-                                          gint                *natural_baseline,
-                                          gpointer             data);
-static gboolean gtk_separator_tool_item_render (GtkCssGadget        *gadget,
-                                          cairo_t             *cr,
-                                          int                  x,
-                                          int                  y,
-                                          int                  width,
-                                          int                  height,
-                                          gpointer             data);
-
-
 G_DEFINE_TYPE_WITH_PRIVATE (GtkSeparatorToolItem, gtk_separator_tool_item, GTK_TYPE_TOOL_ITEM)
 
-static gint
-get_space_size (GtkToolItem *tool_item)
-{
-  gint space_size = _gtk_toolbar_get_default_space_size();
-  GtkWidget *parent;
-
-  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
-
-  if (GTK_IS_TOOLBAR (parent))
-    {
-      gtk_widget_style_get (parent,
-                            "space-size", &space_size,
-                            NULL);
-    }
-  
-  return space_size;
-}
-
 static void
 gtk_separator_tool_item_finalize (GObject *object)
 {
@@ -201,11 +165,8 @@ gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item)
   separator_item->priv->gadget =
     gtk_css_custom_gadget_new_for_node (widget_node,
                                         widget,
-                                        gtk_separator_tool_item_get_size,
-                                        NULL,
-                                        gtk_separator_tool_item_render,
-                                        NULL,
-                                        NULL);
+                                        NULL, NULL, NULL,
+                                        NULL, NULL);
 }
 
 static void
@@ -487,54 +448,13 @@ gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
   if (draw != item->priv->draw)
     {
       item->priv->draw = draw;
+      if (draw)
+        gtk_css_gadget_remove_class (item->priv->gadget, "invisible");
+      else
+        gtk_css_gadget_add_class (item->priv->gadget, "invisible");
 
       gtk_widget_queue_draw (GTK_WIDGET (item));
 
       g_object_notify (G_OBJECT (item), "draw");
     }
 }
-
-static void
-gtk_separator_tool_item_get_size (GtkCssGadget   *gadget,
-                                  GtkOrientation  orientation,
-                                  gint            for_size,
-                                  gint           *minimum,
-                                  gint           *natural,
-                                  gint           *minimum_baseline,
-                                  gint           *natural_baseline,
-                                  gpointer        data)
-{
-  GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
-
-  if (gtk_tool_item_get_orientation (GTK_TOOL_ITEM (widget)) == orientation)
-    *minimum = *natural = get_space_size (GTK_TOOL_ITEM (widget));
-  else
-    *minimum = *natural = 1;
-}
-
-static gboolean
-gtk_separator_tool_item_render (GtkCssGadget *gadget,
-                                cairo_t      *cr,
-                                int           x,
-                                int           y,
-                                int           width,
-                                int           height,
-                                gpointer      data)
-{
-  GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
-  GtkToolbar *toolbar;
-  GtkWidget *parent;
-
-  if (GTK_SEPARATOR_TOOL_ITEM (widget)->priv->draw)
-    {
-      parent = gtk_widget_get_parent (widget);
-      if (GTK_IS_TOOLBAR (parent))
-        toolbar = GTK_TOOLBAR (parent);
-      else
-        toolbar = NULL;
-
-      _gtk_toolbar_paint_space_line (widget, toolbar, cr);
-    }
-
-  return FALSE;
-}
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index ecc7832..c185216 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -594,7 +594,14 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
                                                                    FALSE,
                                                                    GTK_PARAM_READWRITE));
   
-  /* style properties */
+  /**
+   * GtkToolbar:space-size:
+   *
+   * Size of toolbar spacers.
+   *
+   * Deprecated: 3.20: Use the standard margin/padding CSS properties on the
+   *   separator elements; the value of this style property is ignored.
+   */
   gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_int ("space-size",
                                                             P_("Spacer size"),
@@ -602,7 +609,7 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
                                                             0,
                                                             G_MAXINT,
                                                              DEFAULT_SPACE_SIZE,
-                                                            GTK_PARAM_READABLE));
+                                                            GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
   
   /**
    * GtkToolbar:internal-padding:
@@ -3600,97 +3607,6 @@ get_max_child_expand (GtkToolbar *toolbar)
 }
 
 /* GTK+ internal methods */
-
-gint
-_gtk_toolbar_get_default_space_size (void)
-{
-  return DEFAULT_SPACE_SIZE;
-}
-
-void
-_gtk_toolbar_paint_space_line (GtkWidget           *widget,
-                              GtkToolbar          *toolbar,
-                               cairo_t             *cr)
-{
-  GtkOrientation orientation;
-  GtkStyleContext *context;
-  GtkBorder padding;
-  gint width, height;
-  const gdouble start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
-  const gdouble end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-
-  orientation = toolbar ? toolbar->priv->orientation : GTK_ORIENTATION_HORIZONTAL;
-
-  width = gtk_widget_get_allocated_width (widget);
-  height = gtk_widget_get_allocated_height (widget);
-
-  context = gtk_widget_get_style_context (widget);
-  gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
-
-  if (orientation == GTK_ORIENTATION_HORIZONTAL)
-    {
-      gboolean wide_separators;
-      gint     separator_width;
-
-      gtk_widget_style_get (widget,
-                            "wide-separators", &wide_separators,
-                            "separator-width", &separator_width,
-                            NULL);
-
-      if (wide_separators)
-        {
-          gtk_render_background (context, cr,
-                                 (width - separator_width) / 2,
-                                 padding.top,
-                                 separator_width,
-                                 height - padding.bottom);
-          gtk_render_frame (context, cr,
-                            (width - separator_width) / 2,
-                            padding.top,
-                            separator_width,
-                            height - padding.bottom);
-        }
-      else
-        gtk_render_line (context, cr,
-                         (width - padding.left) / 2,
-                         height * start_fraction,
-                         (width - padding.left) / 2,
-                         height * end_fraction);
-    }
-  else
-    {
-      gboolean wide_separators;
-      gint     separator_height;
-
-      gtk_widget_style_get (widget,
-                            "wide-separators",  &wide_separators,
-                            "separator-height", &separator_height,
-                            NULL);
-
-      if (wide_separators)
-        {
-          gtk_render_background (context, cr,
-                                 padding.left,
-                                 (height - separator_height) / 2,
-                                 width - padding.right,
-                                 separator_height);
-          gtk_render_frame (context, cr,
-                            padding.left,
-                            (height - separator_height) / 2,
-                            width - padding.right,
-                            separator_height);
-        }
-      else
-        gtk_render_line (context, cr,
-                         width * start_fraction,
-                         (height - padding.top) / 2,
-                         width * end_fraction,
-                         (height - padding.top) / 2);
-    }
-}
-
 gchar *
 _gtk_toolbar_elide_underscores (const gchar *original)
 {
diff --git a/gtk/gtktoolbarprivate.h b/gtk/gtktoolbarprivate.h
index c63e901..982251a 100644
--- a/gtk/gtktoolbarprivate.h
+++ b/gtk/gtktoolbarprivate.h
@@ -35,11 +35,6 @@
 G_BEGIN_DECLS
 
 gchar *         _gtk_toolbar_elide_underscores      (const gchar         *original);
-void            _gtk_toolbar_paint_space_line       (GtkWidget           *widget,
-                                                    GtkToolbar          *toolbar,
-                                                     cairo_t             *cr);
-gint            _gtk_toolbar_get_default_space_size (void);
-
 
 G_END_DECLS
 
diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss
index 1f94ced..3dd623c 100644
--- a/gtk/theme/Adwaita/_common.scss
+++ b/gtk/theme/Adwaita/_common.scss
@@ -671,10 +671,6 @@ toolbar.inline-toolbar toolbutton:backdrop {
   &:only-child > button.flat { @extend %linked:only-child; }
 }
 
-toolbar separator {
-  background: none;
-}
-
 %linked_middle {
   border-radius: 0;
   border-right-style: none;
@@ -1049,6 +1045,21 @@ toolbar {
   &.osd.right,
   &.osd.top,
   &.osd.bottom { border-radius: 0; } // positional classes for `attached` osd toolbars
+
+  // toolbar separators
+  & separator {
+    background: none;
+  }
+  &.horizontal {
+    & separator {
+      margin: 0 6px;
+    }
+  }
+  &.vertical {
+    & separator {
+      margin: 6px 0;
+    }
+  }
 }
 
 //searchbar, location-bar & inline-toolbar
diff --git a/gtk/theme/Adwaita/gtk-contained-dark.css b/gtk/theme/Adwaita/gtk-contained-dark.css
index c545146..0d6a130 100644
--- a/gtk/theme/Adwaita/gtk-contained-dark.css
+++ b/gtk/theme/Adwaita/gtk-contained-dark.css
@@ -1106,10 +1106,6 @@ button, headerbar button.titlebutton,
     .inline-toolbar toolbutton > button:backdrop:disabled:active > .label, .inline-toolbar toolbutton > 
button:backdrop:disabled:checked > .label {
       color: inherit; }
 
-toolbar separator, .inline-toolbar separator, searchbar separator,
-.location-bar separator {
-  background: none; }
-
 toolbar.inline-toolbar toolbutton > button.flat, .inline-toolbar toolbutton > button.flat, 
searchbar.inline-toolbar toolbutton > button.flat,
 .inline-toolbar.location-bar toolbutton > button.flat, toolbar.inline-toolbar toolbutton > 
button.sidebar-button, .inline-toolbar toolbutton > button.sidebar-button, searchbar.inline-toolbar 
toolbutton > button.sidebar-button,
 .inline-toolbar.location-bar toolbutton > button.sidebar-button, .inline-toolbar headerbar toolbutton > 
button.titlebutton, headerbar .inline-toolbar toolbutton > button.titlebutton,
@@ -1572,6 +1568,15 @@ toolbar, .inline-toolbar, searchbar,
   .osd.top.location-bar, toolbar.osd.bottom, .osd.bottom.inline-toolbar, searchbar.osd.bottom,
   .osd.bottom.location-bar {
     border-radius: 0; }
+  toolbar separator, .inline-toolbar separator, searchbar separator,
+  .location-bar separator {
+    background: none; }
+  toolbar.horizontal separator, .horizontal.inline-toolbar separator, searchbar.horizontal separator,
+  .horizontal.location-bar separator {
+    margin: 0 6px; }
+  toolbar.vertical separator, .vertical.inline-toolbar separator, searchbar.vertical separator,
+  .vertical.location-bar separator {
+    margin: 6px 0; }
 
 .inline-toolbar {
   border-width: 0 1px 1px;
diff --git a/gtk/theme/Adwaita/gtk-contained.css b/gtk/theme/Adwaita/gtk-contained.css
index 60cfc2d..c217e65 100644
--- a/gtk/theme/Adwaita/gtk-contained.css
+++ b/gtk/theme/Adwaita/gtk-contained.css
@@ -1106,10 +1106,6 @@ button, headerbar button.titlebutton,
     .inline-toolbar toolbutton > button:backdrop:disabled:active > .label, .inline-toolbar toolbutton > 
button:backdrop:disabled:checked > .label {
       color: inherit; }
 
-toolbar separator, .inline-toolbar separator, searchbar separator,
-.location-bar separator {
-  background: none; }
-
 toolbar.inline-toolbar toolbutton > button.flat, .inline-toolbar toolbutton > button.flat, 
searchbar.inline-toolbar toolbutton > button.flat,
 .inline-toolbar.location-bar toolbutton > button.flat, toolbar.inline-toolbar toolbutton > 
button.sidebar-button, .inline-toolbar toolbutton > button.sidebar-button, searchbar.inline-toolbar 
toolbutton > button.sidebar-button,
 .inline-toolbar.location-bar toolbutton > button.sidebar-button, .inline-toolbar headerbar toolbutton > 
button.titlebutton, headerbar .inline-toolbar toolbutton > button.titlebutton,
@@ -1572,6 +1568,15 @@ toolbar, .inline-toolbar, searchbar,
   .osd.top.location-bar, toolbar.osd.bottom, .osd.bottom.inline-toolbar, searchbar.osd.bottom,
   .osd.bottom.location-bar {
     border-radius: 0; }
+  toolbar separator, .inline-toolbar separator, searchbar separator,
+  .location-bar separator {
+    background: none; }
+  toolbar.horizontal separator, .horizontal.inline-toolbar separator, searchbar.horizontal separator,
+  .horizontal.location-bar separator {
+    margin: 0 6px; }
+  toolbar.vertical separator, .vertical.inline-toolbar separator, searchbar.vertical separator,
+  .vertical.location-bar separator {
+    margin: 6px 0; }
 
 .inline-toolbar {
   border-width: 0 1px 1px;


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