Exemplo n.º 1
0
        public CssPropertyAlias(CssProperty target, int[] index)
        {
            IsAlias = true;

            if (index != null)
            {
                if (index.Length == 0)
                {
                    index = null;
                }
                else
                {
                    // Update target set size:
                    int maxSize = index[0] + 1;

                    if (maxSize > target.SetSize)
                    {
                        target.SetSize = maxSize;
                    }
                }
            }

            Target = target;
            Index  = index;
        }
Exemplo n.º 2
0
        /// <summary>Sets the named property on this style to the given value.</summary>
        /// <param name="cssProperty">The property to set or overwrite. e.g. "display".</param>
        /// <param name="value">The value to set the property to, e.g. "none".</param>
        public Css.Value Set(string cssProperty, string valueText)
        {
            cssProperty = cssProperty.Trim().ToLower();

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

            if (property == null)
            {
                // Property not found:
                return(null);
            }

            // The underlying value:
            Css.Value value;

            if (string.IsNullOrEmpty(valueText))
            {
                // No value - actually a clear:
                value = null;
            }
            else
            {
                // Create a lexer for the value:
                CssLexer lexer = new CssLexer(valueText, Element);

                // Read the underlying value:
                value = lexer.ReadValue();
            }

            // Apply, taking aliases into account:
            this[property] = value;

            return(value);
        }
Exemplo n.º 3
0
        /// <summary>Attempts to find the named property, returning the global property if it's found.</summary>
        /// <param name="property">The property to look for.</param>
        /// <returns>The global CssProperty if the property was found; Null otherwise.</returns>
        public static CssProperty Get(string property)
        {
            CssProperty globalProperty = null;

            All.TryGetValue(property, out globalProperty);
            return(globalProperty);
        }
Exemplo n.º 4
0
        public override bool OnAttributeChange(string property)
        {
            // Global CSS properties. Width, height, fill, stroke, visibility, font-family,font-style etc are handled here.
            Css.CssProperty cssProperty = Css.CssProperties.Get(property);

            // Style refresh:
            if (Style.Computed.FirstMatch != null)
            {
                // This is a runtime attribute change.
                // We must consider if it's affecting the style or not:
                Style.Computed.AttributeChanged(property);
            }

            if (cssProperty != null)
            {
                // It's a CSS property! Apply to style:
                Css.Value value = ValueHelpers.Get(getAttribute(property));
                style[cssProperty] = value;
            }
            else if (property == "x")
            {
                style.left = getAttribute("x");
            }
            else if (property == "y")
            {
                style.top = getAttribute("y");
            }
            else if (!base.OnAttributeChange(property))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
		/// <summary>Converts this value to a Unity Quaternion.</summary>
		public Quaternion GetQuaternion(RenderableData context,CssProperty property){		
			return Quaternion.Euler(
				this[0].GetDecimal(context,property.GetAliased(0)) * Mathf.Rad2Deg,
				this[1].GetDecimal(context,property.GetAliased(1)) * Mathf.Rad2Deg,
				this[2].GetDecimal(context,property.GetAliased(2)) * Mathf.Rad2Deg
			);
		}
Exemplo n.º 6
0
		/// <summary>Converts this value to a Unity Vector3.</summary>
		public Vector3 GetVector(RenderableData context,CssProperty property){
			return new Vector3(
				this[0].GetDecimal(context,property.GetAliased(0)),
				this[1].GetDecimal(context,property.GetAliased(1)),
				this[2].GetDecimal(context,property.GetAliased(2))
			);
		}
Exemplo n.º 7
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{
                // Get the property:
                CssProperty property = CssProperties.Get(cssProperty);

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

                return(this[property]);
            }

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

                if (property == null)
                {
                    return;
                }

                this[property] = value;
            }
        }
Exemplo n.º 8
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 virtual Value this[CssProperty property] {
     get{
         return(property.GetValue(this));
     }
     set{
         property.OnReadValue(this, value);
     }
 }
Exemplo n.º 9
0
        /// <summary>Sets the named css property from the given style if the property exists in the style.</summary>
        /// <param name="property">The css property, e.g. color.</param>
        /// <param name="style">The style to load value of the property from. This should be the computed style for the parent element.</param>
        public void Reapply(ComputedStyle style, CssProperty property)
        {
            // Get the current value:
            Value value = style[property];

            if (value != null)
            {
                // Apply it:
                property.Apply(style, value);
            }
        }
