1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsHTMLTags_h___
39 : #define nsHTMLTags_h___
40 :
41 : #include "nsStringGlue.h"
42 : #include "plhash.h"
43 :
44 : class nsIAtom;
45 :
46 : /*
47 : Declare the enum list using the magic of preprocessing
48 : enum values are "eHTMLTag_foo" (where foo is the tag)
49 :
50 : To change the list of tags, see nsHTMLTagList.h
51 :
52 : */
53 : #define HTML_TAG(_tag, _classname) eHTMLTag_##_tag,
54 : #define HTML_HTMLELEMENT_TAG(_tag) eHTMLTag_##_tag,
55 : #define HTML_OTHER(_tag) eHTMLTag_##_tag,
56 : enum nsHTMLTag {
57 : /* this enum must be first and must be zero */
58 : eHTMLTag_unknown = 0,
59 : #include "nsHTMLTagList.h"
60 :
61 : /* can't be moved into nsHTMLTagList since gcc3.4 doesn't like a
62 : comma at the end of enum list*/
63 : eHTMLTag_userdefined
64 : };
65 : #undef HTML_TAG
66 : #undef HTML_HTMLELEMENT_TAG
67 : #undef HTML_OTHER
68 :
69 : // All tags before eHTMLTag_text are HTML tags
70 : #define NS_HTML_TAG_MAX PRInt32(eHTMLTag_text - 1)
71 :
72 : class nsHTMLTags {
73 : public:
74 : static nsresult AddRefTable(void);
75 : static void ReleaseTable(void);
76 :
77 : // Functions for converting string or atom to id
78 : static nsHTMLTag LookupTag(const nsAString& aTagName);
79 97133 : static nsHTMLTag CaseSensitiveLookupTag(const PRUnichar* aTagName)
80 : {
81 97133 : NS_ASSERTION(gTagTable, "no lookup table, needs addref");
82 97133 : NS_ASSERTION(aTagName, "null tagname!");
83 :
84 97133 : void* tag = PL_HashTableLookupConst(gTagTable, aTagName);
85 :
86 97133 : return tag ? (nsHTMLTag)NS_PTR_TO_INT32(tag) : eHTMLTag_userdefined;
87 : }
88 33150 : static nsHTMLTag CaseSensitiveLookupTag(nsIAtom* aTagName)
89 : {
90 33150 : NS_ASSERTION(gTagAtomTable, "no lookup table, needs addref");
91 33150 : NS_ASSERTION(aTagName, "null tagname!");
92 :
93 33150 : void* tag = PL_HashTableLookupConst(gTagAtomTable, aTagName);
94 :
95 33150 : return tag ? (nsHTMLTag)NS_PTR_TO_INT32(tag) : eHTMLTag_userdefined;
96 : }
97 :
98 : // Functions for converting an id to a string or atom
99 32637 : static const PRUnichar *GetStringValue(nsHTMLTag aEnum)
100 : {
101 : return aEnum <= eHTMLTag_unknown || aEnum > NS_HTML_TAG_MAX ?
102 32637 : nsnull : sTagUnicodeTable[aEnum - 1];
103 : }
104 32612 : static nsIAtom *GetAtom(nsHTMLTag aEnum)
105 : {
106 : return aEnum <= eHTMLTag_unknown || aEnum > NS_HTML_TAG_MAX ?
107 32612 : nsnull : sTagAtomTable[aEnum - 1];
108 : }
109 :
110 : #ifdef DEBUG
111 : static void TestTagTable();
112 : #endif
113 :
114 : private:
115 : static nsIAtom* sTagAtomTable[eHTMLTag_userdefined - 1];
116 : static const PRUnichar* const sTagUnicodeTable[];
117 :
118 : static PRInt32 gTableRefCount;
119 : static PLHashTable* gTagTable;
120 : static PLHashTable* gTagAtomTable;
121 : };
122 :
123 : #define eHTMLTags nsHTMLTag
124 :
125 : #endif /* nsHTMLTags_h___ */
|