using System.Xml;
using Tizen.NUI.Binding.Internals;
using Tizen.NUI.Binding;
-using Tizen.NUI.StyleSheets;
using static System.String;
if (xKey != null)
resourceDictionary.Add(xKey, value);
- else if (value is Tizen.NUI.Binding.Style)
- resourceDictionary.Add((Tizen.NUI.Binding.Style)value);
else if (value is ResourceDictionary)
resourceDictionary.Add((ResourceDictionary)value);
- else if (value is StyleSheets.StyleSheet)
- resourceDictionary.Add((StyleSheets.StyleSheet)value);
else
{
exception = new XamlParseException("resources in ResourceDictionary require a x:Key attribute", lineInfo);
// {
// return PlatformServices.GetNamedSize(size, targetElementType, useOldSizes);
// }
-
- public static class Styles
- {
- public const string TitleStyleKey = "TitleStyle";
-
- public const string SubtitleStyleKey = "SubtitleStyle";
-
- public const string BodyStyleKey = "BodyStyle";
-
- public const string ListItemTextStyleKey = "ListItemTextStyle";
-
- public const string ListItemDetailTextStyleKey = "ListItemDetailTextStyle";
-
- public const string CaptionStyleKey = "CaptionStyle";
-
- public static readonly Style TitleStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = TitleStyleKey };
-
- public static readonly Style SubtitleStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = SubtitleStyleKey };
-
- public static readonly Style BodyStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = BodyStyleKey };
-
- public static readonly Style ListItemTextStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = ListItemTextStyleKey };
-
- public static readonly Style ListItemDetailTextStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = ListItemDetailTextStyleKey };
-
- public static readonly Style CaptionStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = CaptionStyleKey };
- }
}
}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Tizen.NUI.StyleSheets;
-using Tizen.NUI.BaseComponents;
-
-namespace Tizen.NUI.Binding
-{
- internal sealed class MergedStyle : IStyle
- {
- ////If the base type is one of these, stop registering dynamic resources further
- ////The last one (typeof(Element)) is a safety guard as we might be creating VisualElement directly in internal code
- static readonly IList<Type> s_stopAtTypes = new List<Type> { typeof(View), typeof(Element) };
-
- IList<BindableProperty> _classStyleProperties;
-
- readonly List<BindableProperty> _implicitStyles = new List<BindableProperty>();
-
- IList<Style> _classStyles;
-
- IStyle _implicitStyle;
-
- IStyle _style;
-
- IList<string> _styleClass;
-
- public MergedStyle(Type targetType, BindableObject target)
- {
- Target = target;
- TargetType = targetType;
- RegisterImplicitStyles();
- Apply(Target);
- }
-
- public IStyle Style
- {
- get { return _style; }
- set { SetStyle(ImplicitStyle, ClassStyles, value); }
- }
-
- public IList<string> StyleClass
- {
- get { return _styleClass; }
- set
- {
- if (_styleClass == value)
- return;
-
- if (_styleClass != null && _classStyles != null)
- foreach (var classStyleProperty in _classStyleProperties)
- Target.RemoveDynamicResource(classStyleProperty);
-
- _styleClass = value;
-
- if (_styleClass != null)
- {
- _classStyleProperties = new List<BindableProperty>();
- foreach (var styleClass in _styleClass)
- {
- var classStyleProperty = BindableProperty.Create("ClassStyle", typeof(IList<Style>), typeof(View), default(IList<Style>),
- propertyChanged: (bindable, oldvalue, newvalue) => ((View)bindable)._mergedStyle.OnClassStyleChanged());
- _classStyleProperties.Add(classStyleProperty);
- Target.OnSetDynamicResource(classStyleProperty, Tizen.NUI.Binding.Style.StyleClassPrefix + styleClass);
- }
- }
- }
- }
-
- public BindableObject Target { get; }
-
- IList<Style> ClassStyles
- {
- get { return _classStyles; }
- set { SetStyle(ImplicitStyle, value, Style); }
- }
-
- IStyle ImplicitStyle
- {
- get { return _implicitStyle; }
- set { SetStyle(value, ClassStyles, Style); }
- }
-
- public void Apply(BindableObject bindable)
- {
- ImplicitStyle?.Apply(bindable);
- if (ClassStyles != null)
- foreach (var classStyle in ClassStyles)
- ((IStyle)classStyle)?.Apply(bindable);
- Style?.Apply(bindable);
- }
-
- public Type TargetType { get; }
-
- public void UnApply(BindableObject bindable)
- {
- Style?.UnApply(bindable);
- if (ClassStyles != null)
- foreach (var classStyle in ClassStyles)
- ((IStyle)classStyle)?.UnApply(bindable);
- ImplicitStyle?.UnApply(bindable);
- }
-
- void OnClassStyleChanged()
- {
- ClassStyles = _classStyleProperties.Select(p => (Target.GetValue(p) as IList<Style>)?.FirstOrDefault(s => s.CanBeAppliedTo(TargetType))).ToList();
- }
-
- void OnImplicitStyleChanged()
- {
- var first = true;
- foreach (BindableProperty implicitStyleProperty in _implicitStyles)
- {
- var implicitStyle = (Style)Target.GetValue(implicitStyleProperty);
- if (implicitStyle != null)
- {
- if (first || implicitStyle.ApplyToDerivedTypes)
- {
- ImplicitStyle = implicitStyle;
- return;
- }
- }
- first = false;
- }
- }
-
- void RegisterImplicitStyles()
- {
- Type type = TargetType;
- if (type == null)
- {
- return;
- }
- while (true)
- {
- BindableProperty implicitStyleProperty = BindableProperty.Create(nameof(ImplicitStyle), typeof(Style), typeof(View), default(Style),
- propertyChanged: (bindable, oldvalue, newvalue) => OnImplicitStyleChanged());
- _implicitStyles.Add(implicitStyleProperty);
- Target.SetDynamicResource(implicitStyleProperty, type.FullName);
- type = type.GetTypeInfo().BaseType;
- if (s_stopAtTypes.Contains(type))
- return;
- }
- }
-
- void SetStyle(IStyle implicitStyle, IList<Style> classStyles, IStyle style)
- {
- bool shouldReApplyStyle = implicitStyle != ImplicitStyle || classStyles != ClassStyles || Style != style;
- bool shouldReApplyClassStyle = implicitStyle != ImplicitStyle || classStyles != ClassStyles;
- bool shouldReApplyImplicitStyle = implicitStyle != ImplicitStyle && (Style as Style == null || ((Style)Style).CanCascade);
-
- if (shouldReApplyStyle)
- Style?.UnApply(Target);
- if (shouldReApplyClassStyle && ClassStyles != null)
- foreach (var classStyle in ClassStyles)
- ((IStyle)classStyle)?.UnApply(Target);
- if (shouldReApplyImplicitStyle)
- ImplicitStyle?.UnApply(Target);
-
- _implicitStyle = implicitStyle;
- _classStyles = classStyles;
- _style = style;
-
- if (shouldReApplyImplicitStyle)
- ImplicitStyle?.Apply(Target);
- if (shouldReApplyClassStyle && ClassStyles != null)
- foreach (var classStyle in ClassStyles)
- ((IStyle)classStyle)?.Apply(Target);
- if (shouldReApplyStyle)
- Style?.Apply(Target);
- }
- }
-}
\ No newline at end of file
foreach (KeyValuePair<string, object> res in ve.XamlResources.MergedResources)
if (!resources.ContainsKey(res.Key))
resources.Add(res.Key, res.Value);
- else if (res.Key.StartsWith(Style.StyleClassPrefix, StringComparison.Ordinal))
- {
- var mergedClassStyles = new List<Style>(resources[res.Key] as List<Style>);
- mergedClassStyles.AddRange(res.Value as List<Style>);
- resources[res.Key] = mergedClassStyles;
- }
}
}
foreach (KeyValuePair<string, object> res in app.SystemResources)
if (!resources.ContainsKey(res.Key))
resources.Add(res.Key, res.Value);
- else if (res.Key.StartsWith(Style.StyleClassPrefix, StringComparison.Ordinal))
- {
- var mergedClassStyles = new List<Style>(resources[res.Key] as List<Style>);
- mergedClassStyles.AddRange(res.Value as List<Style>);
- resources[res.Key] = mergedClassStyles;
- }
}
element = element.Parent;
}
+++ /dev/null
-using System.Runtime.CompilerServices;
-
-namespace Tizen.NUI.StyleSheets
-{
- internal static class CharExtensions
- {
- //w [ \t\r\n\f]*
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsW(this char c)
- {
- return c == ' '
- || c == '\t'
- || c == '\r'
- || c == '\n'
- || c == '\f';
- }
-
- //nmstart [_a-z]|{nonascii}|{escape}
- //escape {unicode}|\\[^\n\r\f0-9a-f]
- //nonascii [^\0-\237]
- // TODO support escape and nonascii
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsNmStart(this char c)
- {
- return c == '_' || char.IsLetter(c);
- }
-
- //nmchar [_a-z0-9-]|{nonascii}|{escape}
- //unicode \\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
- //escape {unicode}|\\[^\n\r\f0-9a-f]
- //nonascii [^\0-\237]
- //TODO support escape, nonascii and unicode
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsNmChar(this char c)
- {
- return c == '_'
- || c == '-'
- || char.IsLetterOrDigit(c);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.IO;
-
-namespace Tizen.NUI.StyleSheets
-{
- internal sealed class CssReader : TextReader
- {
- readonly TextReader _reader;
-
- public CssReader(TextReader reader)
- {
- if (reader == null)
- throw new ArgumentNullException(nameof(reader));
-
- _reader = reader;
- }
-
- readonly Queue<char> _cache = new Queue<char>();
-
- //skip comments
- //TODO unescape escaped sequences
- public override int Peek()
- {
- if (_cache.Count > 0)
- return _cache.Peek();
-
- int p = _reader.Peek();
- if (p <= 0)
- return p;
- if (unchecked((char)p) != '/')
- return p;
-
- _cache.Enqueue(unchecked((char)_reader.Read()));
- p = _reader.Peek();
- if (p <= 0)
- return _cache.Peek();
- if (unchecked((char)p) != '*')
- return _cache.Peek();
-
- _cache.Clear();
- _reader.Read(); //consume the '*'
-
- bool hasStar = false;
- while (true)
- {
- var next = _reader.Read();
- if (next <= 0)
- return next;
- if (unchecked((char)next) == '*')
- hasStar = true;
- else if (hasStar && unchecked((char)next) == '/')
- return Peek(); //recursively call self for comments following comments
- else
- hasStar = false;
- }
- }
-
- //skip comments
- //TODO unescape escaped sequences
- public override int Read()
- {
- if (_cache.Count > 0)
- return _cache.Dequeue();
-
- int p = _reader.Read();
- if (p <= 0)
- return p;
- var c = unchecked((char)p);
- if (c != '/')
- return p;
-
- _cache.Enqueue(c);
- p = _reader.Read();
- if (p <= 0)
- return _cache.Dequeue();
- c = unchecked((char)p);
- if (c != '*')
- return _cache.Dequeue();
-
- _cache.Clear();
- _reader.Read(); //consume the '*'
-
- bool hasStar = false;
- while (true)
- {
- var next = _reader.Read();
- if (next <= 0)
- return next;
- if (unchecked((char)next) == '*')
- hasStar = true;
- else if (hasStar && unchecked((char)next) == '/')
- return Read(); //recursively call self for comments following comments
- else
- hasStar = false;
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.StyleSheets
-{
- internal interface IStyle
- {
- Type TargetType { get; }
-
- void Apply(BindableObject bindable);
- void UnApply(BindableObject bindable);
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.StyleSheets
-{
- internal interface IStyleSelectable
- {
- string[] NameAndBases { get; }
- string Id { get; }
- IStyleSelectable Parent { get; }
- IList<string> Classes { get; }
- IEnumerable<IStyleSelectable> Children { get; }
- }
-
- internal interface IStylable
- {
- BindableProperty GetProperty(string key, bool inheriting);
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-
-namespace Tizen.NUI.StyleSheets
-{
- internal abstract class Selector
- {
- Selector()
- {
- }
-
- public static Selector Parse(CssReader reader, char stopChar = '\0')
- {
- Selector root = All, workingRoot = All;
- Operator workingRootParent = null;
- Action<Operator, Selector> setCurrentSelector = (op, sel) => SetCurrentSelector(ref root, ref workingRoot, ref workingRootParent, op, sel);
-
- int p;
- reader.SkipWhiteSpaces();
- while ((p = reader.Peek()) > 0)
- {
- switch (unchecked((char)p))
- {
- case '*':
- setCurrentSelector(new And(), All);
- reader.Read();
- break;
- case '.':
- reader.Read();
- var className = reader.ReadIdent();
- if (className == null)
- return Invalid;
- setCurrentSelector(new And(), new Class(className));
- break;
- case '#':
- reader.Read();
- var id = reader.ReadName();
- if (id == null)
- return Invalid;
- setCurrentSelector(new And(), new Id(id));
- break;
- case '[':
- throw new NotImplementedException("Attributes not implemented");
- case ',':
- reader.Read();
- setCurrentSelector(new Or(), All);
- reader.SkipWhiteSpaces();
- break;
- case '+':
- reader.Read();
- setCurrentSelector(new Adjacent(), All);
- reader.SkipWhiteSpaces();
- break;
- case '~':
- reader.Read();
- setCurrentSelector(new Sibling(), All);
- reader.SkipWhiteSpaces();
- break;
- case '>':
- reader.Read();
- setCurrentSelector(new Child(), All);
- reader.SkipWhiteSpaces();
- break;
- case '^': //not in CSS spec
- reader.Read();
- var element = reader.ReadIdent();
- if (element == null) return Invalid;
- setCurrentSelector(new And(), new Base(element));
- break;
- case ' ':
- case '\t':
- case '\n':
- case '\r':
- case '\f':
- reader.Read();
- bool processWs = false;
- while ((p = reader.Peek()) > 0)
- {
- var c = unchecked((char)p);
- if (char.IsWhiteSpace(c))
- {
- reader.Read();
- continue;
- }
- processWs = (c != '+'
- && c != '>'
- && c != ','
- && c != '~'
- && c != '^'
- && c != stopChar);
- break;
- }
- if (!processWs)
- break;
- setCurrentSelector(new Descendent(), All);
- reader.SkipWhiteSpaces();
- break;
- default:
- if (unchecked((char)p) == stopChar)
- return root;
-
- var elementName = reader.ReadIdent();
- if (elementName == null)
- return Invalid;
- setCurrentSelector(new And(), new Element(elementName));
- break;
- }
- }
- return root;
- }
-
- static void SetCurrentSelector(ref Selector root, ref Selector workingRoot, ref Operator workingRootParent, Operator op, Selector sel)
- {
- var updateRoot = root == workingRoot;
-
- op.Left = workingRoot;
- op.Right = sel;
- workingRoot = op;
- if (workingRootParent != null)
- workingRootParent.Right = workingRoot;
-
- if (updateRoot)
- root = workingRoot;
-
- if (workingRoot is Or)
- {
- workingRootParent = (Operator)workingRoot;
- workingRoot = sel;
- }
- }
-
- public abstract bool Matches(IStyleSelectable styleable);
-
- internal static Selector Invalid = new Generic(s => false);
- internal static Selector All = new Generic(s => true);
-
- abstract class UnarySelector : Selector
- {
- }
-
- abstract class Operator : Selector
- {
- public Selector Left { get; set; } = Invalid;
- public Selector Right { get; set; } = Invalid;
- }
-
- sealed class Generic : UnarySelector
- {
- readonly Func<IStyleSelectable, bool> func;
- public Generic(Func<IStyleSelectable, bool> func)
- {
- this.func = func;
- }
-
- public override bool Matches(IStyleSelectable styleable) => func(styleable);
- }
-
- sealed class Class : UnarySelector
- {
- public Class(string className)
- {
- ClassName = className;
- }
-
- public string ClassName { get; }
- public override bool Matches(IStyleSelectable styleable)
- => styleable.Classes != null && styleable.Classes.Contains(ClassName);
- }
-
- sealed class Id : UnarySelector
- {
- public Id(string id)
- {
- IdName = id;
- }
-
- public string IdName { get; }
- public override bool Matches(IStyleSelectable styleable) => styleable.Id == IdName;
- }
-
- sealed class Or : Operator
- {
- public override bool Matches(IStyleSelectable styleable) => Right.Matches(styleable) || Left.Matches(styleable);
- }
-
- sealed class And : Operator
- {
- public override bool Matches(IStyleSelectable styleable) => Right.Matches(styleable) && Left.Matches(styleable);
- }
-
- sealed class Element : UnarySelector
- {
- public Element(string elementName)
- {
- ElementName = elementName;
- }
-
- public string ElementName { get; }
- public override bool Matches(IStyleSelectable styleable) =>
- string.Equals(styleable.NameAndBases[0], ElementName, StringComparison.OrdinalIgnoreCase);
- }
-
- sealed class Base : UnarySelector
- {
- public Base(string elementName)
- {
- ElementName = elementName;
- }
-
- public string ElementName { get; }
- public override bool Matches(IStyleSelectable styleable)
- {
- for (var i = 0; i < styleable.NameAndBases.Length; i++)
- if (string.Equals(styleable.NameAndBases[i], ElementName, StringComparison.OrdinalIgnoreCase))
- return true;
- return false;
- }
- }
-
- sealed class Child : Operator
- {
- public override bool Matches(IStyleSelectable styleable) =>
- Right.Matches(styleable) && styleable.Parent != null && Left.Matches(styleable.Parent);
- }
-
- sealed class Descendent : Operator
- {
- public override bool Matches(IStyleSelectable styleable)
- {
- if (!Right.Matches(styleable))
- return false;
- var parent = styleable.Parent;
- while (parent != null)
- {
- if (Left.Matches(parent))
- return true;
- parent = parent.Parent;
- }
- return false;
- }
- }
-
- sealed class Adjacent : Operator
- {
- public override bool Matches(IStyleSelectable styleable)
- {
- if (!Right.Matches(styleable))
- return false;
- if (styleable.Parent == null)
- return false;
-
- IStyleSelectable prev = null;
- foreach (var elem in styleable.Parent.Children)
- {
- if (elem == styleable && prev != null)
- return Left.Matches(prev);
- prev = elem;
- }
- return false;
- //var index = styleable.Parent.Children.IndexOf(styleable);
- //if (index == 0)
- // return false;
- //var adjacent = styleable.Parent.Children[index - 1];
- //return Left.Matches(adjacent);
- }
- }
-
- sealed class Sibling : Operator
- {
- public override bool Matches(IStyleSelectable styleable)
- {
- if (!Right.Matches(styleable))
- return false;
- if (styleable.Parent == null)
- return false;
-
- int selfIndex = 0;
- bool foundSelfInParent = false;
- foreach (var elem in styleable.Parent.Children)
- {
- if (elem == styleable)
- {
- foundSelfInParent = true;
- break;
- }
- ++selfIndex;
- }
-
- if (!foundSelfInParent)
- return false;
-
- int index = 0;
- foreach (var elem in styleable.Parent.Children)
- {
- if (index >= selfIndex)
- return false;
- if (Left.Matches(elem))
- return true;
- ++index;
- }
-
- return false;
-
- //var index = styleable.Parent.Children.IndexOf(styleable);
- //if (index == 0)
- // return false;
- //int siblingIndex = -1;
- //for (var i = 0; i < index; i++)
- // if (Left.Matches(styleable.Parent.Children[i])) {
- // siblingIndex = i;
- // break;
- // }
- //return siblingIndex != -1;
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.StyleSheets
-{
- internal sealed class Style
- {
- Style()
- {
- }
-
- public IDictionary<string, string> Declarations { get; set; } = new Dictionary<string, string>();
- Dictionary<KeyValuePair<string, string>, object> convertedValues = new Dictionary<KeyValuePair<string, string>, object>();
-
- public static Style Parse(CssReader reader, char stopChar = '\0')
- {
- Style style = new Style();
- string propertyName = null, propertyValue = null;
-
- int p;
- reader.SkipWhiteSpaces();
- bool readingName = true;
- while ((p = reader.Peek()) > 0)
- {
- switch (unchecked((char)p))
- {
- case ':':
- reader.Read();
- readingName = false;
- reader.SkipWhiteSpaces();
- break;
- case ';':
- reader.Read();
- if (!string.IsNullOrEmpty(propertyName) && !string.IsNullOrEmpty(propertyValue))
- style.Declarations.Add(propertyName, propertyValue);
- propertyName = propertyValue = null;
- readingName = true;
- reader.SkipWhiteSpaces();
- break;
- default:
- if ((char)p == stopChar)
- return style;
-
- if (readingName)
- {
- propertyName = reader.ReadIdent();
- if (propertyName == null)
- throw new Exception();
- }
- else
- propertyValue = reader.ReadUntil(stopChar, ';', ':');
- break;
- }
- }
- return style;
- }
-
- public void Apply(/*VisualElement*/BaseHandle styleable, bool inheriting = false)
- {
- if (styleable == null)
- throw new ArgumentNullException(nameof(styleable));
-
- foreach (var decl in Declarations)
- {
- var property = ((IStylable)styleable).GetProperty(decl.Key, inheriting);
- if (property == null)
- continue;
- if (string.Equals(decl.Value, "initial", StringComparison.OrdinalIgnoreCase))
- styleable.ClearValue(property, fromStyle: true);
- else
- {
- object value;
- if (!convertedValues.TryGetValue(decl, out value))
- convertedValues[decl] = (value = Convert(styleable, decl.Value, property));
- styleable.SetValue(property, value, fromStyle: true);
- }
- }
-
- foreach (var child in styleable.LogicalChildrenInternal)
- {
- var ve = child as /*VisualElement*/BaseHandle;
- if (ve == null)
- continue;
- Apply(ve, inheriting: true);
- }
- }
-
- // [MethodImpl(MethodImplOptions.AggressiveInlining)]
- static object Convert(object target, object value, BindableProperty property)
- {
- Func<MemberInfo> minforetriever = () => property.DeclaringType.GetRuntimeProperty(property.PropertyName) as MemberInfo
- ?? property.DeclaringType.GetRuntimeMethod("Get" + property.PropertyName, new[] { typeof(BindableObject) }) as MemberInfo;
- var serviceProvider = new StyleSheetServiceProvider(target, property);
- // return value.ConvertTo(property.ReturnType, minforetriever, serviceProvider);
- // Unused parameter
- _ = value;
- return null;
- }
-
- public void UnApply(IStylable styleable)
- {
- throw new NotImplementedException();
- }
- }
-}
+++ /dev/null
-using System;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.StyleSheets
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = true)]
- internal sealed class StylePropertyAttribute : Attribute
- {
- public string CssPropertyName { get; }
- public string BindablePropertyName { get; }
- public Type TargetType { get; }
- public Type PropertyOwnerType { get; set; }
- public BindableProperty BindableProperty { get; set; }
- public bool Inherited { get; set; } = false;
-
-
- public StylePropertyAttribute(string cssPropertyName, Type targetType, string bindablePropertyName)
- {
- CssPropertyName = cssPropertyName;
- BindablePropertyName = bindablePropertyName;
- TargetType = targetType;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.IO;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Xml;
-using Tizen.NUI.Xaml;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.StyleSheets
-{
- internal sealed class StyleSheet : IStyle
- {
- StyleSheet()
- {
- }
-
- internal IDictionary<Selector, Style> Styles { get; set; } = new Dictionary<Selector, Style>();
-
- public static StyleSheet FromAssemblyResource(Assembly assembly, string resourceId, IXmlLineInfo lineInfo = null)
- {
- using (var stream = assembly.GetManifestResourceStream(resourceId))
- {
- if (stream == null)
- throw new XamlParseException($"No resource found for '{resourceId}'.", lineInfo);
- using (var reader = new StreamReader(stream))
- {
- return FromReader(reader);
- }
- }
- }
-
- //used by code generated by XamlC. Has to stay public
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static StyleSheet FromString(string stylesheet)
- {
- if (stylesheet == null)
- throw new ArgumentNullException(nameof(stylesheet));
- using (var reader = new StringReader(stylesheet))
- return FromReader(reader);
- }
-
- public static StyleSheet FromReader(TextReader reader)
- {
- if (reader == null)
- throw new ArgumentNullException(nameof(reader));
-
- return Parse(new CssReader(reader));
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- static StyleSheet Parse(CssReader reader)
- {
- var sheet = new StyleSheet();
-
- Style style = null;
- var selector = Selector.All;
-
- int p;
- bool inStyle = false;
- reader.SkipWhiteSpaces();
- while ((p = reader.Peek()) > 0)
- {
- switch ((char)p)
- {
- case '@':
- throw new NotSupportedException("AT-rules not supported");
- case '{':
- reader.Read();
- style = Style.Parse(reader, '}');
- inStyle = true;
- break;
- case '}':
- reader.Read();
- if (!inStyle)
- throw new Exception();
- inStyle = false;
- sheet.Styles.Add(selector, style);
- style = null;
- selector = Selector.All;
- break;
- default:
- selector = Selector.Parse(reader, '{');
- break;
- }
- }
- return sheet;
- }
-
- Type IStyle.TargetType
- => typeof(/*VisualElement*/BaseHandle);
-
- void IStyle.Apply(BindableObject bindable)
- {
- var styleable = bindable as Element;
- if (styleable == null)
- return;
- Apply(styleable);
- }
-
- void Apply(Element styleable)
- {
- ApplyCore(styleable);
- foreach (var child in styleable.LogicalChildrenInternal)
- ((IStyle)this).Apply(child);
- }
-
- void ApplyCore(Element styleable)
- {
- var visualStylable = styleable as /*VisualElement*/BaseHandle;
- if (visualStylable == null)
- return;
- foreach (var kvp in Styles)
- {
- var selector = kvp.Key;
- var style = kvp.Value;
- // if (!selector.Matches(styleable))
- // continue;
- style.Apply(visualStylable);
- }
- }
-
- void IStyle.UnApply(BindableObject bindable)
- {
- throw new NotImplementedException();
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System.Collections.Generic;
-using Tizen.NUI.Binding;
-
-namespace Tizen.NUI.StyleSheets
-{
- internal static class StyleSheetExtensions
- {
- public static IEnumerable<StyleSheet> GetStyleSheets(this IResourcesProvider resourcesProvider)
- {
- if (resourcesProvider == null)
- {
- yield break;
- }
- if (!resourcesProvider.IsResourcesCreated)
- {
- yield break;
- }
- if (resourcesProvider.XamlResources == null || resourcesProvider.XamlResources.StyleSheets == null)
- {
- yield break;
- }
- foreach (var styleSheet in resourcesProvider.XamlResources.StyleSheets)
- {
- yield return styleSheet;
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using Tizen.NUI.Xaml;
-
-namespace Tizen.NUI.StyleSheets
-{
- internal class StyleSheetServiceProvider : IServiceProvider
- {
- IProvideValueTarget vtProvider;
- IConverterOptions convOptions => new ConverterOptions();
-
- public StyleSheetServiceProvider(object targetObject, object targetProperty)
- {
- vtProvider = new ValueTargetProvider
- {
- TargetObject = targetObject,
- TargetProperty = targetProperty
- };
- }
-
- public object GetService(Type serviceType)
- {
- if (serviceType == typeof(IProvideValueTarget))
- return vtProvider;
- if (serviceType == typeof(IConverterOptions))
- return convOptions;
- return null;
- }
-
- class ValueTargetProvider : IProvideValueTarget
- {
- public object TargetObject { get; set; }
- public object TargetProperty { get; set; }
- }
-
- class ConverterOptions : IConverterOptions
- {
- public bool IgnoreCase => true;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-using System;
-using System.IO;
-using System.Linq;
-using System.Text;
-
-namespace Tizen.NUI.StyleSheets
-{
- internal static class TextReaderExtensions
- {
- //ident [-]?{nmstart}{nmchar}*
- public static string ReadIdent(this TextReader reader)
- {
- var sb = new StringBuilder();
- bool first = true;
- bool hasLeadingDash = false;
- int p;
- while ((p = reader.Peek()) > 0)
- {
- var c = unchecked((char)p);
- if (first && !hasLeadingDash && c == '-')
- {
- sb.Append((char)reader.Read());
- hasLeadingDash = true;
- }
- else if (first && c.IsNmStart())
- {
- sb.Append((char)reader.Read());
- first = false;
- }
- else if (first)
- { //a nmstart is expected
- throw new Exception();
- }
- else if (c.IsNmChar())
- sb.Append((char)reader.Read());
- else
- break;
- }
- return sb.ToString();
- }
-
- //name {nmchar}+
- public static string ReadName(this TextReader reader)
- {
- var sb = new StringBuilder();
- int p;
- while ((p = reader.Peek()) > 0)
- {
- var c = unchecked((char)p);
- if (c.IsNmChar())
- sb.Append((char)reader.Read());
- else
- break;
- }
- return sb.ToString();
- }
-
- public static string ReadUntil(this TextReader reader, params char[] limit)
- {
- var sb = new StringBuilder();
- int p;
- while ((p = reader.Peek()) > 0)
- {
- var c = unchecked((char)p);
- if (limit != null && limit.Contains(c))
- break;
- reader.Read();
- sb.Append(c);
- }
- return sb.ToString();
- }
-
- //w [ \t\r\n\f]*
- public static void SkipWhiteSpaces(this TextReader reader)
- {
- int p;
- while ((p = reader.Peek()) > 0)
- {
- var c = unchecked((char)p);
- if (!c.IsW())
- break;
- reader.Read();
- }
- }
- }
-}
\ No newline at end of file
}
}
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Style XamlStyle
- {
- get
- {
- return (Style)GetValue(XamlStyleProperty);
- }
- set
- {
- SetValue(XamlStyleProperty, value);
- }
- }
-
/// <summary>
/// The Color of View. This is an RGBA value.
/// </summary>
});
/// <summary>
- /// XamlStyleProperty
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static readonly BindableProperty XamlStyleProperty = BindableProperty.Create(nameof(XamlStyle), typeof(Style), typeof(View), default(Style), propertyChanged: (bindable, oldvalue, newvalue) => ((View)bindable)._mergedStyle.Style = (Style)newvalue);
-
- /// <summary>
/// EnableControlState property
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
/// <since_tizen> 3 </since_tizen>
public partial class View
{
- private MergedStyle mergedStyle = null;
private ViewSelectorData selectorData;
internal string styleName;
- internal MergedStyle _mergedStyle
- {
- get
- {
- if (null == mergedStyle)
- {
- mergedStyle = new MergedStyle(GetType(), this);
- }
-
- return mergedStyle;
- }
- }
-
/// <summary>
/// The color mode of View.
/// This specifies whether the View uses its own color, or inherits its parent color.
+++ /dev/null
-using System;
-using System.Xml;
-using Tizen.NUI.StyleSheets;
-using System.Reflection;
-using System.IO;
-using Tizen.NUI.Binding;
-using System.ComponentModel;
-
-namespace Tizen.NUI.Xaml
-{
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- [ContentProperty(nameof(Style))]
- [ProvideCompiled("Tizen.NUI.Core.XamlC.StyleSheetProvider")]
- public sealed class StyleSheetExtension : IValueProvider
- {
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public string Style { get; set; }
-
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Uri Source { get; set; }
-
- object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
- {
- IXmlLineInfo lineInfo;
-
- if (!string.IsNullOrEmpty(Style) && Source != null)
- {
- lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
- throw new XamlParseException($"StyleSheet can not have both a Source and a content", lineInfo);
- }
-
- if (Source != null)
- {
- lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
- if (Source.IsAbsoluteUri)
- throw new XamlParseException($"Source only accepts Relative URIs", lineInfo);
-
- var rootObjectType = (serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider)?.RootObject.GetType();
- if (rootObjectType == null)
- return null;
- var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType);
- var resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(Source, rootTargetPath);
- var resString = DependencyService.Get<IResourcesLoader>()?.GetResource(resourcePath, rootObjectType.GetTypeInfo().Assembly, lineInfo);
- return StyleSheet.FromString(resString);
- }
-
- if (!string.IsNullOrEmpty(Style))
- {
- using (var reader = new StringReader(Style))
- return StyleSheet.FromReader(reader);
- }
-
- lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
- throw new XamlParseException($"StyleSheet require either a Source or a content", lineInfo);
- }
- }
-}
\ No newline at end of file
object parent = parentValuesProvider.ParentObjects.Skip(1).FirstOrDefault();
if (parentValuesProvider.TargetObject is Setter)
{
- var style = parent as Style;
var triggerBase = parent as TriggerBase;
var visualState = parent as VisualState;
- if (style != null)
- type = style.TargetType;
- else if (triggerBase != null)
+ if (triggerBase != null)
type = triggerBase.TargetType;
else if (visualState != null)
type = FindTypeForVisualState(parentValuesProvider, lineinfo);
throw new XamlParseException($"Expected {nameof(Setter)} but found {parents[4]}.", lineInfo);
}
- // These must be part of a Style; verify that
- if (!(parents[5] is Style style))
- {
- throw new XamlParseException($"Expected {nameof(Style)} but found {parents[5]}.", lineInfo);
- }
+ throw new XamlParseException("NUI doesn't support VisualState", lineInfo);
- return style.TargetType;
}
}
}
}
internal static Dictionary<string, Type> Effects { get; } = new Dictionary<string, Type>();
- internal static Dictionary<string, StyleSheets.StylePropertyAttribute> StyleProperties { get; } = new Dictionary<string, StyleSheets.StylePropertyAttribute>();
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
}
}
- internal IList<StyleSheets.StyleSheet> StyleSheets { get; set; }
-
- void StyleSheetsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- switch (e.Action)
- {
- case NotifyCollectionChangedAction.Add:
- ValuesChanged?.Invoke(this, ResourcesChangedEventArgs.StyleSheets);
- break;
- }
- }
IList<ResourceDictionary> _collectionTrack;
void MergedDictionaries_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
remove { ValuesChanged -= value; }
}
- internal void Add(Style style)
- {
- if (string.IsNullOrEmpty(style.Class))
- Add(style.TargetType.FullName, style);
- else
- {
- IList<Style> classes;
- object outclasses;
- if (!TryGetValue(Style.StyleClassPrefix + style.Class, out outclasses) || (classes = outclasses as IList<Style>) == null)
- classes = new List<Style>();
- classes.Add(style);
- this[Style.StyleClassPrefix + style.Class] = classes;
- }
- }
-
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public void Add(ResourceDictionary mergedResourceDictionary)
MergedDictionaries.Add(mergedResourceDictionary);
}
- internal void Add(StyleSheets.StyleSheet styleSheet)
- {
- StyleSheets = StyleSheets ?? new List<StyleSheets.StyleSheet>(2);
- StyleSheets.Add(styleSheet);
- ValuesChanged?.Invoke(this, ResourcesChangedEventArgs.StyleSheets);
- }
-
void OnValueChanged(string key, object value)
{
OnValuesChanged(new KeyValuePair<string, object>(key, value));
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using Tizen.NUI.StyleSheets;
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- [ContentProperty("Setters")]
- public sealed class Style : IStyle
- {
- internal const string StyleClassPrefix = "Tizen.NUI.Binding.StyleClass.";
-
- readonly BindableProperty _basedOnResourceProperty = BindableProperty.CreateAttached("BasedOnResource", typeof(Style), typeof(Style), default(Style),
- propertyChanged: OnBasedOnResourceChanged);
-
- readonly List<WeakReference<BindableObject>> _targets = new List<WeakReference<BindableObject>>(4);
-
- Style _basedOnStyle;
-
- string _baseResourceKey;
-
- IList<Behavior> _behaviors;
-
- IList<TriggerBase> _triggers;
-
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Style([TypeConverter(typeof(TypeTypeConverter))][Parameter("TargetType")] Type targetType)
- {
- if (targetType == null)
- throw new ArgumentNullException(nameof(targetType));
-
- TargetType = targetType;
- Setters = new List<Setter>();
- }
-
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public bool ApplyToDerivedTypes { get; set; }
-
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Style BasedOn
- {
- get { return _basedOnStyle; }
- set
- {
- if (_basedOnStyle == value)
- return;
- if (!ValidateBasedOn(value))
- throw new ArgumentException("BasedOn.TargetType is not compatible with TargetType");
- Style oldValue = _basedOnStyle;
- _basedOnStyle = value;
- BasedOnChanged(oldValue, value);
- if (value != null)
- BaseResourceKey = null;
- }
- }
-
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public string BaseResourceKey
- {
- get { return _baseResourceKey; }
- set
- {
- if (_baseResourceKey == value)
- return;
- _baseResourceKey = value;
- //update all DynamicResources
- foreach (WeakReference<BindableObject> bindableWr in _targets)
- {
- BindableObject target;
- if (!bindableWr.TryGetTarget(out target))
- continue;
- target.RemoveDynamicResource(_basedOnResourceProperty);
- if (value != null)
- target.SetDynamicResource(_basedOnResourceProperty, value);
- }
- if (value != null)
- BasedOn = null;
- }
- }
-
- internal IList<Behavior> Behaviors
- {
- get { return _behaviors ?? (_behaviors = new AttachedCollection<Behavior>()); }
- }
-
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public bool CanCascade { get; set; }
-
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public string Class { get; set; }
-
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public IList<Setter> Setters { get; }
-
- /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public IList<TriggerBase> Triggers
- {
- get { return _triggers ?? (_triggers = new AttachedCollection<TriggerBase>()); }
- }
-
- void IStyle.Apply(BindableObject bindable)
- {
- _targets.Add(new WeakReference<BindableObject>(bindable));
- if (BaseResourceKey != null)
- bindable.SetDynamicResource(_basedOnResourceProperty, BaseResourceKey);
- ApplyCore(bindable, BasedOn ?? GetBasedOnResource(bindable));
- }
-
- /// <since_tizen> 6 </since_tizen>
- /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Type TargetType { get; }
-
- void IStyle.UnApply(BindableObject bindable)
- {
- UnApplyCore(bindable, BasedOn ?? GetBasedOnResource(bindable));
- bindable.RemoveDynamicResource(_basedOnResourceProperty);
- _targets.RemoveAll(wr =>
- {
- BindableObject target;
- return wr.TryGetTarget(out target) && target == bindable;
- });
- }
-
- internal bool CanBeAppliedTo(Type targetType)
- {
- if (TargetType == targetType)
- return true;
- if (!ApplyToDerivedTypes)
- return false;
- do
- {
- targetType = targetType.GetTypeInfo().BaseType;
- if (TargetType == targetType)
- return true;
- } while (targetType != typeof(Element));
- return false;
- }
-
- void ApplyCore(BindableObject bindable, Style basedOn)
- {
- if (basedOn != null)
- ((IStyle)basedOn).Apply(bindable);
-
- foreach (Setter setter in Setters)
- setter.Apply(bindable, true);
- ((AttachedCollection<Behavior>)Behaviors).AttachTo(bindable);
- ((AttachedCollection<TriggerBase>)Triggers).AttachTo(bindable);
- }
-
- void BasedOnChanged(Style oldValue, Style newValue)
- {
- foreach (WeakReference<BindableObject> bindableRef in _targets)
- {
- BindableObject bindable;
- if (!bindableRef.TryGetTarget(out bindable))
- continue;
-
- UnApplyCore(bindable, oldValue);
- ApplyCore(bindable, newValue);
- }
- }
-
- Style GetBasedOnResource(BindableObject bindable)
- {
- return (Style)bindable.GetValue(_basedOnResourceProperty);
- }
-
- static void OnBasedOnResourceChanged(BindableObject bindable, object oldValue, object newValue)
- {
- // Style style = (bindable as /*VisualElement*/BaseHandle).Style;
- // if (style == null)
- // return;
- // style.UnApplyCore(bindable, (Style)oldValue);
- // style.ApplyCore(bindable, (Style)newValue);
- }
-
- void UnApplyCore(BindableObject bindable, Style basedOn)
- {
- ((AttachedCollection<TriggerBase>)Triggers).DetachFrom(bindable);
- ((AttachedCollection<Behavior>)Behaviors).DetachFrom(bindable);
- foreach (Setter setter in Setters)
- setter.UnApply(bindable, true);
-
- if (basedOn != null)
- ((IStyle)basedOn).UnApply(bindable);
- }
-
- bool ValidateBasedOn(Style value)
- {
- if (value == null)
- return true;
- return value.TargetType.IsAssignableFrom(TargetType);
- }
- }
-}