Skip to content

Commit e1ddec6

Browse files
committed
intoduced dashed idents to cope with color-mix() custom-color-space
1 parent 52bfaf0 commit e1ddec6

File tree

4 files changed

+135
-9
lines changed

4 files changed

+135
-9
lines changed

org/w3c/css/parser/analyzer/CssParser.jj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import org.w3c.css.values.CssCalc;
7070
import org.w3c.css.values.CssCheckableValue;
7171
import org.w3c.css.values.CssColor;
7272
import org.w3c.css.values.CssComparator;
73+
import org.w3c.css.values.CssDashedIdent;
7374
import org.w3c.css.values.CssEnv;
7475
import org.w3c.css.values.CssExpression;
7576
import org.w3c.css.values.CssFlexibleLength;
@@ -3267,7 +3268,7 @@ void term(CssExpression exp) :
32673268
| func=function() { setValue(func, exp, operator, null, FUNCTION); }
32683269
| n=<STRING> { setValue(new CssString(), exp, operator, n, STRING); }
32693270
| n=<DIV> { setValue(new CssSwitch(), exp, operator, n, DIV); }
3270-
| ( n=<RBRACKET> | n=<LBRACKET> ) { setValue(new CssBracket(), exp, operator, n, RBRACKET); }
3271+
| ( n=<RBRACKET> | n=<LBRACKET> ) { setValue(new CssBracket(), exp, operator, n, RBRACKET); }
32713272
| n=ident() {
32723273
/*
32733274
* Common error :
@@ -3291,6 +3292,7 @@ void term(CssExpression exp) :
32913292
setValue(new CssIdent(), exp, operator, n, IDENT);
32923293
}
32933294
}
3295+
| n=<CUSTOM_PROPERTY_NAME> { setValue(new CssDashedIdent(), exp, operator, n, CUSTOM_PROPERTY_NAME); }
32943296
| hashident(exp)
32953297
| n=<URL> {
32963298
CssURL _u = new CssURL();
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//
2+
// @author Yves Lafon
3+
//
4+
// (c) COPYRIGHT W3C 2026.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
package org.w3c.css.values;
7+
8+
import org.w3c.css.util.ApplContext;
9+
import org.w3c.css.util.InvalidParamException;
10+
11+
public class CssDashedIdent extends CssValue implements Comparable<CssDashedIdent> {
12+
13+
/**
14+
* Get a cached CssIdent, useful for common values like "inherit"
15+
*
16+
* @param name, the ident name
17+
* @return a CssIdent
18+
*/
19+
20+
21+
public static final int type = CssTypes.CSS_DASHED_IDENT;
22+
23+
public int compareTo(CssDashedIdent other) {
24+
int hash, ohash;
25+
hash = hashCode();
26+
ohash = other.hashCode();
27+
if (hash == ohash) {
28+
return 0;
29+
}
30+
return (hash < ohash) ? 1 : -1;
31+
}
32+
33+
private int hashcode = 0;
34+
35+
public final int getType() {
36+
return type;
37+
}
38+
39+
/**
40+
* Create a new CssDashedIdent
41+
*/
42+
public CssDashedIdent() {
43+
}
44+
45+
/**
46+
* Create a new CssIdent
47+
*
48+
* @param s The identificator
49+
*/
50+
public CssDashedIdent(String s) {
51+
value = s;
52+
}
53+
54+
/**
55+
* Set the value of this ident.
56+
*
57+
* @param s the string representation of the identificator.
58+
* @param ac For errors and warnings reports.
59+
*/
60+
public void set(String s, ApplContext ac) {
61+
value = s;
62+
hashcode = 0;
63+
}
64+
65+
/**
66+
* Returns the internal value.
67+
*/
68+
public Object get() {
69+
return value;
70+
}
71+
72+
/**
73+
* Returns a string representation of the object.
74+
*/
75+
public String toString() {
76+
return value;
77+
}
78+
79+
/**
80+
* Compares two values for equality.
81+
*
82+
* @param value The other value.
83+
*/
84+
public boolean equals(Object value) {
85+
return ((value instanceof CssDashedIdent) && (value.hashCode() == hashCode()));
86+
}
87+
88+
/**
89+
* Compares two values for equality.
90+
*
91+
* @param value The other value.
92+
* @return true is the two values are matching
93+
*/
94+
public boolean equals(CssDashedIdent value) {
95+
return (value.hashCode() == hashCode());
96+
}
97+
98+
/**
99+
* Returns a hashcode for this ident.
100+
*/
101+
public int hashCode() {
102+
// we cache, as we use toLowerCase and don't store the resulting string
103+
if (hashcode == 0) {
104+
hashcode = value.toLowerCase().hashCode();
105+
}
106+
return hashcode;
107+
}
108+
109+
/**
110+
* Does this value contain a "\9" CSS declaration hack?
111+
*/
112+
public boolean hasBackslash9Hack() {
113+
return value.endsWith("\\9");
114+
}
115+
116+
private String value;
117+
118+
public CssDashedIdent getDashedHashIdent() throws InvalidParamException {
119+
return this;
120+
}
121+
}

org/w3c/css/values/CssTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class CssTypes {
3838
public static final int CSS_VARIABLE = 25;
3939
public static final int CSS_VARIABLE_DEFINITION = 26;
4040
public static final int CSS_ENV = 27;
41+
public static final int CSS_DASHED_IDENT = 28;
4142

4243
// not really a property value
4344
public static final int CSS_ANPLUSB = 48;

org/w3c/css/values/color/ColorMix.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ public static CssValue parseColorInterpolationMethod(ApplContext ac, CssExpressi
155155
exp.next();
156156
val = exp.getValue();
157157
op = exp.getOperator();
158+
if (val.getType() == CssTypes.CSS_DASHED_IDENT) {
159+
// TODO check it is a declared value
160+
values.add(val);
161+
exp.next();
162+
if (!exp.end()) {
163+
throw new InvalidParamException("unrecognize", ac);
164+
}
165+
return new CssValueList(values);
166+
}
167+
// else it should be a specific IDENT
158168
if (val.getType() != CssTypes.CSS_IDENT) {
159169
throw new InvalidParamException("value",
160170
val.toString(), caller, ac);
@@ -210,14 +220,6 @@ public static CssValue parseColorInterpolationMethod(ApplContext ac, CssExpressi
210220
throw new InvalidParamException("value",
211221
val.toString(), caller, ac);
212222
}
213-
if (id.toString().startsWith("--")) {
214-
// TODO check it is a declared value
215-
values.add(val);
216-
if (!exp.end()) {
217-
throw new InvalidParamException("unrecognize", ac);
218-
}
219-
return new CssValueList(values);
220-
}
221223
throw new InvalidParamException("unrecognize", ac);
222224
}
223225

0 commit comments

Comments
 (0)