Search in sources :

Example 1 with CSSFontFaceRule

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

the class CSSMetaModelUtil method getMetaModelNodeFor.

public CSSMMNode getMetaModelNodeFor(ICSSNode node) {
    if (node instanceof ICSSStyleDeclaration) {
        node = node.getParentNode();
    }
    if (node instanceof ICSSStyleDeclItem) {
        ICSSNode parent = node.getParentNode();
        if (parent != null) {
            parent = parent.getParentNode();
        }
        if (parent instanceof ICSSStyleRule) {
            return getProperty(((ICSSStyleDeclItem) node).getPropertyName());
        } else if (parent instanceof CSSFontFaceRule) {
            return getDescriptor(((ICSSStyleDeclItem) node).getPropertyName());
        }
    }
    if (node == null) {
        return null;
    }
    if (fTypeMap == null) {
        fTypeMap = new HashMap();
        fTypeMap.put(new Short(ICSSNode.STYLERULE_NODE), CSSMMNode.TYPE_STYLE_RULE);
        fTypeMap.put(new Short(ICSSNode.FONTFACERULE_NODE), CSSMMNode.TYPE_FONT_FACE_RULE);
        fTypeMap.put(new Short(ICSSNode.PAGERULE_NODE), CSSMMNode.TYPE_PAGE_RULE);
    }
    String nodeType = (String) fTypeMap.get(new Short(node.getNodeType()));
    if (nodeType == null) {
        return null;
    }
    Iterator iNodes = collectNodesByType(nodeType);
    if (iNodes.hasNext()) {
        CSSMMNode targetNode = (CSSMMNode) iNodes.next();
        if (!iNodes.hasNext()) {
            // it's only one
            return targetNode;
        }
    }
    return null;
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) HashMap(java.util.HashMap) Iterator(java.util.Iterator) 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)

Example 2 with CSSFontFaceRule

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

the class CSSFontFaceRuleTest method _testInsertText1.

public void _testInsertText1() 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 1
    rule = ruleList.item(0);
    assertEquals(CSSRule.FONT_FACE_RULE, rule.getType());
    assertTrue(rule instanceof CSSFontFaceRule);
    declaration = ((CSSFontFaceRule) rule).getStyle();
    assertEquals(4, declaration.getLength());
    value = declaration.getPropertyCSSValue("font-family");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "Swiss 721"));
    value = declaration.getPropertyCSSValue("src");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_URI, "swiss721blk.pfr"));
    value = declaration.getPropertyCSSValue("font-style");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "normal"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "italic"));
    value = declaration.getPropertyCSSValue("font-weight");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 800));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 900));
}
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 3 with CSSFontFaceRule

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

the class CSSFontFaceRuleTest method _testInsertText3.

public void _testInsertText3() 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 3
    rule = ruleList.item(2);
    assertEquals(CSSRule.FONT_FACE_RULE, rule.getType());
    assertTrue(rule instanceof CSSFontFaceRule);
    declaration = ((CSSFontFaceRule) rule).getStyle();
    assertEquals(5, declaration.getLength());
    value = declaration.getPropertyCSSValue("src");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(4, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(ICSSPrimitiveValue.CSS_LOCAL, "Alabama Italic"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_URI, "http://www.fonts.org/A/alabama-italic"));
    checkPrimitiveString(valueList.item(3), new PrimitiveString(ICSSPrimitiveValue.CSS_FORMAT, "truetype"));
    value = declaration.getPropertyCSSValue("panose-1");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(10, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 2));
    checkPrimitiveNumber(valueList.item(1), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 4));
    checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 5));
    checkPrimitiveNumber(valueList.item(3), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 2));
    checkPrimitiveNumber(valueList.item(4), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 5));
    checkPrimitiveNumber(valueList.item(5), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 4));
    checkPrimitiveNumber(valueList.item(6), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 5));
    checkPrimitiveNumber(valueList.item(7), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 9));
    checkPrimitiveNumber(valueList.item(8), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 3));
    checkPrimitiveNumber(valueList.item(9), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 3));
    value = declaration.getPropertyCSSValue("font-family");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Alabama"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "serif"));
    value = declaration.getPropertyCSSValue("font-weight");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(5, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 300));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 400));
    checkPrimitiveString(valueList.item(3), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(4), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 500));
    value = declaration.getPropertyCSSValue("font-style");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "italic"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "oblique"));
}
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 4 with CSSFontFaceRule

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

the class CSSFontFaceRuleTest method testInsertRule.

