Exemple #1
0
        /// <summary>Gets the value of the given property, if any.</summary>
        /// <param name="cssProperty">The property to get the value of, e.g. "display".</param>
        /// <returns>The value of the property if found. Null otherwise.</returns>
        public Value Get(string cssProperty)
        {
            // Get the inner index:
            int innerIndex = Css.Value.GetInnerIndex(ref cssProperty);

            // Get the property:
            CssProperty property = CssProperties.Get(cssProperty);

            if (property == null)
            {
                // Property not found. Stop there.
                return(null);
            }

            Value result = this[property];

            if (result == null)
            {
                return(null);
            }

            if (innerIndex != -1)
            {
                return(result[innerIndex]);
            }

            return(result);
        }
Exemple #2
0
        /// <summary>Gets the given property as a css string. May optionally read the given inner index of it as a css string.</summary>
        /// <param name="property">The property to get as a string.</param>
        /// <param name="innerIndex">The inner value to get from the property. -1 for the whole property.</param>
        /// <returns>The property as a css string, e.g. color-overlay may return "#ffffff".</returns>
        public virtual string GetString(string cssProperty, int innerIndex)
        {
            // Get the property:
            CssProperty property = CssProperties.Get(cssProperty);

            if (property == null)
            {
                // Doesn't exist - can't have been set.
                return("");
            }

            // Get the value:
            Value propertyValue = this[property];

            if (propertyValue == null)
            {
                return("");
            }

            if (innerIndex != -1)
            {
                propertyValue = propertyValue[innerIndex];

                if (propertyValue == null)
                {
                    return("");
                }
            }

            return(propertyValue.ToString());
        }
        /// <summary>This is called to change a property defined by a css selector that matches the ID of this element.
        /// This change may be rejected if a style attribute on the element overrides this change.</summary>
        /// <param name="cssProperty">The css property being changed.</param>
        /// <param name="newValue">The new property value.</param>
        public void ChangeIDProperty(string cssProperty, Css.Value newValue)
        {
            // Resolve the property:
            CssProperty property = CssProperties.Get(cssProperty);

            if (property == null)
            {
                return;
            }

            // Apply now:
            ChangeIDProperty(property, newValue);
        }
Exemple #4
0
        /// <summary>Gets or sets the parsed value of this style by property name.</summary>
        /// <param name="property">The property to get the value for.</param>
        public Value this[string cssProperty] {
            get{
                Value result;

                // Get the property:
                int         innerIndex;
                CssProperty property = CssProperties.Get(cssProperty, out innerIndex);

                if (property == null)
                {
                    return(null);
                }

                if (Properties.TryGetValue(property, out result))
                {
                    if (innerIndex != -1)
                    {
                        // Grab the inner index:
                        result = result[innerIndex];
                    }
                }

                return(result);
            }

            set{
                // Get the CSS property:
                int         innerIndex;
                CssProperty property = CssProperties.Get(cssProperty, out innerIndex);

                if (property == null)
                {
                    return;
                }

                if (innerIndex != -1)
                {
                    // Apply to inner value.

                    // First, get the value we're applying the inner property to:
                    Css.Value mainValue = GetRawValue(property, value.Type);

                    // And apply it now:
                    mainValue[innerIndex] = value;

                    // Update value to the property which actually changed:
                    value = mainValue;

                    return;
                }
                else
                {
                    // Applying it to a main property:

                    if (value == null)
                    {
                        // Remove it:
                        Properties.Remove(property);
                    }
                    else
                    {
                        // Add it now:
                        Properties[property] = value;
                    }
                }

                // Let the sheet know the value changed:
                if (value == null || value.Type == ValueType.Null)
                {
                    OnChanged(property, null);
                }
                else
                {
                    OnChanged(property, value);
                }
            }
        }
Exemple #5
0
        /// <summary>Sets the named property on this style to the given value. An inner value may be set; For example,
        /// setting the red component of color-overlay (color-overlay-r) becomes color-overlay and an innerIndex of 0.</summary>
        /// <param name="property">The property to set or overwrite. e.g. "display".</param>
        /// <param name="value">The value to set the property to, e.g. "none".</param>
        /// <param name="innerIndex">The index of the inner value to set, if any. -1 to set the whole property.</param>
        private void Set(string cssProperty, string value, int innerIndex, bool important)
        {
            if (Element != null && Element.Document.AotDocument)
            {
                return;
            }

            // Get the property:
            CssProperty property = CssProperties.Get(cssProperty);

            if (property == null)
            {
                // It doesn't exist!
                return;
            }

            if (value == "")
            {
                value = null;
            }

            if (value == null)
            {
                Properties.Remove(property);
                // Was in there (and not blank) - change it.
                OnChanged(property, null);

                return;
            }

            // Get the type of the property:
            ValueType type = Css.Value.TypeOf(property, ref value);

            // Read or create the raw property value:
            Value propertyValue = GetRawValue(property, type);

            if (innerIndex != -1)
            {
                // Writing to an inner value, e.g. border-left. Grab it:
                Value innerValue = propertyValue[innerIndex];

                if (innerValue == null)
                {
                    innerValue = propertyValue[innerIndex] = new Value();
                }

                innerValue.Set(value);

                // Apply its importance:
                innerValue.Important = important;
            }
            else
            {
                if (type == ValueType.Null)
                {
                    propertyValue.Set(value);
                }
                else
                {
                    propertyValue.Set(value, type);
                }

                // Apply its importance:
                propertyValue.Important = important;
            }

            // Let the sheet know the value changed:
            if (type == ValueType.Null)
            {
                OnChanged(property, null);
            }
            else
            {
                OnChanged(property, propertyValue);
            }
        }