internal void ApplyShorthandProperty(StylePropertyReader reader)
        {
            switch (reader.propertyID)
            {
            case StylePropertyID.BorderColor:
                ShorthandApplicator.ApplyBorderColor(reader, this);
                break;

            case StylePropertyID.BorderRadius:
                ShorthandApplicator.ApplyBorderRadius(reader, this);
                break;

            case StylePropertyID.BorderWidth:
                ShorthandApplicator.ApplyBorderWidth(reader, this);
                break;

            case StylePropertyID.Flex:
                ShorthandApplicator.ApplyFlex(reader, this);
                break;

            case StylePropertyID.Margin:
                ShorthandApplicator.ApplyMargin(reader, this);
                break;

            case StylePropertyID.Padding:
                ShorthandApplicator.ApplyPadding(reader, this);
                break;

            default:
                throw new ArgumentException(string.Format("Non exhaustive switch statement (value={0})", reader.propertyID));
            }
        }
예제 #2
0
        public static void ApplyBorderWidth(StylePropertyReader reader, VisualElementStylesData styleData)
        {
            StyleLength top;
            StyleLength right;
            StyleLength bottom;
            StyleLength left;

            CompileBoxArea(reader, out top, out right, out bottom, out left);

            // border-width doesn't support any keyword, revert to 0 in that case
            if (top.keyword != StyleKeyword.Undefined)
            {
                top.value = 0f;
            }
            if (right.keyword != StyleKeyword.Undefined)
            {
                right.value = 0f;
            }
            if (bottom.keyword != StyleKeyword.Undefined)
            {
                bottom.value = 0f;
            }
            if (left.keyword != StyleKeyword.Undefined)
            {
                left.value = 0f;
            }

            styleData.borderTopWidth    = top.ToStyleFloat();
            styleData.borderRightWidth  = right.ToStyleFloat();
            styleData.borderBottomWidth = bottom.ToStyleFloat();
            styleData.borderLeftWidth   = left.ToStyleFloat();
        }
        private static void CompileBoxArea(StylePropertyReader reader, out StyleLength top, out StyleLength right, out StyleLength bottom, out StyleLength left)
        {
            top    = 0f;
            right  = 0f;
            bottom = 0f;
            left   = 0f;
            switch (reader.valueCount)
            {
            case 0:
                break;

            case 1:
                top = (right = (bottom = (left = reader.ReadStyleLength(0))));
                break;

            case 2:
                top  = (bottom = reader.ReadStyleLength(0));
                left = (right = reader.ReadStyleLength(1));
                break;

            case 3:
                top    = reader.ReadStyleLength(0);
                left   = (right = reader.ReadStyleLength(1));
                bottom = reader.ReadStyleLength(2);
                break;

            default:
                top    = reader.ReadStyleLength(0);
                right  = reader.ReadStyleLength(1);
                bottom = reader.ReadStyleLength(2);
                left   = reader.ReadStyleLength(3);
                break;
            }
        }
예제 #4
0
        public static void ApplyBorderColor(StylePropertyReader reader, VisualElementStylesData styleData)
        {
            StyleColor top;
            StyleColor right;
            StyleColor bottom;
            StyleColor left;

            CompileBoxArea(reader, out top, out right, out bottom, out left);

            // border-color doesn't support any keyword, revert to Color.clear in that case
            if (top.keyword != StyleKeyword.Undefined)
            {
                top.value = Color.clear;
            }
            if (right.keyword != StyleKeyword.Undefined)
            {
                right.value = Color.clear;
            }
            if (bottom.keyword != StyleKeyword.Undefined)
            {
                bottom.value = Color.clear;
            }
            if (left.keyword != StyleKeyword.Undefined)
            {
                left.value = Color.clear;
            }

            styleData.borderTopColor.Apply(top, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity);
            styleData.borderRightColor.Apply(right, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity);
            styleData.borderBottomColor.Apply(bottom, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity);
            styleData.borderLeftColor.Apply(left, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity);
        }
        private static void CompileBoxAreaNoKeyword(StylePropertyReader reader, out StyleLength top, out StyleLength right, out StyleLength bottom, out StyleLength left)
        {
            ShorthandApplicator.CompileBoxArea(reader, out top, out right, out bottom, out left);
            bool flag = top.keyword > StyleKeyword.Undefined;

            if (flag)
            {
                top.value = 0f;
            }
            bool flag2 = right.keyword > StyleKeyword.Undefined;

            if (flag2)
            {
                right.value = 0f;
            }
            bool flag3 = bottom.keyword > StyleKeyword.Undefined;

            if (flag3)
            {
                bottom.value = 0f;
            }
            bool flag4 = left.keyword > StyleKeyword.Undefined;

            if (flag4)
            {
                left.value = 0f;
            }
        }
