Search in sources :

Example 21 with CSSStyleDeclaration

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

the class CSSFontFaceRuleTest method _testInsertText2.

public void _testInsertText2() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFaceRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(3, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    CSSValueList valueList;
    // rule 2
    rule = ruleList.item(1);
    assertEquals(CSSRule.FONT_FACE_RULE, rule.getType());
    assertTrue(rule instanceof CSSFontFaceRule);
    declaration = ((CSSFontFaceRule) rule).getStyle();
    assertEquals(6, declaration.getLength());
    value = declaration.getPropertyCSSValue("src");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(9, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "Palatino"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "Times New Roman"));
    checkPrimitiveString(valueList.item(3), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(4), new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "New York"));
    checkPrimitiveString(valueList.item(5), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(6), new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "Utopia"));
    checkPrimitiveString(valueList.item(7), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(8), new PrimitiveString(CSSPrimitiveValue.CSS_URI, "http://somewhere/free/font"));
    value = declaration.getPropertyCSSValue("font-family");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "serif"));
    value = declaration.getPropertyCSSValue("font-weight");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(9, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 100));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 200));
    checkPrimitiveString(valueList.item(3), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(4), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 300));
    checkPrimitiveString(valueList.item(5), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(6), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 400));
    checkPrimitiveString(valueList.item(7), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(8), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 500));
    value = declaration.getPropertyCSSValue("font-style");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "normal"));
    value = declaration.getPropertyCSSValue("font-variant");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "normal"));
    value = declaration.getPropertyCSSValue("font-size");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "all"));
}
Also used : 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) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 22 with CSSStyleDeclaration

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

the class CSSStyleRuleTest method testInsertTextNumbers.

public void testInsertTextNumbers() 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(0);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    assertEquals(20, declaration.getLength());
    // 01
    value = declaration.getPropertyCSSValue("NUMBER");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_NUMBER, 123.456f));
    // 02
    value = declaration.getPropertyCSSValue("PERCENTAGE");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PERCENTAGE, 123.456f));
    // 03
    value = declaration.getPropertyCSSValue("EMS");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_EMS, 123.456f));
    // 04
    value = declaration.getPropertyCSSValue("EXS");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_EXS, 123.456f));
    // 05
    value = declaration.getPropertyCSSValue("PX");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PX, +123.456f));
    value = declaration.getPropertyCSSValue("PX2");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PX, -123f));
    // 06
    value = declaration.getPropertyCSSValue("CM");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 123.456f));
    // 07
    value = declaration.getPropertyCSSValue("MM");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_MM, 123.456f));
    // 08
    value = declaration.getPropertyCSSValue("IN");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_IN, 123.456f));
    // 09
    value = declaration.getPropertyCSSValue("PT");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PT, 123.456f));
    // 10
    value = declaration.getPropertyCSSValue("PC");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PC, 123.456f));
    // 11
    value = declaration.getPropertyCSSValue("DEG");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_DEG, -123.456f));
    // 12
    value = declaration.getPropertyCSSValue("RAD");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_RAD, 123.456f));
    // 13
    value = declaration.getPropertyCSSValue("GRAD");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_GRAD, 123.456f));
    // 14
    value = declaration.getPropertyCSSValue("MS");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_MS, 123.456f));
    // 15
    value = declaration.getPropertyCSSValue("S");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_S, 123.456f));
    // 16
    value = declaration.getPropertyCSSValue("HZ");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_HZ, 123.456f));
    // 17
    value = declaration.getPropertyCSSValue("KHZ");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_KHZ, 123.456f));
    // 18
    value = declaration.getPropertyCSSValue("DIMENSION");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_DIMENSION, -123.456f));
    // 19
    value = declaration.getPropertyCSSValue("INTEGER");
    checkPrimitiveNumber(value, new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 123));
}
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 23 with CSSStyleDeclaration

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

the class CSSStyleRuleTest method testInsertTextFunctions.

public void testInsertTextFunctions() 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(2);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    assertEquals(3, declaration.getLength());
    value = declaration.getPropertyCSSValue("COUNTER");
    checkPrimitiveCounter(value, "par-num", "upper-roman", null);
    value = declaration.getPropertyCSSValue("RECT");
    checkPrimitiveRect(value, new Object[] { new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 12), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 34), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 56), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 78) });
    value = declaration.getPropertyCSSValue("RGBCOLOR");
    checkPrimitiveRgb(value, new Object[] { new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 255), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 128), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 0) });
}
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 24 with CSSStyleDeclaration

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

the class CSSModelParser method insertStructuredDocumentRegion.

/**
 * currently public but may be made default access protected in future.
 */
protected CSSNodeImpl insertStructuredDocumentRegion(IStructuredDocumentRegion region) {
    if (fCreationContext == null || region == null) {
        return null;
    }
    String type = ((BasicStructuredDocumentRegion) region).getType();
    CSSNodeImpl modified = null;
    ICSSNode target = fCreationContext.getTargetNode();
    if ((fParseFloating && target == null) || target instanceof ICSSRuleContainer) {
        if (type == CSSRegionContexts.CSS_DELIMITER) {
            modified = insertSemiColonForRule(region);
        } else if (type == CSSRegionContexts.CSS_LBRACE) {
            modified = insertBraceOpen(region);
        } else if (type == CSSRegionContexts.CSS_RBRACE) {
            modified = insertBraceClose(region);
        } else if (type == CSSRegionContexts.CSS_MEDIA || type == CSSRegionContexts.CSS_PAGE || type == CSSRegionContexts.CSS_FONT_FACE || CSSUtil.isSelectorText(region)) {
            checkNextNode(region, CSSRegionContexts.CSS_LBRACE);
        } else if (type == CSSRegionContexts.CSS_IMPORT || type == CSSRegionContexts.CSS_CHARSET) {
            checkNextNode(region, CSSRegionContexts.CSS_DELIMITER);
        }
    } else if ((target instanceof CSSRuleDeclContainer || target instanceof CSSStyleDeclaration) && type == CSSRegionContexts.CSS_DECLARATION_PROPERTY) {
        modified = insertStyleDeclarationItem(region);
    } else if (target instanceof ICSSStyleDeclItem && type == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
        modified = insertSemiColonForStyleDeclarationItem(region);
    } else if (type == CSSRegionContexts.CSS_RBRACE) {
        modified = insertBraceClose(region);
    }
    // post process
    if (modified != null) {
        if (modified instanceof CSSStructuredDocumentRegionContainer) {
            ((CSSStructuredDocumentRegionContainer) modified).propagateRangeStructuredDocumentRegion();
        }
    }
    return modified;
}
Also used : ICSSRuleContainer(org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer) BasicStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocumentRegion) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration)

Aggregations

CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)24 CSSRule (org.w3c.dom.css.CSSRule)17 CSSRuleList (org.w3c.dom.css.CSSRuleList)17 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)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 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)4 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)4 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)3 CSSStyleRuleImpl (com.steadystate.css.dom.CSSStyleRuleImpl)2 CSSStyleSheetImpl (com.steadystate.css.dom.CSSStyleSheetImpl)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2 InputSource (org.w3c.css.sac.InputSource)2 CSSStylableElement (io.sf.carte.doc.dom4j.CSSStylableElement)1 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1