Skip to content

Commit ef8e9f8

Browse files
committed
Replace the W3C computed-style cascade with internal types
Fold the ViewCSS/DocumentCSS machinery into the engine: CSSEngineImpl now holds the stylesheet list and a cached flat rule list directly, and the former ViewCSSImpl.getComputedStyle logic becomes CSSEngine.computeStyle. The rule and stylesheet mirror drops its W3C interfaces: CSSStyleSheetImpl is a plain list of CssRule (a new sealed interface), CSSStyleRuleImpl and CSSImportRuleImpl are simple internal classes, and ViewCSSImpl, DocumentCSSImpl, StyleSheetListImpl, CSSRuleImpl, CSSRuleListImpl, MediaListImpl, AbstractCSSNode, ExtendedCSSRule, and ExtendedDocumentCSS are deleted. CSSEngine.parseStyleSheet now returns the internal stylesheet type and getDocumentCSS()/getViewCSS() are replaced by computeStyle; a deprecated getViewCSS() default method remains as a binary-compatibility bridge for bundles compiled against the old accessor. CSSStyleDeclarationImpl keeps implementing the W3C CSSStyleDeclaration interface because IStylingEngine.getStyle and IThemeEngine.getStyle are frozen public API returning that type; its parent rule is now the internal CSSStyleRuleImpl, reachable via getParentStyleRule(), and the W3C getParentRule() returns null. In-tree callers (ThemeEngine, the font handler, CSSRenderingUtils, PartRenderingEngine) and the css.core parser tests move to the internal API. Contributes to #3980
1 parent fa1a384 commit ef8e9f8

33 files changed

Lines changed: 440 additions & 1169 deletions

File tree

bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedCSSRule.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/dom/ExtendedDocumentCSS.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/engine/CSSEngine.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
import org.eclipse.e4.ui.css.core.dom.IElementProvider;
2121
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
2222
import org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverter;
23+
import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleSheetImpl;
2324
import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors;
2425
import org.eclipse.e4.ui.css.core.resources.IResourcesRegistry;
2526
import org.eclipse.e4.ui.css.core.util.resources.IResourcesLocatorManager;
2627
import org.w3c.dom.Element;
2728
import org.w3c.dom.css.CSSStyleDeclaration;
28-
import org.w3c.dom.css.CSSStyleSheet;
2929
import org.w3c.dom.css.CSSValue;
30-
import org.w3c.dom.css.DocumentCSS;
3130
import org.w3c.dom.css.ViewCSS;
32-
import org.w3c.dom.stylesheets.StyleSheet;
31+
import org.w3c.dom.views.DocumentView;
3332

3433
/**
3534
* CSS Engine interface used to parse style sheet and apply styles to something
@@ -42,18 +41,18 @@ public interface CSSEngine {
4241
/**
4342
* Parse style sheet from Reader reader.
4443
*/
45-
StyleSheet parseStyleSheet(Reader reader) throws IOException;
44+
CSSStyleSheetImpl parseStyleSheet(Reader reader) throws IOException;
4645

4746
/**
4847
* Parse style sheet from InputStream stream.
4948
*/
50-
StyleSheet parseStyleSheet(InputStream stream) throws IOException;
49+
CSSStyleSheetImpl parseStyleSheet(InputStream stream) throws IOException;
5150

5251
/**
5352
* Parse style sheet from InputStream stream, using {@code uri} as the base
5453
* location for resolving relative {@code @import} rules.
5554
*/
56-
StyleSheet parseStyleSheet(InputStream stream, String uri) throws IOException;
55+
CSSStyleSheetImpl parseStyleSheet(InputStream stream, String uri) throws IOException;
5756

5857
/*--------------- Parse style declaration -----------------*/
5958

