* Revert "Fix mc ignorable (#298)"

This reverts commit 31c2be29d5.

* [Xaml] fix mc:Ignorable
This commit is contained in:
Stephane Delcroix 2016-08-15 22:07:35 +02:00 коммит произвёл Jason Smith
Родитель 775df09a3e
Коммит 90396b0ffd
13 изменённых файлов: 95 добавлений и 72 удалений

Просмотреть файл

@ -39,17 +39,6 @@ namespace Xamarin.Forms.Build.Tasks
public void Visit(ValueNode node, INode parentNode)
{
Context.Values[node] = node.Value;
XmlName propertyName;
if (SetPropertiesVisitor.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)
@ -59,12 +48,6 @@ namespace Xamarin.Forms.Build.Tasks
public void Visit(ElementNode node, INode parentNode)
{
if (node.SkipPrefix((node.NamespaceResolver ?? parentNode.NamespaceResolver).LookupPrefix(node.NamespaceURI))) {
node.Properties.Clear();
node.CollectionItems.Clear();
return;
}
var typeref = node.XmlType.GetTypeReference(Module, node);
TypeDefinition typedef = typeref.Resolve();

Просмотреть файл

@ -1,3 +1,4 @@
using System.Xml;
using Mono.Cecil;
using Xamarin.Forms.Xaml;
@ -5,7 +6,7 @@ namespace Xamarin.Forms.Build.Tasks
{
class ILRootNode : RootNode
{
public ILRootNode(XmlType xmlType, TypeReference typeReference) : base(xmlType, null)
public ILRootNode(XmlType xmlType, TypeReference typeReference, IXmlNamespaceResolver nsResolver) : base(xmlType, nsResolver)
{
TypeReference = typeReference;
}

Просмотреть файл

@ -43,9 +43,6 @@ namespace Xamarin.Forms.Build.Tasks
public void Visit(ElementNode node, INode parentNode)
{
if (node.SkipPrefix((node.NamespaceResolver ?? parentNode.NamespaceResolver).LookupPrefix(node.NamespaceURI)))
return;
VariableDefinition ns;
if (parentNode == null || IsDataTemplate(node, parentNode) || IsStyle(node, parentNode))
ns = CreateNamescope();

Просмотреть файл

@ -67,15 +67,9 @@ namespace Xamarin.Forms.Build.Tasks
if (skips.Contains(propertyName))
return;
if (node.SkipPrefix((node.NamespaceResolver ?? parentNode.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(
(node.Value as string).Split(','));
return;
}
SetPropertyValue(Context.Variables[(IElementNode)parentNode], propertyName, node, Context, node);
}
@ -85,9 +79,6 @@ namespace Xamarin.Forms.Build.Tasks
public void Visit(ElementNode node, INode parentNode)
{
if (node.SkipPrefix((node.NamespaceResolver ?? parentNode.NamespaceResolver)?.LookupPrefix(node.NamespaceURI)))
return;
//if this node is an IMarkupExtension, invoke ProvideValue() and replace the variable
var vardef = Context.Variables[node];
var vardefref = new VariableDefinitionReference(vardef);

Просмотреть файл

@ -52,15 +52,9 @@ namespace Xamarin.Forms.Build.Tasks
return;
}
if (node.SkipPrefix((node.NamespaceResolver ?? parentNode.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(
(node.Value as string).Split(','));
return;
}
if (propertyName.LocalName != "MergedWith")
return;
SetPropertiesVisitor.SetPropertyValue(Context.Variables[(IElementNode)parentNode], propertyName, node, Context, node);

Просмотреть файл

@ -300,6 +300,7 @@ namespace Xamarin.Forms.Build.Tasks
rootnode.Accept(new XamlNodeVisitor((node, parent) => node.Parent = parent), null);
rootnode.Accept(new ExpandMarkupsVisitor(visitorContext), null);
rootnode.Accept(new PruneIgnoredNodesVisitor(), null);
rootnode.Accept(new CreateObjectVisitor(visitorContext), null);
rootnode.Accept(new SetNamescopesAndRegisterNamesVisitor(visitorContext), null);
rootnode.Accept(new SetFieldVisitor(visitorContext), null);
@ -427,7 +428,7 @@ namespace Xamarin.Forms.Build.Tasks
}
XamlParser.ParseXaml(
rootnode = new ILRootNode(new XmlType(reader.NamespaceURI, reader.Name, null), typeReference), reader);
rootnode = new ILRootNode(new XmlType(reader.NamespaceURI, reader.Name, null), typeReference, reader as IXmlNamespaceResolver), reader);
break;
}
}

Просмотреть файл

@ -12,6 +12,7 @@
</ContentPage.BindingContext>
<StackLayout x:Name="stack">
<d:FakeControlWithContent>
<d:Invalid />
<Button />
</d:FakeControlWithContent>
</StackLayout>

Просмотреть файл

@ -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(','));
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;

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;

Просмотреть файл

@ -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)
{
}
}
}

Просмотреть файл

@ -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>

Просмотреть файл

@ -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);