A XmlDocument with CSS support
Inheritance: Document, IDocumentCss, ICssView
Exemplo n.º 1
0
        internal StyleSheetList(CssXmlDocument document)
        {
            doc = document;
            XmlNodeList pis = document.SelectNodes("/processing-instruction()");
            styleSheets = new List<StyleSheet>();

            foreach (XmlProcessingInstruction pi in pis)
            {
                if (Regex.IsMatch(pi.Data, "type=[\"']text\\/css[\"']"))
                {
                    styleSheets.Add(new CssStyleSheet(pi, CssStyleSheetType.Author));
                }
                else
                {
                    styleSheets.Add(new StyleSheet(pi));
                }

            }

            XmlNodeList styleNodes;
            foreach(string[] name in document.styleElements)
            {
                styleNodes = document.SelectNodes(
                    "//*[local-name()='" + name[1] + "' and namespace-uri()='" + name[0] + "'][@type='text/css']");

                foreach(XmlElement elm in styleNodes)
                {
                    styleSheets.Add(new CssStyleSheet(elm, CssStyleSheetType.Author));
                }
            }
        }
Exemplo n.º 2
0
        private CssStyleDeclaration getStyles(string xmlContent, string style, string localName)
        {
            CssXmlDocument doc = loadXml(xmlContent, style);
            XmlElement     elm = getElm(doc, localName);

            return((CssStyleDeclaration)doc.GetComputedStyle(elm, ""));
        }
Exemplo n.º 3
0
        public virtual ICssStyleDeclaration GetComputedStyle(string pseudoElt)
        {
            CssXmlDocument ownerDoc = this.OwnerDocument;

            if (_isImported && _importDocument != null && _importNode != null)
            {
                ownerDoc = _importDocument;
            }

            if (_cachedCSD == null)
            {
                CssCollectedStyleDeclaration csd = new CssCollectedStyleDeclaration(this);
                MediaList currentMedia           = ownerDoc.Media;

                if (ownerDoc.UserAgentStyleSheet != null)
                {
                    ownerDoc.UserAgentStyleSheet.GetStylesForElement(this, pseudoElt, currentMedia, csd);
                }
                ((StyleSheetList)ownerDoc.StyleSheets).GetStylesForElement(this, pseudoElt, csd);

                ((CssStyleDeclaration)Style).GetStylesForElement(csd, 0);

                if (ownerDoc.UserStyleSheet != null)
                {
                    ownerDoc.UserStyleSheet.GetStylesForElement(this, pseudoElt, currentMedia, csd);
                }

                _cachedCSD = csd;
            }
            return(_cachedCSD);
        }
        public override ICssValue GetPropertyCssValue(string propertyName)
        {
            if (_collectedStyles.ContainsKey(propertyName))
            {
                CssCollectedProperty scp = _collectedStyles[propertyName];
                if (scp.CssValue.CssValueType == CssValueType.Inherit)
                {
                    // get style from parent chain
                    return(getParentStyle(propertyName));
                }
                return(scp.CssValue.GetAbsoluteValue(propertyName, _element));
            }

            // should this property inherit?
            CssXmlDocument doc = (CssXmlDocument)_element.OwnerDocument;

            if (doc.CssPropertyProfile.IsInheritable(propertyName))
            {
                ICssValue parValue = getParentStyle(propertyName);
                if (parValue != null)
                {
                    return(parValue);
                }
            }

            string initValue = doc.CssPropertyProfile.GetInitialValue(propertyName);

            if (initValue == null)
            {
                return(null);
            }
            return(CssValue.GetCssValue(initValue, false).GetAbsoluteValue(propertyName, _element));
        }
Exemplo n.º 5
0
        private CssXmlDocument loadXml(string content, string style)
        {
            CssXmlDocument doc = TestUtil.GetXmlDoc(content, style);

            doc.CssPropertyProfile.Add("inher", true, "init");
            doc.CssPropertyProfile.Add("not", false, "init");
            doc.CssPropertyProfile.Add("font-size", true, "12px");

            return(doc);
        }
Exemplo n.º 6
0
        public void Init()
        {
            if(!initDone)
            {
                doc = new CssXmlDocument();
                doc.AddStyleElement("http://www.w3.org/2000/svg", "style");
                doc.Load("http://www.sharpvectors.org/tests/css_unittest_01.svg");
                cssStyleSheet = (CssStyleSheet)doc.StyleSheets[0];
                colorRules = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[4]).Style;

                initDone = true;
            }
        }
