Esempio n. 1
0
        public override Rule LoadRule(Css.Rule parent, StyleSheet sheet, Css.Value value)
        {
            // Grab the sheet:
            ParentSheet = sheet;
            RawValue    = value;

            // Simply read a block like normal:
            Css.Value blk = value[value.Count - 1];

            // Grab it as a block unit:
            SelectorBlockUnit block = blk as SelectorBlockUnit;

            if (block == null)
            {
                // Broken page :(
                return(null);
            }

            // Grab the style:
            this.style = block.Style;



            return(this);
        }
Esempio n. 2
0
        public override Rule LoadRule(Css.Rule parent, StyleSheet sheet, Css.Value value)
        {
            // Grab the sheet:
            ParentSheet = sheet;
            RawValue    = value;

            // Read a value:
            Css.Value val = value[1];

            // Get the value as constant text:
            CounterName = val.Text;

            // Read a block like normal:
            Css.Value blk = value[value.Count - 1];

            // Grab it as a block unit:
            SelectorBlockUnit block = blk as SelectorBlockUnit;

            if (block == null)
            {
                // Broken :(
                return(null);
            }

            // Grab the style:
            this.style = block.Style;

            return(this);
        }
Esempio n. 3
0
        public override Rule LoadRule(Css.Rule parent, StyleSheet style, Css.Value value)
        {
            // Read a name:
            Css.Value nameValue = value[1];

            // Get the name:
            string name = nameValue.Text;

            // Read the value (a selector block):
            Css.Value block = value[2];

            // Grab the block:
            SelectorBlockUnit sBlock = block as SelectorBlockUnit;

            // The block should now be a set of other blocks.
            // This set is accessible as sBlock.Rules.

            if (sBlock == null || name == null)
            {
                // Broken keyframe set.
                return(null);
            }

            // Get the frame set:
            List <Rule> rules = sBlock.Rules;

            if (rules == null || style.document == null)
            {
                // Broken keyframe set.
                return(null);
            }

            // Create it:
            return(new KeyframesRule(style, value, name, rules));
        }
Esempio n. 4
0
        public MediaRule(StyleSheet sheet, Css.Value rawValue, MediaQuery query, SelectorBlockUnit contents)
        {
            ParentSheet = sheet;
            Query       = query;
            RawValue    = rawValue;

            // Load rules from contents:
            // - No document here; we don't want them to get added to the lookup until we evaluate the rule.
            Rules = contents.LoadAsRules();
        }
        public override Rule LoadRule(Css.Rule parent, StyleSheet sheet, Css.Value value)
        {
            // Grab the sheet:
            ParentSheet = sheet;
            RawValue    = value;

            // Read a value:
            Css.Value val = value[1];

            // Get the value as constant text:
            FontName = val.Text;

            int count = value.Count;

            // Get the block:
            SelectorBlockUnit sBlock = value[count - 1] as SelectorBlockUnit;

            if (sBlock == null)
            {
                // Try as a set instead:
                ValueSet set = value[count - 1] as ValueSet;

                if (set == null)
                {
                    // Invalid/ unrecognised block. Ignore it.
                    return(null);
                }

                // Get last one in the set:
                sBlock = set[set.Count - 1] as SelectorBlockUnit;

                // still null?
                if (sBlock == null)
                {
                    // Invalid/ unrecognised block. Ignore it.
                    return(null);
                }
            }

            Entries = sBlock.LoadAsRules();

            return(this);
        }
Esempio n. 6
0
		public override Rule LoadRule(Css.Rule parent,StyleSheet style,Css.Value value){
			
			// Read a block like normal:
			Css.Value blk=value[1];
			
			// Grab it as a block unit:
			SelectorBlockUnit block=blk as SelectorBlockUnit;
			
			if(block==null){
				// Broken :(
				return null;
			}
			
			// Grab the style:
			this.style=block.Style;
			
			return this;
			
		}
