Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bundles/org.eclipse.e4.ui.css.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Export-Package: org.eclipse.e4.ui.css.core;x-internal:=true,
org.eclipse.e4.ui.css.core.impl.dom.parsers;x-internal:=true,
org.eclipse.e4.ui.css.core.impl.dom.properties;x-friends:="org.eclipse.e4.ui.css.swt",
org.eclipse.e4.ui.css.core.impl.engine;x-friends:="org.eclipse.e4.ui.css.swt,org.eclipse.e4.ui.workbench.swt",
org.eclipse.e4.ui.css.core.impl.engine.selector;x-friends:="org.eclipse.e4.ui.tests.css.core",
org.eclipse.e4.ui.css.core.impl.sac;x-internal:=true,
org.eclipse.e4.ui.css.core.resources;x-friends:="org.eclipse.e4.ui.css.swt,org.eclipse.e4.ui.workbench.renderers.swt",
org.eclipse.e4.ui.css.core.sac;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2013 Angelo Zerr and others.
* Copyright (c) 2008, 2026 Angelo Zerr and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,8 +13,7 @@
*******************************************************************************/
package org.eclipse.e4.ui.css.core.dom;

import org.w3c.css.sac.Selector;
import org.w3c.css.sac.SelectorList;
import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors;
import org.w3c.dom.css.CSSRule;

/**
Expand All @@ -28,7 +27,7 @@ public interface ExtendedCSSRule extends CSSRule {
public CSSPropertyList getCSSPropertyList();

/**
* Return the list of {@link Selector} of this {@link CSSRule}.
* Return the list of selectors of this {@link CSSRule}.
*/
public SelectorList getSelectorList();
public Selectors.SelectorList getSelectorList();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2018 Angelo Zerr and others.
* Copyright (c) 2008, 2026 Angelo Zerr and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,9 +15,6 @@
package org.eclipse.e4.ui.css.core.dom;

import java.util.EventListener;
import java.util.List;
import org.w3c.css.sac.Condition;
import org.w3c.css.sac.Selector;
import org.w3c.dom.css.DocumentCSS;
import org.w3c.dom.stylesheets.StyleSheet;

Expand All @@ -26,21 +23,10 @@
*/
public interface ExtendedDocumentCSS extends DocumentCSS {

public static final Integer SAC_ID_CONDITION = Integer.valueOf(Condition.SAC_ID_CONDITION);
public static final Integer SAC_CLASS_CONDITION = Integer.valueOf(Condition.SAC_CLASS_CONDITION);
public static final Integer SAC_PSEUDO_CLASS_CONDITION = Integer.valueOf(Condition.SAC_PSEUDO_CLASS_CONDITION);
public static final Integer OTHER_SAC_CONDITIONAL_SELECTOR = Integer.valueOf(Selector.SAC_CONDITIONAL_SELECTOR);

public static final Integer OTHER_SAC_SELECTOR = Integer.valueOf(999);

public void addStyleSheet(StyleSheet styleSheet);

public void removeAllStyleSheets();

public List<?> queryConditionSelector(int conditionType);

public List<?> querySelector(int selectorType, int conditionType);

/**
* @since 0.12.200
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import org.eclipse.e4.ui.css.core.dom.IElementProvider;
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
import org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverter;
import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors;
import org.eclipse.e4.ui.css.core.resources.IResourcesRegistry;
import org.eclipse.e4.ui.css.core.util.resources.IResourcesLocatorManager;
import org.w3c.css.sac.InputSource;
import org.w3c.css.sac.Selector;
import org.w3c.css.sac.SelectorList;
import org.w3c.dom.Element;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.CSSStyleSheet;
Expand Down Expand Up @@ -105,27 +104,27 @@ public interface CSSEngine {
/**
* Parse Selectors from String value.
*/
SelectorList parseSelectors(String text);
Selectors.SelectorList parseSelectors(String text);

/**
* Parse Selectors from InputSource value.
*/
SelectorList parseSelectors(InputSource source) throws IOException;
Selectors.SelectorList parseSelectors(InputSource source) throws IOException;

/**
* Parse Selectors from InputStream.
*/
SelectorList parseSelectors(InputStream stream) throws IOException;
Selectors.SelectorList parseSelectors(InputStream stream) throws IOException;

/**
* Parse Selectors from String value.
*/
SelectorList parseSelectors(Reader reader) throws IOException;
Selectors.SelectorList parseSelectors(Reader reader) throws IOException;

/**
* Check if the <code>selector</code> matches the object <code>node</code>.
*/
boolean matches(Selector selector, Object node, String pseudo);
boolean matches(Selectors.Selector selector, Object node, String pseudo);

/*--------------- Apply styles -----------------*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2015 Angelo Zerr and others.
* Copyright (c) 2008, 2026 Angelo Zerr and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -17,8 +17,7 @@

import org.eclipse.e4.ui.css.core.dom.CSSPropertyList;
import org.eclipse.e4.ui.css.core.dom.ExtendedCSSRule;
import org.w3c.css.sac.Selector;
import org.w3c.css.sac.SelectorList;
import org.eclipse.e4.ui.css.core.impl.engine.selector.Selectors;
import org.w3c.dom.DOMException;
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.css.CSSStyleDeclaration;
Expand All @@ -27,10 +26,10 @@

public class CSSStyleRuleImpl extends CSSRuleImpl implements CSSStyleRule, ExtendedCSSRule {

private final SelectorList selectors;
private final Selectors.SelectorList selectors;
private CSSStyleDeclaration styleDeclaration;

public CSSStyleRuleImpl(CSSStyleSheet parentStyleSheet, CSSRule parentRule, SelectorList selectors) {
public CSSStyleRuleImpl(CSSStyleSheet parentStyleSheet, CSSRule parentRule, Selectors.SelectorList selectors) {
super(parentStyleSheet, parentRule);
this.selectors = selectors;
}
Expand All @@ -55,17 +54,7 @@ public String getCssText() {

@Override
public String getSelectorText() {
StringBuilder sb = new StringBuilder();
for (int selID = 0; selID < getSelectorList().getLength(); selID++) {
Selector item = getSelectorList().item(selID);
sb.append(item.toString());
sb.append(", ");
}
if (getSelectorList().getLength() > 0) {
sb.delete(sb.length() - 2, sb.length());
}

return sb.toString();
return selectors.text();
}

@Override
Expand All @@ -83,7 +72,7 @@ public void setSelectorText(String selectorText) throws DOMException {
// Additional methods

@Override
public SelectorList getSelectorList() {
public Selectors.SelectorList getSelectorList() {
return selectors;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2018 Angelo Zerr and others.
* Copyright (c) 2008, 2026 Angelo Zerr and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -18,19 +18,10 @@
package org.eclipse.e4.ui.css.core.impl.dom;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.e4.ui.css.core.dom.ExtendedCSSRule;
import org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS;
import org.w3c.css.sac.ConditionalSelector;
import org.w3c.css.sac.Selector;
import org.w3c.css.sac.SelectorList;
import org.w3c.dom.Element;
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.css.CSSRuleList;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.CSSStyleSheet;
import org.w3c.dom.css.DocumentCSS;
import org.w3c.dom.stylesheets.StyleSheet;
import org.w3c.dom.stylesheets.StyleSheetList;
Expand All @@ -42,11 +33,6 @@ public class DocumentCSSImpl implements ExtendedDocumentCSS {

private final StyleSheetListImpl styleSheetList = new StyleSheetListImpl();

/**
* key=selector type, value = CSSStyleDeclaration
*/
private Map<Integer, List<?>> styleDeclarationMap;

private final List<StyleSheetChangeListener> styleSheetChangeListeners = new ArrayList<>(1);

@Override
Expand All @@ -72,93 +58,6 @@ public void removeAllStyleSheets() {
styleSheetChangeListeners.forEach(l -> l.styleSheetRemoved(styleSheet));
}
styleSheetList.removeAllStyleSheets();
this.styleDeclarationMap = null;
}

