|
23 | 23 |
|
24 | 24 | /**
|
25 | 25 | * @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 |
26 | 27 | */
|
27 | 28 | public class CssTransform extends org.w3c.css.properties.css.CssTransform {
|
28 | 29 |
|
@@ -139,11 +140,12 @@ protected static void parseFunctionValues(ApplContext ac, CssValue func, CssProp
|
139 | 140 | parseTranslateAxisFunction(ac, function.getParameters(), caller);
|
140 | 141 | break;
|
141 | 142 | 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); |
143 | 145 | break;
|
144 | 146 | case scaleX:
|
145 | 147 | case scaleY:
|
146 |
| - parseOneX(ac, function.getParameters(), CssTypes.CSS_NUMBER, caller); |
| 148 | + parseOneX(ac, function.getParameters(), CssTypes.CSS_NUMBER, CssTypes.CSS_PERCENTAGE, caller); |
147 | 149 | break;
|
148 | 150 | case rotate:
|
149 | 151 | parseOneX(ac, function.getParameters(), CssTypes.CSS_ANGLE, caller);
|
@@ -191,6 +193,24 @@ protected static void parseFunctionValues(ApplContext ac, CssValue func, CssProp
|
191 | 193 | }
|
192 | 194 | }
|
193 | 195 |
|
| 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 | + |
194 | 214 | private static void parseExactlyNX(ApplContext ac, CssExpression expression,
|
195 | 215 | int n, int type, CssProperty caller)
|
196 | 216 | throws InvalidParamException {
|
@@ -241,6 +261,56 @@ private static void parseAtMostX(ApplContext ac, CssExpression expression,
|
241 | 261 | }
|
242 | 262 | }
|
243 | 263 |
|
| 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 | + |
244 | 314 | // parse one value of type (CssTypes.XXX)
|
245 | 315 | private static void parseOneX(ApplContext ac, CssExpression expression,
|
246 | 316 | int type, CssProperty caller)
|
@@ -270,6 +340,37 @@ private static void parseOneX(ApplContext ac, CssExpression expression,
|
270 | 340 | expression.next();
|
271 | 341 | }
|
272 | 342 |
|
| 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 | + |
273 | 374 | // special cases
|
274 | 375 |
|
275 | 376 |
|
|
0 commit comments