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)) {
25 throw new XamlParseException($"No resource found for '{resourceId}'.", lineInfo);
26 using (var reader = new StreamReader(stream)) {
27 return FromReader(reader);
32 //used by code generated by XamlC. Has to stay public
33 [EditorBrowsable(EditorBrowsableState.Never)]
34 public static StyleSheet FromString(string stylesheet)
36 if (stylesheet == null)
37 throw new ArgumentNullException(nameof(stylesheet));
38 using (var reader = new StringReader(stylesheet))
39 return FromReader(reader);
42 public static StyleSheet FromReader(TextReader reader)
45 throw new ArgumentNullException(nameof(reader));
47 return Parse(new CssReader(reader));
50 [MethodImpl(MethodImplOptions.AggressiveInlining)]
51 static StyleSheet Parse(CssReader reader)
53 var sheet = new StyleSheet();
56 var selector = Selector.All;
60 reader.SkipWhiteSpaces();
61 while ((p = reader.Peek()) > 0) {
64 throw new NotSupportedException("AT-rules not supported");
67 style = Style.Parse(reader, '}');
73 throw new Exception();
75 sheet.Styles.Add(selector, style);
77 selector = Selector.All;
80 selector = Selector.Parse(reader, '{');
87 Type IStyle.TargetType
88 => typeof(/*VisualElement*/BaseHandle);
90 void IStyle.Apply(BindableObject bindable)
92 var styleable = bindable as Element;
93 if (styleable == null)
98 void Apply(Element styleable)
100 ApplyCore(styleable);
101 foreach (var child in styleable.LogicalChildrenInternal)
102 ((IStyle)this).Apply(child);
105 void ApplyCore(Element styleable)
107 var visualStylable = styleable as /*VisualElement*/BaseHandle;
108 if (visualStylable == null)
110 foreach (var kvp in Styles) {
111 var selector = kvp.Key;
112 var style = kvp.Value;
113 // if (!selector.Matches(styleable))
115 style.Apply(visualStylable);
119 void IStyle.UnApply(BindableObject bindable)
121 throw new NotImplementedException();