diff --git a/org/w3c/css/properties/CSS3Properties.properties b/org/w3c/css/properties/CSS3Properties.properties index 0ef33ed2d..1bb8bc85f 100644 --- a/org/w3c/css/properties/CSS3Properties.properties +++ b/org/w3c/css/properties/CSS3Properties.properties @@ -143,6 +143,10 @@ scroll-margin-top: org.w3c.css.properties.css3.CssScrollMar scroll-snap-stop: org.w3c.css.properties.css3.CssScrollSnapStop scroll-snap-type: org.w3c.css.properties.css3.CssScrollSnapType +#scrollbar +scrollbar-color: org.w3c.css.properties.css3.CssScrollbarColor +scrollbar-width: org.w3c.css.properties.css3.CssScrollbarWidth + # grid grid: org.w3c.css.properties.css3.CssGrid grid-area: org.w3c.css.properties.css3.CssGridArea diff --git a/org/w3c/css/properties/css/CssScrollbarColor.java b/org/w3c/css/properties/css/CssScrollbarColor.java new file mode 100644 index 000000000..d804e1dfb --- /dev/null +++ b/org/w3c/css/properties/css/CssScrollbarColor.java @@ -0,0 +1,115 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2021. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css; + +import org.w3c.css.parser.CssStyle; +import org.w3c.css.properties.css3.Css3Style; +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssExpression; +import org.w3c.css.values.CssValue; + +/** + * @since CSS3 + */ +public class CssScrollbarColor extends CssProperty { + + public CssValue value; + + /** + * Create a new CssScrollbarColor + */ + public CssScrollbarColor() { + } + + /** + * Creates a new CssScrollbarColor + * + * @param expression The expression for this property + * @throws InvalidParamException + * Expressions are incorrect + */ + public CssScrollbarColor(ApplContext ac, CssExpression expression, // + boolean check) throws InvalidParamException { + throw new InvalidParamException("value", + expression.getValue().toString(), + getPropertyName(), ac); + } + + public CssScrollbarColor(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } + + /** + * Returns the value of this property + */ + public Object get() { + return value; + } + + + /** + * Returns the name of this property + */ + public final String getPropertyName() { + return "scrollbar-color"; + } + + /** + * Returns true if this property is "softly" inherited + * e.g. his value is equals to inherit + */ + public boolean isSoftlyInherited() { + return value.equals(inherit); + } + + /** + * Returns a string representation of the object. + */ + public String toString() { + return value.toString(); + } + + /** + * Add this property to the CssStyle. + * + * @param style The CssStyle + */ + public void addToStyle(ApplContext ac, CssStyle style) { + Css3Style s = (Css3Style) style; + if (s.cssScrollbarColor != null) { + style.addRedefinitionWarning(ac, this); + } + s.cssScrollbarColor = this; + } + + + /** + * Compares two properties for equality. + * + * @param property The other property. + */ + public boolean equals(CssProperty property) { + return (property instanceof CssScrollbarColor && + value.equals(((CssScrollbarColor) property).value)); + } + + + /** + * Get this property in the style. + * + * @param style The style where the property is + * @param resolve if true, resolve the style to find this property + */ + public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { + if (resolve) { + return ((Css3Style) style).getScrollbarColor(); + } else { + return ((Css3Style) style).cssScrollbarColor; + } + } +} diff --git a/org/w3c/css/properties/css/CssScrollbarWidth.java b/org/w3c/css/properties/css/CssScrollbarWidth.java new file mode 100644 index 000000000..f9ffa0a7d --- /dev/null +++ b/org/w3c/css/properties/css/CssScrollbarWidth.java @@ -0,0 +1,115 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2021. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css; + +import org.w3c.css.parser.CssStyle; +import org.w3c.css.properties.css3.Css3Style; +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssExpression; +import org.w3c.css.values.CssValue; + +/** + * @since CSS3 + */ +public class CssScrollbarWidth extends CssProperty { + + public CssValue value; + + /** + * Create a new CssScrollbarWidth + */ + public CssScrollbarWidth() { + } + + /** + * Creates a new CssScrollbarWidth + * + * @param expression The expression for this property + * @throws InvalidParamException + * Expressions are incorrect + */ + public CssScrollbarWidth(ApplContext ac, CssExpression expression, // + boolean check) throws InvalidParamException { + throw new InvalidParamException("value", + expression.getValue().toString(), + getPropertyName(), ac); + } + + public CssScrollbarWidth(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } + + /** + * Returns the value of this property + */ + public Object get() { + return value; + } + + + /** + * Returns the name of this property + */ + public final String getPropertyName() { + return "scrollbar-width"; + } + + /** + * Returns true if this property is "softly" inherited + * e.g. his value is equals to inherit + */ + public boolean isSoftlyInherited() { + return value.equals(inherit); + } + + /** + * Returns a string representation of the object. + */ + public String toString() { + return value.toString(); + } + + /** + * Add this property to the CssStyle. + * + * @param style The CssStyle + */ + public void addToStyle(ApplContext ac, CssStyle style) { + Css3Style s = (Css3Style) style; + if (s.cssScrollbarWidth != null) { + style.addRedefinitionWarning(ac, this); + } + s.cssScrollbarWidth = this; + } + + + /** + * Compares two properties for equality. + * + * @param property The other property. + */ + public boolean equals(CssProperty property) { + return (property instanceof CssScrollbarWidth && + value.equals(((CssScrollbarWidth) property).value)); + } + + + /** + * Get this property in the style. + * + * @param style The style where the property is + * @param resolve if true, resolve the style to find this property + */ + public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { + if (resolve) { + return ((Css3Style) style).getScrollbarWidth(); + } else { + return ((Css3Style) style).cssScrollbarWidth; + } + } +} diff --git a/org/w3c/css/properties/css3/Css3Style.java b/org/w3c/css/properties/css3/Css3Style.java index 8f427aa75..f567806a7 100644 --- a/org/w3c/css/properties/css3/Css3Style.java +++ b/org/w3c/css/properties/css3/Css3Style.java @@ -232,6 +232,8 @@ import org.w3c.css.properties.css.CssScrollSnapAlign; import org.w3c.css.properties.css.CssScrollSnapStop; import org.w3c.css.properties.css.CssScrollSnapType; +import org.w3c.css.properties.css.CssScrollbarColor; +import org.w3c.css.properties.css.CssScrollbarWidth; import org.w3c.css.properties.css.CssSpeakAs; import org.w3c.css.properties.css.CssTabSize; import org.w3c.css.properties.css.CssTextAlignAll; @@ -623,7 +625,27 @@ public class Css3Style extends ATSCStyle { public CssTextDecorationSkipInset cssTextDecorationSkipInset; public CssTextDecorationSkipInk cssTextDecorationSkipInk; public CssTextDecorationSkipSpaces cssTextDecorationSkipSpaces; + public CssScrollbarWidth cssScrollbarWidth; + public CssScrollbarColor cssScrollbarColor; + public CssScrollbarColor getScrollbarColor() { + if (cssScrollbarColor == null) { + cssScrollbarColor = + (CssScrollbarColor) style.CascadingOrder(new CssScrollbarColor(), + style, selector); + } + return cssScrollbarColor; + } + + public CssScrollbarWidth getScrollbarWidth() { + if (cssScrollbarWidth == null) { + cssScrollbarWidth = + (CssScrollbarWidth) style.CascadingOrder(new CssScrollbarWidth(), + style, selector); + } + return cssScrollbarWidth; + } + public CssTextDecorationSkipSpaces getTextDecorationSkipSpaces() { if (cssTextDecorationSkipSpaces == null) { cssTextDecorationSkipSpaces = diff --git a/org/w3c/css/properties/css3/CssScrollbarColor.java b/org/w3c/css/properties/css3/CssScrollbarColor.java new file mode 100644 index 000000000..8f7f645c3 --- /dev/null +++ b/org/w3c/css/properties/css3/CssScrollbarColor.java @@ -0,0 +1,213 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2021. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css3; + +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssExpression; +import org.w3c.css.values.CssIdent; +import org.w3c.css.values.CssTypes; +import org.w3c.css.values.CssValue; +import org.w3c.css.values.CssValueList; + +import java.util.ArrayList; + +import static org.w3c.css.values.CssOperator.SPACE; + +/** + * @spec https://www.w3.org/TR/2021/WD-css-scrollbars-1-20210829/#propdef-scrollbar-color + */ +public class CssScrollbarColor extends org.w3c.css.properties.css.CssScrollbarColor { + + public static final CssIdent[] allowed_values; + + static { + String[] _allowed_values = {"auto"}; + allowed_values = new CssIdent[_allowed_values.length]; + int i = 0; + for (String s : _allowed_values) { + allowed_values[i++] = CssIdent.getIdent(s); + } + } + + public static CssIdent getAllowedIdent(CssIdent ident) { + for (CssIdent id : allowed_values) { + if (id.equals(ident)) { + return id; + } + } + return null; + } + + /** + * Create a new CssScrollbarColor + */ + public CssScrollbarColor() { + value = initial; + } + + /** + * Creates a new CssScrollbarColor + * + * @param expression The expression for this property + * @throws InvalidParamException Expressions are incorrect + */ + public CssScrollbarColor(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + if (check && expression.getCount() > 2) { + throw new InvalidParamException("unrecognize", ac); + } + + setByUser(); + + CssValue val; + org.w3c.css.values.CssColor c; + CssColor tcolor; + char op; + + val = expression.getValue(); + op = expression.getOperator(); + ArrayList values = new ArrayList<>(); + + switch (val.getType()) { + case CssTypes.CSS_IDENT: + if (inherit.equals(val)) { + if (expression.getCount() != 1) { + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + value = val; + break; + } else { + CssIdent ident = getAllowedIdent(val.getIdent()); + // auto can be there once + if (ident != null) { + if (expression.getCount() != 1) { + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + value = val; + break; + } + } + // it must be a color instead + try { + c = new org.w3c.css.values.CssColor(ac, val.getIdent().toString()); + } catch (InvalidParamException e) { + // we recreate the exception, as it will have + // the wrong property name otherwise + throw new InvalidParamException("value", + expression.getValue(), + getPropertyName(), ac); + } + values.add(val); + break; + case CssTypes.CSS_FUNCTION: + try { + tcolor = new CssColor(ac, expression, check); + value = val; + break; + } catch (InvalidParamException e) { + // we recreate the exception, as it will have + // the wrong property name otherwise + throw new InvalidParamException("value", + expression.getValue(), + getPropertyName(), ac); + } + case CssTypes.CSS_HASH_IDENT: + c = new org.w3c.css.values.CssColor(); + c.setShortRGBColor(ac, val.getHashIdent().toString()); + values.add(val); + break; + case CssTypes.CSS_COLOR: + values.add(val); + break; + default: + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + expression.next(); + + if (!expression.end()) { + // second value + if (op != SPACE) { + throw new InvalidParamException("operator", + Character.toString(op), ac); + } + val = expression.getValue(); + switch (val.getType()) { + case CssTypes.CSS_IDENT: + if (inherit.equals(val)) { + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } else { + CssIdent ident = getAllowedIdent(val.getIdent()); + // auto can be there first (and alone) + if (ident != null) { + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + } + // it must be a color instead + try { + c = new org.w3c.css.values.CssColor(ac, val.getIdent().toString()); + } catch (InvalidParamException e) { + // we recreate the exception, as it will have + // the wrong property name otherwise + throw new InvalidParamException("value", + expression.getValue(), + getPropertyName(), ac); + } + values.add(val); + break; + case CssTypes.CSS_FUNCTION: + try { + tcolor = new CssColor(ac, expression, check); + value = val; + break; + } catch (InvalidParamException e) { + // we recreate the exception, as it will have + // the wrong property name otherwise + throw new InvalidParamException("value", + expression.getValue(), + getPropertyName(), ac); + } + case CssTypes.CSS_HASH_IDENT: + c = new org.w3c.css.values.CssColor(); + c.setShortRGBColor(ac, val.getHashIdent().toString()); + values.add(val); + break; + case CssTypes.CSS_COLOR: + values.add(val); + break; + default: + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + expression.next(); + } else { + if (values.size() != 0) { + // we got ony one color + throw new InvalidParamException("unrecognize", ac); + } + } + if (values.size() > 0) { + value = new CssValueList(values); + } + } + + public CssScrollbarColor(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } +} + diff --git a/org/w3c/css/properties/css3/CssScrollbarWidth.java b/org/w3c/css/properties/css3/CssScrollbarWidth.java new file mode 100644 index 000000000..d4d0e9384 --- /dev/null +++ b/org/w3c/css/properties/css3/CssScrollbarWidth.java @@ -0,0 +1,93 @@ +// +// Author: Yves Lafon +// +// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2021. +// Please first read the full copyright statement in file COPYRIGHT.html +package org.w3c.css.properties.css3; + +import org.w3c.css.util.ApplContext; +import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssExpression; +import org.w3c.css.values.CssIdent; +import org.w3c.css.values.CssTypes; +import org.w3c.css.values.CssValue; + +/** + * @spec https://www.w3.org/TR/2021/WD-css-scrollbars-1-20210829/#propdef-scrollbar-width + */ +public class CssScrollbarWidth extends org.w3c.css.properties.css.CssScrollbarWidth { + + public static final CssIdent[] allowed_values; + + static { + String[] _allowed_values = {"auto", "thin", "none"}; + allowed_values = new CssIdent[_allowed_values.length]; + int i = 0; + for (String s : _allowed_values) { + allowed_values[i++] = CssIdent.getIdent(s); + } + } + + public static CssIdent getAllowedIdent(CssIdent ident) { + for (CssIdent id : allowed_values) { + if (id.equals(ident)) { + return id; + } + } + return null; + } + + /** + * Create a new CssScrollbarWidth + */ + public CssScrollbarWidth() { + value = initial; + } + + /** + * Creates a new CssScrollbarWidth + * + * @param expression The expression for this property + * @throws InvalidParamException Expressions are incorrect + */ + public CssScrollbarWidth(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { + if (check && expression.getCount() > 1) { + throw new InvalidParamException("unrecognize", ac); + } + + setByUser(); + + CssValue val; + char op; + + val = expression.getValue(); + op = expression.getOperator(); + + switch (val.getType()) { + case CssTypes.CSS_IDENT: + if (inherit.equals(val)) { + value = val; + break; + } else { + CssIdent ident = getAllowedIdent(val.getIdent()); + if (ident != null) { + value = val; + break; + } + } + // let it fail + default: + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + expression.next(); + } + + public CssScrollbarWidth(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } +} +