2 using System.Collections.Generic;
3 using System.Reflection;
4 using Tizen.NUI.Binding;
6 namespace Tizen.NUI.StyleSheets
8 internal sealed class Style
14 public IDictionary<string, string> Declarations { get; set; } = new Dictionary<string, string>();
15 Dictionary<KeyValuePair<string, string>, object> convertedValues = new Dictionary<KeyValuePair<string, string>, object>();
17 public static Style Parse(CssReader reader, char stopChar = '\0')
19 Style style = new Style();
20 string propertyName = null, propertyValue = null;
23 reader.SkipWhiteSpaces();
24 bool readingName = true;
25 while ((p = reader.Peek()) > 0)
27 switch (unchecked((char)p))
32 reader.SkipWhiteSpaces();
36 if (!string.IsNullOrEmpty(propertyName) && !string.IsNullOrEmpty(propertyValue))
37 style.Declarations.Add(propertyName, propertyValue);
38 propertyName = propertyValue = null;
40 reader.SkipWhiteSpaces();
43 if ((char)p == stopChar)
48 propertyName = reader.ReadIdent();
49 if (propertyName == null)
50 throw new Exception();
53 propertyValue = reader.ReadUntil(stopChar, ';', ':');
60 public void Apply(/*VisualElement*/BaseHandle styleable, bool inheriting = false)
62 if (styleable == null)
63 throw new ArgumentNullException(nameof(styleable));
65 foreach (var decl in Declarations)
67 var property = ((IStylable)styleable).GetProperty(decl.Key, inheriting);
70 if (string.Equals(decl.Value, "initial", StringComparison.OrdinalIgnoreCase))
71 styleable.ClearValue(property, fromStyle: true);
75 if (!convertedValues.TryGetValue(decl, out value))
76 convertedValues[decl] = (value = Convert(styleable, decl.Value, property));
77 styleable.SetValue(property, value, fromStyle: true);
81 foreach (var child in styleable.LogicalChildrenInternal)
83 var ve = child as /*VisualElement*/BaseHandle;
86 Apply(ve, inheriting: true);
90 // [MethodImpl(MethodImplOptions.AggressiveInlining)]
91 static object Convert(object target, object value, BindableProperty property)
93 Func<MemberInfo> minforetriever = () => property.DeclaringType.GetRuntimeProperty(property.PropertyName) as MemberInfo
94 ?? property.DeclaringType.GetRuntimeMethod("Get" + property.PropertyName, new[] { typeof(BindableObject) }) as MemberInfo;
95 var serviceProvider = new StyleSheetServiceProvider(target, property);
96 // return value.ConvertTo(property.ReturnType, minforetriever, serviceProvider);
100 public void UnApply(IStylable styleable)
102 throw new NotImplementedException();