[gtk+/gtk-style-context: 291/490] Rely only on fg/bg colors.



commit 7ba2e2582448005f89bf183f43a88a0c14b8cd05
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Oct 29 05:33:38 2010 +0200

    Rely only on fg/bg colors.
    
    "foreground-color" has been renamed to just "color" as in regular CSS,
    and the "text-color" and "base-color" properties have been removed. The
    default CSS has been changed to have widgets cope with this change.

 gtk/gtkcssprovider.c   |   68 +++++++++++++++++++----------------
 gtk/gtkstyle.c         |   34 ++++++++++++++----
 gtk/gtkstyleset.c      |    4 +--
 gtk/gtkthemingengine.c |   95 ++++++++++++++----------------------------------
 4 files changed, 92 insertions(+), 109 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 21bde66..0025a59 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -97,12 +97,12 @@
  * <programlisting>
  * /&ast; Theme all widgets defining the class entry &ast;/
  * .entry {
- *     foreground-color: &num;39f1f9;
+ *     color: &num;39f1f9;
  * }
  *
  * /&ast; Theme spinbuttons' entry &ast;/
  * GtkSpinButton.entry {
- *     foreground-color: &num;900185;
+ *     color: &num;900185;
  * }
  * </programlisting>
  * </example>
@@ -117,19 +117,19 @@
  * <programlisting>
  * /&ast; Theme any label within a notebook &ast;/
  * GtkNotebook GtkLabel {
- *     foreground-color: &num;f90192;
+ *     color: &num;f90192;
  * }
  *
  * /&ast; Theme labels within notebook tabs &ast;/
  * GtkNotebook tab:nth-child GtkLabel {
- *     foreground-color: &num;703910;
+ *     color: &num;703910;
  * }
  *
  * /&ast; Theme labels in the any first notebook
  *  tab, both selectors are equivalent &ast;/
  * GtkNotebook tab:nth-child(first) GtkLabel,
  * GtkNotebook tab:first-child GtkLabel {
- *     foreground-color: &num;89d012;
+ *     color: &num;89d012;
  * }
  * </programlisting>
  * </example>
@@ -278,24 +278,18 @@
  *       </row>
  *       <row>
  *         <entry>background-color</entry>
- *         <entry morerows="3"><programlisting>color</programlisting></entry>
- *         <entry morerows="3">#GdkRGBA</entry>
- *         <entry morerows="3">
+ *         <entry morerows="1"><programlisting>color</programlisting></entry>
+ *         <entry morerows="1">#GdkRGBA</entry>
+ *         <entry morerows="1">
  *           <programlisting>
  * background-color: &num;fff;
- * foreground-color: @color-name;
- * text-color: shade (@color-name, 0.5);
- * base-color: mix (@color-name, &num;f0f, 0.8);</programlisting>
+ * color: @color-name;
+ * background-color: shade (@color-name, 0.5);
+ * color: mix (@color-name, &num;f0f, 0.8);</programlisting>
  *         </entry>
  *       </row>
  *       <row>
- *         <entry>foreground-color</entry>
- *       </row>
- *       <row>
- *         <entry>text-color</entry>
- *       </row>
- *       <row>
- *         <entry>base-color</entry>
+ *         <entry>color</entry>
  *       </row>
  *       <row>
  *         <entry>font</entry>
@@ -2872,38 +2866,34 @@ gtk_css_provider_get_default (void)
         "*,\n"
         "GtkTreeView > GtkButton {\n"
         "  background-color: @bg_color;\n"
-        "  foreground-color: @fg_color;\n"
-        "  text-color: @text_color; \n"
-        "  base-color: @base_color; \n"
+        "  color: @fg_color;\n"
         "  border-color: shade (@bg_color, 0.7);\n"
         "  padding: 2 2; \n"
         "}\n"
         "\n"
         "*:prelight {\n"
         "  background-color: shade (@bg_color, 2.0);\n"
-        "  foreground-color: shade (@fg_color, 1.3);\n"
-        "  text-color: @selected_fg_color;\n"
-        "  base-color: @selected_bg_color;\n"
+        "  color: shade (@fg_color, 1.3);\n"
         "}\n"
         "\n"
         "*:selected {\n"
         "  background-color: @selected_bg_color;\n"
