Search in sources :

Example 1 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSModelParser method getStructuredDocumentRegionList.

/**
 */
private IStructuredDocumentRegionList getStructuredDocumentRegionList(int start, int end) {
    IStructuredDocumentRegionList nodeList = null;
    if (0 <= start && start <= end) {
        ICSSModel model = fDocument.getModel();
        if (model instanceof CSSModelImpl) {
            IStructuredDocument structuredDocument = ((CSSModelImpl) model).getStructuredDocument();
            if (structuredDocument != null) {
                IStructuredDocumentRegion startNode = structuredDocument.getRegionAtCharacterOffset(start);
                IStructuredDocumentRegion endNode = structuredDocument.getRegionAtCharacterOffset(end - 1);
                if (startNode != null && endNode != null) {
                    nodeList = new CoreNodeList(startNode, endNode);
                }
            }
        }
    }
    return nodeList;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CoreNodeList(org.eclipse.wst.sse.core.internal.text.CoreNodeList)

Example 2 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSFormatUtil method collectCSSNodes.

public List collectCSSNodes(IStructuredModel model, int start, int length) {
    List nodes = new ArrayList();
    IndexedRegion startNode = model.getIndexedRegion(start);
    IndexedRegion endNode = model.getIndexedRegion(start + length - 1);
    if (startNode == null || endNode == null) {
        return nodes;
    }
    if (model instanceof ICSSModel && startNode instanceof ICSSNode && endNode instanceof ICSSNode) {
        // CSS model
        ICSSNode ca = getCommonAncestor((ICSSNode) startNode, (ICSSNode) endNode);
        if (ca != null) {
            for (ICSSNode node = ca.getFirstChild(); node != null && start + length < ((IndexedRegion) node).getStartOffset(); node = node.getNextSibling()) {
                if (start < ((IndexedRegion) node).getEndOffset()) {
                    nodes.add(node);
                }
            }
        }
    } else if (model instanceof IDOMModel && startNode instanceof IDOMNode && endNode instanceof IDOMNode) {
        if (startNode instanceof Text) {
            startNode = (IndexedRegion) ((Text) startNode).getParentNode();
        }
        if (endNode instanceof Text) {
            endNode = (IndexedRegion) ((Text) endNode).getParentNode();
        }
        // HTML model, maybe
        IDOMNode ca = (IDOMNode) getCommonAncestor((Node) startNode, (Node) endNode);
        findCSS(nodes, ca);
    }
    return nodes;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Text(org.w3c.dom.Text) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 3 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSFormatUtil method findCSS.

private void findCSS(List cssNodes, IDOMNode node) {
    ICSSModelAdapter adapter;
    adapter = (ICSSModelAdapter) node.getAdapterFor(IStyleSheetAdapter.class);
    if (adapter != null) {
        ICSSModel model = adapter.getModel();
        if (model != null && model.getStyleSheetType() == ICSSModel.EMBEDDED) {
            cssNodes.add(model.getDocument());
        }
    } else {
        adapter = (ICSSModelAdapter) node.getAdapterFor(IStyleDeclarationAdapter.class);
        if (adapter != null) {
            ICSSModel model = adapter.getModel();
            if (model != null && model.getStyleSheetType() == ICSSModel.INLINE) {
                cssNodes.add(model.getDocument());
            }
        }
    }
    for (IDOMNode child = (IDOMNode) node.getFirstChild(); child != null; child = (IDOMNode) child.getNextSibling()) {
        findCSS(cssNodes, child);
    }
}
Also used : ICSSModelAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 4 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSStyleSheetImpl method getParentStyleSheets.

/**
 * @return org.w3c.dom.stylesheets.StyleSheetList
 */
public org.w3c.dom.stylesheets.StyleSheetList getParentStyleSheets() {
    List list = (getModel().getStyleListeners() != null) ? new Vector(getModel().getStyleListeners()) : null;
    if (list == null)
        return null;
    InternalStyleSheetList sheets = new InternalStyleSheetList();
    Iterator it = list.iterator();
    while (it.hasNext()) {
        Object obj = it.next();
        if (obj instanceof ICSSModel) {
            sheets.appendNode(((ICSSModel) obj).getDocument());
        }
    }
    if (sheets.getLength() > 0)
        return sheets;
    else
        return null;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) Iterator(java.util.Iterator) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList) CSSRuleList(org.w3c.dom.css.CSSRuleList) MediaList(org.w3c.dom.stylesheets.MediaList) NodeList(org.w3c.dom.NodeList) List(java.util.List) Vector(java.util.Vector)

Example 5 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class StyleDeclarationFormatter method formatBefore.

/**
 */
protected void formatBefore(ICSSNode node, ICSSNode child, IRegion region, String toAppend, StringBuffer source) {
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    ICSSModel cssModel = node.getOwnerDocument().getModel();
    // with no model associated with it
    if (cssModel != null) {
        IStructuredDocument structuredDocument = cssModel.getStructuredDocument();
        if (structuredDocument != null) {
            CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, region, stgy);
            CompoundRegion[] outside = getOutsideRegions(structuredDocument, region);
            for (int i = 0; i < regions.length; i++) {
                if (i != 0 || needS(outside[0]))
                    appendSpaceBefore(node, regions[i], source);
                // must
                source.append(decoratedRegion(regions[i], 0, stgy));
            // be
            // comments
            }
            Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
            if (needS(outside[1])) {
                if (((IndexedRegion) child).getStartOffset() == region.getOffset() + region.getLength() && preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_ONE_PER_LINE) && (node.getOwnerDocument() != node || !preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR))) {
                    appendDelimBefore(node, null, source);
                } else
                    appendSpaceBefore(node, toAppend, source);
            }
        }
    }
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Preferences(org.eclipse.core.runtime.Preferences) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Aggregations

ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)82 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)41 CSSRule (org.w3c.dom.css.CSSRule)21 CSSRuleList (org.w3c.dom.css.CSSRuleList)20 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)14 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)14 CSSValue (org.w3c.dom.css.CSSValue)14 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)11 IModelProvideAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter)8 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)7 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)7 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)7 IFile (org.eclipse.core.resources.IFile)6 Path (org.eclipse.core.runtime.Path)6 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)6 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)6 Element (org.w3c.dom.Element)6