Search in sources :

Example 6 with CSSFontFaceRule

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

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

the class CSSModelParser method insertBraceClose.

/**
 */
private CSSNodeImpl insertBraceClose(IStructuredDocumentRegion region) {
    ICSSNode target = CSSModelUtil.findBraceContainer(fCreationContext.getTargetNode());
    if (!(target instanceof CSSStructuredDocumentRegionContainer)) {
        return null;
    }
    CSSStructuredDocumentRegionContainer parent = (CSSStructuredDocumentRegionContainer) target;
    if (CSSModelUtil.isInterruption(parent, region)) {
        ICSSNode node = parent.getParentNode();
        if (node instanceof CSSNodeImpl) {
            fCreationContext.setReparseStart(parent.getStartOffset());
            fCreationContext.setReparseEnd(parent.getEndOffset());
            ((CSSNodeImpl) node).removeChild(parent);
        }
        return null;
    }
    if (parent instanceof ICSSPageRule || parent instanceof ICSSMediaRule || parent instanceof CSSFontFaceRule || parent instanceof ICSSStyleRule) {
        CSSModelUtil.expandStructuredDocumentRegionContainer(parent, region);
        if (!CSSModelUtil.isBraceClosed(target)) {
            fCreationContext.setTargetNode(parent.getParentNode());
            fCreationContext.setNextNode(parent.getNextSibling());
            return parent;
        }
    }
    return null;
}
Also used : ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) ICSSPageRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Aggregations

CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)7 CSSRule (org.w3c.dom.css.CSSRule)4 CSSRuleList (org.w3c.dom.css.CSSRuleList)4 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)4 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)4 CSSValue (org.w3c.dom.css.CSSValue)4 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)3 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)3 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)3 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 CSSValueList (org.w3c.dom.css.CSSValueList)3 ICSSMediaRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule)2 ICSSPageRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule)2 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)2 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)2 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 CSSMMNode (org.eclipse.wst.css.core.internal.metamodel.CSSMMNode)1 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)1