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
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/
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
15 * The Original Code is mozilla.org code.
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.
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.
36 * ***** END LICENSE BLOCK ***** */
47 #ifndef _NSELEMENTABLE
48 #define _NSELEMENTABLE
50 #include "nsHTMLTokens.h"
51 #include "nsDTDUtils.h"
54 //*********************************************************************************************
55 // The following ints define the standard groups of HTML elements...
56 //*********************************************************************************************
58 static const int kNone
= 0x0;
60 static const int kHTMLContent
= 0x0001; // HEAD, (FRAMESET | BODY)
61 static const int kHeadContent
= 0x0002; // Elements that *must* be in the head.
62 static const int kHeadMisc
= 0x0004; // Elements that *can* be in the head.
64 static const int kSpecial
= 0x0008; // A, IMG, APPLET, OBJECT, FONT, BASEFONT, BR, SCRIPT,
65 // MAP, Q, SUB, SUP, SPAN, BDO, IFRAME
67 static const int kFormControl
= 0x0010; // INPUT SELECT TEXTAREA LABEL BUTTON
68 static const int kPreformatted
= 0x0020; // PRE
69 static const int kPreExclusion
= 0x0040; // IMG, OBJECT, APPLET, BIG, SMALL, SUB, SUP, FONT, BASEFONT
70 static const int kFontStyle
= 0x0080; // TT, I, B, U, S, STRIKE, BIG, SMALL, BLINK
71 static const int kPhrase
= 0x0100; // EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM
72 static const int kHeading
= 0x0200; // H1..H6
73 static const int kBlockMisc
= 0x0400; // OBJECT, SCRIPT
74 static const int kBlock
= 0x0800; // ADDRESS, BLOCKQUOTE, CENTER, DIV, DL, FIELDSET, FORM,
75 // ISINDEX, HR, NOSCRIPT, NOFRAMES, P, TABLE
76 static const int kList
= 0x1000; // UL, OL, DIR, MENU
77 static const int kPCDATA
= 0x2000; // plain text and entities...
78 static const int kSelf
= 0x4000; // whatever THIS tag is...
79 static const int kExtensions
= 0x8000; // BGSOUND, WBR, NOBR
80 static const int kTable
= 0x10000;// TR,TD,THEAD,TBODY,TFOOT,CAPTION,TH
81 static const int kDLChild
= 0x20000;// DL, DT
82 static const int kCDATA
= 0x40000;// just plain text...
84 static const int kInlineEntity
= (kPCDATA
|kFontStyle
|kPhrase
|kSpecial
|kFormControl
|kExtensions
); // #PCDATA, %fontstyle, %phrase, %special, %formctrl
85 static const int kBlockEntity
= (kHeading
|kList
|kPreformatted
|kBlock
); // %heading, %list, %preformatted, %block
86 static const int kFlowEntity
= (kBlockEntity
|kInlineEntity
); // %blockentity, %inlineentity
87 static const int kAllTags
= 0xffffff;
90 //*********************************************************************************************
91 // The following ints define the standard groups of HTML elements...
92 //*********************************************************************************************
96 extern void CheckElementTable();
101 * We're asking the question: is aTest a member of bitset.
103 * @update gess 01/04/99
105 * @return TRUE or FALSE
107 inline PRBool
TestBits(int aBitset
,int aTest
) {
109 PRInt32 result
=(aBitset
& aTest
);
110 return PRBool(result
==aTest
);
118 * @update gess 01/04/99
122 struct nsHTMLElement
{
125 static void DebugDumpMembership(const char* aFilename
);
126 static void DebugDumpContainment(const char* aFilename
,const char* aTitle
);
127 static void DebugDumpContainType(const char* aFilename
);
130 static PRBool
IsInlineEntity(eHTMLTags aTag
);
131 static PRBool
IsFlowEntity(eHTMLTags aTag
);
132 static PRBool
IsBlockCloser(eHTMLTags aTag
);
134 inline PRBool
IsBlock(void) const {
135 if((mTagID
>=eHTMLTag_unknown
) & (mTagID
<=eHTMLTag_xmp
)){
136 return TestBits(mParentBits
,kBlock
);
141 inline PRBool
IsBlockEntity(void) const {
142 if((mTagID
>=eHTMLTag_unknown
) & (mTagID
<=eHTMLTag_xmp
)){
143 return TestBits(mParentBits
,kBlockEntity
);
148 inline PRBool
IsSpecialEntity(void) const {
149 if((mTagID
>=eHTMLTag_unknown
) & (mTagID
<=eHTMLTag_xmp
)){
150 return TestBits(mParentBits
,kSpecial
);
155 inline PRBool
IsPhraseEntity(void) const {
156 if((mTagID
>=eHTMLTag_unknown
) & (mTagID
<=eHTMLTag_xmp
)){
157 return TestBits(mParentBits
,kPhrase
);
162 inline PRBool
IsFontStyleEntity(void) const {
163 if((mTagID
>=eHTMLTag_unknown
) & (mTagID
<=eHTMLTag_xmp
)){
164 return TestBits(mParentBits
,kFontStyle
);
169 inline PRBool
IsTableElement(void) const { //return yes if it's a table or child of a table...
170 PRBool result
=PR_FALSE
;
177 case eHTMLTag_caption
:
182 case eHTMLTag_colgroup
:
192 static PRInt32
GetIndexOfChildOrSynonym(nsDTDContext
& aContext
,eHTMLTags aChildTag
);
194 const TagList
* GetSynonymousTags(void) const {return mSynonymousTags
;}
195 const TagList
* GetRootTags(void) const {return mRootNodes
;}
196 const TagList
* GetEndRootTags(void) const {return mEndRootNodes
;}
197 const TagList
* GetAutoCloseStartTags(void) const {return mAutocloseStart
;}
198 const TagList
* GetAutoCloseEndTags(void) const {return mAutocloseEnd
;}
199 eHTMLTags
GetCloseTargetForEndTag(nsDTDContext
& aContext
,PRInt32 anIndex
,nsDTDMode aMode
) const;
201 const TagList
* GetSpecialChildren(void) const {return mSpecialKids
;}
202 const TagList
* GetSpecialParents(void) const {return mSpecialParents
;}
204 PRBool
IsMemberOf(PRInt32 aType
) const;
205 PRBool
ContainsSet(PRInt32 aType
) const;
206 PRBool
CanContainType(PRInt32 aType
) const;
208 PRBool
CanContain(eHTMLTags aChild
,nsDTDMode aMode
) const;
209 PRBool
CanExclude(eHTMLTags aChild
) const;
210 PRBool
CanOmitEndTag(void) const;
211 PRBool
CanContainSelf(void) const;
212 PRBool
CanAutoCloseTag(nsDTDContext
& aContext
,PRInt32 aIndex
,eHTMLTags aTag
) const;
213 PRBool
HasSpecialProperty(PRInt32 aProperty
) const;
214 PRBool
IsSpecialParent(eHTMLTags aTag
) const;
215 PRBool
IsExcludableParent(eHTMLTags aParent
) const;
216 PRBool
SectionContains(eHTMLTags aTag
,PRBool allowDepthSearch
) const;
217 PRBool
ShouldVerifyHierarchy() const;
219 static PRBool
CanContain(eHTMLTags aParent
,eHTMLTags aChild
,nsDTDMode aMode
);
220 static PRBool
IsContainer(eHTMLTags aTag
) ;
221 static PRBool
IsResidualStyleTag(eHTMLTags aTag
) ;
222 static PRBool
IsTextTag(eHTMLTags aTag
);
223 static PRBool
IsWhitespaceTag(eHTMLTags aTag
);
225 static PRBool
IsBlockParent(eHTMLTags aTag
);
226 static PRBool
IsInlineParent(eHTMLTags aTag
);
227 static PRBool
IsFlowParent(eHTMLTags aTag
);
228 static PRBool
IsSectionTag(eHTMLTags aTag
);
229 static PRBool
IsChildOfHead(eHTMLTags aTag
,PRBool
& aExclusively
) ;
232 eHTMLTags mRequiredAncestor
;
233 eHTMLTags mExcludingAncestor
; //If set, the presence of the excl-ancestor prevents this from opening.
234 const TagList
* mRootNodes
; //These are the tags above which you many not autoclose a START tag
235 const TagList
* mEndRootNodes
; //These are the tags above which you many not autoclose an END tag
236 const TagList
* mAutocloseStart
; //these are the start tags that you can automatically close with this START tag
237 const TagList
* mAutocloseEnd
; //these are the start tags that you can automatically close with this END tag
238 const TagList
* mSynonymousTags
; //These are morally equivalent; an end tag for one can close a start tag for another (like <Hn>)
239 const TagList
* mExcludableParents
; //These are the TAGS that cannot contain you
240 int mParentBits
; //defines groups that can contain this element
241 int mInclusionBits
; //defines parental and containment rules
242 int mExclusionBits
; //defines things you CANNOT contain
243 int mSpecialProperties
; //used for various special purposes...
244 PRUint32 mPropagateRange
; //tells us how far a parent is willing to prop. badly formed children
245 const TagList
* mSpecialParents
; //These are the special tags that contain this tag (directly)
246 const TagList
* mSpecialKids
; //These are the extra things you can contain
249 extern const nsHTMLElement gHTMLElements
[];
251 //special property bits...
252 static const int kPreferBody
= 0x0001; //this kHeadMisc tag prefers to be in the body if there isn't an explicit <head>
253 static const int kOmitEndTag
= 0x0002; //safely ignore end tag
254 static const int kLegalOpen
= 0x0004; //Lets BODY, TITLE, SCRIPT to reopen
255 static const int kNoPropagate
= 0x0008; //If set, this tag won't propagate as a child
256 static const int kBadContentWatch
= 0x0010;
258 static const int kNoStyleLeaksIn
= 0x0020;
259 static const int kNoStyleLeaksOut
= 0x0040;
261 static const int kMustCloseSelf
= 0x0080;
262 static const int kSaveMisplaced
= 0x0100; //If set, then children this tag can't contain are pushed onto the misplaced stack
263 static const int kNonContainer
= 0x0200; //If set, then this tag is not a container.
264 static const int kHandleStrayTag
= 0x0400; //If set, we automatically open a start tag
265 static const int kRequiresBody
= 0x0800; //If set, then in case of no BODY one will be opened up immediately.
266 static const int kVerifyHierarchy
= 0x1000; //If set, check to see if the tag is a child or a sibling..
267 static const int kPreferHead
= 0x2000; //This kHeadMisc tag prefers to be in the head if there isn't an explicit <body>