@@ -184,17 +183,32 @@ public interface CSSEngine {
184183
*/
185184
IResourcesLocatorManager getResourcesLocatorManager();
186185

187-
/*--------------- Document/View CSS -----------------*/
186+
/*--------------- Computed style -----------------*/
188187

189188
/**
190-
* Return the {@link DocumentCSS} used to store {@link CSSStyleSheet}.
189+
* Compute the merged style declaration for the given element and pseudo
190+
* element from all stylesheets registered with this engine.
191191
*/
192-
DocumentCSS getDocumentCSS();
192+
CSSStyleDeclaration computeStyle(Element element, String pseudoElt);
193193

194194
/**
195-
* Return the {@link ViewCSS} used to compute {@link CSSStyleDeclaration}.
195+
* Binary-compatibility bridge for callers compiled against the removed
196+
* W3C cascade accessor; use {@link #computeStyle(Element, String)}.
196197
*/
197-
ViewCSS getViewCSS();
198+
@Deprecated(forRemoval = true, since = "2026-06")
199+
default ViewCSS getViewCSS() {
200+
return new ViewCSS() {
201+
@Override
202+
public DocumentView getDocument() {
203+
return null;
204+
}
205+
206+
@Override
207+
public CSSStyleDeclaration getComputedStyle(Element elt, String pseudoElt) {
208+
return computeStyle(elt, pseudoElt);
209+
}
210+
};
211+
}
198212

199213
/*--------------- w3c Element -----------------*/
200214

bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSComputedStyleImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public CSSComputedStyleImpl(List<StyleWrapper> styleRules) {
3737
// only once after reading the stylesheet(s).
3838
this.styleRules.sort(StyleWrapper.COMPARATOR);
3939
for (StyleWrapper styleWrapper : this.styleRules) {
40-
addCSSPropertyList(((CSSStyleDeclarationImpl) styleWrapper.style()).getCSSPropertyList());
40+
addCSSPropertyList(styleWrapper.style().getCSSPropertyList());
4141
}
4242
}
4343

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2008, 2015 Angelo Zerr and others.
2+
* Copyright (c) 2008, 2026 Angelo Zerr and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -12,46 +12,26 @@
1212
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
1313
* IBM Corporation - ongoing development
1414
*******************************************************************************/
15-
1615
package org.eclipse.e4.ui.css.core.impl.dom;
1716

18-
import org.w3c.dom.css.CSSImportRule;
19-
import org.w3c.dom.css.CSSRule;
20-
import org.w3c.dom.css.CSSStyleSheet;
21-
import org.w3c.dom.stylesheets.MediaList;
22-
23-
public class CSSImportRuleImpl extends CSSRuleImpl implements CSSImportRule {
17+
/**
18+
* An {@code @import} rule. The engine resolves and inlines the referenced
19+
* stylesheet when the surrounding sheet is parsed.
20+
*/
21+
public final class CSSImportRuleImpl implements CssRule {
2422

25-
String uri;
26-
MediaListImpl mediaList;
23+
private final String href;
2724

28-
public CSSImportRuleImpl(CSSStyleSheet parentStyleSheet, CSSRule parentRule,
29-
String uri, MediaListImpl mediaListImpl) {
30-
super(parentStyleSheet, parentRule);
31-
this.uri = uri;
32-
this.mediaList = mediaListImpl;
33-
}
34-
35-
@Override
36-
public short getType() {
37-
return CSSRule.IMPORT_RULE;
25+
public CSSImportRuleImpl(String href) {
26+
this.href = href;
3827
}
3928

40-
// W3C CSSImportRule API methods
41-
42-
@Override
4329
public String getHref() {
44-
return uri;
45-
}
46-
47-
@Override
48-
public MediaList getMedia() {
49-
return mediaList;
30+
return href;
5031
}
5132

5233
@Override
53-
public CSSStyleSheet getStyleSheet() {
54-
// TODO Auto-generated method stub
55-
throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
34+
public String toString() {
35+
return "@import url(" + href + ")"; //$NON-NLS-1$ //$NON-NLS-2$
5636
}
57-
}
37+
}

bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSRuleImpl.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSRuleListImpl.java

Lines changed: 0 additions & 53 deletions
This file was deleted.

bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/dom/CSSStyleDeclarationImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
import org.w3c.dom.css.CSSStyleDeclaration;
2727
import org.w3c.dom.css.CSSValue;
2828

29-
public class CSSStyleDeclarationImpl extends AbstractCSSNode implements CSSStyleDeclaration {
29+
public class CSSStyleDeclarationImpl implements CSSStyleDeclaration {
3030

3131
private boolean readOnly;
32-
private final CSSRule parentRule;
32+
private final CSSStyleRuleImpl parentRule;
3333
private final List<CSSProperty> properties = new ArrayList<>();
3434
private CSSPropertyList cssPropertyListView;
3535

36-
public CSSStyleDeclarationImpl(CSSRule parentRule) {
36+
public CSSStyleDeclarationImpl(CSSStyleRuleImpl parentRule) {
3737
this.parentRule = parentRule;
3838
}
3939

@@ -61,6 +61,13 @@ public int getLength() {
6161

6262
@Override
6363
public CSSRule getParentRule() {
64+
// The internal rule model no longer implements the W3C CSSRule type;
65+
// use getParentStyleRule() instead.
66+
return null;
67+
}
68+
69+
/** The style rule this declaration belongs to, or null for computed styles. */
70+
public CSSStyleRuleImpl getParentStyleRule() {
6471
return parentRule;
6572
}
6673

0 commit comments

Comments
 (0)