예제 #6
0
        public static void ApplyBorderRadius(StylePropertyReader reader, VisualElementStylesData styleData)
        {
            StyleLength topLeft;
            StyleLength topRight;
            StyleLength bottomLeft;
            StyleLength bottomRight;

            CompileBoxArea(reader, out topLeft, out topRight, out bottomRight, out bottomLeft);

            // border-radius doesn't support any keyword, revert to 0 in that case
            if (topLeft.keyword != StyleKeyword.Undefined)
            {
                topLeft.value = 0f;
            }
            if (topRight.keyword != StyleKeyword.Undefined)
            {
                topRight.value = 0f;
            }
            if (bottomLeft.keyword != StyleKeyword.Undefined)
            {
                bottomLeft.value = 0f;
            }
            if (bottomRight.keyword != StyleKeyword.Undefined)
            {
                bottomRight.value = 0f;
            }

            styleData.borderTopLeftRadius     = topLeft;
            styleData.borderTopRightRadius    = topRight;
            styleData.borderBottomLeftRadius  = bottomLeft;
            styleData.borderBottomRightRadius = bottomRight;
        }
        public static void ApplyUnityTextOutline(StylePropertyReader reader, ref ComputedStyle computedStyle)
        {
            CompileTextOutline(reader, out Color unityTextOutlineColor, out float unityTextOutlineWidth);

            computedStyle.inheritedData.Write().unityTextOutlineColor = unityTextOutlineColor;
            computedStyle.inheritedData.Write().unityTextOutlineWidth = unityTextOutlineWidth;
        }
        public static void ApplyFlex(StylePropertyReader reader, ref ComputedStyle computedStyle)
        {
            CompileFlexShorthand(reader, out float flexGrow, out float flexShrink, out Length flexBasis);

            computedStyle.layoutData.Write().flexGrow   = flexGrow;
            computedStyle.layoutData.Write().flexShrink = flexShrink;
            computedStyle.layoutData.Write().flexBasis  = flexBasis;
        }
        private static void CompileBoxAreaNoKeyword(StylePropertyReader reader, out StyleColor top, out StyleColor right, out StyleColor bottom, out StyleColor left)
        {
            top    = Color.clear;
            right  = Color.clear;
            bottom = Color.clear;
            left   = Color.clear;
            switch (reader.valueCount)
            {
            case 0:
                break;

            case 1:
                top = (right = (bottom = (left = reader.ReadStyleColor(0))));
                break;

            case 2:
                top  = (bottom = reader.ReadStyleColor(0));
                left = (right = reader.ReadStyleColor(1));
                break;

            case 3:
                top    = reader.ReadStyleColor(0);
                left   = (right = reader.ReadStyleColor(1));
                bottom = reader.ReadStyleColor(2);
                break;

            default:
                top    = reader.ReadStyleColor(0);
                right  = reader.ReadStyleColor(1);
                bottom = reader.ReadStyleColor(2);
                left   = reader.ReadStyleColor(3);
                break;
            }
            bool flag = top.keyword > StyleKeyword.Undefined;

            if (flag)
            {
                top.value = Color.clear;
            }
            bool flag2 = right.keyword > StyleKeyword.Undefined;

            if (flag2)
            {
                right.value = Color.clear;
            }
            bool flag3 = bottom.keyword > StyleKeyword.Undefined;

            if (flag3)
            {
                bottom.value = Color.clear;
            }
            bool flag4 = left.keyword > StyleKeyword.Undefined;

            if (flag4)
            {
                left.value = Color.clear;
            }
        }
예제 #10
0
        public static void ApplyTransition(StylePropertyReader reader, ref ComputedStyle computedStyle)
        {
            CompileTransition(reader, out List <TimeValue> transitionDelay, out List <TimeValue> transitionDuration, out List <StylePropertyName> transitionProperty, out List <EasingFunction> transitionTimingFunction);

            computedStyle.transitionData.Write().transitionDelay.CopyFrom(transitionDelay);
            computedStyle.transitionData.Write().transitionDuration.CopyFrom(transitionDuration);
            computedStyle.transitionData.Write().transitionProperty.CopyFrom(transitionProperty);
            computedStyle.transitionData.Write().transitionTimingFunction.CopyFrom(transitionTimingFunction);
        }