@Override
public List<?> queryConditionSelector(int conditionType) {
return querySelector(Selector.SAC_CONDITIONAL_SELECTOR, conditionType);
}

@Override
public List<?> querySelector(int selectorType, int conditionType) {
List<?> list = getCSSStyleDeclarationList(selectorType, conditionType);
if (list != null) {
return list;
}
int l = styleSheetList.getLength();
for (int i = 0; i < l; i++) {
CSSStyleSheet styleSheet = (CSSStyleSheet) styleSheetList.item(i);
CSSRuleList ruleList = styleSheet.getCssRules();
list = querySelector(ruleList, selectorType, conditionType);
setCSSStyleDeclarationList(list, selectorType, conditionType);
}
return list;
}

protected List<Selector> querySelector(CSSRuleList ruleList, int selectorType, int selectorConditionType) {
List<Selector> list = new ArrayList<>();
if (selectorType == Selector.SAC_CONDITIONAL_SELECTOR) {
int length = ruleList.getLength();
for (int i = 0; i < length; i++) {
CSSRule rule = ruleList.item(i);
if (rule.getType() == CSSRule.STYLE_RULE && rule instanceof ExtendedCSSRule r) {
SelectorList selectorList = r.getSelectorList();
// Loop for SelectorList
int l = selectorList.getLength();
for (int j = 0; j < l; j++) {
Selector selector = selectorList.item(j);
if (selector.getSelectorType() == selectorType) {
// It's conditional selector
ConditionalSelector conditionalSelector = (ConditionalSelector) selector;
short conditionType = conditionalSelector.getCondition().getConditionType();
if (selectorConditionType == conditionType) {
// current selector match the current CSS
// Rule
// CSSStyleRule styleRule = (CSSStyleRule)
// rule;
list.add(selector);
}
}
}
}
}
}
return list;
}

protected List<?> getCSSStyleDeclarationList(int selectorType, int conditionType) {
Integer key = getKey(selectorType, conditionType);
return getStyleDeclarationMap().get(key);
}

protected void setCSSStyleDeclarationList(List<?> list, int selectorType, int conditionType) {
Integer key = getKey(selectorType, conditionType);
getStyleDeclarationMap().put(key, list);
}

protected Integer getKey(int selectorType, int conditionType) {
if (selectorType == Selector.SAC_CONDITIONAL_SELECTOR) {
if (conditionType == SAC_CLASS_CONDITION.intValue()) {
return SAC_CLASS_CONDITION;
}
if (conditionType == SAC_ID_CONDITION.intValue()) {
return SAC_ID_CONDITION;
}
if (conditionType == SAC_PSEUDO_CLASS_CONDITION.intValue()) {
return SAC_PSEUDO_CLASS_CONDITION;
}
return OTHER_SAC_CONDITIONAL_SELECTOR;
}

return OTHER_SAC_SELECTOR;
}

protected Map<Integer, List<?>> getStyleDeclarationMap() {
if (styleDeclarationMap == null) {
styleDeclarationMap = new HashMap<>();
}
return styleDeclarationMap;
}

@Override
Expand Down
Loading
Loading