Exemplo n.º 7
0
        public static CssXmlDocument GetXmlDoc(string content, string style)
        {
            CssXmlDocument doc = new CssXmlDocument();
            doc.AddStyleElement("", "style");

            string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<root>";
            xml += "<style type='text/css'>" + style + "</style>";
            xml += content;
            xml += "</root>";

            doc.LoadXml(xml);
            return doc;
        }
Exemplo n.º 8
0
        public void Init()
        {
            if (!initDone)
            {
                doc = new CssXmlDocument();
                doc.AddStyleElement("http://www.w3.org/2000/svg", "style");
                doc.Load("http://www.sharpvectors.org/tests/css_unittest_01.svg");
                cssStyleSheet = (CssStyleSheet)doc.StyleSheets[0];
                colorRules    = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[4]).Style;

                initDone = true;
            }
        }
Exemplo n.º 9
0
        public static CssXmlDocument GetXmlDoc(string content, string style)
        {
            CssXmlDocument doc = new CssXmlDocument();

            doc.AddStyleElement("", "style");

            string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<root>";

            xml += "<style type='text/css'>" + style + "</style>";
            xml += content;
            xml += "</root>";

            doc.LoadXml(xml);
            return(doc);
        }
        private ICssValue getParentStyle(string propertyName)
        {
            CssXmlDocument doc        = _element.OwnerDocument as CssXmlDocument;
            XmlElement     parentNode = _element.ParentNode as XmlElement;

            if (doc != null && parentNode != null)
            {
                ICssStyleDeclaration parentCsd = doc.GetComputedStyle(parentNode, string.Empty);
                if (parentCsd == null)
                {
                    return(null);
                }
                return(parentCsd.GetPropertyCssValue(propertyName));
            }
            return(null);
        }
Exemplo n.º 11
0
 public CssXmlElement(string prefix, string localname, string ns,
                      CssXmlDocument doc)
     : base(prefix, localname, ns, doc)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Uses the specified CSS XML document with Static state to true.
 /// </summary>
 /// <param name="cssXmlDocument">The CSS XML document.</param>
 public static IDisposable Use(CssXmlDocument cssXmlDocument)
 {
     return new StaticSection(cssXmlDocument);
 }
Exemplo n.º 13
0
 protected internal CssXmlElement(string prefix, string localname, string ns, CssXmlDocument doc) : base(prefix, localname, ns, doc)
 {
 }
Exemplo n.º 14
0
 private XmlElement getElm(CssXmlDocument doc, string localname)
 {
     return((XmlElement)doc.GetElementsByTagName(localname)[0]);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Uses the specified CSS XML document with Static state to true.
 /// </summary>
 /// <param name="cssXmlDocument">The CSS XML document.</param>
 public static IDisposable Use(CssXmlDocument cssXmlDocument)
 {
     return(new StaticSection(cssXmlDocument));
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StaticSection"/> class.
 /// </summary>
 /// <param name="cssXmlDocument">The CSS XML document.</param>
 private StaticSection(CssXmlDocument cssXmlDocument)
 {
     _cssXmlDocument       = cssXmlDocument;
     _previousStatic       = cssXmlDocument.Static;
     cssXmlDocument.Static = true;
 }
Exemplo n.º 17
0
 private XmlElement getElm(CssXmlDocument doc, string localname)
 {
     return (XmlElement)doc.GetElementsByTagName(localname)[0];
 }
Exemplo n.º 18
0
        public static XmlElement GetXmlElement(string content, string style, string localName)
        {
            CssXmlDocument doc = GetXmlDoc(content, style);

            return((XmlElement)doc.SelectSingleNode("//*[local-name()='" + localName + "']"));
        }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StaticSection"/> class.
 /// </summary>
 /// <param name="cssXmlDocument">The CSS XML document.</param>
 private StaticSection(CssXmlDocument cssXmlDocument)
 {
     _cssXmlDocument = cssXmlDocument;
     _previousStatic = cssXmlDocument.Static;
     cssXmlDocument.Static = true;
 }
Exemplo n.º 20
0
 protected internal CssXmlElement(string prefix, string localname, string ns, CssXmlDocument doc)
     : base(prefix, localname, ns, doc)
 {
 }
Exemplo n.º 21
0
 public virtual void TestTypeFromDocument()
 {
     CssXmlDocument doc = new CssXmlDocument();
             doc.LoadXml("<dummy />");
             XmlElement elm = doc.DocumentElement;
             Assert.AreEqual(elmType, elm.GetType());
 }
Exemplo n.º 22
0
    public virtual void TestTypeFromCreateElement()
    {
        CssXmlDocument doc = new CssXmlDocument();
                XmlElement elm = doc.CreateElement("", "dummy", "");

                Assert.AreEqual(elm.GetType(), elmType);
    }