예제 #11
0
        public static void ApplyPadding(StylePropertyReader reader, ref ComputedStyle computedStyle)
        {
            CompileBoxArea(reader, out Length paddingTop, out Length paddingRight, out Length paddingBottom, out Length paddingLeft);

            computedStyle.layoutData.Write().paddingTop    = paddingTop;
            computedStyle.layoutData.Write().paddingRight  = paddingRight;
            computedStyle.layoutData.Write().paddingBottom = paddingBottom;
            computedStyle.layoutData.Write().paddingLeft   = paddingLeft;
        }
예제 #12
0
        public static void ApplyMargin(StylePropertyReader reader, ref ComputedStyle computedStyle)
        {
            CompileBoxArea(reader, out Length marginTop, out Length marginRight, out Length marginBottom, out Length marginLeft);

            computedStyle.layoutData.Write().marginTop    = marginTop;
            computedStyle.layoutData.Write().marginRight  = marginRight;
            computedStyle.layoutData.Write().marginBottom = marginBottom;
            computedStyle.layoutData.Write().marginLeft   = marginLeft;
        }
예제 #13
0
        public static void ApplyBorderColor(StylePropertyReader reader, ref ComputedStyle computedStyle)
        {
            CompileBoxArea(reader, out Color borderTopColor, out Color borderRightColor, out Color borderBottomColor, out Color borderLeftColor);

            computedStyle.visualData.Write().borderTopColor    = borderTopColor;
            computedStyle.visualData.Write().borderRightColor  = borderRightColor;
            computedStyle.visualData.Write().borderBottomColor = borderBottomColor;
            computedStyle.visualData.Write().borderLeftColor   = borderLeftColor;
        }
예제 #14
0
        public static void ApplyBorderRadius(StylePropertyReader reader, ref ComputedStyle computedStyle)
        {
            CompileBorderRadius(reader, out Length borderTopLeftRadius, out Length borderTopRightRadius, out Length borderBottomRightRadius, out Length borderBottomLeftRadius);

            computedStyle.visualData.Write().borderTopLeftRadius     = borderTopLeftRadius;
            computedStyle.visualData.Write().borderTopRightRadius    = borderTopRightRadius;
            computedStyle.visualData.Write().borderBottomRightRadius = borderBottomRightRadius;
            computedStyle.visualData.Write().borderBottomLeftRadius  = borderBottomLeftRadius;
        }
