[gtk+] iconhelper: Pass only the CssStyle when loading icons



commit ee6e685478d07a4c10c6af255a548f7bdc8ffc7c
Author: Benjamin Otte <otte redhat com>
Date:   Mon Dec 7 04:44:39 2015 +0100

    iconhelper: Pass only the CssStyle when loading icons
    
    This is the first step in replacing StyleContext usage with CssNode
    usage.

 gtk/Makefile.am           |    1 +
 gtk/gtkiconhelper.c       |   68 +++++++++++++++++++++++++++++++-------------
 gtk/gtkicontheme.c        |   24 +++++++++------
 gtk/gtkiconthemeprivate.h |   29 +++++++++++++++++++
 4 files changed, 92 insertions(+), 30 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index f56aa57..9659e98 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -463,6 +463,7 @@ gtk_private_h_sources =             \
        gtkhslaprivate.h        \
        gtkiconcache.h          \
        gtkiconhelperprivate.h  \
+       gtkiconthemeprivate.h  \
        gtkiconviewprivate.h    \
        gtkimagedefinitionprivate.h     \
        gtkimageprivate.h       \
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c
index f964ef6..4ae5f97 100644
--- a/gtk/gtkiconhelper.c
+++ b/gtk/gtkiconhelper.c
@@ -25,6 +25,7 @@
 
 #include "gtkcssenumvalueprivate.h"
 #include "gtkcssiconthemevalueprivate.h"
+#include "gtkiconthemeprivate.h"
 #include "gtkrender.h"
 #include "gtkstylecontextprivate.h"
 #include "deprecated/gtkstock.h"
@@ -155,19 +156,19 @@ ensure_icon_size (GtkIconHelper *self,
 }
 
 static GtkIconLookupFlags
-get_icon_lookup_flags (GtkIconHelper *self, GtkStyleContext *context)
+get_icon_lookup_flags (GtkIconHelper    *self,
+                       GtkCssStyle      *style,
+                       GtkTextDirection  dir)
 {
   GtkIconLookupFlags flags;
   GtkCssIconStyle icon_style;
-  GtkStateFlags state;
 
-  state = gtk_style_context_get_state (context);
   flags = GTK_ICON_LOOKUP_USE_BUILTIN;
 
   if (self->priv->pixel_size != -1 || self->priv->force_scale_pixbuf)
     flags |= GTK_ICON_LOOKUP_FORCE_SIZE;
 
-  icon_style = _gtk_css_icon_style_value_get (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_ICON_STYLE));
+  icon_style = _gtk_css_icon_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_STYLE));
 
   switch (icon_style)
     {
@@ -184,9 +185,9 @@ get_icon_lookup_flags (GtkIconHelper *self, GtkStyleContext *context)
       return 0;
     }
 
-  if (state & GTK_STATE_FLAG_DIR_LTR)
+  if (dir == GTK_TEXT_DIR_LTR)
     flags |= GTK_ICON_LOOKUP_DIR_LTR;
-  else if (state & GTK_STATE_FLAG_DIR_RTL)
+  else if (dir == GTK_TEXT_DIR_RTL)
     flags |= GTK_ICON_LOOKUP_DIR_RTL;
 
   return flags;
@@ -364,10 +365,11 @@ G_GNUC_END_IGNORE_DEPRECATIONS;
 }
 
 static cairo_surface_t *
-ensure_surface_for_gicon (GtkIconHelper   *self,
-                          GtkStyleContext *context,
-                          gint             scale,
-                          GIcon           *gicon)
+ensure_surface_for_gicon (GtkIconHelper    *self,
+                          GtkCssStyle      *style,
+                          GtkTextDirection  dir,
+                          gint              scale,
+                          GIcon            *gicon)
 {
   GtkIconTheme *icon_theme;
   gint width, height;
@@ -378,8 +380,8 @@ ensure_surface_for_gicon (GtkIconHelper   *self,
   gboolean symbolic;
 
   icon_theme = gtk_css_icon_theme_value_get_icon_theme
-    (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_THEME));
-  flags = get_icon_lookup_flags (self, context);
+    (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_THEME));
+  flags = get_icon_lookup_flags (self, style, dir);
 
   ensure_icon_size (self, &width, &height);
 
@@ -389,11 +391,25 @@ ensure_surface_for_gicon (GtkIconHelper   *self,
                                                    scale, flags);
   if (info)
     {
-      destination =
-        gtk_icon_info_load_symbolic_for_context (info,
-                                                 context,
-                                                 &symbolic,
-                                                 NULL);
+      symbolic = gtk_icon_info_is_symbolic (info);
+
+      if (symbolic)
+        {
+          GdkRGBA fg, success_color, warning_color, error_color;
+
+          gtk_icon_theme_lookup_symbolic_colors (style, &fg, &success_color, &warning_color, &error_color);
+
+          destination = gtk_icon_info_load_symbolic (info,
+                                                     &fg, &success_color,
+                                                     &warning_color, &error_color,
+                                                     NULL,
+                                                     NULL);
+        }
+      else
+        {
+          destination = gtk_icon_info_load_icon (info, NULL);
+        }
+
       g_object_unref (info);
     }
   else
