diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2ColorHelper.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2ColorHelper.java index b0e9b930184..038175f671b 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2ColorHelper.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2ColorHelper.java @@ -16,8 +16,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.RGBColor; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssColor; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumber; /** * CSS2 Color Helper. @@ -38,20 +38,21 @@ public class CSS2ColorHelper { private static Map colorHexasMap = new HashMap<>(); /** - * Return w3c {@link RGBColor} from string value. Format String value is + * Return a {@link CssColor} from string value. Format String value is * hexadecimal like #FFFFFF or color name like white. * * @param value string representation of color * @return parsed color */ - public static RGBColor getRGBColor(String value) { + public static CssColor getRGBColor(String value) { if (value.startsWith("#") && value.length() == 7) { // Color is like #FFFFFF try { int redValue = Integer.decode("0x" + value.substring(1, 3)).intValue(); int greenValue = Integer.decode("0x" + value.substring(3, 5)).intValue(); int blueValue = Integer.decode("0x" + value.substring(5)).intValue(); - return new CSS2RGBColorImpl(redValue, greenValue, blueValue); + return new CssColor(new CssNumber(redValue, true), new CssNumber(greenValue, true), + new CssNumber(blueValue, true)); } catch (Exception e) { return null; } @@ -66,61 +67,53 @@ public static RGBColor getRGBColor(String value) { } /** - * Return the hex string representation of the given w3c {@code rgbColor}. + * Return the hex string representation of the given color. * - * @param rgbColor the color to get a string representation for - * @return the hex string representation of {@code rgbColor} + * @param color the color to get a string representation for + * @return the hex string representation of {@code color} */ - public static String getColorStringValue(RGBColor rgbColor) { - return getHexaColorStringValue(rgbColor); + public static String getColorStringValue(CssColor color) { + return getHexaColorStringValue(color); } /** - * Return rgb (ex : rgb(0,0,0)) color string value from w3c - * rgbColor instance. + * Return rgb (ex : rgb(0,0,0)) color string value from the given + * color. * - * @param rgbColor the color to get string representation for - * @return rgbColor as rgb(r, g, b) string + * @param color the color to get string representation for + * @return color as rgb(r, g, b) string */ - public static String getRGBColorStringValue(RGBColor rgbColor) { + public static String getRGBColorStringValue(CssColor color) { StringBuilder result = new StringBuilder("rgb("); - int red = (int) rgbColor.getRed().getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - result.append(red); + result.append((int) color.red().value()); result.append(","); - int green = (int) rgbColor.getGreen().getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - result.append(green); + result.append((int) color.green().value()); result.append(","); - int blue = (int) rgbColor.getBlue().getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - result.append(blue); + result.append((int) color.blue().value()); result.append(")"); return result.toString(); } /** - * Return hexadecimal (ex : #FFFFFF) color string value from w3c - * rgbColor instance. + * Return hexadecimal (ex : #FFFFFF) color string value from the given + * color. * - * @param rgbColor the color to get string representation for - * @return rgbColor as hexa string + * @param color the color to get string representation for + * @return color as hexa string */ - public static String getHexaColorStringValue(RGBColor rgbColor) { + public static String getHexaColorStringValue(CssColor color) { StringBuilder result = new StringBuilder("#"); - int red = (int) rgbColor.getRed().getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - if (red < 16) { - result.append("0"); - } - result.append(Integer.toHexString(red)); - int green = (int) rgbColor.getGreen().getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - if (green < 16) { - result.append("0"); - } - result.append(Integer.toHexString(green)); - int blue = (int) rgbColor.getBlue().getFloatValue(CSSPrimitiveValue.CSS_NUMBER); - if (blue < 16) { + appendHexPair(result, (int) color.red().value()); + appendHexPair(result, (int) color.green().value()); + appendHexPair(result, (int) color.blue().value()); + return result.toString(); + } + + private static void appendHexPair(StringBuilder result, int component) { + if (component < 16) { result.append("0"); } - result.append(Integer.toHexString(blue)); - return result.toString(); + result.append(Integer.toHexString(component)); } /** diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2FontHelper.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2FontHelper.java index 6c366983f3c..ad121aeeaeb 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2FontHelper.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2FontHelper.java @@ -13,7 +13,10 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.core.css2; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssUnit; /** * CSS2 Font Helper. @@ -65,14 +68,11 @@ public static String getFontWeight(boolean isBold) { /** * Return the CSS Font Property name (font-style, font-weight, font-size, - * font-family) switch the {@link CSSPrimitiveValue} value. + * font-family) for the given value. */ - public static String getCSSFontPropertyName(CSSPrimitiveValue value) { - short type = value.getPrimitiveType(); - switch (type) { - case CSSPrimitiveValue.CSS_STRING: - case CSSPrimitiveValue.CSS_IDENT: - switch (value.getStringValue()) { + public static String getCSSFontPropertyName(CssPrimitive value) { + if (value instanceof CssText text && (text.kind() == CssText.Kind.STRING || text.kind() == CssText.Kind.IDENT)) { + switch (text.value()) { case "italic": case "oblique": return "font-style"; @@ -83,9 +83,9 @@ public static String getCSSFontPropertyName(CSSPrimitiveValue value) { default: return "font-family"; } - case CSSPrimitiveValue.CSS_PT: - case CSSPrimitiveValue.CSS_NUMBER: - case CSSPrimitiveValue.CSS_PX: + } + if (value instanceof CssNumeric numeric + && (numeric.unit() == CssUnit.PT || numeric.unit() == CssUnit.NUMBER || numeric.unit() == CssUnit.PX)) { return "font-size"; } return null; diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2FontPropertiesHelpers.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2FontPropertiesHelpers.java index 367694c3f90..a521a65f6ea 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2FontPropertiesHelpers.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2FontPropertiesHelpers.java @@ -16,9 +16,9 @@ import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties; import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontPropertiesImpl; import org.eclipse.e4.ui.css.core.engine.CSSElementContext; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; /** * @@ -90,19 +90,15 @@ public static void updateCSSPropertyFont(CSS2FontProperties fontProperties, Stri /** * Update fontProperties instance with the {@link CSSValue} - * value. value can be {@link CSSPrimitiveValue} or - * {@link CSSValueList}. + * value. value can be a single value or a value list. */ public static void updateCSSPropertyFontComposite(CSS2FontProperties font, CSSValue value) { - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - CSSValueList valueList = (CSSValueList) value; - int length = valueList.getLength(); - for (int i = 0; i < length; i++) { - CSSValue value2 = valueList.item(i); - updateCSSPropertyFontComposite(font, value2); + if (value instanceof CssList list) { + for (CSSValue item : list.values()) { + updateCSSPropertyFontComposite(font, item); } - } else if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - String property = CSS2FontHelper.getCSSFontPropertyName((CSSPrimitiveValue) value); + } else if (value instanceof CssPrimitive primitive) { + String property = CSS2FontHelper.getCSSFontPropertyName(primitive); updateCSSPropertyFont(font, property, value); } } @@ -111,8 +107,8 @@ public static void updateCSSPropertyFontComposite(CSS2FontProperties font, CSSVa * Update CSS2FontProperties instance with font-family. */ public static void updateCSSPropertyFontFamily(CSS2FontProperties font, CSSValue value) { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - font.setFamily((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + font.setFamily(primitive); } } @@ -120,8 +116,9 @@ public static void updateCSSPropertyFontFamily(CSS2FontProperties font, CSSValue * Update CSS2FontProperties instance with font-size. */ public static void updateCSSPropertyFontSize(CSS2FontProperties font, CSSValue value) { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - font.setSize((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + font.setSize(primitive); + font.setSizeFromCSS(true); } } @@ -129,8 +126,8 @@ public static void updateCSSPropertyFontSize(CSS2FontProperties font, CSSValue v * Update CSS2FontProperties instance with font-style. */ public static void updateCSSPropertyFontStyle(CSS2FontProperties font, CSSValue value) { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - font.setStyle((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + font.setStyle(primitive); } } @@ -138,8 +135,8 @@ public static void updateCSSPropertyFontStyle(CSS2FontProperties font, CSSValue * Update CSS2FontProperties instance with font-weight. */ public static void updateCSSPropertyFontWeight(CSS2FontProperties font, CSSValue value) { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - font.setWeight((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + font.setWeight(primitive); } } } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2PrimitiveValueImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2PrimitiveValueImpl.java deleted file mode 100644 index dda63d73d94..00000000000 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2PrimitiveValueImpl.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2014 Angelo Zerr and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - *******************************************************************************/ -package org.eclipse.e4.ui.css.core.css2; - -import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.Counter; -import org.w3c.dom.css.RGBColor; -import org.w3c.dom.css.Rect; - -/** - * Simple {@link CSSPrimitiveValue} implementation. - * - * @version 1.0.0 - * @author Angelo ZERR - */ -public class CSS2PrimitiveValueImpl implements CSSPrimitiveValue { - - private String s = null; - - private float v = -9999; - - private int i = -9999; - - private final short primitiveType; - - public CSS2PrimitiveValueImpl(String s) { - this.s = s; - this.primitiveType = CSSPrimitiveValue.CSS_IDENT; - } - - public CSS2PrimitiveValueImpl(float v) { - this.v = v; - this.primitiveType = CSSPrimitiveValue.CSS_NUMBER; - } - - public CSS2PrimitiveValueImpl(int i) { - this.i = i; - this.primitiveType = CSSPrimitiveValue.CSS_NUMBER; - } - - @Override - public Counter getCounterValue() throws DOMException { - return null; - } - - @Override - public float getFloatValue(short word0) throws DOMException { - if (v != -9999) { - return v; - } - return i; - } - - @Override - public short getPrimitiveType() { - return primitiveType; - } - - @Override - public Rect getRectValue() throws DOMException { - // TODO Auto-generated method stub - return null; - } - - @Override - public RGBColor getRGBColorValue() throws DOMException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getStringValue() throws DOMException { - return s; - } - - @Override - public void setFloatValue(short word0, float f) throws DOMException { - // TODO Auto-generated method stub - - } - - @Override - public void setStringValue(short word0, String s) throws DOMException { - // TODO Auto-generated method stub - - } - - @Override - public String getCssText() { - // TODO Auto-generated method stub - return null; - } - - @Override - public short getCssValueType() { - return CSSValue.CSS_PRIMITIVE_VALUE; - } - - @Override - public void setCssText(String s) throws DOMException { - // TODO Auto-generated method stub - - } - - @Override - public String toString() { - if (s != null) { - return s; - } - if (v != -9999) { - return Float.toString(v); - } - if (i != -9999) { - return Integer.toString(i); - } - return super.toString(); - } -} diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2RGBColorImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2RGBColorImpl.java deleted file mode 100644 index 55814dba76b..00000000000 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2RGBColorImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2014 Angelo Zerr and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - *******************************************************************************/ -package org.eclipse.e4.ui.css.core.css2; - -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.RGBColor; - -/** - * Simple {@link RGBColor} implementation. - * - * @version 1.0.0 - * @author Angelo ZERR - */ -public class CSS2RGBColorImpl implements RGBColor { - - private final CSSPrimitiveValue red; - private final CSSPrimitiveValue green; - private final CSSPrimitiveValue blue; - - public CSS2RGBColorImpl(int r, int g, int b) { - red = new CSS2PrimitiveValueImpl(r); - green = new CSS2PrimitiveValueImpl(g); - blue = new CSS2PrimitiveValueImpl(b); - } - - @Override - public CSSPrimitiveValue getBlue() { - return blue; - } - - @Override - public CSSPrimitiveValue getGreen() { - return green; - } - - @Override - public CSSPrimitiveValue getRed() { - return red; - } - -} diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSSBorderPropertiesHelpers.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSSBorderPropertiesHelpers.java index c1715caa265..9f6027772c0 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSSBorderPropertiesHelpers.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSSBorderPropertiesHelpers.java @@ -14,7 +14,9 @@ package org.eclipse.e4.ui.css.core.css2; import org.eclipse.e4.ui.css.core.dom.properties.CSSBorderProperties; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.w3c.dom.css.CSSValue; /** @@ -50,8 +52,8 @@ public static void updateCSSProperty(CSSBorderProperties borderProperties, Strin * value. */ public static void updateCSSPropertyBorderStyle(CSSBorderProperties borderProperties, CSSValue value) { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - borderProperties.setStyle(((CSSPrimitiveValue) value).getStringValue()); + if (value instanceof CssText text) { + borderProperties.setStyle(text.value()); } } @@ -60,8 +62,8 @@ public static void updateCSSPropertyBorderStyle(CSSBorderProperties borderProper * value. */ public static void updateCSSPropertyBorderColor(CSSBorderProperties borderProperties, CSSValue value) { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - borderProperties.setColor((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + borderProperties.setColor(primitive); } } @@ -70,8 +72,8 @@ public static void updateCSSPropertyBorderColor(CSSBorderProperties borderProper * value. */ public static void updateCSSPropertyBorderWidth(CSSBorderProperties borderProperties, CSSValue value) { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - borderProperties.setWidth((int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PT)); + if (value instanceof CssNumeric numeric) { + borderProperties.setWidth((int) numeric.value()); } } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedCSSRule.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedCSSRule.java deleted file mode 100644 index 1d50bb853ed..00000000000 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedCSSRule.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2026 Angelo Zerr and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - *******************************************************************************/ -package org.eclipse.e4.ui.css.core.dom; - -import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors; -import org.w3c.dom.css.CSSRule; - -/** - * Extend {@link CSSRule} to get selector and property list. - */ -public interface ExtendedCSSRule extends CSSRule { - - /** - * Return the list of {@link CSSProperty} of this {@link CSSRule}. - */ - public CSSPropertyList getCSSPropertyList(); - - /** - * Return the list of selectors of this {@link CSSRule}. - */ - public Selectors.SelectorList getSelectorList(); -} diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedDocumentCSS.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedDocumentCSS.java deleted file mode 100644 index d3d7bc717d1..00000000000 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedDocumentCSS.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2026 Angelo Zerr and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - * Karsten Thoms - Bug 532869 - *******************************************************************************/ -package org.eclipse.e4.ui.css.core.dom; - -import java.util.EventListener; -import org.w3c.dom.css.DocumentCSS; -import org.w3c.dom.stylesheets.StyleSheet; - -/** - * Extend {@link DocumentCSS} to add methods like add/remove style sheet. - */ -public interface ExtendedDocumentCSS extends DocumentCSS { - - public void addStyleSheet(StyleSheet styleSheet); - - public void removeAllStyleSheets(); - - /** - * @since 0.12.200 - */ - interface StyleSheetChangeListener extends EventListener { - void styleSheetAdded(StyleSheet styleSheet); - - void styleSheetRemoved(StyleSheet styleSheet); - } - - /** - * @since 0.12.200 - */ - default void addStyleSheetChangeListener(StyleSheetChangeListener listener) { - } - - /** - * @since 0.12.200 - */ - default void removeStyleSheetChangeListener(StyleSheetChangeListener listener) { - } -} diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/AbstractCSSPropertyCompositeHandler.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/AbstractCSSPropertyCompositeHandler.java index 725d2edb934..d720d040bc3 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/AbstractCSSPropertyCompositeHandler.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/AbstractCSSPropertyCompositeHandler.java @@ -14,8 +14,8 @@ package org.eclipse.e4.ui.css.core.dom.properties; import org.eclipse.e4.ui.css.core.engine.CSSEngine; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; /** * Abstract class which manage CSS Property composite like border:solid black @@ -33,12 +33,9 @@ public abstract class AbstractCSSPropertyCompositeHandler implements */ public void applyCSSPropertyComposite(Object element, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - CSSValueList valueList = (CSSValueList) value; - int length = valueList.getLength(); - for (int i = 0; i < length; i++) { - CSSValue value2 = valueList.item(i); - applyCSSProperty(element, value2, pseudo, engine); + if (value instanceof CssList valueList) { + for (CSSValue item : valueList.values()) { + applyCSSProperty(element, item, pseudo, engine); } } else { applyCSSProperty(element, value, pseudo, engine); diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/CSSBorderProperties.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/CSSBorderProperties.java index 1ac9e60c878..8ec497c7b2e 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/CSSBorderProperties.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/CSSBorderProperties.java @@ -13,7 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.core.dom.properties; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; /** * CSS Border properties interface. @@ -26,12 +26,12 @@ public interface CSSBorderProperties { /** * Return border-color value. */ - public CSSPrimitiveValue getColor(); + public CssPrimitive getColor(); /** * Set border-color value. */ - public void setColor(CSSPrimitiveValue color); + public void setColor(CssPrimitive color); /** * Return border-width value. diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/Gradient.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/Gradient.java index f4a9162f182..84360f8fedc 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/Gradient.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/Gradient.java @@ -17,7 +17,7 @@ import java.util.ArrayList; import java.util.List; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; /** * Generic class to store informations to manage Gradient color. @@ -28,7 +28,7 @@ public class Gradient { private final List percents = new ArrayList<>(2); //TODO see bug #278077 - private final List values = new ArrayList<>(2); + private final List values = new ArrayList<>(2); private boolean isLinear = true; @@ -49,7 +49,7 @@ public boolean isRadial() { } //TODO see bug #278077 - public void addRGB(Object rgb, CSSPrimitiveValue value) { + public void addRGB(Object rgb, CssPrimitive value) { rgbs.add(rgb); values.add(value); } @@ -66,7 +66,7 @@ public List getRGBs() { return rgbs; } - public List getValues() { + public List getValues() { return values; } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/converters/CSSValueBooleanConverterImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/converters/CSSValueBooleanConverterImpl.java index 952ab19f21f..81c6451efd5 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/converters/CSSValueBooleanConverterImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/converters/CSSValueBooleanConverterImpl.java @@ -14,7 +14,7 @@ package org.eclipse.e4.ui.css.core.dom.properties.converters; import org.eclipse.e4.ui.css.core.engine.CSSEngine; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.w3c.dom.css.CSSValue; /** @@ -38,11 +38,8 @@ public CSSValueBooleanConverterImpl() { @Override public Object convert(CSSValue value, CSSEngine engine, Object context) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value; - if ("true".equals(primitiveValue.getStringValue())) { - return Boolean.TRUE; - } + if (value instanceof CssText text && "true".equals(text.value())) { + return Boolean.TRUE; } return Boolean.FALSE; } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBackgroundCompositeHandler.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBackgroundCompositeHandler.java index 2e2fe0a2219..d3a9b7093e5 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBackgroundCompositeHandler.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBackgroundCompositeHandler.java @@ -15,7 +15,8 @@ import org.eclipse.e4.ui.css.core.dom.properties.AbstractCSSPropertyCompositeHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssColor; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.w3c.dom.css.CSSValue; /** @@ -35,20 +36,11 @@ public abstract class AbstractCSSPropertyBackgroundCompositeHandler extends @Override public void applyCSSProperty(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value; - short type = primitiveValue.getPrimitiveType(); - switch (type) { - case CSSPrimitiveValue.CSS_IDENT: - case CSSPrimitiveValue.CSS_RGBCOLOR: - engine.applyCSSProperty(element, "background-color", value, - pseudo); - break; - case CSSPrimitiveValue.CSS_URI: - engine.applyCSSProperty(element, "background-image", value, - pseudo); - break; - } + if (value instanceof CssColor + || (value instanceof CssText text && text.kind() == CssText.Kind.IDENT)) { + engine.applyCSSProperty(element, "background-color", value, pseudo); + } else if (value instanceof CssText text && text.kind() == CssText.Kind.URI) { + engine.applyCSSProperty(element, "background-image", value, pseudo); } } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBorderCompositeHandler.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBorderCompositeHandler.java index 085355bea09..96cdd41ed8a 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBorderCompositeHandler.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBorderCompositeHandler.java @@ -16,7 +16,10 @@ import org.eclipse.e4.ui.css.core.css2.CSS2ColorHelper; import org.eclipse.e4.ui.css.core.dom.properties.AbstractCSSPropertyCompositeHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssColor; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssUnit; import org.w3c.dom.css.CSSValue; /** @@ -36,29 +39,17 @@ public abstract class AbstractCSSPropertyBorderCompositeHandler extends @Override public void applyCSSProperty(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value; - short type = primitiveValue.getPrimitiveType(); - switch (type) { - case CSSPrimitiveValue.CSS_IDENT: - if (CSS2ColorHelper - .isColorName(primitiveValue.getStringValue())) { - engine.applyCSSProperty(element, "border-color", value, - pseudo); - } else { - engine.applyCSSProperty(element, "border-style", value, - pseudo); - } - break; - case CSSPrimitiveValue.CSS_RGBCOLOR: + if (value instanceof CssText text && text.kind() == CssText.Kind.IDENT) { + if (CSS2ColorHelper.isColorName(text.value())) { engine.applyCSSProperty(element, "border-color", value, pseudo); - break; - case CSSPrimitiveValue.CSS_PT: - case CSSPrimitiveValue.CSS_NUMBER: - case CSSPrimitiveValue.CSS_PX: - engine.applyCSSProperty(element, "border-width", value, pseudo); - break; + } else { + engine.applyCSSProperty(element, "border-style", value, pseudo); } + } else if (value instanceof CssColor) { + engine.applyCSSProperty(element, "border-color", value, pseudo); + } else if (value instanceof CssNumeric numeric && (numeric.unit() == CssUnit.PT + || numeric.unit() == CssUnit.NUMBER || numeric.unit() == CssUnit.PX)) { + engine.applyCSSProperty(element, "border-width", value, pseudo); } } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBorderHandler.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBorderHandler.java index dce00480fae..153f4052b11 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBorderHandler.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyBorderHandler.java @@ -17,7 +17,9 @@ import org.eclipse.e4.ui.css.core.dom.properties.CSSBorderProperties; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.core.exceptions.UnsupportedPropertyException; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.w3c.dom.css.CSSValue; /** @@ -200,8 +202,8 @@ public void applyCSSPropertyBorderColor(Object element, CSSValue value, public void applyCSSPropertyBorderColor(CSSBorderProperties border, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - border.setColor((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + border.setColor(primitive); } } @@ -266,8 +268,8 @@ public void applyCSSPropertyBorderStyle(Object element, CSSValue value, public void applyCSSPropertyBorderStyle(CSSBorderProperties border, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - border.setStyle(((CSSPrimitiveValue) value).getStringValue()); + if (value instanceof CssText text) { + border.setStyle(text.value()); } } @@ -310,9 +312,8 @@ public void applyCSSPropertyBorderWidth(Object element, CSSValue value, public void applyCSSPropertyBorderWidth(CSSBorderProperties border, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - border.setWidth((int) ((CSSPrimitiveValue) value) - .getFloatValue(CSSPrimitiveValue.CSS_PT)); + if (value instanceof CssNumeric numeric) { + border.setWidth((int) numeric.value()); } } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyFontCompositeHandler.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyFontCompositeHandler.java index 251bc437037..aec19b681a8 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyFontCompositeHandler.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyFontCompositeHandler.java @@ -16,7 +16,7 @@ import org.eclipse.e4.ui.css.core.css2.CSS2FontHelper; import org.eclipse.e4.ui.css.core.dom.properties.AbstractCSSPropertyCompositeHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.w3c.dom.css.CSSValue; /** @@ -36,9 +36,8 @@ public abstract class AbstractCSSPropertyFontCompositeHandler extends @Override public void applyCSSProperty(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - String property = CSS2FontHelper - .getCSSFontPropertyName((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + String property = CSS2FontHelper.getCSSFontPropertyName(primitive); if (property != null) { engine.applyCSSProperty(element, property, value, pseudo); } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyFontHandler.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyFontHandler.java index 5856e82d5a9..202f80c459c 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyFontHandler.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyFontHandler.java @@ -15,7 +15,7 @@ import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.core.exceptions.UnsupportedPropertyException; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.w3c.dom.css.CSSValue; public abstract class AbstractCSSPropertyFontHandler extends @@ -105,8 +105,8 @@ public void applyCSSPropertyFontFamily(Object element, CSSValue value, protected void applyCSSPropertyFontFamily(CSS2FontProperties font, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - font.setFamily((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + font.setFamily(primitive); } } @@ -123,8 +123,9 @@ public void applyCSSPropertyFontSize(Object element, CSSValue value, protected void applyCSSPropertyFontSize(CSS2FontProperties font, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - font.setSize((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + font.setSize(primitive); + font.setSizeFromCSS(true); } } @@ -153,8 +154,8 @@ public void applyCSSPropertyFontStyle(Object element, CSSValue value, protected void applyCSSPropertyFontStyle(CSS2FontProperties font, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - font.setStyle((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + font.setStyle(primitive); } } @@ -177,8 +178,8 @@ public void applyCSSPropertyFontWeight(Object element, CSSValue value, protected void applyCSSPropertyFontWeight(CSS2FontProperties font, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - font.setWeight((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + font.setWeight(primitive); } } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyTextHandler.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyTextHandler.java index 0c6817fc4d7..f16950a6973 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyTextHandler.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/AbstractCSSPropertyTextHandler.java @@ -16,7 +16,7 @@ import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.core.exceptions.UnsupportedPropertyException; import org.eclipse.e4.ui.css.core.utils.StringUtils; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.w3c.dom.css.CSSValue; public abstract class AbstractCSSPropertyTextHandler implements @@ -84,9 +84,8 @@ public String retrieveCSSPropertyTextTransform(Object element, protected String getTextTransform(String text, CSSValue value, String defaultText) { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value; - switch (primitiveValue.getStringValue()) { + if (value instanceof CssText cssText) { + switch (cssText.value()) { case "capitalize": return StringUtils.capitalize(text); case "uppercase": @@ -113,11 +112,11 @@ protected String getTextTransform(String text, CSSValue value, protected String getTextTransform(String textToInsert, String oldText, CSSValue value) { - if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) { + if (!(value instanceof CssText cssText)) { return textToInsert; } - switch (((CSSPrimitiveValue) value).getStringValue()) { + switch (cssText.value()) { case "capitalize": String newText = StringUtils.capitalize(oldText + textToInsert); if (newText.length() > 0) { @@ -142,13 +141,11 @@ protected String getTextTransform(String textToInsert, String oldText, } protected boolean hasTextTransform(CSSValue value) { - if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE - || ((CSSPrimitiveValue) value).getStringValue() == null) { + if (!(value instanceof CssText text) || text.value() == null) { return false; } - String textTransform = ((CSSPrimitiveValue) value).getStringValue(); - switch (textTransform) { + switch (text.value()) { case "capitalize": case "uppercase": case "lowercase": diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/CSS2FontProperties.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/CSS2FontProperties.java index 938ce3119b5..d47e152caa3 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/CSS2FontProperties.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/CSS2FontProperties.java @@ -13,36 +13,45 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.core.dom.properties.css2; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.w3c.dom.css.CSSValue; public interface CSS2FontProperties extends CSSValue { - CSSPrimitiveValue getFamily(); + CssPrimitive getFamily(); - void setFamily(CSSPrimitiveValue family); + void setFamily(CssPrimitive family); - CSSPrimitiveValue getSize(); + CssPrimitive getSize(); - void setSize(CSSPrimitiveValue size); + void setSize(CssPrimitive size); - CSSPrimitiveValue getSizeAdjust(); + /** + * Whether {@link #getSize()} stems from a parsed CSS declaration rather + * than mirroring the widget's current font. Font definitions only + * override the height when the size was not set by CSS. + */ + boolean isSizeFromCSS(); - void setSizeAdjust(CSSPrimitiveValue sizeAdjust); + void setSizeFromCSS(boolean sizeFromCSS); - CSSPrimitiveValue getWeight(); + CssPrimitive getSizeAdjust(); - void setWeight(CSSPrimitiveValue weight); + void setSizeAdjust(CssPrimitive sizeAdjust); - CSSPrimitiveValue getStyle(); + CssPrimitive getWeight(); - void setStyle(CSSPrimitiveValue style); + void setWeight(CssPrimitive weight); - CSSPrimitiveValue getVariant(); + CssPrimitive getStyle(); - void setVariant(CSSPrimitiveValue variant); + void setStyle(CssPrimitive style); - CSSPrimitiveValue getStretch(); + CssPrimitive getVariant(); - void setStretch(CSSPrimitiveValue stretch); + void setVariant(CssPrimitive variant); + + CssPrimitive getStretch(); + + void setStretch(CssPrimitive stretch); } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/CSS2FontPropertiesImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/CSS2FontPropertiesImpl.java index ac9813ae66b..f8562c8e4db 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/CSS2FontPropertiesImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/properties/css2/CSS2FontPropertiesImpl.java @@ -14,92 +14,104 @@ package org.eclipse.e4.ui.css.core.dom.properties.css2; import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.w3c.dom.css.CSSValue; public class CSS2FontPropertiesImpl implements CSS2FontProperties { - private CSSPrimitiveValue family; + private CssPrimitive family; - private CSSPrimitiveValue size; + private CssPrimitive size; - private CSSPrimitiveValue sizeAdjust; + private boolean sizeFromCSS; - private CSSPrimitiveValue weight; + private CssPrimitive sizeAdjust; - private CSSPrimitiveValue style; + private CssPrimitive weight; - private CSSPrimitiveValue variant; + private CssPrimitive style; - private CSSPrimitiveValue stretch; + private CssPrimitive variant; + + private CssPrimitive stretch; @Override - public CSSPrimitiveValue getFamily() { + public CssPrimitive getFamily() { return family; } @Override - public void setFamily(CSSPrimitiveValue family) { + public void setFamily(CssPrimitive family) { this.family = family; } @Override - public CSSPrimitiveValue getSize() { + public CssPrimitive getSize() { return size; } @Override - public void setSize(CSSPrimitiveValue size) { + public void setSize(CssPrimitive size) { this.size = size; } @Override - public CSSPrimitiveValue getSizeAdjust() { + public boolean isSizeFromCSS() { + return sizeFromCSS; + } + + @Override + public void setSizeFromCSS(boolean sizeFromCSS) { + this.sizeFromCSS = sizeFromCSS; + } + + @Override + public CssPrimitive getSizeAdjust() { return sizeAdjust; } @Override - public void setSizeAdjust(CSSPrimitiveValue sizeAdjust) { + public void setSizeAdjust(CssPrimitive sizeAdjust) { this.sizeAdjust = sizeAdjust; } @Override - public CSSPrimitiveValue getWeight() { + public CssPrimitive getWeight() { return weight; } @Override - public void setWeight(CSSPrimitiveValue weight) { + public void setWeight(CssPrimitive weight) { this.weight = weight; } @Override - public CSSPrimitiveValue getStyle() { + public CssPrimitive getStyle() { return style; } @Override - public void setStyle(CSSPrimitiveValue style) { + public void setStyle(CssPrimitive style) { this.style = style; } @Override - public CSSPrimitiveValue getVariant() { + public CssPrimitive getVariant() { return variant; } @Override - public void setVariant(CSSPrimitiveValue variant) { + public void setVariant(CssPrimitive variant) { this.variant = variant; } @Override - public CSSPrimitiveValue getStretch() { + public CssPrimitive getStretch() { return stretch; } @Override - public void setStretch(CSSPrimitiveValue stretch) { + public void setStretch(CssPrimitive stretch) { this.stretch = stretch; } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/engine/CSSEngine.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/engine/CSSEngine.java index 225f08fd6eb..3a8fab1f753 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/engine/CSSEngine.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/engine/CSSEngine.java @@ -20,16 +20,15 @@ import org.eclipse.e4.ui.css.core.dom.IElementProvider; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverter; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl; import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors; import org.eclipse.e4.ui.css.core.resources.IResourcesRegistry; import org.eclipse.e4.ui.css.core.util.resources.IResourcesLocatorManager; import org.w3c.dom.Element; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.DocumentCSS; import org.w3c.dom.css.ViewCSS; -import org.w3c.dom.stylesheets.StyleSheet; +import org.w3c.dom.views.DocumentView; /** * CSS Engine interface used to parse style sheet and apply styles to something @@ -42,18 +41,18 @@ public interface CSSEngine { /** * Parse style sheet from Reader reader. */ - StyleSheet parseStyleSheet(Reader reader) throws IOException; + CSSStyleSheetImpl parseStyleSheet(Reader reader) throws IOException; /** * Parse style sheet from InputStream stream. */ - StyleSheet parseStyleSheet(InputStream stream) throws IOException; + CSSStyleSheetImpl parseStyleSheet(InputStream stream) throws IOException; /** * Parse style sheet from InputStream stream, using {@code uri} as the base * location for resolving relative {@code @import} rules. */ - StyleSheet parseStyleSheet(InputStream stream, String uri) throws IOException; + CSSStyleSheetImpl parseStyleSheet(InputStream stream, String uri) throws IOException; /*--------------- Parse style declaration -----------------*/ @@ -184,17 +183,32 @@ public interface CSSEngine { */ IResourcesLocatorManager getResourcesLocatorManager(); - /*--------------- Document/View CSS -----------------*/ + /*--------------- Computed style -----------------*/ /** - * Return the {@link DocumentCSS} used to store {@link CSSStyleSheet}. + * Compute the merged style declaration for the given element and pseudo + * element from all stylesheets registered with this engine. */ - DocumentCSS getDocumentCSS(); + CSSStyleDeclaration computeStyle(Element element, String pseudoElt); /** - * Return the {@link ViewCSS} used to compute {@link CSSStyleDeclaration}. + * Binary-compatibility bridge for callers compiled against the removed + * W3C cascade accessor; use {@link #computeStyle(Element, String)}. */ - ViewCSS getViewCSS(); + @Deprecated(forRemoval = true, since = "2026-06") + default ViewCSS getViewCSS() { + return new ViewCSS() { + @Override + public DocumentView getDocument() { + return null; + } + + @Override + public CSSStyleDeclaration getComputedStyle(Element elt, String pseudoElt) { + return computeStyle(elt, pseudoElt); + } + }; + } /*--------------- w3c Element -----------------*/ diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSComputedStyleImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSComputedStyleImpl.java index b0fb9aa4a16..541e223b475 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSComputedStyleImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSComputedStyleImpl.java @@ -37,7 +37,7 @@ public CSSComputedStyleImpl(List styleRules) { // only once after reading the stylesheet(s). this.styleRules.sort(StyleWrapper.COMPARATOR); for (StyleWrapper styleWrapper : this.styleRules) { - addCSSPropertyList(((CSSStyleDeclarationImpl) styleWrapper.style()).getCSSPropertyList()); + addCSSPropertyList(styleWrapper.style().getCSSPropertyList()); } } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSImportRuleImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSImportRuleImpl.java index ff4c06100bf..686acbc433b 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSImportRuleImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSImportRuleImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2015 Angelo Zerr and others. + * Copyright (c) 2008, 2026 Angelo Zerr and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -12,46 +12,26 @@ * Angelo Zerr - initial API and implementation * IBM Corporation - ongoing development *******************************************************************************/ - package org.eclipse.e4.ui.css.core.impl.dom; -import org.w3c.dom.css.CSSImportRule; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSStyleSheet; -import org.w3c.dom.stylesheets.MediaList; - -public class CSSImportRuleImpl extends CSSRuleImpl implements CSSImportRule { +/** + * An {@code @import} rule. The engine resolves and inlines the referenced + * stylesheet when the surrounding sheet is parsed. + */ +public final class CSSImportRuleImpl implements CssRule { - String uri; - MediaListImpl mediaList; + private final String href; - public CSSImportRuleImpl(CSSStyleSheet parentStyleSheet, CSSRule parentRule, - String uri, MediaListImpl mediaListImpl) { - super(parentStyleSheet, parentRule); - this.uri = uri; - this.mediaList = mediaListImpl; - } - - @Override - public short getType() { - return CSSRule.IMPORT_RULE; + public CSSImportRuleImpl(String href) { + this.href = href; } - // W3C CSSImportRule API methods - - @Override public String getHref() { - return uri; - } - - @Override - public MediaList getMedia() { - return mediaList; + return href; } @Override - public CSSStyleSheet getStyleSheet() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); + public String toString() { + return "@import url(" + href + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } -} \ No newline at end of file +} diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSRuleImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSRuleImpl.java deleted file mode 100644 index eea1262f96b..00000000000 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSRuleImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2015 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.e4.ui.css.core.impl.dom; - -import org.eclipse.e4.ui.css.core.exceptions.DOMExceptionImpl; -import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSStyleSheet; - -public abstract class CSSRuleImpl extends AbstractCSSNode implements CSSRule { - - private CSSStyleSheet parentStyleSheet = null; // null allowed - private CSSRule parentRule = null; // null allowed - private boolean readOnly; - - //TODO who sets readOnly? Seems should be ViewCSSImpl.getComputedStyle(Element,String) - - public CSSRuleImpl(CSSStyleSheet parentStyleSheet, CSSRule parentRule) { - super(); - this.parentStyleSheet = parentStyleSheet; - this.parentRule = parentRule; - } - - // W3C CSSRule API methods - - @Override - public String getCssText() { - // TODO Auto-generated constructor stub - throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); - } - - @Override - public CSSStyleSheet getParentStyleSheet() { - return parentStyleSheet; - } - - @Override - public CSSRule getParentRule() { - return parentRule; - } - - @Override - abstract public short getType(); - - @Override - public void setCssText(String cssText) throws DOMException { - if(readOnly) { - throw new DOMExceptionImpl(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.NO_MODIFICATION_ALLOWED_ERROR); - } - // TODO Auto-generated method stub - // TODO throws SYNTAX_ERR if cssText is unparsable - // TODO throws INVALID_MODIFICATION_ERR: Raised if the specified CSS string value represents a different type of rule than the current one. - // TODO throws HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at this point in the style sheet. - throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); - } -} diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSRuleListImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSRuleListImpl.java deleted file mode 100644 index d7110c71d1f..00000000000 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSRuleListImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2015 Angelo Zerr and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - * IBM Corporation - ongoing development - *******************************************************************************/ - -package org.eclipse.e4.ui.css.core.impl.dom; - -import java.util.ArrayList; -import java.util.List; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSRuleList; - -public class CSSRuleListImpl implements CSSRuleList { - - private final List ruleList; - - public CSSRuleListImpl() { - super(); - this.ruleList = new ArrayList<>(); - } - - // W3C CSSRuleList API methods - - @Override - public int getLength() { - return ruleList.size(); - } - - @Override - public CSSRule item(int position) { - return ruleList.get(position); - } - - //Additional - - public void add(CSSRule rule) { - ruleList.add(rule); - } - - public void remove(int position) { - ruleList.remove(position); - } -} diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleDeclarationImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleDeclarationImpl.java index efe3b61a733..4f440d2b081 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleDeclarationImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleDeclarationImpl.java @@ -26,14 +26,14 @@ import org.w3c.dom.css.CSSStyleDeclaration; import org.w3c.dom.css.CSSValue; -public class CSSStyleDeclarationImpl extends AbstractCSSNode implements CSSStyleDeclaration { +public class CSSStyleDeclarationImpl implements CSSStyleDeclaration { private boolean readOnly; - private final CSSRule parentRule; + private final CSSStyleRuleImpl parentRule; private final List properties = new ArrayList<>(); private CSSPropertyList cssPropertyListView; - public CSSStyleDeclarationImpl(CSSRule parentRule) { + public CSSStyleDeclarationImpl(CSSStyleRuleImpl parentRule) { this.parentRule = parentRule; } @@ -61,6 +61,13 @@ public int getLength() { @Override public CSSRule getParentRule() { + // The internal rule model no longer implements the W3C CSSRule type; + // use getParentStyleRule() instead. + return null; + } + + /** The style rule this declaration belongs to, or null for computed styles. */ + public CSSStyleRuleImpl getParentStyleRule() { return parentRule; } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleRuleImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleRuleImpl.java index 23200bae6c2..e8a29d81651 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleRuleImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleRuleImpl.java @@ -12,77 +12,39 @@ * Angelo Zerr - initial API and implementation * IBM Corporation - ongoing development *******************************************************************************/ - package org.eclipse.e4.ui.css.core.impl.dom; -import org.eclipse.e4.ui.css.core.dom.CSSPropertyList; -import org.eclipse.e4.ui.css.core.dom.ExtendedCSSRule; import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors; -import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleRule; -import org.w3c.dom.css.CSSStyleSheet; -public class CSSStyleRuleImpl extends CSSRuleImpl implements CSSStyleRule, ExtendedCSSRule { +/** + * A style rule: a selector list plus its style declaration. + */ +public final class CSSStyleRuleImpl implements CssRule { private final Selectors.SelectorList selectors; - private CSSStyleDeclaration styleDeclaration; + private CSSStyleDeclarationImpl styleDeclaration; - public CSSStyleRuleImpl(CSSStyleSheet parentStyleSheet, CSSRule parentRule, Selectors.SelectorList selectors) { - super(parentStyleSheet, parentRule); + public CSSStyleRuleImpl(Selectors.SelectorList selectors) { this.selectors = selectors; } - //---------------------------------------- - // W3C CSSRule API methods - - @Override - public short getType() { - return CSSRule.STYLE_RULE; - } - // ---------------------------------------- - // W3C CSSStyleRule API methods - - @Override public String getCssText() { return getSelectorText() + " { " + getStyle().getCssText() + " }"; } - //---------------------------------------- - // W3C CSSStyleRule API methods - - @Override public String getSelectorText() { return selectors.text(); } - @Override - public CSSStyleDeclaration getStyle() { + public CSSStyleDeclarationImpl getStyle() { return styleDeclaration; } - @Override - public void setSelectorText(String selectorText) throws DOMException { - throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); - } - - - //---------------------------------------- - // Additional methods - - @Override public Selectors.SelectorList getSelectorList() { return selectors; } - - @Override - public CSSPropertyList getCSSPropertyList() { - throw new UnsupportedOperationException("NOT YET IMPLEMENTED"); - } - - public void setStyle(CSSStyleDeclaration styleDeclaration) { + public void setStyle(CSSStyleDeclarationImpl styleDeclaration) { this.styleDeclaration = styleDeclaration; } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleSheetImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleSheetImpl.java index 63192d3a4d3..2a6fbcfa7c1 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleSheetImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleSheetImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2015 Angelo Zerr and others. + * Copyright (c) 2008, 2026 Angelo Zerr and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -12,100 +12,22 @@ * Angelo Zerr - initial API and implementation * IBM Corporation - ongoing development *******************************************************************************/ - package org.eclipse.e4.ui.css.core.impl.dom; -import org.eclipse.e4.ui.css.core.exceptions.DOMExceptionImpl; -import org.w3c.dom.DOMException; -import org.w3c.dom.Node; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSRuleList; -import org.w3c.dom.css.CSSStyleSheet; -import org.w3c.dom.stylesheets.MediaList; -import org.w3c.dom.stylesheets.StyleSheet; - -public class CSSStyleSheetImpl extends AbstractCSSNode implements CSSStyleSheet { - - private static final String NOT_YET_IMPLEMENTED = "NOT YET IMPLEMENTED"; //$NON-NLS-1$ - - private CSSRuleList rules = null; +import java.util.List; - public CSSStyleSheetImpl() { - super(); - } +/** + * A parsed stylesheet: an ordered list of {@link CssRule}s. + */ +public final class CSSStyleSheetImpl { - // W3C CSSStyleSheet API methods + private final List rules; - @Override - public void deleteRule(int position) throws DOMException { - try { - ((CSSRuleListImpl) rules).remove(position); - } catch (IndexOutOfBoundsException ex) { - throw new DOMExceptionImpl(DOMException.INDEX_SIZE_ERR, DOMExceptionImpl.ARRAY_OUT_OF_BOUNDS, ex.getMessage()); - } + public CSSStyleSheetImpl(List rules) { + this.rules = List.copyOf(rules); } - @Override - public CSSRuleList getCssRules() { + public List getRules() { return rules; } - - @Override - public CSSRule getOwnerRule() { - throw new UnsupportedOperationException(NOT_YET_IMPLEMENTED); - } - - @Override - public int insertRule(String arg0, int arg1) throws DOMException { - throw new UnsupportedOperationException(NOT_YET_IMPLEMENTED); - } - - - // org.w3c.dom.stylesheet.StyleSheet API methods - - @Override - public boolean getDisabled() { - throw new UnsupportedOperationException(NOT_YET_IMPLEMENTED); - } - - @Override - public String getHref() { - throw new UnsupportedOperationException(NOT_YET_IMPLEMENTED); - } - - @Override - public MediaList getMedia() { - throw new UnsupportedOperationException(NOT_YET_IMPLEMENTED); - } - - @Override - public Node getOwnerNode() { - throw new UnsupportedOperationException(NOT_YET_IMPLEMENTED); - } - - @Override - public StyleSheet getParentStyleSheet() { - throw new UnsupportedOperationException(NOT_YET_IMPLEMENTED); - } - - @Override - public String getTitle() { - throw new UnsupportedOperationException(NOT_YET_IMPLEMENTED); - } - - @Override - public String getType() { - throw new UnsupportedOperationException(NOT_YET_IMPLEMENTED); - } - - @Override - public void setDisabled(boolean disabled) { - throw new UnsupportedOperationException(NOT_YET_IMPLEMENTED); - } - - // Additional - - public void setRuleList(CSSRuleList rules) { - this.rules = rules; - } } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSValueImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSValueImpl.java index f629bbc0673..967244d15d9 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSValueImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSValueImpl.java @@ -23,7 +23,7 @@ import org.w3c.dom.css.RGBColor; import org.w3c.dom.css.Rect; -public abstract class CSSValueImpl extends AbstractCSSNode implements CSSPrimitiveValue, CSSValue { +public abstract class CSSValueImpl implements CSSPrimitiveValue, CSSValue { private static final String NOT_YET_IMPLEMENTED = "NOT YET IMPLEMENTED"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/AbstractCSSNode.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CssRule.java similarity index 66% rename from bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/AbstractCSSNode.java rename to bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CssRule.java index c63b46808ad..a00367b6bca 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/AbstractCSSNode.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CssRule.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2013 Angelo Zerr and others. + * Copyright (c) 2026 Lars Vogel and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -9,19 +9,12 @@ * SPDX-License-Identifier: EPL-2.0 * * Contributors: - * Angelo Zerr - initial API and implementation - * IBM Corporation + * Lars Vogel - initial API and implementation *******************************************************************************/ - package org.eclipse.e4.ui.css.core.impl.dom; /** - * Abstract CSS Node. + * A rule in a parsed stylesheet: either a style rule or an {@code @import}. */ -public class AbstractCSSNode { - - public AbstractCSSNode() { - super(); - } - +public sealed interface CssRule permits CSSStyleRuleImpl, CSSImportRuleImpl { } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CssValues.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CssValues.java index f1c9a5bf247..2030149569d 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CssValues.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CssValues.java @@ -30,11 +30,11 @@ * dependency ({@code LexicalUnit}). * *

- * The variants still implement the W3C DOM-CSS interfaces so the property - * handlers and converters that read values through {@link CSSValue} / - * {@link CSSPrimitiveValue} keep working unchanged. Those consumers move to - * pattern matching on the records in a later step, after which the W3C - * interfaces can be dropped. + * Consumers pattern-match on the record variants ({@link CssNumber}, + * {@link CssDimension}, {@link CssText}, {@link CssColor}, {@link CssList}) + * and read their components. The variants still implement the W3C DOM-CSS + * interfaces as a transitional bridge; the bridge goes away once the + * computed-style cascade is internal as well. *

*/ public final class CssValues { @@ -48,13 +48,11 @@ public sealed interface CssValue extends CSSValue permits CssPrimitive, CssList } /** - * A single CSS value. Provides the W3C boilerplate; concrete variants only - * implement {@link #getPrimitiveType()}, {@link #getCssText()} and whichever - * of {@link #getFloatValue(short)} / {@link #getStringValue()} / - * {@link #getRGBColorValue()} applies. + * A single CSS value. Provides the W3C bridge boilerplate; read the values + * through the record components, not through the W3C accessors. */ public sealed interface CssPrimitive extends CssValue, CSSPrimitiveValue - permits CssNumber, CssDimension, CssText, CssColor, CssOperator { + permits CssNumeric, CssText, CssColor, CssOperator { @Override default short getCssValueType() { @@ -102,8 +100,40 @@ default void setStringValue(short stringType, String stringValue) throws DOMExce } } + /** Unit of a {@link CssNumeric} value. {@link #NUMBER} marks a unitless number. */ + public enum CssUnit { + NUMBER(""), PX("px"), EM("em"), EX("ex"), CM("cm"), MM("mm"), IN("in"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ + PT("pt"), PC("pc"), DEG("deg"), PERCENT("%"), OTHER(""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + + private final String text; + + CssUnit(String text) { + this.text = text; + } + + /** Canonical unit text, e.g. {@code "px"}; empty for {@link #NUMBER} and {@link #OTHER}. */ + public String text() { + return text; + } + } + + /** A numeric value: a unitless {@link CssNumber} or a {@link CssDimension} with a unit. */ + public sealed interface CssNumeric extends CssPrimitive permits CssNumber, CssDimension { + + /** The numeric magnitude, without unit conversion. */ + double value(); + + /** The unit; {@link CssUnit#NUMBER} for a unitless number. */ + CssUnit unit(); + } + /** {@code 34} or {@code 2.0} - a unitless number. */ - public record CssNumber(double value, boolean integer) implements CssPrimitive { + public record CssNumber(double value, boolean integer) implements CssNumeric { + @Override + public CssUnit unit() { + return CssUnit.NUMBER; + } + @Override public short getPrimitiveType() { return CSS_NUMBER; @@ -120,11 +150,33 @@ public String getCssText() { } } - /** {@code 26px}, {@code 30%}, {@code 75em} - a number with a unit. */ - public record CssDimension(double value, short primitiveType, String unit) implements CssPrimitive { + /** + * {@code 26px}, {@code 30%}, {@code 75em} - a number with a unit. + * {@code unitText} keeps the source spelling for units the {@link CssUnit} + * enum does not model ({@link CssUnit#OTHER}). + */ + public record CssDimension(double value, CssUnit unit, String unitText) implements CssNumeric { + + public CssDimension(double value, CssUnit unit) { + this(value, unit, unit.text()); + } + @Override public short getPrimitiveType() { - return primitiveType; + return switch (unit) { + case NUMBER -> CSS_NUMBER; + case PX -> CSS_PX; + case EM -> CSS_EMS; + case EX -> CSS_EXS; + case CM -> CSS_CM; + case MM -> CSS_MM; + case IN -> CSS_IN; + case PT -> CSS_PT; + case PC -> CSS_PC; + case DEG -> CSS_DEG; + case PERCENT -> CSS_PERCENTAGE; + case OTHER -> CSS_DIMENSION; + }; } @Override @@ -134,15 +186,26 @@ public float getFloatValue(short unitType) { @Override public String getCssText() { - return (float) value + unit; + return (float) value + unitText; } } /** {@code red}, {@code 'a string'}, {@code url(x)}, {@code inherit}. */ - public record CssText(short primitiveType, String value) implements CssPrimitive { + public record CssText(Kind kind, String value) implements CssPrimitive { + + /** What textual form the value had in the source. */ + public enum Kind { + IDENT, STRING, URI, INHERIT + } + @Override public short getPrimitiveType() { - return primitiveType; + return switch (kind) { + case IDENT -> CSS_IDENT; + case STRING -> CSS_STRING; + case URI -> CSS_URI; + case INHERIT -> CSS_INHERIT; + }; } @Override @@ -152,15 +215,15 @@ public String getStringValue() { @Override public String getCssText() { - return switch (primitiveType) { - case CSS_URI -> "url(" + value + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + return switch (kind) { + case URI -> "url(" + value + ")"; //$NON-NLS-1$ //$NON-NLS-2$ default -> value; }; } } /** {@code rgb(...)} or a {@code #rgb} / {@code #rrggbb} colour. */ - public record CssColor(CssPrimitive red, CssPrimitive green, CssPrimitive blue) + public record CssColor(CssNumeric red, CssNumeric green, CssNumeric blue) implements CssPrimitive, RGBColor { @Override public short getPrimitiveType() { diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/DocumentCSSImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/DocumentCSSImpl.java deleted file mode 100644 index b87b42b143c..00000000000 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/DocumentCSSImpl.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2026 Angelo Zerr and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - * IBM Corporation - ongoing development - * Lars Vogel - Bug 422702 - * Karsten Thoms - Bug 532869 - *******************************************************************************/ - -package org.eclipse.e4.ui.css.core.impl.dom; - -import java.util.ArrayList; -import java.util.List; -import org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.DocumentCSS; -import org.w3c.dom.stylesheets.StyleSheet; -import org.w3c.dom.stylesheets.StyleSheetList; - -/** - * w3c {@link DocumentCSS} implementation. - */ -public class DocumentCSSImpl implements ExtendedDocumentCSS { - - private final StyleSheetListImpl styleSheetList = new StyleSheetListImpl(); - - private final List styleSheetChangeListeners = new ArrayList<>(1); - - @Override - public StyleSheetList getStyleSheets() { - return styleSheetList; - } - - @Override - public CSSStyleDeclaration getOverrideStyle(Element element, String s) { - return null; - } - - @Override - public void addStyleSheet(StyleSheet styleSheet) { - styleSheetList.addStyleSheet(styleSheet); - styleSheetChangeListeners.forEach(l -> l.styleSheetAdded(styleSheet)); - } - - @Override - public void removeAllStyleSheets() { - for (int i = 0; i < styleSheetList.getLength(); i++) { - StyleSheet styleSheet = styleSheetList.item(i); - styleSheetChangeListeners.forEach(l -> l.styleSheetRemoved(styleSheet)); - } - styleSheetList.removeAllStyleSheets(); - } - - @Override - public void addStyleSheetChangeListener(StyleSheetChangeListener listener) { - styleSheetChangeListeners.add(listener); - } - - @Override - public void removeStyleSheetChangeListener(StyleSheetChangeListener listener) { - styleSheetChangeListeners.remove(listener); - } -} diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/MediaListImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/MediaListImpl.java deleted file mode 100644 index d0da1c3f902..00000000000 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/MediaListImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2015 Angelo Zerr and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation] - * IBM Corporation - ongoing development - *******************************************************************************/ - -package org.eclipse.e4.ui.css.core.impl.dom; - -import java.util.ArrayList; -import java.util.List; -import org.w3c.dom.DOMException; -import org.w3c.dom.stylesheets.MediaList; - -public class MediaListImpl implements MediaList { - - private final List mediaList; - - public MediaListImpl() { - mediaList = new ArrayList<>(); - } - - @Override - public void appendMedium(String newMedium) throws DOMException { - if (mediaList.contains(newMedium)) { - mediaList.remove(newMedium); - } - mediaList.add(newMedium); - } - - @Override - public void deleteMedium(String oldMedium) throws DOMException { - mediaList.remove(oldMedium); - } - - @Override - public int getLength() { - return (mediaList != null) ? mediaList.size() : 0; - } - - @Override - public String getMediaText() { - StringBuilder media = new StringBuilder(); - int size = mediaList.size(); - if (size > 0) { - media.append(mediaList.get(0)); - for (int i = 1; i < mediaList.size(); i++) { - media.append(", "); - media.append(mediaList.get(i)); - } - } - return media.toString(); - } - - @Override - public String item(int index) { - if (index > mediaList.size()) { - return null; - } - return mediaList.get(index); - } - - @Override - public void setMediaText(String mediaText) throws DOMException { - while (mediaText.length() > 0) { - int next = mediaText.indexOf(','); - if (next == -1) { - next = mediaText.length(); - } - String media = mediaText.substring(0, next); - appendMedium(media.trim()); - if (next + 1 < mediaText.length()) { - mediaText = mediaText.substring(next + 1, mediaText.length()); - } else { - break; - } - } - } - -} \ No newline at end of file diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleSheetListImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleSheetListImpl.java deleted file mode 100644 index 3425557f546..00000000000 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleSheetListImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2015 Angelo Zerr and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - * IBM Corporation - ongoing development - *******************************************************************************/ - -package org.eclipse.e4.ui.css.core.impl.dom; - -import java.util.ArrayList; -import java.util.List; -import org.w3c.dom.stylesheets.StyleSheet; -import org.w3c.dom.stylesheets.StyleSheetList; - -/** - * {@link StyleSheetList} implementation. It provides the abstraction of an - * ordered collection of style sheets. - */ -public class StyleSheetListImpl implements StyleSheetList { - - private List styleSheets; - - - @Override - public int getLength() { - return (styleSheets != null) ? styleSheets.size() : 0; - } - - @Override - public StyleSheet item(int index) { - return (styleSheets != null) ? styleSheets.get(index) : null; - } - - /** - * Add {@link StyleSheet} to the collection of style sheets - */ - public void addStyleSheet(StyleSheet styleSheet) { - if (styleSheets == null) { - styleSheets = new ArrayList<>(); - } - styleSheets.add(styleSheet); - } - - /** - * Remove all style sheet. - */ - public void removeAllStyleSheets() { - styleSheets = null; - } -} diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleWrapper.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleWrapper.java index 1a1ea31d28d..b09f393f60d 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleWrapper.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/StyleWrapper.java @@ -16,19 +16,18 @@ package org.eclipse.e4.ui.css.core.impl.dom; import java.util.Comparator; -import org.w3c.dom.css.CSSStyleDeclaration; /** * A wrapper that holds a reference to the styles defined in a CSS rule block, * together with all the information needed to calculate a matching selector's * precedence. */ -final record StyleWrapper(CSSStyleDeclaration style, int specificity, int position) { +public record StyleWrapper(CSSStyleDeclarationImpl style, int specificity, int position) { /** * A comparator for {@link StyleWrapper}s. */ - static final Comparator COMPARATOR = Comparator.comparingInt(StyleWrapper::specificity) + public static final Comparator COMPARATOR = Comparator.comparingInt(StyleWrapper::specificity) .thenComparingInt(StyleWrapper::position); } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/ViewCSSImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/ViewCSSImpl.java deleted file mode 100644 index aa1a5c8a92c..00000000000 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/ViewCSSImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2026 Angelo Zerr and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Angelo Zerr - initial API and implementation - * IBM Corporation - ongoing development - * Lars Vogel - Bug 422702 - * Stefan Winkler - Bug 458342 - * Karsten Thoms - Bug 532869 - *******************************************************************************/ -package org.eclipse.e4.ui.css.core.impl.dom; - -import java.util.ArrayList; -import java.util.List; -import org.eclipse.e4.ui.css.core.dom.ExtendedCSSRule; -import org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS; -import org.eclipse.e4.ui.css.core.impl.engine.selector.SelectorMatcher; -import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSRuleList; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleRule; -import org.w3c.dom.css.CSSStyleSheet; -import org.w3c.dom.css.DocumentCSS; -import org.w3c.dom.css.ViewCSS; -import org.w3c.dom.stylesheets.StyleSheet; -import org.w3c.dom.stylesheets.StyleSheetList; -import org.w3c.dom.views.DocumentView; - - -/** - * {@link ViewCSS} implementation used to compute {@link CSSStyleDeclaration}. - */ -public class ViewCSSImpl implements ViewCSS, ExtendedDocumentCSS.StyleSheetChangeListener { - - protected DocumentCSS documentCSS; - private boolean ruleCachingEnabled; - /** Cached state of combined CSS rules for the current stylesheets */ - private List currentCombinedRules; - - /** - * Creates a new ViewCSS. - */ - public ViewCSSImpl(DocumentCSS documentCSS) { - this.documentCSS = documentCSS; - if (this.documentCSS instanceof ExtendedDocumentCSS) { - ((ExtendedDocumentCSS) this.documentCSS).addStyleSheetChangeListener(this); - ruleCachingEnabled = true; - } - } - - /** - * DOM: Implements {@link - * org.w3c.dom.views.AbstractView#getDocument()}. - */ - @Override - public DocumentView getDocument() { - return null; - } - - /** - * Determines the relevant style declaration for an DOM element - */ - @Override - public CSSStyleDeclaration getComputedStyle(Element elt, String pseudoElt) { - return getComputedStyle(getCombinedRules(), elt, pseudoElt); - } - - /** - * Retrieves the combined list of CSS rules for all current stylesheets. This - * method returns a cached state when the stylesheets are the same as on its - * last call. When the stylesheets differ, the rules are collected from - * documentCSS's stylesheets. - * - * @return CSS rules for all style sheets - */ - private List getCombinedRules() { - if (this.ruleCachingEnabled && this.currentCombinedRules != null) { - return this.currentCombinedRules; - } - - StyleSheetList styleSheetList = documentCSS.getStyleSheets(); - int l = styleSheetList.getLength(); - - List cssRules = new ArrayList<>(); - - // Loop over the CSS styleSheet list - for (int i = 0; i < l; i++) { - CSSStyleSheet styleSheet = (CSSStyleSheet) styleSheetList.item(i); - - CSSRuleList styleSheetRules = styleSheet.getCssRules(); - int rulesSize = styleSheetRules.getLength(); - for (int j = 0; j < rulesSize; j++) { - cssRules.add(styleSheetRules.item(j)); - } - } - - if (this.ruleCachingEnabled) { - this.currentCombinedRules = cssRules; - } - return cssRules; - } - - private CSSStyleDeclaration getComputedStyle(List ruleList, Element elt, String pseudoElt) { - List styleDeclarations = null; - StyleWrapper firstStyleDeclaration = null; - int position = 0; - - int depth = 0; - for (org.w3c.dom.Node n = elt; n instanceof Element; n = n.getParentNode()) { - depth++; - } - Element[] hierarchy = new Element[depth]; - int idx = 0; - for (org.w3c.dom.Node n = elt; n instanceof Element; n = n.getParentNode()) { - hierarchy[idx++] = (Element) n; - } - - for (CSSRule rule : ruleList) { - if (rule.getType() != CSSRule.STYLE_RULE || (!(rule instanceof ExtendedCSSRule)) ) { - continue; // we only handle the CSSRule.STYLE_RULE and ExtendedCSSRule case - } - CSSStyleRule styleRule = (CSSStyleRule) rule; - ExtendedCSSRule r = (ExtendedCSSRule) rule; - Selectors.SelectorList selectorList = r.getSelectorList(); - for (Selectors.Selector selector : selectorList.alternatives()) { - if (SelectorMatcher.matches(selector, elt, pseudoElt, hierarchy, 0)) { - CSSStyleDeclaration style = styleRule.getStyle(); - int specificity = selector.specificity(); - StyleWrapper wrapper = new StyleWrapper(style, specificity, position++); - if (firstStyleDeclaration == null) { - firstStyleDeclaration = wrapper; - } else { - // There is several Style Declarations which - // match the current element - if (styleDeclarations == null) { - styleDeclarations = new ArrayList<>(); - styleDeclarations.add(firstStyleDeclaration); - } - styleDeclarations.add(wrapper); - } - } - } - } - if (styleDeclarations != null) { - // There is several Style Declarations which match the element, merge the CSS - // Property value. - return new CSSComputedStyleImpl(styleDeclarations); - } - if (firstStyleDeclaration != null) { - return firstStyleDeclaration.style(); - } - return null; - } - - @Override - public void styleSheetAdded(StyleSheet styleSheet) { - currentCombinedRules = null; - } - - @Override - public void styleSheetRemoved(StyleSheet styleSheet) { - currentCombinedRules = null; - } -} diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/properties/CSSBorderPropertiesImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/properties/CSSBorderPropertiesImpl.java index 99023c0a0b3..995f58c9efc 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/properties/CSSBorderPropertiesImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/properties/CSSBorderPropertiesImpl.java @@ -14,7 +14,7 @@ package org.eclipse.e4.ui.css.core.impl.dom.properties; import org.eclipse.e4.ui.css.core.dom.properties.CSSBorderProperties; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; /** * {@link CSSBorderProperties} implementation. @@ -24,19 +24,19 @@ */ public class CSSBorderPropertiesImpl implements CSSBorderProperties { - private CSSPrimitiveValue color; + private CssPrimitive color; private int width = 0; private String style; @Override - public CSSPrimitiveValue getColor() { + public CssPrimitive getColor() { return color; } @Override - public void setColor(CSSPrimitiveValue color) { + public void setColor(CssPrimitive color) { this.color = color; } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/engine/CSSEngineImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/engine/CSSEngineImpl.java index 64d0dddd09f..ff20cde42a9 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/engine/CSSEngineImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/engine/CSSEngineImpl.java @@ -41,8 +41,6 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.e4.ui.css.core.dom.CSSStylableElement; import org.eclipse.e4.ui.css.core.dom.ChildVisibilityAwareElement; -import org.eclipse.e4.ui.css.core.dom.ExtendedCSSRule; -import org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS; import org.eclipse.e4.ui.css.core.dom.IElementProvider; import org.eclipse.e4.ui.css.core.dom.IStreamingNodeList; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyCompositeHandler; @@ -56,10 +54,13 @@ import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.core.engine.CSSErrorHandler; import org.eclipse.e4.ui.css.core.exceptions.UnsupportedPropertyException; -import org.eclipse.e4.ui.css.core.impl.dom.CSSRuleListImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSComputedStyleImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSImportRuleImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleDeclarationImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleRuleImpl; import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl; -import org.eclipse.e4.ui.css.core.impl.dom.DocumentCSSImpl; -import org.eclipse.e4.ui.css.core.impl.dom.ViewCSSImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CssRule; +import org.eclipse.e4.ui.css.core.impl.dom.StyleWrapper; import org.eclipse.e4.ui.css.core.impl.engine.selector.SelectorMatcher; import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors; import org.eclipse.e4.ui.css.core.resources.IResourcesRegistry; @@ -71,19 +72,12 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.w3c.dom.css.CSSImportRule; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSRuleList; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.DocumentCSS; -import org.w3c.dom.css.ViewCSS; -import org.w3c.dom.stylesheets.StyleSheet; /** - * Abstract CSS Engine manage style sheet parsing and store the - * {@link CSSStyleSheet} into {@link DocumentCSS}. + * Abstract CSS Engine which manages stylesheet parsing, the cascade, and + * applying styles. * * To apply styles, call the {@link #applyStyles(Object, boolean, boolean)} * method. This method check if {@link ICSSPropertyHandler} is registered for @@ -105,15 +99,11 @@ public abstract class CSSEngineImpl implements CSSEngine { */ private static final IResourcesLocatorManager defaultResourcesLocatorManager = ResourcesLocatorManager.INSTANCE; - /** - * w3c {@link DocumentCSS}. - */ - private final ExtendedDocumentCSS documentCSS; + /** The stylesheets added to this engine, in registration order. */ + private final List styleSheets = new ArrayList<>(); - /** - * w3c {@link ViewCSS}. - */ - private final ViewCSS viewCSS; + /** Cached flat list of style rules over all stylesheets. */ + private List combinedRules; /** * {@link IElementProvider} used to retrieve w3c Element linked to the @@ -156,12 +146,6 @@ public abstract class CSSEngineImpl implements CSSEngine { private CSSPropertyHandlerLazyProviderImpl lazyHandlerProvider; public CSSEngineImpl() { - this(new DocumentCSSImpl()); - } - - public CSSEngineImpl(ExtendedDocumentCSS documentCSS) { - this.documentCSS = documentCSS; - this.viewCSS = new ViewCSSImpl(documentCSS); keyFactory = new ResourceRegistryKeyFactory(); registerCSSValueConverter(CSSValueBooleanConverterImpl.INSTANCE); } @@ -169,34 +153,31 @@ public CSSEngineImpl(ExtendedDocumentCSS documentCSS) { /*--------------- Parse style sheet -----------------*/ @Override - public StyleSheet parseStyleSheet(Reader reader) throws IOException { + public CSSStyleSheetImpl parseStyleSheet(Reader reader) throws IOException { return parseStyleSheet(readFully(reader), null); } @Override - public StyleSheet parseStyleSheet(InputStream stream) throws IOException { + public CSSStyleSheetImpl parseStyleSheet(InputStream stream) throws IOException { return parseStyleSheet(stream, null); } @Override - public StyleSheet parseStyleSheet(InputStream stream, String uri) throws IOException { + public CSSStyleSheetImpl parseStyleSheet(InputStream stream, String uri) throws IOException { return parseStyleSheet(readFully(new InputStreamReader(stream, StandardCharsets.UTF_8)), uri); } - private StyleSheet parseStyleSheet(String content, String uri) throws IOException { - CSSStyleSheet styleSheet = CssParser.parseStyleSheet(content); + private CSSStyleSheetImpl parseStyleSheet(String content, String uri) throws IOException { + CSSStyleSheetImpl styleSheet = CssParser.parseStyleSheet(content); - CSSRuleList rules = styleSheet.getCssRules(); - int length = rules.getLength(); - CSSRuleListImpl masterList = new CSSRuleListImpl(); + List rules = styleSheet.getRules(); + List masterList = new ArrayList<>(); int counter; - for (counter = 0; counter < length; counter++) { - CSSRule rule = rules.item(counter); - if (rule.getType() != CSSRule.IMPORT_RULE) { + for (counter = 0; counter < rules.size(); counter++) { + if (!(rules.get(counter) instanceof CSSImportRuleImpl importRule)) { break; } // processing an import CSS - CSSImportRule importRule = (CSSImportRule) rule; URL url = null; if (importRule.getHref().startsWith("platform")) { url = FileLocator.resolve(new URL(importRule.getHref())); @@ -209,7 +190,7 @@ private StyleSheet parseStyleSheet(String content, String uri) throws IOExceptio File testFile = new File(url.getFile()); if (!isArchive&&!testFile.exists()) { // look in platform default - String path = getResourcesLocatorManager().resolve((importRule).getHref()); + String path = getResourcesLocatorManager().resolve(importRule.getHref()); testFile = new File(new URL(path).getFile()); if (testFile.exists()) { url = new URL(path); @@ -218,33 +199,39 @@ private StyleSheet parseStyleSheet(String content, String uri) throws IOExceptio } try (InputStream stream = url.openStream()) { parseImport++; + CSSStyleSheetImpl imported; try { - styleSheet = (CSSStyleSheet) parseStyleSheet( + imported = parseStyleSheet( readFully(new InputStreamReader(stream, StandardCharsets.UTF_8)), url.toString()); } finally { parseImport--; } - CSSRuleList tempRules = styleSheet.getCssRules(); - for (int j = 0; j < tempRules.getLength(); j++) { - masterList.add(tempRules.item(j)); - } + masterList.addAll(imported.getRules()); } } // add remaining non import rules - for (int i = counter; i < length; i++) { - masterList.add(rules.item(i)); - } + masterList.addAll(rules.subList(counter, rules.size())); // final stylesheet - CSSStyleSheetImpl s = new CSSStyleSheetImpl(); - s.setRuleList(masterList); + CSSStyleSheetImpl s = new CSSStyleSheetImpl(masterList); if (parseImport == 0) { - documentCSS.addStyleSheet(s); + addStyleSheet(s); } return s; } + /** Register a parsed stylesheet with this engine's cascade. */ + public void addStyleSheet(CSSStyleSheetImpl styleSheet) { + styleSheets.add(styleSheet); + combinedRules = null; + } + + /** The stylesheets registered with this engine, in registration order. */ + public List getStyleSheets() { + return Collections.unmodifiableList(styleSheets); + } + private void processNodeList(NodeList nodes, BiConsumer consumer, boolean applyStylesToChildNodes) { if (nodes instanceof IStreamingNodeList) { ((IStreamingNodeList) nodes).stream().forEach(child -> { @@ -373,7 +360,7 @@ public void applyStyles(Object element, boolean applyStylesToChildNodes, boolean /* * Compute new Style to apply. */ - CSSStyleDeclaration style = viewCSS.getComputedStyle(elt, null); + CSSStyleDeclaration style = computeStyle(elt, null); if (computeDefaultStyle) { if (applyStylesToChildNodes) { this.computeDefaultStyle = computeDefaultStyle; @@ -392,7 +379,7 @@ public void applyStyles(Object element, boolean applyStylesToChildNodes, boolean // there are static pseudo instances defined, loop for it and // apply styles for each pseudo instance. for (String pseudoInstance : pseudoInstances) { - CSSStyleDeclaration styleWithPseudoInstance = viewCSS.getComputedStyle(elt, pseudoInstance); + CSSStyleDeclaration styleWithPseudoInstance = computeStyle(elt, pseudoInstance); if (computeDefaultStyle) { /* * Apply default style for the current pseudo instance. @@ -401,9 +388,11 @@ public void applyStyles(Object element, boolean applyStylesToChildNodes, boolean } if (styleWithPseudoInstance != null) { - CSSRule parentRule = styleWithPseudoInstance.getParentRule(); - if (parentRule instanceof ExtendedCSSRule) { - applyConditionalPseudoStyle((ExtendedCSSRule) parentRule, pseudoInstance, element, styleWithPseudoInstance); + CSSStyleRuleImpl parentRule = styleWithPseudoInstance instanceof CSSStyleDeclarationImpl declaration + ? declaration.getParentStyleRule() + : null; + if (parentRule != null) { + applyConditionalPseudoStyle(parentRule, pseudoInstance, element, styleWithPseudoInstance); } else { applyStyleDeclaration(elt, styleWithPseudoInstance, pseudoInstance); } @@ -462,7 +451,7 @@ protected boolean isVisible(Element elt) { return true; } - private void applyConditionalPseudoStyle(ExtendedCSSRule parentRule, String pseudoInstance, Object element, + private void applyConditionalPseudoStyle(CSSStyleRuleImpl parentRule, String pseudoInstance, Object element, CSSStyleDeclaration styleWithPseudoInstance) { Selectors.SelectorList selectorList = parentRule.getSelectorList(); for (Selectors.Selector alternative : selectorList.alternatives()) { @@ -967,16 +956,67 @@ public void setResourcesLocatorManager( this.resourcesLocatorManager = resourcesLocatorManager; } - /*--------------- Document/View CSS -----------------*/ + /*--------------- Computed style -----------------*/ @Override - public DocumentCSS getDocumentCSS() { - return documentCSS; + public CSSStyleDeclaration computeStyle(Element elt, String pseudoElt) { + List styleDeclarations = null; + StyleWrapper firstStyleDeclaration = null; + int position = 0; + + int depth = 0; + for (Node n = elt; n instanceof Element; n = n.getParentNode()) { + depth++; + } + Element[] hierarchy = new Element[depth]; + int idx = 0; + for (Node n = elt; n instanceof Element; n = n.getParentNode()) { + hierarchy[idx++] = (Element) n; + } + + for (CSSStyleRuleImpl rule : getCombinedRules()) { + for (Selectors.Selector selector : rule.getSelectorList().alternatives()) { + if (SelectorMatcher.matches(selector, elt, pseudoElt, hierarchy, 0)) { + int specificity = selector.specificity(); + StyleWrapper wrapper = new StyleWrapper(rule.getStyle(), specificity, position++); + if (firstStyleDeclaration == null) { + firstStyleDeclaration = wrapper; + } else { + // There are several style declarations which match + // the current element + if (styleDeclarations == null) { + styleDeclarations = new ArrayList<>(); + styleDeclarations.add(firstStyleDeclaration); + } + styleDeclarations.add(wrapper); + } + } + } + } + if (styleDeclarations != null) { + // There are several style declarations which match the element; + // merge the CSS property values. + return new CSSComputedStyleImpl(styleDeclarations); + } + if (firstStyleDeclaration != null) { + return firstStyleDeclaration.style(); + } + return null; } - @Override - public ViewCSS getViewCSS() { - return viewCSS; + private List getCombinedRules() { + if (combinedRules == null) { + List rules = new ArrayList<>(); + for (CSSStyleSheetImpl styleSheet : styleSheets) { + for (CssRule rule : styleSheet.getRules()) { + if (rule instanceof CSSStyleRuleImpl styleRule) { + rules.add(styleRule); + } + } + } + combinedRules = rules; + } + return combinedRules; } @Override @@ -1000,8 +1040,8 @@ public void dispose() { @Override public void reset() { - // Remove All Style Sheets - documentCSS.removeAllStyleSheets(); + styleSheets.clear(); + combinedRules = null; } /*--------------- Resources Registry -----------------*/ diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/parser/CssParser.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/parser/CssParser.java index d9d4313e1d9..55092fa40e5 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/parser/CssParser.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/parser/CssParser.java @@ -18,19 +18,20 @@ import org.eclipse.e4.ui.css.core.impl.dom.CSSImportRuleImpl; import org.eclipse.e4.ui.css.core.impl.dom.CSSPropertyImpl; -import org.eclipse.e4.ui.css.core.impl.dom.CSSRuleListImpl; import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleDeclarationImpl; import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleRuleImpl; import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CssRule; import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssColor; import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssDimension; import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumber; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssOperator; import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssUnit; import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssValue; -import org.eclipse.e4.ui.css.core.impl.dom.MediaListImpl; import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors; import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors.Adjacent; import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors.And; @@ -47,9 +48,7 @@ import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors.Universal; import org.eclipse.e4.ui.css.core.impl.parser.CssTokenizer.Kind; import org.eclipse.e4.ui.css.core.impl.parser.CssTokenizer.Token; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.CSSValue; /** @@ -74,7 +73,7 @@ private CssParser(List tokens) { } /** Parse a complete style sheet. */ - public static CSSStyleSheet parseStyleSheet(String css) { + public static CSSStyleSheetImpl parseStyleSheet(String css) { return new CssParser(CssTokenizer.tokenize(css)).styleSheet(); } @@ -105,23 +104,21 @@ public static Selectors.SelectorList parseSelectors(String selectors) { // ---------- style sheet ---------- private CSSStyleSheetImpl styleSheet() { - CSSStyleSheetImpl sheet = new CSSStyleSheetImpl(); - CSSRuleListImpl rules = new CSSRuleListImpl(); - sheet.setRuleList(rules); + List rules = new ArrayList<>(); skipWhitespace(); while (peek().kind != Kind.EOF) { if (peek().kind == Kind.AT_KEYWORD) { - atRule(sheet, rules); + atRule(rules); } else { - styleRule(sheet, rules); + styleRule(rules); } skipWhitespace(); } - return sheet; + return new CSSStyleSheetImpl(rules); } - private void atRule(CSSStyleSheetImpl sheet, CSSRuleListImpl rules) { + private void atRule(List rules) { Token at = advance(); // AT_KEYWORD String name = at.text.toLowerCase(); if (name.equals("import")) { //$NON-NLS-1$ @@ -134,7 +131,7 @@ private void atRule(CSSStyleSheetImpl sheet, CSSRuleListImpl rules) { } discardUntilStatementEnd(); if (href != null) { - rules.add(new CSSImportRuleImpl(sheet, null, href, new MediaListImpl())); + rules.add(new CSSImportRuleImpl(href)); } } else { // @media / @font-face / @page / unknown: parse and discard. @@ -167,10 +164,10 @@ private void discardUntilStatementEnd() { } } - private void styleRule(CSSStyleSheetImpl sheet, CSSRuleListImpl rules) { + private void styleRule(List rules) { Selectors.SelectorList selectors = selectorList(); expect(Kind.LBRACE); - CSSStyleRuleImpl rule = new CSSStyleRuleImpl(sheet, null, selectors); + CSSStyleRuleImpl rule = new CSSStyleRuleImpl(selectors); CSSStyleDeclarationImpl declaration = new CSSStyleDeclarationImpl(rule); rule.setStyle(declaration); declarations(declaration); @@ -253,21 +250,21 @@ private CssPrimitive primitive() { return new CssNumber(token.number, token.integer); case DIMENSION: advance(); - return new CssDimension(token.number, dimensionType(token.unit), token.unit); + return new CssDimension(token.number, dimensionUnit(token.unit), token.unit); case PERCENTAGE: advance(); - return new CssDimension(token.number, CSSPrimitiveValue.CSS_PERCENTAGE, "%"); //$NON-NLS-1$ + return new CssDimension(token.number, CssUnit.PERCENT); case IDENT: advance(); return token.text.equalsIgnoreCase("inherit") //$NON-NLS-1$ - ? new CssText(CSSPrimitiveValue.CSS_INHERIT, "inherit") //$NON-NLS-1$ - : new CssText(CSSPrimitiveValue.CSS_IDENT, token.text); + ? new CssText(CssText.Kind.INHERIT, "inherit") //$NON-NLS-1$ + : new CssText(CssText.Kind.IDENT, token.text); case STRING: advance(); - return new CssText(CSSPrimitiveValue.CSS_STRING, token.text); + return new CssText(CssText.Kind.STRING, token.text); case URI: advance(); - return new CssText(CSSPrimitiveValue.CSS_URI, token.text); + return new CssText(CssText.Kind.URI, token.text); case HASH: advance(); return hexColor(token.text); @@ -283,23 +280,26 @@ private CssColor function(Token token) { throw error("Unsupported function in value: " + token.text + "()"); //$NON-NLS-1$ //$NON-NLS-2$ } advance(); // FUNCTION consumes the '(' - CssPrimitive red = component(); - CssPrimitive green = component(); - CssPrimitive blue = component(); + CssNumeric red = component(); + CssNumeric green = component(); + CssNumeric blue = component(); skipWhitespace(); expect(Kind.RPAREN); return new CssColor(red, green, blue); } /** One numeric component of an {@code rgb(...)} function, with the trailing comma skipped. */ - private CssPrimitive component() { + private CssNumeric component() { skipWhitespace(); CssPrimitive value = primitive(); + if (!(value instanceof CssNumeric numeric)) { + throw error("Expected a numeric component in rgb(): " + value.getCssText()); //$NON-NLS-1$ + } skipWhitespace(); if (peek().kind == Kind.COMMA) { advance(); } - return value; + return numeric; } private CssColor hexColor(String hex) { @@ -324,18 +324,18 @@ private int hexPair(char high, char low) { return Character.digit(high, 16) * 16 + Character.digit(low, 16); } - private static short dimensionType(String unit) { + private static CssUnit dimensionUnit(String unit) { return switch (unit.toLowerCase()) { - case "px" -> CSSPrimitiveValue.CSS_PX; //$NON-NLS-1$ - case "em" -> CSSPrimitiveValue.CSS_EMS; //$NON-NLS-1$ - case "ex" -> CSSPrimitiveValue.CSS_EXS; //$NON-NLS-1$ - case "cm" -> CSSPrimitiveValue.CSS_CM; //$NON-NLS-1$ - case "mm" -> CSSPrimitiveValue.CSS_MM; //$NON-NLS-1$ - case "in" -> CSSPrimitiveValue.CSS_IN; //$NON-NLS-1$ - case "pt" -> CSSPrimitiveValue.CSS_PT; //$NON-NLS-1$ - case "pc" -> CSSPrimitiveValue.CSS_PC; //$NON-NLS-1$ - case "deg" -> CSSPrimitiveValue.CSS_DEG; //$NON-NLS-1$ - default -> CSSPrimitiveValue.CSS_DIMENSION; + case "px" -> CssUnit.PX; //$NON-NLS-1$ + case "em" -> CssUnit.EM; //$NON-NLS-1$ + case "ex" -> CssUnit.EX; //$NON-NLS-1$ + case "cm" -> CssUnit.CM; //$NON-NLS-1$ + case "mm" -> CssUnit.MM; //$NON-NLS-1$ + case "in" -> CssUnit.IN; //$NON-NLS-1$ + case "pt" -> CssUnit.PT; //$NON-NLS-1$ + case "pc" -> CssUnit.PC; //$NON-NLS-1$ + case "deg" -> CssUnit.DEG; //$NON-NLS-1$ + default -> CssUnit.OTHER; }; } diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/resources/CSSResourcesHelpers.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/resources/CSSResourcesHelpers.java index 5e1ad1092b3..7a65c86ecac 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/resources/CSSResourcesHelpers.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/resources/CSSResourcesHelpers.java @@ -16,9 +16,10 @@ import org.eclipse.e4.ui.css.core.css2.CSS2ColorHelper; import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssColor; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.RGBColor; /** * CSS Resources Helper to manage {@link IResourcesRegistry}. @@ -29,8 +30,8 @@ public static String getCSSValueKey(CSSValue value) { if (value instanceof CSS2FontProperties) { return getCSSFontPropertiesKey((CSS2FontProperties) value); } - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - return getCSSPrimitiveValueKey((CSSPrimitiveValue) value); + if (value instanceof CssPrimitive primitive) { + return getCSSPrimitiveValueKey(primitive); } return null; } @@ -39,35 +40,39 @@ public static String getCSSValueKey(CSSValue value) { * Return the key of the CSSPrimitiveValue value which is * used to cache Resource into {@link IResourcesRegistry}. */ - public static String getCSSPrimitiveValueKey(CSSPrimitiveValue value) { - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_IDENT: - case CSSPrimitiveValue.CSS_URI: - String s = value.getStringValue(); - // Test if s is Color Name - if (CSS2ColorHelper.isColorName(s)) { - RGBColor rgbColor = CSS2ColorHelper.getRGBColor(s); - if (rgbColor != null) { - return getCSSRGBColorKey(rgbColor); + public static String getCSSPrimitiveValueKey(CssPrimitive value) { + if (value instanceof CssText text) { + switch (text.kind()) { + case IDENT: + case URI: + String s = text.value(); + // Test if s is Color Name + if (CSS2ColorHelper.isColorName(s)) { + CssColor rgbColor = CSS2ColorHelper.getRGBColor(s); + if (rgbColor != null) { + return getCSSRGBColorKey(rgbColor); + } } + return text.value(); + case STRING: + return text.getCssText(); + default: + return null; } - return value.getStringValue(); - case CSSPrimitiveValue.CSS_RGBCOLOR: - RGBColor rgbColor = value.getRGBColorValue(); - return getCSSRGBColorKey(rgbColor); - case CSSPrimitiveValue.CSS_STRING: - return value.getCssText(); + } + if (value instanceof CssColor color) { + return getCSSRGBColorKey(color); } return null; } - public static String getCSSRGBColorKey(RGBColor rgbColor) { + public static String getCSSRGBColorKey(CssColor rgbColor) { if (rgbColor == null) { return null; } - StringBuilder rgb = new StringBuilder().append((int) rgbColor.getGreen().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)).append("_"); - rgb.append((int) rgbColor.getRed().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)).append("_"); - rgb.append((int) rgbColor.getBlue().getFloatValue(CSSPrimitiveValue.CSS_NUMBER)).append(""); + StringBuilder rgb = new StringBuilder().append((int) rgbColor.green().value()).append("_"); + rgb.append((int) rgbColor.red().value()).append("_"); + rgb.append((int) rgbColor.blue().value()).append(""); return rgb.toString(); } @@ -76,11 +81,11 @@ public static String getCSSFontPropertiesKey(CSS2FontProperties fontProperties) + getCssText(fontProperties.getStyle()) + "_" + getCssText(fontProperties.getWeight()); } - private static String getCssText(CSSPrimitiveValue cssPrimitiveValue) { - if (cssPrimitiveValue != null) { - return cssPrimitiveValue.getCssText(); + private static String getCssText(CssPrimitive primitive) { + if (primitive != null) { + return primitive.getCssText(); } - return String.valueOf(cssPrimitiveValue); + return String.valueOf(primitive); } /** @@ -88,7 +93,7 @@ private static String getCssText(CSSPrimitiveValue cssPrimitiveValue) { * resourcesRegistry with CSSPrimitiveValue * value key. */ - public static Object getResource(IResourcesRegistry resourcesRegistry, Object type, CSSPrimitiveValue value) { + public static Object getResource(IResourcesRegistry resourcesRegistry, Object type, CssPrimitive value) { String key = getCSSPrimitiveValueKey(value); return getResource(resourcesRegistry, type, key); } @@ -112,7 +117,7 @@ public static Object getResource(IResourcesRegistry resourcesRegistry, Object ty * resourcesRegistry with CSSPrimitiveValue * value key. */ - public static void registerResource(IResourcesRegistry resourcesRegistry, Object type, CSSPrimitiveValue value, + public static void registerResource(IResourcesRegistry resourcesRegistry, Object type, CssPrimitive value, Object resource) { if (resourcesRegistry != null) { String key = getCSSPrimitiveValueKey(value); diff --git a/bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/internal/theme/ThemeEngine.java b/bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/internal/theme/ThemeEngine.java index 42a7a0639a5..98c84677b26 100644 --- a/bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/internal/theme/ThemeEngine.java +++ b/bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/internal/theme/ThemeEngine.java @@ -637,7 +637,7 @@ public CSSStyleDeclaration getStyle(Object widget) { if (context != null) { Element e = context.getElement(); if (e != null) { - return engine.getViewCSS().getComputedStyle(e, null); + return engine.computeStyle(e, null); } } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java index ed3b8786e3e..bafb10abdd9 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java @@ -26,7 +26,6 @@ import java.util.Objects; import java.util.regex.Pattern; import org.eclipse.e4.ui.css.core.css2.CSS2ColorHelper; -import org.eclipse.e4.ui.css.core.css2.CSS2RGBColorImpl; import org.eclipse.e4.ui.css.core.dom.properties.Gradient; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.internal.css.swt.ColorAndFontUtil; @@ -38,10 +37,14 @@ import org.eclipse.swt.graphics.RGBA; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssColor; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumber; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssUnit; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; -import org.w3c.dom.css.RGBColor; public class CSSSWTColorHelper { public static final String COLOR_DEFINITION_MARKER = "#"; @@ -52,27 +55,27 @@ public class CSSSWTColorHelper { /*--------------- SWT Color Helper -----------------*/ - public static Color getSWTColor(RGBColor rgbColor) { + public static Color getSWTColor(CssColor rgbColor) { RGBA rgb = getRGBA(rgbColor); return new Color(rgb); } public static Color getSWTColor(CSSValue value, Display display) { - if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) { + if (!(value instanceof CssPrimitive primitive)) { return null; } Color color = display.getSystemColor(SWT.COLOR_BLACK); - RGBA rgba = getRGBA((CSSPrimitiveValue) value, display); + RGBA rgba = getRGBA(primitive, display); if (rgba != null) { color = new Color(rgba.rgb.red, rgba.rgb.green, rgba.rgb.blue, rgba.alpha); } return color; } - private static RGBA getRGBA(CSSPrimitiveValue value, Display display) { + private static RGBA getRGBA(CssPrimitive value, Display display) { RGBA rgba = getRGBA(value); - if (rgba == null && display != null) { - String name = value.getStringValue(); + if (rgba == null && display != null && value instanceof CssText text) { + String name = text.value(); if (hasColorDefinitionAsValue(name)) { rgba = findColorByDefinition(name); } else if (name.contains("-")) { @@ -87,12 +90,8 @@ private static RGBA getRGBA(CSSPrimitiveValue value, Display display) { } public static boolean hasColorDefinitionAsValue(CSSValue value) { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value; - if (primitiveValue.getPrimitiveType() == CSSPrimitiveValue.CSS_STRING) { - return hasColorDefinitionAsValue(primitiveValue - .getStringValue()); - } + if (value instanceof CssText text && text.kind() == CssText.Kind.STRING) { + return hasColorDefinitionAsValue(text.value()); } return false; } @@ -155,7 +154,7 @@ private static Field[] getFields() { } public static RGBA getRGBA(String name) { - RGBColor color = CSS2ColorHelper.getRGBColor(name); + CssColor color = CSS2ColorHelper.getRGBColor(name); if (color != null) { return getRGBA(color); } @@ -173,104 +172,87 @@ public static RGBA getRGBA(String name) { return null; } - public static RGBA getRGBA(RGBColor color) { - return new RGBA((int) color.getRed().getFloatValue( - CSSPrimitiveValue.CSS_NUMBER), (int) color.getGreen() - .getFloatValue(CSSPrimitiveValue.CSS_NUMBER), (int) color - .getBlue().getFloatValue(CSSPrimitiveValue.CSS_NUMBER), - // for now, we only support solid RGB colors in CSS - our CSS model - // as of now does not have an element for RGBAColor. - 255); + public static RGBA getRGBA(CssColor color) { + // for now, we only support solid RGB colors in CSS - our CSS model + // as of now does not have an element for RGBAColor. + return new RGBA((int) color.red().value(), (int) color.green().value(), (int) color.blue().value(), 255); } public static RGBA getRGBA(CSSValue value) { - if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) { + if (!(value instanceof CssPrimitive primitive)) { return null; } - return getRGBA((CSSPrimitiveValue) value); + return getRGBA(primitive); } - public static RGBA getRGBA(CSSPrimitiveValue value) { - RGBA rgba = null; - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_IDENT: - case CSSPrimitiveValue.CSS_STRING: - String string = value.getStringValue(); - rgba = getRGBA(string); - break; - case CSSPrimitiveValue.CSS_RGBCOLOR: - RGBColor rgbColor = value.getRGBColorValue(); - rgba = getRGBA(rgbColor); - break; + public static RGBA getRGBA(CssPrimitive value) { + if (value instanceof CssText text + && (text.kind() == CssText.Kind.IDENT || text.kind() == CssText.Kind.STRING)) { + return getRGBA(text.value()); } - return rgba; + if (value instanceof CssColor color) { + return getRGBA(color); + } + return null; } - public static Integer getPercent(CSSPrimitiveValue value) { + public static Integer getPercent(CssPrimitive value) { int percent = 0; - switch (value.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_PERCENTAGE: - percent = (int) value - .getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE); + if (value instanceof CssNumeric numeric && numeric.unit() == CssUnit.PERCENT) { + percent = (int) numeric.value(); } return Integer.valueOf(percent); } - public static Gradient getGradient(CSSValueList list, Display display) { + public static Gradient getGradient(CssList list, Display display) { Gradient gradient = new Gradient(); - for (int i = 0; i < list.getLength(); i++) { - CSSValue value = list.item(i); - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - short primType = ((CSSPrimitiveValue) value).getPrimitiveType(); - - if (primType == CSSPrimitiveValue.CSS_IDENT) { - switch (value.getCssText()) { - case "gradient": - // Skip the keyword "gradient" - continue; - case "linear": - gradient.setLinear(true); - continue; - case "radial": - gradient.setLinear(false); - continue; - default: - break; - } + for (CSSValue value : list.values()) { + if (!(value instanceof CssPrimitive primitive)) { + continue; + } + boolean isIdent = primitive instanceof CssText text && text.kind() == CssText.Kind.IDENT; + if (isIdent) { + switch (value.getCssText()) { + case "gradient": + // Skip the keyword "gradient" + continue; + case "linear": + gradient.setLinear(true); + continue; + case "radial": + gradient.setLinear(false); + continue; + default: + break; } + } - switch (primType) { - case CSSPrimitiveValue.CSS_IDENT: - case CSSPrimitiveValue.CSS_STRING: - case CSSPrimitiveValue.CSS_RGBCOLOR: - RGBA rgba = getRGBA((CSSPrimitiveValue) value, display); - if (rgba != null) { - // note that in this call we lose the RGBA alpha - // component - we do currently not support alpha - // gradients - gradient.addRGB(rgba, (CSSPrimitiveValue) value); - } else { - //check for vertical gradient - gradient.setVertical(!value.getCssText().equals("false")); - } - break; - case CSSPrimitiveValue.CSS_PERCENTAGE: - gradient.addPercent(getPercent((CSSPrimitiveValue) value)); - break; + if (isIdent || primitive instanceof CssColor + || (primitive instanceof CssText text && text.kind() == CssText.Kind.STRING)) { + RGBA rgba = getRGBA(primitive, display); + if (rgba != null) { + // note that in this call we lose the RGBA alpha + // component - we do currently not support alpha + // gradients + gradient.addRGB(rgba, primitive); + } else { + // check for vertical gradient + gradient.setVertical(!value.getCssText().equals("false")); } + } else if (primitive instanceof CssNumeric numeric && numeric.unit() == CssUnit.PERCENT) { + gradient.addPercent(getPercent(numeric)); } } return gradient; } - @SuppressWarnings("rawtypes") public static Color[] getSWTColors(Gradient grad, Display display, CSSEngine engine) throws Exception { - List values = grad.getValues(); + List values = grad.getValues(); Color[] colors = new Color[values.size()]; for (int i = 0; i < values.size(); i++) { - CSSPrimitiveValue value = (CSSPrimitiveValue) values.get(i); + CssPrimitive value = values.get(i); //We rely on the fact that when a gradient is created, it's colors are converted and in the registry //TODO see bug #278077 Color color = (Color) engine.convert(value, Color.class, display); @@ -325,18 +307,14 @@ private static int[] getDefaultPercents(Gradient grad) { return percents; } - public static RGBColor getRGBColor(Color color) { - int red = color.getRed(); - int green = color.getGreen(); - int blue = color.getBlue(); - return new CSS2RGBColorImpl(red, green, blue); + public static CssColor getRGBColor(Color color) { + return new CssColor(new CssNumber(color.getRed(), true), new CssNumber(color.getGreen(), true), + new CssNumber(color.getBlue(), true)); } - public static RGBColor getRGBColor(RGB color) { - int red = color.red; - int green = color.green; - int blue = color.blue; - return new CSS2RGBColorImpl(red, green, blue); + public static CssColor getRGBColor(RGB color) { + return new CssColor(new CssNumber(color.red, true), new CssNumber(color.green, true), + new CssNumber(color.blue, true)); } private static RGBA findColorByDefinition(String name) { diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTCursorHelper.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTCursorHelper.java index eb3beb4574b..f87a3f9d7ea 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTCursorHelper.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTCursorHelper.java @@ -18,7 +18,7 @@ import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.w3c.dom.css.CSSValue; public class CSSSWTCursorHelper { @@ -29,10 +29,10 @@ public class CSSSWTCursorHelper { * "http://www.w3schools.com/css/pr_class_cursor.asp">http://www.w3schools.com/css/pr_class_cursor.asp */ public static Cursor getSWTCursor(CSSValue value, Display display) { - if (!(value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) { + if (!(value instanceof CssText text)) { return null; } - int i = getSWTCursorId((CSSPrimitiveValue) value); + int i = getSWTCursorId(text); if (i == SWT.NONE) { return null; } @@ -101,8 +101,8 @@ public static String getCSSCursor(Cursor cursor) { return "auto"; } - public static int getSWTCursorId(CSSPrimitiveValue value) { - String cursorName = value.getStringValue(); + public static int getSWTCursorId(CssText value) { + String cursorName = value.value(); switch (cursorName) { case "default": // The default cursor (often an arrow) diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java index fcda1ee1547..ee4ab3f264f 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java @@ -19,7 +19,10 @@ import org.eclipse.e4.ui.css.core.css2.CSS2FontHelper; import org.eclipse.e4.ui.css.core.css2.CSS2FontPropertiesHelpers; -import org.eclipse.e4.ui.css.core.css2.CSS2PrimitiveValueImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumber; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties; import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontPropertiesImpl; import org.eclipse.e4.ui.css.core.engine.CSSElementContext; @@ -32,7 +35,6 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Widget; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; /** @@ -107,16 +109,17 @@ public static CSS2FontProperties getCSS2FontProperties(Font font) { FontData fontData = getFirstFontData(font); // Update font-family String fontFamily = getFontFamily(font); - fontProperties.setFamily(new CSS2PrimitiveValueImpl(fontFamily)); - // Update font-size + fontProperties.setFamily(new CssText(CssText.Kind.IDENT, fontFamily)); + // Update font-size; mirrors the widget font, not a CSS declaration int fontSize = fontData.getHeight(); - fontProperties.setSize(new CSS2PrimitiveValueImpl(fontSize)); + fontProperties.setSize(new CssNumber(fontSize, true)); + fontProperties.setSizeFromCSS(false); // Update font-weight String fontWeight = getFontWeight(font); - fontProperties.setWeight((new CSS2PrimitiveValueImpl(fontWeight))); + fontProperties.setWeight(new CssText(CssText.Kind.IDENT, fontWeight)); // Update font-style String fontStyle = getFontStyle(font); - fontProperties.setStyle((new CSS2PrimitiveValueImpl(fontStyle))); + fontProperties.setStyle(new CssText(CssText.Kind.IDENT, fontStyle)); } return fontProperties; } @@ -144,17 +147,17 @@ public static FontData getFontData(CSS2FontProperties fontProperties, FontData o FontData newFontData = new FontData(); // Family - CSSPrimitiveValue cssFontFamily = fontProperties.getFamily(); + CssPrimitive cssFontFamily = fontProperties.getFamily(); FontData[] fontDataByDefinition = new FontData[0]; boolean fontDefinitionAsFamily = hasFontDefinitionAsFamily(fontProperties); if (fontDefinitionAsFamily) { - fontDataByDefinition = findFontDataByDefinition(cssFontFamily); + fontDataByDefinition = findFontDataByDefinition((CssText) cssFontFamily); if (fontDataByDefinition.length > 0) { newFontData.setName(fontDataByDefinition[0].getName()); } - } else if (cssFontFamily != null) { - newFontData.setName(cssFontFamily.getStringValue()); + } else if (cssFontFamily instanceof CssText family) { + newFontData.setName(family.value()); } boolean fontFamilySet = newFontData.getName() != null && newFontData.getName().trim().length() > 0; @@ -175,16 +178,16 @@ public static FontData getFontData(CSS2FontProperties fontProperties, FontData o newFontData.setStyle(style); // Height - CSSPrimitiveValue cssFontSize = fontProperties.getSize(); + CssPrimitive cssFontSize = fontProperties.getSize(); boolean fontHeightSet = false; - if (cssFontSize == null || cssFontSize.getCssText() == null) { + if (!(cssFontSize instanceof CssNumeric) || !fontProperties.isSizeFromCSS()) { if (fontDefinitionAsFamily && fontDataByDefinition.length > 0) { newFontData.setHeight(fontDataByDefinition[0].getHeight()); fontHeightSet = true; } } else { - newFontData.setHeight((int) (cssFontSize).getFloatValue(CSSPrimitiveValue.CSS_PT)); + newFontData.setHeight((int) ((CssNumeric) cssFontSize).value()); fontHeightSet = true; } if (!fontHeightSet && oldFontData != null) { @@ -196,18 +199,17 @@ public static FontData getFontData(CSS2FontProperties fontProperties, FontData o public static boolean hasFontDefinitionAsFamily(CSSValue value) { if (value instanceof CSS2FontProperties props) { - return props.getFamily() != null - && props.getFamily().getStringValue() - .startsWith(FONT_DEFINITION_MARKER); + return props.getFamily() instanceof CssText family + && family.value().startsWith(FONT_DEFINITION_MARKER); } return false; } - private static FontData[] findFontDataByDefinition(CSSPrimitiveValue cssFontFamily) { + private static FontData[] findFontDataByDefinition(CssText cssFontFamily) { IColorAndFontProvider provider = ColorAndFontUtil.getColorAndFontProvider(); FontData[] result = new FontData[0]; if (provider != null) { - FontData[] fontData = provider.getFont(normalizeId(cssFontFamily.getStringValue().substring(1))); + FontData[] fontData = provider.getFont(normalizeId(cssFontFamily.value().substring(1))); if (fontData != null) { result = fontData; } @@ -227,9 +229,9 @@ public static int getSWTStyle(CSS2FontProperties fontProperties, } // CSS2 font-style - CSSPrimitiveValue cssFontStyle = fontProperties.getStyle(); - if (cssFontStyle != null) { - String style = cssFontStyle.getStringValue(); + CssPrimitive cssFontStyle = fontProperties.getStyle(); + if (cssFontStyle instanceof CssText styleText) { + String style = styleText.value(); if ("italic".equals(style)) { fontStyle = fontStyle | SWT.ITALIC; } else if (fontStyle == (fontStyle | SWT.ITALIC)) { @@ -237,9 +239,9 @@ public static int getSWTStyle(CSS2FontProperties fontProperties, } } // CSS font-weight - CSSPrimitiveValue cssFontWeight = fontProperties.getWeight(); - if (cssFontWeight != null) { - String weight = cssFontWeight.getStringValue(); + CssPrimitive cssFontWeight = fontProperties.getWeight(); + if (cssFontWeight instanceof CssText weightText) { + String weight = weightText.value(); if ("bold".equals(weight.toLowerCase())) { fontStyle = fontStyle | SWT.BOLD; } else if (fontStyle == (fontStyle | SWT.BOLD)) { diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelpers.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelpers.java index 95ca3729f99..e73a9d6995a 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelpers.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelpers.java @@ -23,7 +23,7 @@ import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Control; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.w3c.dom.css.CSSValue; /** @@ -72,7 +72,7 @@ public void paintControl(PaintEvent e) { } int width = border.getWidth(); GC gc = e.gc; - CSSPrimitiveValue value = border.getColor(); + CssPrimitive value = border.getColor(); if (value == null) { return; } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTImageHelper.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTImageHelper.java index f6bdcfc892c..7848ab0b603 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTImageHelper.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTImageHelper.java @@ -26,7 +26,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.swt.widgets.Widget; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.w3c.dom.css.CSSValue; public class CSSSWTImageHelper { @@ -38,14 +38,8 @@ public class CSSSWTImageHelper { public static Image getImage(CSSValue value, IResourcesLocatorManager manager, Display display) throws Exception { - if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) { - return null; - } - CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value; - switch (primitiveValue.getPrimitiveType()) { - case CSSPrimitiveValue.CSS_URI: - String path = primitiveValue.getStringValue(); - return loadImageFromURL(path, manager); + if (value instanceof CssText text && text.kind() == CssText.Kind.URI) { + return loadImageFromURL(text.value(), manager); } return null; } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTColorConverterImpl.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTColorConverterImpl.java index 34c13f62958..4b197feab29 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTColorConverterImpl.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTColorConverterImpl.java @@ -23,9 +23,9 @@ import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssColor; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.RGBColor; /** * CSS Value converter to convert : @@ -59,7 +59,7 @@ public Color convert(CSSValue value, CSSEngine engine, Object context) public String convert(Object value, CSSEngine engine, Object context, ICSSValueConverterConfig config) throws Exception { Color color = (Color) value; - RGBColor rgbColor = CSSSWTColorHelper.getRGBColor(color); + CssColor rgbColor = CSSSWTColorHelper.getRGBColor(color); return CSS2ColorHelper.getColorStringValue(rgbColor); } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTGradientConverterImpl.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTGradientConverterImpl.java index c16024654d5..6c63df48f66 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTGradientConverterImpl.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTGradientConverterImpl.java @@ -23,9 +23,9 @@ import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; -import org.w3c.dom.css.CSSPrimitiveValue; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; /** * CSS Value converter to convert : @@ -44,14 +44,13 @@ public CSSValueSWTGradientConverterImpl() { @Override public Object convert(CSSValue value, CSSEngine engine, Object context) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { + if (value instanceof CssList list) { Display display = (context instanceof Display d) ? d : null; - Gradient grad = CSSSWTColorHelper.getGradient((CSSValueList) value, display); - List values = grad.getValues(); - for (int i = 0; i < values.size(); i++) { + Gradient grad = CSSSWTColorHelper.getGradient(list, display); + List values = grad.getValues(); + for (CssPrimitive prim : values) { //Ensure all the colors are already converted and in the registry //TODO see bug #278077 - CSSPrimitiveValue prim = (CSSPrimitiveValue) values.get(i); engine.convert(prim, Color.class, context); } return grad; diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTRGBConverterImpl.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTRGBConverterImpl.java index c951aa8ee87..4fedb2d7655 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTRGBConverterImpl.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTRGBConverterImpl.java @@ -21,8 +21,8 @@ import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper; import org.eclipse.swt.graphics.RGB; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssColor; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.RGBColor; /** * CSS Value converter to convert : @@ -52,7 +52,7 @@ public Object convert(CSSValue value, CSSEngine engine, Object context) public String convert(Object value, CSSEngine engine, Object context, ICSSValueConverterConfig config) throws Exception { RGB color = (RGB) value; - RGBColor rgbColor = CSSSWTColorHelper.getRGBColor(color); + CssColor rgbColor = CSSSWTColorHelper.getRGBColor(color); return CSS2ColorHelper.getColorStringValue(rgbColor); } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBackgroundSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBackgroundSWTHandler.java index 14ace740aa8..35267a7575f 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBackgroundSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBackgroundSWTHandler.java @@ -14,6 +14,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.css2; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.dom.properties.Gradient; import org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyBackgroundHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; @@ -59,8 +61,7 @@ public String retrieveCSSProperty(Object element, String property, public void applyCSSPropertyBackgroundColor(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { Widget widget = (Widget) ((WidgetElement) element).getNativeWidget(); - switch (value.getCssValueType()) { - case CSSValue.CSS_PRIMITIVE_VALUE: + if (value instanceof CssPrimitive) { Color newColor = (Color) engine.convert(value, Color.class, widget .getDisplay()); if (widget instanceof CTabItem) { @@ -79,8 +80,7 @@ public void applyCSSPropertyBackgroundColor(Object element, CSSValue value, CSSSWTColorHelper.setBackground((Control) widget, newColor); CompositeElement.setBackgroundOverriddenByCSSMarker(widget); } - break; - case CSSValue.CSS_VALUE_LIST: + } else if (value instanceof CssList) { Gradient grad = (Gradient) engine.convert(value, Gradient.class, widget.getDisplay()); if (grad == null) { @@ -102,9 +102,6 @@ public void applyCSSPropertyBackgroundColor(Object element, CSSValue value, GradientBackgroundListener.handle((Control) widget, grad); CompositeElement.setBackgroundOverriddenByCSSMarker(widget); } - break; - default: - break; } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBorderSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBorderSWTHandler.java index e7a4c6d0802..7c523d54bec 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBorderSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBorderSWTHandler.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.css2; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; import org.eclipse.e4.ui.css.core.dom.properties.CSSBorderProperties; import org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyBorderHandler; import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyBorderHandler; @@ -24,7 +25,6 @@ import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; public class CSSPropertyBorderSWTHandler extends AbstractCSSPropertyBorderHandler { @@ -50,9 +50,8 @@ public boolean applyCSSProperty(Object element, String property, .createBorderPaintListener(engine, control)); } super.applyCSSProperty(border, property, value, pseudo, engine); - if((parent.getData("CSS_SUPPORTS_BORDERS") != null) && - (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) { - int pixelValue = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PT); + if ((parent.getData("CSS_SUPPORTS_BORDERS") != null) && value instanceof CssNumeric numeric) { + int pixelValue = (int) numeric.value(); if(property.equals("border-width")) { ((FillLayout) parent.getLayout()).marginWidth = pixelValue; ((FillLayout) parent.getLayout()).marginHeight = pixelValue; diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyClassificationSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyClassificationSWTHandler.java index 89aee40539b..40476e04a7b 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyClassificationSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyClassificationSWTHandler.java @@ -14,6 +14,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.css2; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyClassificationHandler; import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyClassificationHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; @@ -21,7 +23,6 @@ import org.eclipse.e4.ui.css.swt.helpers.SWTElementHelpers; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.widgets.Control; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; public class CSSPropertyClassificationSWTHandler extends @@ -53,7 +54,7 @@ public String retrieveCSSProperty(Object element, String property, @Override public void applyCSSPropertyCursor(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { final Control control = (Control) element; Cursor cursor = (Cursor) engine.convert(value, Cursor.class, control.getDisplay()); @@ -65,10 +66,9 @@ public void applyCSSPropertyCursor(Object element, CSSValue value, @Override public void applyCSSPropertyVisibility(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssText text) { Control control = (Control) element; - CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value; - String visibility = primitiveValue.getStringValue(); + String visibility = text.value(); switch (visibility) { case "hidden": case "collapse": diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyFontSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyFontSWTHandler.java index a5a6afe595b..4fbc09eeb70 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyFontSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyFontSWTHandler.java @@ -348,8 +348,7 @@ private void applyStyles(CSSStyleDeclaration styleDeclaration, */ private void styleUnselected(Item[] items) { for (Item item : items) { - CSSStyleDeclaration unselectedStyle = engine.getViewCSS() - .getComputedStyle(engine.getElement(item), null); + CSSStyleDeclaration unselectedStyle = engine.computeStyle(engine.getElement(item), null); if (unselectedStyle == null) { // no styles defined, just reset the font setFont(item, null); @@ -367,8 +366,7 @@ private void styleUnselected(Item[] items) { * the item to style */ private boolean styleSelected(Item selection) { - CSSStyleDeclaration selectedStyle = engine.getViewCSS() - .getComputedStyle(engine.getElement(selection), "selected"); + CSSStyleDeclaration selectedStyle = engine.computeStyle(engine.getElement(selection), "selected"); if (selectedStyle == null) { return false; } @@ -380,6 +378,7 @@ private boolean styleSelected(Item selection) { private void reset(CSS2FontProperties properties) { properties.setFamily(null); properties.setSize(null); + properties.setSizeFromCSS(false); properties.setSizeAdjust(null); properties.setWeight(null); properties.setStyle(null); diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyMarginSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyMarginSWTHandler.java index 2f2a243b260..b349af5277d 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyMarginSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyMarginSWTHandler.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.css2; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyMarginHandler; import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyMarginHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; @@ -23,9 +26,7 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.Widget; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; public class CSSPropertyMarginSWTHandler extends AbstractCSSPropertyMarginHandler { @@ -49,7 +50,7 @@ public void applyCSSPropertyMargin(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { // If single value then assigned to all four margins - if(value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { setMargin(element, TOP, value); setMargin(element, RIGHT, value); setMargin(element, BOTTOM, value); @@ -57,8 +58,7 @@ public void applyCSSPropertyMargin(Object element, CSSValue value, return; } - if(value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - CSSValueList valueList = (CSSValueList) value; + if (value instanceof CssList valueList) { int length = valueList.getLength(); if(length < 2 || length > 4) { @@ -170,10 +170,10 @@ private GridLayout getLayout(Control control) { } private void setMargin(Object element, int side, CSSValue value) { - if(value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) { + if (!(value instanceof CssNumeric numeric)) { return; } - int pixelValue = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PX); + int pixelValue = (int) numeric.value(); Widget widget = SWTElementHelpers.getWidget(element); diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyPaddingSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyPaddingSWTHandler.java index e42c7659b9a..fb30957e78d 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyPaddingSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyPaddingSWTHandler.java @@ -15,6 +15,10 @@ package org.eclipse.e4.ui.css.swt.properties.css2; import java.lang.reflect.Method; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssUnit; import org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyPaddingHandler; import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2PaddingPropertiesImpl; import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyPaddingHandler; @@ -24,9 +28,7 @@ import org.eclipse.swt.custom.CTabFolderRenderer; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Widget; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; public class CSSPropertyPaddingSWTHandler extends AbstractCSSPropertyPaddingHandler { @@ -50,14 +52,13 @@ public void applyCSSPropertyPadding(Object element, CSSValue value, CSS2PaddingPropertiesImpl padding = new CSS2PaddingPropertiesImpl(); // If single value then assigned to all four paddings - if(value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { padding.top = padding.bottom = padding.left = padding.right = value; setPadding(element, padding); return; } - if(value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - CSSValueList valueList = (CSSValueList) value; + if (value instanceof CssList valueList) { int length = valueList.getLength(); if(length < 2 || length > 4) { @@ -97,7 +98,7 @@ public void applyCSSPropertyPadding(Object element, CSSValue value, public void applyCSSPropertyPaddingTop(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { CSS2PaddingPropertiesImpl padding = new CSS2PaddingPropertiesImpl(); - if(value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { padding.top = value; setPadding(element, padding); } @@ -107,7 +108,7 @@ public void applyCSSPropertyPaddingTop(Object element, CSSValue value, public void applyCSSPropertyPaddingRight(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { CSS2PaddingPropertiesImpl padding = new CSS2PaddingPropertiesImpl(); - if(value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { padding.right = value; setPadding(element, padding); } @@ -117,7 +118,7 @@ public void applyCSSPropertyPaddingRight(Object element, CSSValue value, public void applyCSSPropertyPaddingBottom(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { CSS2PaddingPropertiesImpl padding = new CSS2PaddingPropertiesImpl(); - if(value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { padding.bottom = value; setPadding(element, padding); } @@ -127,7 +128,7 @@ public void applyCSSPropertyPaddingBottom(Object element, CSSValue value, public void applyCSSPropertyPaddingLeft(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception { CSS2PaddingPropertiesImpl padding = new CSS2PaddingPropertiesImpl(); - if(value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { padding.left = value; setPadding(element, padding); } @@ -190,20 +191,20 @@ private void setPadding(Object element, CSSValue value) { int top = pad.x, right = pad.y, bottom = pad.width, left = pad.height; - if (vTop != null && (vTop.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) && ((CSSPrimitiveValue) vTop).getPrimitiveType() == CSSPrimitiveValue.CSS_PX) { - top = (int) ((CSSPrimitiveValue) vTop).getFloatValue(CSSPrimitiveValue.CSS_PX); + if (vTop instanceof CssNumeric numeric && numeric.unit() == CssUnit.PX) { + top = (int) numeric.value(); } - if (vRight != null && (vRight.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) && ((CSSPrimitiveValue) vRight).getPrimitiveType() == CSSPrimitiveValue.CSS_PX) { - right = (int) ((CSSPrimitiveValue) vRight).getFloatValue(CSSPrimitiveValue.CSS_PX); + if (vRight instanceof CssNumeric numeric && numeric.unit() == CssUnit.PX) { + right = (int) numeric.value(); } - if (vBottom != null && (vBottom.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) && ((CSSPrimitiveValue) vBottom).getPrimitiveType() == CSSPrimitiveValue.CSS_PX) { - bottom = (int) ((CSSPrimitiveValue) vBottom).getFloatValue(CSSPrimitiveValue.CSS_PX); + if (vBottom instanceof CssNumeric numeric && numeric.unit() == CssUnit.PX) { + bottom = (int) numeric.value(); } - if (vLeft != null && (vLeft.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) && ((CSSPrimitiveValue) vLeft).getPrimitiveType() == CSSPrimitiveValue.CSS_PX) { - left = (int) ((CSSPrimitiveValue) vLeft).getFloatValue(CSSPrimitiveValue.CSS_PX); + if (vLeft instanceof CssNumeric numeric && numeric.unit() == CssUnit.PX) { + left = (int) numeric.value(); } if (top != pad.x || right != pad.y || bottom != pad.width diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyTextSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyTextSWTHandler.java index 239f8b13405..cabd2c44d95 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyTextSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyTextSWTHandler.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.css2; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyTextHandler; import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyTextHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; @@ -61,7 +62,7 @@ public void applyCSSPropertyColor(Object element, CSSValue value, Widget widget = (Widget) element; Color newColor = (Color) engine.convert(value, Color.class, widget.getDisplay()); - if (newColor != null && newColor.isDisposed() || value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) { + if (newColor != null && newColor.isDisposed() || !(value instanceof CssPrimitive)) { return; } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSBackgroundModePropertyHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSBackgroundModePropertyHandler.java index c7044a63a1b..7d3898df7bc 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSBackgroundModePropertyHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSBackgroundModePropertyHandler.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.swt.SWT; @@ -26,7 +27,7 @@ public class CSSBackgroundModePropertyHandler extends @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE || !(control instanceof Composite composite)) { + if (!(value instanceof CssPrimitive) || !(control instanceof Composite composite)) { return; } String stringValue = value.getCssText().toLowerCase(); diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCustomTabContentBackgroundSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCustomTabContentBackgroundSWTHandler.java index 82c79184300..e36c94495db 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCustomTabContentBackgroundSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCustomTabContentBackgroundSWTHandler.java @@ -11,6 +11,7 @@ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; @@ -24,7 +25,7 @@ public class CSSPropertyCustomTabContentBackgroundSWTHandler extends @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder tabFolder) || value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) { + if (!(control instanceof CTabFolder tabFolder) || !(value instanceof CssPrimitive)) { return; } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyHeaderHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyHeaderHandler.java index 792f0ccaf11..626d8114980 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyHeaderHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyHeaderHandler.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.dom.ElementAdapter; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; @@ -45,12 +46,12 @@ public boolean applyCSSProperty(Object element, String property, CSSValue value, private boolean setHeaderColor(String property, CSSValue value, CSSEngine engine, IHeaderCustomizationElement headerCustomizationElement, Widget widget) throws Exception { if (SWT_HEADER_COLOR.equals(property) - && value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + && value instanceof CssPrimitive) { Color newColor = (Color) engine.convert(value, Color.class, widget.getDisplay()); headerCustomizationElement.setHeaderColor(newColor); return true; } else if (SWT_HEADER_BACKGROUND_COLOR.equals(property) - && value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + && value instanceof CssPrimitive) { Color newColor = (Color) engine.convert(value, Color.class, widget.getDisplay()); headerCustomizationElement.setHeaderBackgroundColor(newColor); return true; diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java index 2d32f50032d..12febe5d802 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; @@ -30,7 +31,7 @@ protected void applyCSSProperty(Control control, String property, if (!(control instanceof CTabFolder)) { return; } - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay()); CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); if (renderer instanceof ICTabRendering) { diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyLinesVisibleSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyLinesVisibleSWTHandler.java index ece7133d699..35d34a19769 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyLinesVisibleSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyLinesVisibleSWTHandler.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.swt.widgets.Control; @@ -25,7 +26,7 @@ public class CSSPropertyLinesVisibleSWTHandler extends AbstractCSSPropertySWTHan @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { boolean linesVisible = (Boolean) engine.convert(value, Boolean.class, control.getDisplay()); if (control instanceof Table) { ((Table) control).setLinesVisible(linesVisible); diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyLinkSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyLinkSWTHandler.java index 4ce5a58d0b6..86981715661 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyLinkSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyLinkSWTHandler.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.dom.LinkElement; @@ -32,7 +33,7 @@ public boolean applyCSSProperty(Object element, String property, CSSValue value, if (!(element instanceof LinkElement)) { return false; } - if (!(value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) { + if (!(value instanceof CssPrimitive)) { return false; } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java index 6e98801d0b8..c7626a40afe 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; @@ -30,7 +31,7 @@ protected void applyCSSProperty(Control control, String property, if (!(control instanceof CTabFolder)) { return; } - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay()); CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); if (renderer instanceof ICTabRendering) { diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertySelectedTabsSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertySelectedTabsSWTHandler.java index 5e5bf757bed..62aa575ad3f 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertySelectedTabsSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertySelectedTabsSWTHandler.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; import org.eclipse.e4.ui.css.core.dom.properties.Gradient; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper; @@ -30,7 +31,7 @@ protected void applyCSSProperty(Control control, String property, if (!(control instanceof CTabFolder folder)) { return; } - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { + if (value instanceof CssList) { Gradient grad = (Gradient) engine.convert(value, Gradient.class, control.getDisplay()); if (grad.getValues().isEmpty()) { folder.setSelectionBackground(null, null, true); diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabHeightHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabHeightHandler.java index 5b95e65566d..223cd054a37 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabHeightHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabHeightHandler.java @@ -12,11 +12,12 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumeric; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssUnit; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.widgets.Control; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; public class CSSPropertyTabHeightHandler extends @@ -29,9 +30,8 @@ protected void applyCSSProperty(Control control, String property, return; } - if ((value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) && - ( ((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_PX) ) { - int height = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PX); + if (value instanceof CssNumeric numeric && numeric.unit() == CssUnit.PX) { + int height = (int) numeric.value(); ((CTabFolder) control).setTabHeight(height); } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabPositionSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabPositionSWTHandler.java index 95a8f74dd83..3a51caa674f 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabPositionSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabPositionSWTHandler.java @@ -15,12 +15,12 @@ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.widgets.Control; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; public class CSSPropertyTabPositionSWTHandler extends @@ -29,12 +29,12 @@ public class CSSPropertyTabPositionSWTHandler extends @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder tabFolder) || value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE - || ((CSSPrimitiveValue) value).getPrimitiveType() != CSSPrimitiveValue.CSS_IDENT) { + if (!(control instanceof CTabFolder tabFolder) || !(value instanceof CssText text) + || text.kind() != CssText.Kind.IDENT) { return; } - String position = ((CSSPrimitiveValue) value).getStringValue(); + String position = text.value(); switch (position.toLowerCase()) { case "bottom": tabFolder.setTabPosition(SWT.BOTTOM); diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabRendererSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabRendererSWTHandler.java index d3e5cd313ba..96bb01c1d7d 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabRendererSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabRendererSWTHandler.java @@ -17,13 +17,14 @@ import java.net.URI; import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.Platform; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolderRenderer; import org.eclipse.swt.widgets.Control; import org.osgi.framework.Bundle; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; public class CSSPropertyTabRendererSWTHandler extends AbstractCSSPropertySWTHandler { @@ -34,9 +35,9 @@ protected void applyCSSProperty(Control control, String property, if (!(control instanceof CTabFolder tabFolder)) { return; } - if (value instanceof CSSPrimitiveValue primitiveValue) { - if (primitiveValue.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) { - String rendURL = primitiveValue.getStringValue(); + if (value instanceof CssPrimitive) { + if (value instanceof CssText text && text.kind() == CssText.Kind.URI) { + String rendURL = text.value(); URI uri = new URI(rendURL); Bundle bundle = Platform.getBundle(uri.getAuthority()); String[] segments = getPathSegments(uri); diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabTextMinimumCharactersSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabTextMinimumCharactersSWTHandler.java index 8b9d4e703cb..acf837a68e7 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabTextMinimumCharactersSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabTextMinimumCharactersSWTHandler.java @@ -12,11 +12,11 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumber; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.widgets.Control; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; /** @@ -36,9 +36,8 @@ protected void applyCSSProperty(Control control, String property, CSSValue value return; } - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE - && (((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_NUMBER)) { - int minimumCharacters = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_NUMBER); + if (value instanceof CssNumber number) { + int minimumCharacters = (int) number.value(); folder.setMinimumCharacters(minimumCharacters); } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectHotTabsColorBackgroundHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectHotTabsColorBackgroundHandler.java index b7d88794d00..d076b719eb7 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectHotTabsColorBackgroundHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectHotTabsColorBackgroundHandler.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; @@ -29,7 +30,7 @@ public class CSSPropertyUnselectHotTabsColorBackgroundHandler extends AbstractCS @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder) || value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) { + if (!(control instanceof CTabFolder) || !(value instanceof CssPrimitive)) { return; } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java index 03a1f710986..f285d02930e 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.dom.properties.Gradient; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper; @@ -43,7 +45,7 @@ protected void applyCSSProperty(Control control, String property, return; } - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { Color color = (Color) engine.convert(value, Color.class, control.getDisplay()); ((ICTabRendering) renderer).setUnselectedTabsColor(color); @@ -51,7 +53,7 @@ protected void applyCSSProperty(Control control, String property, removeResizeEventListener(folder); return; } - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { + if (value instanceof CssList) { Gradient grad = (Gradient) engine.convert(value, Gradient.class, control.getDisplay()); if (grad == null) { return; diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4SelectedTabFillHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4SelectedTabFillHandler.java index 6c118ab9289..f01c10cec6b 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4SelectedTabFillHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4SelectedTabFillHandler.java @@ -14,6 +14,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.dom.properties.Gradient; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper; @@ -41,7 +43,7 @@ protected void applyCSSProperty(Control control, String property, if (!(renderer instanceof ICTabRendering)) { return; } - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay()); if (newColor == null) { @@ -60,7 +62,7 @@ protected void applyCSSProperty(Control control, String property, } else { ((ICTabRendering) renderer).setSelectedTabFill(newColor); } - } else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { + } else if (value instanceof CssList) { Gradient grad = (Gradient) engine.convert(value, Gradient.class, control.getDisplay()); if (grad == null || grad.getRGBs().isEmpty()) { diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4TabOutline.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4TabOutline.java index c1308cdff67..0b779f4c132 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4TabOutline.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4TabOutline.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; @@ -30,7 +31,7 @@ protected void applyCSSProperty(Control control, String property, if (!(control instanceof CTabFolder)) { return; } - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + if (value instanceof CssPrimitive) { Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay()); CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); if (renderer instanceof ICTabRendering) { diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/definition/CSSPropertyThemeElementDefinitionHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/definition/CSSPropertyThemeElementDefinitionHandler.java index d2474d09fe7..ce0e33aff9d 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/definition/CSSPropertyThemeElementDefinitionHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/definition/CSSPropertyThemeElementDefinitionHandler.java @@ -21,6 +21,7 @@ import java.util.ResourceBundle; import java.util.WeakHashMap; import org.eclipse.core.runtime.Platform; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.dom.definition.ThemeDefinitionElement; @@ -29,7 +30,6 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; import org.osgi.framework.ServiceReference; -import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; public class CSSPropertyThemeElementDefinitionHandler implements ICSSPropertyHandler { @@ -158,10 +158,9 @@ private BundleLocalization getBundleLocalization(Bundle bundle) { } private static URI getResourceBundleURI(CSSValue value) { - if (value instanceof CSSPrimitiveValue primitiveValue - && primitiveValue.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) { + if (value instanceof CssText text && text.kind() == CssText.Kind.URI) { try { - return new URI(primitiveValue.getStringValue()); + return new URI(text.value()); } catch (URISyntaxException exc) { // do nothing } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandler.java index 4cd64dd9af3..316864c81be 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandler.java @@ -16,12 +16,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.dom.preference.EclipsePreferencesElement; import org.eclipse.e4.ui.css.swt.helpers.EclipsePreferencesHelper; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; public class EclipsePreferencesHandler implements ICSSPropertyHandler { public static final String PREFERENCES_PROP = "preferences"; @@ -37,10 +37,9 @@ public boolean applyCSSProperty(Object element, String property, CSSValue value, IEclipsePreferences preferences = (IEclipsePreferences) ((EclipsePreferencesElement) element).getNativeWidget(); - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - CSSValueList list = (CSSValueList) value; - for (int i = 0; i < list.getLength(); i++) { - overrideProperty(preferences, list.item(i)); + if (value instanceof CssList list) { + for (CSSValue item : list.values()) { + overrideProperty(preferences, item); } } else { overrideProperty(preferences, value); diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF index 37a7e9d1ea0..75d82205e69 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.e4.ui.workbench.swt;singleton:=true -Bundle-Version: 0.18.100.qualifier +Bundle-Version: 0.18.200.qualifier Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSRenderingUtils.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSRenderingUtils.java index cc2a6590195..7e0496b3f02 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSRenderingUtils.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSRenderingUtils.java @@ -213,8 +213,7 @@ public CSSValue getCSSValue(Control styleControl, String className, WidgetElement.setCSSClass(styleControl, className); } - CSSStyleDeclaration styleDeclarations = csseng.getViewCSS() - .getComputedStyle(tempEment, ""); //$NON-NLS-1$ + CSSStyleDeclaration styleDeclarations = csseng.computeStyle(tempEment, ""); //$NON-NLS-1$ if (styleDeclarations == null) { return null; @@ -240,8 +239,7 @@ public Image createImage(Control styleControl, String classId, WidgetElement.setCSSClass(styleControl, classId); } - CSSStyleDeclaration styleDeclarations = csseng.getViewCSS() - .getComputedStyle(tempEment, ""); + CSSStyleDeclaration styleDeclarations = csseng.computeStyle(tempEment, ""); if (styleDeclarations == null) { return null; } diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java index a1c630cf1f3..2b932f06b00 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java @@ -1356,7 +1356,7 @@ public CSSStyleDeclaration getStyle(Object widget) { if (e == null) { return null; } - return cssEngine.getViewCSS().getComputedStyle(e, null); + return cssEngine.computeStyle(e, null); } @Override diff --git a/bundles/org.eclipse.ui.forms/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.forms/META-INF/MANIFEST.MF index b17c669780e..5b183e0562f 100644 --- a/bundles/org.eclipse.ui.forms/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.ui.forms/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %name Bundle-SymbolicName: org.eclipse.ui.forms;singleton:=true -Bundle-Version: 3.14.100.qualifier +Bundle-Version: 3.14.200.qualifier Bundle-Vendor: %provider-name Bundle-Localization: plugin Export-Package: org.eclipse.ui.forms, diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/properties/css2/CSSPropertyFormHandler.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/properties/css2/CSSPropertyFormHandler.java index eba1f4b53a0..12b44c00b58 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/properties/css2/CSSPropertyFormHandler.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/css/properties/css2/CSSPropertyFormHandler.java @@ -71,7 +71,7 @@ protected void applyCSSProperty(Control control, String property, CSSValue value if (grad == null) { return; } - List values = grad.getValues(); + List values = grad.getValues(); List colors = new ArrayList<>(values.size()); for (CSSPrimitiveValue cssValue : values) { if (cssValue != null && cssValue.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/CascadeTest.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/CascadeTest.java index 1dcb21c0c86..62d3f72ac13 100644 --- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/CascadeTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/CascadeTest.java @@ -18,9 +18,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; +import java.io.StringReader; -import org.eclipse.e4.ui.css.core.impl.dom.DocumentCSSImpl; -import org.eclipse.e4.ui.css.core.impl.dom.ViewCSSImpl; + +import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl; import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil; import org.eclipse.e4.ui.tests.css.core.util.TestElement; @@ -28,8 +29,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleSheet; -import org.w3c.dom.css.ViewCSS; /** * Test to ensure the that CSS honors the CSS cascading rules, i.e.: @@ -63,10 +62,10 @@ void testPosition() throws Exception { // precedence because of its position in the stylesheet String css = "Button { color: blue; font-weight: bold; }\n" + "Button { color: black }\n"; - ViewCSS viewCSS = createViewCss(css); + CSSEngine viewCSS = createViewCss(css); TestElement button = new TestElement("Button", engine); - CSSStyleDeclaration style = viewCSS.getComputedStyle(button, null); + CSSStyleDeclaration style = viewCSS.computeStyle(button, null); assertEquals("black", style.getPropertyCSSValue("color").getCssText()); assertEquals("bold", style.getPropertyCSSValue("font-weight").getCssText()); } @@ -77,14 +76,14 @@ void testSpecificity() throws Exception { // precedence because of its higher specificity String css = "Label, Button.special { color: black; }\n" + "Button { color: blue; font-weight: bold; }\n"; - ViewCSS viewCSS = createViewCss(css); + CSSEngine viewCSS = createViewCss(css); TestElement button = new TestElement("Button", engine); - CSSStyleDeclaration style = viewCSS.getComputedStyle(button, null); + CSSStyleDeclaration style = viewCSS.computeStyle(button, null); assertEquals("blue", style.getPropertyCSSValue("color").getCssText()); button.setClass("special"); - style = viewCSS.getComputedStyle(button, null); + style = viewCSS.computeStyle(button, null); assertEquals("black", style.getPropertyCSSValue("color").getCssText()); assertEquals("bold", style.getPropertyCSSValue("font-weight") .getCssText()); @@ -99,21 +98,21 @@ void ensureThatClassAndIdareConsideredIfOnTheSameLevel() throws Exception { CTabFolder > Composite > .special { color: blue; font-weight: bold; } CTabFolder > Composite > #special { color: red; font-weight: bold; } """; - ViewCSS viewCSS = createViewCss(css); + CSSEngine viewCSS = createViewCss(css); TestElement tabFolder = new TestElement("CTabFolder", engine); TestElement composite = new TestElement("Composite", tabFolder, engine); TestElement toolbar = new TestElement("Toolbar", composite, engine); - CSSStyleDeclaration style = viewCSS.getComputedStyle(toolbar, null); + CSSStyleDeclaration style = viewCSS.computeStyle(toolbar, null); assertEquals("black", style.getPropertyCSSValue("color").getCssText()); toolbar.setClass("special"); - style = viewCSS.getComputedStyle(toolbar, null); + style = viewCSS.computeStyle(toolbar, null); assertEquals("blue", style.getPropertyCSSValue("color").getCssText()); toolbar.setId("special"); - style = viewCSS.getComputedStyle(toolbar, null); + style = viewCSS.computeStyle(toolbar, null); assertEquals("red", style.getPropertyCSSValue("color").getCssText()); } @@ -128,36 +127,35 @@ void testSpecificities() throws Exception { Button.special { color: green; } Button#myid { color: red; } """; - ViewCSS viewCSS = createViewCss(css); + CSSEngine viewCSS = createViewCss(css); TestElement label = new TestElement("Label", engine); - CSSStyleDeclaration style = viewCSS.getComputedStyle(label, null); + CSSStyleDeclaration style = viewCSS.computeStyle(label, null); assertEquals("black", style.getPropertyCSSValue("color").getCssText()); TestElement button = new TestElement("Button", engine); - style = viewCSS.getComputedStyle(button, null); + style = viewCSS.computeStyle(button, null); assertEquals("blue", style.getPropertyCSSValue("color").getCssText()); button.setAttribute("BORDER", "true"); - style = viewCSS.getComputedStyle(button, null); + style = viewCSS.computeStyle(button, null); assertEquals("gray", style.getPropertyCSSValue("color").getCssText()); button.setClass("special"); - style = viewCSS.getComputedStyle(button, null); + style = viewCSS.computeStyle(button, null); assertEquals("green", style.getPropertyCSSValue("color").getCssText()); button.setId("myid"); - style = viewCSS.getComputedStyle(button, null); + style = viewCSS.computeStyle(button, null); assertEquals("red", style.getPropertyCSSValue("color").getCssText()); } - private static ViewCSS createViewCss(String... css) throws IOException { - DocumentCSSImpl docCss = new DocumentCSSImpl(); + private CSSEngine createViewCss(String... css) throws IOException { + CSSEngine cascadeEngine = ParserTestUtil.createEngine(); for (String cssString : css) { - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(cssString); - docCss.addStyleSheet(styleSheet); + cascadeEngine.parseStyleSheet(new StringReader(cssString)); } - return new ViewCSSImpl(docCss); + return cascadeEngine; } // public void testImportantRule() throws Exception { @@ -168,10 +166,10 @@ private static ViewCSS createViewCss(String... css) throws IOException { // String css = "Button{color:red ! important;}\n" // +"Button{ color: blue ! important;}\n" // + "Button { color: black }\n"; - // ViewCSS viewCSS = createViewCss(css); + // CSSEngine viewCSS = createViewCss(css); // // TestElement button = new TestElement("Button", engine); - // CSSStyleDeclaration style = viewCSS.getComputedStyle(button, null); + // CSSStyleDeclaration style = viewCSS.computeStyle(button, null); // assertEquals("blue", style.getPropertyCSSValue("color").getCssText()); // } @@ -181,10 +179,10 @@ void testBug261081() throws Exception { // precedence because of its position in the stylesheet String css = "Button, Label { color: blue; font-weight: bold; }\n" + "Button { color: black }\n"; - ViewCSS viewCSS = createViewCss(css); + CSSEngine viewCSS = createViewCss(css); TestElement button = new TestElement("Button", engine); - CSSStyleDeclaration style = viewCSS.getComputedStyle(button, null); + CSSStyleDeclaration style = viewCSS.computeStyle(button, null); assertEquals("black", style.getPropertyCSSValue("color").getCssText()); assertEquals("bold", style.getPropertyCSSValue("font-weight").getCssText()); } @@ -195,10 +193,10 @@ void testBug458342_combine() throws Exception { String css1 = "Button { color: blue; }"; String css2 = "Button { font-weight: bold; }"; - ViewCSS viewCSS = createViewCss(css1, css2); + CSSEngine viewCSS = createViewCss(css1, css2); TestElement button = new TestElement("Button", engine); - CSSStyleDeclaration style = viewCSS.getComputedStyle(button, null); + CSSStyleDeclaration style = viewCSS.computeStyle(button, null); assertEquals("blue", style.getPropertyCSSValue("color").getCssText()); assertEquals("bold", style.getPropertyCSSValue("font-weight").getCssText()); } @@ -210,10 +208,10 @@ void testBug458342_override() throws Exception { String css1 = "Button { color: blue; font-weight: bold; }"; String css2 = "Button { color: black; }"; - ViewCSS viewCSS = createViewCss(css1, css2); + CSSEngine viewCSS = createViewCss(css1, css2); TestElement button = new TestElement("Button", engine); - CSSStyleDeclaration style = viewCSS.getComputedStyle(button, null); + CSSStyleDeclaration style = viewCSS.computeStyle(button, null); assertEquals("black", style.getPropertyCSSValue("color").getCssText()); assertEquals("bold", style.getPropertyCSSValue("font-weight").getCssText()); } diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/CssParserTest.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/CssParserTest.java index a4c7d549de3..36114551078 100644 --- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/CssParserTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/CssParserTest.java @@ -23,13 +23,14 @@ import org.eclipse.e4.ui.css.core.impl.parser.CssParseException; import org.eclipse.e4.ui.css.core.impl.parser.CssParser; import org.junit.jupiter.api.Test; -import org.w3c.dom.css.CSSImportRule; +import java.util.List; + +import org.eclipse.e4.ui.css.core.impl.dom.CSSImportRuleImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleRuleImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CssRule; import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSRuleList; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleRule; -import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.CSSValue; import org.w3c.dom.css.CSSValueList; @@ -45,8 +46,8 @@ private static Selector firstSelector(String selector) { return CssParser.parseSelectors(selector).item(0); } - private static CSSStyleRule firstStyleRule(String css) { - return (CSSStyleRule) CssParser.parseStyleSheet(css).getCssRules().item(0); + private static CSSStyleRuleImpl firstStyleRule(String css) { + return (CSSStyleRuleImpl) CssParser.parseStyleSheet(css).getRules().get(0); } // ---------- selectors ---------- @@ -113,7 +114,7 @@ void testMalformedSelectorThrows() { @Test void testSingleDeclaration() { - CSSStyleRule rule = firstStyleRule("Button { color: red; }"); + CSSStyleRuleImpl rule = firstStyleRule("Button { color: red; }"); assertEquals("Button", rule.getSelectorText()); CSSStyleDeclaration style = rule.getStyle(); assertEquals(1, style.getLength()); @@ -176,50 +177,50 @@ void testShorthandHexExpands() { @Test void testCommentsIgnored() { - CSSStyleSheet sheet = CssParser.parseStyleSheet(""" + CSSStyleSheetImpl sheet = CssParser.parseStyleSheet(""" /* lead */ Button { /* in */ color: red; } /* tail */ """); - assertEquals(1, sheet.getCssRules().getLength()); + assertEquals(1, sheet.getRules().size()); } // ---------- at-rules ---------- @Test void testImportRuleKept() { - CSSStyleSheet sheet = CssParser.parseStyleSheet("@import url('other.css');"); - assertEquals(1, sheet.getCssRules().getLength()); - CSSRule rule = sheet.getCssRules().item(0); - assertEquals(CSSRule.IMPORT_RULE, rule.getType()); - assertEquals("other.css", ((CSSImportRule) rule).getHref()); + CSSStyleSheetImpl sheet = CssParser.parseStyleSheet("@import url('other.css');"); + assertEquals(1, sheet.getRules().size()); + CssRule rule = sheet.getRules().get(0); + assertTrue(rule instanceof CSSImportRuleImpl); + assertEquals("other.css", ((CSSImportRuleImpl) rule).getHref()); } @Test void testMediaAndFontFaceDiscardedFollowingRuleKept() { - CSSStyleSheet sheet = CssParser.parseStyleSheet(""" + CSSStyleSheetImpl sheet = CssParser.parseStyleSheet(""" @font-face { font-family: x; } @media screen { Hidden { color: red; } } Label { color: blue; } """); // Both at-rules are discarded entirely; only the top-level Label remains. - CSSRuleList rules = sheet.getCssRules(); - assertEquals(1, rules.getLength()); - CSSStyleRule label = (CSSStyleRule) rules.item(0); + List rules = sheet.getRules(); + assertEquals(1, rules.size()); + CSSStyleRuleImpl label = (CSSStyleRuleImpl) rules.get(0); assertEquals("Label", label.getSelectorText()); assertEquals("blue", label.getStyle().getPropertyCSSValue("color").getCssText()); } @Test void testMultipleRulesPreserveOrder() { - CSSRuleList rules = CssParser.parseStyleSheet("A { color: red; } B { color: green; } C { color: blue; }") - .getCssRules(); - assertEquals(3, rules.getLength()); - assertEquals("A", ((CSSStyleRule) rules.item(0)).getSelectorText()); - assertEquals("C", ((CSSStyleRule) rules.item(2)).getSelectorText()); + List rules = CssParser.parseStyleSheet("A { color: red; } B { color: green; } C { color: blue; }") + .getRules(); + assertEquals(3, rules.size()); + assertEquals("A", ((CSSStyleRuleImpl) rules.get(0)).getSelectorText()); + assertEquals("C", ((CSSStyleRuleImpl) rules.get(2)).getSelectorText()); } @Test void testEmptyStyleSheet() { - assertEquals(0, CssParser.parseStyleSheet("").getCssRules().getLength()); - assertTrue(CssParser.parseStyleSheet(" \n ").getCssRules().getLength() == 0); + assertEquals(0, CssParser.parseStyleSheet("").getRules().size()); + assertTrue(CssParser.parseStyleSheet(" \n ").getRules().isEmpty()); } } diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/FontFaceRulesTest.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/FontFaceRulesTest.java index fd285a93d03..3393b0e7474 100644 --- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/FontFaceRulesTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/FontFaceRulesTest.java @@ -17,9 +17,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleRuleImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl; import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil; import org.junit.jupiter.api.Test; -import org.w3c.dom.css.CSSStyleSheet; /** * Assert that @font-face rules are ignored. @@ -30,9 +31,9 @@ public class FontFaceRulesTest { void testEmptyFontFaceRule() throws Exception { String css = "@font-face {}\n" + "Label { background-color: #FF0000 }"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); assertNotNull(styleSheet); - assertEquals(1, styleSheet.getCssRules().getLength()); + assertEquals(1, styleSheet.getRules().size()); } @Test @@ -43,8 +44,8 @@ void testFontFaceRuleWithProperties() throws Exception { src: url("http://site/fonts/rob-celt") } Label { background-color: #FF0000 }"""; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); assertNotNull(styleSheet); - assertEquals(1, styleSheet.getCssRules().getLength()); + assertEquals(1, styleSheet.getRules().size()); } } diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ImportTest.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ImportTest.java index c2db00a5ab1..6e0457ca78e 100644 --- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ImportTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ImportTest.java @@ -17,27 +17,25 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.List; import org.eclipse.e4.ui.css.core.engine.CSSEngine; -import org.eclipse.e4.ui.css.core.impl.dom.DocumentCSSImpl; -import org.eclipse.e4.ui.css.core.impl.dom.ViewCSSImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleRuleImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CssRule; +import org.eclipse.e4.ui.css.core.impl.engine.CSSEngineImpl; import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil; import org.eclipse.e4.ui.tests.css.core.util.TestElement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSRuleList; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleSheet; -import org.w3c.dom.css.ViewCSS; -import org.w3c.dom.stylesheets.StyleSheet; -import org.w3c.dom.stylesheets.StyleSheetList; public class ImportTest { @@ -72,7 +70,7 @@ void testOverrideImportedRule() throws Exception { String importedFolderPath = importedFile.getParent(); String importingUrl = "file:///" + importedFolderPath + "/importing.css"; - ViewCSS viewCSS = createViewCss(importingUrl, importingCss); + parseStyleSheet(importingUrl, importingCss); TestElement buttonAlpha = new TestElement("Button", engine); buttonAlpha.setClass("ClassAlpha"); @@ -80,10 +78,8 @@ void testOverrideImportedRule() throws Exception { TestElement buttonBeta = new TestElement("Button", engine); buttonBeta.setClass("ClassBeta"); - CSSStyleDeclaration styleAlpha = viewCSS.getComputedStyle(buttonAlpha, - null); - CSSStyleDeclaration styleBeta = viewCSS.getComputedStyle(buttonBeta, - null); + CSSStyleDeclaration styleAlpha = engine.computeStyle(buttonAlpha, null); + CSSStyleDeclaration styleBeta = engine.computeStyle(buttonBeta, null); assertEquals("value", styleAlpha.getPropertyCSSValue("property") .getCssText()); @@ -111,25 +107,24 @@ void testNestedImports() throws IOException { String importedFolderPath = importedFile.getParent(); String importingUrl = "file:///" + importedFolderPath + "/root.css"; - CSSStyleSheet result = parseStyleSheet(importingUrl, rootCss); + CSSStyleSheetImpl result = parseStyleSheet(importingUrl, rootCss); // check the parsing result assertNotNull(result); - CSSRuleList cssRules = result.getCssRules(); - assertEquals(3, cssRules.getLength()); + List cssRules = result.getRules(); + assertEquals(3, cssRules.size()); assertStyle(deepNestedCss, cssRules, 0); assertStyle(childStyle, cssRules, 1); assertStyle(rootStyle, cssRules, 2); - // check the full DocumentCSS of the engine - StyleSheetList documentStyleSheets = engine.getDocumentCSS().getStyleSheets(); - assertEquals(1, documentStyleSheets.getLength()); - StyleSheet documentStyleSheet = documentStyleSheets.item(0); - assertEquals(result, documentStyleSheet); + // check that the engine's cascade holds exactly this sheet + List documentStyleSheets = ((CSSEngineImpl) engine).getStyleSheets(); + assertEquals(1, documentStyleSheets.size()); + assertEquals(result, documentStyleSheets.get(0)); } - private void assertStyle(String expectedStyleText, CSSRuleList cssRules, int index) { - assertEquals(CSSRule.STYLE_RULE, cssRules.item(index).getType()); - assertEquals(expectedStyleText.trim(), cssRules.item(index).getCssText()); + private void assertStyle(String expectedStyleText, List cssRules, int index) { + assertTrue(cssRules.get(index) instanceof CSSStyleRuleImpl); + assertEquals(expectedStyleText.trim(), ((CSSStyleRuleImpl) cssRules.get(index)).getCssText()); } private File createTempCssFile(String cssString) throws IOException { @@ -145,17 +140,8 @@ private String createImport(File importedFile) { return "@import url('" + cssUrl + "');\n"; } - private CSSStyleSheet parseStyleSheet(String sourceUrl, String cssString) throws IOException { - return (CSSStyleSheet) engine.parseStyleSheet( + private CSSStyleSheetImpl parseStyleSheet(String sourceUrl, String cssString) throws IOException { + return engine.parseStyleSheet( new ByteArrayInputStream(cssString.getBytes(StandardCharsets.UTF_8)), sourceUrl); } - - private ViewCSS createViewCss(String sourceUrl, String cssString) - throws IOException { - StyleSheet styleSheet = parseStyleSheet(sourceUrl, cssString); - - DocumentCSSImpl docCss = new DocumentCSSImpl(); - docCss.addStyleSheet(styleSheet); - return new ViewCSSImpl(docCss); - } } diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/InheritTest.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/InheritTest.java index 7b5966a7604..993c6c9e49c 100644 --- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/InheritTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/InheritTest.java @@ -16,20 +16,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; +import java.io.StringReader; import java.util.Collection; import java.util.Collections; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandlerProvider; import org.eclipse.e4.ui.css.core.engine.CSSEngine; -import org.eclipse.e4.ui.css.core.impl.dom.DocumentCSSImpl; import org.eclipse.e4.ui.css.core.impl.engine.CSSEngineImpl; import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil; import org.eclipse.e4.ui.tests.css.core.util.TestElement; import org.junit.jupiter.api.Test; import org.w3c.dom.Element; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.CSSValue; /** @@ -89,11 +88,7 @@ void testInheritExplicitProperty() throws Exception { } private CSSEngine createEngine(String css) throws IOException { - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - DocumentCSSImpl docCss = new DocumentCSSImpl(); - docCss.addStyleSheet(styleSheet); - - return new CSSEngineImpl(docCss) { + CSSEngine cssEngine = new CSSEngineImpl() { { registerCSSPropertyHandlerProvider(new TestHandlerProvider()); } @@ -111,6 +106,8 @@ public Element getElement(Object element) { return super.getElement(element); } }; + cssEngine.parseStyleSheet(new StringReader(css)); + return cssEngine; } /** diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/MediaRulesTest.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/MediaRulesTest.java index b3c11020709..9a3cf954fe6 100644 --- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/MediaRulesTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/MediaRulesTest.java @@ -19,9 +19,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleRuleImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl; import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil; import org.junit.jupiter.api.Test; -import org.w3c.dom.css.CSSStyleSheet; /** * Assert that @media rules are ignored. @@ -35,12 +36,12 @@ void testMediaRule() throws Exception { BODY { line-height: 1.2 } } Label { background-color: #FF0000 }"""; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); assertNotNull(styleSheet); // The @media block is discarded entirely; only the following top-level // rule remains, with its declaration intact. - assertEquals(1, styleSheet.getCssRules().getLength()); - assertFalse(styleSheet.getCssRules().item(0).getCssText().contains("line-height")); - assertTrue(styleSheet.getCssRules().item(0).getCssText().contains("background-color")); + assertEquals(1, styleSheet.getRules().size()); + assertFalse(((CSSStyleRuleImpl) styleSheet.getRules().get(0)).getCssText().contains("line-height")); + assertTrue(((CSSStyleRuleImpl) styleSheet.getRules().get(0)).getCssText().contains("background-color")); } } diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/StyleRuleTest.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/StyleRuleTest.java index 0462ba989ab..aa782e92cc4 100644 --- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/StyleRuleTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/StyleRuleTest.java @@ -18,14 +18,15 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.List; + +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleRuleImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CssRule; import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil; import org.junit.jupiter.api.Test; import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSRuleList; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleRule; -import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.CSSValue; import org.w3c.dom.css.RGBColor; @@ -35,22 +36,20 @@ public class StyleRuleTest { @Test void testSimpleStyleRule() throws Exception { String css = "Label { color: #FF0000 }"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); assertNotNull(styleSheet); - CSSRuleList rules = styleSheet.getCssRules(); - assertEquals(1, rules.getLength()); - CSSRule rule = rules.item(0); - assertEquals(CSSRule.STYLE_RULE, rule.getType()); + List rules = styleSheet.getRules(); + assertEquals(1, rules.size()); + assertTrue(rules.get(0) instanceof CSSStyleRuleImpl); } @Test void testHexColor() throws Exception { String css = "Label { color: #FF0220 }"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - CSSRuleList rules = styleSheet.getCssRules(); - CSSRule rule = rules.item(0); - assertEquals(CSSRule.STYLE_RULE, rule.getType()); - CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle(); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); + List rules = styleSheet.getRules(); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) rules.get(0); + CSSStyleDeclaration style = rule.getStyle(); CSSValue value = style.getPropertyCSSValue("color"); assertTrue(value instanceof CSSPrimitiveValue); RGBColor colorValue = ((CSSPrimitiveValue) value).getRGBColorValue(); @@ -65,11 +64,10 @@ void testHexColor() throws Exception { @Test void testNamedColor() throws Exception { String css = "Label { color: green }"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - CSSRuleList rules = styleSheet.getCssRules(); - CSSRule rule = rules.item(0); - assertEquals(CSSRule.STYLE_RULE, rule.getType()); - CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle(); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); + List rules = styleSheet.getRules(); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) rules.get(0); + CSSStyleDeclaration style = rule.getStyle(); CSSValue value = style.getPropertyCSSValue("color"); assertTrue(value instanceof CSSPrimitiveValue); String colorString = ((CSSPrimitiveValue) value).getStringValue(); @@ -79,11 +77,10 @@ void testNamedColor() throws Exception { @Test void testFont() throws Exception { String css = "Label { font: Verdana }"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - CSSRuleList rules = styleSheet.getCssRules(); - CSSRule rule = rules.item(0); - assertEquals(CSSRule.STYLE_RULE, rule.getType()); - CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle(); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); + List rules = styleSheet.getRules(); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) rules.get(0); + CSSStyleDeclaration style = rule.getStyle(); CSSValue value = style.getPropertyCSSValue("font"); assertTrue(value instanceof CSSPrimitiveValue); String colorString = ((CSSPrimitiveValue) value).getStringValue(); @@ -93,11 +90,10 @@ void testFont() throws Exception { @Test void testTestFontItalic() throws Exception { String css = "Label { font: Arial 12px; font-style: italic }"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - CSSRuleList rules = styleSheet.getCssRules(); - CSSRule rule = rules.item(0); - assertEquals(CSSRule.STYLE_RULE, rule.getType()); - CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle(); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); + List rules = styleSheet.getRules(); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) rules.get(0); + CSSStyleDeclaration style = rule.getStyle(); CSSValue value = style.getPropertyCSSValue("font-style"); assertTrue(value instanceof CSSPrimitiveValue); String colorString = ((CSSPrimitiveValue) value).getStringValue(); @@ -107,11 +103,10 @@ void testTestFontItalic() throws Exception { @Test void testTestFontBold() throws Exception { String css = "Label { font: Arial 12px; font-style: bold }"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - CSSRuleList rules = styleSheet.getCssRules(); - CSSRule rule = rules.item(0); - assertEquals(CSSRule.STYLE_RULE, rule.getType()); - CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle(); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); + List rules = styleSheet.getRules(); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) rules.get(0); + CSSStyleDeclaration style = rule.getStyle(); CSSValue value = style.getPropertyCSSValue("font-style"); assertTrue(value instanceof CSSPrimitiveValue); String colorString = ((CSSPrimitiveValue) value).getStringValue(); @@ -121,11 +116,10 @@ void testTestFontBold() throws Exception { @Test void testBackgroundNameColor() throws Exception { String css = "Label { background-color: green }"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - CSSRuleList rules = styleSheet.getCssRules(); - CSSRule rule = rules.item(0); - assertEquals(CSSRule.STYLE_RULE, rule.getType()); - CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle(); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); + List rules = styleSheet.getRules(); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) rules.get(0); + CSSStyleDeclaration style = rule.getStyle(); CSSValue value = style.getPropertyCSSValue("background-color"); assertTrue(value instanceof CSSPrimitiveValue); String colorString = ((CSSPrimitiveValue) value).getStringValue(); @@ -135,11 +129,10 @@ void testBackgroundNameColor() throws Exception { @Test void testBackgroundHexColor() throws Exception { String css = "Label { background-color: #FF0220 }"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - CSSRuleList rules = styleSheet.getCssRules(); - CSSRule rule = rules.item(0); - assertEquals(CSSRule.STYLE_RULE, rule.getType()); - CSSStyleDeclaration style = ((CSSStyleRule) rule).getStyle(); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); + List rules = styleSheet.getRules(); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) rules.get(0); + CSSStyleDeclaration style = rule.getStyle(); CSSValue value = style.getPropertyCSSValue("background-color"); assertTrue(value instanceof CSSPrimitiveValue); RGBColor colorValue = ((CSSPrimitiveValue) value).getRGBColorValue(); @@ -154,9 +147,8 @@ void testBackgroundHexColor() throws Exception { @Test void testGetCSSText() throws Exception { String css = "Label, * > Label { background-color: rgb(255, 2, 32); }"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - CSSRuleList rules = styleSheet.getCssRules(); - CSSRule rule = rules.item(0); + CSSStyleSheetImpl styleSheet = ParserTestUtil.parseCss(css); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) styleSheet.getRules().get(0); assertEquals(css, rule.getCssText()); } diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/StyleSheetStructureTest.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/StyleSheetStructureTest.java index ed25bb31a32..11f04b76f10 100644 --- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/StyleSheetStructureTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/StyleSheetStructureTest.java @@ -28,13 +28,12 @@ import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil; import org.eclipse.swt.widgets.Display; import org.junit.jupiter.api.Test; -import org.w3c.dom.css.CSSImportRule; +import org.eclipse.e4.ui.css.core.impl.dom.CSSImportRuleImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleRuleImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CssRule; import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSRule; -import org.w3c.dom.css.CSSRuleList; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleRule; -import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.CSSValue; import org.w3c.dom.css.CSSValueList; import org.w3c.dom.css.RGBColor; @@ -49,23 +48,23 @@ public class StyleSheetStructureTest { @Test void testEmptyStyleSheet() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss(""); + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss(""); assertNotNull(sheet); - assertEquals(0, sheet.getCssRules().getLength()); + assertEquals(0, sheet.getRules().size()); } @Test void testSingleRule() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss("Button { color: red; }"); + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss("Button { color: red; }"); assertNotNull(sheet); - assertEquals(1, sheet.getCssRules().getLength()); + assertEquals(1, sheet.getRules().size()); - CSSRule rule = sheet.getCssRules().item(0); - assertEquals(CSSRule.STYLE_RULE, rule.getType()); + CssRule rule = sheet.getRules().get(0); + assertInstanceOf(CSSStyleRuleImpl.class, rule); - CSSStyleRule styleRule = (CSSStyleRule) rule; + CSSStyleRuleImpl styleRule = (CSSStyleRuleImpl) rule; assertEquals("Button", styleRule.getSelectorText()); CSSStyleDeclaration style = styleRule.getStyle(); @@ -84,21 +83,21 @@ void testMultipleRulesPreserveOrder() throws Exception { Label { color: green; } Composite { color: blue; } """; - CSSStyleSheet sheet = ParserTestUtil.parseCss(css); + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss(css); - CSSRuleList rules = sheet.getCssRules(); - assertEquals(3, rules.getLength()); - assertEquals("Button", ((CSSStyleRule) rules.item(0)).getSelectorText()); - assertEquals("Label", ((CSSStyleRule) rules.item(1)).getSelectorText()); - assertEquals("Composite", ((CSSStyleRule) rules.item(2)).getSelectorText()); + List rules = sheet.getRules(); + assertEquals(3, rules.size()); + assertEquals("Button", ((CSSStyleRuleImpl) rules.get(0)).getSelectorText()); + assertEquals("Label", ((CSSStyleRuleImpl) rules.get(1)).getSelectorText()); + assertEquals("Composite", ((CSSStyleRuleImpl) rules.get(2)).getSelectorText()); } @Test void testMultipleSelectorsInOneRule() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss("Button, Label { color: red; }"); + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss("Button, Label { color: red; }"); - assertEquals(1, sheet.getCssRules().getLength()); - CSSStyleRule rule = (CSSStyleRule) sheet.getCssRules().item(0); + assertEquals(1, sheet.getRules().size()); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) sheet.getRules().get(0); String selectorText = rule.getSelectorText(); assertTrue(selectorText.contains("Button"), () -> "expected Button in " + selectorText); @@ -107,10 +106,10 @@ void testMultipleSelectorsInOneRule() throws Exception { @Test void testMultipleDeclarations() throws Exception { - CSSStyleSheet sheet = ParserTestUtil + CSSStyleSheetImpl sheet = ParserTestUtil .parseCss("Button { color: red; background-color: blue; font-style: italic; }"); - CSSStyleRule rule = (CSSStyleRule) sheet.getCssRules().item(0); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) sheet.getRules().get(0); CSSStyleDeclaration style = rule.getStyle(); assertEquals(3, style.getLength()); @@ -125,8 +124,8 @@ void testMultipleDeclarations() throws Exception { @Test void testWhitespaceTolerance() throws Exception { - CSSStyleSheet compact = ParserTestUtil.parseCss("Button{color:red;background-color:blue;}"); - CSSStyleSheet padded = ParserTestUtil.parseCss(""" + CSSStyleSheetImpl compact = ParserTestUtil.parseCss("Button{color:red;background-color:blue;}"); + CSSStyleSheetImpl padded = ParserTestUtil.parseCss(""" Button { color: red; @@ -135,10 +134,10 @@ void testWhitespaceTolerance() throws Exception { """); - assertEquals(compact.getCssRules().getLength(), padded.getCssRules().getLength()); + assertEquals(compact.getRules().size(), padded.getRules().size()); - CSSStyleRule compactRule = (CSSStyleRule) compact.getCssRules().item(0); - CSSStyleRule paddedRule = (CSSStyleRule) padded.getCssRules().item(0); + CSSStyleRuleImpl compactRule = (CSSStyleRuleImpl) compact.getRules().get(0); + CSSStyleRuleImpl paddedRule = (CSSStyleRuleImpl) padded.getRules().get(0); assertEquals(compactRule.getSelectorText(), paddedRule.getSelectorText()); assertEquals(compactRule.getStyle().getLength(), paddedRule.getStyle().getLength()); @@ -150,7 +149,7 @@ void testWhitespaceTolerance() throws Exception { @Test void testCommentsIgnored() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss(""" + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss(""" /* leading comment */ Button { /* inside */ @@ -160,69 +159,68 @@ void testCommentsIgnored() throws Exception { Label { color: blue; } """); - assertEquals(2, sheet.getCssRules().getLength()); - CSSStyleRule first = (CSSStyleRule) sheet.getCssRules().item(0); + assertEquals(2, sheet.getRules().size()); + CSSStyleRuleImpl first = (CSSStyleRuleImpl) sheet.getRules().get(0); assertEquals("Button", first.getSelectorText()); assertEquals("red", first.getStyle().getPropertyCSSValue("color").getCssText()); } @Test void testImportRuleType() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCssWithoutImports("@import url('other.css');"); + CSSStyleSheetImpl sheet = ParserTestUtil.parseCssWithoutImports("@import url('other.css');"); - assertEquals(1, sheet.getCssRules().getLength()); - CSSRule rule = sheet.getCssRules().item(0); - assertEquals(CSSRule.IMPORT_RULE, rule.getType()); - assertInstanceOf(CSSImportRule.class, rule); + assertEquals(1, sheet.getRules().size()); + CssRule rule = sheet.getRules().get(0); + assertInstanceOf(CSSImportRuleImpl.class, rule); } @Test void testImportHrefExposed() throws Exception { - CSSStyleSheet sheet = ParserTestUtil + CSSStyleSheetImpl sheet = ParserTestUtil .parseCssWithoutImports("@import url('platform:/plugin/x/style.css');"); - CSSImportRule rule = (CSSImportRule) sheet.getCssRules().item(0); + CSSImportRuleImpl rule = (CSSImportRuleImpl) sheet.getRules().get(0); assertEquals("platform:/plugin/x/style.css", rule.getHref()); } @Test void testStringValues() throws Exception { - CSSStyleSheet quoted = ParserTestUtil.parseCss("Button[style~='SWT.CHECK'] { color: red; }"); - CSSStyleSheet unquoted = ParserTestUtil.parseCss("Button[style~=SWT_CHECK] { color: red; }"); + CSSStyleSheetImpl quoted = ParserTestUtil.parseCss("Button[style~='SWT.CHECK'] { color: red; }"); + CSSStyleSheetImpl unquoted = ParserTestUtil.parseCss("Button[style~=SWT_CHECK] { color: red; }"); - assertEquals(1, quoted.getCssRules().getLength()); - assertEquals(1, unquoted.getCssRules().getLength()); + assertEquals(1, quoted.getRules().size()); + assertEquals(1, unquoted.getRules().size()); - assertTrue(((CSSStyleRule) quoted.getCssRules().item(0)).getSelectorText().contains("SWT.CHECK")); - assertTrue(((CSSStyleRule) unquoted.getCssRules().item(0)).getSelectorText().contains("SWT_CHECK")); + assertTrue(((CSSStyleRuleImpl) quoted.getRules().get(0)).getSelectorText().contains("SWT.CHECK")); + assertTrue(((CSSStyleRuleImpl) unquoted.getRules().get(0)).getSelectorText().contains("SWT_CHECK")); } @Test void testColorValueForms() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss(""" + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss(""" A { color: #fff; } B { color: #ffffff; } C { color: rgb(255, 255, 255); } D { color: white; } """); - assertEquals(4, sheet.getCssRules().getLength()); + assertEquals(4, sheet.getRules().size()); for (int i = 0; i < 4; i++) { - CSSStyleRule rule = (CSSStyleRule) sheet.getCssRules().item(i); + CSSStyleRuleImpl rule = (CSSStyleRuleImpl) sheet.getRules().get(i); CSSValue value = rule.getStyle().getPropertyCSSValue("color"); assertNotNull(value, () -> "rule " + rule.getSelectorText() + " has no color value"); } - CSSValue hex3 = ((CSSStyleRule) sheet.getCssRules().item(0)).getStyle().getPropertyCSSValue("color"); - CSSValue hex6 = ((CSSStyleRule) sheet.getCssRules().item(1)).getStyle().getPropertyCSSValue("color"); - CSSValue rgb = ((CSSStyleRule) sheet.getCssRules().item(2)).getStyle().getPropertyCSSValue("color"); + CSSValue hex3 = ((CSSStyleRuleImpl) sheet.getRules().get(0)).getStyle().getPropertyCSSValue("color"); + CSSValue hex6 = ((CSSStyleRuleImpl) sheet.getRules().get(1)).getStyle().getPropertyCSSValue("color"); + CSSValue rgb = ((CSSStyleRuleImpl) sheet.getRules().get(2)).getStyle().getPropertyCSSValue("color"); // All three numeric forms are CSS_RGBCOLOR primitive values resolving to white. assertWhiteRgb((CSSPrimitiveValue) hex3); assertWhiteRgb((CSSPrimitiveValue) hex6); assertWhiteRgb((CSSPrimitiveValue) rgb); - CSSValue named = ((CSSStyleRule) sheet.getCssRules().item(3)).getStyle().getPropertyCSSValue("color"); + CSSValue named = ((CSSStyleRuleImpl) sheet.getRules().get(3)).getStyle().getPropertyCSSValue("color"); assertEquals("white", named.getCssText()); } @@ -250,28 +248,28 @@ void testInvalidInputErrorReported() throws Exception { @Test void testImportantPriorityPreserved() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss("Button { color: red !important; }"); + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss("Button { color: red !important; }"); - CSSStyleDeclaration style = ((CSSStyleRule) sheet.getCssRules().item(0)).getStyle(); + CSSStyleDeclaration style = ((CSSStyleRuleImpl) sheet.getRules().get(0)).getStyle(); assertEquals("red", style.getPropertyCSSValue("color").getCssText()); assertEquals("important", style.getPropertyPriority("color")); } @Test void testImportantOnlyMarksItsOwnDeclaration() throws Exception { - CSSStyleSheet sheet = ParserTestUtil + CSSStyleSheetImpl sheet = ParserTestUtil .parseCss("Button { color: red !important; background-color: blue; }"); - CSSStyleDeclaration style = ((CSSStyleRule) sheet.getCssRules().item(0)).getStyle(); + CSSStyleDeclaration style = ((CSSStyleRuleImpl) sheet.getRules().get(0)).getStyle(); assertEquals("important", style.getPropertyPriority("color")); assertEquals("", style.getPropertyPriority("background-color")); } @Test void testTrailingSemicolonOptional() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss("Button { color: red }"); + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss("Button { color: red }"); - CSSStyleDeclaration style = ((CSSStyleRule) sheet.getCssRules().item(0)).getStyle(); + CSSStyleDeclaration style = ((CSSStyleRuleImpl) sheet.getRules().get(0)).getStyle(); assertEquals(1, style.getLength()); assertEquals("red", style.getPropertyCSSValue("color").getCssText()); assertEquals("", style.getPropertyPriority("color")); @@ -279,18 +277,18 @@ void testTrailingSemicolonOptional() throws Exception { @Test void testStraySemicolonsTolerated() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss("Button { ; color: red;; }"); + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss("Button { ; color: red;; }"); - CSSStyleDeclaration style = ((CSSStyleRule) sheet.getCssRules().item(0)).getStyle(); + CSSStyleDeclaration style = ((CSSStyleRuleImpl) sheet.getRules().get(0)).getStyle(); assertEquals(1, style.getLength()); assertEquals("red", style.getPropertyCSSValue("color").getCssText()); } @Test void testMultiValuePropertyIsValueList() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss("Button { margin: 1px 2px 3px 4px; }"); + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss("Button { margin: 1px 2px 3px 4px; }"); - CSSValue value = ((CSSStyleRule) sheet.getCssRules().item(0)).getStyle().getPropertyCSSValue("margin"); + CSSValue value = ((CSSStyleRuleImpl) sheet.getRules().get(0)).getStyle().getPropertyCSSValue("margin"); assertEquals(CSSValue.CSS_VALUE_LIST, value.getCssValueType()); CSSValueList list = (CSSValueList) value; @@ -304,17 +302,17 @@ void testMultiValuePropertyIsValueList() throws Exception { @Test void testLengthAndPercentageUnits() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss(""" + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss(""" A { width: 10px; } B { width: 50%; } """); - CSSPrimitiveValue px = (CSSPrimitiveValue) ((CSSStyleRule) sheet.getCssRules().item(0)).getStyle() + CSSPrimitiveValue px = (CSSPrimitiveValue) ((CSSStyleRuleImpl) sheet.getRules().get(0)).getStyle() .getPropertyCSSValue("width"); assertEquals(CSSPrimitiveValue.CSS_PX, px.getPrimitiveType()); assertEquals(10.0f, px.getFloatValue(CSSPrimitiveValue.CSS_PX)); - CSSPrimitiveValue percent = (CSSPrimitiveValue) ((CSSStyleRule) sheet.getCssRules().item(1)).getStyle() + CSSPrimitiveValue percent = (CSSPrimitiveValue) ((CSSStyleRuleImpl) sheet.getRules().get(1)).getStyle() .getPropertyCSSValue("width"); assertEquals(CSSPrimitiveValue.CSS_PERCENTAGE, percent.getPrimitiveType()); assertEquals(50.0f, percent.getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE)); @@ -322,30 +320,30 @@ void testLengthAndPercentageUnits() throws Exception { @Test void testUnquotedImportUrlHref() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCssWithoutImports("@import url(other.css);"); + CSSStyleSheetImpl sheet = ParserTestUtil.parseCssWithoutImports("@import url(other.css);"); - CSSImportRule rule = (CSSImportRule) sheet.getCssRules().item(0); + CSSImportRuleImpl rule = (CSSImportRuleImpl) sheet.getRules().get(0); assertEquals("other.css", rule.getHref()); } @Test void testFontFaceRuleDiscarded() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss(""" + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss(""" @font-face { font-family: x; } Label { color: blue; } """); // The engine parses but does not retain @font-face; the regular rule that // follows it must still be present and intact. - assertEquals(1, sheet.getCssRules().getLength()); - CSSStyleRule label = (CSSStyleRule) sheet.getCssRules().item(0); + assertEquals(1, sheet.getRules().size()); + CSSStyleRuleImpl label = (CSSStyleRuleImpl) sheet.getRules().get(0); assertEquals("Label", label.getSelectorText()); assertEquals("blue", label.getStyle().getPropertyCSSValue("color").getCssText()); } @Test void testMediaRuleToleratedAndFollowingRuleParsed() throws Exception { - CSSStyleSheet sheet = ParserTestUtil.parseCss(""" + CSSStyleSheetImpl sheet = ParserTestUtil.parseCss(""" @media screen { Button { color: red; } } Label { color: blue; } """); @@ -353,9 +351,9 @@ void testMediaRuleToleratedAndFollowingRuleParsed() throws Exception { // @media is accepted without applying its block; the top-level rule after // it must remain reachable with its declarations intact. boolean labelFound = false; - CSSRuleList rules = sheet.getCssRules(); - for (int i = 0; i < rules.getLength(); i++) { - if (rules.item(i) instanceof CSSStyleRule rule && "Label".equals(rule.getSelectorText())) { + List rules = sheet.getRules(); + for (int i = 0; i < rules.size(); i++) { + if (rules.get(i) instanceof CSSStyleRuleImpl rule && "Label".equals(rule.getSelectorText())) { assertEquals("blue", rule.getStyle().getPropertyCSSValue("color").getCssText()); labelFound = true; } diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ViewCSSTest.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ViewCSSTest.java index aa8e445d326..d34b2614f1e 100644 --- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ViewCSSTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/parser/ViewCSSTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 EclipseSource and others. + * Copyright (c) 2008, 2026 Angelo Zerr and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -9,11 +9,9 @@ * SPDX-License-Identifier: EPL-2.0 * * Contributors: - * EclipseSource - initial API and implementation - * Stefan Winkler - Bug 419482 - * Lars Vogel - Bug 430468 - * Karsten Thoms - Bug 532869 - ******************************************************************************/ + * Angelo Zerr - initial API and implementation + * IBM Corporation - ongoing development + *******************************************************************************/ package org.eclipse.e4.ui.tests.css.core.parser; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -24,23 +22,22 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; +import java.io.StringReader; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.List; -import org.eclipse.e4.ui.css.core.impl.dom.DocumentCSSImpl; -import org.eclipse.e4.ui.css.core.impl.dom.ViewCSSImpl; +import org.eclipse.e4.ui.css.core.impl.engine.CSSEngineImpl; import org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl; -import org.eclipse.e4.ui.tests.css.core.util.ParserTestUtil; import org.eclipse.e4.ui.tests.css.core.util.TestElement; import org.eclipse.swt.widgets.Display; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSStyleSheet; -import org.w3c.dom.css.ViewCSS; +/** + * Tests the computed-style cascade ({@code CSSEngine.computeStyle}). + */ public class ViewCSSTest { private Display display; @@ -61,19 +58,19 @@ void testGetComputedStyle() throws Exception { Button { color: blue; font-weight: bold; } Button { color: green; } """; - ViewCSS viewCSS = createViewCss(css); + parseStyleSheet(css); TestElement shell = new TestElement("Shell", engine); - CSSStyleDeclaration shellStyle = viewCSS.getComputedStyle(shell, null); + CSSStyleDeclaration shellStyle = engine.computeStyle(shell, null); assertNull(shellStyle); TestElement label = new TestElement("Label", engine); - CSSStyleDeclaration labelStyle = viewCSS.getComputedStyle(label, null); + CSSStyleDeclaration labelStyle = engine.computeStyle(label, null); assertNotNull(labelStyle); assertEquals(1, labelStyle.getLength()); TestElement button = new TestElement("Button", engine); - CSSStyleDeclaration buttonStyle = viewCSS.getComputedStyle(button, null); + CSSStyleDeclaration buttonStyle = engine.computeStyle(button, null); assertNotNull(buttonStyle); assertEquals(2, buttonStyle.getLength()); } @@ -81,13 +78,13 @@ void testGetComputedStyle() throws Exception { @Test void testBug419482_order1() throws Exception { String css = "Shell > * > * { color: red; }\n" + "Button { color: blue; }\n"; - ViewCSS viewCSS = createViewCss(css); + parseStyleSheet(css); final TestElement shell = new TestElement("Shell", engine); final TestElement composite = new TestElement("Composite", shell, engine); final TestElement button = new TestElement("Button", composite, engine); - CSSStyleDeclaration buttonStyle = viewCSS.getComputedStyle(button, null); + CSSStyleDeclaration buttonStyle = engine.computeStyle(button, null); assertNotNull(buttonStyle); assertEquals(1, buttonStyle.getLength()); assertEquals("color: blue;", buttonStyle.getCssText()); @@ -96,13 +93,13 @@ void testBug419482_order1() throws Exception { @Test void testBug419482_order2() throws Exception { String css = "Button { color: blue; }\n" + "Shell > * > * { color: red; }\n"; - ViewCSS viewCSS = createViewCss(css); + parseStyleSheet(css); final TestElement shell = new TestElement("Shell", engine); final TestElement composite = new TestElement("Composite", shell, engine); final TestElement button = new TestElement("Button", composite, engine); - CSSStyleDeclaration buttonStyle = viewCSS.getComputedStyle(button, null); + CSSStyleDeclaration buttonStyle = engine.computeStyle(button, null); assertNotNull(buttonStyle); assertEquals(1, buttonStyle.getLength()); assertEquals("color: red;", buttonStyle.getCssText()); @@ -111,13 +108,13 @@ void testBug419482_order2() throws Exception { @Test void testBug419482_higherSpecificity() throws Exception { String css = "Shell > * > Button { color: blue; }\n" + "Shell > * > * { color: red; }\n"; - ViewCSS viewCSS = createViewCss(css); + parseStyleSheet(css); final TestElement shell = new TestElement("Shell", engine); final TestElement composite = new TestElement("Composite", shell, engine); final TestElement button = new TestElement("Button", composite, engine); - CSSStyleDeclaration buttonStyle = viewCSS.getComputedStyle(button, null); + CSSStyleDeclaration buttonStyle = engine.computeStyle(button, null); assertNotNull(buttonStyle); assertEquals(1, buttonStyle.getLength()); assertEquals("color: blue;", buttonStyle.getCssText()); @@ -127,52 +124,42 @@ void testBug419482_higherSpecificity() throws Exception { @Test void testRuleCaching() throws Exception { String css = "Shell > * > * { color: red; }\n" + "Button { color: blue; }\n"; - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - DocumentCSSImpl docCss = new DocumentCSSImpl(); - docCss.addStyleSheet(styleSheet); - ViewCSSImpl viewCSS = new ViewCSSImpl(docCss); + parseStyleSheet(css); - Field currentCombinedRulesField = ViewCSSImpl.class.getDeclaredField("currentCombinedRules"); - currentCombinedRulesField.setAccessible(true); + Field combinedRulesField = CSSEngineImpl.class.getDeclaredField("combinedRules"); + combinedRulesField.setAccessible(true); + // before the first computeStyle() call the cache is empty + assertNull(combinedRulesField.get(engine)); - // after creation and before call of getComputedStyle() the fields are null - assertNull(currentCombinedRulesField.get(viewCSS)); - - // now call getComputedStyle() for a shell final TestElement shell = new TestElement("Shell", engine); final TestElement composite = new TestElement("Composite", shell, engine); final TestElement button = new TestElement("Button", composite, engine); - CSSStyleDeclaration buttonStyle = viewCSS.getComputedStyle(button, null); + CSSStyleDeclaration buttonStyle = engine.computeStyle(button, null); assertNotNull(buttonStyle); - // now the fields are filled - assertNotNull(currentCombinedRulesField.get(viewCSS)); + // now the cache is filled + assertNotNull(combinedRulesField.get(engine)); // deeper inspection: check what private method getCombinedRules returns - Method getCombinedRulesMethod = ViewCSSImpl.class.getDeclaredMethod("getCombinedRules"); + Method getCombinedRulesMethod = CSSEngineImpl.class.getDeclaredMethod("getCombinedRules"); getCombinedRulesMethod.setAccessible(true); + List cssRules = (List) getCombinedRulesMethod.invoke(engine); - List cssRules = (List) getCombinedRulesMethod.invoke(viewCSS); - // check caching: a 2nd call retrieves cached list - assertSame(cssRules, getCombinedRulesMethod.invoke(viewCSS)); + // check caching: a 2nd call retrieves the cached list + assertSame(cssRules, getCombinedRulesMethod.invoke(engine)); // add a new stylesheet => flush cache css = "Shell > * > * { color: blue; }\n" + "Label { color: green; }\n"; - styleSheet = ParserTestUtil.parseCss(css); - docCss.addStyleSheet(styleSheet); - - assertNull(currentCombinedRulesField.get(viewCSS)); + parseStyleSheet(css); + assertNull(combinedRulesField.get(engine)); - List cssRules2 = (List) getCombinedRulesMethod.invoke(viewCSS); + List cssRules2 = (List) getCombinedRulesMethod.invoke(engine); assertNotSame(cssRules, cssRules2); // stylesheet added => more rules assertTrue(cssRules2.size() > cssRules.size()); } - private static ViewCSS createViewCss(String css) throws IOException { - CSSStyleSheet styleSheet = ParserTestUtil.parseCss(css); - DocumentCSSImpl docCss = new DocumentCSSImpl(); - docCss.addStyleSheet(styleSheet); - return new ViewCSSImpl(docCss); + private void parseStyleSheet(String css) throws IOException { + engine.parseStyleSheet(new StringReader(css)); } } diff --git a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/util/ParserTestUtil.java b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/util/ParserTestUtil.java index 98c4ea5aa32..8a071bac374 100644 --- a/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/util/ParserTestUtil.java +++ b/tests/org.eclipse.e4.ui.tests.css.core/src/org/eclipse/e4/ui/tests/css/core/util/ParserTestUtil.java @@ -19,10 +19,9 @@ import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.core.engine.CSSErrorHandler; import org.eclipse.e4.ui.css.core.impl.parser.CssParser; +import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl; import org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl; import org.eclipse.swt.widgets.Display; -import org.w3c.dom.css.CSSStyleSheet; -import org.w3c.dom.stylesheets.StyleSheet; public final class ParserTestUtil { @@ -35,11 +34,10 @@ private ParserTestUtil() { // prevent instantiation } - public static CSSStyleSheet parseCss(String css) + public static CSSStyleSheetImpl parseCss(String css) throws IOException { CSSEngine engine = createEngine(); - StyleSheet result = engine.parseStyleSheet(new StringReader(css)); - return (CSSStyleSheet) result; + return engine.parseStyleSheet(new StringReader(css)); } /** @@ -47,8 +45,8 @@ public static CSSStyleSheet parseCss(String css) * want the AST as the parser produced it; {@link #parseCss(String)} runs * the engine's import-inlining pass which fails for placeholder URLs. */ - public static CSSStyleSheet parseCssWithoutImports(String css) { - return (CSSStyleSheet) CssParser.parseStyleSheet(css); + public static CSSStyleSheetImpl parseCssWithoutImports(String css) { + return CssParser.parseStyleSheet(css); } public static CSSEngine createEngine() { diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelperTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelperTest.java index 5e85629211a..e81b5053cb8 100644 --- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelperTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelperTest.java @@ -25,7 +25,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.w3c.dom.css.CSSValue; public class CSSSWTColorHelperTest extends CSSSWTHelperTestCase { private Display display; @@ -46,8 +45,7 @@ void testGetSWTColor() { @Test void testGetSWTColorWhenNotSupportedColorType() { - Color result = getSWTColor(colorValue("123213", CSSValue.CSS_CUSTOM), - display); + Color result = getSWTColor(nonPrimitiveValue("123213"), display); assertNull(result); } diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelperTestCase.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelperTestCase.java index 0afa53ed2d6..df6c93d6eeb 100644 --- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelperTestCase.java +++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTHelperTestCase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2015 IBM Corporation and others. + * Copyright (c) 2013, 2026 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -19,16 +19,20 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import java.util.List; + import org.eclipse.e4.ui.css.core.css2.CSS2FontHelper; import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties; -import org.eclipse.e4.ui.css.core.impl.dom.CSSValueImpl; +import org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontPropertiesImpl; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssNumber; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssPrimitive; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssValue; import org.eclipse.e4.ui.internal.css.swt.definition.IColorAndFontProvider; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.RGB; import org.osgi.framework.FrameworkUtil; -import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; public abstract class CSSSWTHelperTestCase { @@ -58,53 +62,31 @@ protected CSS2FontProperties fontProperties(String family) { } protected CSS2FontProperties fontProperties(String family, Object size, Object style, Object weight) { - CSS2FontProperties result = mock(CSS2FontProperties.class); - doReturn(valueImpl(family)).when(result).getFamily(); + CSS2FontProperties result = new CSS2FontPropertiesImpl(); + if (family != null) { + result.setFamily(new CssText(CssText.Kind.IDENT, family)); + } if (size != null) { - doReturn(valueImpl(size)).when(result).getSize(); + result.setSize(new CssNumber(((Number) size).doubleValue(), true)); + result.setSizeFromCSS(true); } if (style != null) { - doReturn(valueImpl(style)).when(result).getStyle(); + result.setStyle(new CssText(CssText.Kind.IDENT, style.toString())); } if (weight != null) { - doReturn(valueImpl(weight)).when(result).getWeight(); + result.setWeight(new CssText(CssText.Kind.IDENT, weight.toString())); } return result; } - private CSSValueImpl valueImpl(final Object value) { - if (value != null) { - return new CSSValueImpl() { - @Override - public String getCssText() { - return value.toString(); - } - - @Override - public String getStringValue() { - return getCssText(); - } - - @Override - public float getFloatValue(short valueType) throws DOMException { - return Float.parseFloat(getCssText()); - } - }; - } - return null; - } - - protected CSSValueImpl colorValue(String value) { - return colorValue(value, CSSValue.CSS_PRIMITIVE_VALUE); + /** A string-typed primitive value, the form the engine sees for quoted CSS strings. */ + protected CssPrimitive colorValue(String value) { + return new CssText(CssText.Kind.STRING, value); } - protected CSSValueImpl colorValue(String value, short type) { - CSSValueImpl result = mock(CSSValueImpl.class); - doReturn(CSSPrimitiveValue.CSS_STRING).when(result).getPrimitiveType(); - doReturn(type).when(result).getCssValueType(); - doReturn(value).when(result).getStringValue(); - doReturn(value).when(result).getCssText(); - return result; + /** A value that is deliberately not a primitive, for the rejection paths. */ + protected CssValue nonPrimitiveValue(String value) { + return new CssList(List.of(new CssText(CssText.Kind.STRING, value))); } protected String addFontDefinitionMarker(String fontDefinitionId) { diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandlerTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandlerTest.java index 9cd12589817..36c63e0ebf9 100644 --- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandlerTest.java +++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandlerTest.java @@ -29,13 +29,16 @@ import static org.mockito.Mockito.verify; import org.eclipse.core.internal.preferences.EclipsePreferences; +import java.util.List; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.dom.preference.EclipsePreferencesElement; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssList; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssText; +import org.eclipse.e4.ui.css.core.impl.dom.CssValues.CssValue; import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; public class EclipsePreferencesHandlerTest { @@ -74,13 +77,10 @@ void testApplyCSSPropertyWhenCssValueList() { EclipsePreferencesElement element = new EclipsePreferencesElement(preferences, engine); - CSSValue[] values = new CSSValue[] { mock(CSSValue.class), mock(CSSValue.class) }; + CssValue[] values = new CssValue[] { new CssText(CssText.Kind.IDENT, "one"), + new CssText(CssText.Kind.IDENT, "two") }; - CSSValueList listValue = mock(CSSValueList.class); - doReturn(CSSValue.CSS_VALUE_LIST).when(listValue).getCssValueType(); - doReturn(values.length).when(listValue).getLength(); - doReturn(values[0]).when(listValue).item(0); - doReturn(values[1]).when(listValue).item(1); + CssList listValue = new CssList(List.of(values)); EclipsePreferencesHandlerTestable handler = spy(new EclipsePreferencesHandlerTestable());