Skip to content

Commit 3682b2f

Browse files
committed
1 parent dfc4ca1 commit 3682b2f

File tree

5 files changed

+113
-2
lines changed

5 files changed

+113
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8650,6 +8650,14 @@ final public boolean prio() throws ParseException {
86508650
} else if (funcname.equals("device-cmyk(")) {
86518651
color.setDeviceCMYKColor(ac, exp);
86528652
{if ("" != null) return color;}
8653+
} else if (funcname.equals("light-dark(")) {
8654+
color.setLightDark(ac, exp);
8655+
{if ("" != null) return color;}
8656+
/*
8657+
} else if (funcname.equals("color-mix(")) {
8658+
color.setColorMix(ac, exp);
8659+
return color;
8660+
*/
86538661
} else if (funcname.equals("image(")) {
86548662
CssImage img = new CssImage();
86558663
img.setImageList(exp, ac);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3465,7 +3465,7 @@ CssCheckableValue mathsum() :
34653465
nb_pre_sp = 0;
34663466
}
34673467
// special case for "-" as it can't match like <PLUS> (<PLUS> is <_W>* "+")
3468-
( LOOKAHEAD(2) ( o=<PLUS> | ( ( <S> { nb_pre_sp++; } )* o=<MINUS> ) ) {
3468+
( LOOKAHEAD(2) ( o=<PLUS> | ( ( <S> { nb_pre_sp++; } )* o=<MINUS> ) ) {
34693469
if (o.image.length() < 2 && nb_pre_sp == 0) {
34703470
throw new ParseException(ac.getMsg().getString("parser.calcwhitespace"));
34713471
}
@@ -3722,6 +3722,14 @@ CssValue function() :
37223722
} else if (funcname.equals("device-cmyk(")) {
37233723
color.setDeviceCMYKColor(ac, exp);
37243724
return color;
3725+
} else if (funcname.equals("light-dark(")) {
3726+
color.setLightDark(ac, exp);
3727+
return color;
3728+
/*
3729+
} else if (funcname.equals("color-mix(")) {
3730+
color.setColorMix(ac, exp);
3731+
return color;
3732+
*/
37253733
} else if (funcname.equals("image(")) {
37263734
CssImage img = new CssImage();
37273735
img.setImageList(exp, ac);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public CssColor(ApplContext ac, CssExpression expression, boolean check)
6969
color = val;
7070
break;
7171
case CssTypes.CSS_FUNCTION:
72-
CssFunction attr = val.getFunction();
72+
CssFunction attr = val.getFunction();
7373
CssExpression params = attr.getParameters();
7474
String fname = attr.getName();
7575

org/w3c/css/values/CssColor.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public final int getType() {
3636
LAB lab = null;
3737
LCH lch = null;
3838
DeviceCMYK cmyk = null;
39+
LightDark lightdark = null;
3940

4041
boolean contains_variable = false;
4142

@@ -114,6 +115,24 @@ public String toString() {
114115
return "*invalid*";
115116
}
116117

118+
public void setLightDark(ApplContext ac, CssExpression exp)
119+
throws InvalidParamException {
120+
if ((exp == null) || (exp.getCount() != 2)) {
121+
throw new InvalidParamException("invalid-color", ac);
122+
}
123+
LightDark ld = new LightDark();
124+
CssValue l = exp.getValue();
125+
char op = exp.getOperator();
126+
if (l == null || op != COMMA) {
127+
throw new InvalidParamException("invalid-color", ac);
128+
}
129+
exp.next();
130+
CssValue d = exp.getValue();
131+
ld.setLight(ac, l);
132+
ld.setDark(ac, d);
133+
this.lightdark = ld;
134+
exp.next();
135+
}
117136

118137
public void setRGBColor(ApplContext ac, CssExpression exp)
119138
throws InvalidParamException {
@@ -1379,5 +1398,20 @@ public void setDeviceCMYKColor(ApplContext ac, CssExpression exp)
13791398
}
13801399
}
13811400

1401+
/**
1402+
* Parse a LightDark color.
1403+
* format: light-dark( <color>, <color>) [ / <alpha-value> ]? ) |
1404+
*/
1405+
public void setLightDarkColor(ApplContext ac, CssExpression exp)
1406+
throws InvalidParamException {
1407+
// light-dark defined in CSS3 and onward
1408+
if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) {
1409+
StringBuilder sb = new StringBuilder();
1410+
sb.append("light-dark(").append(exp.toStringFromStart()).append(')');
1411+
throw new InvalidParamException("notversion", sb.toString(),
1412+
ac.getCssVersionString(), ac);
1413+
}
1414+
lightdark = new LightDark();
1415+
}
13821416
}
13831417

org/w3c/css/values/LightDark.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio University, Beihang University 2018.
5+
// Please first read the full copyright statement in file COPYRIGHT.html
6+
//
7+
package org.w3c.css.values;
8+
9+
import org.w3c.css.util.ApplContext;
10+
import org.w3c.css.util.InvalidParamException;
11+
12+
public class LightDark {
13+
String output = null;
14+
CssColor light, dark;
15+
boolean has_css_variable = false;
16+
17+
/**
18+
* Create a new LightDark
19+
*/
20+
public LightDark() {
21+
}
22+
23+
public final void setLight(ApplContext ac, CssValue val) throws InvalidParamException {
24+
if (val.getType() == CssTypes.CSS_COLOR) {
25+
light = (CssColor) val;
26+
if (light.hasCssVariable()) {
27+
has_css_variable = true;
28+
}
29+
output = null;
30+
}
31+
}
32+
33+
public final void setDark(ApplContext ac, CssValue val) throws InvalidParamException {
34+
if (val.getType() == CssTypes.CSS_COLOR) {
35+
dark = (CssColor) val;
36+
if (dark.hasCssVariable()) {
37+
has_css_variable = true;
38+
}
39+
output = null;
40+
}
41+
}
42+
43+
public boolean equals(LightDark other) {
44+
if (other != null) {
45+
return (light.equals(other.light) && dark.equals(other.dark));
46+
}
47+
return false;
48+
}
49+
50+
/**
51+
* Returns a string representation of the object.
52+
*/
53+
public String toString() {
54+
if (output == null) {
55+
StringBuilder sb = new StringBuilder("light-dark(");
56+
sb.append(light).append(", ").append(dark).append(')');
57+
output = sb.toString();
58+
}
59+
return output;
60+
}
61+
}

0 commit comments

Comments
 (0)