コード例 #1
0
        internal CssValue(ECssValueTypes type, object value, ECssUnit unit) : this(type)
        {
            this.unit  = unit;
            this.value = value;

            if (type == ECssValueTypes.KEYWORD)// Try and catch some common IMPORTANT keywords
            {
                /* If our keyword can be resolved to another ECssValueType then its an global keyword */
                if (!Lookup.TryEnum(value as string, out ECssValueTypes outType))
                {
                    type = outType;
                }
            }
            else if (type == ECssValueTypes.DIMENSION || type == ECssValueTypes.RESOLUTION)
            {
                /* Make sure to correct the value and distinguish whether we are a Dimension or a Resolution */
                switch (unit)
                {
                case ECssUnit.DPI:
                case ECssUnit.DPCM:
                case ECssUnit.DPPX:
                    type = ECssValueTypes.RESOLUTION;
                    break;

                default:
                    type = ECssValueTypes.DIMENSION;
                    break;
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Clones an already existing <see cref="CssValue"/>
 /// </summary>
 internal CssValue(CssValue sv)
 {
     type  = sv.Type;
     value = sv.value;
     unit  = sv.Unit;
     flags = sv.Flags;
 }
コード例 #3
0
 /// <summary>
 /// Returns whether the specified value is valid according to the currently set options
 /// </summary>
 /// <param name="Value"></param>
 /// <returns></returns>
 public bool Is_Valid_Value_Type(ECssValueTypes Type)
 {
     return(0 != (AllowedTypes & Type));
 }
コード例 #4
0
        /// <summary>
        /// Define a new Css Styling property
        /// </summary>
        /// <param name="Name">CSS property name</param>
        /// <param name="Inherited">Do child elements inherit this value if they are unset?</param>
        /// <param name="Flags">Indicates what aspects of an element this property affects</param>
        /// <param name="Initial">Default value for the property</param>
        /// <param name="DisallowedTypes">Bitmask of all value data types which cannot be assigned to this property</param>
        /// <param name="Keywords">List of keywords which can be assigned to this property</param>
        /// <param name="IsPrivate">If TRUE then this property cannot be set from style-sheets</param>
        public MediaDefinition(AtomicName <EMediaFeatureName> Name, EMediaFeatureType Type, ECssValueTypes AllowedTypes, string[] Keywords = null)
        {
            this.Name = Name;
            this.Type = Type;

            if (Keywords is null)
            {
                keywordWhitelist = Array.Empty <string>();
            }
            else
            {
                keywordWhitelist = Keywords;
            }

            // Append the specified allowed types to our defaults
            this.AllowedTypes |= AllowedTypes;
        }
コード例 #5
0
        private static ECssValueFlags Get_Inherent_Value_Type_Flags(ECssValueTypes Type, ECssUnit Unit, object Value)
        {
            ECssValueFlags Flags = ECssValueFlags.None;

            /*if (Value is Array)
             * {
             *  Flags |= ECssValueFlags.Collection;
             * }*/

            switch (Type)
            {
            // NOTE: Auto values get calculated in vastly different ways, sometimes this doesn't even indicate that a value depends on the value of other properties,
            //so it should NOT get the 'Depends' flag
            case ECssValueTypes.INHERIT:    // Inherited values function like redirects which compute to the current value of the matching property for the owning element's parent
            case ECssValueTypes.PERCENT:    // Percentage values represent a percentage of another property's value
            {
                Flags |= ECssValueFlags.Depends;
                break;
            }

            case ECssValueTypes.NULL:
            case ECssValueTypes.NONE:
            case ECssValueTypes.INITIAL:
            case ECssValueTypes.INTEGER:
            case ECssValueTypes.NUMBER:
            case ECssValueTypes.STRING:
            case ECssValueTypes.KEYWORD:
            case ECssValueTypes.COLOR:
            case ECssValueTypes.IMAGE:
            case ECssValueTypes.POSITION:    // The position has already been resolved here.
            case ECssValueTypes.FUNCTION:    // The function args have already been resolved here.
            {
                Flags |= ECssValueFlags.Absolute;
                break;
            }

            case ECssValueTypes.UNSET:
            case ECssValueTypes.AUTO:
            case ECssValueTypes.DIMENSION:
            case ECssValueTypes.RATIO:
            case ECssValueTypes.RESOLUTION:
            {
                /* XXX:
                 * These values when used on properties CAN be dependant but arent always so idk maybe its best to leave them as absolute?
                 * Maybe we can come up with some sort of intermediate state that causes them to resolve their flag to absolute/dependent AFTER they get assigned to a property?
                 */
                Flags |= ECssValueFlags.Absolute;
                break;
            }

            case ECssValueTypes.COLLECTION:    // A collections flags are the combined flags of all it's sub-values
            {
                if (Value is Array array)
                {        // Multi object
                    foreach (object o in array)
                    {
                        if (o is CssValue cssValue)
                        {
                            Flags |= Get_Inherent_Value_Type_Flags(cssValue.Type, cssValue.Unit, cssValue.value);
                        }
                        else
                        {
                            throw new CssException($"All {nameof(CssValue)} collection members must be {nameof(CssValue)}s");
                        }
                    }
                    return(Flags);
                }
                else if (Value is CssValue cssValue)
                {        // Single object
                    Flags |= Get_Inherent_Value_Type_Flags(cssValue.Type, cssValue.Unit, cssValue.value);
                }
                else
                {
                    throw new CssException($"All {nameof(CssValue)} collection members must be {nameof(CssValue)}s");
                }
                break;
            }

            default:
            {
                throw new NotImplementedException($"Flag handling for the '{Enum.GetName(typeof(ECssValueTypes), Type)}' css-value type has not been implemented!");
            }
            }

            return(Flags);
        }
コード例 #6
0
 internal CssValue(ECssValueTypes type, object value, ECssValueFlags flags) : this(type)
 {
     this.value  = value;
     this.flags |= flags;
     this.value  = value;
 }
コード例 #7
0
 internal CssValue(ECssValueTypes type, object value = null) : this(type)
 {
     this.value = value;
 }
コード例 #8
0
 private CssValue(ECssValueTypes type)
 {
     this.type = type;
     flags    |= Get_Inherent_Value_Type_Flags(type, unit, value);
 }
コード例 #9
0
 internal CssValue(CssFunction function)
 {
     type  = ECssValueTypes.FUNCTION;
     value = function;
 }
コード例 #10
0
        /// <summary>
        /// Creates a new CSS property definition
        /// </summary>
        /// <param name="Name">CSS property name</param>
        /// <param name="Inherited">Do child elements inherit this value if they are unset?</param>
        /// <param name="Flags">Indicates what aspects of an element this property affects</param>
        /// <param name="Initial">Default value for the property</param>
        /// <param name="Keywords">List of keywords which can be assigned to this property</param>
        /// <param name="IsPrivate">If TRUE then this property cannot be set from style-sheets</param>
        public StyleDefinition(AtomicName <ECssPropertyID> Name, bool Inherited, EPropertyDirtFlags Flags, CssValue Initial, ECssValueTypes AllowedTypes = 0x0, string[] Keywords = null, bool IsPrivate = false, CssPercentageResolver Percentage_Resolver = null, params Tuple <EPropertyStage, PropertyResolverFunc>[] Resolvers)
        {
            this.Name                = Name;
            this.Flags               = Flags;
            this.IsPrivate           = IsPrivate;
            this.Inherited           = Inherited;
            this.Initial             = Initial;
            this.Percentage_Resolver = Percentage_Resolver;

            if (Keywords is null)
            {
                keywordWhitelist = Array.Empty <string>();
            }
            else
            {
                keywordWhitelist = Keywords.ToArray();
            }

            // Append the specified allowed types to our defaults
            this.AllowedTypes |= AllowedTypes;

            // Setup our resolver index
            foreach (var o in Resolvers)
            {
                propertyStageResolver[(int)o.Item1] = o.Item2;
            }
        }