2010-03-12 Jb Evain <jbevain@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlImage.cs
1 //
2 // System.Web.UI.HtmlControls.HtmlImage.cs
3 //
4 // Author:
5 //      Dick Porter  <dick@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System.ComponentModel;
30 using System.Globalization;
31 using System.Security.Permissions;
32 using System.Web.Util;
33
34 namespace System.Web.UI.HtmlControls 
35 {
36         // CAS
37         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39         // attributes
40 #if NET_2_0
41         [ControlBuilder (typeof (HtmlEmptyTagControlBuilder))]
42 #else
43         [ControlBuilder (typeof (HtmlControlBuilder))]
44 #endif
45         public class HtmlImage : HtmlControl 
46         {
47                 public HtmlImage () : base ("img")
48                 {
49                 }
50
51                 [DefaultValue ("")]
52                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
53                 [WebSysDescription("")]
54                 [WebCategory("Layout")]
55                 public string Align 
56                 {
57                         get {
58                                 string align = Attributes["align"];
59
60                                 if (align == null) {
61                                         return (String.Empty);
62                                 }
63                                 
64                                 return (align);
65                         }
66                         set {
67                                 if (value == null) {
68                                         Attributes.Remove ("align");
69                                 } else {
70                                         Attributes["align"] = value;
71                                 }
72                         }
73                 }
74
75                 [DefaultValue ("")]
76                 [WebSysDescription("")]
77                 [WebCategory("Appearance")]
78                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
79 #if NET_2_0
80                 [Localizable (true)]
81 #endif
82                 public string Alt 
83                 {
84                         get {
85                                 string alt = Attributes["alt"];
86
87                                 if (alt == null) {
88                                         return (String.Empty);
89                                 }
90                                 
91                                 return (alt);
92                         }
93                         set {
94                                 if (value == null) {
95                                         Attributes.Remove ("alt");
96                                 } else {
97                                         Attributes["alt"] = value;
98                                 }
99                         }
100                 }
101         
102                 [DefaultValue (0)]
103                 [WebSysDescription("")]
104                 [WebCategory("Appearance")]
105                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
106                 public int Border 
107                 {
108                         get {
109                                 string border = Attributes["border"];
110                                 
111                                 if (border == null) {
112                                         return (-1);
113                                 } else {
114                                         return (Int32.Parse (border, Helpers.InvariantCulture));
115                                 }
116                         }
117                         set {
118                                 if (value == -1) {
119                                         Attributes.Remove ("border");
120                                 } else {
121                                         Attributes["border"] = value.ToString ();
122                                 }
123                         }
124                 }
125
126                 [DefaultValue (100)]
127                 [WebSysDescription("")]
128                 [WebCategory("Layout")]
129                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
130                 public int Height
131                 {
132                         get {
133                                 string height = Attributes["height"];
134                                 
135                                 if (height == null) {
136                                         return (-1);
137                                 } else {
138                                         return (Int32.Parse (height, Helpers.InvariantCulture));
139                                 }
140                         }
141                         set {
142                                 if (value == -1) {
143                                         Attributes.Remove ("height");
144                                 } else {
145                                         Attributes["height"] = value.ToString ();
146                                 }
147                         }
148                 }
149                 
150                 [DefaultValue ("")]
151                 [WebSysDescription("")]
152                 [WebCategory("Behavior")]
153                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
154 #if NET_2_0
155                 [UrlProperty]
156 #endif
157                 public string Src 
158                 {
159                         get {
160                                 string src = Attributes["src"];
161
162                                 if (src == null) {
163                                         return (String.Empty);
164                                 }
165                                 
166                                 return (src);
167                         }
168                         set {
169                                 if (value == null) {
170                                         Attributes.Remove ("src");
171                                 } else {
172                                         Attributes["src"] = value;
173                                 }
174                         }
175                 }
176
177                 [DefaultValue (100)]
178                 [WebSysDescription("")]
179                 [WebCategory("Layout")]
180                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
181                 public int Width 
182                 {
183                         get {
184                                 string width = Attributes["width"];
185
186                                 if (width == null) {
187                                         return (-1);
188                                 }
189                                 else {
190                                         return (Int32.Parse (width, Helpers.InvariantCulture));
191                                 }
192                         }
193                         set {
194                                 if (value == -1) {
195                                         Attributes.Remove ("width");
196                                 } else {
197                                         Attributes["width"] = value.ToString ();
198                                 }
199                         }
200                 }
201
202                 protected override void RenderAttributes (HtmlTextWriter w)
203                 {
204                         PreProcessRelativeReference (w, "src");
205
206                         /* MS does not seem to render the src attribute if it
207                          * is empty. Firefox, at least, will fetch the current
208                          * page as the src="" if other img attributes exist.
209                          */
210                         string src = Attributes["src"];
211                         if (src == null || src.Length == 0)
212                                 Attributes.Remove ("src");
213
214                         base.RenderAttributes (w);
215
216                         /* MS closes the HTML element at the end of
217                          * the attributes too, according to the nunit
218                          * tests
219                          */
220                         w.Write (" /");
221                 }
222         }
223 }
224
225