Back to index

lightning-sunbird  0.9+nobinonly
CNavDTD.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 
00096 #ifndef NS_NAVHTMLDTD__
00097 #define NS_NAVHTMLDTD__
00098 
00099 #include "nsIDTD.h"
00100 #include "nsISupports.h"
00101 #include "nsIParser.h"
00102 #include "nsHTMLTags.h"
00103 #include "nsVoidArray.h"
00104 #include "nsDeque.h"
00105 #include "nsParserCIID.h"
00106 #include "nsTime.h"
00107 #include "nsDTDUtils.h"
00108 
00109 #define NS_INAVHTML_DTD_IID      \
00110   {0x5c5cce40, 0xcfd6,  0x11d1,  \
00111   {0xaa, 0xda, 0x00,    0x80, 0x5f, 0x8a, 0x3e, 0x14}}
00112 
00113 
00114 class nsIHTMLContentSink;
00115 class nsIParserNode;
00116 class nsParser;
00117 class nsDTDContext;
00118 class nsEntryStack;
00119 class nsITokenizer;
00120 class nsCParserNode;
00121 class nsTokenAllocator;
00122 
00123 /***************************************************************
00124   Now the main event: CNavDTD.
00125 
00126   This not so simple class performs all the duties of token 
00127   construction and model building. It works in conjunction with
00128   an nsParser.
00129  ***************************************************************/
00130 
00131 #ifdef _MSC_VER
00132 #pragma warning( disable : 4275 )
00133 #endif
00134 
00135 class CNavDTD : public nsIDTD
00136 {
00137 
00138 #ifdef _MSC_VER
00139 #pragma warning( default : 4275 )
00140 #endif
00141 
00142 public:
00143     NS_DECL_ISUPPORTS
00144     NS_DECL_NSIDTD
00145      
00152     CNavDTD();
00153     virtual ~CNavDTD();
00154     
00155 
00165     virtual PRBool CanPropagate(eHTMLTags aParent,
00166                                 eHTMLTags aChild,
00167                                 PRBool aParentContains) ;
00168 
00179     virtual PRBool CanOmit(eHTMLTags aParent, 
00180                            eHTMLTags aChild,
00181                            PRBool& aParentContains);
00182 
00193     virtual PRBool ForwardPropagate(nsString& aSequence,
00194                                     eHTMLTags aParent,
00195                                     eHTMLTags aChild);
00196 
00206     virtual PRBool BackwardPropagate(nsString& aSequence,
00207                                      eHTMLTags aParent,
00208                                      eHTMLTags aChild) const;
00209 
00217     nsresult CreateContextStackFor(eHTMLTags aChild);
00218 
00225     virtual PRBool HasOpenContainer(eHTMLTags aContainer) const;
00226 
00233     virtual PRBool HasOpenContainer(const eHTMLTags aTagSet[],PRInt32 aCount) const;
00234 
00242     virtual eHTMLTags GetTopNode() const;
00243 
00250     // virtual PRInt32 GetTopmostIndexOf(eHTMLTags aTag) const;
00251 
00258     virtual PRInt32 LastOf(eHTMLTags aTagSet[],PRInt32 aCount) const;
00259 
00267     nsresult    HandleStartToken(CToken* aToken);
00268     nsresult    HandleDefaultStartToken(CToken* aToken, eHTMLTags aChildTag,
00269                                         nsCParserNode *aNode);
00270     nsresult    HandleEndToken(CToken* aToken);
00271     nsresult    HandleEntityToken(CToken* aToken);
00272     nsresult    HandleCommentToken(CToken* aToken);
00273     nsresult    HandleAttributeToken(CToken* aToken);
00274     nsresult    HandleScriptToken(const nsIParserNode *aNode);
00275     nsresult    HandleProcessingInstructionToken(CToken* aToken);
00276     nsresult    HandleDocTypeDeclToken(CToken* aToken);
00277     nsresult    BuildNeglectedTarget(eHTMLTags aTarget, eHTMLTokenTypes aType,
00278                                      nsIParser* aParser, nsIContentSink* aSink);
00279 
00280     //*************************************************
00281     //these cover methods mimic the sink, and are used
00282     //by the parser to manage its context-stack.
00283     //*************************************************
00284 
00293     nsresult OpenHTML(const nsCParserNode *aNode);
00294     nsresult OpenHead(const nsIParserNode *aNode);
00295     nsresult OpenBody(const nsCParserNode *aNode);
00296     nsresult OpenForm(const nsIParserNode *aNode);
00297     nsresult OpenMap(const nsCParserNode *aNode);
00298     nsresult OpenFrameset(const nsCParserNode *aNode);
00299     nsresult OpenContainer(const nsCParserNode *aNode,
00300                            eHTMLTags aTag,
00301                            PRBool aClosedByStartTag,
00302                            nsEntryStack* aStyleStack=0);
00303 
00311     nsresult CloseHTML();
00312     nsresult CloseHead();
00313     nsresult CloseBody();
00314     nsresult CloseForm();
00315     nsresult CloseMap();
00316     nsresult CloseFrameset();
00317     
00324     nsresult CloseContainer(const eHTMLTags aTag,
00325                             eHTMLTags aTarget,
00326                             PRBool aClosedByStartTag);
00327     nsresult CloseContainersTo(eHTMLTags aTag,
00328                                PRBool aClosedByStartTag);
00329     nsresult CloseContainersTo(PRInt32 anIndex,
00330                                eHTMLTags aTag,
00331                                PRBool aClosedByStartTag);
00332 
00339     nsresult AddLeaf(const nsIParserNode *aNode);
00340     nsresult AddHeadLeaf(nsIParserNode *aNode);
00341 
00351     nsresult  OpenTransientStyles(eHTMLTags aChildTag,
00352                                   PRBool aCloseInvalid = PR_TRUE);
00353     nsresult  CloseTransientStyles(eHTMLTags aChildTag);
00354     nsresult  PopStyle(eHTMLTags aTag);
00355 
00356     nsresult  PushIntoMisplacedStack(CToken* aToken)
00357     {
00358       NS_ENSURE_ARG_POINTER(aToken);
00359       aToken->SetNewlineCount(0); // Note: We have already counted the newlines for these tokens
00360 
00361       mMisplacedContent.Push(aToken);
00362       return NS_OK;
00363     }
00364 
00365 protected:
00366 
00367     nsresult        CollectAttributes(nsIParserNode* aNode,eHTMLTags aTag,PRInt32 aCount);
00368     nsresult        CollectSkippedContent(nsIParserNode& aNode,PRInt32& aCount);
00369     nsresult        WillHandleStartTag(CToken* aToken,eHTMLTags aChildTag,nsIParserNode& aNode);
00370     nsresult        DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag);
00371     nsresult        HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags aParent,nsIParserNode *aNode);
00372     nsresult        HandleSavedTokens(PRInt32 anIndex);
00373     nsresult        HandleKeyGen(nsIParserNode *aNode);
00374     PRBool          IsAlternateTag(eHTMLTags aTag);
00375     PRBool          IsBlockElement(PRInt32 aTagID, PRInt32 aParentID) const;
00376     PRBool          IsInlineElement(PRInt32 aTagID, PRInt32 aParentID) const;
00377     
00378     nsDeque             mMisplacedContent;
00379     nsDeque             mSkippedContent;
00380     
00381     nsIHTMLContentSink* mSink;
00382     nsTokenAllocator*   mTokenAllocator;
00383     nsDTDContext*       mBodyContext;
00384     nsDTDContext*       mTempContext;
00385     nsParser*           mParser;
00386     nsITokenizer*       mTokenizer; // weak
00387    
00388     nsString            mFilename; 
00389     nsString            mScratch;  //used for various purposes; non-persistent
00390     nsCString           mMimeType;
00391 
00392     nsNodeAllocator     mNodeAllocator;
00393     nsDTDMode           mDTDMode;
00394     eParserDocType      mDocType;
00395     eParserCommands     mParserCommand;   //tells us to viewcontent/viewsource/viewerrors...
00396 
00397     eHTMLTags           mSkipTarget;
00398     PRInt32             mLineNumber;
00399     PRInt32             mOpenMapCount;
00400 
00401     PRUint16            mFlags;
00402 };
00403 
00404 inline nsresult NS_NewNavHTMLDTD(nsIDTD** aInstancePtrResult)
00405 {
00406   NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
00407   return CallCreateInstance(kNavDTDCID, aInstancePtrResult);
00408 }
00409 
00410 #endif 
00411 
00412 
00413