Search in sources :

Example 1 with CSSImportRule

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

the class CSSImportRuleTest method checkInsert.

private void checkInsert(String ruleString, String href, String[] media) {
    CSSStyleSheet sheet = getStyleSheet();
    assertEquals(0, sheet.insertRule(ruleString, 0));
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSImportRule);
    CSSImportRule importRule = (CSSImportRule) rule;
    assertEquals(href, importRule.getHref());
    if (media != null) {
        assertEquals(media.length, importRule.getMedia().getLength());
        for (int i = 0; i < media.length; i++) {
            assertEquals(media[i], importRule.getMedia().item(i));
        }
    }
    assertEquals(ruleString, importRule.getCssText());
}
Also used : CSSRule(org.w3c.dom.css.CSSRule) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule) CSSImportRule(org.w3c.dom.css.CSSImportRule) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 2 with CSSImportRule

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

the class CSSImportRuleTest method testCreateRule.

public void testCreateRule() {
    ICSSStyleSheet sheet = getStyleSheet();
    ICSSDocument doc = sheet;
    ICSSImportRule newRule = doc.createCSSImportRule();
    newRule.setHref("dummy.css");
    MediaList newList = newRule.getMedia();
    newList.appendMedium("media1");
    newList.appendMedium("media2");
    sheet.insertRuleBefore(newRule, null);
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSImportRule);
    CSSImportRule importRule = (CSSImportRule) rule;
    assertEquals("dummy.css", importRule.getHref());
    MediaList mediaList = importRule.getMedia();
    assertEquals(2, mediaList.getLength());
    assertEquals("media1", mediaList.item(0));
    assertEquals("media2", mediaList.item(1));
    assertEquals("@import url(\"dummy.css\") media1, media2;", importRule.getCssText());
}
Also used : MediaList(org.w3c.dom.stylesheets.MediaList) CSSRule(org.w3c.dom.css.CSSRule) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule) CSSImportRule(org.w3c.dom.css.CSSImportRule) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Aggregations

ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 CSSImportRule (org.w3c.dom.css.CSSImportRule)2 CSSRule (org.w3c.dom.css.CSSRule)2 CSSRuleList (org.w3c.dom.css.CSSRuleList)2 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)1 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)1 MediaList (org.w3c.dom.stylesheets.MediaList)1