-        "  foreground-color: @selected_fg_color;\n"
+        "  color: @selected_fg_color;\n"
         "}\n"
         "\n"
         "*:insensitive {\n"
         "  background-color: shade (@bg_color, 0.7);\n"
-        "  foreground-color: shade (@fg_color, 0.7);\n"
+        "  color: shade (@fg_color, 0.7);\n"
         "}\n"
         "\n"
-        "GtkTreeView, GtkIconView {\n"
+        "GtkTreeView, GtkIconView, GtkTextView {\n"
         "  background-color: @base_color;\n"
-        "  foreground-color: @text_color;\n"
+        "  color: @text_color;\n"
         "}\n"
         "\n"
         "GtkTreeView > row {\n"
         "  background-color: @base_color;\n"
-        "  foreground-color: @text_color;\n"
+        "  color: @text_color;\n"
         "}\n"
         "\n"
         "GtkTreeView > row:nth-child(odd) { \n"
@@ -2912,7 +2902,7 @@ gtk_css_provider_get_default (void)
         "\n"
         ".tooltip {\n"
         "  background-color: @tooltip_bg_color; \n"
-        "  foreground-color: @tooltip_fg_color; \n"
+        "  color: @tooltip_fg_color; \n"
         "}\n"
         "\n"
         ".button,\n"
@@ -2929,7 +2919,7 @@ gtk_css_provider_get_default (void)
         ".button:prelight,\n"
         ".slider:prelight {\n"
         "  background-color: @selected_bg_color;\n"
-        "  foreground-color: @selected_fg_color;\n"
+        "  color: @selected_fg_color;\n"
         "  border-color: shade (@selected_bg_color, 0.7);\n"
         "}\n"
         "\n"
@@ -2941,6 +2931,22 @@ gtk_css_provider_get_default (void)
         ".entry {\n"
         "  border-style: inset;\n"
         "  border-width: 2;\n"
+        "  background-color: @base_color;\n"
+        "  color: @text_color;\n"
+        "}\n"
+        ".check, .radio {\n"
+        "  background-color: @base_color;\n"
+        "  color: @text_color;\n"
+        "}\n"
+        "\n"
+        ".menu.check,\n"
+        ".menu.radio {\n"
+        "  color: @fg_color;\n"
+        "}\n"
+        "\n"
+        ".menu:hover {\n"
+        "  background-color: @selected_bg_color;\n"
+        "  border-style: none;\n"
         "}\n"
         "\n"
         ".viewport {\n"
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index 7c80afb..efb8383 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -655,19 +655,19 @@ set_color (GtkStyle        *style,
       break;
     case GTK_RC_FG:
       gtk_style_context_get (context, state,
-                             "foreground-color", &color,
+                             "color", &color,
                              NULL);
       dest = &style->fg[state];
       break;
     case GTK_RC_TEXT:
       gtk_style_context_get (context, state,
-                             "text-color", &color,
+                             "color", &color,
                              NULL);
       dest = &style->text[state];
       break;
     case GTK_RC_BASE:
       gtk_style_context_get (context, state,
-                             "base-color", &color,
+                             "background-color", &color,
                              NULL);
       dest = &style->base[state];
       break;
@@ -694,10 +694,28 @@ gtk_style_update_from_context (GtkStyle *style)
 
   for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++)
     {
-      set_color (style, priv->context, state, GTK_RC_BG);
-      set_color (style, priv->context, state, GTK_RC_FG);
-      set_color (style, priv->context, state, GTK_RC_BASE);
-      set_color (style, priv->context, state, GTK_RC_TEXT);
+      if (gtk_style_context_has_class (priv->context, "entry"))
+        {
+          gtk_style_context_save (priv->context);
+          gtk_style_context_remove_class (priv->context, "entry");
+          set_color (style, priv->context, state, GTK_RC_BG);
+          set_color (style, priv->context, state, GTK_RC_FG);
+          gtk_style_context_restore (priv->context);
+
+          set_color (style, priv->context, state, GTK_RC_BASE);
+          set_color (style, priv->context, state, GTK_RC_TEXT);
+        }
+      else
+        {
+          gtk_style_context_save (priv->context);
+          gtk_style_context_add_class (priv->context, "entry");
+          set_color (style, priv->context, state, GTK_RC_BASE);
+          set_color (style, priv->context, state, GTK_RC_TEXT);
+          gtk_style_context_restore (priv->context);
+
+          set_color (style, priv->context, state, GTK_RC_BG);
+          set_color (style, priv->context, state, GTK_RC_FG);
+        }
     }
 
   if (style->font_desc)
