2 using System.Collections.Generic;
3 using System.ComponentModel;
5 using System.Reflection;
6 using System.Runtime.CompilerServices;
9 using Tizen.NUI.Binding;
11 namespace Tizen.NUI.StyleSheets
13 internal sealed class StyleSheet : IStyle
19 internal IDictionary<Selector, Style> Styles { get; set; } = new Dictionary<Selector, Style>();
21 public static StyleSheet FromAssemblyResource(Assembly assembly, string resourceId, IXmlLineInfo lineInfo = null)
23 using (var stream = assembly.GetManifestResourceStream(resourceId))
26 throw new XamlParseException($"No resource found for '{resourceId}'.", lineInfo);
27 using (var reader = new StreamReader(stream))
29 return FromReader(reader);
34 //used by code generated by XamlC. Has to stay public
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public static StyleSheet FromString(string stylesheet)
38 if (stylesheet == null)
39 throw new ArgumentNullException(nameof(stylesheet));
40 using (var reader = new StringReader(stylesheet))
41 return FromReader(reader);
44 public static StyleSheet FromReader(TextReader reader)
47 throw new ArgumentNullException(nameof(reader));
49 return Parse(new CssReader(reader));
52 [MethodImpl(MethodImplOptions.AggressiveInlining)]
53 static StyleSheet Parse(CssReader reader)
55 var sheet = new StyleSheet();
58 var selector = Selector.All;
62 reader.SkipWhiteSpaces();
63 while ((p = reader.Peek()) > 0)
68 throw new NotSupportedException("AT-rules not supported");
71 style = Style.Parse(reader, '}');
77 throw new Exception();
79 sheet.Styles.Add(selector, style);
81 selector = Selector.All;
84 selector = Selector.Parse(reader, '{');
91 Type IStyle.TargetType
92 => typeof(/*VisualElement*/BaseHandle);
94 void IStyle.Apply(BindableObject bindable)
96 var styleable = bindable as Element;
97 if (styleable == null)
102 void Apply(Element styleable)
104 ApplyCore(styleable);
105 foreach (var child in styleable.LogicalChildrenInternal)
106 ((IStyle)this).Apply(child);
109 void ApplyCore(Element styleable)
111 var visualStylable = styleable as /*VisualElement*/BaseHandle;
112 if (visualStylable == null)
114 foreach (var kvp in Styles)
116 var selector = kvp.Key;
117 var style = kvp.Value;
118 // if (!selector.Matches(styleable))
120 style.Apply(visualStylable);
124 void IStyle.UnApply(BindableObject bindable)
126 throw new NotImplementedException();