Skip to content

Commit 993902a

Browse files
committed
1 parent 18d98ae commit 993902a

File tree

4 files changed

+340
-0
lines changed

4 files changed

+340
-0
lines changed

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ scroll-snap-stop: org.w3c.css.properties.css3.CssScrollSna
144144
scroll-snap-type: org.w3c.css.properties.css3.CssScrollSnapType
145145

146146
#scrollbar
147+
scrollbar-color: org.w3c.css.properties.css3.CssScrollbarColor
147148
scrollbar-width: org.w3c.css.properties.css3.CssScrollbarWidth
148149

149150
# grid
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2021.
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+
import org.w3c.css.values.CssValue;
14+
15+
/**
16+
* @since CSS3
17+
*/
18+
public class CssScrollbarColor extends CssProperty {
19+
20+
public CssValue value;
21+
22+
/**
23+
* Create a new CssScrollbarColor
24+
*/
25+
public CssScrollbarColor() {
26+
}
27+
28+
/**
29+
* Creates a new CssScrollbarColor
30+
*
31+
* @param expression The expression for this property
32+
* @throws InvalidParamException
33+
* Expressions are incorrect
34+
*/
35+
public CssScrollbarColor(ApplContext ac, CssExpression expression, //
36+
boolean check) throws InvalidParamException {
37+
throw new InvalidParamException("value",
38+
expression.getValue().toString(),
39+
getPropertyName(), ac);
40+
}
41+
42+
public CssScrollbarColor(ApplContext ac, CssExpression expression)
43+
throws InvalidParamException {
44+
this(ac, expression, false);
45+
}
46+
47+
/**
48+
* Returns the value of this property
49+
*/
50+
public Object get() {
51+
return value;
52+
}
53+
54+
55+
/**
56+
* Returns the name of this property
57+
*/
58+
public final String getPropertyName() {
59+
return "scrollbar-color";
60+
}
61+
62+
/**
63+
* Returns true if this property is "softly" inherited
64+
* e.g. his value is equals to inherit
65+
*/
66+
public boolean isSoftlyInherited() {
67+
return value.equals(inherit);
68+
}
69+
70+
/**
71+
* Returns a string representation of the object.
72+
*/
73+
public String toString() {
74+
return value.toString();
75+
}
76+
77+
/**
78+
* Add this property to the CssStyle.
79+
*
80+
* @param style The CssStyle
81+
*/
82+
public void addToStyle(ApplContext ac, CssStyle style) {
83+
Css3Style s = (Css3Style) style;
84+
if (s.cssScrollbarColor != null) {
85+
style.addRedefinitionWarning(ac, this);
86+
}
87+
s.cssScrollbarColor = this;
88+
}
89+
90+
91+
/**
92+
* Compares two properties for equality.
93+
*
94+
* @param property The other property.
95+
*/
96+
public boolean equals(CssProperty property) {
97+
return (property instanceof CssScrollbarColor &&
98+
value.equals(((CssScrollbarColor) property).value));
99+
}
100+
101+
102+
/**
103+
* Get this property in the style.
104+
*
105+
* @param style The style where the property is
106+
* @param resolve if true, resolve the style to find this property
107+
*/
108+
public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) {
109+
if (resolve) {
110+
return ((Css3Style) style).getScrollbarColor();
111+
} else {
112+
return ((Css3Style) style).cssScrollbarColor;
113+
}
114+
}
115+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
import org.w3c.css.properties.css.CssScrollSnapAlign;
233233
import org.w3c.css.properties.css.CssScrollSnapStop;
234234
import org.w3c.css.properties.css.CssScrollSnapType;
235+
import org.w3c.css.properties.css.CssScrollbarColor;
235236
import org.w3c.css.properties.css.CssScrollbarWidth;
236237
import org.w3c.css.properties.css.CssSpeakAs;
237238
import org.w3c.css.properties.css.CssTabSize;
@@ -625,7 +626,17 @@ public class Css3Style extends ATSCStyle {
625626
public CssTextDecorationSkipInk cssTextDecorationSkipInk;
626627
public CssTextDecorationSkipSpaces cssTextDecorationSkipSpaces;
627628
public CssScrollbarWidth cssScrollbarWidth;
629+
public CssScrollbarColor cssScrollbarColor;
628630

631+
public CssScrollbarColor getScrollbarColor() {
632+
if (cssScrollbarColor == null) {
633+
cssScrollbarColor =
634+
(CssScrollbarColor) style.CascadingOrder(new CssScrollbarColor(),
635+
style, selector);
636+
}
637+
return cssScrollbarColor;
638+
}
639+
629640
public CssScrollbarWidth getScrollbarWidth() {
630641
if (cssScrollbarWidth == null) {
631642
cssScrollbarWidth =
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
//
2+
// Author: Yves Lafon <ylafon@w3.org>
3+
//
4+
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2021.
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-scrollbars-1-20210829/#propdef-scrollbar-color
22+
*/
23+
public class CssScrollbarColor extends org.w3c.css.properties.css.CssScrollbarColor {
24+
25+
public static final CssIdent[] allowed_values;
26+
27+
static {
28+
String[] _allowed_values = {"auto"};
29+
allowed_values = new CssIdent[_allowed_values.length];
30+
int i = 0;
31+
for (String s : _allowed_values) {
32+
allowed_values[i++] = CssIdent.getIdent(s);
33+
}
34+
}
35+
36+
public static CssIdent getAllowedIdent(CssIdent ident) {
37+
for (CssIdent id : allowed_values) {
38+
if (id.equals(ident)) {
39+
return id;
40+
}
41+
}
42+
return null;
43+
}
44+
45+
/**
46+
* Create a new CssScrollbarColor
47+
*/
48+
public CssScrollbarColor() {
49+
value = initial;
50+
}
51+
52+
/**
53+
* Creates a new CssScrollbarColor
54+
*
55+
* @param expression The expression for this property
56+
* @throws InvalidParamException Expressions are incorrect
57+
*/
58+
public CssScrollbarColor(ApplContext ac, CssExpression expression, boolean check)
59+
throws InvalidParamException {
60+
if (check && expression.getCount() > 2) {
61+
throw new InvalidParamException("unrecognize", ac);
62+
}
63+
64+
setByUser();
65+
66+
CssValue val;
67+
org.w3c.css.values.CssColor c;
68+
CssColor tcolor;
69+
char op;
70+
71+
val = expression.getValue();
72+
op = expression.getOperator();
73+
ArrayList<CssValue> values = new ArrayList<>();
74+
75+
switch (val.getType()) {
76+
case CssTypes.CSS_IDENT:
77+
if (inherit.equals(val)) {
78+
if (expression.getCount() != 1) {
79+
throw new InvalidParamException("value",
80+
val.toString(),
81+
getPropertyName(), ac);
82+
}
83+
value = val;
84+
break;
85+
} else {
86+
CssIdent ident = getAllowedIdent(val.getIdent());
87+
// auto can be there once
88+
if (ident != null) {
89+
if (expression.getCount() != 1) {
90+
throw new InvalidParamException("value",
91+
val.toString(),
92+
getPropertyName(), ac);
93+
}
94+
value = val;
95+
break;
96+
}
97+
}
98+
// it must be a color instead
99+
try {
100+
c = new org.w3c.css.values.CssColor(ac, val.getIdent().toString());
101+
} catch (InvalidParamException e) {
102+
// we recreate the exception, as it will have
103+
// the wrong property name otherwise
104+
throw new InvalidParamException("value",
105+
expression.getValue(),
106+
getPropertyName(), ac);
107+
}
108+
values.add(val);
109+
break;
110+
case CssTypes.CSS_FUNCTION:
111+
try {
112+
tcolor = new CssColor(ac, expression, check);
113+
value = val;
114+
break;
115+
} catch (InvalidParamException e) {
116+
// we recreate the exception, as it will have
117+
// the wrong property name otherwise
118+
throw new InvalidParamException("value",
119+
expression.getValue(),
120+
getPropertyName(), ac);
121+
}
122+
case CssTypes.CSS_HASH_IDENT:
123+
c = new org.w3c.css.values.CssColor();
124+
c.setShortRGBColor(ac, val.getHashIdent().toString());
125+
values.add(val);
126+
break;
127+
case CssTypes.CSS_COLOR:
128+
values.add(val);
129+
break;
130+
default:
131+
throw new InvalidParamException("value",
132+
val.toString(),
133+
getPropertyName(), ac);
134+
}
135+
expression.next();
136+
137+
if (!expression.end()) {
138+
// second value
139+
if (op != SPACE) {
140+
throw new InvalidParamException("operator",
141+
Character.toString(op), ac);
142+
}
143+
val = expression.getValue();
144+
switch (val.getType()) {
145+
case CssTypes.CSS_IDENT:
146+
if (inherit.equals(val)) {
147+
throw new InvalidParamException("value",
148+
val.toString(),
149+
getPropertyName(), ac);
150+
} else {
151+
CssIdent ident = getAllowedIdent(val.getIdent());
152+
// auto can be there first (and alone)
153+
if (ident != null) {
154+
throw new InvalidParamException("value",
155+
val.toString(),
156+
getPropertyName(), ac);
157+
}
158+
}
159+
// it must be a color instead
160+
try {
161+
c = new org.w3c.css.values.CssColor(ac, val.getIdent().toString());
162+
} catch (InvalidParamException e) {
163+
// we recreate the exception, as it will have
164+
// the wrong property name otherwise
165+
throw new InvalidParamException("value",
166+
expression.getValue(),
167+
getPropertyName(), ac);
168+
}
169+
values.add(val);
170+
break;
171+
case CssTypes.CSS_FUNCTION:
172+
try {
173+
tcolor = new CssColor(ac, expression, check);
174+
value = val;
175+
break;
176+
} catch (InvalidParamException e) {
177+
// we recreate the exception, as it will have
178+
// the wrong property name otherwise
179+
throw new InvalidParamException("value",
180+
expression.getValue(),
181+
getPropertyName(), ac);
182+
}
183+
case CssTypes.CSS_HASH_IDENT:
184+
c = new org.w3c.css.values.CssColor();
185+
c.setShortRGBColor(ac, val.getHashIdent().toString());
186+
values.add(val);
187+
break;
188+
case CssTypes.CSS_COLOR:
189+
values.add(val);
190+
break;
191+
default:
192+
throw new InvalidParamException("value",
193+
val.toString(),
194+
getPropertyName(), ac);
195+
}
196+
expression.next();
197+
} else {
198+
if (values.size() != 0) {
199+
// we got ony one color
200+
throw new InvalidParamException("unrecognize", ac);
201+
}
202+
}
203+
if (values.size() > 0) {
204+
value = new CssValueList(values);
205+
}
206+
}
207+
208+
public CssScrollbarColor(ApplContext ac, CssExpression expression)
209+
throws InvalidParamException {
210+
this(ac, expression, false);
211+
}
212+
}
213+

0 commit comments

Comments
 (0)