New test.
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlForm.cs
index 0463a115ae4c821182c2dbc37a166352bd1afd88..7d6c753ccffe4b23e4e3987c70f98f75a13942d2 100644 (file)
 
 using System.ComponentModel;
 using System.Collections.Specialized;
+using System.Security.Permissions;
+using System.Web.Util;
+using System.Web.UI.WebControls;
 
 namespace System.Web.UI.HtmlControls 
 {
+       // CAS
+       [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class HtmlForm : HtmlContainerControl 
        {
+               bool inited;
+
                public HtmlForm () : base ("form")
                {
                }
 
 #if NET_2_0
+               string defaultbutton = "";
                [DefaultValue ("")]
-               [MonoTODO]
                public string DefaultButton
                {
                        get {
-                               throw new NotImplementedException ();
+                               return defaultbutton;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               defaultbutton = (value == null ? "" : value);
                        }
                }
 
+               string defaultfocus = "";
                [DefaultValue ("")]
-               [MonoTODO]
                public string DefaultFocus
                {
                        get {
-                               throw new NotImplementedException ();
+                               return defaultfocus;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               defaultfocus = (value == null ? "" : value);
                        }
                }
 #endif         
@@ -92,7 +100,7 @@ namespace System.Web.UI.HtmlControls
                        get {
                                string method = Attributes["method"];
 
-                               if (method == null) {
+                               if ((method == null) || (method.Length == 0)) {
                                        return ("post");
                                }
                                
@@ -109,41 +117,26 @@ namespace System.Web.UI.HtmlControls
 
                [DefaultValue ("")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-#if NET_2_0
-               public virtual
-#else          
-               public
-#endif         
-               string Name 
+               public virtual string Name 
                {
                        get {
-                               string name = Attributes["name"];
-
-                               if (name == null) {
-                                       return (UniqueID);
-                               }
-                               
-                               return (name);
+                               return UniqueID;
                        }
                        set {
-                               if (value == null) {
-                                       Attributes.Remove ("name");
-                               } else {
-                                       Attributes["name"] = value;
-                               }
+                               /* why am i here? I do nothing. */
                        }
                }
 
 #if NET_2_0
+               bool submitdisabledcontrols = false;
                [DefaultValue (false)]
-               [MonoTODO]
                public virtual bool SubmitDisabledControls 
                {
                        get {
-                               throw new NotImplementedException ();
+                               return submitdisabledcontrols;
                        }
                        set {
-                               throw new NotImplementedException ();
+                               submitdisabledcontrols = value;
                        }
                }
 #endif
@@ -170,21 +163,14 @@ namespace System.Web.UI.HtmlControls
                        }
                }
 
-#if NET_2_0
-               public override
-#else          
-               // New in NET1.1 sp1
-               public new
-#endif         
-               string UniqueID
-               {
+               public override string UniqueID {
                        get {
                                return base.UniqueID;
                        }
                }
 
 #if NET_2_0            
-               [MonoTODO]
+               [MonoTODO ("why override?")]
                protected override ControlCollection CreateControlCollection ()
                {
                        return base.CreateControlCollection ();
@@ -198,13 +184,45 @@ namespace System.Web.UI.HtmlControls
 #endif         
                override void OnInit (EventArgs e)
                {
+                       inited = true;
                        Page.RegisterViewStateHandler ();
 
+#if NET_2_0
+                       Page.RegisterForm (this);
+#endif
+
                        base.OnInit (e);
                }
 
 #if NET_2_0
-               [MonoTODO("Probably something about validators here")]
+               internal bool DetermineRenderUplevel ()
+               {
+                       /* this bit is c&p'ed from BaseValidator.DetermineRenderUplevel */
+                       try {
+                               if (Page != null && Page.Request != null)
+                                       return (
+                                               /* From someplace on the web: "JavaScript 1.2
+                                                * and later (also known as ECMAScript) has
+                                                * built-in support for regular
+                                                * expressions" */
+                                               ((Page.Request.Browser.EcmaScriptVersion.Major == 1
+                                                 && Page.Request.Browser.EcmaScriptVersion.Minor >= 2)
+                                                || (Page.Request.Browser.EcmaScriptVersion.Major > 1))
+
+                                               /* document.getElementById, .getAttribute,
+                                                * etc, are all DOM level 1.  I don't think we
+                                                * use anything in level 2.. */
+                                               && Page.Request.Browser.W3CDomVersion.Major >= 1);
+                       }
+                       catch {
+                               /* this can happen with a fake Page in nunit
+                                * tests, since Page.Context == null */
+                               ;
+                       }
+
+                       return false;
+               }
+
                protected internal override void OnPreRender (EventArgs e)
                {
                        base.OnPreRender(e);
@@ -217,13 +235,24 @@ namespace System.Web.UI.HtmlControls
                         * and id
                         */
 
-                       string action = Page.Request.FilePath;
-                       string query = Page.Request.QueryStringRaw;
-                       if (query != null && query.Length > 0) {
-                               action += "?" + query;
+                       string action;
+                       string file_path = Page.Request.FilePath;
+                       string current_path = Page.Request.CurrentExecutionFilePath;
+                       if (file_path == current_path) {
+                               // Just the filename will do
+                               action = UrlUtils.GetFile (file_path);
+                       } else {
+                               // Fun. We need to make cookieless sessions work, so no
+                               // absolute paths here.
+                               Uri current_uri = new Uri ("http://host" + current_path);
+                               Uri fp_uri = new Uri ("http://host" + file_path);
+                               action = fp_uri.MakeRelative (current_uri);
                        }
-                       
+
+                       action += Page.Request.QueryStringRaw;
+
                        w.WriteAttribute ("name", Name);
+
                        w.WriteAttribute ("method", Method);
                        w.WriteAttribute ("action", action);
 
@@ -251,11 +280,21 @@ namespace System.Web.UI.HtmlControls
                        if (target != null && target != "") {
                                w.WriteAttribute ("target", target);
                        }
-                       
+
+#if NET_2_0
+                       string defaultbutton = DefaultButton;
+                       if (defaultbutton != null && defaultbutton != "") {
+                               Control c = FindControl (defaultbutton);
+
+                               if (c == null || !(c is IButtonControl))
+                                       throw new InvalidOperationException(String.Format ("The DefaultButton of '{0}' must be the ID of a control of type IButtonControl.",
+                                                                                          ID));
+                       }
+#endif
+
                        /* Now remove them from the hash so the base
                         * RenderAttributes can do all the rest
                         */
-                       Attributes.Remove ("name");
                        Attributes.Remove ("method");
                        Attributes.Remove ("enctype");
                        Attributes.Remove ("target");
@@ -270,6 +309,12 @@ namespace System.Web.UI.HtmlControls
 #endif         
                override void RenderChildren (HtmlTextWriter w)
                {
+                       if (!inited) {
+                               Page.RegisterViewStateHandler ();
+#if NET_2_0
+                               Page.RegisterForm (this);
+#endif
+                       }
                        Page.OnFormRender (w, ClientID);
                        base.RenderChildren (w);
                        Page.OnFormPostRender (w, ClientID);
@@ -277,7 +322,7 @@ namespace System.Web.UI.HtmlControls
 
 #if NET_2_0
                /* According to corcompare */
-               [MonoTODO]
+               [MonoTODO ("why override?")]
                public override void RenderControl (HtmlTextWriter w)
                {
                        base.RenderControl (w);