Search in sources :

Example 1 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList 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 CSSRuleList

use of org.w3c.dom.css.CSSRuleList 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 CSSRuleList

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

the class CSSMediaRuleTest method testCreateRule.

public void testCreateRule() {
    ICSSStyleSheet sheet = getStyleSheet();
    ICSSDocument doc = sheet;
    ICSSMediaRule newRule = doc.createCSSMediaRule();
    MediaList newList = newRule.getMedia();
    newList.appendMedium("media1");
    newList.appendMedium("media2");
    sheet.insertRuleBefore(newRule, null);
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSMediaRule);
    CSSMediaRule mediaRule = (CSSMediaRule) rule;
    MediaList mediaList = mediaRule.getMedia();
    assertEquals(2, mediaList.getLength());
    assertEquals("media1", mediaList.item(0));
    assertEquals("media2", mediaList.item(1));
    assertEquals("@media media1, media2 {" + FileUtil.commonEOL + "}", mediaRule.getCssText());
}
Also used : ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) MediaList(org.w3c.dom.stylesheets.MediaList) CSSRule(org.w3c.dom.css.CSSRule) ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) CSSMediaRule(org.w3c.dom.css.CSSMediaRule) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 4 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList 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 5 with CSSRuleList

use of org.w3c.dom.css.CSSRuleList 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)

Aggregations

CSSRuleList (org.w3c.dom.css.CSSRuleList)30 CSSRule (org.w3c.dom.css.CSSRule)29 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)19 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)19 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)17 CSSValue (org.w3c.dom.css.CSSValue)15 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)14 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)10 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)8 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)7 IFile (org.eclipse.core.resources.IFile)6 CSSPageRule (org.w3c.dom.css.CSSPageRule)6 Path (org.eclipse.core.runtime.Path)5 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 CSSValueList (org.w3c.dom.css.CSSValueList)5 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)4 CSSStyleRuleImpl (com.steadystate.css.dom.CSSStyleRuleImpl)2 CSSStyleSheetImpl (com.steadystate.css.dom.CSSStyleSheetImpl)2 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2