Author: mhabersack
Date: 2007-06-08 19:51:23 -0400 (Fri, 08 Jun 2007)
New Revision: 79021

Modified:
   trunk/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs
   trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog
   trunk/mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs
   trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI/Control.cs
   trunk/mcs/class/System.Web/System.Web.UI/TemplateControl.cs
   trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog
   trunk/mcs/class/System.Web/Test/System.Web.UI/ControlTest.cs
Log:
2007-06-09  Marek Habersack  <[EMAIL PROTECTED]>

        * TemplateControlCompiler.cs: TemplateControl is assigned for
        controls that are placed within ContentPlaceHolder and not for the
        ContentPlaceHolder itself.
        No longer add the overriden version of TemplateSourceDirectory to
        the generated source, all the work is now done in
        Control.TemplateSourceDirectory.

        * BaseCompiler.cs: AppRelativeVirtualPath shouldn't end with a
        slash, for compatibility with MS.NET

2007-06-09  Marek Habersack  <[EMAIL PROTECTED]>

        * TemplateControl.cs: make sure TemplateControl is set to the
        current control.

        * Control.cs: TemplateControl property goes up the parent chain if
        the property isn't defined in the current control.
        TemplateSourceDir finally implemented correctly.

2007-06-09  Marek Habersack  <[EMAIL PROTECTED]>

        * ControlTest.cs: enabled two tests that hadn't been working
        before.



Modified: trunk/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs   
2007-06-08 23:22:23 UTC (rev 79020)
+++ trunk/mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs   
2007-06-08 23:51:23 UTC (rev 79021)
@@ -212,16 +212,16 @@
                                return;
                        if (!baseType.IsSubclassOf (typeof 
(System.Web.UI.TemplateControl)))
                                return;
-                       
+
                        string arvp = Path.Combine (parser.BaseVirtualDir, 
Path.GetFileName (parser.InputFile));
                        if (VirtualPathUtility.IsAbsolute (arvp))
                                arvp = "~" + arvp;
-                       
+
                        CodeExpression cast = new CodeCastExpression (baseType, 
new CodeThisReferenceExpression ());
                        CodePropertyReferenceExpression arvpProp = new 
CodePropertyReferenceExpression (cast, "AppRelativeVirtualPath");
                        CodeAssignStatement arvpAssign = new 
CodeAssignStatement ();
                        arvpAssign.Left = arvpProp;
-                       arvpAssign.Right = new CodePrimitiveExpression (arvp);
+                       arvpAssign.Right = new CodePrimitiveExpression 
(VirtualPathUtility.RemoveTrailingSlash (arvp));
                        ctor.Statements.Add (arvpAssign);
                }
 #endif

Modified: trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog 2007-06-08 
23:22:23 UTC (rev 79020)
+++ trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog 2007-06-08 
23:51:23 UTC (rev 79021)
@@ -1,3 +1,15 @@
+2007-06-09  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * TemplateControlCompiler.cs: TemplateControl is assigned for
+       controls that are placed within ContentPlaceHolder and not for the
+       ContentPlaceHolder itself.
+       No longer add the overriden version of TemplateSourceDirectory to
+       the generated source, all the work is now done in
+       Control.TemplateSourceDirectory.
+
+       * BaseCompiler.cs: AppRelativeVirtualPath shouldn't end with a
+       slash, for compatibility with MS.NET
+
 2007-06-05  Marek Habersack  <[EMAIL PROTECTED]>
 
        * TemplateControlCompiler.cs: TemplateSourceDirectory in the 2.0

Modified: 
trunk/mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs
===================================================================
--- 
trunk/mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs    
    2007-06-08 23:22:23 UTC (rev 79020)
+++ 
trunk/mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs    
    2007-06-08 23:51:23 UTC (rev 79021)
@@ -248,6 +248,15 @@
                                }
 
 #if NET_2_0
+                               if (builder.ParentTemplateBuilder is 
System.Web.UI.WebControls.ContentBuilderInternal) {
+                                       // __ctrl.TemplateControl = this;
+                                       assign = new CodeAssignStatement ();
+                                       assign.Left = new 
CodePropertyReferenceExpression (ctrlVar, "TemplateControl");;
+                                       assign.Right = thisRef;
+                                       
+                                       method.Statements.Add (assign);
+                               }
+                               
                                // _ctrl.SkinID = $value
                                // _ctrl.ApplyStyleSheetSkin (this);
                                //
@@ -338,13 +347,6 @@
 
                                        // this is the bit that causes the 
following stuff to end up in the else { }
                                        builder.methodStatements = 
condStatement.FalseStatements;
-
-                                       // __ctrl.TemplateControl = this;
-                                       assign = new CodeAssignStatement ();
-                                       assign.Left = new 
CodePropertyReferenceExpression (ctrlVar, "TemplateControl");;
-                                       assign.Right = thisRef;
-
-                                       method.Statements.Add (assign);
                                }
 #endif
                        }