Exemplo n.º 10
0
        /// <summary>Attempts to find the property with the given name.
        /// If it's not found, a default property which is known to exist can be returned instead.
        /// For example, property "color".</summary>
        /// <param name="property">The property to look for.</param>
        /// <param name="defaultProperty">If the given property is not found, this is used instead.</param>
        /// <returns>The global property object.</returns>
        public static CssProperty Get(string property, string defaultProperty)
        {
            CssProperty globalProperty = Get(property);

            if (globalProperty == null)
            {
                globalProperty = Get(defaultProperty);
            }

            return(globalProperty);
        }
        /// <summary>Sets the named css property from the given style if the property exists in the style.</summary>
        /// <param name="property">The css property, e.g. color.</param>
        /// <param name="style">The style to load value of the property from. This should be the computed style for the parent element.</param>
        private void SetValue(CssProperty property, ComputedStyle style)
        {
            // Get the current value:
            Value value = style[property];

            if (value != null)
            {
                // Apply it:
                property.ApplyText(this, RenderData, style, value);
            }
        }
Exemplo n.º 12
0
        /// <summary>In order to know when certain properties have been set and which have not, each property that a composite property updates
        /// has a 'set info' object. When reading a composite value, all the set info values are checked to see which ones were
        /// not set. It then proceeds to update those to their initial value.</summary>
        public CssPropertySetInfo GetPropertySetInfo(CssProperty prop)
        {
            CssPropertySetInfo result;

            if (!AllProperties.TryGetValue(prop, out result))
            {
                result = new CssPropertySetInfo();
                AllProperties[prop] = result;
            }

            return(result);
        }
Exemplo n.º 13
0
        public override float GetDecimal(RenderableData context, CssProperty property)
        {
            // Act as the first value in the set:
            Value first = First;

            if (first == null)
            {
                return(0f);
            }

            return(first.GetDecimal(context, property));
        }
Exemplo n.º 14
0
        public override string GetText(RenderableData context, CssProperty property)
        {
            // Act as the first value in the set:
            Value first = First;

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

            return(first.GetText(context, property));
        }
Exemplo n.º 15
0
        public override bool GetBoolean(RenderableData context, CssProperty property)
        {
            // Act as the first value in the set:
            Value first = First;

            if (first == null)
            {
                return(false);
            }

            return(first.GetBoolean(context, property));
        }
Exemplo n.º 16
0
        /// <summary>This is called to change a CSS property from an element.
        /// For example, font color=".." uses this. It sets a specifity of 0 as required by
        /// https://www.w3.org/TR/CSS2/cascade.html 6.4.4</summary>
        /// <param name="cssProperty">The css property being changed.</param>
        /// <param name="newValue">The new property value.</param>
        public void ChangeTagProperty(string cssProperty, Css.Value newValue)
        {
            // Resolve the property:
            CssProperty property = CssProperties.Get(cssProperty);

            if (property == null)
            {
                return;
            }

            // Apply now:
            ChangeProperty(property, newValue);
        }
Exemplo n.º 17
0
		/// <summary>If this is a decimal, the raw decimal value. This is generally the main output.
		/// This overload explicitly tells it to use the vertical axis or not (e.g. when resolving %).</summary>
		public float GetDecimal(RenderableData context,ValueAxis axis){
			
			// Create the width or height property:
			if(VerticalProperty==null){
				CreateAxisProperties();
			}
			
			CssProperty property=(axis==ValueAxis.Y) ? VerticalProperty : (axis==ValueAxis.X) ? HorizontalProperty : DepthProperty;
			property.RelativeTo=ValueRelativity.SelfDimensions;
			
			// Get decimal using them:
			return GetDecimal(context,property);
		}
Exemplo n.º 18
0
        /// <summary>Resolves the named CSS property into a decimal value held in the computed style.</summary>
        protected float ResolveDecimal(Css.CssProperty prop)
        {
            // Reslove now:
            Css.Value val = ComputedStyle.Resolve(prop);

            if (val == null)
            {
                // Use initial value to avoid this one.
                return(0f);
            }

            return(val.GetDecimal(RenderData, prop));
        }
Exemplo n.º 19
0
        /// <summary>Creates vertical and horizontal CSS properties which are used when needing to specify which
        /// axis a % value is relative to.</summary>
        private static void CreateAxisProperties()
        {
            // Create the vertical property:
            VerticalProperty      = new CssProperty();
            VerticalProperty.Axis = ValueAxis.Y;

            // Create the horizontal property:
            HorizontalProperty      = new CssProperty();
            HorizontalProperty.Axis = ValueAxis.X;

            // Z property:
            DepthProperty      = new CssProperty();
            DepthProperty.Axis = ValueAxis.Z;
        }
