Search in sources :

Example 16 with CSSStyleDeclaration

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

the class CSSPageRuleTest 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", "CSSPageRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(6, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    CSSValueList valueList;
    // rule 1
    rule = ruleList.item(0);
    assertEquals(CSSRule.PAGE_RULE, rule.getType());
    assertTrue(rule instanceof CSSPageRule);
    declaration = ((CSSPageRule) rule).getStyle();
    assertEquals(2, 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_IN, (float) 8.5));
    checkPrimitiveNumber(valueList.item(1), new PrimitiveNumber(CSSPrimitiveValue.CSS_IN, 11));
    value = declaration.getPropertyCSSValue("margin");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 2));
}
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)

Example 17 with CSSStyleDeclaration

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

the class CSSPageRuleTest method testInsertText6.

public void testInsertText6() 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 6
    rule = ruleList.item(5);
    assertEquals(CSSRule.PAGE_RULE, rule.getType());
    assertTrue(rule instanceof CSSPageRule);
    assertEquals("rotated", ((CSSPageRule) rule).getSelectorText());
    declaration = ((CSSPageRule) rule).getStyle();
    assertEquals(1, declaration.getLength());
    value = declaration.getPropertyCSSValue("size");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "landscape"));
}
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 18 with CSSStyleDeclaration

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

the class CSSPageRuleTest 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", "CSSPageRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(6, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    // rule 2
    rule = ruleList.item(1);
    assertEquals(CSSRule.PAGE_RULE, rule.getType());
    assertTrue(rule instanceof CSSPageRule);
    declaration = ((CSSPageRule) rule).getStyle();
    assertEquals(2, declaration.getLength());
    value = declaration.getPropertyCSSValue("size");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "auto"));
    value = declaration.getPropertyCSSValue("margin");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_PERCENTAGE, 10));
}
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 19 with CSSStyleDeclaration

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

the class CSSPageRuleTest 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", "CSSPageRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(6, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    // rule 3
    rule = ruleList.item(2);
    assertEquals(CSSRule.PAGE_RULE, rule.getType());
    assertTrue(rule instanceof CSSPageRule);
    assertEquals(":left", ((CSSPageRule) rule).getSelectorText());
    declaration = ((CSSPageRule) rule).getStyle();
    assertEquals(2, declaration.getLength());
    value = declaration.getPropertyCSSValue("margin-left");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 4));
    value = declaration.getPropertyCSSValue("margin-right");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 3));
}
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 20 with CSSStyleDeclaration

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

the class StructuredSelectEnclosingHandler method getNewSelectionRegion.

protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
    Region newRegion = null;
    if (indexedRegion instanceof ICSSNode) {
        ICSSNode cursorNode = (ICSSNode) indexedRegion;
        Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
        int currentOffset = textSelection.getOffset();
        int currentEndOffset = currentOffset + textSelection.getLength();
        if (cursorNodeRegion.getOffset() >= currentOffset && cursorNodeRegion.getOffset() <= currentEndOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset) {
            ICSSNode newNode = cursorNode.getParentNode();
            if (newNode instanceof CSSStyleDeclaration) {
                newNode = newNode.getParentNode();
            }
            if (newNode instanceof IndexedRegion) {
                IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
            }
        } else
            newRegion = cursorNodeRegion;
    }
    return newRegion;
}
Also used : Region(org.eclipse.jface.text.Region) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

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