Back to index

lightning-sunbird  0.9+nobinonly
nsXMLContentSink.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 Communicator client 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 #ifndef nsXMLContentSink_h__
00039 #define nsXMLContentSink_h__
00040 
00041 #include "nsContentSink.h"
00042 #include "nsIXMLContentSink.h"
00043 #include "nsIExpatSink.h"
00044 #include "nsIDocumentTransformer.h"
00045 #include "nsCOMArray.h"
00046 #include "nsCOMPtr.h"
00047 
00048 
00049 class nsIDocument;
00050 class nsIURI;
00051 class nsIContent;
00052 class nsINodeInfo;
00053 class nsIParser;
00054 class nsIViewManager;
00055 
00056 typedef enum {
00057   eXMLContentSinkState_InProlog,
00058   eXMLContentSinkState_InDocumentElement,
00059   eXMLContentSinkState_InEpilog
00060 } XMLContentSinkState;
00061 
00062 class nsXMLContentSink : public nsContentSink,
00063                          public nsIXMLContentSink,
00064                          public nsITransformObserver,
00065                          public nsIExpatSink
00066 {
00067 public:
00068   nsXMLContentSink();
00069   virtual ~nsXMLContentSink();
00070 
00071   nsresult Init(nsIDocument* aDoc,
00072                 nsIURI* aURL,
00073                 nsISupports* aContainer,
00074                 nsIChannel* aChannel);
00075 
00076   // nsISupports
00077   NS_DECL_ISUPPORTS_INHERITED
00078 
00079   NS_DECL_NSIEXPATSINK
00080 
00081   // nsIContentSink
00082   NS_IMETHOD WillBuildModel(void);
00083   NS_IMETHOD DidBuildModel(void);
00084   NS_IMETHOD WillInterrupt(void);
00085   NS_IMETHOD WillResume(void);
00086   NS_IMETHOD SetParser(nsIParser* aParser);  
00087   virtual void FlushPendingNotifications(mozFlushType aType) { }
00088   NS_IMETHOD SetDocumentCharset(nsACString& aCharset);
00089   virtual nsISupports *GetTarget();
00090 
00091   // nsITransformObserver
00092   NS_IMETHOD OnDocumentCreated(nsIDOMDocument *aResultDocument);
00093   NS_IMETHOD OnTransformDone(nsresult aResult, nsIDOMDocument *aResultDocument);
00094 
00095   static void ParsePIData(const nsString &aData, nsString &aHref,
00096                           nsString &aTitle, nsString &aMedia,
00097                           PRBool &aIsAlternate);
00098 
00099 protected:
00100   void StartLayout();
00101 
00102   virtual nsresult AddAttributes(const PRUnichar** aNode, nsIContent* aContent);
00103   nsresult AddText(const PRUnichar* aString, PRInt32 aLength);
00104   nsresult ProcessEndSCRIPTTag(nsIContent* aContent, nsIContent* aParent);
00105 
00106   virtual PRBool OnOpenContainer(const PRUnichar **aAtts, 
00107                                  PRUint32 aAttsCount, 
00108                                  PRInt32 aNameSpaceID, 
00109                                  nsIAtom* aTagName,
00110                                  PRUint32 aLineNumber) { return PR_TRUE; }
00111   // Set the given content as the root element for the created document
00112   //  don't set if root element was already set.
00113   //  return TRUE if this call set the root element
00114   virtual PRBool SetDocElement(PRInt32 aNameSpaceID, 
00115                                nsIAtom *aTagName,
00116                                nsIContent *aContent);
00117   virtual nsresult CreateElement(const PRUnichar** aAtts, PRUint32 aAttsCount,
00118                                  nsINodeInfo* aNodeInfo, PRUint32 aLineNumber,
00119                                  nsIContent** aResult, PRBool* aAppendContent);
00120 
00121   // aParent is allowed to be null here if this is the root content
00122   // being closed
00123   virtual nsresult CloseElement(nsIContent* aContent, nsIContent* aParent,
00124                                 PRBool* aAppendContent);
00125 
00126   virtual nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
00127                              PRBool* aDidFlush=nsnull);
00128 
00129   nsresult AddContentAsLeaf(nsIContent *aContent);
00130 
00131   nsIContent* GetCurrentContent();
00132   PRInt32 PushContent(nsIContent *aContent);
00133   already_AddRefed<nsIContent> PopContent();
00134 
00135   nsresult ProcessBASETag(nsIContent* aContent);
00136 
00137   
00138   // nsContentSink override
00139   virtual nsresult ProcessStyleLink(nsIContent* aElement,
00140                                     const nsSubstring& aHref,
00141                                     PRBool aAlternate,
00142                                     const nsSubstring& aTitle,
00143                                     const nsSubstring& aType,
00144                                     const nsSubstring& aMedia);
00145 
00146   nsresult LoadXSLStyleSheet(nsIURI* aUrl);
00147 
00148   nsresult MaybePrettyPrint();
00149   
00150   nsIContent*      mDocElement;
00151   PRUnichar*       mText;
00152 
00153   XMLContentSinkState mState;
00154 
00155   nsString mTitleText; 
00156   
00157   PRInt32 mTextLength;
00158   PRInt32 mTextSize;
00159   PRUint32 mScriptLineNo;
00160   
00161   PRUint8 mConstrainSize : 1;
00162   PRUint8 mInTitle : 1;
00163   PRUint8 mPrettyPrintXML : 1;
00164   PRUint8 mPrettyPrintHasSpecialRoot : 1;
00165   PRUint8 mPrettyPrintHasFactoredElements : 1;
00166   PRUint8 mHasProcessedBase : 1;
00167   PRUint8 mAllowAutoXLinks : 1;
00168   PRUint8 unused : 1;  // bit available if someone needs one
00169   
00170   nsCOMArray<nsIContent>           mContentStack;
00171   nsCOMPtr<nsIDocumentTransformer> mXSLTProcessor;
00172 };
00173 
00174 #endif // nsXMLContentSink_h__