示例#1
0
        /// <summary>
        /// Sets the <see cref="Assigned"/> value for this property to the given color
        /// </summary>
        /// <param name="value"></param>
        public void Set(CssValue Horizontal, CssValue Vertical = null)
        {
            var newValue = CssValue.From(Horizontal, Vertical ?? CssValue.Null);

            if (Assigned != newValue)
            {
                Assigned = newValue;
            }
        }
示例#2
0
        /// <summary>
        /// Sets the <see cref="Assigned"/> value for this property to the given color
        /// </summary>
        /// <param name="value"></param>
        public void Set(Color value)
        {
            var newValue = CssValue.From(value);

            if (Assigned != newValue)
            {
                Assigned = newValue;
            }
        }
示例#3
0
        public void Set(string value)
        {
            var newValue = CssValue.From_String(value);

            if (base.Assigned != newValue)
            {
                base.Assigned = newValue;
            }
        }
示例#4
0
        /// <summary>
        /// Sets the <see cref="Assigned"/> value for this property
        /// </summary>
        /// <param name="value"></param>
        public void Set(int?value)
        {
            var newValue = CssValue.From(value, CssValue.Null);

            if (Assigned != newValue)
            {
                Assigned = newValue;
            }
        }
示例#5
0
        /// <summary>
        /// Sets the <see cref="Assigned"/> value for this property to the given length (in pixels)
        /// </summary>
        /// <param name="value"></param>
        public void Set(double?value)
        {
            var newValue = CssValue.From(value, ECssUnit.PX, CssValue.Null);

            if (Assigned != newValue)
            {
                Assigned = newValue;
            }
        }
示例#6
0
        public void Set_Margin_Implicit(int?horizontal, int?vertical)
        {
            /*Margin_Top.Set(vertical);
             * Margin_Right.Set(horizontal);
             * Margin_Bottom.Set(vertical);
             * Margin_Left.Set(horizontal);*/

            Margin_Top.Set(!vertical.HasValue ? null : CssValue.From(vertical.Value, ECssUnit.PX));
            Margin_Right.Set(!horizontal.HasValue ? null : CssValue.From(horizontal.Value, ECssUnit.PX));
            Margin_Bottom.Set(!vertical.HasValue ? null : CssValue.From(vertical.Value, ECssUnit.PX));
            Margin_Left.Set(!horizontal.HasValue ? null : CssValue.From(horizontal.Value, ECssUnit.PX));
        }
示例#7
0
        public void Set_Margin(int?top, int?right, int?bottom, int?left)
        {
            /*Margin_Top.Set(top);
             * Margin_Right.Set(right);
             * Margin_Bottom.Set(bottom);
             * Margin_Left.Set(left);*/

            Margin_Top.Set(!top.HasValue ? null : CssValue.From(top.Value, ECssUnit.PX));
            Margin_Right.Set(!right.HasValue ? null : CssValue.From(right.Value, ECssUnit.PX));
            Margin_Bottom.Set(!bottom.HasValue ? null : CssValue.From(bottom.Value, ECssUnit.PX));
            Margin_Left.Set(!left.HasValue ? null : CssValue.From(left.Value, ECssUnit.PX));
        }
示例#8
0
        public void Set_Padding(int?horizontal, int?vertical)
        {
            /*Padding_Top.Set(vertical);
             * Padding_Right.Set(horizontal);
             * Padding_Bottom.Set(vertical);
             * Padding_Left.Set(horizontal);*/

            Padding_Top.Set(!vertical.HasValue ? null : CssValue.From(vertical.Value, ECssUnit.PX));
            Padding_Right.Set(!horizontal.HasValue ? null : CssValue.From(horizontal.Value, ECssUnit.PX));
            Padding_Bottom.Set(!vertical.HasValue ? null : CssValue.From(vertical.Value, ECssUnit.PX));
            Padding_Left.Set(!horizontal.HasValue ? null : CssValue.From(horizontal.Value, ECssUnit.PX));
        }
示例#9
0
        public void Set_Padding(int?top, int?right, int?bottom, int?left)
        {
            /*Padding_Top.Set(top);
             * Padding_Right.Set(right);
             * Padding_Bottom.Set(bottom);
             * Padding_Left.Set(left);*/

            Padding_Top.Set(!top.HasValue ? null : CssValue.From(top.Value, ECssUnit.PX));
            Padding_Right.Set(!right.HasValue ? null : CssValue.From(right.Value, ECssUnit.PX));
            Padding_Bottom.Set(!bottom.HasValue ? null : CssValue.From(bottom.Value, ECssUnit.PX));
            Padding_Left.Set(!left.HasValue ? null : CssValue.From(left.Value, ECssUnit.PX));
        }
示例#10
0
        public static double Solve_Object_Axis_Position(CssValue Pos, double ObjectArea, double ObjectSize)
        {/* https://www.w3.org/TR/css-backgrounds-3/#the-background-position */
            if (Pos is null)
            {
                throw new ArgumentNullException(nameof(Pos));
            }
            if (Pos.Type != ECssValueTypes.PERCENT)
            {
                throw new ArgumentException("Pos must be a CSS percent-type value!");
            }
            Contract.EndContractBlock();

            var P = Pos.AsDecimal();

            return((P * ObjectArea) - (P * ObjectSize));
        }
