Skip to content

Commit 18d98ae

Browse files
committed
1 parent a2b9ba5 commit 18d98ae

File tree

4 files changed

+222
-0
lines changed

4 files changed

+222
-0
lines changed

org/w3c/css/properties/CSS3Properties.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ scroll-margin-top: org.w3c.css.properties.css3.CssScrollMar
143143
scroll-snap-stop: org.w3c.css.properties.css3.CssScrollSnapStop
144144
scroll-snap-type: org.w3c.css.properties.css3.CssScrollSnapType
145145

146+
#scrollbar
147+
scrollbar-width: org.w3c.css.properties.css3.CssScrollbarWidth
148+
146149
# grid
147150
grid: org.w3c.css.properties.css3.CssGrid
148151
grid-area: org.w3c.css.properties.css3.CssGridArea
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 CssScrollbarWidth extends CssProperty {
19+
20+
public CssValue value;
21+
22+
/**
23+
* Create a new CssScrollbarWidth
24+
*/
25+
public CssScrollbarWidth() {
26+
}
27+
28+
/**
29+
* Creates a new CssScrollbarWidth
30+
*
31+
* @param expression The expression for this property
32+
* @throws InvalidParamException
33+
* Expressions are incorrect
34+
*/
35+
public CssScrollbarWidth(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 CssScrollbarWidth(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-width";
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.cssScrollbarWidth != null) {
85+
style.addRedefinitionWarning(ac, this);
86+
}
87+
s.cssScrollbarWidth = 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 CssScrollbarWidth &&
98+
value.equals(((CssScrollbarWidth) 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).getScrollbarWidth();
111+
} else {
112+
return ((Css3Style) style).cssScrollbarWidth;
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.CssScrollbarWidth;
235236
import org.w3c.css.properties.css.CssSpeakAs;
236237
import org.w3c.css.properties.css.CssTabSize;
237238
import org.w3c.css.properties.css.CssTextAlignAll;
@@ -623,7 +624,17 @@ public class Css3Style extends ATSCStyle {
623624
public CssTextDecorationSkipInset cssTextDecorationSkipInset;
624625
public CssTextDecorationSkipInk cssTextDecorationSkipInk;
625626
public CssTextDecorationSkipSpaces cssTextDecorationSkipSpaces;
627+
public CssScrollbarWidth cssScrollbarWidth;
626628

629+
public CssScrollbarWidth getScrollbarWidth() {
630+
if (cssScrollbarWidth == null) {
631+
cssScrollbarWidth =
632+
(CssScrollbarWidth) style.CascadingOrder(new CssScrollbarWidth(),
633+
style, selector);
634+
}
635+
return cssScrollbarWidth;
636+
}
637+
627638
public CssTextDecorationSkipSpaces getTextDecorationSkipSpaces() {
628639
if (cssTextDecorationSkipSpaces == null) {
629640
cssTextDecorationSkipSpaces =
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
15+
/**
16+
* @spec https://www.w3.org/TR/2021/WD-css-scrollbars-1-20210829/#propdef-scrollbar-width
17+
*/
18+
public class CssScrollbarWidth extends org.w3c.css.properties.css.CssScrollbarWidth {
19+
20+
public static final CssIdent[] allowed_values;
21+
22+
static {
23+
String[] _allowed_values = {"auto", "thin", "none"};
24+
allowed_values = new CssIdent[_allowed_values.length];
25+
int i = 0;
26+
for (String s : _allowed_values) {
27+
allowed_values[i++] = CssIdent.getIdent(s);
28+
}
29+
}
30+
31+
public static CssIdent getAllowedIdent(CssIdent ident) {
32+
for (CssIdent id : allowed_values) {
33+
if (id.equals(ident)) {
34+
return id;
35+
}
36+
}
37+
return null;
38+
}
39+
40+
/**
41+
* Create a new CssScrollbarWidth
42+
*/
43+
public CssScrollbarWidth() {
44+
value = initial;
45+
}
46+
47+
/**
48+
* Creates a new CssScrollbarWidth
49+
*
50+
* @param expression The expression for this property
51+
* @throws InvalidParamException Expressions are incorrect
52+
*/
53+
public CssScrollbarWidth(ApplContext ac, CssExpression expression, boolean check)
54+
throws InvalidParamException {
55+
if (check && expression.getCount() > 1) {
56+
throw new InvalidParamException("unrecognize", ac);
57+
}
58+
59+
setByUser();
60+
61+
CssValue val;
62+
char op;
63+
64+
val = expression.getValue();
65+
op = expression.getOperator();
66+
67+
switch (val.getType()) {
68+
case CssTypes.CSS_IDENT:
69+
if (inherit.equals(val)) {
70+
value = val;
71+
break;
72+
} else {
73+
CssIdent ident = getAllowedIdent(val.getIdent());
74+
if (ident != null) {
75+
value = val;
76+
break;
77+
}
78+
}
79+
// let it fail
80+
default:
81+
throw new InvalidParamException("value",
82+
val.toString(),
83+
getPropertyName(), ac);
84+
}
85+
expression.next();
86+
}
87+
88+
public CssScrollbarWidth(ApplContext ac, CssExpression expression)
89+
throws InvalidParamException {
90+
this(ac, expression, false);
91+
}
92+
}
93+

0 commit comments

Comments
 (0)