@@ -1440,60 +1442,8 @@
                        }
 
                        CreateApplicationInstance ();
-                       CreateTemplateSourceDirectory ();
                }
-
-               void CreateTemplateSourceDirectory ()
-               {
-                       CodeMemberProperty prop = new CodeMemberProperty ();
-                       prop.Type = new CodeTypeReference (typeof (string));
-                       prop.Name = "TemplateSourceDirectory";
-                       prop.Attributes = MemberAttributes.Public | 
MemberAttributes.Override;
-
-#if NET_2_0
-                       if (!(parser is MasterPageParser)) {
-#endif
-                               // if ((this.TemplateControl != null))
-                               //   return 
this.TemplateControl.TemplateSourceDirectory;
-                               CodeFieldReferenceExpression parentField = new 
CodeFieldReferenceExpression ();
-                               parentField.TargetObject = thisRef;
-#if NET_2_0
-                               parentField.FieldName = "TemplateControl";
-#else
-                               parentField.FieldName = "Parent";
-#endif
-                               CodeFieldReferenceExpression tsdField = new 
CodeFieldReferenceExpression ();
-                               tsdField.TargetObject = parentField;
-                               tsdField.FieldName = "TemplateSourceDirectory";
-
-                               CodeMethodReturnStatement parentRet = new 
CodeMethodReturnStatement (tsdField);
-                               CodeConditionStatement condStatement = new 
CodeConditionStatement (
-                                       new CodeBinaryOperatorExpression 
(parentField,
-                                                                         
CodeBinaryOperatorType.IdentityInequality,
-                                                                         new 
CodePrimitiveExpression (null)),
-                                       parentRet);
-                       
-                               prop.GetStatements.Add (condStatement);
-#if NET_2_0
-                       }
-#endif
-
-                       string tsd, bvd = parser.BaseVirtualDir;
-                       int len = bvd.Length;
-                       if (len >= 2 && bvd [0] == '~') {
-                               if (bvd [1] == '/')
-                                   tsd = bvd.Substring (1);
-                               else
-                                   tsd = '/' + bvd.Substring (1);
-                       } else if (len >= 1 && bvd [0] != '/')
-                               tsd = '/' + bvd;
-                       else
-                               tsd = bvd;
-                       CodePrimitiveExpression expr = new 
CodePrimitiveExpression (tsd);
-                       prop.GetStatements.Add (new CodeMethodReturnStatement 
(expr));
-                       mainClass.Members.Add (prop);
-               }
-
+               
                void CreateApplicationInstance ()
                {
                        CodeMemberProperty prop = new CodeMemberProperty ();
@@ -1700,7 +1650,7 @@
 
                                return new CodeCastExpression (tref, invoke);
                        }
-                       
+
                        Console.WriteLine ("Unknown type: " + type + " value: " 
+ str);
 
                        return new CodePrimitiveExpression (str);

Modified: trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/ChangeLog  2007-06-08 23:22:23 UTC 
(rev 79020)
+++ trunk/mcs/class/System.Web/System.Web.UI/ChangeLog  2007-06-08 23:51:23 UTC 
(rev 79021)
@@ -1,3 +1,12 @@
+2007-06-09  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * TemplateControl.cs: make sure TemplateControl is set to the
+       current control.
+
+       * Control.cs: TemplateControl property goes up the parent chain if
+       the property isn't defined in the current control.
+       TemplateSourceDir finally implemented correctly.
+
 2007-06-06  Marek Habersack  <[EMAIL PROTECTED]>
 
        * Control.cs: more changes to the way TemplateSourceDirectory

Modified: trunk/mcs/class/System.Web/System.Web.UI/Control.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/Control.cs 2007-06-08 23:22:23 UTC 
(rev 79020)
+++ trunk/mcs/class/System.Web/System.Web.UI/Control.cs 2007-06-08 23:51:23 UTC 
(rev 79021)
@@ -109,6 +109,7 @@
 #if NET_2_0
                TemplateControl _templateControl;
                bool _isChildControlStateCleared;
+               string _templateSourceDirectory;
 #endif
                /*************/
                int stateMask;