示例#11
0
        /// <summary>
        /// Returns whether the specified value is valid according to the currently set options
        /// </summary>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool IsValid(CssValue Value)
        {
            switch (Value.Type)
            {
            case ECssValueTypes.AUTO:
                return(AllowAuto);

            case ECssValueTypes.INHERIT:
                return(AllowInherited);

            case ECssValueTypes.PERCENT:
                return(AllowPercentage);

            default:
                return(true);
            }
        }
示例#12
0
        /// <summary>
        /// Applies the CSS specification formula for resolving object relative positions using the values given
        /// </summary>
        /// <param name="xPos">Positioning (along x-axis) to resolve </param>
        /// <param name="yPos">Positioning (along y-axis) to resolve </param>
        /// <param name="ObjectArea">Size of the area the object resides in</param>
        /// <param name="ObjectSize">Size of the object itsself</param>
        public static Point2f Solve_Object_Position(CssValue xPos, CssValue yPos, Rect2f ObjectArea, Rect2f ObjectSize)
        {/* https://www.w3.org/TR/css-backgrounds-3/#the-background-position */
            if (ObjectArea is null)
            {
                throw new ArgumentNullException(nameof(ObjectArea));
            }
            if (ObjectSize is null)
            {
                throw new ArgumentNullException(nameof(ObjectSize));
            }
            Contract.EndContractBlock();

            var retPos = new Point2f
            {
                X = Solve_Object_Axis_Position(xPos, ObjectArea.Width, ObjectSize.Width),
                Y = Solve_Object_Axis_Position(yPos, ObjectArea.Height, ObjectSize.Height)
            };

            return(retPos);
        }
示例#13
0
        internal CssValue Derive_ComputedValue(ICssProperty Property)
        {/* Docs:  https://www.w3.org/TR/css-cascade-3/#computed  */
            StyleDefinition Def = Property.Definition;

            // Resolve any relative values
            switch (Type)
            {
            case ECssValueTypes.INHERIT:    // Docs:  https://www.w3.org/TR/CSS2/cascade.html#value-def-inherit
            {
                return(Property.Find_Inherited_Value());
            }

            case ECssValueTypes.PERCENT:
            {
                if (Def.Percentage_Resolver != null)
                {
                    return(Def.Percentage_Resolver(Property, (double)value));
                }
            }
            break;

            case ECssValueTypes.DIMENSION:
            {
                double nv = Resolve(Property.Owner.ownerDocument.cssUnitResolver);
                return(CssValue.From(nv));
            }
            }

            // If we havent resolved a value yet that means this was meant to be handled by a custom handler
            var ResolutionDelegate = Def.PropertyStageResolver[(int)EPropertyStage.Computed];

            if (ResolutionDelegate is object)
            {
                return((CssValue)ResolutionDelegate.Invoke(Property));
            }


            return(this);
        }
示例#14
0
 public void Set_SizeMax(CssValue width, CssValue height)
 {
     Max_Width.Set(width);
     Max_Height.Set(height);
 }
示例#15
0
 public void Set_Size(CssValue width, CssValue height)
 {
     Width.Set(width);
     Height.Set(height);
 }
示例#16
0
 public void Set_Position(CssValue x, CssValue y)
 {
     Left.Set(x);
     Top.Set(y);
 }
