Skip to content

Commit b8f7495

Browse files
committed
1 parent b77d26d commit b8f7495

4 files changed

Lines changed: 262 additions & 1 deletion

File tree

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,12 @@ transform-style: org.w3c.css.properties.css3.CssTransform
294294
backface-visibility: org.w3c.css.properties.css3.CssBackfaceVisibility
295295
perspective: org.w3c.css.properties.css3.CssPerspective
296296
perspective-origin: org.w3c.css.properties.css3.CssPerspectiveOrigin
297+
rotate: org.w3c.css.properties.css3.CssRotate
298+
scale: org.w3c.css.properties.css3.CssScale
297299
transform-origin: org.w3c.css.properties.css3.CssTransformOrigin
298300
transform-box: org.w3c.css.properties.css3.CssTransformBox
299301
transform: org.w3c.css.properties.css3.CssTransform
300302
translate: org.w3c.css.properties.css3.CssTranslate
301-
scale: org.w3c.css.properties.css3.CssScale
302303

303304
# image
304305
object-fit: org.w3c.css.properties.css3.CssObjectFit
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT World Wide Web Consortium, 2025.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
package org.w3c.css.properties.css;
7+
8+
import org.w3c.css.parser.CssStyle;
9+
import org.w3c.css.properties.css3.Css3Style;
10+
import org.w3c.css.util.ApplContext;
11+
import org.w3c.css.util.InvalidParamException;
12+
import org.w3c.css.values.CssExpression;
13+
14+
/**
15+
* @since CSS3
16+
*/
17+
public class CssRotate extends CssProperty {
18+
19+
/**
20+
* Create a new CssRotate
21+
*/
22+
public CssRotate() {
23+
}
24+
25+
/**
26+
* Creates a new CssRotate
27+
*
28+
* @param expression The expression for this property
29+
* @throws InvalidParamException
30+
* Expressions are incorrect
31+
*/
32+
public CssRotate(ApplContext ac, CssExpression expression, boolean check)
33+
throws InvalidParamException {
34+
throw new InvalidParamException("value",
35+
expression.getValue().toString(),
36+
getPropertyName(), ac);
37+
}
38+
39+
public CssRotate(ApplContext ac, CssExpression expression)
40+
throws InvalidParamException {
41+
this(ac, expression, false);
42+
}
43+
44+
/**
45+
* Returns the value of this property
46+
*/
47+
public Object get() {
48+
return value;
49+
}
50+
51+
52+
/**
53+
* Returns the name of this property
54+
*/
55+
public final String getPropertyName() {
56+
return "rotate";
57+
}
58+
59+
/**
60+
* Returns true if this property is "softly" inherited
61+
* e.g. his value is equals to inherit
62+
*/
63+
public boolean isSoftlyInherited() {
64+
return value.equals(inherit);
65+
}
66+
67+
/**
68+
* Returns a string representation of the object.
69+
*/
70+
public String toString() {
71+
return value.toString();
72+
}
73+
74+
/**
75+
* Add this property to the CssStyle.
76+
*
77+
* @param style The CssStyle
78+
*/
79+
public void addToStyle(ApplContext ac, CssStyle style) {
80+
Css3Style s = (Css3Style) style;
81+
if (s.cssRotate != null) {
82+
style.addRedefinitionWarning(ac, this);
83+
}
84+
s.cssRotate = this;
85+
}
86+
87+
88+
/**
89+
* Compares two properties for equality.
90+
*
91+
* @param property The other property.
92+
*/
93+
public boolean equals(CssProperty property) {
94+
return (property instanceof CssRotate &&
95+
value.equals(((CssRotate) property).value));
96+
}
97+
98+
99+
/**
100+
* Get this property in the style.
101+
*
102+
* @param style The style where the property is
103+
* @param resolve if true, resolve the style to find this property
104+
*/
105+
public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) {
106+
if (resolve) {
107+
return ((Css3Style) style).getRotate();
108+
} else {
109+
return ((Css3Style) style).cssRotate;
110+
}
111+
}
112+
}
113+

