[gtk+/wip/ebassi/gsk-renderer: 160/194] gadget: Add a has_content vfunc



commit a51a45ff2c5eefd174231cdebf5cafc2083d9a02
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 6 17:23:24 2016 -0400

    gadget: Add a has_content vfunc
    
    ...and implement it for GtkCssGadget and GtkCssCustomGadget.
    This allows us to decide on a per-object basis if a custom
    gadget needs a render node for content or not.

 gtk/gtkcsscustomgadget.c  |    9 +++++++++
 gtk/gtkcssgadget.c        |   12 ++++++++++--
 gtk/gtkcssgadgetprivate.h |    3 +++
 3 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcsscustomgadget.c b/gtk/gtkcsscustomgadget.c
index 60a1881..7cf9096 100644
--- a/gtk/gtkcsscustomgadget.c
+++ b/gtk/gtkcsscustomgadget.c
@@ -161,6 +161,14 @@ gtk_css_custom_gadget_draw (GtkCssGadget *gadget,
     return GTK_CSS_GADGET_CLASS (gtk_css_custom_gadget_parent_class)->draw (gadget, cr, x, y, width, height);
 }
 
+static gboolean
+gtk_css_custom_gadget_has_content (GtkCssGadget *gadget)
+{
+  GtkCssCustomGadgetPrivate *priv = gtk_css_custom_gadget_get_instance_private (GTK_CSS_CUSTOM_GADGET 
(gadget));
+
+  return priv->draw_func != NULL;
+}
+
 static void
 gtk_css_custom_gadget_finalize (GObject *object)
 {
@@ -183,6 +191,7 @@ gtk_css_custom_gadget_class_init (GtkCssCustomGadgetClass *klass)
   gadget_class->get_preferred_size = gtk_css_custom_gadget_get_preferred_size;
   gadget_class->allocate = gtk_css_custom_gadget_allocate;
   gadget_class->draw = gtk_css_custom_gadget_draw;
+  gadget_class->has_content = gtk_css_custom_gadget_has_content;
 }
 
 static void
diff --git a/gtk/gtkcssgadget.c b/gtk/gtkcssgadget.c
index 1074d1a..b89c41b 100644
--- a/gtk/gtkcssgadget.c
+++ b/gtk/gtkcssgadget.c
@@ -242,7 +242,6 @@ gtk_css_gadget_set_property (GObject      *object,
   }
 }
 
-
 static void
 gtk_css_gadget_finalize (GObject *object)
 {
@@ -253,6 +252,14 @@ gtk_css_gadget_finalize (GObject *object)
   G_OBJECT_CLASS (gtk_css_gadget_parent_class)->finalize (object);
 }
 
+static gboolean
+gtk_css_gadget_has_content (GtkCssGadget *gadget)
+{
+  GtkCssGadgetClass *gadget_class = GTK_CSS_GADGET_GET_CLASS (gadget);
+
+  return gadget_class->draw != gtk_css_gadget_real_draw;
+}
+
 static void
 gtk_css_gadget_class_init (GtkCssGadgetClass *klass)
 {
@@ -266,6 +273,7 @@ gtk_css_gadget_class_init (GtkCssGadgetClass *klass)
   klass->allocate = gtk_css_gadget_real_allocate;
   klass->draw = gtk_css_gadget_real_draw;
   klass->style_changed = gtk_css_gadget_real_style_changed;
+  klass->has_content = gtk_css_gadget_has_content;
 
   properties[PROP_NODE] = g_param_spec_object ("node", "Node",
                                                "CSS node",
@@ -904,7 +912,7 @@ gtk_css_gadget_get_render_node (GtkCssGadget  *gadget,
                                       graphene_point3d_init (&tmp, -contents_x, -contents_y, 0));
 
       /* If there's an override in place, create a temporary node */
-      if (gadget_class->draw != gtk_css_gadget_real_draw)
+      if (gadget_class->has_content (gadget))
         {
           content_node = gsk_renderer_create_render_node (renderer);
 
diff --git a/gtk/gtkcssgadgetprivate.h b/gtk/gtkcssgadgetprivate.h
index 94a0630..54c6132 100644
--- a/gtk/gtkcssgadgetprivate.h
+++ b/gtk/gtkcssgadgetprivate.h
@@ -70,6 +70,8 @@ struct _GtkCssGadgetClass
 
   void          (* style_changed)                       (GtkCssGadget           *gadget,
                                                          GtkCssStyleChange      *change);
+
+  gboolean      (* has_content)                         (GtkCssGadget           *gadget);
 };
 
 GType           gtk_css_gadget_get_type                 (void) G_GNUC_CONST;
@@ -143,6 +145,7 @@ void            gtk_css_gadget_get_content_allocation   (GtkCssGadget
                                                          GtkAllocation          *allocation,
                                                          int                    *baseline);
 
+
 G_END_DECLS
 
 #endif /* __GTK_CSS_GADGET_PRIVATE_H__ */


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