Skip to content

Commit 03198dd

Browse files
committed
updated scale() scaleX() scaleY() and perspective() per https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#changes-recent
1 parent b8f7495 commit 03198dd

File tree

1 file changed

+103
-2
lines changed

1 file changed

+103
-2
lines changed

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

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @spec https://www.w3.org/TR/2019/CR-css-transforms-1-20190214/#propdef-transform
26+
* @spec https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#transform-functions
2627
*/
2728
public class CssTransform extends org.w3c.css.properties.css.CssTransform {
2829

@@ -139,11 +140,12 @@ protected static void parseFunctionValues(ApplContext ac, CssValue func, CssProp
139140
parseTranslateAxisFunction(ac, function.getParameters(), caller);
140141
break;
141142
case scale:
142-
parseAtMostX(ac, function.getParameters(), 2, CssTypes.CSS_NUMBER, caller);
143+
parseAtMostX(ac, function.getParameters(), 2,
144+
CssTypes.CSS_NUMBER, CssTypes.CSS_PERCENTAGE, caller);
143145
break;
144146
case scaleX:
145147
case scaleY:
146-
parseOneX(ac, function.getParameters(), CssTypes.CSS_NUMBER, caller);
148+
parseOneX(ac, function.getParameters(), CssTypes.CSS_NUMBER, CssTypes.CSS_PERCENTAGE, caller);
147149
break;
148150
case rotate:
149151
parseOneX(ac, function.getParameters(), CssTypes.CSS_ANGLE, caller);
@@ -191,6 +193,24 @@ protected static void parseFunctionValues(ApplContext ac, CssValue func, CssProp
191193
}
192194
}
193195

196+
private static void parsePerspective(ApplContext ac, CssExpression expression, CssProperty caller)
197+
throws InvalidParamException {
198+
if (expression.getCount() > 1) {
199+
throw new InvalidParamException("unrecognize", ac);
200+
}
201+
if (expression.getCount() == 0) {
202+
throw new InvalidParamException("few-value", caller.getPropertyName(), ac);
203+
}
204+
CssValue val = expression.getValue();
205+
if (val.getType() == CssTypes.CSS_IDENT) {
206+
if (none.equals(val.getIdent())) {
207+
return;
208+
}
209+
// if not none, it will fail later
210+
}
211+
parseOneX(ac, expression, CssTypes.CSS_LENGTH, caller);
212+
}
213+
194214
private static void parseExactlyNX(ApplContext ac, CssExpression expression,
195215
int n, int type, CssProperty caller)
196216
throws InvalidParamException {
@@ -241,6 +261,56 @@ private static void parseAtMostX(ApplContext ac, CssExpression expression,
241261
}
242262
}
243263

264+
// parse at most n values of type (CssTypes.XXX)
265+
private static void parseAtMostX(ApplContext ac, CssExpression expression,
266+
int atMost, int type1, int type2, CssProperty caller)
267+
throws InvalidParamException {
268+
if (expression.getCount() > atMost) {
269+
throw new InvalidParamException("unrecognize", ac);
270+
}
271+
CssValue val;
272+
char op;
273+
while (!expression.end()) {
274+
val = expression.getValue();
275+
op = expression.getOperator();
276+
// special case, 0 can be a length or an angle...
277+
if (val.getType() == CssTypes.CSS_NUMBER) {
278+
switch (type1) {
279+
case CssTypes.CSS_LENGTH:
280+
val.getLength();
281+
break;
282+
case CssTypes.CSS_ANGLE:
283+
val.getAngle();
284+
case CssTypes.CSS_NUMBER:
285+
break;
286+
default:
287+
switch (type2) {
288+
case CssTypes.CSS_LENGTH:
289+
val.getLength();
290+
break;
291+
case CssTypes.CSS_ANGLE:
292+
val.getAngle();
293+
case CssTypes.CSS_NUMBER:
294+
break;
295+
default:
296+
throw new InvalidParamException("value",
297+
val.toString(),
298+
caller.getPropertyName(), ac);
299+
}
300+
}
301+
} else if ((val.getType() != type1) && (val.getType() != type2)) {
302+
throw new InvalidParamException("value",
303+
val.toString(),
304+
caller.getPropertyName(), ac);
305+
}
306+
expression.next();
307+
if (!expression.end() && (op != COMMA)) {
308+
throw new InvalidParamException("operator",
309+
Character.toString(op), ac);
310+
}
311+
}
312+
}
313+
244314
// parse one value of type (CssTypes.XXX)
245315
private static void parseOneX(ApplContext ac, CssExpression expression,
246316
int type, CssProperty caller)
@@ -270,6 +340,37 @@ private static void parseOneX(ApplContext ac, CssExpression expression,
270340
expression.next();
271341
}
272342

343+
// parse one value of type (CssTypes.XXX)
344+
private static void parseOneX(ApplContext ac, CssExpression expression,
345+
int type1, int type2, CssProperty caller)
346+
throws InvalidParamException {
347+
if (expression.getCount() > 1) {
348+
throw new InvalidParamException("unrecognize", ac);
349+
}
350+
if (expression.getCount() == 0) {
351+
throw new InvalidParamException("few-value", caller.getPropertyName(), ac);
352+
}
353+
CssValue val;
354+
val = expression.getValue();
355+
// special case, 0 can be a length or an angle...
356+
if (val.getType() == CssTypes.CSS_NUMBER) {
357+
if (type1 == CssTypes.CSS_LENGTH || type1 == CssTypes.CSS_ANGLE ||
358+
type1 == CssTypes.CSS_PERCENTAGE || type2 == CssTypes.CSS_PERCENTAGE ||
359+
type2 == CssTypes.CSS_LENGTH || type2 == CssTypes.CSS_ANGLE) {
360+
// if not zero, it will fail
361+
val.getCheckableValue().checkEqualsZero(ac, caller.getPropertyName());
362+
expression.next();
363+
return;
364+
}
365+
}
366+
if (val.getType() != type1 && val.getType() != type2) {
367+
throw new InvalidParamException("value",
368+
val.toString(),
369+
caller.getPropertyName(), ac);
370+
}
371+
expression.next();
372+
}
373+
273374
// special cases
274375

275376

0 commit comments

Comments
 (0)