Esempio n. 7
0
        public override Rule LoadRule(Css.Rule parent, StyleSheet style, Css.Value value)
        {
            // Get the count:
            int count = value.Count;

            // Get the block:
            SelectorBlockUnit sBlock = value[count - 1] as SelectorBlockUnit;

            if (sBlock == null)
            {
                // This happens when it contains a *comma* or it's actually broken.

                // Try as a set instead:
                ValueSet set = value[count - 1] as ValueSet;

                if (set == null)
                {
                    // Invalid/ unrecognised block. Ignore it.
                    return(null);
                }

                // Get last one in the set:
                sBlock = set[set.Count - 1] as SelectorBlockUnit;

                // still null?
                if (sBlock == null)
                {
                    // Invalid/ unrecognised block. Ignore it.
                    return(null);
                }

                // Clear it:
                set[set.Count - 1] = null;

                // Clear the @media part too:
                value[0][0] = null;

                // For each part, build a query:
                List <SupportsQuery> results = new List <SupportsQuery>();

                for (int i = 0; i < value.Count; i++)
                {
                    Value part = value[i];

                    if (part == null)
                    {
                        continue;
                    }

                    SupportsQuery q = SupportsQuery.Load(part, 0, part.Count - 1);

                    if (q != null)
                    {
                        results.Add(q);
                    }
                }

                if (results.Count == 1)
                {
                    Query = results[0];
                }
                else
                {
                    Query = new SupportsQueryList(results.ToArray());
                }
            }
            else
            {
                // Build the media query:
                Query = SupportsQuery.Load(value, 1, count - 2);
            }

            return(this);
        }
Esempio n. 8
0
        /// <summary>Converts a value to a rule. Note that it can be a set of rules (RuleSet).</summary>
        public static Rule ConvertToRule(Rule parentRule, Css.Value value, StyleSheet sheet, out Rule[] ruleSet)
        {
            ruleSet = null;

            if (value == null)
            {
                // Nothing else.
                return(null);
            }

            // Is it an @ rule? Note that they can actually be 'nested' inside an,array,of,selectors (happens with @media)
            AtRuleUnit atRule = value[0] as AtRuleUnit;

            if (atRule != null)
            {
                // Let the @ rule handle the value:
                return(atRule.AtRule.LoadRule(parentRule, sheet, value));
            }

            // One or more selectors followed by a block unit.
            // Get the block:
            int max = value.Count - 1;

            SelectorBlockUnit block = value[max] as SelectorBlockUnit;

            if (block == null)
            {
                // Try as a set instead:
                ValueSet set = value[max] as ValueSet;

                if (set == null)
                {
                    // Invalid/ unrecognised selector block. Ignore it.
                    return(null);
                }

                // Get last one in the set:
                block = set[set.Count - 1] as SelectorBlockUnit;

                // still null?
                if (block == null)
                {
                    // Invalid/ unrecognised selector block. Ignore it.
                    return(null);
                }

                // Check again for an @rule:
                Css.Value v0 = value[0];

                if (v0 != null && v0[0] is AtRuleUnit)
                {
                    // Got an at rule!
                    atRule = v0[0] as AtRuleUnit;

                    return(atRule.AtRule.LoadRule(parentRule, sheet, value));
                }

                // Clear last one:
                set[set.Count - 1] = null;
            }
            else
            {
                // Clear the block from the value:
                value[max] = null;
            }

            // Get the style object:
            Style style = block.Style;

            // Read the selector(s):
            List <Selector> into = new List <Selector>();

            ReadSelectors(sheet, value, into);

            if (into.Count == 0)
            {
                return(null);
            }

            if (into.Count != 1)
            {
                ruleSet = new Rule[into.Count];
            }

            // Got a specifity override? -spark-specifity:x
            Css.Value specifityOverride = null;
            int       specOverride      = -1;

            if (style.Properties.TryGetValue(Css.Properties.SparkSpecifity.GlobalProperty, out specifityOverride))
            {
                // Yep! Pull the integer value:
                specOverride = specifityOverride.GetInteger(null, null);
            }

            for (int i = 0; i < into.Count; i++)
            {
                // Get it:
                Selector s = into[i];

                // Create the rule:
                StyleRule rule = new StyleRule(style);
                rule.ParentStyleSheet = sheet;
                rule.Selector         = s;
                s.Rule = rule;

                // Must use a copy of the style if its a secondary selector.
                // This is because the 'specifity' of CSS properties is defined by how specific
                // a selector is. So, when there's multiple selectors, we have to clone the style.

                Style currentStyle = i == 0?style:style.Clone();

                // Apply the selectors specifity to the style:
                int specifity = s.Specifity;

                if (specOverride != -1)
                {
                    specifity = specOverride;
                }

                foreach (KeyValuePair <CssProperty, Css.Value> kvp in currentStyle.Properties)
                {
                    // Apply:
                    kvp.Value.SetSpecifity(specifity);
                }

                if (ruleSet == null)
                {
                    return(rule);
                }

                ruleSet[i] = rule;
            }

            return(null);
        }