@@ -1831,6 +1849,8 @@ transform_detail_string (const gchar     *detail,
       gtk_style_context_add_class (context, "slider");
       gtk_style_context_add_class (context, "scrollbar");
     }
+  else if (strcmp (detail, "menuitem") == 0)
+    gtk_style_context_add_class (context, "menu");
   else if (g_str_has_prefix (detail, "cell"))
     {
       GtkRegionFlags row, col;
diff --git a/gtk/gtkstyleset.c b/gtk/gtkstyleset.c
index 6009329..e856d29 100644
--- a/gtk/gtkstyleset.c
+++ b/gtk/gtkstyleset.c
@@ -81,10 +81,8 @@ gtk_style_set_class_init (GtkStyleSetClass *klass)
   object_class->finalize = gtk_style_set_finalize;
 
   /* Initialize default property set */
-  gtk_style_set_register_property ("foreground-color", GDK_TYPE_RGBA, NULL, NULL);
+  gtk_style_set_register_property ("color", GDK_TYPE_RGBA, NULL, NULL);
   gtk_style_set_register_property ("background-color", GDK_TYPE_RGBA, NULL, NULL);
-  gtk_style_set_register_property ("text-color", GDK_TYPE_RGBA, NULL, NULL);
-  gtk_style_set_register_property ("base-color", GDK_TYPE_RGBA, NULL, NULL);
 
   gtk_style_set_register_property ("font", PANGO_TYPE_FONT_DESCRIPTION, NULL, NULL);
 
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 9fa5f27..5360ad0 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -865,7 +865,7 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
                                  gdouble           width,
                                  gdouble           height)
 {
-  GdkRGBA *fg_color, *base_color, *text_color;
+  GdkRGBA *fg_color, *bg_color;
   const GtkWidgetPath *path;
   GtkStateFlags flags;
   gint exterior_size, interior_size, thickness, pad;
@@ -875,9 +875,8 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
   cairo_save (cr);
 
   gtk_theming_engine_get (engine, flags,
-                          "foreground-color", &fg_color,
-                          "base-color", &base_color,
-                          "text-color", &text_color,
+                          "color", &fg_color,
+                          "background-color", &bg_color,
                           NULL);
 
   exterior_size = MIN (width, height);
@@ -904,21 +903,15 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
       cairo_set_line_width (cr, 1.0);
 
       cairo_rectangle (cr, x + 0.5, y + 0.5, exterior_size - 1, exterior_size - 1);
-      gdk_cairo_set_source_rgba (cr, base_color);
+      gdk_cairo_set_source_rgba (cr, bg_color);
       cairo_fill_preserve (cr);
 
-      if (gtk_theming_engine_has_class (engine, "cell"))
-	gdk_cairo_set_source_rgba (cr, text_color);
-      else
-	gdk_cairo_set_source_rgba (cr, fg_color);
+      gdk_cairo_set_source_rgba (cr, fg_color);
 
       cairo_stroke (cr);
     }
 
-  if (gtk_theming_engine_has_class (engine, "menu"))
-    gdk_cairo_set_source_rgba (cr, fg_color);
-  else
-    gdk_cairo_set_source_rgba (cr, text_color);
+  gdk_cairo_set_source_rgba (cr, fg_color);
 
   if (flags & GTK_STATE_FLAG_INCONSISTENT)
     {
@@ -977,8 +970,6 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
   cairo_restore (cr);
 
   gdk_rgba_free (fg_color);
-  gdk_rgba_free (base_color);
-  gdk_rgba_free (text_color);
 }
 
 static void
