Back to index

lightning-sunbird  0.9+nobinonly
nsElementTable.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 
00047 #ifndef _NSELEMENTABLE
00048 #define _NSELEMENTABLE
00049 
00050 #include "nsHTMLTokens.h"
00051 #include "nsDTDUtils.h"
00052 
00053 
00054 //*********************************************************************************************
00055 // The following ints define the standard groups of HTML elements...
00056 //*********************************************************************************************
00057 
00058 static const int kNone= 0x0;
00059 
00060 static const int kHTMLContent   = 0x0001; //  HEAD, (FRAMESET | BODY)
00061 static const int kHeadContent   = 0x0002; //  Elements that *must* be in the head.
00062 static const int kHeadMisc      = 0x0004; //  Elements that *can* be in the head.
00063 
00064 static const int kSpecial       = 0x0008; //  A,    IMG,  APPLET, OBJECT, FONT, BASEFONT, BR, SCRIPT, 
00065                                           //  MAP,  Q,    SUB,    SUP,    SPAN, BDO,      IFRAME
00066 
00067 static const int kFormControl   = 0x0010; //  INPUT SELECT  TEXTAREA  LABEL BUTTON
00068 static const int kPreformatted  = 0x0020; //  PRE
00069 static const int kPreExclusion  = 0x0040; //  IMG,  OBJECT, APPLET, BIG,  SMALL,  SUB,  SUP,  FONT, BASEFONT
00070 static const int kFontStyle     = 0x0080; //  TT, I, B, U, S, STRIKE, BIG, SMALL, BLINK
00071 static const int kPhrase        = 0x0100; //  EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM
00072 static const int kHeading       = 0x0200; //  H1..H6
00073 static const int kBlockMisc     = 0x0400; //  OBJECT, SCRIPT
00074 static const int kBlock         = 0x0800; //  ADDRESS, BLOCKQUOTE, CENTER, DIV, DL, FIELDSET, FORM, 
00075                                           //  ISINDEX, HR, NOSCRIPT, NOFRAMES, P, TABLE
00076 static const int kList          = 0x1000; //  UL, OL, DIR, MENU
00077 static const int kPCDATA        = 0x2000; //  plain text and entities...
00078 static const int kSelf          = 0x4000; //  whatever THIS tag is...
00079 static const int kExtensions    = 0x8000; //  BGSOUND, WBR, NOBR
00080 static const int kTable         = 0x10000;//  TR,TD,THEAD,TBODY,TFOOT,CAPTION,TH
00081 static const int kDLChild       = 0x20000;//  DL, DT
00082 static const int kCDATA         = 0x40000;//  just plain text...
00083 
00084 static const int kInlineEntity  = (kPCDATA|kFontStyle|kPhrase|kSpecial|kFormControl|kExtensions);  //  #PCDATA, %fontstyle, %phrase, %special, %formctrl
00085 static const int kBlockEntity   = (kHeading|kList|kPreformatted|kBlock); //  %heading, %list, %preformatted, %block
00086 static const int kFlowEntity    = (kBlockEntity|kInlineEntity); //  %blockentity, %inlineentity
00087 static const int kAllTags       = 0xffffff;
00088 
00089 
00090 //*********************************************************************************************
00091 // The following ints define the standard groups of HTML elements...
00092 //*********************************************************************************************
00093 
00094 
00095 #ifdef NS_DEBUG
00096 extern void CheckElementTable();
00097 #endif
00098 
00099 typedef PRBool (*ContainFunc)(eHTMLTags aTag,nsDTDContext &aContext);
00100 
00101 
00109 inline PRBool TestBits(int aBitset,int aTest) {
00110   if(aTest) {
00111     PRInt32 result=(aBitset & aTest);
00112     return PRBool(result==aTest);
00113   }
00114   return PR_FALSE;
00115 }
00116 
00117 
00124 struct nsHTMLElement {
00125 
00126 #ifdef DEBUG
00127   static  void    DebugDumpMembership(const char* aFilename);
00128   static  void    DebugDumpContainment(const char* aFilename,const char* aTitle);
00129   static  void    DebugDumpContainType(const char* aFilename);
00130 #endif
00131 
00132   static  PRBool  IsInlineEntity(eHTMLTags aTag);
00133   static  PRBool  IsFlowEntity(eHTMLTags aTag);
00134   static  PRBool  IsBlockCloser(eHTMLTags aTag);
00135 
00136   inline  PRBool  IsBlock(void) const { 
00137                     if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
00138                       return TestBits(mParentBits,kBlock);
00139                     } 
00140                     return PR_FALSE;
00141                   }
00142 
00143   inline  PRBool  IsBlockEntity(void) const { 
00144                     if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
00145                       return TestBits(mParentBits,kBlockEntity);
00146                     } 
00147                     return PR_FALSE;
00148                   }
00149 
00150   inline  PRBool  IsSpecialEntity(void) const { 
00151                     if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
00152                       return TestBits(mParentBits,kSpecial);
00153                     } 
00154                     return PR_FALSE;
00155                   }
00156 
00157   inline  PRBool  IsPhraseEntity(void) const { 
00158                     if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
00159                       return TestBits(mParentBits,kPhrase);
00160                     } 
00161                     return PR_FALSE;
00162                   }
00163 
00164   inline  PRBool  IsFontStyleEntity(void) const { 
00165                     if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
00166                       return TestBits(mParentBits,kFontStyle);
00167                     } 
00168                     return PR_FALSE;
00169                   }
00170   
00171   inline  PRBool  IsTableElement(void) const {  //return yes if it's a table or child of a table...
00172                     PRBool result=PR_FALSE;
00173 
00174                     switch(mTagID) {
00175                       case eHTMLTag_table:
00176                       case eHTMLTag_thead:
00177                       case eHTMLTag_tbody:
00178                       case eHTMLTag_tfoot:
00179                       case eHTMLTag_caption:
00180                       case eHTMLTag_tr:
00181                       case eHTMLTag_td:
00182                       case eHTMLTag_th:
00183                       case eHTMLTag_col:
00184                       case eHTMLTag_colgroup:
00185                         result=PR_TRUE;
00186                         break;
00187                       default:
00188                         result=PR_FALSE;
00189                     }
00190                     return result;
00191                   }
00192 
00193 
00194   static  PRInt32 GetIndexOfChildOrSynonym(nsDTDContext& aContext,eHTMLTags aChildTag);
00195 
00196   const TagList*  GetSynonymousTags(void) const {return mSynonymousTags;}
00197   const TagList*  GetRootTags(void) const {return mRootNodes;}
00198   const TagList*  GetEndRootTags(void) const {return mEndRootNodes;}
00199   const TagList*  GetAutoCloseStartTags(void) const {return mAutocloseStart;}
00200   const TagList*  GetAutoCloseEndTags(void) const {return mAutocloseEnd;}
00201   eHTMLTags       GetCloseTargetForEndTag(nsDTDContext& aContext,PRInt32 anIndex,nsDTDMode aMode) const;
00202 
00203   const TagList*        GetSpecialChildren(void) const {return mSpecialKids;}
00204   const TagList*        GetSpecialParents(void) const {return mSpecialParents;}
00205 
00206   PRBool          IsMemberOf(PRInt32 aType) const;
00207   PRBool          ContainsSet(PRInt32 aType) const;
00208   PRBool          CanContainType(PRInt32 aType) const;
00209   
00210   eHTMLTags       GetTag(void) const {return mTagID;}
00211   PRBool          CanContain(eHTMLTags aChild,nsDTDMode aMode) const;
00212   PRBool          CanExclude(eHTMLTags aChild) const;
00213   PRBool          CanOmitStartTag(eHTMLTags aChild) const;
00214   PRBool          CanOmitEndTag(void) const;
00215   PRBool          CanContainSelf(void) const;
00216   PRBool          CanAutoCloseTag(nsDTDContext& aContext,PRInt32 aIndex,eHTMLTags aTag) const;
00217   PRBool          HasSpecialProperty(PRInt32 aProperty) const;
00218   PRBool          IsSpecialParent(eHTMLTags aTag) const;
00219   PRBool          IsExcludableParent(eHTMLTags aParent) const;
00220   PRBool          SectionContains(eHTMLTags aTag,PRBool allowDepthSearch) const;
00221   PRBool          ShouldVerifyHierarchy() const;
00222 
00223   PRBool          CanBeContained(eHTMLTags aParentTag,nsDTDContext &aContext) const; //default version
00224 
00225   static  PRBool  CanContain(eHTMLTags aParent,eHTMLTags aChild,nsDTDMode aMode);
00226   static  PRBool  IsContainer(eHTMLTags aTag) ;
00227   static  PRBool  IsResidualStyleTag(eHTMLTags aTag) ;
00228   static  PRBool  IsTextTag(eHTMLTags aTag);
00229   static  PRBool  IsWhitespaceTag(eHTMLTags aTag);
00230 
00231   static  PRBool  IsBlockParent(eHTMLTags aTag);
00232   static  PRBool  IsInlineParent(eHTMLTags aTag); 
00233   static  PRBool  IsFlowParent(eHTMLTags aTag);
00234   static  PRBool  IsSectionTag(eHTMLTags aTag);
00235   static  PRBool  IsChildOfHead(eHTMLTags aTag,PRBool& aExclusively) ;
00236 
00237   eHTMLTags       mTagID;
00238   eHTMLTags       mRequiredAncestor;
00239   eHTMLTags       mExcludingAncestor; //If set, the presence of the excl-ancestor prevents this from opening.
00240   const TagList*  mRootNodes;         //These are the tags above which you many not autoclose a START tag
00241   const TagList*        mEndRootNodes;      //These are the tags above which you many not autoclose an END tag
00242   const TagList*        mAutocloseStart;    //these are the start tags that you can automatically close with this START tag
00243   const TagList*        mAutocloseEnd;      //these are the start tags that you can automatically close with this END tag
00244   const TagList*        mSynonymousTags;    //These are morally equivalent; an end tag for one can close a start tag for another (like <Hn>)
00245   const TagList*        mExcludableParents; //These are the TAGS that cannot contain you
00246   int             mParentBits;        //defines groups that can contain this element
00247   int             mInclusionBits;     //defines parental and containment rules
00248   int             mExclusionBits;     //defines things you CANNOT contain
00249   int             mSpecialProperties; //used for various special purposes...
00250   PRUint32        mPropagateRange;    //tells us how far a parent is willing to prop. badly formed children
00251   const TagList*  mSpecialParents;    //These are the special tags that contain this tag (directly)
00252   const TagList*  mSpecialKids;       //These are the extra things you can contain
00253   eHTMLTags       mSkipTarget;        //If set, then we skip all content until this tag is seen
00254   ContainFunc     mCanBeContained;
00255 }; 
00256 
00257 extern const nsHTMLElement gHTMLElements[];
00258 
00259 //special property bits...
00260 static const int kPreferBody       = 0x0001; //this kHeadMisc tag prefers to be in the body if there isn't an explicit <head>
00261 static const int kOmitEndTag       = 0x0002; //safely ignore end tag
00262 static const int kLegalOpen        = 0x0004; //Lets BODY, TITLE, SCRIPT to reopen
00263 static const int kNoPropagate      = 0x0008; //If set, this tag won't propagate as a child
00264 static const int kBadContentWatch  = 0x0010; 
00265 
00266 static const int kNoStyleLeaksIn   = 0x0020; 
00267 static const int kNoStyleLeaksOut  = 0x0040; 
00268 
00269 static const int kMustCloseSelf    = 0x0080; 
00270 static const int kSaveMisplaced    = 0x0100; //If set, then children this tag can't contain are pushed onto the misplaced stack
00271 static const int kNonContainer     = 0x0200; //If set, then this tag is not a container.
00272 static const int kHandleStrayTag   = 0x0400; //If set, we automatically open a start tag
00273 static const int kRequiresBody     = 0x0800; //If set, then in case of no BODY one will be opened up immediately.
00274 static const int kVerifyHierarchy  = 0x1000; //If set, check to see if the tag is a child or a sibling..
00275 
00276 #endif