2007-03-12 Igor Zelmanovich <igorz@mainsoft.com>
authorIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Mon, 12 Mar 2007 10:30:01 +0000 (10:30 -0000)
committerIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Mon, 12 Mar 2007 10:30:01 +0000 (10:30 -0000)
* AttributeCollection.cs:
* CssStyleCollection.cs: fixed: works w/o state bag.

2007-03-12 Igor Zelmanovich <igorz@mainsoft.com>

* Style.cs: optimization: used CssStyleCollection .ctor w/o parameters.

svn path=/trunk/mcs/; revision=74108

mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/System.Web.UI.WebControls/Style.cs
mcs/class/System.Web/System.Web.UI/AttributeCollection.cs
mcs/class/System.Web/System.Web.UI/ChangeLog
mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs
mcs/class/System.Web/Test/System.Web.UI/AttributeCollectionTest.cs

index ca70ad302103051c8c2eb49f00c1471977eea75e..2a2b5f87e4d3cd8950d3b2e281bdcf9aee04d51b 100644 (file)
@@ -1,3 +1,7 @@
+2007-03-12 Igor Zelmanovich <igorz@mainsoft.com>
+
+       * Style.cs: optimization: used CssStyleCollection .ctor w/o parameters. 
+
 2007-03-09  Marek Habersack  <mhabersack@novell.com>
 
        * Login.cs: Make command name comparison case-insensitive in
 
        * CreateUserWizardStep.cs: fixed validators message display
 
-2006-08-25  Kornél Pál  <kornelpal@gmail.com>
+2006-08-25  Korn__l P__l  <kornelpal@gmail.com>
 
        * FileUpload.cs: Use assembly name constants.
 
 2006-07-13 Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * DataList.cs: correctly initialize editable items when there's an
-       EditItemTemplate. Patch by JarosÅ\82aw Pawlak.
+       EditItemTemplate. Patch by Jaros_\82aw Pawlak.
 
 2006-07-13  Juraj Skripsky <js@hotfeet.ch>
 
 2004-10-25 Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * ListItemCollection.cs: fixed bug when indexing changed elements in
-       LoadViewState. Patch from Alois Bělaška.
+       LoadViewState. Patch from Alois B_\9bla__ka.
 
 2004-10-20 Sanjay Gupta <gsanjay@novell.com>
        
