2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections;
22 using Tizen.NUI.EXaml;
24 using Tizen.NUI.Xaml.Build.Tasks;
26 namespace Tizen.NUI.EXaml.Build.Tasks
28 class EXamlSetResourcesVisitor : IXamlNodeVisitor
30 public EXamlSetResourcesVisitor(EXamlContext context)
33 Module = context.Module;
36 public EXamlContext Context { get; }
37 ModuleDefinition Module { get; }
38 public TreeVisitingMode VisitingMode => TreeVisitingMode.TopDown;
39 public bool StopOnDataTemplate => true;
40 public bool StopOnResourceDictionary => false;
41 public bool VisitNodeOnDataTemplate => false;
43 public void Visit(ValueNode node, INode parentNode)
45 if (!IsResourceDictionary((IElementNode)parentNode))
48 node.Accept(new EXamlSetPropertiesVisitor(Context, stopOnResourceDictionary: false), parentNode);
51 public void Visit(MarkupNode node, INode parentNode)
56 public void Visit(ElementNode node, INode parentNode)
59 //Set ResourcesDictionaries to their parents
60 if (IsResourceDictionary(node) && EXamlSetPropertiesVisitor.TryGetPropertyName(node, parentNode, out propertyName))
62 string realPropertyName;
63 if (propertyName.LocalName.EndsWith(".XamlResources", StringComparison.Ordinal))
65 realPropertyName = propertyName.LocalName.Substring(propertyName.LocalName.Length - ".XamlResources".Length);
69 realPropertyName = propertyName.LocalName;
72 if (realPropertyName == "XamlResources")
74 new EXamlSetProperty(Context, Context.Values[parentNode] as EXamlCreateObject, realPropertyName, Context.Values[node]);
75 //Context.IL.Append(SetPropertiesVisitor.SetPropertyValue(Context.Variables[(IElementNode)parentNode], propertyName, node, Context, node));
80 //Only proceed further if the node is a keyless RD
81 if ( parentNode is IElementNode
82 && IsResourceDictionary((IElementNode)parentNode)
83 && !((IElementNode)parentNode).Properties.ContainsKey(XmlName.xKey))
84 node.Accept(new EXamlSetPropertiesVisitor(Context, stopOnResourceDictionary: false), parentNode);
85 else if ( parentNode is ListNode
86 && IsResourceDictionary((IElementNode)parentNode.Parent)
87 && !((IElementNode)parentNode.Parent).Properties.ContainsKey(XmlName.xKey))
88 node.Accept(new EXamlSetPropertiesVisitor(Context, stopOnResourceDictionary: false), parentNode);
91 public void Visit(RootNode node, INode parentNode)
95 public void Visit(ListNode node, INode parentNode)
99 public bool IsResourceDictionary(ElementNode node) => IsResourceDictionary((IElementNode)node);
101 bool IsResourceDictionary(IElementNode node)
103 var instance = Context.Values[node] as EXamlCreateObject;
105 if (null != instance)
107 return instance.Type.InheritsFromOrImplements("Tizen.NUI.Binding.ResourceDictionary");
115 public bool SkipChildren(INode node, INode parentNode)
117 var enode = node as ElementNode;
120 if ( parentNode is IElementNode
121 && IsResourceDictionary((IElementNode)parentNode)
122 && !((IElementNode)parentNode).Properties.ContainsKey(XmlName.xKey))
124 if ( parentNode is ListNode
125 && IsResourceDictionary((IElementNode)parentNode.Parent)
126 && !((IElementNode)parentNode.Parent).Properties.ContainsKey(XmlName.xKey))