2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Reflection;
5 using Tizen.NUI.XamlBinding;
7 namespace Tizen.NUI.StyleSheets
9 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
10 [EditorBrowsable(EditorBrowsableState.Never)]
11 public sealed class Style
13 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
14 [EditorBrowsable(EditorBrowsableState.Never)]
19 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
20 [EditorBrowsable(EditorBrowsableState.Never)]
21 public IDictionary<string, string> Declarations { get; set; } = new Dictionary<string, string>();
22 Dictionary<KeyValuePair<string, string>, object> convertedValues = new Dictionary<KeyValuePair<string, string>, object>();
24 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
25 [EditorBrowsable(EditorBrowsableState.Never)]
26 public static Style Parse(CssReader reader, char stopChar = '\0')
28 Style style = new Style();
29 string propertyName = null, propertyValue = null;
32 reader.SkipWhiteSpaces();
33 bool readingName = true;
34 while ((p = reader.Peek()) > 0) {
35 switch (unchecked((char)p)) {
39 reader.SkipWhiteSpaces();
43 if (!string.IsNullOrEmpty(propertyName) && !string.IsNullOrEmpty(propertyValue))
44 style.Declarations.Add(propertyName, propertyValue);
45 propertyName = propertyValue = null;
47 reader.SkipWhiteSpaces();
50 if ((char)p == stopChar)
54 propertyName = reader.ReadIdent();
55 if (propertyName == null)
56 throw new Exception();
58 propertyValue = reader.ReadUntil(stopChar, ';', ':');
65 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
66 [EditorBrowsable(EditorBrowsableState.Never)]
67 public void Apply(Element styleable, bool inheriting = false)
69 if (styleable == null)
70 throw new ArgumentNullException(nameof(styleable));
72 foreach (var decl in Declarations) {
73 var property = ((IStylable)styleable).GetProperty(decl.Key, inheriting);
76 if (string.Equals(decl.Value, "initial", StringComparison.OrdinalIgnoreCase))
77 styleable.ClearValue(property, fromStyle: true);
80 if (!convertedValues.TryGetValue(decl, out value))
81 convertedValues[decl] = (value = Convert(styleable, decl.Value, property));
82 styleable.SetValue(property, value, fromStyle: true);
86 foreach (var child in styleable.LogicalChildrenInternal) {
87 var ve = child as Element;
90 Apply(ve, inheriting: true);
94 // [MethodImpl(MethodImplOptions.AggressiveInlining)]
95 static object Convert(object target, object value, BindableProperty property)
97 Func<MemberInfo> minforetriever = () => property.DeclaringType.GetRuntimeProperty(property.PropertyName) as MemberInfo
98 ?? property.DeclaringType.GetRuntimeMethod("Get" + property.PropertyName, new[] { typeof(BindableObject) }) as MemberInfo;
99 var serviceProvider = new StyleSheetServiceProvider(target, property);
100 // return value.ConvertTo(property.ReturnType, minforetriever, serviceProvider);
104 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
105 [EditorBrowsable(EditorBrowsableState.Never)]
106 public void UnApply(IStylable styleable)
108 throw new NotImplementedException();