summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-08-15 22:07:35 +0200
committerJason Smith <jason.smith@xamarin.com>2016-08-15 13:07:35 -0700
commit90396b0ffdecf65b8e2eea8eb4f148bdea1071c4 (patch)
treeb2a18b90525c693113b796f97c273e25d9980ddb /Xamarin.Forms.Xaml
parent775df09a3e45e90128f9047e8618461d4c4411a0 (diff)
downloadxamarin-forms-90396b0ffdecf65b8e2eea8eb4f148bdea1071c4.tar.gz
xamarin-forms-90396b0ffdecf65b8e2eea8eb4f148bdea1071c4.tar.bz2
xamarin-forms-90396b0ffdecf65b8e2eea8eb4f148bdea1071c4.zip
Refix mc ignorable (#302)
* Revert "Fix mc ignorable (#298)" This reverts commit 31c2be29d5982338ae178d1b0f107e23e7749782. * [Xaml] fix mc:Ignorable
Diffstat (limited to 'Xamarin.Forms.Xaml')
-rw-r--r--Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs13
-rw-r--r--Xamarin.Forms.Xaml/CreateValuesVisitor.cs17
-rw-r--r--Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs8
-rw-r--r--Xamarin.Forms.Xaml/PruneIgnoredNodesVisitor.cs85
-rw-r--r--Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.csproj1
-rw-r--r--Xamarin.Forms.Xaml/XamlLoader.cs1
6 files changed, 90 insertions, 35 deletions
diff --git a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
index cdcbe00d..1e332323 100644
--- a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
+++ b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
@@ -9,7 +9,7 @@ using Xamarin.Forms.Xaml.Internals;
namespace Xamarin.Forms.Xaml
{
- class ApplyPropertiesVisitor : IXamlNodeVisitor
+ internal class ApplyPropertiesVisitor : IXamlNodeVisitor
{
public static readonly IList<XmlName> Skips = new List<XmlName>
{
@@ -58,15 +58,9 @@ namespace Xamarin.Forms.Xaml
return;
if (parentElement.SkipProperties.Contains(propertyName))
return;
- if (parentElement.SkipPrefix(node.NamespaceResolver.LookupPrefix(propertyName.NamespaceURI)))
- return;
if (propertyName.NamespaceURI == "http://schemas.openxmlformats.org/markup-compatibility/2006" &&
- propertyName.LocalName == "Ignorable")
- {
- (parentNode.IgnorablePrefixes ?? (parentNode.IgnorablePrefixes = new List<string>())).AddRange(
- (value as string).Split(','));
+ propertyName.LocalName == "Ignorable")
return;
- }
SetPropertyValue(source, propertyName, value, Context.RootElement, node, Context, node);
}
else if (IsCollectionItem(node, parentNode) && parentNode is IElementNode)
@@ -91,9 +85,6 @@ namespace Xamarin.Forms.Xaml
public void Visit(ElementNode node, INode parentNode)
{
- if (node.SkipPrefix(node.NamespaceResolver.LookupPrefix(node.NamespaceURI)))
- return;
-
var value = Values[node];
var parentElement = parentNode as IElementNode;
var markupExtension = value as IMarkupExtension;
diff --git a/Xamarin.Forms.Xaml/CreateValuesVisitor.cs b/Xamarin.Forms.Xaml/CreateValuesVisitor.cs
index 014d82c2..d6848033 100644
--- a/Xamarin.Forms.Xaml/CreateValuesVisitor.cs
+++ b/Xamarin.Forms.Xaml/CreateValuesVisitor.cs
@@ -41,17 +41,6 @@ namespace Xamarin.Forms.Xaml
public void Visit(ValueNode node, INode parentNode)
{
Values[node] = node.Value;
-
- XmlName propertyName;
- if (ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out propertyName))
- {
- if (propertyName.NamespaceURI == "http://schemas.openxmlformats.org/markup-compatibility/2006" &&
- propertyName.LocalName == "Ignorable")
- {
- (parentNode.IgnorablePrefixes ?? (parentNode.IgnorablePrefixes = new List<string>())).AddRange(
- (node.Value as string).Split(','));
- }
- }
}
public void Visit(MarkupNode node, INode parentNode)
@@ -62,12 +51,6 @@ namespace Xamarin.Forms.Xaml
{
object value = null;
- if (node.SkipPrefix(node.NamespaceResolver.LookupPrefix(node.NamespaceURI))) {
- node.Properties.Clear();
- node.CollectionItems.Clear();
- return;
- }
-
XamlParseException xpe;
var type = XamlParser.GetElementType(node.XmlType, node, Context.RootElement?.GetType().GetTypeInfo().Assembly,
out xpe);
diff --git a/Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs b/Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs
index c140084a..a3f12109 100644
--- a/Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs
+++ b/Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs
@@ -48,11 +48,8 @@ namespace Xamarin.Forms.Xaml
if (parentElement.SkipPrefix(node.NamespaceResolver.LookupPrefix(propertyName.NamespaceURI)))
return;
if (propertyName.NamespaceURI == "http://schemas.openxmlformats.org/markup-compatibility/2006" &&
- propertyName.LocalName == "Ignorable") {
- (parentNode.IgnorablePrefixes ?? (parentNode.IgnorablePrefixes = new List<string> ())).AddRange (
- (value as string).Split (','));
+ propertyName.LocalName == "Ignorable")
return;
- }
if (propertyName.LocalName != "MergedWith")
return;
ApplyPropertiesVisitor.SetPropertyValue(source, propertyName, value, Context.RootElement, node, Context, node);
@@ -66,9 +63,6 @@ namespace Xamarin.Forms.Xaml
public void Visit(ElementNode node, INode parentNode)
{
- if (node.SkipPrefix(node.NamespaceResolver.LookupPrefix(node.NamespaceURI)))
- return;
-
var value = Values[node];
var parentElement = parentNode as IElementNode;
var markupExtension = value as IMarkupExtension;
diff --git a/Xamarin.Forms.Xaml/PruneIgnoredNodesVisitor.cs b/Xamarin.Forms.Xaml/PruneIgnoredNodesVisitor.cs
new file mode 100644
index 00000000..95ddb20f
--- /dev/null
+++ b/Xamarin.Forms.Xaml/PruneIgnoredNodesVisitor.cs
@@ -0,0 +1,85 @@
+´╗┐using System.Collections.Generic;
+using System.Linq;
+
+namespace Xamarin.Forms.Xaml
+{
+ class PruneIgnoredNodesVisitor : IXamlNodeVisitor
+ {
+ public bool StopOnDataTemplate {
+ get { return false; }
+ }
+
+ public bool StopOnResourceDictionary {
+ get { return false; }
+ }
+
+ public bool VisitChildrenFirst {
+ get { return false; }
+ }
+
+ public void Visit(ElementNode node, INode parentNode)
+ {
+ foreach (var propertyKvp in node.Properties)
+ {
+ var propertyName = propertyKvp.Key;
+ var propertyValue = (propertyKvp.Value as ValueNode)?.Value as string;
+ if (propertyValue == null)
+ continue;
+ if (propertyName.NamespaceURI != "http://schemas.openxmlformats.org/markup-compatibility/2006" ||
+ propertyName.LocalName != "Ignorable")
+ continue;
+ (parentNode.IgnorablePrefixes ?? (parentNode.IgnorablePrefixes = new List<string>())).AddRange(propertyValue.Split(','));
+ }
+
+ foreach (var propertyKvp in node.Properties.ToList())
+ {
+ // skip d:foo="bar"
+ var prefix = node.NamespaceResolver.LookupPrefix(propertyKvp.Key.NamespaceURI);
+ if (node.SkipPrefix(prefix))
+ node.Properties.Remove(propertyKvp.Key);
+ var propNs = (propertyKvp.Value as IElementNode)?.NamespaceURI ?? "";
+ var propPrefix = node.NamespaceResolver.LookupPrefix(propNs);
+ if (node.SkipPrefix(propPrefix))
+ node.Properties.Remove(propertyKvp.Key);
+ }
+
+ foreach (var prop in node.CollectionItems.ToList())
+ {
+ var propNs = (prop as IElementNode)?.NamespaceURI ?? "";
+ var propPrefix = node.NamespaceResolver.LookupPrefix(propNs);
+ if (node.SkipPrefix(propPrefix))
+ node.CollectionItems.Remove(prop);
+ }
+
+ if (node.SkipPrefix(node.NamespaceResolver.LookupPrefix(node.NamespaceURI)))
+ {
+ node.Properties.Clear();
+ node.CollectionItems.Clear();
+ }
+ }
+
+ public void Visit(RootNode node, INode parentNode)
+ {
+ Visit((ElementNode)node, node);
+ }
+
+ public void Visit(MarkupNode node, INode parentNode)
+ {
+ }
+
+ public void Visit(ListNode node, INode parentNode)
+ {
+ foreach (var prop in node.CollectionItems.ToList())
+ {
+ var propNs = (prop as IElementNode)?.NamespaceURI ?? "";
+ var propPrefix = node.NamespaceResolver.LookupPrefix(propNs);
+ if (node.SkipPrefix(propPrefix))
+ node.CollectionItems.Remove(prop);
+ }
+ }
+
+ public void Visit(ValueNode node, INode parentNode)
+ {
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.csproj b/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.csproj
index cb4577c9..f521d362 100644
--- a/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.csproj
+++ b/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.csproj
@@ -81,6 +81,7 @@
<Compile Include="ExpandMarkupsVisitor.cs" />
<Compile Include="XamlCompilationAttribute.cs" />
<Compile Include="TypeArgumentsParser.cs" />
+ <Compile Include="PruneIgnoredNodesVisitor.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>
diff --git a/Xamarin.Forms.Xaml/XamlLoader.cs b/Xamarin.Forms.Xaml/XamlLoader.cs
index 40414092..dcab4e94 100644
--- a/Xamarin.Forms.Xaml/XamlLoader.cs
+++ b/Xamarin.Forms.Xaml/XamlLoader.cs
@@ -117,6 +117,7 @@ namespace Xamarin.Forms.Xaml
{
rootnode.Accept (new XamlNodeVisitor ((node, parent) => node.Parent = parent), null); //set parents for {StaticResource}
rootnode.Accept (new ExpandMarkupsVisitor (visitorContext), null);
+ rootnode.Accept (new PruneIgnoredNodesVisitor(), null);
rootnode.Accept (new NamescopingVisitor (visitorContext), null); //set namescopes for {x:Reference}
rootnode.Accept (new CreateValuesVisitor (visitorContext), null);
rootnode.Accept (new RegisterXNamesVisitor (visitorContext), null);