Skip to content

Commit b77d26d

Browse files
committed
1 parent 5197323 commit b77d26d

4 files changed

Lines changed: 226 additions & 0 deletions

File tree

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ perspective-origin: org.w3c.css.properties.css3.CssPerspecti
297297
transform-origin: org.w3c.css.properties.css3.CssTransformOrigin
298298
transform-box: org.w3c.css.properties.css3.CssTransformBox
299299
transform: org.w3c.css.properties.css3.CssTransform
300+
translate: org.w3c.css.properties.css3.CssTranslate
300301
scale: org.w3c.css.properties.css3.CssScale
301302

302303
# image
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 CssTranslate extends CssProperty {
18+
19+
/**
20+
* Create a new CssTranslate
21+
*/
22+
public CssTranslate() {
23+
}
24+
25+
/**
26+
* Creates a new CssTranslate
27+
*
28+
* @param expression The expression for this property
29+
* @throws InvalidParamException
30+
* Expressions are incorrect
31+
*/
32+
public CssTranslate(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 CssTranslate(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 "translate";
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.cssTranslate != null) {
82+
style.addRedefinitionWarning(ac, this);
83+
}
84+
s.cssTranslate = 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 CssTranslate &&
95+
value.equals(((CssTranslate) 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).getTranslate();
108+
} else {
109+
return ((Css3Style) style).cssTranslate;
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
@@ -301,6 +301,7 @@
301301
import org.w3c.css.properties.css.CssTransitionDuration;
302302
import org.w3c.css.properties.css.CssTransitionProperty;
303303
import org.w3c.css.properties.css.CssTransitionTimingFunction;
304+
import org.w3c.css.properties.css.CssTranslate;
304305
import org.w3c.css.properties.css.CssUserSelect;
305306
import org.w3c.css.properties.css.CssVoiceBalance;
306307
import org.w3c.css.properties.css.CssVoiceDuration;
@@ -725,7 +726,17 @@ public class Css3Style extends ATSCStyle {
725726
public CssTextAutospace cssTextAutospace;
726727
public CssTextSpacingTrim cssTextSpacingTrim;
727728
public CssTextSpacing cssTextSpacing;
729+
public CssTranslate cssTranslate;
728730

731+
public CssTranslate getTranslate() {
732+
if (cssTranslate == null) {
733+
cssTranslate =
734+
(CssTranslate) style.CascadingOrder(new CssTranslate(),
735+
style, selector);
736+
}
737+
return cssTranslate;
738+
}
739+
729740
public CssScale getScale() {
730741
if (cssScale == null) {
731742
cssScale =
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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.CssCheckableValue;
11+
import org.w3c.css.values.CssExpression;
12+
import org.w3c.css.values.CssIdent;
13+
import org.w3c.css.values.CssTypes;
14+
import org.w3c.css.values.CssValue;
15+
import org.w3c.css.values.CssValueList;
16+
17+
import java.util.ArrayList;
18+
19+
import static org.w3c.css.values.CssOperator.SPACE;
20+
21+
/**
22+
* @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#propdef-translate
23+
*/
24+
public class CssTranslate extends org.w3c.css.properties.css.CssTranslate {
25+
26+
/**
27+
* Create a new CssTranslate
28+
*/
29+
public CssTranslate() {
30+
value = initial;
31+
}
32+
33+
/**
34+
* Creates a new CssTranslate
35+
*
36+
* @param expression The expression for this property
37+
* @throws InvalidParamException Expressions are incorrect
38+
*/
39+
public CssTranslate(ApplContext ac, CssExpression expression, boolean check)
40+
throws InvalidParamException {
41+
if (check && expression.getCount() > 3) {
42+
throw new InvalidParamException("unrecognize", ac);
43+
}
44+
CssValue val;
45+
ArrayList<CssValue> v = new ArrayList<>();
46+
char op;
47+
setByUser();
48+
49+
50+
while (!expression.end()) {
51+
val = expression.getValue();
52+
op = expression.getOperator();
53+
54+
switch (val.getType()) {
55+
case CssTypes.CSS_NUMBER:
56+
// only 0 can be a length...
57+
CssCheckableValue p = val.getCheckableValue();
58+
p.checkEqualsZero(ac, this);
59+
v.add(val);
60+
break;
61+
case CssTypes.CSS_PERCENTAGE:
62+
if (v.size() == 2) {
63+
// percentage can appear only in the first two values
64+
throw new InvalidParamException("value", val.toString(),
65+
getPropertyName(), ac);
66+
}
67+
case CssTypes.CSS_LENGTH:
68+
v.add(val);
69+
break;
70+
case CssTypes.CSS_IDENT:
71+
CssIdent id = val.getIdent();
72+
if (none.equals(id) || CssIdent.isCssWide(id)) {
73+
if (expression.getCount() > 1) {
74+
throw new InvalidParamException("value", val.toString(),
75+
getPropertyName(), ac);
76+
}
77+
v.add(val);
78+
break;
79+
}
80+
// unrecognize ident, let it fail
81+
default:
82+
throw new InvalidParamException("value",
83+
val.toString(),
84+
getPropertyName(), ac);
85+
}
86+
if (op != SPACE) {
87+
throw new InvalidParamException("operator",
88+
Character.toString(op), ac);
89+
}
90+
expression.next();
91+
}
92+
value = (v.size() == 1) ? v.get(0) : new CssValueList(v);
93+
}
94+
95+
96+
public CssTranslate(ApplContext ac, CssExpression expression)
97+
throws InvalidParamException {
98+
this(ac, expression, false);
99+
}
100+
}
101+

0 commit comments

Comments
 (0)