Search in sources :

Example 1 with CSSStyleRule

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

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

the class CSSStyleRuleTest method testInsertTextStrings.

public void testInsertTextStrings() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSStyleRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(3, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    rule = ruleList.item(1);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    assertEquals(11, declaration.getLength());
    // 01
    value = declaration.getPropertyCSSValue("STRING");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "string"));
    // 02
    value = declaration.getPropertyCSSValue("URI");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_URI, "http://www.ibm.com/"));
    // 03
    value = declaration.getPropertyCSSValue("IDENT");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "left"));
    // 04
    value = declaration.getPropertyCSSValue("HASH");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_HASH, "#abcdef"));
    // 05
    value = declaration.getPropertyCSSValue("URANGE");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_URANGE, "U+20A7"));
    // 06
    value = declaration.getPropertyCSSValue("SLASH");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_SLASH, "/"));
    // 07
    value = declaration.getPropertyCSSValue("COMMA");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    // 08
    value = declaration.getPropertyCSSValue("INHERIT_PRIMITIVE");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_INHERIT_PRIMITIVE, "inherit"));
    // 09
    value = declaration.getPropertyCSSValue("ATTR");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_ATTR, "KEY"));
    // 10
    value = declaration.getPropertyCSSValue("FORMAT");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_FORMAT, "truedoc"));
    // 11
    value = declaration.getPropertyCSSValue("LOCAL");
    checkPrimitiveString(value, new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "Excelsior Roman"));
}
Also used : 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 CSSStyleRule

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

the class CSSRuleFoldingPosition method getStartOffset.

/**
 * @see org.eclipse.wst.sse.ui.internal.projection.AbstractStructuredFoldingPosition#getStartOffset()
 */
protected int getStartOffset() {
    int startOffset = fRegion.getStartOffset();
    // so that multi-line CSS selector text does not get folded
    if (this.fRegion instanceof CSSStyleRule) {
        CSSStyleRule rule = (CSSStyleRule) this.fRegion;
        startOffset += rule.getSelectorText().length();
    }
    return startOffset;
}
Also used : CSSStyleRule(org.w3c.dom.css.CSSStyleRule)

Example 4 with CSSStyleRule

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

the class CSSFontFamilyTest method testValueModification.

public void testValueModification() 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"));
    declaration.setProperty(FONT_FAMILY, "\"Times New Roman\", Times, serif", "");
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    assertTrue(value instanceof ICSSValue);
    assertEquals("\"Times New Roman\", Times, serif", ((ICSSValue) value).getCSSValueText());
    declaration.setProperty(FONT_FAMILY, "\"Times New Roman\", Times", "");
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    assertTrue(value instanceof ICSSValue);
    assertEquals("\"Times New Roman\", Times", ((ICSSValue) value).getCSSValueText());
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) 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 5 with CSSStyleRule

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

the class StyleSheetTest method testImportMethods.

/**
 * Tests that imports can be resolved using the various syntaxes for import.
 * <ul>
 * <li>@import url("example.css");</li>
 * <li>@import url(example.css);</li>
 * <li>@import "example.css";</li>
 * </ul>
 * @throws Exception
 */
public void testImportMethods() throws Exception {
    String filePath = "/" + PROJECT_NAME + "/WebContent/importMethods.css";
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
    assertTrue("File doesn't exist: " + filePath, file.exists());
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForRead(file);
        if (model instanceof ICSSModel) {
            ICSSDocument document = ((ICSSModel) model).getDocument();
            if (document instanceof ICSSStyleSheet) {
                CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
                assertTrue("There should be a total of 3 rules.", list.getLength() == 3);
                for (int i = 0; i < list.getLength(); i++) {
                    CSSRule rule = list.item(i);
                    assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
                    CSSStyleRule style = (CSSStyleRule) rule;
                    assertEquals("Selector text did not match.", "#content", style.getSelectorText().trim());
                }
            }
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleRule(org.w3c.dom.css.CSSStyleRule) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Aggregations

CSSStyleRule (org.w3c.dom.css.CSSStyleRule)8 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)7 CSSRule (org.w3c.dom.css.CSSRule)7 CSSRuleList (org.w3c.dom.css.CSSRuleList)7 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)5 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)5 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)5 CSSValue (org.w3c.dom.css.CSSValue)5 IFile (org.eclipse.core.resources.IFile)2 Path (org.eclipse.core.runtime.Path)2 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2