예제 #15
0
        public static void ApplyBorderWidth(StylePropertyReader reader, ref ComputedStyle computedStyle)
        {
            CompileBoxArea(reader, out float borderTopWidth, out float borderRightWidth, out float borderBottomWidth, out float borderLeftWidth);

            computedStyle.layoutData.Write().borderTopWidth    = borderTopWidth;
            computedStyle.layoutData.Write().borderRightWidth  = borderRightWidth;
            computedStyle.layoutData.Write().borderBottomWidth = borderBottomWidth;
            computedStyle.layoutData.Write().borderLeftWidth   = borderLeftWidth;
        }
        private void ApplyUnsetStyleValue(StylePropertyReader reader, InheritedStylesData inheritedStylesData)
        {
            if (inheritedStylesData == null)
            {
                ApplyInitialStyleValue(reader);
            }

            var specificity = reader.specificity;

            switch (reader.propertyID)
            {
            case StylePropertyID.Color:
                color             = inheritedStylesData.color;
                color.specificity = specificity;
                break;

            case StylePropertyID.Font:
                unityFont             = inheritedStylesData.font;
                unityFont.specificity = specificity;
                break;

            case StylePropertyID.FontSize:
                fontSize             = inheritedStylesData.fontSize;
                fontSize.specificity = specificity;
                break;

            case StylePropertyID.FontStyleAndWeight:
                unityFontStyleAndWeight             = inheritedStylesData.unityFontStyle;
                unityFontStyleAndWeight.specificity = specificity;
                break;

            case StylePropertyID.UnityTextAlign:
                unityTextAlign             = inheritedStylesData.unityTextAlign;
                unityTextAlign.specificity = specificity;
                break;

            case StylePropertyID.Visibility:
                visibility             = inheritedStylesData.visibility;
                visibility.specificity = specificity;
                break;

            case StylePropertyID.WhiteSpace:
                whiteSpace             = inheritedStylesData.whiteSpace;
                whiteSpace.specificity = specificity;
                break;

            case StylePropertyID.Custom:
                RemoveCustomStyleProperty(reader.property.name);
                break;

            default:
                ApplyInitialStyleValue(reader.propertyID, specificity);
                break;
            }
        }
 private void ApplyInitialStyleValue(StylePropertyReader reader)
 {
     if (reader.propertyID == StylePropertyID.Custom)
     {
         RemoveCustomStyleProperty(reader.property.name);
     }
     else
     {
         ApplyInitialStyleValue(reader.propertyID, reader.specificity);
     }
 }
        public static void ApplyFlex(StylePropertyReader reader, ComputedStyle computedStyle)
        {
            StyleFloat  flexGrow;
            StyleFloat  flexShrink;
            StyleLength flexBasis;

            ShorthandApplicator.CompileFlexShorthand(reader, out flexGrow, out flexShrink, out flexBasis);
            computedStyle.nonInheritedData.flexGrow   = flexGrow;
            computedStyle.nonInheritedData.flexShrink = flexShrink;
            computedStyle.nonInheritedData.flexBasis  = flexBasis;
        }
        public static void ApplyBorderRadius(StylePropertyReader reader, ComputedStyle computedStyle)
        {
            StyleLength borderTopLeftRadius;
            StyleLength borderTopRightRadius;
            StyleLength borderBottomRightRadius;
            StyleLength borderBottomLeftRadius;

            ShorthandApplicator.CompileBoxAreaNoKeyword(reader, out borderTopLeftRadius, out borderTopRightRadius, out borderBottomRightRadius, out borderBottomLeftRadius);
            computedStyle.nonInheritedData.borderTopLeftRadius     = borderTopLeftRadius;
            computedStyle.nonInheritedData.borderTopRightRadius    = borderTopRightRadius;
            computedStyle.nonInheritedData.borderBottomRightRadius = borderBottomRightRadius;
            computedStyle.nonInheritedData.borderBottomLeftRadius  = borderBottomLeftRadius;
        }
        private static void CompileBoxAreaNoKeyword(StylePropertyReader reader, out StyleFloat top, out StyleFloat right, out StyleFloat bottom, out StyleFloat left)
        {
            StyleLength styleLength;
            StyleLength styleLength2;
            StyleLength styleLength3;
            StyleLength styleLength4;

            ShorthandApplicator.CompileBoxAreaNoKeyword(reader, out styleLength, out styleLength2, out styleLength3, out styleLength4);
            top    = styleLength.ToStyleFloat();
            right  = styleLength2.ToStyleFloat();
            bottom = styleLength3.ToStyleFloat();
            left   = styleLength4.ToStyleFloat();
        }
        public static void ApplyBorderWidth(StylePropertyReader reader, ComputedStyle computedStyle)
        {
            StyleFloat borderTopWidth;
            StyleFloat borderRightWidth;
            StyleFloat borderBottomWidth;
            StyleFloat borderLeftWidth;

            ShorthandApplicator.CompileBoxAreaNoKeyword(reader, out borderTopWidth, out borderRightWidth, out borderBottomWidth, out borderLeftWidth);
            computedStyle.nonInheritedData.borderTopWidth    = borderTopWidth;
            computedStyle.nonInheritedData.borderRightWidth  = borderRightWidth;
            computedStyle.nonInheritedData.borderBottomWidth = borderBottomWidth;
            computedStyle.nonInheritedData.borderLeftWidth   = borderLeftWidth;
        }
        public static void ApplyBorderColor(StylePropertyReader reader, ComputedStyle computedStyle)
        {
            StyleColor borderTopColor;
            StyleColor borderRightColor;
            StyleColor borderBottomColor;
            StyleColor borderLeftColor;

            ShorthandApplicator.CompileBoxAreaNoKeyword(reader, out borderTopColor, out borderRightColor, out borderBottomColor, out borderLeftColor);
            computedStyle.nonInheritedData.borderTopColor    = borderTopColor;
            computedStyle.nonInheritedData.borderRightColor  = borderRightColor;
            computedStyle.nonInheritedData.borderBottomColor = borderBottomColor;
            computedStyle.nonInheritedData.borderLeftColor   = borderLeftColor;
        }
        public static void ApplyMargin(StylePropertyReader reader, ComputedStyle computedStyle)
        {
            StyleLength marginTop;
            StyleLength marginRight;
            StyleLength marginBottom;
            StyleLength marginLeft;

            ShorthandApplicator.CompileBoxArea(reader, out marginTop, out marginRight, out marginBottom, out marginLeft);
            computedStyle.nonInheritedData.marginTop    = marginTop;
            computedStyle.nonInheritedData.marginRight  = marginRight;
            computedStyle.nonInheritedData.marginBottom = marginBottom;
            computedStyle.nonInheritedData.marginLeft   = marginLeft;
        }
        public static void ApplyPadding(StylePropertyReader reader, ComputedStyle computedStyle)
        {
            StyleLength paddingTop;
            StyleLength paddingRight;
            StyleLength paddingBottom;
            StyleLength paddingLeft;

            ShorthandApplicator.CompileBoxAreaNoKeyword(reader, out paddingTop, out paddingRight, out paddingBottom, out paddingLeft);
            computedStyle.nonInheritedData.paddingTop    = paddingTop;
            computedStyle.nonInheritedData.paddingRight  = paddingRight;
            computedStyle.nonInheritedData.paddingBottom = paddingBottom;
            computedStyle.nonInheritedData.paddingLeft   = paddingLeft;
        }
