Search in sources :

Example 1 with CSSStyleSheet

use of org.w3c.dom.css.CSSStyleSheet in project webtools.sourceediting by eclipse.

the class CSSCharsetRuleTest method testInsertRule.

public void testInsertRule() {
    CSSStyleSheet sheet = getStyleSheet();
    assertEquals(0, sheet.insertRule(RULE, 0));
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSCharsetRule);
    CSSCharsetRule charsetRule = (CSSCharsetRule) rule;
    assertEquals("iso-8859-1", charsetRule.getEncoding());
    assertEquals(RULE, charsetRule.getCssText());
}
Also used : CSSCharsetRule(org.w3c.dom.css.CSSCharsetRule) CSSRule(org.w3c.dom.css.CSSRule) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 2 with CSSStyleSheet

use of org.w3c.dom.css.CSSStyleSheet in project webtools.sourceediting by eclipse.

the class CSSFontFamilyTest method testFontFamilies.

public void testFontFamilies() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFamilyTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList rules = sheet.getCssRules();
    assertEquals(4, rules.getLength());
    // Rule 1: No whitespace
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    // Rule 1: No whitespace
    rule = rules.item(0);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier"));
    // Rule 2: Single whitespace
    rule = rules.item(1);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier New"));
    // Rule 3: In quotes
    rule = rules.item(2);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "Courier New"));
    // Rule 4: Tabs and spaces all over
    rule = rules.item(3);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Comic Sans"));
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleRule(org.w3c.dom.css.CSSStyleRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 3 with CSSStyleSheet

use of org.w3c.dom.css.CSSStyleSheet in project webtools.sourceediting by eclipse.

the class CSSPageRuleTest method testInsertText4.

public void testInsertText4() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSPageRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(6, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    // rule 4
    rule = ruleList.item(3);
    assertEquals(CSSRule.PAGE_RULE, rule.getType());
    assertTrue(rule instanceof CSSPageRule);
    assertEquals(":right", ((CSSPageRule) rule).getSelectorText());
    declaration = ((CSSPageRule) rule).getStyle();
    assertEquals(2, declaration.getLength());
    value = declaration.getPropertyCSSValue("margin-left");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 3));
    value = declaration.getPropertyCSSValue("margin-right");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 4));
}
Also used : CSSPageRule(org.w3c.dom.css.CSSPageRule) CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 4 with CSSStyleSheet

use of org.w3c.dom.css.CSSStyleSheet in project webtools.sourceediting by eclipse.

the class CSSPageRuleTest method testInsertText5.

public void testInsertText5() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSPageRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(6, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    CSSValueList valueList;
    // rule 5
    rule = ruleList.item(4);
    assertEquals(CSSRule.PAGE_RULE, rule.getType());
    assertTrue(rule instanceof CSSPageRule);
    assertEquals("narrow", ((CSSPageRule) rule).getSelectorText());
    declaration = ((CSSPageRule) rule).getStyle();
    assertEquals(1, declaration.getLength());
    value = declaration.getPropertyCSSValue("size");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(2, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 9));
    checkPrimitiveNumber(valueList.item(1), new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 18));
}
Also used : CSSPageRule(org.w3c.dom.css.CSSPageRule) CSSValue(org.w3c.dom.css.CSSValue) CSSValueList(org.w3c.dom.css.CSSValueList) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 5 with CSSStyleSheet

use of org.w3c.dom.css.CSSStyleSheet in project webtools.sourceediting by eclipse.

the class CSSStyleSheetTest method testInsertRule.

public void testInsertRule() {
    CSSStyleSheet sheet = getStyleSheet();
    assertEquals(0, sheet.insertRule(RULE_H3, 0));
    assertEquals(0, sheet.insertRule(RULE_H1, 0));
    assertEquals(1, sheet.insertRule(RULE_H2, 1));
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule;
    rule = ruleList.item(0);
    assertEquals(RULE_H1, rule.getCssText());
    rule = ruleList.item(1);
    assertEquals(RULE_H2, rule.getCssText());
    rule = ruleList.item(2);
    assertEquals(RULE_H3, rule.getCssText());
}
Also used : CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Aggregations

CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)22 CSSRule (org.w3c.dom.css.CSSRule)20 CSSRuleList (org.w3c.dom.css.CSSRuleList)19 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)15 CSSValue (org.w3c.dom.css.CSSValue)15 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)14 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)14 CSSPageRule (org.w3c.dom.css.CSSPageRule)6 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)5 CSSValueList (org.w3c.dom.css.CSSValueList)5 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)4 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)3 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2 CSSOMParser (com.steadystate.css.parser.CSSOMParser)1 IOException (java.io.IOException)1 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)1 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 InputSource (org.w3c.css.sac.InputSource)1