public void testInsertRule() {
    final String RULE = "@font-face { font-family: \"Swiss 721\"; src: url(swiss721.pfr); /* The expanded Swiss 721 */ font-stretch: expanded; }";
    CSSStyleSheet sheet = getStyleSheet();
    assertEquals(0, sheet.insertRule(RULE, 0));
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSFontFaceRule);
    CSSStyleDeclaration declaration = ((CSSFontFaceRule) rule).getStyle();
    assertEquals(3, declaration.getLength());
    CSSValue value;
    CSSPrimitiveValue primitiveValue;
    value = declaration.getPropertyCSSValue("font-family");
    assertTrue(value instanceof CSSPrimitiveValue);
    primitiveValue = (CSSPrimitiveValue) value;
    assertEquals(CSSPrimitiveValue.CSS_STRING, primitiveValue.getPrimitiveType());
    assertEquals("Swiss 721", primitiveValue.getStringValue());
    value = declaration.getPropertyCSSValue("src");
    assertTrue(value instanceof CSSPrimitiveValue);
    primitiveValue = (CSSPrimitiveValue) value;
    assertEquals(CSSPrimitiveValue.CSS_URI, primitiveValue.getPrimitiveType());
    assertEquals("swiss721.pfr", primitiveValue.getStringValue());
    value = declaration.getPropertyCSSValue("font-stretch");
    assertTrue(value instanceof CSSPrimitiveValue);
    primitiveValue = (CSSPrimitiveValue) value;
    assertEquals(CSSPrimitiveValue.CSS_IDENT, primitiveValue.getPrimitiveType());
    assertEquals("expanded", primitiveValue.getStringValue());
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) CSSPrimitiveValue(org.w3c.dom.css.CSSPrimitiveValue) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 5 with CSSFontFaceRule

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

the class CSSProposalArranger method buildProposals.

/**
 */
void buildProposals() {
    fProposals.clear();
    /*
		 * String text; ICompletionProposal item; text = "---- Test
		 * Information ----"; item = new CompletionProposal("",
		 * fContext.getReplaceBegin(), 0, 0, null, text, null, null);
		 * fProposals.add(item);
		 * 
		 * text = "Target: \"" + fContext.getRegionText() + "\"";
		 * 
		 * item = new CompletionProposal("", fContext.getReplaceBegin(), 0, 0,
		 * null, text, null, null); fProposals.add(item);
		 * 
		 * text = fContext.getTargetNode().getClass().toString(); int
		 * lastPeriodPos = text.lastIndexOf('.'); text = "Node: " +
		 * text.substring(lastPeriodPos + 1); item = new
		 * CompletionProposal("", fContext.getReplaceBegin(), 0, 0, null,
		 * text, null, null); fProposals.add(item);
		 */
    ICSSNode targetNode = fContext.getTargetNode();
    // int targetPos = fContext.getTargetPos();
    if (targetNode instanceof ICSSStyleSheet) {
        buildProposalsForAnyRule();
    } else if ((targetNode instanceof ICSSMediaRule && fContext.isTargetPosAfterOf(CSSRegionContexts.CSS_LBRACE)) || (targetNode instanceof ICSSStyleRule && fContext.isTargetPosBeforeOf(CSSRegionContexts.CSS_LBRACE))) {
        buildProposalsForAnyRule();
    // buildProposalsForStyleRule();
    } else if ((targetNode instanceof ICSSPageRule && fContext.isTargetPosBeforeOf(CSSRegionContexts.CSS_LBRACE))) {
        buildProposalsForPageRulePseudoClass();
    } else if ((targetNode instanceof ICSSStyleRule || targetNode instanceof CSSFontFaceRule || targetNode instanceof ICSSPageRule || targetNode instanceof ICSSStyleDeclaration) && (targetNode.getOwnerDocument() instanceof ICSSStyleDeclaration || fContext.targetFollows(CSSRegionContexts.CSS_DECLARATION_DELIMITER) || fContext.targetFollows(CSSRegionContexts.CSS_LBRACE))) {
        buildProposalsForDeclarationName();
    } else if (targetNode instanceof ICSSStyleDeclItem) {
        if (fContext.isTargetPosAfterOf(CSSRegionContexts.CSS_DECLARATION_SEPARATOR)) {
            buildProposalsForDeclarationValue();
        } else {
            buildProposalsForDeclarationName();
        }
    } else if (targetNode instanceof ICSSPrimitiveValue) {
        buildProposalsForDeclarationValue();
    }
/*
		 * else if (targetNode instanceof ICSSPrimitiveValue || ((targetNode
		 * instanceof ICSSStyleRule || targetNode instanceof CSSFontFaceRule ||
		 * targetNode instanceof ICSSStyleDeclaration || targetNode instanceof
		 * ICSSStyleDeclItem) &&
		 * fContext.isTargetPosAfterOf(CSSRegionContexts.COLON))) {
		 * buildProposalsForDeclarationValue(); }
		 */
// for Test
}
Also used : ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) ICSSPageRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) 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