Exemplo n.º 20
0
        /// <summary>Converts this value to a Unity colour.</summary>
        /// <returns>The unity colour represented by this value.</returns>
        public Color GetColour(RenderableData context, CssProperty property)
        {
            float r;
            float g;
            float b;
            float a;

            // If we actually hold less than 4 values, the value read is always 255.
            // We do this because alpha must not get wrapped, and because defaulting white is more useful.
            // (e.g. if you only declare rgb, the ValueSet handler will wrap r as alpha).
            int count = Count;

            if (count < 1)
            {
                r = 1f;
            }
            else
            {
                r = this[0].GetDecimal(context, property);
            }

            if (count < 2)
            {
                g = 1f;
            }
            else
            {
                g = this[1].GetDecimal(context, property);
            }

            if (count < 3)
            {
                b = 1f;
            }
            else
            {
                b = this[2].GetDecimal(context, property);
            }

            if (count < 4)
            {
                a = 1f;
            }
            else
            {
                a = this[3].GetDecimal(context, property);
            }

            return(new Color(r, g, b, a));
        }
Exemplo n.º 21
0
        /// <summary>Adds a CSS property to the global set.
        /// This is generally done automatically, but you can also add one manually if you wish.</summary>
        /// <param name="propertyType">The type of the property to add.</param>
        /// <returns>True if adding it was successful.</returns>
        public static bool Add(Type propertyType)
        {
            if (All == null)
            {
                // Create sets:
                All     = new Dictionary <string, CssProperty>();
                AllText = new Dictionary <string, CssProperty>();
            }

            // Create an instance now:
            CssProperty property = (CssProperty)Activator.CreateInstance(propertyType);

            string[] tags = property.GetProperties();

            if (tags == null || tags.Length == 0)
            {
                return(false);
            }

            for (int i = 0; i < tags.Length; i++)
            {
                // Grab the property:
                string propertyName = tags[i].ToLower();

                // Is it the first? If so, set the name:
                if (i == 0)
                {
                    property.Name = propertyName;
                }

                // Add it to properties:
                All[propertyName] = property;

                if (property.IsTextual)
                {
                    // Add it to text properties too:
                    AllText[propertyName] = property;
                }

                // Make sure initial value has low specif:
                property.InitialValue.Specifity = -1;

                // Add aliases:
                property.Aliases();
            }

            return(true);
        }
Exemplo n.º 22
0
        /// <summary>This is called to change a CSS property from an element.
        /// For example, font color=".." uses this. It sets a specifity of 0 as required by
        /// https://www.w3.org/TR/CSS2/cascade.html 6.4.4</summary>
        /// <param name="cssProperty">The css property being changed.</param>
        /// <param name="newValue">The new property value.</param>
        public Css.Value ChangeTagProperty(string cssProperty, string newValue)
        {
            // Resolve the property:
            CssProperty property = CssProperties.Get(cssProperty);

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

            Css.Value val = Css.Value.Load(newValue);

            // Apply now:
            ChangeProperty(property, val);

            return(val);
        }
Exemplo n.º 23
0
        /// <summary>Sets a property from a composite set. Any new values that are null are set to the initial value
        /// and inherit the specifity from the composite value.</summary>
        public void SetComposite(string cssProperty, Css.Value newValue, Css.Value composite)
        {
            // Get the property:
            CssProperty property = CssProperties.Get(cssProperty);

            if (property == null)
            {
                return;
            }

            if (newValue == null && composite != null)
            {
                // Use the specifity in the comps value:
                newValue = new Css.Keywords.Initial(property, composite.Specifity);
            }

            // Write it now:
            this[property] = newValue;
        }
Exemplo n.º 24
0
        /// <summary>Causes the named property to apply its value.</summary>
        public void Reapply(ComputedStyle computed, string propertyName)
        {
            // Get the property:
            CssProperty property = CssProperties.Get(propertyName);

            if (property == null)
            {
                return;
            }

            // Got a value?
            Value value = computed[property];

            if (value == null)
            {
                return;
            }

            // Apply:
            property.Apply(computed, value);
        }
