cssimage: Add is_computed vfunc

Same semantics as the is_computed field of GtkCssValue
This commit is contained in:
Timm Bäder 2020-01-11 14:38:49 +01:00
parent 24d8c0a7dc
commit 0b2a6e34c4
7 changed files with 122 additions and 0 deletions

View File

@ -115,6 +115,12 @@ gtk_css_image_real_get_dynamic_image (GtkCssImage *image,
return g_object_ref (image);
}
static gboolean
gtk_css_image_real_is_computed (GtkCssImage *image)
{
return FALSE;
}
static void
_gtk_css_image_class_init (GtkCssImageClass *klass)
{
@ -127,6 +133,7 @@ _gtk_css_image_class_init (GtkCssImageClass *klass)
klass->is_invalid = gtk_css_image_real_is_invalid;
klass->is_dynamic = gtk_css_image_real_is_dynamic;
klass->get_dynamic_image = gtk_css_image_real_get_dynamic_image;
klass->is_computed = gtk_css_image_real_is_computed;
}
static void
@ -565,3 +572,10 @@ _gtk_css_image_new_parse (GtkCssParser *parser)
return image;
}
gboolean
gtk_css_image_is_computed (GtkCssImage *image)
{
GtkCssImageClass *klass = GTK_CSS_IMAGE_GET_CLASS (image);
return klass->is_computed (image);
}

View File

@ -414,6 +414,22 @@ gtk_css_image_cross_fade_dispose (GObject *object)
G_OBJECT_CLASS (gtk_css_image_cross_fade_parent_class)->dispose (object);
}
static gboolean
gtk_css_image_cross_fade_is_computed (GtkCssImage *image)
{
GtkCssImageCrossFade *cross_fade = GTK_CSS_IMAGE_CROSS_FADE (image);
guint i;
for (i = 0; i < cross_fade->images->len; i++)
{
const CrossFadeEntry *entry = &g_array_index (cross_fade->images, CrossFadeEntry, i);
if (!gtk_css_image_is_computed (entry->image))
return FALSE;
}
return TRUE;
}
static void
gtk_css_image_cross_fade_class_init (GtkCssImageCrossFadeClass *klass)
{
@ -429,6 +445,7 @@ gtk_css_image_cross_fade_class_init (GtkCssImageCrossFadeClass *klass)
image_class->get_dynamic_image = gtk_css_image_cross_fade_get_dynamic_image;
image_class->parse = gtk_css_image_cross_fade_parse;
image_class->print = gtk_css_image_cross_fade_print;
image_class->is_computed = gtk_css_image_cross_fade_is_computed;
object_class->dispose = gtk_css_image_cross_fade_dispose;
}

View File

@ -270,6 +270,30 @@ gtk_css_image_fallback_equal (GtkCssImage *image1,
fallback2->images[fallback2->used]);
}
static gboolean
gtk_css_image_fallback_is_computed (GtkCssImage *image)
{
GtkCssImageFallback *fallback = GTK_CSS_IMAGE_FALLBACK (image);
if (fallback->used < 0)
{
guint i;
if (fallback->color && !fallback->images)
return gtk_css_value_is_computed (fallback->color);
for (i = 0; i < fallback->n_images; i++)
{
if (!gtk_css_image_is_computed (fallback->images[i]))
{
return FALSE;
}
}
}
return TRUE;
}
static void
_gtk_css_image_fallback_class_init (GtkCssImageFallbackClass *klass)
{
@ -284,6 +308,7 @@ _gtk_css_image_fallback_class_init (GtkCssImageFallbackClass *klass)
image_class->compute = gtk_css_image_fallback_compute;
image_class->print = gtk_css_image_fallback_print;
image_class->equal = gtk_css_image_fallback_equal;
image_class->is_computed = gtk_css_image_fallback_is_computed;
object_class->dispose = gtk_css_image_fallback_dispose;
}

View File

@ -662,6 +662,35 @@ gtk_css_image_linear_dispose (GObject *object)
G_OBJECT_CLASS (_gtk_css_image_linear_parent_class)->dispose (object);
}
static gboolean
gtk_css_image_linear_is_computed (GtkCssImage *image)
{
GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
guint i;
gboolean computed = TRUE;
computed = !linear->angle || gtk_css_value_is_computed (linear->angle);
for (i = 0; i < linear->n_stops; i ++)
{
const GtkCssImageLinearColorStop *stop = &linear->color_stops[i];
if (stop->offset && !gtk_css_value_is_computed (stop->offset))
{
computed = FALSE;
break;
}
if (!gtk_css_value_is_computed (stop->color))
{
computed = FALSE;
break;
}
}
return computed;
}
static void
_gtk_css_image_linear_class_init (GtkCssImageLinearClass *klass)
{
@ -674,6 +703,7 @@ _gtk_css_image_linear_class_init (GtkCssImageLinearClass *klass)
image_class->compute = gtk_css_image_linear_compute;
image_class->equal = gtk_css_image_linear_equal;
image_class->transition = gtk_css_image_linear_transition;
image_class->is_computed = gtk_css_image_linear_is_computed;
object_class->dispose = gtk_css_image_linear_dispose;
}

View File

@ -89,6 +89,7 @@ struct _GtkCssImageClass
/* print to CSS */
void (* print) (GtkCssImage *image,
GString *string);
gboolean (* is_computed) (GtkCssImage *image);
};
GType _gtk_css_image_get_type (void) G_GNUC_CONST;
@ -139,6 +140,8 @@ cairo_surface_t *
cairo_surface_t *target,
int surface_width,
int surface_height);
gboolean gtk_css_image_is_computed (GtkCssImage *image);
G_END_DECLS

View File

@ -710,6 +710,37 @@ gtk_css_image_radial_dispose (GObject *object)
G_OBJECT_CLASS (_gtk_css_image_radial_parent_class)->dispose (object);
}
static gboolean
gtk_css_image_radial_is_computed (GtkCssImage *image)
{
GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (image);
guint i;
gboolean computed = TRUE;
computed = computed && (!radial->position || gtk_css_value_is_computed (radial->position));
computed = computed && (!radial->sizes[0] || gtk_css_value_is_computed (radial->sizes[0]));
computed = computed && (!radial->sizes[1] || gtk_css_value_is_computed (radial->sizes[1]));
if (computed)
for (i = 0; i < radial->n_stops; i ++)
{
const GtkCssImageRadialColorStop *stop = &radial->color_stops[i];
if (stop->offset && !gtk_css_value_is_computed (stop->offset))
{
computed = FALSE;
break;
}
if (!gtk_css_value_is_computed (stop->color))
{
computed = FALSE;
break;
}
}
return computed;
}
static void
_gtk_css_image_radial_class_init (GtkCssImageRadialClass *klass)
{
@ -722,6 +753,7 @@ _gtk_css_image_radial_class_init (GtkCssImageRadialClass *klass)
image_class->compute = gtk_css_image_radial_compute;
image_class->transition = gtk_css_image_radial_transition;
image_class->equal = gtk_css_image_radial_equal;
image_class->is_computed = gtk_css_image_radial_is_computed;
object_class->dispose = gtk_css_image_radial_dispose;
}

View File

@ -144,6 +144,7 @@ _gtk_css_image_value_new (GtkCssImage *image)
value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_IMAGE);
value->image = image;
value->is_computed = gtk_css_image_is_computed (image);
return value;
}