org/w3c/css/properties/css3/Css3Style.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
import org.w3c.css.properties.css.CssRest;
227227
import org.w3c.css.properties.css.CssRestAfter;
228228
import org.w3c.css.properties.css.CssRestBefore;
229+
import org.w3c.css.properties.css.CssRotate;
229230
import org.w3c.css.properties.css.CssRowGap;
230231
import org.w3c.css.properties.css.CssRubyAlign;
231232
import org.w3c.css.properties.css.CssRubyMerge;
@@ -727,6 +728,16 @@ public class Css3Style extends ATSCStyle {
727728
public CssTextSpacingTrim cssTextSpacingTrim;
728729
public CssTextSpacing cssTextSpacing;
729730
public CssTranslate cssTranslate;
731+
public CssRotate cssRotate;
732+
733+
public CssRotate getRotate() {
734+
if (cssRotate == null) {
735+
cssRotate =
736+
(CssRotate) style.CascadingOrder(new CssRotate(),
737+
style, selector);
738+
}
739+
return cssRotate;
740+
}
730741

731742
public CssTranslate getTranslate() {
732743
if (cssTranslate == null) {
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT World Wide Web Consortium, 2025.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
package org.w3c.css.properties.css3;
7+
8+
import org.w3c.css.util.ApplContext;
9+
import org.w3c.css.util.InvalidParamException;
10+
import org.w3c.css.values.CssExpression;
11+
import org.w3c.css.values.CssIdent;
12+
import org.w3c.css.values.CssTypes;
13+
import org.w3c.css.values.CssValue;
14+
import org.w3c.css.values.CssValueList;
15+
16+
import java.util.ArrayList;
17+
18+
import static org.w3c.css.values.CssOperator.SPACE;
19+
20+
/**
21+
* @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-rotate
22+
*/
23+
public class CssRotate extends org.w3c.css.properties.css.CssRotate {
24+
25+
public static final CssIdent[] allowedValues;
26+
27+
static {
28+
String[] _allowedValues = {"x", "y", "z"};
29+
allowedValues = new CssIdent[_allowedValues.length];
30+
for (int i = 0; i < allowedValues.length; i++) {
31+
allowedValues[i] = CssIdent.getIdent(_allowedValues[i]);
32+
}
33+
}
34+
35+
public static final CssIdent getAllowedValue(CssIdent ident) {
36+
for (CssIdent id : allowedValues) {
37+
if (id.equals(ident)) {
38+
return id;
39+
}
40+
}
41+
return null;
42+
}
43+
/**
44+
* Create a new CssRotate
45+
*/
46+
public CssRotate() {
47+
value = initial;
48+
}
49+
50+
/**
51+
* Creates a new CssRotate
52+
*
53+
* @param expression The expression for this property
54+
* @throws InvalidParamException Expressions are incorrect
55+
*/
56+
public CssRotate(ApplContext ac, CssExpression expression, boolean check)
57+
throws InvalidParamException {
58+
if (check && expression.getCount() > 4) {
59+
throw new InvalidParamException("unrecognize", ac);
60+
}
61+
CssValue val;
62+
ArrayList<CssValue> v = new ArrayList<>();
63+
char op;
64+
int nbNumber = 0;
65+
boolean gotIdent = false;
66+
boolean gotAngle = false;
67+
setByUser();
68+
69+
70+
while (!expression.end()) {
71+
val = expression.getValue();
72+
op = expression.getOperator();
73+
74+
switch (val.getType()) {
75+
case CssTypes.CSS_NUMBER:
76+
// if we got an axis or more than 3 values, report error
77+
if (gotIdent || (nbNumber == 3)) {
78+
throw new InvalidParamException("value", val.toString(),
79+
getPropertyName(), ac);
80+
}
81+
nbNumber++;
82+
v.add(val);
83+
break;
84+
case CssTypes.CSS_ANGLE:
85+
// if we got numbers, we must get them all before the angle value
86+
if (gotAngle || nbNumber == 1 || nbNumber == 2) {
87+
throw new InvalidParamException("value", val.toString(),
88+
getPropertyName(), ac);
89+
}
90+
gotAngle = true;
91+
v.add(val);
92+
break;
93+
case CssTypes.CSS_IDENT:
94+
CssIdent id = val.getIdent();
95+
if (none.equals(id) || CssIdent.isCssWide(id)) {
96+
if (expression.getCount() > 1) {
97+
throw new InvalidParamException("value", val.toString(),
98+
getPropertyName(), ac);
99+
}
100+
v.add(val);
101+
break;
102+
}
103+
// if wa got a number (ie: defining axis) or another ident axis, report error
104+
if (!gotIdent && (nbNumber == 0) && getAllowedValue(id) != null) {
105+
v.add(val);
106+
gotIdent = true;
107+
break;
108+
}
109+
// unrecognize ident, or unwanted one, let it fail
110+
default:
111+
throw new InvalidParamException("value",
112+
val.toString(),
113+
getPropertyName(), ac);
114+
}
115+
if (op != SPACE) {
116+
throw new InvalidParamException("operator",
117+
Character.toString(op), ac);
118+
}
119+
expression.next();
120+
}
121+
// sanity check, if we got an axis, we should get an angle, if we got number we should get 3 of them
122+
if ((nbNumber > 0 && nbNumber != 3) || ((gotIdent || (nbNumber != 0)) && !gotAngle)) {
123+
throw new InvalidParamException("value",
124+
v.toString(),
125+
getPropertyName(), ac);
126+
}
127+
value = (v.size() == 1) ? v.get(0) : new CssValueList(v);
128+
}
129+
130+
131+
public CssRotate(ApplContext ac, CssExpression expression)
132+
throws InvalidParamException {
133+
this(ac, expression, false);
134+
}
135+
}
136+

0 commit comments

Comments
 (0)