Exemplo n.º 25
0
        /// <summary>This is called to change a CSS property from an element.
        /// For example, font color=".." uses this. It sets a specifity of 0 as required by
        /// https://www.w3.org/TR/CSS2/cascade.html 6.4.4</summary>
        /// <param name="cssProperty">The css property being changed.</param>
        /// <param name="newValue">The new property value.</param>
        public void ChangeTagProperty(string cssProperty, Css.Value newValue, bool requestLayout)
        {
            // Resolve the property:
            CssProperty property = CssProperties.Get(cssProperty);

            if (property == null)
            {
                return;
            }

            Renderman rm = (Element.document as Css.ReflowDocument).Renderer;

            bool layoutState = rm.DoLayout;

            // Apply now:
            ChangeProperty(property, newValue);

            // Restore layout state:
            if (!requestLayout)
            {
                rm.DoLayout = layoutState;
            }
        }
Exemplo n.º 26
0
        /// <summary>Gets or creates the base value for the given property.
        /// The base value is essentially the value held directly in this style sheet.
        /// E.g. if the value you're setting is the R channel of color-overlay, this sets up the color-overlay value for you.</summary>
        /// <returns>The raw value (which may have just been created). Never an 'inherit' or 'initial' keyword.</returns>
        internal Css.Value GetBaseValue(CssProperty property)
        {
            Css.Value propertyValue;

            // Does it exist already?
            if (!Properties.TryGetValue(property, out propertyValue))
            {
                // Nope! Create it now. Does the computed style hold a value instead?
                ComputedStyle computed = GetComputed();

                if (computed != null && computed.Properties.TryGetValue(property, out propertyValue) && propertyValue != null)
                {
                    // Derive from the computed value.
                    if (propertyValue is Css.Keywords.Inherit)
                    {
                        // Must clone the inherited value (using special inherit copy):
                        propertyValue = (propertyValue as Css.Keywords.Inherit).SetCopy();
                    }
                    else if (propertyValue is Css.Keywords.Initial)
                    {
                        // Clone the initial value:
                        propertyValue = property.InitialValue.Copy();
                    }
                    else
                    {
                        // Must copy it:
                        propertyValue = propertyValue.Copy();
                    }

                    // Make sure it has low specif:
                    propertyValue.Specifity = -1;
                }
                else
                {
                    // Needs to be created. Must also copy it.
                    // Copy is used because it'll probably change some internal value.
                    propertyValue = property.InitialValue.Copy();
                }

                Properties[property] = propertyValue;
            }
            else if (propertyValue is Css.Keywords.Inherit)
            {
                // Must clone the inherited value (using special inherit copy):
                propertyValue = (propertyValue as Css.Keywords.Inherit).SetCopy();

                // Make sure it has low specif:
                propertyValue.Specifity = -1;

                Properties[property] = propertyValue;
            }
            else if (propertyValue is Css.Keywords.Initial)
            {
                // Clone the initial value:
                propertyValue = property.InitialValue.Copy();

                // Make sure it has low specif:
                propertyValue.Specifity = -1;

                Properties[property] = propertyValue;
            }

            // If it's not currently a set, we need it as one.
            int size = property.SetSize;

            if (propertyValue is Css.ValueSet)
            {
                if (propertyValue.Count < size)
                {
                    // Resize it:
                    propertyValue.Count = size;
                }
            }
            else
            {
                // Create the set:
                Css.ValueSet set = new Css.ValueSet();
                set.Count = size;

                // Make sure it has low specif:
                set.Specifity = -1;

                for (int i = 0; i < size; i++)
                {
                    // Must copy each value (e.g. if they get animated):
                    set[i] = propertyValue.Copy();
                }

                Properties[property] = set;

                propertyValue = set;
            }

            return(propertyValue);
        }
Exemplo n.º 27
0
 /// <summary>Lets the sheet know that a value changed. Non-alias values here only.</summary>
 public void CallChange(CssProperty property, Value value)
 {
     // Let the sheet know the value changed:
     OnChanged(property, value);
 }
 public DirectionAwareProperty(CssProperty target, int[] index) : base(target, index)
 {
     // Last one becomes our logical index:
     LogicalIndex            = index[index.Length - 1];
     index[index.Length - 1] = -1;
 }
Exemplo n.º 29
0
 public override string GetText(RenderableData context, CssProperty property)
 {
     return(Name);
 }
Exemplo n.º 30
0
 /// <summary>called when the named property changes.</summary>
 /// <param name="property">The property that changed.</param>
 /// <param name="newValue">It's new fully parsed value. May be null.</param>
 public virtual void OnChanged(CssProperty property, Value newValue)
 {
 }