예제 #25
0
        public static void ApplyPadding(StylePropertyReader reader, VisualElementStylesData styleData)
        {
            StyleLength top;
            StyleLength right;
            StyleLength bottom;
            StyleLength left;

            CompileBoxArea(reader, out top, out right, out bottom, out left);

            styleData.paddingTop    = top;
            styleData.paddingRight  = right;
            styleData.paddingBottom = bottom;
            styleData.paddingLeft   = left;
        }
예제 #26
0
        private static void CompileBoxAreaNoKeyword(StylePropertyReader reader, out StyleFloat top, out StyleFloat right, out StyleFloat bottom, out StyleFloat left)
        {
            StyleLength t;
            StyleLength r;
            StyleLength b;
            StyleLength l;

            CompileBoxAreaNoKeyword(reader, out t, out r, out b, out l);

            top    = t.ToStyleFloat();
            right  = r.ToStyleFloat();
            bottom = b.ToStyleFloat();
            left   = l.ToStyleFloat();
        }
예제 #27
0
        public static void ApplyFlex(StylePropertyReader reader, VisualElementStylesData styleData)
        {
            StyleFloat  grow;
            StyleFloat  shrink;
            StyleLength basis;
            bool        valid = CompileFlexShorthand(reader, out grow, out shrink, out basis);

            if (valid)
            {
                styleData.flexGrow   = grow;
                styleData.flexShrink = shrink;
                styleData.flexBasis  = basis;
            }
        }
        private static void CompileBoxArea(StylePropertyReader reader, out float top, out float right, out float bottom, out float left)
        {
            Length t;
            Length r;
            Length b;
            Length l;

            CompileBoxArea(reader, out t, out r, out b, out l);

            top    = t.value;
            right  = r.value;
            bottom = b.value;
            left   = l.value;
        }
        private static void CompileBoxArea(StylePropertyReader reader, out Length top, out Length right, out Length bottom, out Length left)
        {
            top    = 0f;
            right  = 0f;
            bottom = 0f;
            left   = 0f;

            var valueCount = reader.valueCount;

            switch (valueCount)
            {
            // apply to all four sides
            case 0:
                break;

            case 1:
            {
                top = right = bottom = left = reader.ReadLength(0);
                break;
            }

            // vertical | horizontal
            case 2:
            {
                top  = bottom = reader.ReadLength(0);
                left = right = reader.ReadLength(1);
                break;
            }

            // top | horizontal | bottom
            case 3:
            {
                top    = reader.ReadLength(0);
                left   = right = reader.ReadLength(1);
                bottom = reader.ReadLength(2);
                break;
            }

            // top | right | bottom | left
            default:
            {
                top    = reader.ReadLength(0);
                right  = reader.ReadLength(1);
                bottom = reader.ReadLength(2);
                left   = reader.ReadLength(3);
                break;
            }
            }
        }
        private static void CompileBoxArea(StylePropertyReader reader, out Color top, out Color right, out Color bottom, out Color left)
        {
            top    = Color.clear;
            right  = Color.clear;
            bottom = Color.clear;
            left   = Color.clear;

            var valueCount = reader.valueCount;

            switch (valueCount)
            {
            // apply to all four sides
            case 0:
                break;

            case 1:
            {
                top = right = bottom = left = reader.ReadColor(0);
                break;
            }

            // vertical | horizontal
            case 2:
            {
                top  = bottom = reader.ReadColor(0);
                left = right = reader.ReadColor(1);
                break;
            }

            // top | horizontal | bottom
            case 3:
            {
                top    = reader.ReadColor(0);
                left   = right = reader.ReadColor(1);
                bottom = reader.ReadColor(2);
                break;
            }

            // top | right | bottom | left
            default:
            {
                top    = reader.ReadColor(0);
                right  = reader.ReadColor(1);
                bottom = reader.ReadColor(2);
                left   = reader.ReadColor(3);
                break;
            }
            }
        }