[gtk/wip/baedert/for-master: 9/29] cssrgbavalue: Add a singleton for transparent colors
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master: 9/29] cssrgbavalue: Add a singleton for transparent colors
- Date: Fri, 23 Aug 2019 07:54:04 +0000 (UTC)
commit 6c94041470f0989b656962e1fede99765100f283
Author: Timm Bäder <mail baedert org>
Date: Sat Aug 17 19:53:32 2019 +0200
cssrgbavalue: Add a singleton for transparent colors
The most common background color is no background color.
gtk/gtkcsscolorvalue.c | 6 ++----
gtk/gtkcssrgbavalue.c | 22 ++++++++++++++++++++++
gtk/gtkcssrgbavalueprivate.h | 3 ++-
gtk/gtkcssshadowvalue.c | 4 +---
gtk/gtkcssstylepropertyimpl.c | 2 +-
5 files changed, 28 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkcsscolorvalue.c b/gtk/gtkcsscolorvalue.c
index 617f92bdc1..091cb07c85 100644
--- a/gtk/gtkcsscolorvalue.c
+++ b/gtk/gtkcsscolorvalue.c
@@ -97,8 +97,6 @@ gtk_css_value_color_get_fallback (guint property_id,
GtkCssStyle *style,
GtkCssStyle *parent_style)
{
- static const GdkRGBA transparent = { 0, 0, 0, 0 };
-
switch (property_id)
{
case GTK_CSS_PROPERTY_BACKGROUND_IMAGE:
@@ -106,7 +104,7 @@ gtk_css_value_color_get_fallback (guint property_id,
case GTK_CSS_PROPERTY_TEXT_SHADOW:
case GTK_CSS_PROPERTY_ICON_SHADOW:
case GTK_CSS_PROPERTY_BOX_SHADOW:
- return _gtk_css_rgba_value_new_from_rgba (&transparent);
+ return _gtk_css_rgba_value_new_transparent ();
case GTK_CSS_PROPERTY_COLOR:
case GTK_CSS_PROPERTY_BACKGROUND_COLOR:
case GTK_CSS_PROPERTY_BORDER_TOP_COLOR:
@@ -127,7 +125,7 @@ gtk_css_value_color_get_fallback (guint property_id,
if (property_id < GTK_CSS_PROPERTY_N_PROPERTIES)
g_warning ("No fallback color defined for property '%s'",
_gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id
(property_id))));
- return _gtk_css_rgba_value_new_from_rgba (&transparent);
+ return _gtk_css_rgba_value_new_transparent ();
}
}
diff --git a/gtk/gtkcssrgbavalue.c b/gtk/gtkcssrgbavalue.c
index a7134ef465..f840160bde 100644
--- a/gtk/gtkcssrgbavalue.c
+++ b/gtk/gtkcssrgbavalue.c
@@ -107,6 +107,9 @@ static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
gtk_css_value_rgba_print
};
+static GtkCssValue transparent_black_singleton = (GtkCssValue) { >K_CSS_VALUE_RGBA, 1, { 0, 0, 0, 0 }};
+static GtkCssValue transparent_white_singleton = (GtkCssValue) { >K_CSS_VALUE_RGBA, 1, { 1, 1, 1, 0 }};
+
GtkCssValue *
_gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
{
@@ -114,12 +117,31 @@ _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
g_return_val_if_fail (rgba != NULL, NULL);
+ if (gdk_rgba_is_clear (rgba))
+ {
+ if (rgba->red == 1 &&
+ rgba->green == 1 &&
+ rgba->blue == 1)
+ return _gtk_css_value_ref (&transparent_white_singleton);
+
+ if (rgba->red == 0 &&
+ rgba->green == 0 &&
+ rgba->blue == 0)
+ return _gtk_css_value_ref (&transparent_black_singleton);
+ }
+
value = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_RGBA);
value->rgba = *rgba;
return value;
}
+GtkCssValue *
+_gtk_css_rgba_value_new_transparent (void)
+{
+ return _gtk_css_value_ref (&transparent_black_singleton);
+}
+
const GdkRGBA *
_gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
{
diff --git a/gtk/gtkcssrgbavalueprivate.h b/gtk/gtkcssrgbavalueprivate.h
index 60a0cffd6f..56760c275e 100644
--- a/gtk/gtkcssrgbavalueprivate.h
+++ b/gtk/gtkcssrgbavalueprivate.h
@@ -26,7 +26,8 @@
G_BEGIN_DECLS
-GtkCssValue * _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba);
+GtkCssValue * _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba);
+GtkCssValue * _gtk_css_rgba_value_new_transparent (void);
const GdkRGBA * _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba) G_GNUC_PURE;
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index f0b2fc243d..d2febe7522 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -189,8 +189,6 @@ gtk_css_shadow_value_new (GtkCssValue *hoffset,
GtkCssValue *
_gtk_css_shadow_value_new_for_transition (GtkCssValue *target)
{
- GdkRGBA transparent = { 0, 0, 0, 0 };
-
g_return_val_if_fail (target->class == >K_CSS_VALUE_SHADOW, NULL);
return gtk_css_shadow_value_new (_gtk_css_number_value_new (0, GTK_CSS_PX),
@@ -198,7 +196,7 @@ _gtk_css_shadow_value_new_for_transition (GtkCssValue *target)
_gtk_css_number_value_new (0, GTK_CSS_PX),
_gtk_css_number_value_new (0, GTK_CSS_PX),
target->inset,
- _gtk_css_rgba_value_new_from_rgba (&transparent));
+ _gtk_css_rgba_value_new_transparent ());
}
enum {
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index a1987b751a..af2869121b 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -991,7 +991,7 @@ _gtk_css_style_property_init_properties (void)
GTK_CSS_AFFECTS_BACKGROUND,
color_parse,
color_query,
- _gtk_css_color_value_new_rgba (0, 0, 0, 0));
+ _gtk_css_rgba_value_new_transparent ());
gtk_css_style_property_register ("font-family",
GTK_CSS_PROPERTY_FONT_FAMILY,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]