LCOV - code coverage report
Current view: directory - parser/htmlparser/src - nsElementTable.h (source / functions) Found Hit Coverage
Test: app.info Lines: 39 18 46.2 %
Date: 2012-06-02 Functions: 14 10 71.4 %

       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.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                 :  * 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                 : 
      39                 : /**
      40                 :  * MODULE NOTES:
      41                 :  * @update  gess 4/1/98
      42                 :  * 
      43                 :  */
      44                 : 
      45                 : 
      46                 : 
      47                 : #ifndef _NSELEMENTABLE
      48                 : #define _NSELEMENTABLE
      49                 : 
      50                 : #include "nsHTMLTokens.h"
      51                 : #include "nsDTDUtils.h"
      52                 : 
      53                 : 
      54                 : //*********************************************************************************************
      55                 : // The following ints define the standard groups of HTML elements...
      56                 : //*********************************************************************************************
      57                 : 
      58                 : static const int kNone= 0x0;
      59                 : 
      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.
      63                 : 
      64                 : static const int kSpecial       = 0x0008; //  A,    IMG,  APPLET, OBJECT, FONT, BASEFONT, BR, SCRIPT, 
      65                 :                                           //  MAP,  Q,    SUB,    SUP,    SPAN, BDO,      IFRAME
      66                 : 
      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...
      83                 : 
      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;
      88                 : 
      89                 : 
      90                 : //*********************************************************************************************
      91                 : // The following ints define the standard groups of HTML elements...
      92                 : //*********************************************************************************************
      93                 : 
      94                 : 
      95                 : #ifdef NS_DEBUG
      96                 : extern void CheckElementTable();
      97                 : #endif
      98                 : 
      99                 : 
     100                 : /**
     101                 :  * We're asking the question: is aTest a member of bitset. 
     102                 :  *
     103                 :  * @update      gess 01/04/99
     104                 :  * @param 
     105                 :  * @return TRUE or FALSE
     106                 :  */
     107           34677 : inline bool TestBits(int aBitset,int aTest) {
     108           34677 :   if(aTest) {
     109           33213 :     PRInt32 result=(aBitset & aTest);
     110           33213 :     return bool(result==aTest);
     111                 :   }
     112            1464 :   return false;
     113                 : }
     114                 : 
     115                 : 
     116                 : /**
     117                 :  * 
     118                 :  * @update      gess 01/04/99
     119                 :  * @param 
     120                 :  * @return
     121                 :  */
     122                 : struct nsHTMLElement {
     123                 : 
     124                 : #ifdef DEBUG
     125                 :   static  void    DebugDumpMembership(const char* aFilename);
     126                 :   static  void    DebugDumpContainment(const char* aFilename,const char* aTitle);
     127                 :   static  void    DebugDumpContainType(const char* aFilename);
     128                 : #endif
     129                 : 
     130                 :   static  bool    IsInlineEntity(eHTMLTags aTag);
     131                 :   static  bool    IsFlowEntity(eHTMLTags aTag);
     132                 :   static  bool    IsBlockCloser(eHTMLTags aTag);
     133                 : 
     134            1213 :   inline  bool    IsBlock(void) const { 
     135            1213 :                     if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
     136            1213 :                       return TestBits(mParentBits,kBlock);
     137                 :                     } 
     138               0 :                     return false;
     139                 :                   }
     140                 : 
     141            1148 :   inline  bool    IsBlockEntity(void) const { 
     142            1148 :                     if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
     143            1148 :                       return TestBits(mParentBits,kBlockEntity);
     144                 :                     } 
     145               0 :                     return false;
     146                 :                   }
     147                 : 
     148               0 :   inline  bool    IsSpecialEntity(void) const { 
     149               0 :                     if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
     150               0 :                       return TestBits(mParentBits,kSpecial);
     151                 :                     } 
     152               0 :                     return false;
     153                 :                   }
     154                 : 
     155               0 :   inline  bool    IsPhraseEntity(void) const { 
     156               0 :                     if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
     157               0 :                       return TestBits(mParentBits,kPhrase);
     158                 :                     } 
     159               0 :                     return false;
     160                 :                   }
     161                 : 
     162               0 :   inline  bool    IsFontStyleEntity(void) const { 
     163               0 :                     if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_xmp)){
     164               0 :                       return TestBits(mParentBits,kFontStyle);
     165                 :                     } 
     166               0 :                     return false;
     167                 :                   }
     168                 :   
     169               0 :   inline  bool    IsTableElement(void) const {  //return yes if it's a table or child of a table...
     170               0 :                     bool result=false;
     171                 : 
     172               0 :                     switch(mTagID) {
     173                 :                       case eHTMLTag_table:
     174                 :                       case eHTMLTag_thead:
     175                 :                       case eHTMLTag_tbody:
     176                 :                       case eHTMLTag_tfoot:
     177                 :                       case eHTMLTag_caption:
     178                 :                       case eHTMLTag_tr:
     179                 :                       case eHTMLTag_td:
     180                 :                       case eHTMLTag_th:
     181                 :                       case eHTMLTag_col:
     182                 :                       case eHTMLTag_colgroup:
     183               0 :                         result=true;
     184               0 :                         break;
     185                 :                       default:
     186               0 :                         result=false;
     187                 :                     }
     188               0 :                     return result;
     189                 :                   }
     190                 : 
     191                 : 
     192                 :   static  PRInt32 GetIndexOfChildOrSynonym(nsDTDContext& aContext,eHTMLTags aChildTag);
     193                 : 
     194             520 :   const TagList*  GetSynonymousTags(void) const {return mSynonymousTags;}
     195            2424 :   const TagList*  GetRootTags(void) const {return mRootNodes;}
     196              86 :   const TagList*  GetEndRootTags(void) const {return mEndRootNodes;}
     197            1925 :   const TagList*  GetAutoCloseStartTags(void) const {return mAutocloseStart;}
     198             172 :   const TagList*  GetAutoCloseEndTags(void) const {return mAutocloseEnd;}
     199                 :   eHTMLTags       GetCloseTargetForEndTag(nsDTDContext& aContext,PRInt32 anIndex,nsDTDMode aMode) const;
     200                 : 
     201              86 :   const TagList*        GetSpecialChildren(void) const {return mSpecialKids;}
     202              62 :   const TagList*        GetSpecialParents(void) const {return mSpecialParents;}
     203                 : 
     204                 :   bool            IsMemberOf(PRInt32 aType) const;
     205                 :   bool            ContainsSet(PRInt32 aType) const;
     206                 :   bool            CanContainType(PRInt32 aType) const;
     207                 : 
     208                 :   bool            CanContain(eHTMLTags aChild,nsDTDMode aMode) const;
     209                 :   bool            CanExclude(eHTMLTags aChild) const;
     210                 :   bool            CanOmitEndTag(void) const;
     211                 :   bool            CanContainSelf(void) const;
     212                 :   bool            CanAutoCloseTag(nsDTDContext& aContext,PRInt32 aIndex,eHTMLTags aTag) const;
     213                 :   bool            HasSpecialProperty(PRInt32 aProperty) const;
     214                 :   bool            IsSpecialParent(eHTMLTags aTag) const;
     215                 :   bool            IsExcludableParent(eHTMLTags aParent) const;
     216                 :   bool            SectionContains(eHTMLTags aTag,bool allowDepthSearch) const;
     217                 :   bool            ShouldVerifyHierarchy() const;
     218                 : 
     219                 :   static  bool    CanContain(eHTMLTags aParent,eHTMLTags aChild,nsDTDMode aMode);
     220                 :   static  bool    IsContainer(eHTMLTags aTag) ;
     221                 :   static  bool    IsResidualStyleTag(eHTMLTags aTag) ;
     222                 :   static  bool    IsTextTag(eHTMLTags aTag);
     223                 :   static  bool    IsWhitespaceTag(eHTMLTags aTag);
     224                 : 
     225                 :   static  bool    IsBlockParent(eHTMLTags aTag);
     226                 :   static  bool    IsInlineParent(eHTMLTags aTag); 
     227                 :   static  bool    IsFlowParent(eHTMLTags aTag);
     228                 :   static  bool    IsSectionTag(eHTMLTags aTag);
     229                 :   static  bool    IsChildOfHead(eHTMLTags aTag,bool& aExclusively) ;
     230                 : 
     231                 :   eHTMLTags       mTagID;
     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
     247                 : }; 
     248                 : 
     249                 : extern const nsHTMLElement gHTMLElements[];
     250                 : 
     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; 
     257                 : 
     258                 : static const int kNoStyleLeaksIn   = 0x0020; 
     259                 : static const int kNoStyleLeaksOut  = 0x0040; 
     260                 : 
     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>
     268                 : 
     269                 : #endif

Generated by: LCOV version 1.7