static GtkCssValue * gtk_css_value_bg_size_compute (GtkCssValue *value, guint property_id, GtkStyleProviderPrivate *provider, int scale, GtkCssComputedValues *values, GtkCssComputedValues *parent_values, GtkCssDependencies *dependencies) { GtkCssValue *x, *y; GtkCssDependencies x_deps, y_deps; if (value->x == NULL && value->y == NULL) return _gtk_css_value_ref (value); x_deps = y_deps = 0; x = y = NULL; if (value->x) x = _gtk_css_value_compute (value->x, property_id, provider, scale, values, parent_values, &x_deps); if (value->y) y = _gtk_css_value_compute (value->y, property_id, provider, scale, values, parent_values, &y_deps); *dependencies = _gtk_css_dependencies_union (x_deps, y_deps); return _gtk_css_bg_size_value_new (value->x ? x : NULL, value->y ? y : NULL); }
static GtkCssValue * gtk_css_value_shadows_compute (GtkCssValue *value, guint property_id, GtkStyleProviderPrivate *provider, int scale, GtkCssComputedValues *values, GtkCssComputedValues *parent_values, GtkCssDependencies *dependencies) { GtkCssValue *result; GtkCssDependencies child_deps; guint i; if (value->len == 0) return _gtk_css_value_ref (value); result = gtk_css_shadows_value_new (value->values, value->len); for (i = 0; i < value->len; i++) { result->values[i] = _gtk_css_value_compute (value->values[i], property_id, provider, scale, values, parent_values, &child_deps); *dependencies = _gtk_css_dependencies_union (*dependencies, child_deps); } return result; }
static GtkCssImage * gtk_css_image_radial_compute (GtkCssImage *image, guint property_id, GtkStyleProviderPrivate *provider, GtkCssStyle *style, GtkCssStyle *parent_style) { GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (image); GtkCssImageRadial *copy; guint i; copy = g_object_new (GTK_TYPE_CSS_IMAGE_RADIAL, NULL); copy->repeating = radial->repeating; copy->circle = radial->circle; copy->size = radial->size; copy->position = _gtk_css_value_compute (radial->position, property_id, provider, style, parent_style); if (radial->sizes[0]) copy->sizes[0] = _gtk_css_value_compute (radial->sizes[0], property_id, provider, style, parent_style); if (radial->sizes[1]) copy->sizes[1] = _gtk_css_value_compute (radial->sizes[1], property_id, provider, style, parent_style); g_array_set_size (copy->stops, radial->stops->len); for (i = 0; i < radial->stops->len; i++) { GtkCssImageRadialColorStop *stop, *scopy; stop = &g_array_index (radial->stops, GtkCssImageRadialColorStop, i); scopy = &g_array_index (copy->stops, GtkCssImageRadialColorStop, i); scopy->color = _gtk_css_value_compute (stop->color, property_id, provider, style, parent_style); if (stop->offset) { scopy->offset = _gtk_css_value_compute (stop->offset, property_id, provider, style, parent_style); } else { scopy->offset = NULL; } } return GTK_CSS_IMAGE (copy); }
static GtkCssValue * gtk_css_value_initial_compute (GtkCssValue *value, guint property_id, GtkStyleProviderPrivate *provider, GtkCssStyle *style, GtkCssStyle *parent_style) { GtkSettings *settings; switch (property_id) { case GTK_CSS_PROPERTY_DPI: settings = _gtk_style_provider_private_get_settings (provider); if (settings) { GdkScreen *screen = _gtk_settings_get_screen (settings); double resolution = gdk_screen_get_resolution (screen); if (resolution > 0.0) return _gtk_css_number_value_new (resolution, GTK_CSS_NUMBER); } break; case GTK_CSS_PROPERTY_FONT_FAMILY: settings = _gtk_style_provider_private_get_settings (provider); if (settings) { PangoFontDescription *description; char *font_name; GtkCssValue *value; g_object_get (settings, "gtk-font-name", &font_name, NULL); description = pango_font_description_from_string (font_name); g_free (font_name); if (description == NULL) break; if (pango_font_description_get_set_fields (description) & PANGO_FONT_MASK_FAMILY) { value = _gtk_css_array_value_new (_gtk_css_string_value_new (pango_font_description_get_family (description))); pango_font_description_free (description); return value; } pango_font_description_free (description); } break; default: break; } return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)), property_id, provider, style, parent_style); }
static GtkCssImage * gtk_css_image_linear_compute (GtkCssImage *image, guint property_id, GtkStyleProviderPrivate *provider, GtkCssStyle *style, GtkCssStyle *parent_style) { GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image); GtkCssImageLinear *copy; guint i; copy = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL); copy->repeating = linear->repeating; copy->side = linear->side; if (linear->angle) copy->angle = _gtk_css_value_compute (linear->angle, property_id, provider, style, parent_style); g_array_set_size (copy->stops, linear->stops->len); for (i = 0; i < linear->stops->len; i++) { GtkCssImageLinearColorStop *stop, *scopy; stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i); scopy = &g_array_index (copy->stops, GtkCssImageLinearColorStop, i); scopy->color = _gtk_css_value_compute (stop->color, property_id, provider, style, parent_style); if (stop->offset) { scopy->offset = _gtk_css_value_compute (stop->offset, property_id, provider, style, parent_style); } else { scopy->offset = NULL; } } return GTK_CSS_IMAGE (copy); }
static GtkCssValue * gtk_css_value_bg_size_compute (GtkCssValue *value, guint property_id, GtkStyleProviderPrivate *provider, GtkCssStyle *style, GtkCssStyle *parent_style) { GtkCssValue *x, *y; if (value->x == NULL && value->y == NULL) return _gtk_css_value_ref (value); x = y = NULL; if (value->x) x = _gtk_css_value_compute (value->x, property_id, provider, style, parent_style); if (value->y) y = _gtk_css_value_compute (value->y, property_id, provider, style, parent_style); return _gtk_css_bg_size_value_new (value->x ? x : NULL, value->y ? y : NULL); }
static GtkCssImage * gtk_css_image_fallback_compute (GtkCssImage *image, guint property_id, GtkStyleProviderPrivate *provider, GtkCssStyle *style, GtkCssStyle *parent_style) { GtkCssImageFallback *fallback = GTK_CSS_IMAGE_FALLBACK (image); GtkCssImageFallback *copy; int i; if (fallback->used < 0) { copy = g_object_new (_gtk_css_image_fallback_get_type (), NULL); copy->n_images = fallback->n_images; copy->images = g_new (GtkCssImage *, fallback->n_images); for (i = 0; i < fallback->n_images; i++) { copy->images[i] = _gtk_css_image_compute (fallback->images[i], property_id, provider, style, parent_style); /* Assume that failing to load an image leaves a 0x0 surface image */ if (GTK_IS_CSS_IMAGE_SURFACE (copy->images[i]) && _gtk_css_image_get_width (copy->images[i]) == 0 && _gtk_css_image_get_height (copy->images[i]) == 0) continue; if (copy->used < 0) copy->used = i; } if (fallback->color) copy->color = _gtk_css_value_compute (fallback->color, property_id, provider, style, parent_style); else copy->color = NULL; return GTK_CSS_IMAGE (copy); }
static GtkCssImage * gtk_css_image_fallback_compute (GtkCssImage *image, guint property_id, GtkStyleProvider *provider, GtkCssStyle *style, GtkCssStyle *parent_style) { GtkCssImageFallback *fallback = GTK_CSS_IMAGE_FALLBACK (image); GtkCssImageFallback *copy; int i; if (fallback->used < 0) { copy = g_object_new (_gtk_css_image_fallback_get_type (), NULL); copy->n_images = fallback->n_images; copy->images = g_new (GtkCssImage *, fallback->n_images); for (i = 0; i < fallback->n_images; i++) { copy->images[i] = _gtk_css_image_compute (fallback->images[i], property_id, provider, style, parent_style); if (gtk_css_image_is_invalid (copy->images[i])) continue; if (copy->used < 0) copy->used = i; } if (fallback->color) copy->color = _gtk_css_value_compute (fallback->color, property_id, provider, style, parent_style); else copy->color = NULL; return GTK_CSS_IMAGE (copy); }
static GtkCssValue * gtk_css_value_inherit_compute (GtkCssValue *value, guint property_id, GtkStyleProviderPrivate *provider, GtkCssStyle *style, GtkCssStyle *parent_style) { if (parent_style) { return _gtk_css_value_ref (gtk_css_style_get_value (parent_style, property_id)); } else { return _gtk_css_value_compute (_gtk_css_initial_value_get (), property_id, provider, style, parent_style); } }
void _gtk_css_computed_values_compute_value (GtkCssComputedValues *values, GtkStyleProviderPrivate *provider, GtkCssComputedValues *parent_values, guint id, GtkCssValue *specified, GtkCssSection *section) { GtkCssDependencies dependencies; GtkCssValue *value; gtk_internal_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values)); gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider)); gtk_internal_return_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values)); /* http://www.w3.org/TR/css3-cascade/#cascade * Then, for every element, the value for each property can be found * by following this pseudo-algorithm: * 1) Identify all declarations that apply to the element */ if (specified == NULL) { GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (id); if (_gtk_css_style_property_is_inherit (prop)) specified = _gtk_css_inherit_value_new (); else specified = _gtk_css_initial_value_new (); } else _gtk_css_value_ref (specified); value = _gtk_css_value_compute (specified, id, provider, values, parent_values, &dependencies); _gtk_css_computed_values_set_value (values, id, value, dependencies, section); _gtk_css_value_unref (value); _gtk_css_value_unref (specified); }
static GtkCssValue * gtk_css_value_unset_compute (GtkCssValue *value, guint property_id, GtkStyleProviderPrivate *provider, GtkCssStyle *style, GtkCssStyle *parent_style) { GtkCssStyleProperty *property; GtkCssValue *unset_value; property = _gtk_css_style_property_lookup_by_id (property_id); if (_gtk_css_style_property_is_inherit (property)) unset_value = _gtk_css_inherit_value_get (); else unset_value = _gtk_css_initial_value_get (); return _gtk_css_value_compute (unset_value, property_id, provider, style, parent_style); }
static GtkCssValue * gtk_css_value_inherit_compute (GtkCssValue *value, guint property_id, GtkStyleProviderPrivate *provider, GtkCssComputedValues *values, GtkCssComputedValues *parent_values, GtkCssDependencies *dependencies) { if (parent_values) { *dependencies = GTK_CSS_EQUALS_PARENT; return _gtk_css_value_ref (_gtk_css_computed_values_get_value (parent_values, property_id)); } else { return _gtk_css_value_compute (_gtk_css_initial_value_get (), property_id, provider, values, parent_values, dependencies); } }
void _gtk_css_computed_values_compute_value (GtkCssComputedValues *values, GtkStyleProviderPrivate *provider, int scale, GtkCssComputedValues *parent_values, guint id, GtkCssValue *specified, GtkCssSection *section) { GtkCssDependencies dependencies; GtkCssValue *value; gtk_internal_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values)); gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider)); gtk_internal_return_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values)); /* http://www.w3.org/TR/css3-cascade/#cascade * Then, for every element, the value for each property can be found * by following this pseudo-algorithm: * 1) Identify all declarations that apply to the element */ if (specified == NULL) { GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (id); if (_gtk_css_style_property_is_inherit (prop)) specified = _gtk_css_inherit_value_new (); else specified = _gtk_css_initial_value_new (); } else _gtk_css_value_ref (specified); value = _gtk_css_value_compute (specified, id, provider, scale, values, parent_values, &dependencies); if (values->values == NULL) values->values = g_ptr_array_new_full (_gtk_css_style_property_get_n_properties (), (GDestroyNotify)_gtk_css_value_unref); if (id >= values->values->len) g_ptr_array_set_size (values->values, id + 1); if (g_ptr_array_index (values->values, id)) _gtk_css_value_unref (g_ptr_array_index (values->values, id)); g_ptr_array_index (values->values, id) = _gtk_css_value_ref (value); if (dependencies & (GTK_CSS_DEPENDS_ON_PARENT | GTK_CSS_EQUALS_PARENT)) values->depends_on_parent = _gtk_bitmask_set (values->depends_on_parent, id, TRUE); if (dependencies & (GTK_CSS_EQUALS_PARENT)) values->equals_parent = _gtk_bitmask_set (values->equals_parent, id, TRUE); if (dependencies & (GTK_CSS_DEPENDS_ON_COLOR)) values->depends_on_color = _gtk_bitmask_set (values->depends_on_color, id, TRUE); if (dependencies & (GTK_CSS_DEPENDS_ON_FONT_SIZE)) values->depends_on_font_size = _gtk_bitmask_set (values->depends_on_font_size, id, TRUE); if (values->sections && values->sections->len > id && g_ptr_array_index (values->sections, id)) { gtk_css_section_unref (g_ptr_array_index (values->sections, id)); g_ptr_array_index (values->sections, id) = NULL; } if (section) { if (values->sections == NULL) values->sections = g_ptr_array_new_with_free_func (maybe_unref_section); if (values->sections->len <= id) g_ptr_array_set_size (values->sections, id + 1); g_ptr_array_index (values->sections, id) = gtk_css_section_ref (section); } _gtk_css_value_unref (value); _gtk_css_value_unref (specified); }