From bf091de44045a00585ca35d73da6b30160e70465 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Thu, 11 Jun 2026 19:37:35 +0200 Subject: [PATCH] Migrate CSS value consumers to the internal record model Move the property handlers, converters, and SWT helpers off the W3C CSSValue accessor API (getCssValueType, getPrimitiveType, getFloatValue, getStringValue, getRGBColorValue) onto pattern matching over the CssValues records. The records get their final internal shape: a CssUnit enum and a shared CssNumeric interface replace the raw W3C primitive type shorts on CssDimension, and CssText carries an explicit Kind (IDENT, STRING, URI, INHERIT). CSS2FontProperties and CSSBorderProperties now store CssPrimitive values, which retires the CSS2PrimitiveValueImpl and CSS2RGBColorImpl shims; CSS2ColorHelper and CSSSWTColorHelper build CssColor records directly. The old code distinguished widget-derived font sizes from CSS-set sizes through a null getCssText() quirk of CSS2PrimitiveValueImpl; that distinction is now an explicit sizeFromCSS flag on CSS2FontProperties, so font definitions still supply the height when no CSS size is set. The records still implement the W3C interfaces as a bridge for the style-declaration layer; the bridge goes away once the computed-style cascade is internal. The css.swt test helpers build real value records instead of Mockito mocks of CSSValueImpl, which the pattern matching would not recognize. Contributes to https://github.com/eclipse-platform/eclipse.platform.ui/issues/3980 --- .../e4/ui/css/core/css2/CSS2ColorHelper.java | 73 ++++---- .../e4/ui/css/core/css2/CSS2FontHelper.java | 22 +-- .../core/css2/CSS2FontPropertiesHelpers.java | 37 ++-- .../css/core/css2/CSS2PrimitiveValueImpl.java | 131 -------------- .../e4/ui/css/core/css2/CSS2RGBColorImpl.java | 52 ------ .../core/css2/CSSBorderPropertiesHelpers.java | 16 +- .../AbstractCSSPropertyCompositeHandler.java | 11 +- .../dom/properties/CSSBorderProperties.java | 6 +- .../ui/css/core/dom/properties/Gradient.java | 8 +- .../CSSValueBooleanConverterImpl.java | 9 +- ...CSSPropertyBackgroundCompositeHandler.java | 22 +-- ...ractCSSPropertyBorderCompositeHandler.java | 35 ++-- .../AbstractCSSPropertyBorderHandler.java | 17 +- ...stractCSSPropertyFontCompositeHandler.java | 7 +- .../css2/AbstractCSSPropertyFontHandler.java | 19 +- .../css2/AbstractCSSPropertyTextHandler.java | 17 +- .../properties/css2/CSS2FontProperties.java | 39 ++-- .../css2/CSS2FontPropertiesImpl.java | 56 +++--- .../e4/ui/css/core/impl/dom/CssValues.java | 103 ++++++++--- .../properties/CSSBorderPropertiesImpl.java | 8 +- .../e4/ui/css/core/impl/parser/CssParser.java | 50 +++--- .../core/resources/CSSResourcesHelpers.java | 65 +++---- .../ui/css/swt/helpers/CSSSWTColorHelper.java | 170 ++++++++---------- .../css/swt/helpers/CSSSWTCursorHelper.java | 10 +- .../ui/css/swt/helpers/CSSSWTFontHelper.java | 52 +++--- .../e4/ui/css/swt/helpers/CSSSWTHelpers.java | 4 +- .../ui/css/swt/helpers/CSSSWTImageHelper.java | 12 +- .../CSSValueSWTColorConverterImpl.java | 4 +- .../CSSValueSWTGradientConverterImpl.java | 13 +- .../CSSValueSWTRGBConverterImpl.java | 4 +- .../css2/CSSPropertyBackgroundSWTHandler.java | 11 +- .../css2/CSSPropertyBorderSWTHandler.java | 7 +- .../CSSPropertyClassificationSWTHandler.java | 10 +- .../css2/CSSPropertyFontSWTHandler.java | 1 + .../css2/CSSPropertyMarginSWTHandler.java | 14 +- .../css2/CSSPropertyPaddingSWTHandler.java | 35 ++-- .../css2/CSSPropertyTextSWTHandler.java | 3 +- .../CSSBackgroundModePropertyHandler.java | 3 +- ...yCustomTabContentBackgroundSWTHandler.java | 3 +- .../custom/CSSPropertyHeaderHandler.java | 5 +- .../CSSPropertyInnerKeylineSWTHandler.java | 3 +- .../CSSPropertyLinesVisibleSWTHandler.java | 3 +- .../custom/CSSPropertyLinkSWTHandler.java | 3 +- .../CSSPropertyOuterKeylineSWTHandler.java | 3 +- .../CSSPropertySelectedTabsSWTHandler.java | 3 +- .../custom/CSSPropertyTabHeightHandler.java | 8 +- .../CSSPropertyTabPositionSWTHandler.java | 8 +- .../CSSPropertyTabRendererSWTHandler.java | 9 +- ...rtyTabTextMinimumCharactersSWTHandler.java | 7 +- ...UnselectHotTabsColorBackgroundHandler.java | 3 +- .../CSSPropertyUnselectedTabsSWTHandler.java | 6 +- .../CSSPropertye4SelectedTabFillHandler.java | 6 +- .../custom/CSSPropertye4TabOutline.java | 3 +- ...PropertyThemeElementDefinitionHandler.java | 7 +- .../preference/EclipsePreferencesHandler.java | 9 +- .../org.eclipse.ui.forms/META-INF/MANIFEST.MF | 2 +- .../css2/CSSPropertyFormHandler.java | 2 +- .../swt/helpers/CSSSWTColorHelperTest.java | 4 +- .../css/swt/helpers/CSSSWTHelperTestCase.java | 64 +++---- .../EclipsePreferencesHandlerTest.java | 14 +- 60 files changed, 586 insertions(+), 745 deletions(-) delete mode 100644 bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2PrimitiveValueImpl.java delete mode 100644 bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/css2/CSS2RGBColorImpl.java 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/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/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/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/parser/CssParser.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/parser/CssParser.java index d9d4313e1d9..395e4f8ac97 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 @@ -26,9 +26,11 @@ 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; @@ -47,7 +49,6 @@ 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; @@ -253,21 +254,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 +284,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 +328,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/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..17415338f0b 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 @@ -380,6 +380,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.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.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());