示例#17
0
        /// <summary>
        /// The default sizing algorithm is a set of rules commonly used to find an object's concrete object size.
        /// It resolves the simultaneous constraints presented by the object's intrinsic dimensions and either an unconstrained specified size or one consisting of only a definite width and/or height.
        /// </summary>
        public static Rect2f Default_Sizing_Algorithm(CssPrincipalBox Box, CssValue Specified_Width, CssValue Specified_Height, double Default_Width, double Default_Height)
        {/* Docs: https://www.w3.org/TR/css3-images/#default-object-size */
            if (Box is null)
            {
                throw new ArgumentNullException(nameof(Box));
            }
            if (Specified_Width is null)
            {
                throw new ArgumentNullException(nameof(Specified_Width));
            }
            if (Specified_Height is null)
            {
                throw new ArgumentNullException(nameof(Specified_Height));
            }
            Contract.EndContractBlock();

            /* The default sizing algorithm is defined as follows: */

            /* If the specified size is a definite width and height, the concrete object size is given that width and height. */
            if (Specified_Width.IsDefinite && Specified_Height.IsDefinite)
            {
                return(new Rect2f(Specified_Width.AsDecimal(), Specified_Height.AsDecimal()));
            }

            /*
             * If the specified size is only a width or height (but not both) then the concrete object size is given that specified width or height. The other dimension is calculated as follows:
             * 1) If the object has an intrinsic aspect ratio, the missing dimension of the concrete object size is calculated using the intrinsic aspect ratio and the present dimension.
             * 2) Otherwise, if the missing dimension is present in the object's intrinsic dimensions, the missing dimension is taken from the object's intrinsic dimensions.
             * 3) Otherwise, the missing dimension of the concrete object size is taken from the default object size.
             */
            if (Specified_Width.HasValue ^ Specified_Height.HasValue)
            {
                if (Box.Intrinsic_Ratio.HasValue)
                {/* 1) If the object has an intrinsic aspect ratio, the missing dimension of the concrete object size is calculated using the intrinsic aspect ratio and the present dimension. */
                    if (Specified_Width.HasValue)
                    {
                        return(new Rect2f(Specified_Width.AsDecimal(), (Specified_Width.AsDecimal() / Box.Intrinsic_Ratio.Value)));
                    }
                    else
                    {
                        return(new Rect2f((Specified_Height.AsDecimal() * Box.Intrinsic_Ratio.Value), Specified_Height.AsDecimal()));
                    }
                }

                /* 2) Otherwise, if the missing dimension is present in the object's intrinsic dimensions, the missing dimension is taken from the object's intrinsic dimensions. */
                if (!Specified_Width.HasValue && Box.Intrinsic_Width.HasValue)
                {
                    return(new Rect2f(Box.Intrinsic_Width.Value, Specified_Height.AsDecimal()));
                }
                else if (!Specified_Height.HasValue && Box.Intrinsic_Height.HasValue)
                {
                    return(new Rect2f(Specified_Width.AsDecimal(), Box.Intrinsic_Height.Value));
                }

                /* 3) Otherwise, the missing dimension of the concrete object size is taken from the default object size. */
                if (Specified_Width.HasValue)
                {
                    return(new Rect2f(Specified_Width.AsDecimal(), Default_Height));
                }
                else
                {
                    return(new Rect2f(Default_Width, Specified_Height.AsDecimal()));
                }
            }

            /*
             * If the specified size has no constraints:
             * 1) If the object has an intrinsic height or width, its size is resolved as if its intrinsic size were given as the specified size.
             * 2) Otherwise, its size is resolved as a contain constraint against the default object size.
             */
            if (Box.Intrinsic_Width.HasValue || Box.Intrinsic_Height.HasValue)
            {
                if (Box.Intrinsic_Width.HasValue && Box.Intrinsic_Height.HasValue)
                {
                    return(new Rect2f(Box.Intrinsic_Width.Value, Box.Intrinsic_Height.Value));
                }
            }
            else if (Box.Intrinsic_Width.HasValue ^ Box.Intrinsic_Height.HasValue)
            {
                /* Step 1 */
                if (Box.Intrinsic_Ratio.HasValue)
                {/* 1) If the object has an intrinsic aspect ratio, the missing dimension of the concrete object size is calculated using the intrinsic aspect ratio and the present dimension. */
                    if (Box.Intrinsic_Width.HasValue)
                    {
                        return(new Rect2f(Box.Intrinsic_Width.Value, (Box.Intrinsic_Width.Value / Box.Intrinsic_Ratio.Value)));
                    }
                    else
                    {
                        return(new Rect2f((Box.Intrinsic_Height.Value * Box.Intrinsic_Ratio.Value), Box.Intrinsic_Height.Value));
                    }
                }

                /* Step 3 */
                if (Box.Intrinsic_Width.HasValue)
                {
                    return(new Rect2f(Box.Intrinsic_Width.Value, Default_Height));
                }
                else
                {
                    return(new Rect2f(Default_Width, Box.Intrinsic_Height.Value));
                }
            }

            /* 2) Otherwise, its size is resolved as a contain constraint against the default object size. */
            return(Contain_Constraint_Algorithm(Box, Default_Width, Default_Height));
        }
示例#18
0
 internal void Set_Position_Implicit(CssValue x, CssValue y)
 {
     Left.Set(x);
     Top.Set(y);
 }
示例#19
0
 /// <summary>Create an absolute integer value if not null, or return the given default value</summary>
 public static CssValue From(int?value, CssValue defaultValue) => (!value.HasValue ? defaultValue : new CssValue(ECssValueTypes.INTEGER, value.Value));
示例#20
0
 public void Set_SizeMin(CssValue width, CssValue height)
 {
     Min_Width.Set(width);
     Min_Height.Set(height);
 }
示例#21
0
 /// <summary>Create an absolute number value if not null, or return the given default value</summary>
 public static CssValue From(double?value, CssValue defaultValue) => (!value.HasValue ? defaultValue : new CssValue(ECssValueTypes.NUMBER, value.Value));
示例#22
0
 public void Set(Ty Value)
 {
     Assigned = CssValue.From(Value);
 }
示例#23
0
 /// <summary>Create an absolute length value if not null, or return the given default value</summary>
 public static CssValue From(double?value, ECssUnit Unit, CssValue defaultValue) => (!value.HasValue ? defaultValue : new CssValue(ECssValueTypes.DIMENSION, value.Value, Unit));