The MediaList interface provides the abstraction of an ordered collection of media, without defining or constraining how this collection is implemented. An empty list is the same as a list that contains the medium "all". The items in the MediaList are accessible via an integral index, starting from 0.
Inheritance: IMediaList
Example #1
0
        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;
        }
Example #2
0
        public void TestMatchesAll()
        {
            MediaList ssList = new MediaList("all");
            MediaList rendList = new MediaList("screen");

            Assert.IsTrue(ssList.Matches(rendList));
        }
Example #3
0
        public void TestMatchesMultiple1()
        {
            MediaList ssList = new MediaList("foo, screen");
            MediaList rendList = new MediaList("screen");

            Assert.IsTrue(ssList.Matches(rendList));
        }
Example #4
0
 /// <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);
 }
Example #5
0
        public void TestMatchesEmpty()
        {
            MediaList ssList = new MediaList(String.Empty);
            MediaList rendList = new MediaList("screen");

            Assert.IsTrue(ssList.Matches(rendList));
        }
Example #6
0
 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]);
 }
Example #7
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;
        }
Example #8
0
        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;
        }
Example #9
0
        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]);
        }
Example #10
0
 public CssMediaRule(string cssText, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
     : base(parent, readOnly, replacedStrings, origin)
 {
     media = new MediaList(cssText);
 }
Example #11
0
        public void TestMatchesNoMatch()
        {
            MediaList ssList = new MediaList("dummy");
            MediaList rendList = new MediaList("screen");

            Assert.IsTrue(!ssList.Matches(rendList));
        }
Example #12
0
 /// <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)
 {
 }
Example #13
0
 public void TestToBigIndex()
 {
     MediaList list = new MediaList("all, screen");
     Assert.IsNull(list[2]);
 }
Example #14
0
 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]);
 }
Example #15
0
 /// <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);
     }
 }
Example #16
0
 /// <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);
     }
 }
Example #17
0
 /// <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);
     }
 }
Example #18
0
 /// <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;
 }
Example #19
0
 /// <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);
     }
 }
Example #20
0
 public void TestEmptyConstructor()
 {
     MediaList list = new MediaList();
     Assert.AreEqual(0, list.Length);
     Assert.AreEqual("", list.MediaText);
 }
Example #21
0
 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);
 }
Example #22
0
 /// <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)
 {
 }
Example #23
0
 public void TestIncorrectButParsable1()
 {
     MediaList list = new MediaList("screen,,all");
     Assert.AreEqual(2, list.Length);
     Assert.AreEqual("screen,all", list.MediaText);
 }
Example #24
0
 /// <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);
     }
 }
Example #25
0
        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);
            }
        }
Example #26
0
 /// <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;
         }
     }
 }