X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web.UI%2FCssStyleCollection.cs;h=cb2d93e39fa996332878f3c58c63edbed90a84e7;hb=d49951ccf584ba637afb1dab7fff714478e3174d;hp=826635e9b8b099a0ec2c4d1a38c82d218f958632;hpb=5e6643734df34c002b914b3d44c91ed897a8a6d6;p=mono.git diff --git a/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs b/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs index 826635e9b8b..cb2d93e39fa 100644 --- a/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs +++ b/mcs/class/System.Web/System.Web.UI/CssStyleCollection.cs @@ -30,24 +30,37 @@ using System.IO; using System.Collections; +using System.Security.Permissions; using System.Text; +using System.Collections.Specialized; +using System.Globalization; namespace System.Web.UI { + // CAS - no InheritanceDemand here as the class is sealed + [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] public sealed class CssStyleCollection { StateBag bag; - StateBag style; - string last_string; + HybridDictionary style; internal CssStyleCollection (StateBag bag) { this.bag = bag; - if (bag != null) { - last_string = (string) bag ["style"]; - style = new StateBag (); - if (last_string != null) - FillStyle (last_string); + if (bag != null) + 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); } } @@ -79,22 +92,19 @@ namespace System.Web.UI { string BagToString () { - if (last_string != null) - return last_string; - StringBuilder sb = new StringBuilder (); - foreach (string key in Keys) - sb.AppendFormat ("{0}: {1};", key, style [key]); + foreach (string key in style.Keys) { + if (key == "background-image" && 0 != String.Compare ("url", ((string) style [key]).Substring (0, 3), true, CultureInfo.InvariantCulture)) + sb.AppendFormat ("{0}:url({1});", key, HttpUtility.UrlPathEncode ((string) style [key])); + else + sb.AppendFormat ("{0}:{1};", key, style [key]); + } - last_string = sb.ToString (); - return last_string; + return sb.ToString (); } - public int Count - { + public int Count { get { - if (bag == null) - throw new NullReferenceException (); return style.Count; } } @@ -110,15 +120,14 @@ namespace System.Web.UI { } public ICollection Keys { - get { return style.Keys; } + get { + return style.Keys; + } } public void Add (string key, string value) { - if (style == null) - style = new StateBag (); style [key] = value; - last_string = null; bag ["style"] = BagToString (); } @@ -134,17 +143,15 @@ namespace System.Web.UI { public void Clear () { - if (style != null) - style.Clear (); - last_string = null; + style.Clear (); bag.Remove ("style"); } public void Remove (string key) { - if (style != null) - style.Remove (key); - last_string = null; + if (style [key] == null) + return; + style.Remove (key); bag ["style"] = BagToString (); } #if NET_2_0 @@ -169,13 +176,8 @@ namespace System.Web.UI { string Value { get { return BagToString (); } set { - if (style != null) - style = new StateBag (); - style.Clear (); - last_string = value; bag ["style"] = value; - if (value != null) - FillStyle (value); + InitFromStyle (); } } }