svn path=/branches/mono-1-1-9/mcs/; revision=51206
[mono.git] / mcs / class / System.Web / System.Web.UI / HtmlTextWriter.cs
1 // 
2 // System.Web.UI.HtmlTextWriter
3 //
4 // Author:
5 //        Ben Maurer <bmaurer@novell.com>
6 //
7 // (c) 2005 Novell
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.IO;
30 using System.Globalization;
31 using System.Collections;
32 using System.Text;
33
34 namespace System.Web.UI {
35         
36         public class HtmlTextWriter : TextWriter {
37
38
39                 public HtmlTextWriter (TextWriter writer) : this (writer, DefaultTabString)
40                 {
41                 }
42         
43                 public HtmlTextWriter (TextWriter writer, string tabString)
44                 {
45                         if (writer == null)
46                                 throw new ArgumentNullException ();
47
48                         b = writer;
49                         tab_string = tabString;
50                 }
51
52                 internal static string StaticGetStyleName (System.Web.UI.HtmlTextWriterStyle styleKey) 
53                 {
54                         if ((int) styleKey < htmlstyles.Length)
55                                 return htmlstyles [(int) styleKey].name;
56
57                         return null;
58                 }
59                 
60                 [MonoTODO]
61                 protected static void RegisterAttribute (string name, HtmlTextWriterAttribute key)
62                 {
63                 }
64                 
65                 [MonoTODO]
66                 protected static void RegisterStyle (string name, HtmlTextWriterStyle key)
67                 {
68                 }
69                 
70                 [MonoTODO]
71                 protected static void RegisterTag (string name, HtmlTextWriterTag key)
72                 {
73                 }
74                 
75         
76                 public virtual void AddAttribute (HtmlTextWriterAttribute key, string value, bool fEncode)
77                 {
78                         if (fEncode)
79                                 value = EncodeAttributeValue (key, value);
80                         AddAttribute (GetAttributeName (key), value, key);
81                 }
82                 
83                 
84                 public virtual void AddAttribute (HtmlTextWriterAttribute key, string value)
85                 {
86                         AddAttribute (key, value, true);
87                 }
88         
89         
90                 public virtual void AddAttribute (string name, string value, bool fEncode)
91                 {
92                         if (fEncode)
93                                 value = HttpUtility.HtmlAttributeEncode (value);
94
95                         AddAttribute (name, value, GetAttributeKey (name));
96                 }
97                 
98                 public virtual void AddAttribute (string name, string value)
99                 {
100                         AddAttribute (name, value, true);
101                 }
102         
103                 protected virtual void AddAttribute (string name, string value, HtmlTextWriterAttribute key)
104                 {
105                         NextAttrStack ();
106                         attrs [attrs_pos].name = name;
107                         attrs [attrs_pos].value = value;
108                         attrs [attrs_pos].key = key;
109                 }
110                 
111                 
112                 protected virtual void AddStyleAttribute (string name, string value, HtmlTextWriterStyle key)
113                 {
114                         NextStyleStack ();
115                         styles [styles_pos].name = name;
116                         styles [styles_pos].value = value;
117                         styles [styles_pos].key = key;
118                 }
119                 
120
121                 public virtual void AddStyleAttribute (string name, string value)
122                 {
123                         AddStyleAttribute (name, value, GetStyleKey (name));
124                 }
125                 
126                 public virtual void AddStyleAttribute (HtmlTextWriterStyle key, string value)
127                 {
128                         AddStyleAttribute (GetStyleName (key), value, key);
129                 }
130         
131                 public override void Close ()
132                 {
133                         b.Close ();     
134                 }
135
136                 [MonoTODO]
137                 protected virtual string EncodeAttributeValue (HtmlTextWriterAttribute attrKey, string value)
138                 {
139                         return value;
140                 }
141                 
142                 [MonoTODO]
143                 protected string EncodeAttributeValue (string value, bool fEncode)
144                 {
145                         return value;
146                 }
147                 
148                 [MonoTODO]
149                 protected string EncodeUrl (string url)
150                 {
151                         return url;
152                 }
153                 
154
155                 protected virtual void FilterAttributes ()
156                 {
157                         AddedAttr style_attr = new AddedAttr ();
158                         
159                         for (int i = 0; i <= attrs_pos; i ++) {
160                                 AddedAttr a = attrs [i];
161                                 if (OnAttributeRender (a.name, a.value, a.key)) {
162                                         if (a.key == HtmlTextWriterAttribute.Style) {
163                                                 style_attr = a;
164                                                 continue;
165                                         }
166                                         
167                                         WriteAttribute (a.name, a.value, false);
168                                 }
169                         }
170
171                         if (styles_pos != -1 || style_attr.value != null) {
172                                 Write (SpaceChar);
173                                 Write ("style");
174                                 Write (EqualsDoubleQuoteString);
175                                 
176                                 
177                                 for (int i = 0; i <= styles_pos; i ++) {
178                                         AddedStyle a = styles [i];
179                                         if (OnStyleAttributeRender (a.name, a.value, a.key))
180                                                 WriteStyleAttribute (a.name, a.value, false);
181                                 }
182
183                                 Write (style_attr.value);                               
184                                 Write (DoubleQuoteChar);
185                         }
186
187                         styles_pos = attrs_pos = -1;
188                 }
189         
190                 public override void Flush ()
191                 {
192                         b.Flush ();
193                 }
194
195                 [MonoTODO]
196                 protected HtmlTextWriterAttribute GetAttributeKey (string attrName)
197                 {
198                         // I don't think we want to binary search
199                         // because there might be something added to
200                         // the enum later. Do we really need anything
201                         // faster than a linear search?
202                         
203                         foreach (HtmlAttribute t in htmlattrs) {
204                                 if (t.name == attrName)
205                                         return t.key;
206                         }
207
208                         return 0;               
209                 }
210
211                 [MonoTODO]
212                 protected string GetAttributeName (HtmlTextWriterAttribute attrKey)
213                 {
214                         if ((int) attrKey < htmlattrs.Length)
215                                 return htmlattrs [(int) attrKey].name;
216
217                         return null;
218                 }
219                 
220                 [MonoTODO]
221                 protected HtmlTextWriterStyle GetStyleKey (string styleName)
222                 {
223                         // I don't think we want to binary search
224                         // because there might be something added to
225                         // the enum later. Do we really need anything
226                         // faster than a linear search?
227                         
228                         foreach (HtmlStyle t in htmlstyles) {
229                                 if (t.name == styleName)
230                                         return t.key;
231                         }
232
233                         return 0;                       
234                 }
235                 
236                 [MonoTODO]
237                 protected string GetStyleName (HtmlTextWriterStyle styleKey)
238                 {
239                         return StaticGetStyleName (styleKey);
240                 }
241                 
242                 [MonoTODO]
243                 protected virtual HtmlTextWriterTag GetTagKey (string tagName) 
244                 {
245                         // I don't think we want to binary search
246                         // because there might be something added to
247                         // the enum later. Do we really need anything
248                         // faster than a linear search?
249                         
250                         foreach (HtmlTag t in tags) {
251                                 if (t.name == tagName)
252                                         return t.key;
253                         }
254
255                         return HtmlTextWriterTag.Unknown;
256                 }
257
258                 internal static string StaticGetTagName (HtmlTextWriterTag tagKey)
259                 {
260                         if ((int) tagKey < tags.Length)
261                                 return tags [(int) tagKey].name;
262
263                         return null;    
264                 }
265                 
266                 
267                 [MonoTODO]
268                 protected virtual string GetTagName (HtmlTextWriterTag tagKey)
269                 {
270                         if ((int) tagKey < tags.Length)
271                                 return tags [(int) tagKey].name;
272
273                         return null;
274                 }
275                 
276                 protected bool IsAttributeDefined (HtmlTextWriterAttribute key)
277                 {
278                         string value;
279                         return IsAttributeDefined (key, out value);
280                 }
281         
282                 protected bool IsAttributeDefined (HtmlTextWriterAttribute key, out string value)
283                 {
284                         for (int i = 0; i <= attrs_pos; i ++)
285                                 if (attrs [i].key == key){
286                                         value = attrs [i].value;
287                                         return true;
288                                 }
289
290                         value = null;
291                         return false;
292                 }
293                 
294                 protected bool IsStyleAttributeDefined (HtmlTextWriterStyle key)
295                 {
296                         string value;
297                         return IsStyleAttributeDefined (key, out value);
298                 }
299         
300                 protected bool IsStyleAttributeDefined (HtmlTextWriterStyle key, out string value)
301                 {
302                         for (int i = 0; i <= styles_pos; i ++)
303                                 if (styles [i].key == key){
304                                         value = styles [i].value;
305                                         return true;
306                                 }
307
308                         value = null;
309                         return false;
310                 }
311                 
312                 protected virtual bool OnAttributeRender (string name, string value, HtmlTextWriterAttribute key)
313                 {
314                         return true;
315                 }
316                 
317                 protected virtual bool OnStyleAttributeRender (string name, string value, HtmlTextWriterStyle key)
318                 {
319                         return true;
320                 }
321                 
322                 protected virtual bool OnTagRender (string name, HtmlTextWriterTag key)
323                 {
324                         return true;
325                 }
326                 
327         
328                 protected virtual void OutputTabs ()
329                 {
330                         if (! newline)
331                                 return;
332                         newline = false;
333                         
334                         for (int i = 0; i < Indent; i ++)
335                                 b.Write (tab_string);
336                 }
337         
338
339                         
340                 protected string PopEndTag ()
341                 {
342                         if (tagstack_pos == -1)
343                                 throw new InvalidOperationException ();
344                         
345                         string s = TagName;
346                         tagstack_pos --;
347                         return s;
348                 }
349                 
350                 protected void PushEndTag (string endTag)
351                 {
352                         NextTagStack ();
353                         TagName = endTag;
354                 }
355
356                 void PushEndTag (HtmlTextWriterTag t)
357                 {
358                         NextTagStack ();
359                         TagKey = t;
360                 }
361                 
362
363                 protected virtual string RenderAfterContent ()
364                 {
365                         return null;
366                 }
367                 
368                 protected virtual string RenderAfterTag ()
369                 {
370                         return null;
371                 }
372                 
373                 protected virtual string RenderBeforeContent ()
374                 {
375                         return null;
376                 }
377                         
378                 protected virtual string RenderBeforeTag ()
379                 {
380                         return null;
381                 }
382
383                 public virtual void RenderBeginTag (string tagName)
384                 {
385                         if (! OnTagRender (tagName, GetTagKey (tagName)))
386                                 return;
387
388                         PushEndTag (tagName);
389                         
390                         DoBeginTag ();
391                 }
392                 
393                 public virtual void RenderBeginTag (HtmlTextWriterTag tagKey)
394                 {
395                         if (! OnTagRender (GetTagName (tagKey), tagKey))
396                                 return;
397
398                         PushEndTag (tagKey);
399
400                         DoBeginTag ();
401                 }
402
403                 void WriteIfNotNull (string s)
404                 {
405                         if (s != null)
406                                 Write (s);
407                 }
408                 
409
410                 void DoBeginTag ()
411                 {
412                         WriteIfNotNull (RenderBeforeTag ());
413                         WriteBeginTag (TagName);
414                         FilterAttributes ();
415
416                         HtmlTextWriterTag key = (int) TagKey < tags.Length ? TagKey : HtmlTextWriterTag.Unknown;
417
418                         switch (tags [(int) key].tag_type) {
419                         case TagType.Inline:
420                                 Write (TagRightChar);
421                                 break;
422                         case TagType.Block:
423                                 Write (TagRightChar);
424                                 WriteLine ();
425                                 Indent ++;
426                                 break;
427                         case TagType.SelfClosing:
428                                 Write (SelfClosingTagEnd);
429                                 break;
430                         }
431                         
432                         // FIXME what do i do for self close here?
433                         WriteIfNotNull (RenderBeforeContent ());
434                 }
435                 
436
437                 public virtual void RenderEndTag ()
438                 {
439                         // FIXME what do i do for self close here?
440                         WriteIfNotNull (RenderAfterContent ());
441                         
442                         HtmlTextWriterTag key = (int) TagKey < tags.Length ? TagKey : HtmlTextWriterTag.Unknown;
443
444                         switch (tags [(int) key].tag_type) {
445                         case TagType.Inline:
446                                 WriteEndTag (TagName);
447                                 break;
448                         case TagType.Block:
449                                 Indent --;
450                                 WriteLineNoTabs ("");
451                                 WriteEndTag (TagName);
452                                 
453                                 break;
454                         case TagType.SelfClosing:
455                                 // NADA
456                                 break;
457                         }
458                         WriteIfNotNull (RenderAfterTag ());
459
460                         PopEndTag ();
461                 }
462                 
463
464                 public virtual void WriteAttribute (string name, string value, bool fEncode)
465                 {
466                         Write (SpaceChar);
467                         Write (name);
468                         if (value != null) {
469                                 Write (EqualsDoubleQuoteString);
470                                 value = EncodeAttributeValue (value, fEncode);
471                                 Write (value);
472                                 Write (DoubleQuoteChar);
473                         }
474                 }
475                 
476         
477                 public virtual void WriteBeginTag (string tagName)
478                 {
479                         Write (TagLeftChar);
480                         Write (tagName);
481                 }
482                 
483                 public virtual void WriteEndTag (string tagName)
484                 {
485                         Write (EndTagLeftChars);
486                         Write (tagName);
487                         Write (TagRightChar);   
488                 }
489                 
490                 public virtual void WriteFullBeginTag (string tagName)
491                 {
492                         Write (TagLeftChar);
493                         Write (tagName);
494                         Write (TagRightChar);
495                 }
496                         
497                 public virtual void WriteStyleAttribute (string name, string value)
498                 {
499                         WriteStyleAttribute (name, value, true);
500                 }
501
502                 public virtual void WriteStyleAttribute (string name, string value, bool fEncode)
503                 {
504 #if NET_2_0
505                         if (name == "background-image") {
506                                 value = String.Concat ("url(", value, ")");
507                         }
508 #endif
509                         Write (name);
510                         Write (StyleEqualsChar);
511                         Write (EncodeAttributeValue (value, fEncode));
512                         Write (SemicolonChar);
513                 }
514                 
515                 public override void Write (char [] buffer, int index, int count)
516                 {
517                         OutputTabs ();
518                         b.Write (buffer, index, count);
519                 }
520         
521                 public override void Write (double value)
522                 {
523                         OutputTabs ();
524                         b.Write (value);
525                 }
526         
527                 public override void Write (char value)
528                 {
529                         OutputTabs ();
530                         b.Write (value);
531                 }
532         
533                 public override void Write (char [] buffer)
534                 {
535                         OutputTabs ();
536                         b.Write (buffer);
537                 }
538         
539                 public override void Write (int value)
540                 {
541                         OutputTabs ();
542                         b.Write (value);
543                 }
544         
545                 public override void Write (string format, object arg0)
546                 {
547                         OutputTabs ();
548                         b.Write (format, arg0);
549                 }
550         
551                 public override void Write (string format, object arg0, object arg1)
552                 {
553                         OutputTabs ();
554                         b.Write (format, arg0, arg1);
555                 }
556         
557                 public override void Write (string format, params object [] args)
558                 {
559                         OutputTabs ();
560                         b.Write (format, args);
561                 }
562
563                 public override void Write (string s)
564                 {
565                         OutputTabs ();
566                         b.Write (s);
567                 }
568                 
569                 public override void Write (long value)
570                 {
571                         OutputTabs ();
572                         b.Write (value);
573                 }
574         
575                 public override void Write (object value)
576                 {
577                         OutputTabs ();
578                         b.Write (value);
579                 }
580                 
581                 public override void Write (float value)
582                 {
583                         OutputTabs ();
584                         b.Write (value);
585                 }
586         
587                 public override void Write (bool value)
588                 {
589                         OutputTabs ();
590                         b.Write (value);
591                 }
592         
593                 public virtual void WriteAttribute (string name, string value)
594                 {
595                         WriteAttribute (name, value, true);
596                 }
597
598                 public override void WriteLine (char value)
599                 {
600                         OutputTabs ();
601                         b.WriteLine (value);
602                         newline = true;
603                 }
604         
605                 public override void WriteLine (long value)
606                 {
607                         OutputTabs ();
608                         b.WriteLine (value);
609                         newline = true;
610                 }
611         
612                 public override void WriteLine (object value)
613                 {
614                         OutputTabs ();
615                         b.WriteLine (value);
616                         newline = true; 
617                 }
618         
619                 public override void WriteLine (double value)
620                 {
621                         OutputTabs ();
622                         b.WriteLine (value);
623                         newline = true;
624                 }
625         
626                 public override void WriteLine (char [] buffer, int index, int count)
627                 {
628                         OutputTabs ();
629                         b.WriteLine (buffer, index, count);
630                         newline = true;
631                 }
632         
633                 public override void WriteLine (char [] buffer)
634                 {
635                         OutputTabs ();
636                         b.WriteLine (buffer);
637                         newline = true;
638                 }
639                 
640                 public override void WriteLine (bool value)
641                 {
642                         OutputTabs ();
643                         b.WriteLine (value);
644                         newline = true;
645                 }
646         
647                 public override void WriteLine ()
648                 {
649                         OutputTabs ();
650                         b.WriteLine ();
651                         newline = true;
652                 }
653         
654                 public override void WriteLine (int value)
655                 {
656                         OutputTabs ();
657                         b.WriteLine (value);
658                         newline = true;
659                 }
660         
661                 public override void WriteLine (string format, object arg0, object arg1)
662                 {
663                         OutputTabs ();
664                         b.WriteLine (format, arg0, arg1);
665                         newline = true;
666                 }
667         
668                 public override void WriteLine (string format, object arg0)
669                 {
670                         OutputTabs ();
671                         b.WriteLine (format, arg0);
672                         newline = true;
673                 }
674         
675                 public override void WriteLine (string format, params object [] args)
676                 {
677                         OutputTabs ();
678                         b.WriteLine (format, args);
679                         newline = true;
680                 }
681                 
682                 [CLSCompliant (false)]
683                 public override void WriteLine (uint value)
684                 {
685                         OutputTabs ();
686                         b.WriteLine (value);
687                         newline = true;
688                 }
689         
690                 public override void WriteLine (string s)
691                 {
692                         OutputTabs ();
693                         b.WriteLine (s);
694                         newline = true;
695                 }
696         
697                 public override void WriteLine (float value)
698                 {
699                         OutputTabs ();
700                         b.WriteLine (value);
701                         newline = true;
702                 }
703         
704                 public void WriteLineNoTabs (string s)
705                 {
706                         b.WriteLine (s);
707                         newline = true;
708                 }
709
710                 public override Encoding Encoding {
711                         get {
712                                 return b.Encoding;      
713                         }
714                 }
715
716                 int indent;
717                 public int Indent {
718                         get {
719                                 return indent;
720                         }
721                         set {
722                                 indent = value;
723                         }
724                 }
725         
726                 public System.IO.TextWriter InnerWriter {
727                         get {
728                                 return b;
729                         }
730                         set {
731                                 b = value;
732                         }       
733                 }
734         
735                 public override string NewLine {
736                         get {
737                                 return b.NewLine;
738                         }
739                         set {
740                                 b.NewLine = value;
741                         }
742                 }
743         
744                 protected HtmlTextWriterTag TagKey {
745                         get {
746                                 if (tagstack_pos == -1)
747                                         throw new InvalidOperationException ();
748
749                                 return tagstack [tagstack_pos].key;
750                         }
751                         set {
752                                 tagstack [tagstack_pos].key = value;
753                                 tagstack [tagstack_pos].name = GetTagName (value);
754                         }
755                 }
756         
757                 protected string TagName {
758                         get {
759                                 if (tagstack_pos == -1)
760                                         throw new InvalidOperationException ();
761                                 
762                                 return tagstack [tagstack_pos].name;
763                         }
764                         set {
765                                 tagstack [tagstack_pos].name = value;
766                                 tagstack [tagstack_pos].key = GetTagKey (value);
767                                 if (tagstack [tagstack_pos].key != HtmlTextWriterTag.Unknown)
768                                         tagstack [tagstack_pos].name = GetTagName (tagstack [tagstack_pos].key);
769                         }
770                 }
771                 
772
773                 TextWriter b;
774                 string tab_string;
775                 bool newline;
776                 
777                 //
778                 // These emulate generic Stack <T>, since we can't use that ;-(. _pos is the current
779                 // element.IE, you edit blah [blah_pos]. I *really* want generics, sigh.
780                 //
781                 AddedStyle [] styles;
782                 AddedAttr [] attrs;
783                 AddedTag [] tagstack;
784
785                 int styles_pos = -1, attrs_pos = -1, tagstack_pos = -1;
786                 
787                 struct AddedTag {
788                         public string name;
789                         public HtmlTextWriterTag key;
790                 }
791                 
792                 struct AddedStyle {
793                         public string name;
794                         public HtmlTextWriterStyle key;
795                         public string value;
796                 }
797                 
798                 struct AddedAttr {
799                         public string name;
800                         public HtmlTextWriterAttribute key;
801                         public string value;
802                 }
803
804                 void NextStyleStack ()
805                 {
806                         if (styles == null)
807                                 styles = new AddedStyle [16];
808                                 
809                         if (++styles_pos < styles.Length)
810                                 return;
811                         
812                         int nsize = styles.Length * 2;
813                         AddedStyle [] ncontents = new AddedStyle [nsize];
814
815                         Array.Copy (styles, ncontents, styles.Length);
816                         styles = ncontents;
817                 }
818
819                 void NextAttrStack ()
820                 {
821                         if (attrs == null)
822                                 attrs = new AddedAttr [16];
823                                 
824                         if (++attrs_pos < attrs.Length)
825                                 return;
826                         
827                         int nsize = attrs.Length * 2;
828                         AddedAttr [] ncontents = new AddedAttr [nsize];
829
830                         Array.Copy (attrs, ncontents, attrs.Length);
831                         attrs = ncontents;
832                 }
833
834                 void NextTagStack ()
835                 {
836                         if (tagstack == null)
837                                 tagstack = new AddedTag [16];
838                                 
839                         if (++tagstack_pos < tagstack.Length)
840                                 return;
841                                                 
842                         int nsize = tagstack.Length * 2;
843                         AddedTag [] ncontents = new AddedTag [nsize];
844
845                         Array.Copy (tagstack, ncontents, tagstack.Length);
846                         tagstack = ncontents;
847                 }
848         
849                 public const string DefaultTabString = "\t";
850                 public const char DoubleQuoteChar = '"';
851                 public const string EndTagLeftChars = "</";
852                 public const char EqualsChar = '=';
853                 public const string EqualsDoubleQuoteString = "=\"";
854                 public const string SelfClosingChars = " /";
855                 public const string SelfClosingTagEnd = " />";
856                 public const char SemicolonChar = ';';
857                 public const char SingleQuoteChar = '\'';
858                 public const char SlashChar = '/';
859                 public const char SpaceChar = ' ' ;
860                 public const char StyleEqualsChar = ':';
861                 public const char TagLeftChar = '<';
862                 public const char TagRightChar = '>';
863
864                 enum TagType {
865                         Block,
866                         Inline,
867                         SelfClosing,
868                 }
869                 
870                 
871                 struct HtmlTag {
872                         public HtmlTextWriterTag key;
873                         public string name;
874                         public TagType tag_type;
875
876                         public HtmlTag (HtmlTextWriterTag k, string n, TagType tt)
877                         {
878                                 key = k;
879                                 name = n;
880                                 tag_type = tt;
881                         }
882                 }
883
884                 struct HtmlStyle {
885                         public HtmlTextWriterStyle key;
886                         public string name;
887                         
888                         public HtmlStyle (HtmlTextWriterStyle k, string n)
889                         {
890                                 key = k;
891                                 name = n;
892                         }
893                 }
894
895                 
896                 struct HtmlAttribute {
897                         public HtmlTextWriterAttribute key;
898                         public string name;
899
900                         public HtmlAttribute (HtmlTextWriterAttribute k, string n)
901                         {
902                                 key = k;
903                                 name = n;
904                         }
905                 }
906                 
907                 static HtmlTag [] tags = {
908                         new HtmlTag (HtmlTextWriterTag.Unknown,    "",                  TagType.Block),
909                         new HtmlTag (HtmlTextWriterTag.A,          "a",                 TagType.Inline),
910                         new HtmlTag (HtmlTextWriterTag.Acronym,    "acronym",           TagType.Inline),
911                         new HtmlTag (HtmlTextWriterTag.Address,    "address",           TagType.Block),
912                         new HtmlTag (HtmlTextWriterTag.Area,       "area",              TagType.Block),
913                         new HtmlTag (HtmlTextWriterTag.B,          "b",                 TagType.Inline),
914                         new HtmlTag (HtmlTextWriterTag.Base,       "base",              TagType.SelfClosing),
915                         new HtmlTag (HtmlTextWriterTag.Basefont,   "basefont",          TagType.SelfClosing),
916                         new HtmlTag (HtmlTextWriterTag.Bdo,        "bdo",               TagType.Inline),
917                         new HtmlTag (HtmlTextWriterTag.Bgsound,    "bgsound",           TagType.SelfClosing),
918                         new HtmlTag (HtmlTextWriterTag.Big,        "big",               TagType.Inline),
919                         new HtmlTag (HtmlTextWriterTag.Blockquote, "blockquote",        TagType.Block),
920                         new HtmlTag (HtmlTextWriterTag.Body,       "body",              TagType.Block),
921                         new HtmlTag (HtmlTextWriterTag.Br,         "br",                TagType.Block),
922                         new HtmlTag (HtmlTextWriterTag.Button,     "button",            TagType.Inline),
923                         new HtmlTag (HtmlTextWriterTag.Caption,    "caption",           TagType.Block),
924                         new HtmlTag (HtmlTextWriterTag.Center,     "center",            TagType.Block),
925                         new HtmlTag (HtmlTextWriterTag.Cite,       "cite",              TagType.Inline),
926                         new HtmlTag (HtmlTextWriterTag.Code,       "code",              TagType.Inline),
927                         new HtmlTag (HtmlTextWriterTag.Col,        "col",               TagType.SelfClosing),
928                         new HtmlTag (HtmlTextWriterTag.Colgroup,   "colgroup",          TagType.Block),
929                         new HtmlTag (HtmlTextWriterTag.Dd,         "dd",                TagType.Inline),
930                         new HtmlTag (HtmlTextWriterTag.Del,        "del",               TagType.Inline),
931                         new HtmlTag (HtmlTextWriterTag.Dfn,        "dfn",               TagType.Inline),
932                         new HtmlTag (HtmlTextWriterTag.Dir,        "dir",               TagType.Block),
933                         new HtmlTag (HtmlTextWriterTag.Div,        "div",               TagType.Block),
934                         new HtmlTag (HtmlTextWriterTag.Dl,         "dl",                TagType.Block),
935                         new HtmlTag (HtmlTextWriterTag.Dt,         "dt",                TagType.Inline),
936                         new HtmlTag (HtmlTextWriterTag.Em,         "em",                TagType.Inline),
937                         new HtmlTag (HtmlTextWriterTag.Embed,      "embed",             TagType.SelfClosing),
938                         new HtmlTag (HtmlTextWriterTag.Fieldset,   "fieldset",          TagType.Block),
939                         new HtmlTag (HtmlTextWriterTag.Font,       "font",              TagType.Inline),
940                         new HtmlTag (HtmlTextWriterTag.Form,       "form",              TagType.Block),
941                         new HtmlTag (HtmlTextWriterTag.Frame,      "frame",             TagType.SelfClosing),
942                         new HtmlTag (HtmlTextWriterTag.Frameset,   "frameset",          TagType.Block),
943                         new HtmlTag (HtmlTextWriterTag.H1,         "h1",                TagType.Block),
944                         new HtmlTag (HtmlTextWriterTag.H2,         "h2",                TagType.Block),
945                         new HtmlTag (HtmlTextWriterTag.H3,         "h3",                TagType.Block),
946                         new HtmlTag (HtmlTextWriterTag.H4,         "h4",                TagType.Block),
947                         new HtmlTag (HtmlTextWriterTag.H5,         "h5",                TagType.Block),
948                         new HtmlTag (HtmlTextWriterTag.H6,         "h6",                TagType.Block),
949                         new HtmlTag (HtmlTextWriterTag.Head,       "head",              TagType.Block),
950                         new HtmlTag (HtmlTextWriterTag.Hr,         "hr",                TagType.SelfClosing),
951                         new HtmlTag (HtmlTextWriterTag.Html,       "html",              TagType.Block),
952                         new HtmlTag (HtmlTextWriterTag.I,          "i",                 TagType.Inline),
953                         new HtmlTag (HtmlTextWriterTag.Iframe,     "iframe",            TagType.Block),
954                         new HtmlTag (HtmlTextWriterTag.Img,        "img",               TagType.SelfClosing),
955                         new HtmlTag (HtmlTextWriterTag.Input,      "input",             TagType.SelfClosing),
956                         new HtmlTag (HtmlTextWriterTag.Ins,        "ins",               TagType.Inline),
957                         new HtmlTag (HtmlTextWriterTag.Isindex,    "isindex",           TagType.SelfClosing),
958                         new HtmlTag (HtmlTextWriterTag.Kbd,        "kbd",               TagType.Inline),
959                         new HtmlTag (HtmlTextWriterTag.Label,      "label",             TagType.Inline),
960                         new HtmlTag (HtmlTextWriterTag.Legend,     "legend",            TagType.Block),
961                         new HtmlTag (HtmlTextWriterTag.Li,         "li",                TagType.Inline),
962                         new HtmlTag (HtmlTextWriterTag.Link,       "link",              TagType.SelfClosing),
963                         new HtmlTag (HtmlTextWriterTag.Map,        "map",               TagType.Block),
964                         new HtmlTag (HtmlTextWriterTag.Marquee,    "marquee",           TagType.Block),
965                         new HtmlTag (HtmlTextWriterTag.Menu,       "menu",              TagType.Block),
966                         new HtmlTag (HtmlTextWriterTag.Meta,       "meta",              TagType.SelfClosing),
967                         new HtmlTag (HtmlTextWriterTag.Nobr,       "nobr",              TagType.Inline),
968                         new HtmlTag (HtmlTextWriterTag.Noframes,   "noframes",          TagType.Block),
969                         new HtmlTag (HtmlTextWriterTag.Noscript,   "noscript",          TagType.Block),
970                         new HtmlTag (HtmlTextWriterTag.Object,     "object",            TagType.Block),
971                         new HtmlTag (HtmlTextWriterTag.Ol,         "ol",                TagType.Block),
972                         new HtmlTag (HtmlTextWriterTag.Option,     "option",            TagType.Block),
973                         new HtmlTag (HtmlTextWriterTag.P,          "p",                 TagType.Inline),
974                         new HtmlTag (HtmlTextWriterTag.Param,      "param",             TagType.Block),
975                         new HtmlTag (HtmlTextWriterTag.Pre,        "pre",               TagType.Block),
976                         new HtmlTag (HtmlTextWriterTag.Q,          "q",                 TagType.Inline),
977                         new HtmlTag (HtmlTextWriterTag.Rt,         "rt",                TagType.Block),
978                         new HtmlTag (HtmlTextWriterTag.Ruby,       "ruby",              TagType.Block),
979                         new HtmlTag (HtmlTextWriterTag.S,          "s",                 TagType.Inline),
980                         new HtmlTag (HtmlTextWriterTag.Samp,       "samp",              TagType.Inline),
981                         new HtmlTag (HtmlTextWriterTag.Script,     "script",            TagType.Block),
982                         new HtmlTag (HtmlTextWriterTag.Select,     "select",            TagType.Block),
983                         new HtmlTag (HtmlTextWriterTag.Small,      "small",             TagType.Block),
984                         new HtmlTag (HtmlTextWriterTag.Span,       "span",              TagType.Inline),
985                         new HtmlTag (HtmlTextWriterTag.Strike,     "strike",            TagType.Inline),
986                         new HtmlTag (HtmlTextWriterTag.Strong,     "strong",            TagType.Inline),
987                         new HtmlTag (HtmlTextWriterTag.Style,      "style",             TagType.Block),
988                         new HtmlTag (HtmlTextWriterTag.Sub,        "sub",               TagType.Inline),
989                         new HtmlTag (HtmlTextWriterTag.Sup,        "sup",               TagType.Inline),
990                         new HtmlTag (HtmlTextWriterTag.Table,      "table",             TagType.Block),
991                         new HtmlTag (HtmlTextWriterTag.Tbody,      "tbody",             TagType.Block),
992                         new HtmlTag (HtmlTextWriterTag.Td,         "td",                TagType.Inline),
993                         new HtmlTag (HtmlTextWriterTag.Textarea,   "textarea",          TagType.Inline),
994                         new HtmlTag (HtmlTextWriterTag.Tfoot,      "tfoot",             TagType.Block),
995                         new HtmlTag (HtmlTextWriterTag.Th,         "th",                TagType.Inline),
996                         new HtmlTag (HtmlTextWriterTag.Thead,      "thead",             TagType.Block),
997                         new HtmlTag (HtmlTextWriterTag.Title,      "title",             TagType.Block),
998                         new HtmlTag (HtmlTextWriterTag.Tr,         "tr",                TagType.Block),
999                         new HtmlTag (HtmlTextWriterTag.Tt,         "tt",                TagType.Inline),
1000                         new HtmlTag (HtmlTextWriterTag.U,          "u",                 TagType.Inline),
1001                         new HtmlTag (HtmlTextWriterTag.Ul,         "ul",                TagType.Block),
1002                         new HtmlTag (HtmlTextWriterTag.Var,        "var",               TagType.Inline),
1003                         new HtmlTag (HtmlTextWriterTag.Wbr,        "wbr",               TagType.SelfClosing),
1004                         new HtmlTag (HtmlTextWriterTag.Xml,        "xml",               TagType.Block),
1005                 };
1006
1007                 static HtmlAttribute [] htmlattrs = {
1008                         new HtmlAttribute (HtmlTextWriterAttribute.Accesskey,         "accesskey"),
1009                         new HtmlAttribute (HtmlTextWriterAttribute.Align,             "align"),
1010                         new HtmlAttribute (HtmlTextWriterAttribute.Alt,               "alt"),
1011                         new HtmlAttribute (HtmlTextWriterAttribute.Background,        "background"),
1012                         new HtmlAttribute (HtmlTextWriterAttribute.Bgcolor,           "bgcolor"),
1013                         new HtmlAttribute (HtmlTextWriterAttribute.Border,            "border"),
1014                         new HtmlAttribute (HtmlTextWriterAttribute.Bordercolor,       "bordercolor"),
1015                         new HtmlAttribute (HtmlTextWriterAttribute.Cellpadding,       "cellpadding"),
1016                         new HtmlAttribute (HtmlTextWriterAttribute.Cellspacing,       "cellspacing"),
1017                         new HtmlAttribute (HtmlTextWriterAttribute.Checked,           "checked"),
1018                         new HtmlAttribute (HtmlTextWriterAttribute.Class,             "class"),
1019                         new HtmlAttribute (HtmlTextWriterAttribute.Cols,              "cols"),
1020                         new HtmlAttribute (HtmlTextWriterAttribute.Colspan,           "colspan"),
1021                         new HtmlAttribute (HtmlTextWriterAttribute.Disabled,          "disabled"),
1022                         new HtmlAttribute (HtmlTextWriterAttribute.For,               "for"),
1023                         new HtmlAttribute (HtmlTextWriterAttribute.Height,            "height"),
1024                         new HtmlAttribute (HtmlTextWriterAttribute.Href,              "href"),
1025                         new HtmlAttribute (HtmlTextWriterAttribute.Id,                "id"),
1026                         new HtmlAttribute (HtmlTextWriterAttribute.Maxlength,         "maxlength"),
1027                         new HtmlAttribute (HtmlTextWriterAttribute.Multiple,          "multiple"),
1028                         new HtmlAttribute (HtmlTextWriterAttribute.Name,              "name"),
1029                         new HtmlAttribute (HtmlTextWriterAttribute.Nowrap,            "nowrap"),
1030                         new HtmlAttribute (HtmlTextWriterAttribute.Onchange,          "onchange"),
1031                         new HtmlAttribute (HtmlTextWriterAttribute.Onclick,           "onclick"),
1032                         new HtmlAttribute (HtmlTextWriterAttribute.ReadOnly,          "readonly"),
1033                         new HtmlAttribute (HtmlTextWriterAttribute.Rows,              "rows"),
1034                         new HtmlAttribute (HtmlTextWriterAttribute.Rowspan,           "rowspan"),
1035                         new HtmlAttribute (HtmlTextWriterAttribute.Rules,             "rules"),
1036                         new HtmlAttribute (HtmlTextWriterAttribute.Selected,          "selected"),
1037                         new HtmlAttribute (HtmlTextWriterAttribute.Size,              "size"),
1038                         new HtmlAttribute (HtmlTextWriterAttribute.Src,               "src"),
1039                         new HtmlAttribute (HtmlTextWriterAttribute.Style,             "style"),
1040                         new HtmlAttribute (HtmlTextWriterAttribute.Tabindex,          "tabindex"),
1041                         new HtmlAttribute (HtmlTextWriterAttribute.Target,            "target"),
1042                         new HtmlAttribute (HtmlTextWriterAttribute.Title,             "title"),
1043                         new HtmlAttribute (HtmlTextWriterAttribute.Type,              "type"),
1044                         new HtmlAttribute (HtmlTextWriterAttribute.Valign,            "valign"),
1045                         new HtmlAttribute (HtmlTextWriterAttribute.Value,             "value"),
1046                         new HtmlAttribute (HtmlTextWriterAttribute.Width,             "width"),
1047                         new HtmlAttribute (HtmlTextWriterAttribute.Wrap,              "wrap"),
1048 #if NET_2_0
1049                         new HtmlAttribute (HtmlTextWriterAttribute.Abbr,              "abbr"),
1050                         new HtmlAttribute (HtmlTextWriterAttribute.AutoComplete,      "autocomplete"),
1051                         new HtmlAttribute (HtmlTextWriterAttribute.Axis,              "axis"),
1052                         new HtmlAttribute (HtmlTextWriterAttribute.Content,           "content"),
1053                         new HtmlAttribute (HtmlTextWriterAttribute.Coords,            "coords"),
1054                         new HtmlAttribute (HtmlTextWriterAttribute.DesignerRegion,    "_designerregion"),
1055                         new HtmlAttribute (HtmlTextWriterAttribute.Dir,               "dir"),
1056                         new HtmlAttribute (HtmlTextWriterAttribute.Headers,           "headers"),
1057                         new HtmlAttribute (HtmlTextWriterAttribute.Longdesc,          "longdesc"),
1058                         new HtmlAttribute (HtmlTextWriterAttribute.Rel,               "rel"),
1059                         new HtmlAttribute (HtmlTextWriterAttribute.Scope,             "scope"),
1060                         new HtmlAttribute (HtmlTextWriterAttribute.Shape,             "shape"),
1061                         new HtmlAttribute (HtmlTextWriterAttribute.Usemap,            "usemap"),
1062                         new HtmlAttribute (HtmlTextWriterAttribute.VCardName,         "vcard_name"),
1063 #endif
1064                 };
1065
1066                 static HtmlStyle [] htmlstyles = {
1067                         new HtmlStyle (HtmlTextWriterStyle.BackgroundColor,    "background-color"),
1068                         new HtmlStyle (HtmlTextWriterStyle.BackgroundImage,    "background-image"),
1069                         new HtmlStyle (HtmlTextWriterStyle.BorderCollapse,     "border-collapse"),
1070                         new HtmlStyle (HtmlTextWriterStyle.BorderColor,        "border-color"),
1071                         new HtmlStyle (HtmlTextWriterStyle.BorderStyle,        "border-style"),
1072                         new HtmlStyle (HtmlTextWriterStyle.BorderWidth,        "border-width"),
1073                         new HtmlStyle (HtmlTextWriterStyle.Color,              "color"),
1074                         new HtmlStyle (HtmlTextWriterStyle.FontFamily,         "font-family"),
1075                         new HtmlStyle (HtmlTextWriterStyle.FontSize,           "font-size"),
1076                         new HtmlStyle (HtmlTextWriterStyle.FontStyle,          "font-style"),
1077                         new HtmlStyle (HtmlTextWriterStyle.FontWeight,         "font-weight"),
1078                         new HtmlStyle (HtmlTextWriterStyle.Height,             "height"),
1079                         new HtmlStyle (HtmlTextWriterStyle.TextDecoration,     "text-decoration"),
1080                         new HtmlStyle (HtmlTextWriterStyle.Width,              "width"),
1081 #if NET_2_0
1082                         new HtmlStyle (HtmlTextWriterStyle.ListStyleImage,     "list-style-image"),
1083                         new HtmlStyle (HtmlTextWriterStyle.ListStyleType,      "list-style-type"),
1084                         new HtmlStyle (HtmlTextWriterStyle.Cursor,             "cursor"),
1085                         new HtmlStyle (HtmlTextWriterStyle.Direction,          "direction"),
1086                         new HtmlStyle (HtmlTextWriterStyle.Display,            "display"),
1087                         new HtmlStyle (HtmlTextWriterStyle.Filter,             "filter"),
1088                         new HtmlStyle (HtmlTextWriterStyle.FontVariant,        "font-variant"),
1089                         new HtmlStyle (HtmlTextWriterStyle.Left,               "left"),
1090                         new HtmlStyle (HtmlTextWriterStyle.Margin,             "margin"),
1091                         new HtmlStyle (HtmlTextWriterStyle.MarginBottom,       "margin-bottom"),
1092                         new HtmlStyle (HtmlTextWriterStyle.MarginLeft,         "margin-left"),
1093                         new HtmlStyle (HtmlTextWriterStyle.MarginRight,        "margin-right"),
1094                         new HtmlStyle (HtmlTextWriterStyle.MarginTop,          "margin-top"),
1095                         new HtmlStyle (HtmlTextWriterStyle.Overflow,           "overflow"),
1096                         new HtmlStyle (HtmlTextWriterStyle.OverflowX,          "overflow-x"),
1097                         new HtmlStyle (HtmlTextWriterStyle.OverflowY,          "overflow-y"),
1098                         new HtmlStyle (HtmlTextWriterStyle.Padding,            "padding"),
1099                         new HtmlStyle (HtmlTextWriterStyle.PaddingBottom,      "padding-bottom"),
1100                         new HtmlStyle (HtmlTextWriterStyle.PaddingLeft,        "padding-left"),
1101                         new HtmlStyle (HtmlTextWriterStyle.PaddingRight,       "padding-right"),
1102                         new HtmlStyle (HtmlTextWriterStyle.PaddingTop,         "padding-top"),
1103                         new HtmlStyle (HtmlTextWriterStyle.Position,           "position"),
1104                         new HtmlStyle (HtmlTextWriterStyle.TextAlign,          "text-align"),
1105                         new HtmlStyle (HtmlTextWriterStyle.VerticalAlign,      "vertical-align"),
1106                         new HtmlStyle (HtmlTextWriterStyle.TextOverflow,       "text-overflow"),
1107                         new HtmlStyle (HtmlTextWriterStyle.Top,                "top"),
1108                         new HtmlStyle (HtmlTextWriterStyle.Visibility,         "visibility"),
1109                         new HtmlStyle (HtmlTextWriterStyle.WhiteSpace,         "white-space"),
1110                         new HtmlStyle (HtmlTextWriterStyle.ZIndex,             "z-index"),
1111 #endif
1112                 };
1113         }
1114 }