@@ -384,7 +385,13 @@
                [Browsable (false)]
                [DesignerSerializationVisibility 
(DesignerSerializationVisibility.Hidden)]
                public TemplateControl TemplateControl {
-                       get { return _templateControl; }
+                       get {
+                               if (_templateControl != null)
+                                       return _templateControl;
+                               if (_parent != null)
+                                       return _parent.TemplateControl;
+                               return null;
+                       }
                        
                        [EditorBrowsable (EditorBrowsableState.Never)]
                        set { _templateControl = value; }
@@ -398,16 +405,39 @@
                 public virtual string TemplateSourceDirectory {
                        get {
 #if NET_2_0
-                               if (_templateControl != null)
-                                       return 
_templateControl.TemplateSourceDirectory;
+                               if (_templateSourceDirectory == null) {
+                                       TemplateControl tc = TemplateControl;
 
-                               // Arguably, a hack, but this is the easiest 
way of doing it. We must be sure that controls placed
-                               // in an .ascx file get their source directory 
right, or otherwise ResolveClientUrl will return
-                               // invalid paths in such situations.
-                               return (_parent == null || !(_parent is 
UserControl)) ? String.Empty : _parent.TemplateSourceDirectory;
-#else
+                                       if (tc == null) {
+                                               HttpContext ctx = Context;
+                                               if (ctx != null)
+                                                       
_templateSourceDirectory = VirtualPathUtility.GetDirectory 
(ctx.Request.CurrentExecutionFilePath);
+                                       } else if (tc != this)
+                                               _templateSourceDirectory = 
tc.TemplateSourceDirectory;
+                                       
+                                       if (_templateSourceDirectory == null && 
this is TemplateControl) {
+                                               string path = 
((TemplateControl)this).AppRelativeVirtualPath;
+                                               
+                                               if (path != null) {
+                                                       // Pretend our 
application virtual root is "/" even if it isn't - we just
+                                                       // want to get an 
absolute url out of relative one, without the real
+                                                       // application root 
prepended to it.
+                                                       string ret = 
VirtualPathUtility.GetDirectory (VirtualPathUtility.ToAbsolute (path, "/"));
+                                                       int len = ret.Length;
+                                                       if (len <= 1)
+                                                               return ret;
+                                                       if (ret [--len] == '/')
+                                                               
_templateSourceDirectory = ret.Substring (0, len);
+                                               } else
+                                                       
_templateSourceDirectory = String.Empty;
+                                       }
+                                       if (_templateSourceDirectory == null)
+                                               _templateSourceDirectory = 
String.Empty;
+                               }
+                               
+                               return _templateSourceDirectory;
+#endif
                                return (_parent == null) ? String.Empty : 
_parent.TemplateSourceDirectory;
-#endif
                        }
                 }
 #endif
@@ -1258,13 +1288,13 @@
                        HttpContext context = Context;
                        if (context != null && context.Request != null) {
                                string basePath = 
context.Request.CurrentExecutionFilePath;
-                               if (basePath.Length > 1 && basePath 
[basePath.Length - 1] != '/') {
+
+                               if (basePath.Length > 1 && basePath 
[basePath.Length - 1] != '/')
                                        basePath = 
VirtualPathUtility.GetDirectory (basePath);
-                               }
                                
                                
if(VirtualPathUtility.IsAppRelative(relativeUrl))
                                        return VirtualPathUtility.MakeRelative 
(basePath, relativeUrl);
-
+                               
                                string templateSourceDirectory = 
TemplateSourceDirectory;
                                if (templateSourceDirectory == null || 
templateSourceDirectory.Length == 0)
                                        return relativeUrl;
@@ -1273,7 +1303,7 @@
                                
                                if (basePath.Length == templatePath.Length && 
String.CompareOrdinal (basePath, templatePath) == 0)
                                        return relativeUrl;
-
+                               
                                relativeUrl = VirtualPathUtility.Combine 
(templatePath, relativeUrl);
                                return VirtualPathUtility.MakeRelative 
(basePath, relativeUrl);
                        }

Modified: trunk/mcs/class/System.Web/System.Web.UI/TemplateControl.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/TemplateControl.cs 2007-06-08 
23:22:23 UTC (rev 79020)
+++ trunk/mcs/class/System.Web/System.Web.UI/TemplateControl.cs 2007-06-08 
23:51:23 UTC (rev 79021)
@@ -80,6 +80,9 @@
                #region Constructor
                protected TemplateControl ()
                {
+#if NET_2_0
+                       TemplateControl = this;
+#endif
                        Construct ();
                }
 

Modified: trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog     2007-06-08 
23:22:23 UTC (rev 79020)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI/ChangeLog     2007-06-08 
23:51:23 UTC (rev 79021)
@@ -1,3 +1,8 @@
+2007-06-09  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * ControlTest.cs: enabled two tests that hadn't been working
+       before.
+
 2007-05-21 Igor Zelmanovich <[EMAIL PROTECTED]>
 
        * ControlTest.cs: added new tests.

Modified: trunk/mcs/class/System.Web/Test/System.Web.UI/ControlTest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI/ControlTest.cs        
2007-06-08 23:22:23 UTC (rev 79020)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI/ControlTest.cs        
2007-06-08 23:51:23 UTC (rev 79021)
@@ -336,7 +336,6 @@
                }
 
                [Test]
-                       [Category("NotWorking")]  //EnsureID is not implemented.
                public void EnsureID ()
                {
                        MyNC ctrl = new MyNC ();
@@ -652,9 +651,6 @@
                
                [Test]
                [Category ("NunitWeb")]
-#if !TARGET_JVM
-               [Category ("NotWorking")] // TemplateSourceDirectory does't 
work properly
-#endif
                public void ResolveClientUrl2 ()
                {
                        WebTest t = new WebTest ("ResolveUrl.aspx");

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to