HtmlImage.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // System.Web.UI.HtmlControls.HtmlImage.cs
  3. //
  4. // Author:
  5. // Dick Porter <[email protected]>
  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. using System.ComponentModel;
  29. using System.Globalization;
  30. using System.Security.Permissions;
  31. using System.Web.Util;
  32. namespace System.Web.UI.HtmlControls
  33. {
  34. // CAS
  35. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  36. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  37. // attributes
  38. #if NET_2_0
  39. [ControlBuilder (typeof (HtmlEmptyTagControlBuilder))]
  40. #else
  41. [ControlBuilder (typeof (HtmlControlBuilder))]
  42. #endif
  43. public class HtmlImage : HtmlControl
  44. {
  45. public HtmlImage () : base ("img")
  46. {
  47. }
  48. [DefaultValue ("")]
  49. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  50. [WebSysDescription("")]
  51. [WebCategory("Layout")]
  52. public string Align
  53. {
  54. get {
  55. string align = Attributes["align"];
  56. if (align == null) {
  57. return (String.Empty);
  58. }
  59. return (align);
  60. }
  61. set {
  62. if (value == null) {
  63. Attributes.Remove ("align");
  64. } else {
  65. Attributes["align"] = value;
  66. }
  67. }
  68. }
  69. [DefaultValue ("")]
  70. [WebSysDescription("")]
  71. [WebCategory("Appearance")]
  72. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  73. #if NET_2_0
  74. [Localizable (true)]
  75. #endif
  76. public string Alt
  77. {
  78. get {
  79. string alt = Attributes["alt"];
  80. if (alt == null) {
  81. return (String.Empty);
  82. }
  83. return (alt);
  84. }
  85. set {
  86. if (value == null) {
  87. Attributes.Remove ("alt");
  88. } else {
  89. Attributes["alt"] = value;
  90. }
  91. }
  92. }
  93. [DefaultValue (0)]
  94. [WebSysDescription("")]
  95. [WebCategory("Appearance")]
  96. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  97. public int Border
  98. {
  99. get {
  100. string border = Attributes["border"];
  101. if (border == null) {
  102. return (-1);
  103. } else {
  104. return (Int32.Parse (border, Helpers.InvariantCulture));
  105. }
  106. }
  107. set {
  108. if (value == -1) {
  109. Attributes.Remove ("border");
  110. } else {
  111. Attributes["border"] = value.ToString ();
  112. }
  113. }
  114. }
  115. [DefaultValue (100)]
  116. [WebSysDescription("")]
  117. [WebCategory("Layout")]
  118. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  119. public int Height
  120. {
  121. get {
  122. string height = Attributes["height"];
  123. if (height == null) {
  124. return (-1);
  125. } else {
  126. return (Int32.Parse (height, Helpers.InvariantCulture));
  127. }
  128. }
  129. set {
  130. if (value == -1) {
  131. Attributes.Remove ("height");
  132. } else {
  133. Attributes["height"] = value.ToString ();
  134. }
  135. }
  136. }
  137. [DefaultValue ("")]
  138. [WebSysDescription("")]
  139. [WebCategory("Behavior")]
  140. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  141. #if NET_2_0
  142. [UrlProperty]
  143. #endif
  144. public string Src
  145. {
  146. get {
  147. string src = Attributes["src"];
  148. if (src == null) {
  149. return (String.Empty);
  150. }
  151. return (src);
  152. }
  153. set {
  154. if (value == null) {
  155. Attributes.Remove ("src");
  156. } else {
  157. Attributes["src"] = value;
  158. }
  159. }
  160. }
  161. [DefaultValue (100)]
  162. [WebSysDescription("")]
  163. [WebCategory("Layout")]
  164. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  165. public int Width
  166. {
  167. get {
  168. string width = Attributes["width"];
  169. if (width == null) {
  170. return (-1);
  171. }
  172. else {
  173. return (Int32.Parse (width, Helpers.InvariantCulture));
  174. }
  175. }
  176. set {
  177. if (value == -1) {
  178. Attributes.Remove ("width");
  179. } else {
  180. Attributes["width"] = value.ToString ();
  181. }
  182. }
  183. }
  184. protected override void RenderAttributes (HtmlTextWriter w)
  185. {
  186. PreProcessRelativeReference (w, "src");
  187. /* MS does not seem to render the src attribute if it
  188. * is empty. Firefox, at least, will fetch the current
  189. * page as the src="" if other img attributes exist.
  190. */
  191. string src = Attributes["src"];
  192. if (src == null || src.Length == 0)
  193. Attributes.Remove ("src");
  194. base.RenderAttributes (w);
  195. /* MS closes the HTML element at the end of
  196. * the attributes too, according to the nunit
  197. * tests
  198. */
  199. w.Write (" /");
  200. }
  201. }
  202. }