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; }
void ProcessMatchedRules(VisualElement element, List <SelectorMatchRecord> matchingSelectors) { matchingSelectors.Sort(SelectorMatchRecord.Compare); Int64 matchingRulesHash = element.fullTypeName.GetHashCode(); // Let current DPI contribute to the hash so cache is invalidated when this changes matchingRulesHash = (matchingRulesHash * 397) ^ currentPixelsPerPoint.GetHashCode(); foreach (var record in matchingSelectors) { StyleRule rule = record.complexSelector.rule; int specificity = record.complexSelector.specificity; matchingRulesHash = (matchingRulesHash * 397) ^ rule.GetHashCode(); matchingRulesHash = (matchingRulesHash * 397) ^ specificity; } VisualElementStylesData resolvedStyles; if (StyleCache.TryGetValue(matchingRulesHash, out resolvedStyles)) { element.SetSharedStyles(resolvedStyles); } else { resolvedStyles = new VisualElementStylesData(isShared: true); foreach (var record in matchingSelectors) { StylePropertyID[] propertyIDs = StyleSheetCache.GetPropertyIDs(record.sheet, record.complexSelector.ruleIndex); resolvedStyles.ApplyRule(record.sheet, record.complexSelector.specificity, record.complexSelector.rule, propertyIDs); } resolvedStyles.ApplyLayoutValues(); StyleCache.SetValue(matchingRulesHash, resolvedStyles); element.SetSharedStyles(resolvedStyles); } }
void ProcessMatchedRules(VisualElement element, List <SelectorMatchRecord> matchingSelectors) { matchingSelectors.Sort((a, b) => SelectorMatchRecord.Compare(a, b)); Int64 matchingRulesHash = element.fullTypeName.GetHashCode(); // Let current DPI contribute to the hash so cache is invalidated when this changes matchingRulesHash = (matchingRulesHash * 397) ^ currentPixelsPerPoint.GetHashCode(); int oldVariablesHash = m_StyleMatchingContext.variableContext.GetVariableHash(); int customPropertiesCount = 0; foreach (var record in matchingSelectors) { StyleRule rule = record.complexSelector.rule; int specificity = record.complexSelector.specificity; matchingRulesHash = (matchingRulesHash * 397) ^ rule.GetHashCode(); matchingRulesHash = (matchingRulesHash * 397) ^ specificity; if (rule.customPropertiesCount > 0) { customPropertiesCount += rule.customPropertiesCount; ProcessMatchedVariables(record.sheet, rule); } } var parent = element.hierarchy.parent; int inheritedStyleHash = parent != null ? parent.inheritedStylesHash : 0; matchingRulesHash = (matchingRulesHash * 397) ^ inheritedStyleHash; int variablesHash = oldVariablesHash; if (customPropertiesCount > 0) { // Element defines new variables, add the parents variables at the beginning of the processing context m_ProcessVarContext.InsertRange(0, m_StyleMatchingContext.variableContext); variablesHash = m_ProcessVarContext.GetVariableHash(); } matchingRulesHash = (matchingRulesHash * 397) ^ variablesHash; if (oldVariablesHash != variablesHash) { StyleVariableContext ctx; if (!StyleCache.TryGetValue(variablesHash, out ctx)) { ctx = new StyleVariableContext(m_ProcessVarContext); StyleCache.SetValue(variablesHash, ctx); } m_StyleMatchingContext.variableContext = ctx; } element.variableContext = m_StyleMatchingContext.variableContext; m_ProcessVarContext.Clear(); ComputedStyle resolvedStyles; if (StyleCache.TryGetValue(matchingRulesHash, out resolvedStyles)) { element.SetSharedStyles(resolvedStyles); } else { var parentStyle = parent?.computedStyle; resolvedStyles = ComputedStyle.Create(parentStyle, true); float dpiScaling = element.scaledPixelsPerPoint; foreach (var record in matchingSelectors) { m_StylePropertyReader.SetContext(record.sheet, record.complexSelector, m_StyleMatchingContext.variableContext, dpiScaling); resolvedStyles.ApplyProperties(m_StylePropertyReader, parentStyle); } resolvedStyles.FinalizeApply(parentStyle); StyleCache.SetValue(matchingRulesHash, resolvedStyles); element.SetSharedStyles(resolvedStyles); } }
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; }
void ProcessMatchedRules(VisualElement element, List <SelectorMatchRecord> matchingSelectors) { matchingSelectors.Sort(SelectorMatchRecord.Compare); Int64 matchingRulesHash = element.fullTypeName.GetHashCode(); // Let current DPI contribute to the hash so cache is invalidated when this changes matchingRulesHash = (matchingRulesHash * 397) ^ currentPixelsPerPoint.GetHashCode(); int oldVariablesHash = m_StyleMatchingContext.variableContext.GetVariableHash(); int customPropertiesCount = 0; foreach (var record in matchingSelectors) { StyleRule rule = record.complexSelector.rule; int specificity = record.complexSelector.specificity; matchingRulesHash = (matchingRulesHash * 397) ^ rule.GetHashCode(); matchingRulesHash = (matchingRulesHash * 397) ^ specificity; if (rule.customPropertiesCount > 0) { customPropertiesCount += rule.customPropertiesCount; ProcessMatchedVariables(record.sheet, rule); } } int variablesHash = customPropertiesCount > 0 ? m_ProcessVarContext.GetVariableHash() : oldVariablesHash; matchingRulesHash = (matchingRulesHash * 397) ^ variablesHash; if (oldVariablesHash != variablesHash) { StyleVariableContext ctx; if (!StyleCache.TryGetValue(variablesHash, out ctx)) { ctx = new StyleVariableContext(m_ProcessVarContext); StyleCache.SetValue(variablesHash, ctx); } m_StyleMatchingContext.variableContext = ctx; } element.variableContext = m_StyleMatchingContext.variableContext; VisualElementStylesData resolvedStyles; if (StyleCache.TryGetValue(matchingRulesHash, out resolvedStyles)) { element.SetSharedStyles(resolvedStyles); } else { resolvedStyles = new VisualElementStylesData(isShared: true); foreach (var record in matchingSelectors) { m_StylePropertyReader.SetContext(record.sheet, record.complexSelector, m_StyleMatchingContext.variableContext); resolvedStyles.ApplyProperties(m_StylePropertyReader, m_StyleMatchingContext.inheritedStyle); } resolvedStyles.ApplyLayoutValues(); StyleCache.SetValue(matchingRulesHash, resolvedStyles); element.SetSharedStyles(resolvedStyles); } }