summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-01-24 22:46:01 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-01-24 22:49:08 -0500
commit344f9fcf0584290c622cacb310cd2f7b1567a538 (patch)
tree1f3e951c0608fa01133aa7eb9277571d3b6f26e6
parent4c971cd4da925d8cac0286366d5b22204ee91a55 (diff)
downloadgtk+-344f9fcf0584290c622cacb310cd2f7b1567a538.tar.gz
css: Implement transform-origin
Implement most of transform-origin. We only handle the xy components currently, which lets us reuse the position value implementation that is used for background-position.
-rw-r--r--docs/reference/gtk/css-properties.md1
-rw-r--r--gtk/gtkcssanimatedstyle.c4
-rw-r--r--gtk/gtkcssstaticstyle.c5
-rw-r--r--gtk/gtkcssstyle.c2
-rw-r--r--gtk/gtkcssstyleprivate.h1
-rw-r--r--gtk/gtkcssstylepropertyimpl.c14
-rw-r--r--gtk/gtkcsstypesprivate.h1
-rw-r--r--gtk/gtkwidget.c10
8 files changed, 36 insertions, 2 deletions
diff --git a/docs/reference/gtk/css-properties.md b/docs/reference/gtk/css-properties.md
index c44b1308d1..e50f577650 100644
--- a/docs/reference/gtk/css-properties.md
+++ b/docs/reference/gtk/css-properties.md
@@ -164,6 +164,7 @@ done with
|-gtk-icon-shadow| [Shadow](https://www.w3.org/TR/css-backgrounds-3/#typedef-shadow) or `none` | applied to builtin and application-loaded icons |
|-gtk-icon-filter| [Filter value list](https://www.w3.org/TR/filter-effects-1/#typedef-filter-value-list) or `none` | applied to builtin and application-loaded icons |
|transform| [CSS Transforms Level 1](https://www.w3.org/TR/css-transforms-1/#transform-property) | |
+|transform-origin| [CSS Transforms Level 1](https://www.w3.org/TR/css-transforms-1/#transform-origin-property) | CSS allows specifying a z component|
|min-width| [CSS Box Model Level 3](https://www.w3.org/TR/css3-box/#min-width) | CSS allows percentages |
|min-height| [CSS Box Model Level 3](https://www.w3.org/TR/css3-box/#min-height) | CSS allows percentages |
|margin-top| [CSS Box Model Level 3](https://www.w3.org/TR/css3-box/#margin-top) | CSS allows percentages or auto |
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index bef4a9028c..52e0cabc3b 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -440,6 +440,10 @@ gtk_css_animated_style_set_animated_value (GtkCssAnimatedStyle *animated,
unshare_other (animated);
gtk_css_take_value (&style->other->transform, value);
break;
+ case GTK_CSS_PROPERTY_TRANSFORM_ORIGIN:
+ unshare_other (animated);
+ gtk_css_take_value (&style->other->transform_origin, value);
+ break;
case GTK_CSS_PROPERTY_MIN_WIDTH:
unshare_size (animated);
gtk_css_take_value (&style->size->min_width, value);
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index d4f7bb5fc7..1c8dd80c56 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -163,6 +163,7 @@ static const int other_props[] = {
GTK_CSS_PROPERTY_ICON_TRANSFORM,
GTK_CSS_PROPERTY_ICON_FILTER,
GTK_CSS_PROPERTY_TRANSFORM,
+ GTK_CSS_PROPERTY_TRANSFORM_ORIGIN,
GTK_CSS_PROPERTY_OPACITY,
GTK_CSS_PROPERTY_FILTER,
};
@@ -593,6 +594,9 @@ gtk_css_static_style_set_value (GtkCssStaticStyle *sstyle,
case GTK_CSS_PROPERTY_TRANSFORM:
gtk_css_take_value (&style->other->transform, value);
break;
+ case GTK_CSS_PROPERTY_TRANSFORM_ORIGIN:
+ gtk_css_take_value (&style->other->transform_origin, value);
+ break;
case GTK_CSS_PROPERTY_MIN_WIDTH:
gtk_css_take_value (&style->size->min_width, value);
break;
@@ -880,6 +884,7 @@ gtk_css_other_create_initial_values (void)
values->icon_transform = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_ICON_TRANSFORM, NULL, NULL, NULL);
values->icon_filter = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_ICON_FILTER, NULL, NULL, NULL);
values->transform = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_TRANSFORM, NULL, NULL, NULL);
+ values->transform_origin = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_TRANSFORM_ORIGIN, NULL, NULL, NULL);
values->opacity = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_OPACITY, NULL, NULL, NULL);
values->filter = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_FILTER, NULL, NULL, NULL);
diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c
index 106a90ea5a..5d5fc2b44f 100644
--- a/gtk/gtkcssstyle.c
+++ b/gtk/gtkcssstyle.c
@@ -235,6 +235,8 @@ gtk_css_style_get_value (GtkCssStyle *style,
return style->size->border_spacing;
case GTK_CSS_PROPERTY_TRANSFORM:
return style->other->transform;
+ case GTK_CSS_PROPERTY_TRANSFORM_ORIGIN:
+ return style->other->transform_origin;
case GTK_CSS_PROPERTY_MIN_WIDTH:
return style->size->min_width;
case GTK_CSS_PROPERTY_MIN_HEIGHT:
diff --git a/gtk/gtkcssstyleprivate.h b/gtk/gtkcssstyleprivate.h
index 65c8c6f700..27666e9978 100644
--- a/gtk/gtkcssstyleprivate.h
+++ b/gtk/gtkcssstyleprivate.h
@@ -208,6 +208,7 @@ struct _GtkCssOtherValues {
GtkCssValue *icon_transform;
GtkCssValue *icon_filter;
GtkCssValue *transform;
+ GtkCssValue *transform_origin;
GtkCssValue *opacity;
GtkCssValue *filter;
};
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index de7f2e3762..3eb4ac7c5c 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -790,6 +790,13 @@ background_position_parse (GtkCssStyleProperty *property,
return _gtk_css_array_value_parse (parser, _gtk_css_position_value_parse);
}
+static GtkCssValue *
+transform_origin_parse (GtkCssStyleProperty *property,
+ GtkCssParser *parser)
+{
+ return _gtk_css_position_value_parse (parser);
+}
+
/*** REGISTRATION ***/
G_STATIC_ASSERT (GTK_CSS_PROPERTY_COLOR == 0);
@@ -1248,6 +1255,13 @@ _gtk_css_style_property_init_properties (void)
GTK_CSS_AFFECTS_TRANSFORM,
transform_value_parse,
_gtk_css_transform_value_new_none ());
+ gtk_css_style_property_register ("transform-origin",
+ GTK_CSS_PROPERTY_TRANSFORM_ORIGIN,
+ GTK_STYLE_PROPERTY_ANIMATED,
+ GTK_CSS_AFFECTS_TRANSFORM,
+ transform_origin_parse,
+ _gtk_css_position_value_new (_gtk_css_number_value_new (50, GTK_CSS_PERCENT),
+ _gtk_css_number_value_new (50, GTK_CSS_PERCENT)));
gtk_css_style_property_register ("min-width",
GTK_CSS_PROPERTY_MIN_WIDTH,
GTK_STYLE_PROPERTY_ANIMATED,
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index e95e31ac9c..fe30beaae1 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -254,6 +254,7 @@ enum { /*< skip >*/
GTK_CSS_PROPERTY_ICON_FILTER,
GTK_CSS_PROPERTY_BORDER_SPACING,
GTK_CSS_PROPERTY_TRANSFORM,
+ GTK_CSS_PROPERTY_TRANSFORM_ORIGIN,
GTK_CSS_PROPERTY_MIN_WIDTH,
GTK_CSS_PROPERTY_MIN_HEIGHT,
GTK_CSS_PROPERTY_TRANSITION_PROPERTY,
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 217293cd23..0daeef7a6d 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -36,6 +36,7 @@
#include "gtkcssboxesprivate.h"
#include "gtkcssfiltervalueprivate.h"
#include "gtkcsstransformvalueprivate.h"
+#include "gtkcsspositionvalueprivate.h"
#include "gtkcssfontvariationsvalueprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkcssstylepropertyprivate.h"
@@ -3937,12 +3938,17 @@ gtk_widget_allocate (GtkWidget *widget,
if (css_transform)
{
+ double origin_x, origin_y;
+
+ origin_x = _gtk_css_position_value_get_x (style->other->transform_origin, adjusted.width);
+ origin_y = _gtk_css_position_value_get_y (style->other->transform_origin, adjusted.height);
+
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (adjusted.x, adjusted.y));
adjusted.x = adjusted.y = 0;
- transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (adjusted.width / 2, adjusted.height / 2));
+ transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (origin_x, origin_y));
transform = gsk_transform_transform (transform, css_transform);
- transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (- adjusted.width / 2, - adjusted.height / 2));
+ transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (- origin_x, - origin_y));
gsk_transform_unref (css_transform);
}