1 //------------------------------------------------------------------------------ 2 // <copyright file="HTMLTagNameToTypeMapper.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 //------------------------------------------------------------------------------ 6 7 /* 8 * Mapper of html tags to control types. 9 * 10 * Copyright (c) 1998 Microsoft Corporation 11 */ 12 13 namespace System.Web.UI { 14 using System; 15 using System.Collections; 16 using System.Web.Compilation; 17 using System.Web.Configuration; 18 using System.Web.UI.HtmlControls; 19 using System.Web.Util; 20 21 internal class HtmlTagNameToTypeMapper : ITagNameToTypeMapper { 22 static Hashtable _tagMap; 23 static Hashtable _inputTypes; 24 HtmlTagNameToTypeMapper()25 internal HtmlTagNameToTypeMapper() { 26 } 27 ITagNameToTypeMapper.GetControlType(string tagName, IDictionary attributeBag)28 /*public*/ Type ITagNameToTypeMapper.GetControlType(string tagName, IDictionary attributeBag) { 29 Type controlType; 30 31 if (_tagMap == null) { 32 Hashtable t = new Hashtable(10, StringComparer.OrdinalIgnoreCase); 33 t.Add("a", typeof(HtmlAnchor)); 34 t.Add("button", typeof(HtmlButton)); 35 t.Add("form", typeof(HtmlForm)); 36 t.Add("head", typeof(HtmlHead)); 37 t.Add("img", typeof(HtmlImage)); 38 t.Add("textarea", typeof(HtmlTextArea)); 39 t.Add("select", typeof(HtmlSelect)); 40 t.Add("table", typeof(HtmlTable)); 41 t.Add("tr", typeof(HtmlTableRow)); 42 t.Add("td", typeof(HtmlTableCell)); 43 t.Add("th", typeof(HtmlTableCell)); 44 45 // Add new html 5 audio/video tags which resolve the src tag 46 if (MultiTargetingUtil.IsTargetFramework45OrAbove) { 47 t.Add("audio", typeof(HtmlAudio)); 48 t.Add("video", typeof(HtmlVideo)); 49 t.Add("track", typeof(HtmlTrack)); 50 t.Add("source", typeof(HtmlSource)); 51 t.Add("iframe", typeof(HtmlIframe)); 52 t.Add("embed", typeof(HtmlEmbed)); 53 t.Add("area", typeof(HtmlArea)); 54 t.Add("html", typeof(HtmlElement)); 55 } 56 _tagMap = t; 57 } 58 59 if (_inputTypes == null) { 60 Hashtable t = new Hashtable(10, StringComparer.OrdinalIgnoreCase); 61 t.Add("text", typeof(HtmlInputText)); 62 t.Add("password", typeof(HtmlInputPassword)); 63 t.Add("button", typeof(HtmlInputButton)); 64 t.Add("submit", typeof(HtmlInputSubmit)); 65 t.Add("reset", typeof(HtmlInputReset)); 66 t.Add("image", typeof(HtmlInputImage)); 67 t.Add("checkbox", typeof(HtmlInputCheckBox)); 68 t.Add("radio", typeof(HtmlInputRadioButton)); 69 t.Add("hidden", typeof(HtmlInputHidden)); 70 t.Add("file", typeof(HtmlInputFile)); 71 _inputTypes = t; 72 } 73 74 if (StringUtil.EqualsIgnoreCase("input", tagName)) { 75 string type = "text"; 76 if (attributeBag != null) { 77 type = (string)attributeBag["type"] ?? type; 78 } 79 80 controlType = (Type)_inputTypes[type]; 81 if (controlType == null) { 82 // HtmlInputGenericControl was introduced in 4.5, so we do explicit version checking to preserve the old throwing behavior 83 if (MultiTargetingUtil.IsTargetFramework45OrAbove) { 84 controlType = typeof(HtmlInputGenericControl); 85 } 86 else { 87 throw new HttpException(SR.GetString(SR.Invalid_type_for_input_tag, type)); 88 } 89 } 90 } 91 else { 92 controlType = (Type)_tagMap[tagName]; 93 if (controlType == null) { 94 controlType = typeof(HtmlGenericControl); 95 } 96 } 97 98 return controlType; 99 } 100 } 101 } 102 103