Internal class that stores a style in a declaration block
Example #1
0
 /// <summary>
 /// Used to find matching style rules in the cascading order
 /// </summary>
 internal void GetStylesForElement(CssCollectedStyleDeclaration csd, int specificity)
 {
     foreach (DictionaryEntry de in styles)
     {
         SharpCssStyle scs = (SharpCssStyle)de.Value;
         csd.CollectProperty(scs.Name, specificity, (CssValue)GetPropertyCssValue(scs.Name), scs.Origin, scs.Priority);
     }
 }
Example #2
0
        /// <summary>
        /// Used to set a property value and priority within this declaration block
        /// </summary>
        /// <param name="propertyName">The name of the CSS property. See the CSS property index.</param>
        /// <param name="value">The new value of the property.</param>
        /// <param name="priority">The new priority of the property (e.g. "important").</param>
        /// <exception cref="DomException">SYNTAX_ERR: Raised if the specified value has a syntax error and is unparsable.</exception>
        /// <exception cref="DomException">NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly.</exception>
        public void SetProperty(string propertyName, string value, string priority)
        {
            if (ReadOnly)
            {
                throw new DomException(DomExceptionType.NoModificationAllowedErr);
            }

            styles[propertyName] = new SharpCssStyle(propertyName, value, priority, _origin);
        }
Example #3
0
 /// <summary>
 /// Used to retrieve the object representation of the value of a CSS property if it has been explicitly set within this declaration block. This method returns null if the property is a shorthand property. Shorthand property values can only be accessed and modified as strings, using the getPropertyValue and setProperty methods.
 /// </summary>
 /// <param name="propertyName">The name of the CSS property. See the CSS property index.</param>
 /// <returns>Returns the value of the property if it has been explicitly set for this declaration block. Returns null if the property has not been set.</returns>
 public virtual ICssValue GetPropertyCssValue(string propertyName)
 {
     if (styles.ContainsKey(propertyName))
     {
         SharpCssStyle scs = (SharpCssStyle)styles[propertyName];
         if (scs.CssValue == null)
         {
             scs.CssValue = CssValue.GetCssValue(scs.Value, ReadOnly);
         }
         return(scs.CssValue);
     }
     else
     {
         return(null);
     }
 }
Example #4
0
        /// <summary>
        /// Used to remove a CSS property if it has been explicitly set within this declaration block.
        /// </summary>
        /// <param name="propertyName">The name of the CSS property. See the CSS property index.</param>
        /// <returns>Returns the value of the property if it has been explicitly set for this declaration block. Returns the empty string if the property has not been set or the property name does not correspond to a known CSS property.</returns>
        /// <exception cref="DomException">NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly.</exception>
        public string RemoveProperty(string propertyName)
        {
            if (ReadOnly)
            {
                throw new DomException(DomExceptionType.NoModificationAllowedErr);
            }

            if (styles.ContainsKey(propertyName))
            {
                SharpCssStyle s = (SharpCssStyle)styles[propertyName];
                styles.Remove(propertyName);
                return(s.Value);
            }
            else
            {
                return(String.Empty);
            }
        }
Example #5
0
 internal SharpCssStyle(SharpCssStyle style, int specificity, CssStyleSheetType origin)
     : this(style.Name, style.Value, style.Priority, origin)
 {
     Specificity = specificity;
 }
Example #6
0
 internal SharpCssStyle(SharpCssStyle style, int specificity, CssStyleSheetType origin) : this(style.Name, style.Value, style.Priority, origin)
 {
     Specificity = specificity;
 }
        private string parseString(string cssText)
        {
            bool startedWithABracket = false;

            cssText = cssText.Trim();
            if(cssText.StartsWith("{"))
            {
                cssText = cssText.Substring(1).Trim();
                startedWithABracket = true;
            }

            Match match = styleRegex.Match(cssText);
            while(match.Success)
            {
                string name = match.Groups["name"].Value;
                string value = match.Groups["value"].Value;
                if(_parentRule != null)
                {
                    value = ((CssRule)_parentRule).DeReplaceStrings(value);
                }
                string prio = match.Groups["priority"].Value;

                SharpCssStyle style = new SharpCssStyle(name, value, prio, _origin);

                bool addStyle = false;
                if(styles.ContainsKey(name))
                {
                    string existingPrio = ((SharpCssStyle)styles[name]).Priority;

                    if(existingPrio != "important" ||
                        prio == "important")
                    {
                        styles.Remove(name);
                        addStyle = true;
                    }
                }
                else
                {
                    addStyle = true;

                }

                if(addStyle)
                {
                    styles.Add(name, style);
                }

                cssText = cssText.Substring(match.Length).Trim();
                match = styleRegex.Match(cssText);
            }

            cssText = cssText.Trim();
            if(cssText.StartsWith("}"))
            {
                cssText = cssText.Substring(1);
            }
            else if(startedWithABracket)
            {
                throw new DomException(DomExceptionType.SyntaxErr, "Style declaration ending bracket missing");
            }
            return cssText;
        }
        /// <summary>
        /// Used to set a property value and priority within this declaration block
        /// </summary>
        /// <param name="propertyName">The name of the CSS property. See the CSS property index.</param>
        /// <param name="value">The new value of the property.</param>
        /// <param name="priority">The new priority of the property (e.g. "important").</param>
        /// <exception cref="DomException">SYNTAX_ERR: Raised if the specified value has a syntax error and is unparsable.</exception>
        /// <exception cref="DomException">NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly.</exception>
        public void SetProperty(string propertyName, string value, string priority)
        {
            if(ReadOnly) throw new DomException(DomExceptionType.NoModificationAllowedErr);

            styles[propertyName] = new SharpCssStyle(propertyName, value, priority, _origin);
        }
Example #9
0
        private string parseString(string cssText)
        {
            bool startedWithABracket = false;

            cssText = cssText.Trim();
            if (cssText.StartsWith("{"))
            {
                cssText             = cssText.Substring(1).Trim();
                startedWithABracket = true;
            }

            Match match = styleRegex.Match(cssText);

            while (match.Success)
            {
                string name  = match.Groups["name"].Value;
                string value = match.Groups["value"].Value;
                if (_parentRule != null)
                {
                    value = ((CssRule)_parentRule).DeReplaceStrings(value);
                }
                string prio = match.Groups["priority"].Value;

                SharpCssStyle style = new SharpCssStyle(name, value, prio, _origin);

                bool addStyle = false;
                if (styles.ContainsKey(name))
                {
                    string existingPrio = ((SharpCssStyle)styles[name]).Priority;

                    if (existingPrio != "important" ||
                        prio == "important")
                    {
                        styles.Remove(name);
                        addStyle = true;
                    }
                }
                else
                {
                    addStyle = true;
                }

                if (addStyle)
                {
                    styles.Add(name, style);
                }

                cssText = cssText.Substring(match.Length).Trim();
                match   = styleRegex.Match(cssText);
            }

            cssText = cssText.Trim();
            if (cssText.StartsWith("}"))
            {
                cssText = cssText.Substring(1);
            }
            else if (startedWithABracket)
            {
                throw new DomException(DomExceptionType.SyntaxErr, "Style declaration ending bracket missing");
            }
            return(cssText);
        }