@@ -990,7 +981,7 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
                                   gdouble           height)
 {
   GtkStateFlags flags;
-  GdkRGBA *base_color, *fg_color, *text_color;
+  GdkRGBA *fg_color, *bg_color;
   const GtkWidgetPath *path;
   gint exterior_size, interior_size, pad, thickness;
   gdouble radius;
@@ -1002,9 +993,8 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
   cairo_save (cr);
 
   gtk_theming_engine_get (engine, flags,
-                          "foreground-color", &fg_color,
-                          "base-color", &base_color,
-                          "text-color", &text_color,
+                          "color", &fg_color,
+                          "background-color", &bg_color,
                           NULL);
 
   exterior_size = MIN (width, height);
@@ -1017,7 +1007,7 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
 
   if (!gtk_theming_engine_has_class (engine, "menu"))
     {
-      gdk_cairo_set_source_rgba (cr, base_color);
+      gdk_cairo_set_source_rgba (cr, bg_color);
 
       cairo_arc (cr,
 		 x + exterior_size / 2.,
@@ -1027,19 +1017,13 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
 
       cairo_fill_preserve (cr);
 
-      if (gtk_theming_engine_has_class (engine, "cell"))
-	gdk_cairo_set_source_rgba (cr, text_color);
-      else
-	gdk_cairo_set_source_rgba (cr, fg_color);
+      gdk_cairo_set_source_rgba (cr, fg_color);
 
       cairo_set_line_width (cr, 1.);
       cairo_stroke (cr);
     }
 
-  if (gtk_theming_engine_has_class (engine, "menu"))
-    gdk_cairo_set_source_rgba (cr, fg_color);
-  else
-    gdk_cairo_set_source_rgba (cr, text_color);
+  gdk_cairo_set_source_rgba (cr, fg_color);
 
   /* FIXME: thickness */
   thickness = 1;
@@ -1088,8 +1072,7 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
   cairo_restore (cr);
 
   gdk_rgba_free (fg_color);
-  gdk_rgba_free (base_color);
-  gdk_rgba_free (text_color);
+  gdk_rgba_free (bg_color);
 }
 
 static void
@@ -1128,7 +1111,7 @@ gtk_theming_engine_render_arrow (GtkThemingEngine *engine,
   flags = gtk_theming_engine_get_state (engine);
 
   gtk_theming_engine_get (engine, flags,
-                          "foreground-color", &fg_color,
+                          "color", &fg_color,
                           NULL);
 
   if (flags & GTK_STATE_FLAG_INSENSITIVE)
@@ -1350,7 +1333,7 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
                                       gdouble           width,
                                       gdouble           height)
 {
-  GdkRGBA *bg_color, *base_color;
+  GdkRGBA *bg_color;
   cairo_pattern_t *pattern;
   GtkStateFlags flags;
   gboolean running;
@@ -1374,7 +1357,6 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
   gtk_theming_engine_get (engine, flags,
                           "background-image", &pattern,
                           "background-color", &bg_color,
-                          "base-color", &base_color,
                           "border-radius", &radius,
                           NULL);
 
@@ -1399,7 +1381,7 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
     {
       cairo_pattern_t *other_pattern;
       GtkStateFlags other_flags;
-      GdkRGBA *other_bg, *other_base;
+      GdkRGBA *other_bg;
       cairo_pattern_t *new_pattern = NULL;
 
       if (flags & GTK_STATE_FLAG_PRELIGHT)
@@ -1413,7 +1395,6 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
       gtk_theming_engine_get (engine, other_flags,
                               "background-image", &other_pattern,
                               "background-color", &other_bg,
-                              "base-color", &other_base,
                               NULL);
 
       if (pattern && other_pattern)
@@ -1499,7 +1480,7 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
       else if (pattern || other_pattern)
         {
           cairo_pattern_t *p;
-          GdkRGBA *c;
+          const GdkRGBA *c;
           gdouble x0, y0, x1, y1, r0, r1;
           gint n, i;
 
@@ -1507,13 +1488,13 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
           if (pattern)
             {
               p = pattern;
-              c = gtk_theming_engine_has_class (engine, "entry") ? other_base : other_bg;
+	      c = other_bg;
               progress = 1 - progress;
             }
           else
             {
               p = other_pattern;
-              c = gtk_theming_engine_has_class (engine, "entry") ? base_color : bg_color;
+	      c = bg_color;
             }
 
           if (cairo_pattern_get_type (p) == CAIRO_PATTERN_TYPE_LINEAR)
@@ -1550,16 +1531,8 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
           const GdkRGBA *color, *other_color;
 
           /* Merge just colors */
-          if (gtk_theming_engine_has_class (engine, "entry"))
-            {
-              color = base_color;
-              other_color = other_base;
-            }
-          else
-            {
-              color = bg_color;
-              other_color = other_bg;
-            }
+	  color = bg_color;
+	  other_color = other_bg;
 
           new_pattern = cairo_pattern_create_rgba (CLAMP (color->red + ((other_color->red - color->red) * progress), 0, 1),
                                                    CLAMP (color->green + ((other_color->green - color->green) * progress), 0, 1),
@@ -1579,9 +1552,6 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
 
       if (other_bg)
         gdk_rgba_free (other_bg);
-
-      if (other_base)
-        gdk_rgba_free (other_base);
     }
 
   cairo_rectangle (cr, 0, 0, 1, 1);
@@ -1592,12 +1562,7 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
       cairo_pattern_destroy (pattern);
     }
   else
-    {
-      if (gtk_theming_engine_has_class (engine, "entry"))
-        gdk_cairo_set_source_rgba (cr, base_color);
-      else
-        gdk_cairo_set_source_rgba (cr, bg_color);
-    }
+    gdk_cairo_set_source_rgba (cr, bg_color);
 
   if (gtk_theming_engine_has_class (engine, "tooltip"))
     {
@@ -1622,7 +1587,6 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
 
   cairo_restore (cr);
 
-  gdk_rgba_free (base_color);
   gdk_rgba_free (bg_color);
 }
 
@@ -1780,7 +1744,7 @@ gtk_theming_engine_render_expander (GtkThemingEngine *engine,
                                     gdouble           height)
 {
   GtkStateFlags flags;
-  GdkRGBA *bg_color, *fg_color, *base_color;
+  GdkRGBA *bg_color, *fg_color;
   double vertical_overshoot;
   int diameter;
   double radius;
@@ -1795,9 +1759,8 @@ gtk_theming_engine_render_expander (GtkThemingEngine *engine,
   flags = gtk_theming_engine_get_state (engine);
 
   gtk_theming_engine_get (engine, flags,
-                          "foreground-color", &fg_color,
+                          "color", &fg_color,
                           "background-color", &bg_color,
-                          "base-color", &base_color,
                           NULL);
 
   line_width = 1;
@@ -1863,10 +1826,7 @@ gtk_theming_engine_render_expander (GtkThemingEngine *engine,
 
   cairo_set_line_width (cr, line_width);
 
-  if (flags & GTK_STATE_FLAG_PRELIGHT)
-    gdk_cairo_set_source_rgba (cr, fg_color);
-  else
-    gdk_cairo_set_source_rgba (cr, base_color);
+  gdk_cairo_set_source_rgba (cr, fg_color);
 
   cairo_fill_preserve (cr);
 
@@ -1875,7 +1835,6 @@ gtk_theming_engine_render_expander (GtkThemingEngine *engine,
 
   cairo_restore (cr);
 
-  gdk_rgba_free (base_color);
   gdk_rgba_free (fg_color);
   gdk_rgba_free (bg_color);
 }
@@ -1897,7 +1856,7 @@ gtk_theming_engine_render_focus (GtkThemingEngine *engine,
   flags = gtk_theming_engine_get_state (engine);
 
   gtk_theming_engine_get (engine, flags,
-                          "foreground-color", &color,
+                          "color", &color,
                           NULL);
 
   gtk_theming_engine_get_style (engine,
@@ -2044,7 +2003,7 @@ gtk_theming_engine_render_layout (GtkThemingEngine *engine,
   flags = gtk_theming_engine_get_state (engine);
 
   gtk_theming_engine_get (engine, flags,
-                          "foreground-color", &fg_color,
+                          "color", &fg_color,
                           NULL);
 
   screen = gtk_theming_engine_get_screen (engine);



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