cssvalue: First step of proper dependency tracking

Instead of using the EVERYTHING aka FIXME value for tdependencies,
actually compute the dependencies in a bunch of simple cases.
This commit is contained in:
Benjamin Otte 2012-08-25 01:59:13 +02:00
parent 8ff08e7c5e
commit 012526241a
7 changed files with 35 additions and 22 deletions

View File

@ -48,11 +48,10 @@ gtk_css_value_border_compute (GtkCssValue *value,
GtkCssDependencies *dependencies)
{
GtkCssValue *computed;
GtkCssDependencies child_deps;
gboolean changed = FALSE;
guint i;
*dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
computed = _gtk_css_border_value_new (NULL, NULL, NULL, NULL);
computed->fill = value->fill;
@ -60,7 +59,8 @@ gtk_css_value_border_compute (GtkCssValue *value,
{
if (value->values[i])
{
computed->values[i] = _gtk_css_value_compute (value->values[i], property_id, context, NULL);
computed->values[i] = _gtk_css_value_compute (value->values[i], property_id, context, &child_deps);
*dependencies = _gtk_css_dependencies_union (*dependencies, child_deps);
changed |= (computed->values[i] != value->values[i]);
}
}

View File

@ -43,11 +43,11 @@ gtk_css_value_corner_compute (GtkCssValue *corner,
GtkCssDependencies *dependencies)
{
GtkCssValue *x, *y;
GtkCssDependencies x_deps, y_deps;
*dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
x = _gtk_css_value_compute (corner->x, property_id, context, NULL);
y = _gtk_css_value_compute (corner->y, property_id, context, NULL);
x = _gtk_css_value_compute (corner->x, property_id, context, &x_deps);
y = _gtk_css_value_compute (corner->y, property_id, context, &y_deps);
*dependencies = _gtk_css_dependencies_union (x_deps, y_deps);
if (x == corner->x && y == corner->y)
{
_gtk_css_value_unref (x);

View File

@ -41,15 +41,18 @@ gtk_css_value_inherit_compute (GtkCssValue *value,
{
GtkStyleContext *parent = gtk_style_context_get_parent (context);
*dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
if (parent)
return _gtk_css_value_ref (_gtk_style_context_peek_property (parent, property_id));
{
*dependencies = GTK_CSS_EQUALS_PARENT;
return _gtk_css_value_ref (_gtk_style_context_peek_property (parent, property_id));
}
else
return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
property_id,
context,
NULL);
{
return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
property_id,
context,
dependencies);
}
}
static gboolean

View File

@ -74,8 +74,6 @@ gtk_css_value_number_compute (GtkCssValue *number,
break;
}
*dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
switch (number->unit)
{
default:
@ -107,12 +105,14 @@ gtk_css_value_number_compute (GtkCssValue *number,
GTK_CSS_PX);
break;
case GTK_CSS_EM:
*dependencies = GTK_CSS_DEPENDS_ON_FONT_SIZE;
return _gtk_css_number_value_new (number->value *
_gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100),
GTK_CSS_PX);
break;
case GTK_CSS_EX:
/* for now we pretend ex is half of em */
*dependencies = GTK_CSS_DEPENDS_ON_FONT_SIZE;
return _gtk_css_number_value_new (number->value * 0.5 *
_gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100),
GTK_CSS_PX);

View File

@ -43,9 +43,11 @@ gtk_css_value_position_compute (GtkCssValue *position,
GtkCssDependencies *dependencies)
{
GtkCssValue *x, *y;
GtkCssDependencies x_deps, y_deps;
x = _gtk_css_value_compute (position->x, property_id, context, NULL);
y = _gtk_css_value_compute (position->y, property_id, context, NULL);
x = _gtk_css_value_compute (position->x, property_id, context, &x_deps);
y = _gtk_css_value_compute (position->y, property_id, context, &y_deps);
*dependencies = _gtk_css_dependencies_union (x_deps, y_deps);
if (x == position->x && y == position->y)
{
_gtk_css_value_unref (x);
@ -53,8 +55,6 @@ gtk_css_value_position_compute (GtkCssValue *position,
return _gtk_css_value_ref (position);
}
*dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
return _gtk_css_position_value_new (x, y);
}

View File

@ -82,3 +82,11 @@ _gtk_css_change_for_child (GtkCssChange match)
return gtk_css_change_translate (match, table, G_N_ELEMENTS (table));
}
GtkCssDependencies
_gtk_css_dependencies_union (GtkCssDependencies first,
GtkCssDependencies second)
{
return (first & ~GTK_CSS_EQUALS_PARENT) | ((first & GTK_CSS_EQUALS_PARENT) ? GTK_CSS_DEPENDS_ON_PARENT : 0)
| (second & ~GTK_CSS_EQUALS_PARENT) | ((second & GTK_CSS_EQUALS_PARENT) ? GTK_CSS_DEPENDS_ON_PARENT : 0);
}

View File

@ -170,8 +170,10 @@ typedef enum /*< skip >*/ {
GTK_CSS_MS,
} GtkCssUnit;
GtkCssChange _gtk_css_change_for_sibling (GtkCssChange match);
GtkCssChange _gtk_css_change_for_child (GtkCssChange match);
GtkCssChange _gtk_css_change_for_sibling (GtkCssChange match);
GtkCssChange _gtk_css_change_for_child (GtkCssChange match);
GtkCssDependencies _gtk_css_dependencies_union (GtkCssDependencies first,
GtkCssDependencies second);
G_END_DECLS