1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
---|
2 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
3 | * Version: NPL 1.1/GPL 2.0/LGPL 2.1 |
---|
4 | * |
---|
5 | * The contents of this file are subject to the Netscape Public License |
---|
6 | * Version 1.1 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. You may obtain a copy of the License at |
---|
8 | * http://www.mozilla.org/NPL/ |
---|
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.org 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 | * |
---|
25 | * Alternatively, the contents of this file may be used under the terms of |
---|
26 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
---|
27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
---|
28 | * in which case the provisions of the GPL or the LGPL are applicable instead |
---|
29 | * of those above. If you wish to allow use of your version of this file only |
---|
30 | * under the terms of either the GPL or the LGPL, and not to allow others to |
---|
31 | * use your version of this file under the terms of the NPL, indicate your |
---|
32 | * decision by deleting the provisions above and replace them with the notice |
---|
33 | * and other provisions required by the GPL or the LGPL. If you do not delete |
---|
34 | * the provisions above, a recipient may use your version of this file under |
---|
35 | * the terms of any one of the NPL, the GPL or the LGPL. |
---|
36 | * |
---|
37 | * ***** END LICENSE BLOCK ***** */ |
---|
38 | |
---|
39 | |
---|
40 | /** |
---|
41 | * MODULE NOTES: |
---|
42 | * @update gess 4/1/98 |
---|
43 | * |
---|
44 | */ |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | #ifndef _NSELEMENTABLE |
---|
49 | #define _NSELEMENTABLE |
---|
50 | |
---|
51 | #include "nsHTMLTokens.h" |
---|
52 | #include "nsDTDUtils.h" |
---|
53 | |
---|
54 | |
---|
55 | //********************************************************************************************* |
---|
56 | // The following ints define the standard groups of HTML elements... |
---|
57 | //********************************************************************************************* |
---|
58 | |
---|
59 | static const int kNone= 0x0; |
---|
60 | |
---|
61 | static const int kHTMLContent = 0x0001; // HEAD, (FRAMESET | BODY) |
---|
62 | static const int kHeadContent = 0x0002; // TITLE, ISINDEX, BASE |
---|
63 | static const int kHeadMisc = 0x0004; // SCRIPT, STYLE, META, LINK, OBJECT |
---|
64 | |
---|
65 | static const int kSpecial = 0x0008; // A, IMG, APPLET, OBJECT, FONT, BASEFONT, BR, SCRIPT, |
---|
66 | // MAP, Q, SUB, SUP, SPAN, BDO, IFRAME |
---|
67 | |
---|
68 | static const int kFormControl = 0x0010; // INPUT SELECT TEXTAREA LABEL BUTTON |
---|
69 | static const int kPreformatted = 0x0020; // PRE |
---|
70 | static const int kPreExclusion = 0x0040; // IMG, OBJECT, APPLET, BIG, SMALL, SUB, SUP, FONT, BASEFONT |
---|
71 | static const int kFontStyle = 0x0080; // TT, I, B, U, S, STRIKE, BIG, SMALL, BLINK |
---|
72 | static const int kPhrase = 0x0100; // EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM |
---|
73 | static const int kHeading = 0x0200; // H1..H6 |
---|
74 | static const int kBlockMisc = 0x0400; // OBJECT, SCRIPT |
---|
75 | static const int kBlock = 0x0800; // ADDRESS, BLOCKQUOTE, CENTER, DIV, DL, FIELDSET, FORM, |
---|
76 | // ISINDEX, HR, NOSCRIPT, NOFRAMES, P, TABLE |
---|
77 | static const int kList = 0x1000; // UL, OL, DIR, MENU |
---|
78 | static const int kPCDATA = 0x2000; // plain text and entities... |
---|
79 | static const int kSelf = 0x4000; // whatever THIS tag is... |
---|
80 | static const int kExtensions = 0x8000; // BGSOUND, WBR, NOBR |
---|
81 | static const int kTable = 0x10000;// TR,TD,THEAD,TBODY,TFOOT,CAPTION,TH |
---|
82 | static const int kDLChild = 0x20000;// DL, DT |
---|
83 | static const int kCDATA = 0x40000;// just plain text... |
---|
84 | |
---|
85 | static const int kInlineEntity = (kPCDATA|kFontStyle|kPhrase|kSpecial|kFormControl|kExtensions); // #PCDATA, %fontstyle, %phrase, %special, %formctrl |
---|
86 | static const int kBlockEntity = (kHeading|kList|kPreformatted|kBlock); // %heading, %list, %preformatted, %block |
---|
87 | static const int kFlowEntity = (kBlockEntity|kInlineEntity); // %blockentity, %inlineentity |
---|
88 | static const int kAllTags = 0xffffff; |
---|
89 | |
---|
90 | |
---|
91 | //********************************************************************************************* |
---|
92 | // The following ints define the standard groups of HTML elements... |
---|
93 | //********************************************************************************************* |
---|
94 | |
---|
95 | |
---|
96 | extern void InitializeElementTable(void); |
---|
97 | extern void DeleteElementTable(void); |
---|
98 | |
---|
99 | typedef PRBool (*ContainFunc)(eHTMLTags aTag,nsDTDContext &aContext); |
---|
100 | |
---|
101 | |
---|
102 | /** |
---|
103 | * We're asking the question: is aTest a member of bitset. |
---|
104 | * |
---|
105 | * @update gess 01/04/99 |
---|
106 | * @param |
---|
107 | * @return TRUE or FALSE |
---|
108 | */ |
---|
109 | inline PRBool TestBits(int aBitset,int aTest) { |
---|
110 | if(aTest) { |
---|
111 | PRInt32 result=(aBitset & aTest); |
---|
112 | return PRBool(result==aTest); |
---|
113 | } |
---|
114 | return PR_FALSE; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | /** |
---|
119 | * |
---|
120 | * @update gess 01/04/99 |
---|
121 | * @param |
---|
122 | * @return |
---|
123 | */ |
---|
124 | struct nsHTMLElement { |
---|
125 | |
---|
126 | #ifdef DEBUG |
---|
127 | static void DebugDumpMembership(const char* aFilename); |
---|
128 | static void DebugDumpContainment(const char* aFilename,const char* aTitle); |
---|
129 | static void DebugDumpContainType(const char* aFilename); |
---|
130 | #endif |
---|
131 | |
---|
132 | static PRBool IsInlineEntity(eHTMLTags aTag); |
---|
133 | static PRBool IsFlowEntity(eHTMLTags aTag); |
---|
134 | static PRBool IsBlockCloser(eHTMLTags aTag); |
---|
135 | |
---|
136 | inline PRBool IsBlock(void) { |
---|
137 | if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){ |
---|
138 | return TestBits(mParentBits,kBlock); |
---|
139 | } |
---|
140 | return PR_FALSE; |
---|
141 | } |
---|
142 | |
---|
143 | inline PRBool IsBlockEntity(void) { |
---|
144 | if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){ |
---|
145 | return TestBits(mParentBits,kBlockEntity); |
---|
146 | } |
---|
147 | return PR_FALSE; |
---|
148 | } |
---|
149 | |
---|
150 | inline PRBool IsSpecialEntity(void) { |
---|
151 | if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){ |
---|
152 | return TestBits(mParentBits,kSpecial); |
---|
153 | } |
---|
154 | return PR_FALSE; |
---|
155 | } |
---|
156 | |
---|
157 | inline PRBool IsPhraseEntity(void) { |
---|
158 | if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){ |
---|
159 | return TestBits(mParentBits,kPhrase); |
---|
160 | } |
---|
161 | return PR_FALSE; |
---|
162 | } |
---|
163 | |
---|
164 | inline PRBool IsFontStyleEntity(void) { |
---|
165 | if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){ |
---|
166 | return TestBits(mParentBits,kFontStyle); |
---|
167 | } |
---|
168 | return PR_FALSE; |
---|
169 | } |
---|
170 | |
---|
171 | inline PRBool IsTableElement(void) { //return yes if it's a table or child of a table... |
---|
172 | PRBool result=PR_FALSE; |
---|
173 | |
---|
174 | switch(mTagID) { |
---|
175 | case eHTMLTag_table: |
---|
176 | case eHTMLTag_thead: |
---|
177 | case eHTMLTag_tbody: |
---|
178 | case eHTMLTag_tfoot: |
---|
179 | case eHTMLTag_caption: |
---|
180 | case eHTMLTag_tr: |
---|
181 | case eHTMLTag_td: |
---|
182 | case eHTMLTag_th: |
---|
183 | case eHTMLTag_col: |
---|
184 | case eHTMLTag_colgroup: |
---|
185 | result=PR_TRUE; |
---|
186 | break; |
---|
187 | default: |
---|
188 | result=PR_FALSE; |
---|
189 | } |
---|
190 | return result; |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | static int GetSynonymousGroups(eHTMLTags aTag); |
---|
195 | |
---|
196 | static PRInt32 GetIndexOfChildOrSynonym(nsDTDContext& aContext,eHTMLTags aChildTag); |
---|
197 | |
---|
198 | const TagList* GetSynonymousTags(void) const {return mSynonymousTags;} |
---|
199 | const TagList* GetRootTags(void) const {return mRootNodes;} |
---|
200 | const TagList* GetEndRootTags(void) const {return mEndRootNodes;} |
---|
201 | const TagList* GetAutoCloseStartTags(void) const {return mAutocloseStart;} |
---|
202 | const TagList* GetAutoCloseEndTags(void) const {return mAutocloseEnd;} |
---|
203 | eHTMLTags GetCloseTargetForEndTag(nsDTDContext& aContext,PRInt32 anIndex,nsDTDMode aMode) const; |
---|
204 | |
---|
205 | const TagList* GetSpecialChildren(void) const {return mSpecialKids;} |
---|
206 | const TagList* GetSpecialParents(void) const {return mSpecialParents;} |
---|
207 | |
---|
208 | PRBool IsMemberOf(PRInt32 aType) const; |
---|
209 | PRBool ContainsSet(PRInt32 aType) const; |
---|
210 | PRBool CanContainType(PRInt32 aType) const; |
---|
211 | |
---|
212 | eHTMLTags GetTag(void) const {return mTagID;} |
---|
213 | PRBool CanContain(eHTMLTags aChild,nsDTDMode aMode) const; |
---|
214 | PRBool CanExclude(eHTMLTags aChild) const; |
---|
215 | PRBool CanOmitStartTag(eHTMLTags aChild) const; |
---|
216 | PRBool CanOmitEndTag(void) const; |
---|
217 | PRBool CanContainSelf(void) const; |
---|
218 | PRBool CanAutoCloseTag(nsDTDContext& aContext,eHTMLTags aTag) const; |
---|
219 | PRBool HasSpecialProperty(PRInt32 aProperty) const; |
---|
220 | PRBool IsSpecialParent(eHTMLTags aTag) const; |
---|
221 | PRBool IsExcludableParent(eHTMLTags aParent) const; |
---|
222 | PRBool SectionContains(eHTMLTags aTag,PRBool allowDepthSearch); |
---|
223 | PRBool ShouldVerifyHierarchy(); |
---|
224 | |
---|
225 | PRBool CanBeContained(eHTMLTags aParentTag,nsDTDContext &aContext); //default version |
---|
226 | |
---|
227 | static PRBool CanContain(eHTMLTags aParent,eHTMLTags aChild,nsDTDMode aMode); |
---|
228 | static PRBool IsContainer(eHTMLTags aTag) ; |
---|
229 | static PRBool IsResidualStyleTag(eHTMLTags aTag) ; |
---|
230 | static PRBool IsTextTag(eHTMLTags aTag); |
---|
231 | static PRBool IsWhitespaceTag(eHTMLTags aTag); |
---|
232 | |
---|
233 | static PRBool IsBlockParent(eHTMLTags aTag); |
---|
234 | static PRBool IsInlineParent(eHTMLTags aTag); |
---|
235 | static PRBool IsFlowParent(eHTMLTags aTag); |
---|
236 | static PRBool IsSectionTag(eHTMLTags aTag); |
---|
237 | static PRBool IsChildOfHead(eHTMLTags aTag,PRBool& aExclusively) ; |
---|
238 | |
---|
239 | eHTMLTags mTagID; |
---|
240 | eHTMLTags mRequiredAncestor; |
---|
241 | eHTMLTags mExcludingAncestor; //If set, the presence of the excl-ancestor prevents this from opening. |
---|
242 | const TagList* mRootNodes; //These are the tags above which you many not autoclose a START tag |
---|
243 | const TagList* mEndRootNodes; //These are the tags above which you many not autoclose an END tag |
---|
244 | const TagList* mAutocloseStart; //these are the start tags that you can automatically close with this START tag |
---|
245 | const TagList* mAutocloseEnd; //these are the start tags that you can automatically close with this END tag |
---|
246 | const TagList* mSynonymousTags; //These are morally equivalent; an end tag for one can close a start tag for another (like <Hn>) |
---|
247 | const TagList* mExcludableParents; //These are the TAGS that cannot contain you |
---|
248 | int mParentBits; //defines groups that can contain this element |
---|
249 | int mInclusionBits; //defines parental and containment rules |
---|
250 | int mExclusionBits; //defines things you CANNOT contain |
---|
251 | int mSpecialProperties; //used for various special purposes... |
---|
252 | PRUint32 mPropagateRange; //tells us how far a parent is willing to prop. badly formed children |
---|
253 | const TagList* mSpecialParents; //These are the special tags that contain this tag (directly) |
---|
254 | const TagList* mSpecialKids; //These are the extra things you can contain |
---|
255 | eHTMLTags mSkipTarget; //If set, then we skip all content until this tag is seen |
---|
256 | ContainFunc mCanBeContained; |
---|
257 | }; |
---|
258 | |
---|
259 | extern nsHTMLElement* gHTMLElements; |
---|
260 | |
---|
261 | //special property bits... |
---|
262 | static const int kDiscardTag = 0x0001; //tells us to toss this tag |
---|
263 | static const int kOmitEndTag = 0x0002; //safely ignore end tag |
---|
264 | static const int kLegalOpen = 0x0004; //Lets BODY, TITLE, SCRIPT to reopen |
---|
265 | static const int kOmitWS = 0x0008; //If set, the tag can omit all ws and newlines |
---|
266 | static const int kNoPropagate = 0x0010; //If set, this tag won't propagate as a child |
---|
267 | static const int kBadContentWatch = 0x0020; |
---|
268 | |
---|
269 | static const int kNoStyleLeaksIn = 0x0040; |
---|
270 | static const int kNoStyleLeaksOut = 0x0080; |
---|
271 | |
---|
272 | static const int kMustCloseSelf = 0x0100; |
---|
273 | static const int kSaveMisplaced = 0x0200; //If set, then children this tag can't contain are pushed onto the misplaced stack |
---|
274 | static const int kNonContainer = 0x0400; //If set, then this tag is not a container. |
---|
275 | static const int kHandleStrayTag = 0x0800; //If set, we automatically open a start tag |
---|
276 | static const int kRequiresBody = 0x1000; //If set, then in case of no BODY one will be opened up immediately. |
---|
277 | static const int kVerifyHierarchy = 0x2000; //If set, check to see if the tag is a child or a sibling.. |
---|
278 | |
---|
279 | #endif |
---|