internal void AppendDeclarations(StyleDeclaration style, string declarations) { var tokenizer = CreateTokenizer(declarations); var builder = new StylesheetComposer(tokenizer, this); builder.FillDeclarations(style); }
///<summary> ///</summary> ///<param name="style"></param> ///<param name="parentStyle"></param> ///<param name="selector"></param> ///<param name="autoRegisterWithStyleManager"></param> public CSSMergedStyleDeclaration(StyleDeclaration style, StyleDeclaration parentStyle, string selector, bool autoRegisterWithStyleManager) : base(selector, autoRegisterWithStyleManager) { _style = style; //_parentStyle = parentStyle; //int i; //int n; //if (null != _parentStyle && _parentStyle.effects) //{ // if (!effects) // effects = []; // effectsArray = _parentStyle.effects; // n = effectsArray.length; // for (i = 0; i < n; i++) // { // effects[i] = effectsArray[i]; // if (effects.indexOf(effectsArray[i]) == -1) // effects[i] = effectsArray[i]; // } //} _updateOverrides = true; }
// ReSharper disable UnusedMember.Local void Update() // ReSharper restore UnusedMember.Local { if (null == _declaration) { _declaration = StyleManager.Instance.GetStyleDeclaration(typeof(InspectorOverlay).FullName); } if (_borderColor != BorderColor || _textColor != TextColor || _font != Font) { if (_borderColor != BorderColor) { _borderColor = BorderColor; _declaration.SetStyle("borderColor", _borderColor); } if (_textColor != TextColor) { _textColor = TextColor; _declaration.SetStyle("textColor", _textColor); } if (_font != Font) { _font = Font; _declaration.SetStyle("font", _font); } } }
internal static StyleDeclaration ParseDeclarations(string declarations) { var parser = new StylesheetParser(); var style = new StyleDeclaration(parser); style.Update(declarations); return(style); }
internal static void AppendDeclarations(StyleDeclaration list, string css, bool quirksMode = false) { var parser = new Parser();//(new StyleSheet(), new StylesheetReader(declarations)) parser.AddRuleSet(list.ParentRule ?? new StyleRule(list)); parser._parsingContext = ParsingContext.InDeclaration; parser.Parse(css); }
internal static StyleDeclaration ParseDeclarations(string declarations, bool quirksMode = false) { var decl = new StyleDeclaration(); AppendDeclarations(decl, declarations, quirksMode); return(decl); }
/// <summary> /// Gets or sets logo. /// </summary> /// <param name="cssClass">CSS class.</param> /// <param name="value">New value.</param> /// <returns>Value.</returns> private string QueryBackgroundImage(string cssClass, bool addThemeRule, string value = null) { Property prop = null; StyleRule rule = null; string selector = null; string ret = string.Empty; StyleDeclaration declaration = null; rule = _stylesheet.Rules.OfType <StyleRule>() .Where(r => r.Selector.ToString().IndexOf(string.Concat(".theme-", _id, " ", cssClass), StringComparison.OrdinalIgnoreCase) >= 0) .FirstOrDefault(); if (rule != null) { prop = rule.Declarations.Where(d => string.Compare(d.Name, "background-image", true) == 0) .FirstOrDefault(); if (prop != null) { ret = Regex.Match( prop.Term.ToString(), @"url\s*\(([^\)]+)\)", RegexOptions.IgnoreCase ).Groups[1].Value.Trim('\'', '"').Trim(); if (value != null) { ret = value; rule.Declarations.Add(NewProperty("background-image", string.Format("url('{0}')", value))); } } } else if (value != null) { selector = string.Concat(".theme-", _id, " ", cssClass); if (addThemeRule) { selector += string.Concat(", .theme-", _id, cssClass); } declaration = new StyleDeclaration(); rule = new StyleRule(declaration); rule.Selector = new SimpleSelector(selector); rule.Declarations.Add(NewProperty("background-image", value.Length > 0 ? string.Format("url('{0}')", value) : "none")); _stylesheet.Rules.Add(rule); } return(ret); }
public static StyleSheet Parse(string code) { var styleSheet = new StyleSheet(); string capturedText = ""; string capturedCode = ""; StyleRule styleRule = new StyleRule(); StyleDeclaration rule = new StyleDeclaration(); for (int i = 0; i < code.Length; i++) { capturedCode += code[i]; if (code[i] == '{') { styleRule = new StyleRule() { SelectorText = capturedText.Trim() }; capturedText = ""; } else if (code[i] == ':') { rule = new StyleDeclaration() { Property = capturedText.Trim() }; capturedText = ""; } else if (code[i] == ';') { rule.Value = capturedText.Trim(); styleRule.Rules.Add(rule); capturedText = ""; } else if (code[i] == '}') { styleRule.CssText = capturedCode.Trim(); styleSheet.Rules.Add(styleRule); capturedCode = ""; } else { capturedText += code[i]; } } return(styleSheet); }
public static List <LayoutValue> GetLayoutDic(StyleDeclaration rule, bool important) { List <LayoutValue> dic = null; foreach (var item in rule.Where(x => important == x.IsImportant)) { var hasCssStyle = LayoutProperties.CssPropertyMap.TryGetValue(item.Name, out var prop); if (hasCssStyle) { if (dic == null) { dic = new List <LayoutValue>(); } dic.Add(new LayoutValue(prop, prop.Convert(item.Value))); } } return(dic); }
public void CssPropertyFactoryCalls() { var parser = new StylesheetParser(); var decl = new StyleDeclaration(parser); var invalid = decl.CreateProperty("invalid"); var border = decl.CreateProperty("border"); var color = decl.CreateProperty("color"); decl.SetProperty(color); var colorAgain = decl.CreateProperty("color"); Assert.Null(invalid); Assert.NotNull(border); Assert.NotNull(color); Assert.NotNull(colorAgain); Assert.IsType <BorderProperty>(border); Assert.IsType <ColorProperty>(color); Assert.Equal(color, colorAgain); }
public TextPosition FillDeclarations(StyleDeclaration style) { var token = NextToken(); _nodes.Push(style); ParseComments(ref token); while (token.IsNot(TokenType.EndOfFile, TokenType.CurlyBracketClose)) { //var property = CreateDeclarationWith(Factory.Properties.Create, ref token); var property = CreateDeclarationWith(PropertyFactory.Instance.Create, ref token); if ((property != null) && property.HasValue) { style.SetProperty(property); } ParseComments(ref token); } _nodes.Pop(); return(token.Position); }
public static Dictionary <string, object> GetRuleDic(StyleDeclaration rule, bool important) { var dic = new Dictionary <string, object>(); foreach (var item in rule.Where(x => important == x.IsImportant)) { var hasCssStyle = StyleProperties.CssPropertyMap.TryGetValue(item.Name, out var prop); if (hasCssStyle) { var specialName = GetSpecialName(item.Value); object value; if (specialName == SpecialNames.Initial) { value = prop.defaultValue; } if (specialName == SpecialNames.None) { value = prop.noneValue; } else if (specialName != SpecialNames.NoSpecialName && specialName != SpecialNames.CantParse) { value = specialName; } else { value = prop.Convert(item.Value); } if (!Equals(value, SpecialNames.CantParse)) { dic[prop.name] = value; } } } return(dic); }
public FontFaceRule() { _declarations = new StyleDeclaration(); RuleType = RuleType.FontFace; }
public StyleRule(IEnumerable<Property> declarations) { RuleType = RuleType.Style; _declarations = declarations as StyleDeclaration; if (_declarations == null) _declarations = new StyleDeclaration(declarations); }
public GenericRule() { Declarations = new StyleDeclaration(); }
public PageRule() { _declarations = new StyleDeclaration(); RuleType = RuleType.Page; }
public StyleRule(StyleDeclaration declarations) { RuleType = RuleType.Style; _declarations = declarations; }
// ReSharper restore UnassignedField.Global #endif /// <summary> /// Loads style declarations<br/> /// We are actually doing a full process from scratch on each screen resize<br/> /// The things that are cached are default styles (reflected) and eDriven stylesheet styles<br/> /// Each style declaration is being tested against its media queries<br/> /// Only declarations passing the media query are turned into actual CSSStyleDeclarations and are further processed<br/> /// </summary> internal static void Process() { var styleManager = StyleManager.Instance; #if DEBUG if (DebugMode) { Debug.Log("##### Loading style sheets #####"); } #endif /** * 1. Reloading the cache (the cache itself will do a full reload if needed) * */ StyleDeclarationCache.Instance.Load(); /** * 2. Getting ALL the style declarations from the cache * */ List<Serialization.StyleDeclaration> declarations = StyleDeclarationCache.Instance.GetDeclarations(); if (null == declarations) return; // nothing to do here int count = 0; var list = new List<string>(); /** * 4. Merging (A) * We need to group the same declarations together * That's because we need - at this stage - to merge declarations for the same component * In the StyleDeclaration system, there are no duplicated declarations * */ Dictionary<string, List<Serialization.StyleDeclaration>> groups = new Dictionary<string, List<Serialization.StyleDeclaration>>(); foreach (Serialization.StyleDeclaration declaration in declarations) { var mediaQueryPasses = true; if (null != declaration.MediaQueries) { foreach (MediaQuery query in declaration.MediaQueries) { /* if a single query doesn't pass, do not process this style declaration */ try { #if DEBUG if (DebugMode) { Debug.Log("Query: " + query); } #endif mediaQueryPasses = MediaQueryManager.Instance.EvaluateQuery(query.Name, query.Value); #if DEBUG if (DebugMode) { if (!mediaQueryPasses) Debug.Log(" " + query + " doesn't pass"); } #endif /** * When a single query doesn't pass, break the loop! * (this is the AND operation!) * */ if (!mediaQueryPasses) break; } catch (Exception ex) { Debug.LogError(ex.Message); } } } if (!mediaQueryPasses) continue; // skip //declarationsPassingMediaQueries.Add(declaration); Selector selector = Selector.BuildSelector(declaration.Type, declaration.Class, declaration.Id); var selString = selector.ToString(); if (!groups.ContainsKey(selString)) { groups[selString] = new List<Serialization.StyleDeclaration>(); } groups[selString].Add(declaration); /** * If we are here, it means the style declaration passes its own media queries * */ count++; } /** * 5. Merging (B) * Mearge declarations from each group together * */ foreach (var key in groups.Keys) { // check if the group contains declarations (it should, at least one) var decls = groups[key]; if (decls.Count == 0) continue; // take the first declaration var declaration = decls[0]; // create selector (same for all the declarations in the group) Selector selector = Selector.BuildSelector(declaration.Type, declaration.Class, declaration.Id); list.Add(selector.ToString()); // get the existing or create new declaration //StyleDeclaration mergedStyle = styleManager.GetMergedStyleDeclaration(selector.ToString()); StyleDeclaration style = styleManager.GetStyleDeclaration(selector.ToString()); if (null == style) { style = new StyleDeclaration(selector, true) // register { Module = declaration.Module }; } /*StyleDeclaration style = new StyleDeclaration(selector, mergedStyle == null) { Module = declaration.Module };*/ // create (blank) factory if (style.Set2 == null) { StyleTable mainTable = new StyleTable(); style.Set2 = new StyleTableValuesFactory(mainTable); // override the factory with each declaration foreach (Serialization.StyleDeclaration styleDeclaration in decls) { StyleTable styleTable = new StyleTable(); foreach (StyleProperty property in styleDeclaration.Properties) { var value = property.Value; /** * Very important: * null == value -> works only in build! * For the editor we need a paralel check: value.GetType() != typeof(Object) * That's because in editor the value isn't null!!!!! * */ if (null == value || value.GetType() != typeof(Object)) { styleTable.Add(property.Name, value); } } mainTable.OverrideWith(styleTable); } } //Debug.Log("style: " + style); } /*Debug.Log(@"!!!! declarationsPassingMediaQueries: " + ListUtil<StyleDeclaration>.Format(declarationsPassingMediaQueries));*/ #if DEBUG if (DebugMode) { StringBuilder sb = new StringBuilder(); list.Sort(); foreach (string name in list) { var line = string.Format(@"============== {0} ============== ", name); var decls = styleManager.GetStyleDeclarations(name); if (null != decls) line = string.Format(@"============== {0} [found {1}] ============== {2}", name, decls.Count, ListUtil<StyleDeclaration>.Format(decls)); sb.AppendLine(line); } Debug.Log(string.Format(@"Style declarations loaded from stylesheet ({0}): {1}", count, sb)); } #endif }
public KeyframeRule() { Declarations = new StyleDeclaration(); RuleType = RuleType.Keyframe; _values = new List<string>(); }
public KeyframeRule() { Declarations = new StyleDeclaration(); RuleType = RuleType.Keyframe; }