Skip to content

Commit f4dda67

Browse files
committed
1 parent 4586578 commit f4dda67

4 files changed

Lines changed: 215 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+
scale: org.w3c.css.properties.css3.CssScale
300301

301302
# image
302303
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 MIT, ERCIM, Keio, Beihang, 2022.
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 CssScale extends CssProperty {
18+
19+
/**
20+
* Create a new CssScale
21+
*/
22+
public CssScale() {
23+
}
24+
25+
/**
26+
* Creates a new CssScale
27+
*
28+
* @param expression The expression for this property
29+
* @throws InvalidParamException
30+
* Expressions are incorrect
31+
*/
32+
public CssScale(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 CssScale(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 "scale";
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.cssScale != null) {
82+
style.addRedefinitionWarning(ac, this);
83+
}
84+
s.cssScale = 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 CssScale &&
95+
value.equals(((CssScale) 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).getScale();
108+
} else {
109+
return ((Css3Style) style).cssScale;
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
@@ -230,6 +230,7 @@
230230
import org.w3c.css.properties.css.CssRubyAlign;
231231
import org.w3c.css.properties.css.CssRubyMerge;
232232
import org.w3c.css.properties.css.CssRubyPosition;
233+
import org.w3c.css.properties.css.CssScale;
233234
import org.w3c.css.properties.css.CssScrollBehavior;
234235
import org.w3c.css.properties.css.CssScrollMargin;
235236
import org.w3c.css.properties.css.CssScrollMarginBlock;
@@ -564,6 +565,7 @@ public class Css3Style extends ATSCStyle {
564565
public CssTransformOrigin cssTransformOrigin;
565566
public CssTransform cssTransform;
566567
public CssTransformBox cssTransformBox;
568+
public CssScale cssScale;
567569

568570
public CssBoxSizing cssBoxSizing;
569571
public CssResize cssResize;
@@ -724,6 +726,15 @@ public class Css3Style extends ATSCStyle {
724726
public CssTextSpacingTrim cssTextSpacingTrim;
725727
public CssTextSpacing cssTextSpacing;
726728

729+
public CssScale getScale() {
730+
if (cssScale == null) {
731+
cssScale =
732+
(CssScale) style.CascadingOrder(new CssScale(),
733+
style, selector);
734+
}
735+
return cssScale;
736+
}
737+
727738
public CssTextSpacing getTextSpacing() {
728739
if (cssTextSpacing == null) {
729740
cssTextSpacing =
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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-scale
22+
*/
23+
public class CssScale extends org.w3c.css.properties.css.CssScale {
24+
25+
/**
26+
* Create a new CssScale
27+
*/
28+
public CssScale() {
29+
value = initial;
30+
}
31+
32+
/**
33+
* Creates a new CssScale
34+
*
35+
* @param expression The expression for this property
36+
* @throws InvalidParamException Expressions are incorrect
37+
*/
38+
public CssScale(ApplContext ac, CssExpression expression, boolean check)
39+
throws InvalidParamException {
40+
if (check && expression.getCount() > 3) {
41+
throw new InvalidParamException("unrecognize", ac);
42+
}
43+
CssValue val;
44+
ArrayList<CssValue> v = new ArrayList<>();
45+
char op;
46+
setByUser();
47+
48+
49+
while (!expression.end()) {
50+
val = expression.getValue();
51+
op = expression.getOperator();
52+
53+
switch (val.getType()) {
54+
case CssTypes.CSS_NUMBER:
55+
case CssTypes.CSS_PERCENTAGE:
56+
// spec is silent on negative values
57+
v.add(val);
58+
break;
59+
case CssTypes.CSS_IDENT:
60+
CssIdent id = val.getIdent();
61+
if (none.equals(id) || CssIdent.isCssWide(id)) {
62+
if (expression.getCount() > 1) {
63+
throw new InvalidParamException("value", val.toString(),
64+
getPropertyName(), ac);
65+
}
66+
v.add(val);
67+
break;
68+
}
69+
// unrecognize ident, let it fail
70+
default:
71+
throw new InvalidParamException("value",
72+
val.toString(),
73+
getPropertyName(), ac);
74+
}
75+
if (op != SPACE) {
76+
throw new InvalidParamException("operator",
77+
Character.toString(op), ac);
78+
}
79+
expression.next();
80+
}
81+
value = (v.size() == 1) ? v.get(0) : new CssValueList(v);
82+
}
83+
84+
85+
public CssScale(ApplContext ac, CssExpression expression)
86+
throws InvalidParamException {
87+
this(ac, expression, false);
88+
}
89+
}
90+

0 commit comments

Comments
 (0)