Skip to content

Commit 0588f8d

Browse files
committed
Upgrade to css4j 3.9.0
1 parent 3b51bdf commit 0588f8d

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies {
2626
api('io.sf.carte:css4j') {
2727
version {
2828
strictly '[3.7.1,)'
29-
prefer '3.8.0'
29+
prefer '3.9.0'
3030
}
3131
}
3232
useragentImplementation('io.sf.carte:css4j-agent') {
@@ -48,7 +48,7 @@ dependencies {
4848
xmlpullImplementation 'xmlpull:xmlpull:1.2.0'
4949
xmlpullImplementation 'xpp3:xpp3_min:1.2.0'
5050
testImplementation group: 'io.sf.carte', name: 'css4j', classifier: 'tests',
51-
version: '3.8.0'
51+
version: '3.9.0'
5252
testImplementation 'jaxen:jaxen:1.2.0'
5353
testImplementation('org.slf4j:slf4j-api') {
5454
version {

junit/io/sf/carte/doc/dom4j/XHTMLDocumentTest.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,24 @@
4545
import io.sf.carte.doc.style.css.nsac.CSSParseException;
4646
import io.sf.carte.doc.style.css.nsac.InputSource;
4747
import io.sf.carte.doc.style.css.nsac.LexicalUnit;
48+
import io.sf.carte.doc.style.css.nsac.SelectorList;
4849
import io.sf.carte.doc.style.css.om.AbstractCSSRule;
4950
import io.sf.carte.doc.style.css.om.AbstractCSSStyleDeclaration;
5051
import io.sf.carte.doc.style.css.om.AbstractCSSStyleSheet;
5152
import io.sf.carte.doc.style.css.om.BaseCSSDeclarationRule;
53+
import io.sf.carte.doc.style.css.om.BaseCSSStyleSheet;
5254
import io.sf.carte.doc.style.css.om.CSSOMParser;
5355
import io.sf.carte.doc.style.css.om.CSSRuleArrayList;
5456
import io.sf.carte.doc.style.css.om.ComputedCSSStyle;
5557
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
5658
import io.sf.carte.doc.style.css.om.MediaRule;
59+
import io.sf.carte.doc.style.css.om.PropertyCountVisitor;
60+
import io.sf.carte.doc.style.css.om.StyleCountVisitor;
61+
import io.sf.carte.doc.style.css.om.StyleRule;
62+
import io.sf.carte.doc.style.css.parser.CSSParser;
5763
import io.sf.carte.doc.style.css.parser.SyntaxParser;
5864
import io.sf.carte.doc.style.css.property.LexicalValue;
65+
import io.sf.carte.doc.style.css.property.TypedValue;
5966

6067
public class XHTMLDocumentTest {
6168

@@ -893,6 +900,60 @@ public void testCascade() throws IOException {
893900
assertEquals("#8a2be2", style.getPropertyValue("color"));
894901
}
895902

903+
@Test
904+
public void testCascade2() throws IOException {
905+
BaseCSSStyleSheet sheet = (BaseCSSStyleSheet) xhtmlDoc.getStyleSheets().item(5);
906+
907+
// Obtain the rule where a value is declared
908+
CSSParser parser = new CSSParser();
909+
SelectorList selist = parser.parseSelectors("p.boldmargin");
910+
StyleRule rule = (StyleRule) sheet.getFirstStyleRule(selist);
911+
assertNotNull(rule);
912+
913+
AbstractCSSStyleDeclaration declStyle = rule.getStyle();
914+
TypedValue declMarginLeft = (TypedValue) declStyle.getPropertyCSSValue("margin-left");
915+
assertEquals("2%", declMarginLeft.getCssText());
916+
917+
/*
918+
* Get an element that obtains the above value as computed style
919+
*/
920+
XHTMLElement elm = xhtmlDoc.getElementById("para1");
921+
assertNotNull(elm);
922+
CSSStyleDeclaration style = elm.getComputedStyle(null);
923+
assertEquals("2%", style.getPropertyValue("margin-left"));
924+
925+
// Change the value itself
926+
declMarginLeft.setFloatValue(CSSUnit.CSS_PX, 6f);
927+
style = elm.getComputedStyle(null);
928+
assertEquals("6px", style.getPropertyValue("margin-left"));
929+
930+
// Overwrite the property's value
931+
declStyle.setProperty("margin-left", "4px", null);
932+
style = elm.getComputedStyle(null);
933+
// The new value is not there yet
934+
assertEquals("6px", style.getPropertyValue("margin-left"));
935+
936+
// Rebuild the cascade
937+
xhtmlDoc.rebuildCascade();
938+
style = elm.getComputedStyle(null);
939+
assertEquals("4px", style.getPropertyValue("margin-left"));
940+
}
941+
942+
@Test
943+
public void testVisitors() throws IOException {
944+
StyleCountVisitor visitor = new StyleCountVisitor();
945+
xhtmlDoc.getStyleSheets().acceptStyleRuleVisitor(visitor);
946+
assertEquals(29, visitor.getCount());
947+
//
948+
PropertyCountVisitor visitorP = new PropertyCountVisitor();
949+
xhtmlDoc.getStyleSheets().acceptDeclarationRuleVisitor(visitorP);
950+
assertEquals(111, visitorP.getCount());
951+
//
952+
visitorP.reset();
953+
xhtmlDoc.getStyleSheets().acceptDescriptorRuleVisitor(visitorP);
954+
assertEquals(2, visitorP.getCount());
955+
}
956+
896957
@Test
897958
public void testStyleElement() {
898959
StyleElement style = (StyleElement) xhtmlDoc.getElementsByTagName("style").item(0);

junit/io/sf/carte/doc/dom4j/XMLDocumentBuilderTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package io.sf.carte.doc.dom4j;
1313

1414
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.assertFalse;
1516
import static org.junit.Assert.assertNotNull;
1617
import static org.junit.Assert.assertNull;
1718
import static org.junit.Assert.assertTrue;
@@ -153,9 +154,14 @@ private void testPlainXML(Document document) {
153154
Element docElement = document.getDocumentElement();
154155
assertNotNull(docElement);
155156
assertEquals("body", docElement.getNodeName());
157+
156158
Element element = document.getElementById("divid");
157159
assertNotNull(element);
158160
assertTrue(element.hasChildNodes());
161+
assertEquals("divid", element.getAttribute("id"));
162+
163+
assertFalse(element.hasAttribute("xmlns"));
164+
159165
Node parent = element.getParentNode();
160166
assertNotNull(parent);
161167
assertEquals("body", parent.getNodeName());

src/io/sf/carte/doc/dom4j/XHTMLDocument.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@ public CSSCanvas getCanvas() {
610610
return canvas;
611611
}
612612

613+
@Override
614+
public void rebuildCascade() {
615+
onStyleModify();
616+
}
617+
613618
@Override
614619
protected XHTMLDocumentFactory getDocumentFactory() {
615620
return (XHTMLDocumentFactory) super.getDocumentFactory();

0 commit comments

Comments
 (0)