index 8febbc2b68700b4e6a16b52276dbf35d2a08c192..663f078618800be59ebc2ab1067a325149843a6b 100644 (file)
@@ -412,7 +412,7 @@ namespace System.Web.UI.WebControls {
                                if (CssClass.Length > 0)
                                        writer.AddAttribute (HtmlTextWriterAttribute.Class, CssClass);
 #if NET_2_0
-                               CssStyleCollection col = new CssStyleCollection (new StateBag ());
+                               CssStyleCollection col = new CssStyleCollection ();
                                FillStyleAttributes (col, owner);
                                foreach (string key in col.Keys) {
                                        writer.AddStyleAttribute (key, col [key]);
@@ -813,7 +813,7 @@ namespace System.Web.UI.WebControls {
 
                public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
                {
-                       CssStyleCollection col = new CssStyleCollection (new StateBag ());
+                       CssStyleCollection col = new CssStyleCollection ();
                        FillStyleAttributes (col, resolver);
                        return col;
                }
index 038029e00136d218aede022d7057bcc796f2d990..7ec7277cf4064528f970d7a2269b87940aef0704 100644 (file)
@@ -40,6 +40,7 @@ namespace System.Web.UI {
        {
                private StateBag bag;
                private CssStyleCollection styleCollection;
+               internal const string StyleAttribute = "style";
                
                public AttributeCollection (StateBag bag)
                {
@@ -72,7 +73,7 @@ namespace System.Web.UI {
 
                public void Add (string key, string value)
                {
-                       if (0 == String.Compare (key, "style", true, CultureInfo.InvariantCulture)) {
+                       if (0 == String.Compare (key, StyleAttribute, true, CultureInfo.InvariantCulture)) {
                                CssStyle.Value = value;
                                return;
                        }
@@ -95,7 +96,7 @@ namespace System.Web.UI {
 
                public void Remove (string key)
                {
-                       if (0 == String.Compare (key, "style", true, CultureInfo.InvariantCulture)) {
+                       if (0 == String.Compare (key, StyleAttribute, true, CultureInfo.InvariantCulture)) {
                                CssStyle.Clear ();
                                return;
                        }
index 8f7e3f628b65a88fcc875404756bc58e75ed4550..2fc1fb922ea74eb8477f70510fbdfe517eef10fc 100644 (file)
@@ -1,3 +1,8 @@
+2007-03-12 Igor Zelmanovich <igorz@mainsoft.com>
+
+       * AttributeCollection.cs:
+       * CssStyleCollection.cs: fixed: works w/o state bag.    
+
 2007-03-12 Igor Zelmanovich <igorz@mainsoft.com>
 
        * HtmlTextWriter.cs: fixed:
index cb2d93e39fa996332878f3c58c63edbed90a84e7..1c16bc851cf8f5484e1aabd5d10f1bce390cb722 100644 (file)
@@ -43,24 +43,46 @@ namespace System.Web.UI {
        {
                StateBag bag;
                HybridDictionary style;
+               string _value;
+               
+               string ValueInternal {
+                       get { return _value; }
+                       set {
+                               _value = value;
+                               if (bag != null) {
+                                       if (_value == null) {
+                                               bag.Remove (AttributeCollection.StyleAttribute);
+                                       }
+                                       else {
+                                               bag [AttributeCollection.StyleAttribute] = _value;
+                                       }
+                               }
+                       }
+               }
+               
+               internal CssStyleCollection ()
+               {
+#if NET_2_0
+                       style = new HybridDictionary (true);
+#else
+                       style = new HybridDictionary (false);
+#endif
+               }
 
                internal CssStyleCollection (StateBag bag)
+                       : this ()
                {
                        this.bag = bag;
                        if (bag != null)
-                               InitFromStyle ();
+                               _value = (string) bag [AttributeCollection.StyleAttribute];
+                       InitFromStyle ();
                }
 
                void InitFromStyle ()
                {
-#if NET_2_0
-                       style = new HybridDictionary (true);
-#else
-                       style = new HybridDictionary (false);
-#endif
-                       string att = (string) bag ["style"];
-                       if (att != null) {
-                               FillStyle (att);
+                       style.Clear ();
+                       if (_value != null) {
+                               FillStyle (_value);
                        }
                }
 
@@ -128,7 +150,7 @@ namespace System.Web.UI {
                public void Add (string key, string value)
                {
                        style [key] = value;
-                       bag ["style"] = BagToString ();
+                       ValueInternal = BagToString ();
                }
 
 #if NET_2_0
@@ -144,7 +166,7 @@ namespace System.Web.UI {
                public void Clear ()
                {
                        style.Clear ();
-                       bag.Remove ("style");
+                       ValueInternal = null;
                }
 
                public void Remove (string key)
@@ -152,7 +174,10 @@ namespace System.Web.UI {
                        if (style [key] == null)
                                return;
                        style.Remove (key);
-                       bag ["style"] = BagToString ();
+                       if (style.Count == 0)
+                               ValueInternal = null;
+                       else
+                               ValueInternal = BagToString ();
                }
 #if NET_2_0
                public string this [HtmlTextWriterStyle key] {
@@ -174,9 +199,9 @@ namespace System.Web.UI {
                internal
 #endif
                string Value {
-                       get { return BagToString (); }
+                       get { return ValueInternal; }
                        set {
-                               bag ["style"] = value;
+                               ValueInternal = value;
                                InitFromStyle ();
                        }
                }
index 80bff8f59d5c257f5093a3ae6513174b989dfea2..9ab358615f1d4a8c5a711e5c9b9b8f9682e393d4 100644 (file)
@@ -113,7 +113,6 @@ namespace MonoTests.System.Web.UI {
                }
 
                [Test]
-               [Category("NotWorking")]
                public void InitialNoBag10()
                {
                    AC ac = new AC(null);
@@ -123,7 +122,6 @@ namespace MonoTests.System.Web.UI {
                }
 
                [Test]
-               [Category("NotWorking")]
                public void InitialNoBag11()
                {
                    AC ac = new AC(null);
@@ -133,7 +131,6 @@ namespace MonoTests.System.Web.UI {
                }
 
                [Test]
-               [Category("NotWorking")]
                public void InitialNoBag12()
                {
                    AC ac = new AC(null);
@@ -209,6 +206,67 @@ namespace MonoTests.System.Web.UI {
                        Assert.AreEqual ("", str, "value2");
                        Assert.AreEqual (1, bag.Count, "count2");
                }
+               
+               [Test]
+               public void Count1 ()
+               {
+                       StateBag bag = new StateBag (true);
+                       AC ac = new AC (bag);
+                       ac.Add ("style", "padding: 0px; margin: 0px");
+                       Assert.AreEqual (1, ac.Count, "AttributeCollection.Count");
+                       Assert.AreEqual (2, ac.CssStyle.Count, "AttributeCollection.Count");
+                       
+                       ac.Remove ("style");
+                       Assert.AreEqual (0, ac.Count, "AttributeCollection.Count");
+                       Assert.AreEqual (0, ac.CssStyle.Count, "AttributeCollection.Count");
+               }
+
+               [Test]
+               public void Count2 ()
+               {
+                       StateBag bag = new StateBag (true);
+                       AC ac = new AC (bag);
+                       ac ["style"] = "padding: 0px; margin: 0px";
+                       Assert.AreEqual (1, ac.Count, "AttributeCollection.Count");
+                       Assert.AreEqual (2, ac.CssStyle.Count, "AttributeCollection.Count");
+
+                       ac ["style"] = null;
+                       Assert.AreEqual (0, ac.Count, "AttributeCollection.Count");
+                       Assert.AreEqual (0, ac.CssStyle.Count, "AttributeCollection.Count");
+               }
+
+               [Test]
+               public void Count3 ()
+               {
+                       StateBag bag = new StateBag (true);
+                       AC ac = new AC (bag);
+                       ac.CssStyle.Add("padding", "0px");
+                       ac.CssStyle.Add("margin", "0px");
+                       Assert.AreEqual (1, ac.Count, "AttributeCollection.Count");
+                       Assert.AreEqual (2, ac.CssStyle.Count, "AttributeCollection.Count");
+
+                       ac.CssStyle.Remove ("padding");
+                       ac.CssStyle.Remove ("margin");
+                       Assert.AreEqual (0, ac.Count, "AttributeCollection.Count");
+                       Assert.AreEqual (0, ac.CssStyle.Count, "AttributeCollection.Count");
+               }
+
+#if NET_2_0
+               [Test]
+               public void Count4 ()
+               {
+                       StateBag bag = new StateBag (true);
+                       AC ac = new AC (bag);
+                       ac.CssStyle ["padding"] = "0px";
+                       ac.CssStyle ["margin"] = "0px";
+                       Assert.AreEqual (1, ac.Count, "AttributeCollection.Count");
+                       Assert.AreEqual (2, ac.CssStyle.Count, "AttributeCollection.Count");
+
+                       ac.CssStyle.Value = null;
+                       Assert.AreEqual (0, ac.Count, "AttributeCollection.Count");
+                       Assert.AreEqual (0, ac.CssStyle.Count, "AttributeCollection.Count");
+               }
+#endif
        }
 }