New test.
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlForm.cs
index 2abe5f8391b6e47469968d6874d33f38e5844423..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 ("")]
                public string DefaultButton
                {
                        get {
-                               string defaultbutton = Attributes["defaultbutton"];
-
-                               if (defaultbutton == null) {
-                                       return (String.Empty);
-                               }
-
-                               return (defaultbutton);
+                               return defaultbutton;
                        }
                        set {
-                               if (value == null) {
-                                       Attributes.Remove ("defaultbutton");
-                               } else {
-                                       Attributes["defaultbutton"] = value;
-                               }
+                               defaultbutton = (value == null ? "" : value);
                        }
                }
 
+               string defaultfocus = "";
                [DefaultValue ("")]
                public string DefaultFocus
                {
                        get {
-                               string defaultfocus = Attributes["defaultfocus"];
-
-                               if (defaultfocus == null) {
-                                       return (String.Empty);
-                               }
-
-                               return (defaultfocus);
+                               return defaultfocus;
                        }
                        set {
-                               if (value == null) {
-                                       Attributes.Remove ("defaultfocus");
-                               } else {
-                                       Attributes["defaultfocus"] = value;
-                               }
+                               defaultfocus = (value == null ? "" : value);
                        }
                }
 #endif         
 
                [DefaultValue ("")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-               [WebSysDescription("")]
                public string Enctype 
                {
                        get {
@@ -107,14 +95,12 @@ namespace System.Web.UI.HtmlControls
                
                [DefaultValue ("")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-               [WebSysDescription("")]
-               [WebCategory("Behavior")]
                public string Method 
                {
                        get {
                                string method = Attributes["method"];
 
-                               if (method == null) {
+                               if ((method == null) || (method.Length == 0)) {
                                        return ("post");
                                }
                                
@@ -131,51 +117,32 @@ namespace System.Web.UI.HtmlControls
 
                [DefaultValue ("")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-               [WebSysDescription("")]
-               [WebCategory("Appearance")]
-#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
                        
                [DefaultValue ("")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-               [WebSysDescription("")]
-               [WebCategory("Behavior")]
                public string Target 
                {
                        get {
@@ -196,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 ();
@@ -224,24 +184,23 @@ 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
-               protected internal override void OnPreRender (EventArgs e)
+               internal bool DetermineRenderUplevel ()
                {
-                       string focus_id = null;
-                       bool render_uplevel = false;
-                       bool need_script_block = false;
-
-                       base.OnPreRender(e);
-
                        /* this bit is c&p'ed from BaseValidator.DetermineRenderUplevel */
                        try {
                                if (Page != null && Page.Request != null)
-                                       render_uplevel = (
+                                       return (
                                                /* From someplace on the web: "JavaScript 1.2
                                                 * and later (also known as ECMAScript) has
                                                 * built-in support for regular
@@ -261,37 +220,12 @@ namespace System.Web.UI.HtmlControls
                                ;
                        }
 
+                       return false;
+               }
 
-                       /* figure out if we have some control we're going to focus */
-                       if (DefaultFocus != null && DefaultFocus != "")
-                               focus_id = DefaultFocus;
-                       else if (DefaultButton != null && DefaultButton != "")
-                               focus_id = DefaultButton;
-
-                       /* presumably there are other conditions to
-                        * this test, not just whether or not we have
-                        * a default focus/button */
-                       need_script_block = (focus_id != null);
-
-                       if (render_uplevel) {
-                               Page.RequiresPostBackScript();
-
-                               if (need_script_block && !Page.ClientScript.IsClientScriptBlockRegistered ("Mono-System.Web-HtmlScriptBlock")) {
-                                       Page.ClientScript.RegisterClientScriptBlock ("Mono-System.Web-HtmlScriptBlock",
-                                                                                    String.Format ("<script language=\"JavaScript\" src=\"{0}\"></script>",
-                                                                                                   Page.ClientScript.GetWebResourceUrl (GetType(),
-                                                                                                                                        "webform.js")));
-                               }
-
-
-                               if (focus_id != null) {
-                                       Page.ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
-                                                                                String.Format ("<script language=\"JavaScript\">\n" + 
-                                                                                               "<!--\n" + 
-                                                                                               "WebForm_AutoFocus('{0}');// -->\n" + 
-                                                                                               "</script>\n", focus_id));
-                               }
-                       }
+               protected internal override void OnPreRender (EventArgs e)
+               {
+                       base.OnPreRender(e);
                }
 #endif         
 
@@ -301,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);
 
@@ -350,14 +295,9 @@ namespace System.Web.UI.HtmlControls
                        /* 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");
-#if NET_2_0
-                       Attributes.Remove ("defaultfocus");
-                       Attributes.Remove ("defaultbutton");
-#endif
 
                        base.RenderAttributes (w);
                }
@@ -369,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);
@@ -376,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);