Esempio n. 9
0
        public override Rule LoadRule(Css.Rule parent, StyleSheet style, Css.Value value)
        {
            // Get the count:
            int count = value.Count;

            // Get the block:
            SelectorBlockUnit sBlock = value[count - 1] as SelectorBlockUnit;

            if (sBlock == null)
            {
                // This happens in the following situations:
                // @media screen,projection{} (when it contains a *comma*)
                // @media screen; (broken css without an actual block)

                // Try as a set instead:
                ValueSet set = value[count - 1] as ValueSet;

                if (set == null)
                {
                    // Invalid/ unrecognised block. Ignore it.
                    return(null);
                }

                // Get last one in the set:
                sBlock = set[set.Count - 1] as SelectorBlockUnit;

                // still null?
                if (sBlock == null)
                {
                    // Invalid/ unrecognised block. Ignore it.
                    return(null);
                }

                // Clear it:
                set[set.Count - 1] = null;

                // Clear the @media part too:
                value[0][0] = null;

                // For each part, build a query:
                List <MediaQuery> results = new List <MediaQuery>();

                for (int i = 0; i < value.Count; i++)
                {
                    Value part = value[i];

                    if (part == null)
                    {
                        continue;
                    }

                    MediaQuery q = MediaQuery.Load(part, 0, part.Count - 1);

                    if (q != null)
                    {
                        results.Add(q);
                    }
                }

                if (results.Count == 1)
                {
                    Query = results[0];
                }
                else
                {
                    Query = new MediaQueryList(results.ToArray());
                }
            }
            else
            {
                // Build the media query:
                Query = MediaQuery.Load(value, 1, count - 2);
            }

            // Create the rule now:
            return(new MediaRule(style, value, Query, sBlock));
        }
Esempio n. 10
0
        public override Rule LoadRule(Css.Rule parent, StyleSheet sheet, Css.Value value)
        {
            // Grab the sheet:
            ParentSheet = sheet;
            RawValue    = value;

            // Simply read a block like normal:
            Css.Value blk = value[1];

            // Grab it as a block unit:
            SelectorBlockUnit block = blk as SelectorBlockUnit;

            if (block == null)
            {
                // Broken font-face :(
                return(null);
            }

            // Grab the style:
            this.style = block.Style;

            // Grab the src:
            Value src = this.style["src"];

            // Is it set?
            if (src == null)
            {
                return(null);
            }

            // Get the one with a format of otf or ttf:
            Value specificFormat = src.GetEntryWithAttribute(
                "format",
                "otf",
                "ttf",
                "truetype",
                "opentype"
                );

            if (specificFormat == null)
            {
                // Just a url()?
                if (src.IsCommaArray)
                {
                    //  url(), url(),.. (may contain formats)

                    // Get the first entry with no format attribute:
                    specificFormat = src.GetEntryWithoutAttribute("format");
                }
                else
                {
                    // Either just url() or url() format(unsupported)

                    // Check if it's the first form:
                    if (src["format"] == null)
                    {
                        // Yep, just a url. We'll try using it.
                        specificFormat = src;
                    }
                }
            }

            if (specificFormat != null)
            {
                LoadFont(specificFormat);
            }

            return(this);
        }