HtmlImage.cs 5.1 KB

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