@@ -419,7 +435,7 @@ ensure_surface_for_gicon (GtkIconHelper   *self,
       GtkCssIconEffect icon_effect;
 
       surface = gdk_cairo_surface_create_from_pixbuf (destination, scale, self->priv->window);
-      icon_effect = _gtk_css_icon_effect_value_get (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_ICON_EFFECT));
+      icon_effect = _gtk_css_icon_effect_value_get (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_ICON_EFFECT));
       gtk_css_icon_effect_apply (icon_effect, surface);
     }
   else
@@ -472,12 +488,24 @@ gtk_icon_helper_load_surface (GtkIconHelper   *self,
         gicon = g_themed_icon_new_with_default_fallbacks (gtk_image_definition_get_icon_name 
(self->priv->def));
       else
         gicon = g_themed_icon_new (gtk_image_definition_get_icon_name (self->priv->def));
-      surface = ensure_surface_for_gicon (self, context, scale, gicon);
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+      surface = ensure_surface_for_gicon (self,
+                                          gtk_style_context_lookup_style (context), 
+                                          gtk_style_context_get_direction (context), 
+                                          scale, 
+                                          gicon);
+G_GNUC_END_IGNORE_DEPRECATIONS;
       g_object_unref (gicon);
       break;
 
     case GTK_IMAGE_GICON:
-      surface = ensure_surface_for_gicon (self, context, scale, gtk_image_definition_get_gicon 
(self->priv->def));
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+      surface = ensure_surface_for_gicon (self, 
+                                          gtk_style_context_lookup_style (context), 
+                                          gtk_style_context_get_direction (context), 
+                                          scale,
+                                          gtk_image_definition_get_gicon (self->priv->def));
+G_GNUC_END_IGNORE_DEPRECATIONS;
       break;
 
     case GTK_IMAGE_ANIMATION:
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index a440510..e425169 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -4666,18 +4666,18 @@ gtk_icon_info_load_symbolic (GtkIconInfo    *icon_info,
                                                error);
 }
 
-static void
-lookup_colors_from_style_context (GtkStyleContext *context,
-                                  GdkRGBA         *color_out,
-                                  GdkRGBA         *success_out,
-                                  GdkRGBA         *warning_out,
-                                  GdkRGBA         *error_out)
+void
+gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style,
+                                       GdkRGBA     *color_out,
+                                       GdkRGBA     *success_out,
+                                       GdkRGBA     *warning_out,
+                                       GdkRGBA     *error_out)
 {
   GtkCssValue *palette, *color;
   const GdkRGBA *lookup;
 
-  color = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR);
-  palette = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_PALETTE);
+  color = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_COLOR);
+  palette = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_PALETTE);
   *color_out = *_gtk_css_rgba_value_get_rgba (color);
 
   lookup = gtk_css_palette_value_get_color (palette, "success");
@@ -4747,7 +4747,9 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo      *icon_info,
   if (!is_symbolic)
     return gtk_icon_info_load_icon (icon_info, error);
 
-  lookup_colors_from_style_context (context, &fg, &success_color, &warning_color, &error_color);
+  gtk_icon_theme_lookup_symbolic_colors (gtk_style_context_lookup_style (context),
+                                         &fg, &success_color,
+                                         &warning_color, &error_color);
 
   return gtk_icon_info_load_symbolic_internal (icon_info,
                                                &fg, &success_color,
@@ -5011,7 +5013,9 @@ gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo         *icon_info,
   g_return_if_fail (icon_info != NULL);
   g_return_if_fail (context != NULL);
 
-  lookup_colors_from_style_context (context, &fg, &success_color, &warning_color, &error_color);
+  gtk_icon_theme_lookup_symbolic_colors (gtk_style_context_lookup_style (context),
+                                         &fg, &success_color,
+                                         &warning_color, &error_color);
 
   gtk_icon_info_load_symbolic_async (icon_info,
                                      &fg, &success_color,
diff --git a/gtk/gtkiconthemeprivate.h b/gtk/gtkiconthemeprivate.h
new file mode 100644
index 0000000..77d9561
--- /dev/null
+++ b/gtk/gtkiconthemeprivate.h
@@ -0,0 +1,29 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2015 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_ICON_THEME_PRIVATE_H__
+#define __GTK_ICON_THEME_PRIVATE_H__
+
+#include <gtk/gtkicontheme.h>
+
+void        gtk_icon_theme_lookup_symbolic_colors       (GtkCssStyle    *style,
+                                                         GdkRGBA        *color_out,
+                                                         GdkRGBA        *success_out,
+                                                         GdkRGBA        *warning_out,
+                                                         GdkRGBA        *error_out);
+
+#endif /* __GTK_ICON_THEME_PRIVATE_H__ */


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