From 4586578b093ad09d31114121a879549df2ed4dba Mon Sep 17 00:00:00 2001 From: Yves Lafon Date: Mon, 3 Mar 2025 15:38:09 +0100 Subject: [PATCH 1/6] updated refs --- org/w3c/css/properties/css3/CssBackfaceVisibility.java | 3 +-- org/w3c/css/properties/css3/CssPerspective.java | 2 +- org/w3c/css/properties/css3/CssPerspectiveOrigin.java | 4 +++- org/w3c/css/properties/css3/CssTransformStyle.java | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/org/w3c/css/properties/css3/CssBackfaceVisibility.java b/org/w3c/css/properties/css3/CssBackfaceVisibility.java index 48752afac..9897e2983 100644 --- a/org/w3c/css/properties/css3/CssBackfaceVisibility.java +++ b/org/w3c/css/properties/css3/CssBackfaceVisibility.java @@ -13,8 +13,7 @@ import org.w3c.css.values.CssValue; /** - * @spec https://www.w3.org/TR/2020/WD-css-transforms-2-20200303/#propdef-backface-visibility - + * @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-backface-visibility */ public class CssBackfaceVisibility extends org.w3c.css.properties.css.CssBackfaceVisibility { diff --git a/org/w3c/css/properties/css3/CssPerspective.java b/org/w3c/css/properties/css3/CssPerspective.java index 9f2fd8553..f05145d51 100644 --- a/org/w3c/css/properties/css3/CssPerspective.java +++ b/org/w3c/css/properties/css3/CssPerspective.java @@ -17,7 +17,7 @@ import org.w3c.css.values.CssValue; /** - * @spec https://www.w3.org/TR/2020/WD-css-transforms-2-20200303/#propdef-perspective + * @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-perspective */ public class CssPerspective extends org.w3c.css.properties.css.CssPerspective { diff --git a/org/w3c/css/properties/css3/CssPerspectiveOrigin.java b/org/w3c/css/properties/css3/CssPerspectiveOrigin.java index 7df57db33..d45bd2eb3 100644 --- a/org/w3c/css/properties/css3/CssPerspectiveOrigin.java +++ b/org/w3c/css/properties/css3/CssPerspectiveOrigin.java @@ -18,13 +18,15 @@ import static org.w3c.css.values.CssOperator.SPACE; /** - * @spec http://www.w3.org/TR/2012/WD-css3-transforms-20120911/#perspective-origin + * @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-perspective-origin */ public class CssPerspectiveOrigin extends org.w3c.css.properties.css.CssPerspectiveOrigin { public static CssIdent[] allowed_values; public static CssIdent center, top, bottom, left, right; + // FIXME this should be a generic 'position' parsing + static { top = CssIdent.getIdent("top"); bottom = CssIdent.getIdent("bottom"); diff --git a/org/w3c/css/properties/css3/CssTransformStyle.java b/org/w3c/css/properties/css3/CssTransformStyle.java index 056cb8b5b..ceb62cb1e 100644 --- a/org/w3c/css/properties/css3/CssTransformStyle.java +++ b/org/w3c/css/properties/css3/CssTransformStyle.java @@ -13,7 +13,7 @@ import org.w3c.css.values.CssValue; /** - * @spec https://www.w3.org/TR/2020/WD-css-transforms-2-20200303/#propdef-transform-style + * @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-transform-style */ public class CssTransformStyle extends org.w3c.css.properties.css.CssTransformStyle { From f4dda67d7274fdd6488116b2b972324be5e3281c Mon Sep 17 00:00:00 2001 From: Yves Lafon Date: Mon, 3 Mar 2025 15:40:50 +0100 Subject: [PATCH 2/6] scale per https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-scale --- .../css/properties/CSS3Properties.properties | 1 + org/w3c/css/properties/css/CssScale.java | 113 ++++++++++++++++++ org/w3c/css/properties/css3/Css3Style.java | 11 ++ org/w3c/css/properties/css3/CssScale.java | 90 ++++++++++++++ 4 files changed, 215 insertions(+) create mode 100644 org/w3c/css/properties/css/CssScale.java create mode 100644 org/w3c/css/properties/css3/CssScale.java diff --git a/org/w3c/css/properties/CSS3Properties.properties b/org/w3c/css/properties/CSS3Properties.properties index 833340130..4ba9ce38b 100644 --- a/org/w3c/css/properties/CSS3Properties.properties +++ b/org/w3c/css/properties/CSS3Properties.properties @@ -297,6 +297,7 @@ perspective-origin: org.w3c.css.properties.css3.CssPerspecti transform-origin: org.w3c.css.properties.css3.CssTransformOrigin transform-box: org.w3c.css.properties.css3.CssTransformBox transform: org.w3c.css.properties.css3.CssTransform +scale: org.w3c.css.properties.css3.CssScale # image object-fit: org.w3c.css.properties.css3.CssObjectFit diff --git a/org/w3c/css/properties/css/CssScale.java b/org/w3c/css/properties/css/CssScale.java new file mode 100644 index 000000000..efac47127 --- /dev/null +++ b/org/w3c/css/properties/css/CssScale.java @@ -0,0 +1,113 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2022. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css; + +import org.w3c.css.parser.CssStyle; +import org.w3c.css.properties.css3.Css3Style; +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssExpression; + +/** + * @since CSS3 + */ +public class CssScale extends CssProperty { + + /** + * Create a new CssScale + */ + public CssScale() { + } + + /** + * Creates a new CssScale + * + * @param expression The expression for this property + * @throws InvalidParamException + * Expressions are incorrect + */ + public CssScale(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + throw new InvalidParamException("value", + expression.getValue().toString(), + getPropertyName(), ac); + } + + public CssScale(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } + + /** + * Returns the value of this property + */ + public Object get() { + return value; + } + + + /** + * Returns the name of this property + */ + public final String getPropertyName() { + return "scale"; + } + + /** + * Returns true if this property is "softly" inherited + * e.g. his value is equals to inherit + */ + public boolean isSoftlyInherited() { + return value.equals(inherit); + } + + /** + * Returns a string representation of the object. + */ + public String toString() { + return value.toString(); + } + + /** + * Add this property to the CssStyle. + * + * @param style The CssStyle + */ + public void addToStyle(ApplContext ac, CssStyle style) { + Css3Style s = (Css3Style) style; + if (s.cssScale != null) { + style.addRedefinitionWarning(ac, this); + } + s.cssScale = this; + } + + + /** + * Compares two properties for equality. + * + * @param property The other property. + */ + public boolean equals(CssProperty property) { + return (property instanceof CssScale && + value.equals(((CssScale) property).value)); + } + + + /** + * Get this property in the style. + * + * @param style The style where the property is + * @param resolve if true, resolve the style to find this property + */ + public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { + if (resolve) { + return ((Css3Style) style).getScale(); + } else { + return ((Css3Style) style).cssScale; + } + } +} + diff --git a/org/w3c/css/properties/css3/Css3Style.java b/org/w3c/css/properties/css3/Css3Style.java index 12c131b89..334935480 100644 --- a/org/w3c/css/properties/css3/Css3Style.java +++ b/org/w3c/css/properties/css3/Css3Style.java @@ -230,6 +230,7 @@ import org.w3c.css.properties.css.CssRubyAlign; import org.w3c.css.properties.css.CssRubyMerge; import org.w3c.css.properties.css.CssRubyPosition; +import org.w3c.css.properties.css.CssScale; import org.w3c.css.properties.css.CssScrollBehavior; import org.w3c.css.properties.css.CssScrollMargin; import org.w3c.css.properties.css.CssScrollMarginBlock; @@ -564,6 +565,7 @@ public class Css3Style extends ATSCStyle { public CssTransformOrigin cssTransformOrigin; public CssTransform cssTransform; public CssTransformBox cssTransformBox; + public CssScale cssScale; public CssBoxSizing cssBoxSizing; public CssResize cssResize; @@ -724,6 +726,15 @@ public class Css3Style extends ATSCStyle { public CssTextSpacingTrim cssTextSpacingTrim; public CssTextSpacing cssTextSpacing; + public CssScale getScale() { + if (cssScale == null) { + cssScale = + (CssScale) style.CascadingOrder(new CssScale(), + style, selector); + } + return cssScale; + } + public CssTextSpacing getTextSpacing() { if (cssTextSpacing == null) { cssTextSpacing = diff --git a/org/w3c/css/properties/css3/CssScale.java b/org/w3c/css/properties/css3/CssScale.java new file mode 100644 index 000000000..f77be61e4 --- /dev/null +++ b/org/w3c/css/properties/css3/CssScale.java @@ -0,0 +1,90 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT World Wide Web Consortium, 2025. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css3; + +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssExpression; +import org.w3c.css.values.CssIdent; +import org.w3c.css.values.CssTypes; +import org.w3c.css.values.CssValue; +import org.w3c.css.values.CssValueList; + +import java.util.ArrayList; + +import static org.w3c.css.values.CssOperator.SPACE; + +/** + * @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-scale + */ +public class CssScale extends org.w3c.css.properties.css.CssScale { + + /** + * Create a new CssScale + */ + public CssScale() { + value = initial; + } + + /** + * Creates a new CssScale + * + * @param expression The expression for this property + * @throws InvalidParamException Expressions are incorrect + */ + public CssScale(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + if (check && expression.getCount() > 3) { + throw new InvalidParamException("unrecognize", ac); + } + CssValue val; + ArrayList v = new ArrayList<>(); + char op; + setByUser(); + + + while (!expression.end()) { + val = expression.getValue(); + op = expression.getOperator(); + + switch (val.getType()) { + case CssTypes.CSS_NUMBER: + case CssTypes.CSS_PERCENTAGE: + // spec is silent on negative values + v.add(val); + break; + case CssTypes.CSS_IDENT: + CssIdent id = val.getIdent(); + if (none.equals(id) || CssIdent.isCssWide(id)) { + if (expression.getCount() > 1) { + throw new InvalidParamException("value", val.toString(), + getPropertyName(), ac); + } + v.add(val); + break; + } + // unrecognize ident, let it fail + default: + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + if (op != SPACE) { + throw new InvalidParamException("operator", + Character.toString(op), ac); + } + expression.next(); + } + value = (v.size() == 1) ? v.get(0) : new CssValueList(v); + } + + + public CssScale(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } +} + From 51973238c2c265fbdc30752dbdc1e5a4d1e8fec3 Mon Sep 17 00:00:00 2001 From: Yves Lafon Date: Thu, 6 Mar 2025 10:30:03 +0100 Subject: [PATCH 3/6] copy/paste fix --- org/w3c/css/properties/css/CssScale.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org/w3c/css/properties/css/CssScale.java b/org/w3c/css/properties/css/CssScale.java index efac47127..cdf857993 100644 --- a/org/w3c/css/properties/css/CssScale.java +++ b/org/w3c/css/properties/css/CssScale.java @@ -1,7 +1,7 @@ // // Author: Yves Lafon // -// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2022. +// (c) COPYRIGHT World Wide Web Consortium, 2025. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.properties.css; From b77d26d3f0bd85f214416bd9987358c81ea9f2b5 Mon Sep 17 00:00:00 2001 From: Yves Lafon Date: Thu, 6 Mar 2025 10:30:50 +0100 Subject: [PATCH 4/6] translate per https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-translate --- .../css/properties/CSS3Properties.properties | 1 + org/w3c/css/properties/css/CssTranslate.java | 113 ++++++++++++++++++ org/w3c/css/properties/css3/Css3Style.java | 11 ++ org/w3c/css/properties/css3/CssTranslate.java | 101 ++++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 org/w3c/css/properties/css/CssTranslate.java create mode 100644 org/w3c/css/properties/css3/CssTranslate.java diff --git a/org/w3c/css/properties/CSS3Properties.properties b/org/w3c/css/properties/CSS3Properties.properties index 4ba9ce38b..08479d560 100644 --- a/org/w3c/css/properties/CSS3Properties.properties +++ b/org/w3c/css/properties/CSS3Properties.properties @@ -297,6 +297,7 @@ perspective-origin: org.w3c.css.properties.css3.CssPerspecti transform-origin: org.w3c.css.properties.css3.CssTransformOrigin transform-box: org.w3c.css.properties.css3.CssTransformBox transform: org.w3c.css.properties.css3.CssTransform +translate: org.w3c.css.properties.css3.CssTranslate scale: org.w3c.css.properties.css3.CssScale # image diff --git a/org/w3c/css/properties/css/CssTranslate.java b/org/w3c/css/properties/css/CssTranslate.java new file mode 100644 index 000000000..cf453be0c --- /dev/null +++ b/org/w3c/css/properties/css/CssTranslate.java @@ -0,0 +1,113 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT World Wide Web Consortium, 2025. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css; + +import org.w3c.css.parser.CssStyle; +import org.w3c.css.properties.css3.Css3Style; +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssExpression; + +/** + * @since CSS3 + */ +public class CssTranslate extends CssProperty { + + /** + * Create a new CssTranslate + */ + public CssTranslate() { + } + + /** + * Creates a new CssTranslate + * + * @param expression The expression for this property + * @throws InvalidParamException + * Expressions are incorrect + */ + public CssTranslate(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + throw new InvalidParamException("value", + expression.getValue().toString(), + getPropertyName(), ac); + } + + public CssTranslate(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } + + /** + * Returns the value of this property + */ + public Object get() { + return value; + } + + + /** + * Returns the name of this property + */ + public final String getPropertyName() { + return "translate"; + } + + /** + * Returns true if this property is "softly" inherited + * e.g. his value is equals to inherit + */ + public boolean isSoftlyInherited() { + return value.equals(inherit); + } + + /** + * Returns a string representation of the object. + */ + public String toString() { + return value.toString(); + } + + /** + * Add this property to the CssStyle. + * + * @param style The CssStyle + */ + public void addToStyle(ApplContext ac, CssStyle style) { + Css3Style s = (Css3Style) style; + if (s.cssTranslate != null) { + style.addRedefinitionWarning(ac, this); + } + s.cssTranslate = this; + } + + + /** + * Compares two properties for equality. + * + * @param property The other property. + */ + public boolean equals(CssProperty property) { + return (property instanceof CssTranslate && + value.equals(((CssTranslate) property).value)); + } + + + /** + * Get this property in the style. + * + * @param style The style where the property is + * @param resolve if true, resolve the style to find this property + */ + public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { + if (resolve) { + return ((Css3Style) style).getTranslate(); + } else { + return ((Css3Style) style).cssTranslate; + } + } +} + diff --git a/org/w3c/css/properties/css3/Css3Style.java b/org/w3c/css/properties/css3/Css3Style.java index 334935480..7beaf1faf 100644 --- a/org/w3c/css/properties/css3/Css3Style.java +++ b/org/w3c/css/properties/css3/Css3Style.java @@ -301,6 +301,7 @@ import org.w3c.css.properties.css.CssTransitionDuration; import org.w3c.css.properties.css.CssTransitionProperty; import org.w3c.css.properties.css.CssTransitionTimingFunction; +import org.w3c.css.properties.css.CssTranslate; import org.w3c.css.properties.css.CssUserSelect; import org.w3c.css.properties.css.CssVoiceBalance; import org.w3c.css.properties.css.CssVoiceDuration; @@ -725,7 +726,17 @@ public class Css3Style extends ATSCStyle { public CssTextAutospace cssTextAutospace; public CssTextSpacingTrim cssTextSpacingTrim; public CssTextSpacing cssTextSpacing; + public CssTranslate cssTranslate; + public CssTranslate getTranslate() { + if (cssTranslate == null) { + cssTranslate = + (CssTranslate) style.CascadingOrder(new CssTranslate(), + style, selector); + } + return cssTranslate; + } + public CssScale getScale() { if (cssScale == null) { cssScale = diff --git a/org/w3c/css/properties/css3/CssTranslate.java b/org/w3c/css/properties/css3/CssTranslate.java new file mode 100644 index 000000000..63224e554 --- /dev/null +++ b/org/w3c/css/properties/css3/CssTranslate.java @@ -0,0 +1,101 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT World Wide Web Consortium, 2025. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css3; + +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssCheckableValue; +import org.w3c.css.values.CssExpression; +import org.w3c.css.values.CssIdent; +import org.w3c.css.values.CssTypes; +import org.w3c.css.values.CssValue; +import org.w3c.css.values.CssValueList; + +import java.util.ArrayList; + +import static org.w3c.css.values.CssOperator.SPACE; + +/** + * @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-translate + */ +public class CssTranslate extends org.w3c.css.properties.css.CssTranslate { + + /** + * Create a new CssTranslate + */ + public CssTranslate() { + value = initial; + } + + /** + * Creates a new CssTranslate + * + * @param expression The expression for this property + * @throws InvalidParamException Expressions are incorrect + */ + public CssTranslate(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + if (check && expression.getCount() > 3) { + throw new InvalidParamException("unrecognize", ac); + } + CssValue val; + ArrayList v = new ArrayList<>(); + char op; + setByUser(); + + + while (!expression.end()) { + val = expression.getValue(); + op = expression.getOperator(); + + switch (val.getType()) { + case CssTypes.CSS_NUMBER: + // only 0 can be a length... + CssCheckableValue p = val.getCheckableValue(); + p.checkEqualsZero(ac, this); + v.add(val); + break; + case CssTypes.CSS_PERCENTAGE: + if (v.size() == 2) { + // percentage can appear only in the first two values + throw new InvalidParamException("value", val.toString(), + getPropertyName(), ac); + } + case CssTypes.CSS_LENGTH: + v.add(val); + break; + case CssTypes.CSS_IDENT: + CssIdent id = val.getIdent(); + if (none.equals(id) || CssIdent.isCssWide(id)) { + if (expression.getCount() > 1) { + throw new InvalidParamException("value", val.toString(), + getPropertyName(), ac); + } + v.add(val); + break; + } + // unrecognize ident, let it fail + default: + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + if (op != SPACE) { + throw new InvalidParamException("operator", + Character.toString(op), ac); + } + expression.next(); + } + value = (v.size() == 1) ? v.get(0) : new CssValueList(v); + } + + + public CssTranslate(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } +} + From b8f74955001abebf7c2e0adc2e17865881f24efe Mon Sep 17 00:00:00 2001 From: Yves Lafon Date: Thu, 6 Mar 2025 11:12:50 +0100 Subject: [PATCH 5/6] rotate per https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-rotate --- .../css/properties/CSS3Properties.properties | 3 +- org/w3c/css/properties/css/CssRotate.java | 113 +++++++++++++++ org/w3c/css/properties/css3/Css3Style.java | 11 ++ org/w3c/css/properties/css3/CssRotate.java | 136 ++++++++++++++++++ 4 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 org/w3c/css/properties/css/CssRotate.java create mode 100644 org/w3c/css/properties/css3/CssRotate.java diff --git a/org/w3c/css/properties/CSS3Properties.properties b/org/w3c/css/properties/CSS3Properties.properties index 08479d560..a61820d01 100644 --- a/org/w3c/css/properties/CSS3Properties.properties +++ b/org/w3c/css/properties/CSS3Properties.properties @@ -294,11 +294,12 @@ transform-style: org.w3c.css.properties.css3.CssTransform backface-visibility: org.w3c.css.properties.css3.CssBackfaceVisibility perspective: org.w3c.css.properties.css3.CssPerspective perspective-origin: org.w3c.css.properties.css3.CssPerspectiveOrigin +rotate: org.w3c.css.properties.css3.CssRotate +scale: org.w3c.css.properties.css3.CssScale transform-origin: org.w3c.css.properties.css3.CssTransformOrigin transform-box: org.w3c.css.properties.css3.CssTransformBox transform: org.w3c.css.properties.css3.CssTransform translate: org.w3c.css.properties.css3.CssTranslate -scale: org.w3c.css.properties.css3.CssScale # image object-fit: org.w3c.css.properties.css3.CssObjectFit diff --git a/org/w3c/css/properties/css/CssRotate.java b/org/w3c/css/properties/css/CssRotate.java new file mode 100644 index 000000000..7ee89d9f8 --- /dev/null +++ b/org/w3c/css/properties/css/CssRotate.java @@ -0,0 +1,113 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT World Wide Web Consortium, 2025. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css; + +import org.w3c.css.parser.CssStyle; +import org.w3c.css.properties.css3.Css3Style; +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssExpression; + +/** + * @since CSS3 + */ +public class CssRotate extends CssProperty { + + /** + * Create a new CssRotate + */ + public CssRotate() { + } + + /** + * Creates a new CssRotate + * + * @param expression The expression for this property + * @throws InvalidParamException + * Expressions are incorrect + */ + public CssRotate(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + throw new InvalidParamException("value", + expression.getValue().toString(), + getPropertyName(), ac); + } + + public CssRotate(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } + + /** + * Returns the value of this property + */ + public Object get() { + return value; + } + + + /** + * Returns the name of this property + */ + public final String getPropertyName() { + return "rotate"; + } + + /** + * Returns true if this property is "softly" inherited + * e.g. his value is equals to inherit + */ + public boolean isSoftlyInherited() { + return value.equals(inherit); + } + + /** + * Returns a string representation of the object. + */ + public String toString() { + return value.toString(); + } + + /** + * Add this property to the CssStyle. + * + * @param style The CssStyle + */ + public void addToStyle(ApplContext ac, CssStyle style) { + Css3Style s = (Css3Style) style; + if (s.cssRotate != null) { + style.addRedefinitionWarning(ac, this); + } + s.cssRotate = this; + } + + + /** + * Compares two properties for equality. + * + * @param property The other property. + */ + public boolean equals(CssProperty property) { + return (property instanceof CssRotate && + value.equals(((CssRotate) property).value)); + } + + + /** + * Get this property in the style. + * + * @param style The style where the property is + * @param resolve if true, resolve the style to find this property + */ + public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { + if (resolve) { + return ((Css3Style) style).getRotate(); + } else { + return ((Css3Style) style).cssRotate; + } + } +} + diff --git a/org/w3c/css/properties/css3/Css3Style.java b/org/w3c/css/properties/css3/Css3Style.java index 7beaf1faf..9562af752 100644 --- a/org/w3c/css/properties/css3/Css3Style.java +++ b/org/w3c/css/properties/css3/Css3Style.java @@ -226,6 +226,7 @@ import org.w3c.css.properties.css.CssRest; import org.w3c.css.properties.css.CssRestAfter; import org.w3c.css.properties.css.CssRestBefore; +import org.w3c.css.properties.css.CssRotate; import org.w3c.css.properties.css.CssRowGap; import org.w3c.css.properties.css.CssRubyAlign; import org.w3c.css.properties.css.CssRubyMerge; @@ -727,6 +728,16 @@ public class Css3Style extends ATSCStyle { public CssTextSpacingTrim cssTextSpacingTrim; public CssTextSpacing cssTextSpacing; public CssTranslate cssTranslate; + public CssRotate cssRotate; + + public CssRotate getRotate() { + if (cssRotate == null) { + cssRotate = + (CssRotate) style.CascadingOrder(new CssRotate(), + style, selector); + } + return cssRotate; + } public CssTranslate getTranslate() { if (cssTranslate == null) { diff --git a/org/w3c/css/properties/css3/CssRotate.java b/org/w3c/css/properties/css3/CssRotate.java new file mode 100644 index 000000000..a8e96da0b --- /dev/null +++ b/org/w3c/css/properties/css3/CssRotate.java @@ -0,0 +1,136 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT World Wide Web Consortium, 2025. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css3; + +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssExpression; +import org.w3c.css.values.CssIdent; +import org.w3c.css.values.CssTypes; +import org.w3c.css.values.CssValue; +import org.w3c.css.values.CssValueList; + +import java.util.ArrayList; + +import static org.w3c.css.values.CssOperator.SPACE; + +/** + * @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-rotate + */ +public class CssRotate extends org.w3c.css.properties.css.CssRotate { + + public static final CssIdent[] allowedValues; + + static { + String[] _allowedValues = {"x", "y", "z"}; + allowedValues = new CssIdent[_allowedValues.length]; + for (int i = 0; i < allowedValues.length; i++) { + allowedValues[i] = CssIdent.getIdent(_allowedValues[i]); + } + } + + public static final CssIdent getAllowedValue(CssIdent ident) { + for (CssIdent id : allowedValues) { + if (id.equals(ident)) { + return id; + } + } + return null; + } + /** + * Create a new CssRotate + */ + public CssRotate() { + value = initial; + } + + /** + * Creates a new CssRotate + * + * @param expression The expression for this property + * @throws InvalidParamException Expressions are incorrect + */ + public CssRotate(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + if (check && expression.getCount() > 4) { + throw new InvalidParamException("unrecognize", ac); + } + CssValue val; + ArrayList v = new ArrayList<>(); + char op; + int nbNumber = 0; + boolean gotIdent = false; + boolean gotAngle = false; + setByUser(); + + + while (!expression.end()) { + val = expression.getValue(); + op = expression.getOperator(); + + switch (val.getType()) { + case CssTypes.CSS_NUMBER: + // if we got an axis or more than 3 values, report error + if (gotIdent || (nbNumber == 3)) { + throw new InvalidParamException("value", val.toString(), + getPropertyName(), ac); + } + nbNumber++; + v.add(val); + break; + case CssTypes.CSS_ANGLE: + // if we got numbers, we must get them all before the angle value + if (gotAngle || nbNumber == 1 || nbNumber == 2) { + throw new InvalidParamException("value", val.toString(), + getPropertyName(), ac); + } + gotAngle = true; + v.add(val); + break; + case CssTypes.CSS_IDENT: + CssIdent id = val.getIdent(); + if (none.equals(id) || CssIdent.isCssWide(id)) { + if (expression.getCount() > 1) { + throw new InvalidParamException("value", val.toString(), + getPropertyName(), ac); + } + v.add(val); + break; + } + // if wa got a number (ie: defining axis) or another ident axis, report error + if (!gotIdent && (nbNumber == 0) && getAllowedValue(id) != null) { + v.add(val); + gotIdent = true; + break; + } + // unrecognize ident, or unwanted one, let it fail + default: + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + if (op != SPACE) { + throw new InvalidParamException("operator", + Character.toString(op), ac); + } + expression.next(); + } + // sanity check, if we got an axis, we should get an angle, if we got number we should get 3 of them + if ((nbNumber > 0 && nbNumber != 3) || ((gotIdent || (nbNumber != 0)) && !gotAngle)) { + throw new InvalidParamException("value", + v.toString(), + getPropertyName(), ac); + } + value = (v.size() == 1) ? v.get(0) : new CssValueList(v); + } + + + public CssRotate(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } +} + From 03198ddf6d7a5fc5b4bb26c003769a9ed5b5d041 Mon Sep 17 00:00:00 2001 From: Yves Lafon Date: Thu, 6 Mar 2025 11:37:24 +0100 Subject: [PATCH 6/6] updated scale() scaleX() scaleY() and perspective() per https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#changes-recent --- org/w3c/css/properties/css3/CssTransform.java | 105 +++++++++++++++++- 1 file changed, 103 insertions(+), 2 deletions(-) diff --git a/org/w3c/css/properties/css3/CssTransform.java b/org/w3c/css/properties/css3/CssTransform.java index ccbb75107..01811b7f1 100644 --- a/org/w3c/css/properties/css3/CssTransform.java +++ b/org/w3c/css/properties/css3/CssTransform.java @@ -23,6 +23,7 @@ /** * @spec https://www.w3.org/TR/2019/CR-css-transforms-1-20190214/#propdef-transform + * @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#transform-functions */ public class CssTransform extends org.w3c.css.properties.css.CssTransform { @@ -139,11 +140,12 @@ protected static void parseFunctionValues(ApplContext ac, CssValue func, CssProp parseTranslateAxisFunction(ac, function.getParameters(), caller); break; case scale: - parseAtMostX(ac, function.getParameters(), 2, CssTypes.CSS_NUMBER, caller); + parseAtMostX(ac, function.getParameters(), 2, + CssTypes.CSS_NUMBER, CssTypes.CSS_PERCENTAGE, caller); break; case scaleX: case scaleY: - parseOneX(ac, function.getParameters(), CssTypes.CSS_NUMBER, caller); + parseOneX(ac, function.getParameters(), CssTypes.CSS_NUMBER, CssTypes.CSS_PERCENTAGE, caller); break; case rotate: parseOneX(ac, function.getParameters(), CssTypes.CSS_ANGLE, caller); @@ -191,6 +193,24 @@ protected static void parseFunctionValues(ApplContext ac, CssValue func, CssProp } } + private static void parsePerspective(ApplContext ac, CssExpression expression, CssProperty caller) + throws InvalidParamException { + if (expression.getCount() > 1) { + throw new InvalidParamException("unrecognize", ac); + } + if (expression.getCount() == 0) { + throw new InvalidParamException("few-value", caller.getPropertyName(), ac); + } + CssValue val = expression.getValue(); + if (val.getType() == CssTypes.CSS_IDENT) { + if (none.equals(val.getIdent())) { + return; + } + // if not none, it will fail later + } + parseOneX(ac, expression, CssTypes.CSS_LENGTH, caller); + } + private static void parseExactlyNX(ApplContext ac, CssExpression expression, int n, int type, CssProperty caller) throws InvalidParamException { @@ -241,6 +261,56 @@ private static void parseAtMostX(ApplContext ac, CssExpression expression, } } + // parse at most n values of type (CssTypes.XXX) + private static void parseAtMostX(ApplContext ac, CssExpression expression, + int atMost, int type1, int type2, CssProperty caller) + throws InvalidParamException { + if (expression.getCount() > atMost) { + throw new InvalidParamException("unrecognize", ac); + } + CssValue val; + char op; + while (!expression.end()) { + val = expression.getValue(); + op = expression.getOperator(); + // special case, 0 can be a length or an angle... + if (val.getType() == CssTypes.CSS_NUMBER) { + switch (type1) { + case CssTypes.CSS_LENGTH: + val.getLength(); + break; + case CssTypes.CSS_ANGLE: + val.getAngle(); + case CssTypes.CSS_NUMBER: + break; + default: + switch (type2) { + case CssTypes.CSS_LENGTH: + val.getLength(); + break; + case CssTypes.CSS_ANGLE: + val.getAngle(); + case CssTypes.CSS_NUMBER: + break; + default: + throw new InvalidParamException("value", + val.toString(), + caller.getPropertyName(), ac); + } + } + } else if ((val.getType() != type1) && (val.getType() != type2)) { + throw new InvalidParamException("value", + val.toString(), + caller.getPropertyName(), ac); + } + expression.next(); + if (!expression.end() && (op != COMMA)) { + throw new InvalidParamException("operator", + Character.toString(op), ac); + } + } + } + // parse one value of type (CssTypes.XXX) private static void parseOneX(ApplContext ac, CssExpression expression, int type, CssProperty caller) @@ -270,6 +340,37 @@ private static void parseOneX(ApplContext ac, CssExpression expression, expression.next(); } + // parse one value of type (CssTypes.XXX) + private static void parseOneX(ApplContext ac, CssExpression expression, + int type1, int type2, CssProperty caller) + throws InvalidParamException { + if (expression.getCount() > 1) { + throw new InvalidParamException("unrecognize", ac); + } + if (expression.getCount() == 0) { + throw new InvalidParamException("few-value", caller.getPropertyName(), ac); + } + CssValue val; + val = expression.getValue(); + // special case, 0 can be a length or an angle... + if (val.getType() == CssTypes.CSS_NUMBER) { + if (type1 == CssTypes.CSS_LENGTH || type1 == CssTypes.CSS_ANGLE || + type1 == CssTypes.CSS_PERCENTAGE || type2 == CssTypes.CSS_PERCENTAGE || + type2 == CssTypes.CSS_LENGTH || type2 == CssTypes.CSS_ANGLE) { + // if not zero, it will fail + val.getCheckableValue().checkEqualsZero(ac, caller.getPropertyName()); + expression.next(); + return; + } + } + if (val.getType() != type1 && val.getType() != type2) { + throw new InvalidParamException("value", + val.toString(), + caller.getPropertyName(), ac); + } + expression.next(); + } + // special cases