Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.e4.ui.css.core.impl.dom;

import java.util.Iterator;
import java.util.List;
import org.eclipse.e4.ui.css.core.dom.CSSProperty;
import org.eclipse.e4.ui.css.core.dom.CSSPropertyList;
Expand All @@ -37,10 +36,8 @@ public CSSComputedStyleImpl(List<StyleWrapper> styleRules) {
// TODO [rst] Optimize: A list of StyleWrapper instances could be sorted
// only once after reading the stylesheet(s).
this.styleRules.sort(StyleWrapper.COMPARATOR);
Iterator<StyleWrapper> iterator = this.styleRules.iterator();
while (iterator.hasNext()) {
StyleWrapper styleWrapper = iterator.next();
addCSSPropertyList(((CSSStyleDeclarationImpl) styleWrapper.style).getCSSPropertyList());
for (StyleWrapper styleWrapper : this.styleRules) {
addCSSPropertyList(((CSSStyleDeclarationImpl) styleWrapper.style()).getCSSPropertyList());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2014 EclipseSource and others.
* Copyright (c) 2009, 2026 EclipseSource and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -23,41 +23,12 @@
* together with all the information needed to calculate a matching selector's
* precedence.
*/
final class StyleWrapper {

private static class StyleWrapperComparator implements Comparator<StyleWrapper> {

@Override
public int compare(final StyleWrapper object1, final StyleWrapper object2) {
int result = 0;
StyleWrapper wrapper1 = object1;
StyleWrapper wrapper2 = object2;
if (wrapper1.specificity > wrapper2.specificity) {
result = 1;
} else if (wrapper1.specificity < wrapper2.specificity) {
result = -1;
} else if (wrapper1.position > wrapper2.position) {
result = 1;
} else if (wrapper1.position < wrapper2.position) {
result = -1;
}
return result;
}
}
final record StyleWrapper(CSSStyleDeclaration style, int specificity, int position) {

/**
* A comparator for {@link StyleWrapper}s.
*/
public static final StyleWrapperComparator COMPARATOR = new StyleWrapperComparator();

public final CSSStyleDeclaration style;
public final int specificity;
public final int position;
static final Comparator<StyleWrapper> COMPARATOR = Comparator.comparingInt(StyleWrapper::specificity)
.thenComparingInt(StyleWrapper::position);

public StyleWrapper(CSSStyleDeclaration style, int specificity,
int position) {
this.style = style;
this.specificity = specificity;
this.position = position;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private CSSStyleDeclaration getComputedStyle(List<CSSRule> ruleList, Element elt
return new CSSComputedStyleImpl(styleDeclarations);
}
if (firstStyleDeclaration != null) {
return firstStyleDeclaration.style;
return firstStyleDeclaration.style();
}
return null;
}
Expand Down
Loading
Loading