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) {
26 switch (unchecked((char)p)) {
30 reader.SkipWhiteSpaces();
34 if (!string.IsNullOrEmpty(propertyName) && !string.IsNullOrEmpty(propertyValue))
35 style.Declarations.Add(propertyName, propertyValue);
36 propertyName = propertyValue = null;
38 reader.SkipWhiteSpaces();
41 if ((char)p == stopChar)
45 propertyName = reader.ReadIdent();
46 if (propertyName == null)
47 throw new Exception();
49 propertyValue = reader.ReadUntil(stopChar, ';', ':');
56 public void Apply(/*VisualElement*/BaseHandle styleable, bool inheriting = false)
58 if (styleable == null)
59 throw new ArgumentNullException(nameof(styleable));
61 foreach (var decl in Declarations) {
62 var property = ((IStylable)styleable).GetProperty(decl.Key, inheriting);
65 if (string.Equals(decl.Value, "initial", StringComparison.OrdinalIgnoreCase))
66 styleable.ClearValue(property, fromStyle: true);
69 if (!convertedValues.TryGetValue(decl, out value))
70 convertedValues[decl] = (value = Convert(styleable, decl.Value, property));
71 styleable.SetValue(property, value, fromStyle: true);
75 foreach (var child in styleable.LogicalChildrenInternal) {
76 var ve = child as /*VisualElement*/BaseHandle;
79 Apply(ve, inheriting: true);
83 // [MethodImpl(MethodImplOptions.AggressiveInlining)]
84 static object Convert(object target, object value, BindableProperty property)
86 Func<MemberInfo> minforetriever = () => property.DeclaringType.GetRuntimeProperty(property.PropertyName) as MemberInfo
87 ?? property.DeclaringType.GetRuntimeMethod("Get" + property.PropertyName, new[] { typeof(BindableObject) }) as MemberInfo;
88 var serviceProvider = new StyleSheetServiceProvider(target, property);
89 // return value.ConvertTo(property.ReturnType, minforetriever, serviceProvider);
93 public void UnApply(IStylable styleable)
95 throw new NotImplementedException();