public StyleSheet(XmlProcessingInstruction pi) : this(String.Empty) { Regex re = new Regex(@"(?<name>[a-z]+)=[""'](?<value>[^""']*)[""']"); Match match = re.Match(pi.Data); while(match.Success) { string name = match.Groups["name"].Value; string val = match.Groups["value"].Value; switch(name) { case "href": _Href = val; break; case "type": _Type = val; break; case "title": _Title = val; break; case "media": _Media = new MediaList(val); break; } match = match.NextMatch(); } ownerNode = pi; }
public void TestMatchesAll() { MediaList ssList = new MediaList("all"); MediaList rendList = new MediaList("screen"); Assert.IsTrue(ssList.Matches(rendList)); }
public void TestMatchesMultiple1() { MediaList ssList = new MediaList("foo, screen"); MediaList rendList = new MediaList("screen"); Assert.IsTrue(ssList.Matches(rendList)); }
/// <summary> /// The constructor for CssImportRule /// </summary> /// <param name="match">The Regex match that found the charset rule</param> /// <param name="parent">The parent rule or parent stylesheet</param> /// <param name="readOnly">True if this instance is readonly</param> /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param> /// <param name="origin">The type of CssStyleSheet</param> internal CssImportRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin) { media = new MediaList(match.Groups["importmedia"].Value); href = DeReplaceStrings(match.Groups["importhref"].Value); styleSheet = new CssStyleSheet(ResolveOwnerNode(), Href, null, match.Groups["importmedia"].Value, this, Origin); }
public void TestMatchesEmpty() { MediaList ssList = new MediaList(String.Empty); MediaList rendList = new MediaList("screen"); Assert.IsTrue(ssList.Matches(rendList)); }
public void TestDeleteMedium() { MediaList list = new MediaList("screen, all"); list.DeleteMedium("screen"); Assert.AreEqual(1, list.Length); Assert.AreEqual("all", list.MediaText); Assert.AreEqual("all", list[0]); }
internal StyleSheet(XmlElement styleElement) { if(styleElement.HasAttribute("href")) _Href = styleElement.Attributes["href"].Value; if(styleElement.HasAttribute("type")) _Type = styleElement.Attributes["type"].Value; if(styleElement.HasAttribute("title")) _Title = styleElement.Attributes["title"].Value; if(styleElement.HasAttribute("media")) _Media = new MediaList(styleElement.Attributes["media"].Value); ownerNode = (XmlNode)styleElement; }
public StyleSheet(XmlElement styleElement) : this(String.Empty) { if (styleElement.HasAttribute("href")) _Href = styleElement.Attributes["href"].Value; if (styleElement.HasAttribute("type")) _Type = styleElement.Attributes["type"].Value; if (styleElement.HasAttribute("title")) _Title = styleElement.Attributes["title"].Value; if (styleElement.HasAttribute("media")) _Media = new MediaList(styleElement.Attributes["media"].Value); ownerNode = styleElement; }
public void TestAppendMedium() { MediaList list = new MediaList(); list.AppendMedium("screen"); Assert.AreEqual(1, list.Length); Assert.AreEqual("screen", list.MediaText); Assert.AreEqual("screen", list[0]); list.AppendMedium("all"); Assert.AreEqual(2, list.Length); Assert.AreEqual("screen,all", list.MediaText); Assert.AreEqual("screen", list[0]); Assert.AreEqual("all", list[1]); list.AppendMedium("screen"); Assert.AreEqual(2, list.Length); Assert.AreEqual("all,screen", list.MediaText); Assert.AreEqual("all", list[0]); Assert.AreEqual("screen", list[1]); }
public CssMediaRule(string cssText, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin) { media = new MediaList(cssText); }
public void TestMatchesNoMatch() { MediaList ssList = new MediaList("dummy"); MediaList rendList = new MediaList("screen"); Assert.IsTrue(!ssList.Matches(rendList)); }
/// <summary> /// Used to find matching style rules in the cascading order /// </summary> /// <param name="elt">The element to find styles for</param> /// <param name="pseudoElt">The pseudo-element to find styles for</param> /// <param name="ml">The medialist that the document is using</param> /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param> protected internal virtual void GetStylesForElement(XmlElement elt, string pseudoElt, MediaList ml, CssCollectedStyleDeclaration csd) { }
public void TestToBigIndex() { MediaList list = new MediaList("all, screen"); Assert.IsNull(list[2]); }
public void TestStringConstructor() { MediaList list = new MediaList("all, screen"); Assert.AreEqual(2, list.Length); Assert.AreEqual("all,screen", list.MediaText); Assert.AreEqual("all", list[0]); Assert.AreEqual("screen", list[1]); }
/// <summary> /// Used to find matching style rules in the cascading order /// </summary> /// <param name="elt">The element to find styles for</param> /// <param name="pseudoElt">The pseudo-element to find styles for</param> /// <param name="ml">The medialist that the document is using</param> /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param> internal void GetStylesForElement(XmlElement elt, string pseudoElt, MediaList ml, CssCollectedStyleDeclaration csd) { ulong len = Length; for(ulong i = 0; i<len; i++) { CssRule csr = (CssRule)this[i]; csr.GetStylesForElement(elt, pseudoElt, ml, csd); } }
/// <summary> /// Used to find matching style rules in the cascading order /// </summary> /// <param name="elt">The element to find styles for</param> /// <param name="pseudoElt">The pseudo-element to find styles for</param> /// <param name="ml">The medialist that the document is using</param> /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param> protected internal override void GetStylesForElement(XmlElement elt, string pseudoElt, MediaList ml, CssCollectedStyleDeclaration csd) { if(media.Matches(ml)) { ((CssStyleSheet)StyleSheet).GetStylesForElement(elt, pseudoElt, ml, csd); } }
/// <summary> /// Used to find matching style rules in the cascading order /// </summary> /// <param name="elt">The element to find styles for</param> /// <param name="pseudoElt">The pseudo-element to find styles for</param> /// <param name="ml">The medialist that the document is using</param> /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param> internal void GetStylesForElement(XmlElement elt, string pseudoElt, CssCollectedStyleDeclaration csd, MediaList ml) { foreach (StyleSheet ss in styleSheets) { ss.GetStylesForElement(elt, pseudoElt, ml, csd); } }
/// <summary> /// Compares this MediaList with another and see if the second fits this /// </summary> /// <param name="inMedia">The MediaList to compare</param> /// <returns>True if this list fits the specified</returns> public bool Matches(MediaList inMedia) { if(inMedia.Length == 0) return false; else if(Length == 0 || containsAll) { // is empty or this list contains "all" return true; } else { for(ulong i = 0; i<inMedia.Length; i++) { if (medias.Contains(inMedia[i])) return true; } } return false; }
/// <summary> /// Used to find matching style rules in the cascading order /// </summary> /// <param name="elt">The element to find styles for</param> /// <param name="pseudoElt">The pseudo-element to find styles for</param> /// <param name="ml">The medialist that the document is using</param> /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param> protected internal override void GetStylesForElement(XmlElement elt, string pseudoElt, MediaList ml, CssCollectedStyleDeclaration csd) { if(((MediaList)Media).Matches(ml)) { ((CssRuleList)CssRules).GetStylesForElement(elt, pseudoElt, ml, csd); } }
public void TestEmptyConstructor() { MediaList list = new MediaList(); Assert.AreEqual(0, list.Length); Assert.AreEqual("", list.MediaText); }
internal StyleSheet(XmlNode ownerNode, string href, string type, string title, string media) { this.ownerNode = ownerNode; _Href = href; _Type = type; _Title = title; _Media = new MediaList(media); }
/// <summary> /// Used to find matching style rules in the cascading order /// </summary> /// <param name="elt">The element to find styles for</param> /// <param name="pseudoElt">The pseudo-element to find styles for</param> /// <param name="ml">The medialist that the document is using</param> /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param> protected internal virtual void GetStylesForElement(XmlElement elt, string pseudoElt, MediaList ml, CssCollectedStyleDeclaration csd) { }
public void TestIncorrectButParsable1() { MediaList list = new MediaList("screen,,all"); Assert.AreEqual(2, list.Length); Assert.AreEqual("screen,all", list.MediaText); }
/// <summary> /// Used to find matching style rules in the cascading order /// </summary> /// <param name="elt">The element to find styles for</param> /// <param name="pseudoElt">The pseudo-element to find styles for</param> /// <param name="ml">The medialist that the document is using</param> /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param> internal void GetStylesForElement(XmlElement elt, string pseudoElt, CssCollectedStyleDeclaration csd, MediaList ml) { foreach (StyleSheet ss in styleSheets) { ss.GetStylesForElement(elt, pseudoElt, ml, csd); } }
protected StyleSheet(string media) { _Title = String.Empty; _Href = String.Empty; _Type = String.Empty; if (String.IsNullOrEmpty(media)) { _Media = new MediaList(); } else { _Media = new MediaList(media); } }
/// <summary> /// Used to find matching style rules in the cascading order /// </summary> /// <param name="elt">The element to find styles for</param> /// <param name="pseudoElt">The pseudo-element to find styles for</param> /// <param name="ml">The medialist that the document is using</param> /// <param name="csd">A CssStyleDeclaration that holds the collected styles</param> protected internal override void GetStylesForElement(XmlElement elt, string pseudoElt, MediaList ml, CssCollectedStyleDeclaration csd) { XPathNavigator nav = elt.CreateNavigator(); foreach(CssXPathSelector sel in XPathSelectors) { // TODO: deal with pseudoElt if(sel != null && sel.Matches(nav)) { ((CssStyleDeclaration)Style).GetStylesForElement(csd, sel.Specificity); break; } } }