Ejemplo n.º 1
0
        private void ResolveInheritance(VisualElement element)
        {
            var specifiedStyle = element.specifiedStyle;

            var currentInheritedStyle = m_StyleMatchingContext.inheritedStyle;

            element.inheritedStyle = currentInheritedStyle;

            m_ResolveInheritData.CopyFrom(currentInheritedStyle);

            if (specifiedStyle.color.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.color = specifiedStyle.color;
            }

            if (specifiedStyle.unityFont.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.font = specifiedStyle.unityFont;
            }

            if (specifiedStyle.fontSize.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.fontSize = specifiedStyle.fontSize;
            }

            if (specifiedStyle.unityFontStyleAndWeight.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.unityFontStyle = specifiedStyle.unityFontStyleAndWeight;
            }

            if (specifiedStyle.unityTextAlign.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.unityTextAlign = specifiedStyle.unityTextAlign;
            }

            if (specifiedStyle.visibility.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.visibility = specifiedStyle.visibility;
            }

            if (specifiedStyle.whiteSpace.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.whiteSpace = specifiedStyle.whiteSpace;
            }

            if (!m_ResolveInheritData.Equals(currentInheritedStyle))
            {
                InheritedStylesData inheritData = null;
                int hash = m_ResolveInheritData.GetHashCode();
                if (!StyleCache.TryGetValue(hash, out inheritData))
                {
                    inheritData = new InheritedStylesData(m_ResolveInheritData);
                    StyleCache.SetValue(hash, inheritData);
                }

                m_StyleMatchingContext.inheritedStyle = inheritData;
            }

            element.propagatedStyle = m_StyleMatchingContext.inheritedStyle;
        }
        private void ResolveInheritance(VisualElement element)
        {
            var specifiedStyle = element.specifiedStyle;

            var currentInheritedStyle = m_StyleMatchingContext.inheritedStyle;

            element.inheritedStyle = currentInheritedStyle;

            m_ResolveInheritData.CopyFrom(currentInheritedStyle);

            if (specifiedStyle.color.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.color = specifiedStyle.color;
            }

            if (specifiedStyle.unityFont.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.font = specifiedStyle.unityFont;
            }

            if (specifiedStyle.fontSize.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                // Only calculated value can be inherited
                // Thus if it's a percentage the real value needs to be propagated
                // See: https://developer.mozilla.org/en-US/docs/Web/CSS/percentage
                m_ResolveInheritData.fontSize             = new StyleLength(ComputedStyle.CalculatePixelFontSize(element));
                m_ResolveInheritData.fontSize.specificity = specifiedStyle.fontSize.specificity;
            }

            if (specifiedStyle.unityFontStyleAndWeight.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.unityFontStyle = specifiedStyle.unityFontStyleAndWeight;
            }

            if (specifiedStyle.unityTextAlign.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.unityTextAlign = specifiedStyle.unityTextAlign;
            }

            if (specifiedStyle.visibility.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.visibility = specifiedStyle.visibility;
            }

            if (specifiedStyle.whiteSpace.specificity != StyleValueExtensions.UndefinedSpecificity)
            {
                m_ResolveInheritData.whiteSpace = specifiedStyle.whiteSpace;
            }

            if (!m_ResolveInheritData.Equals(currentInheritedStyle))
            {
                InheritedStylesData inheritData = null;
                int hash = m_ResolveInheritData.GetHashCode();
                if (!StyleCache.TryGetValue(hash, out inheritData))
                {
                    inheritData = new InheritedStylesData(m_ResolveInheritData);
                    StyleCache.SetValue(hash, inheritData);
                }

                m_StyleMatchingContext.inheritedStyle = inheritData;
            }

            element.propagatedStyle = m_StyleMatchingContext.inheritedStyle;
        }
 public static void SetValue(int hash, InheritedStylesData data)
 {
     s_InheritedStyleDataCache[hash] = data;
 }
 public static bool TryGetValue(int hash, out InheritedStylesData data)
 {
     return(s_InheritedStyleDataCache.TryGetValue(hash, out data));
 }