Back to index

lightning-sunbird  0.9+nobinonly
nsXBLContentSink.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  *   David Hyatt <hyatt@netscape.com> (Original Author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsXBLContentSink_h__
00040 #define nsXBLContentSink_h__
00041 
00042 #include "nsXMLContentSink.h"
00043 #include "nsXBLDocumentInfo.h"
00044 #include "nsXBLPrototypeHandler.h"
00045 #include "nsXBLProtoImpl.h"
00046 #include "nsICSSParser.h"
00047 #include "nsLayoutCID.h"
00048 
00049 /*
00050  * Enum that describes the primary state of the parsing process
00051  */
00052 typedef enum {
00053   eXBL_InDocument,       /* outside any bindings */
00054   eXBL_InBindings,       /* Inside a <bindings> element */
00055   eXBL_InBinding,        /* Inside a <binding> */
00056   eXBL_InResources,      /* Inside a <resources> */
00057   eXBL_InImplementation, /* Inside a <implementation> */
00058   eXBL_InHandlers,       /* Inside a <handlers> */
00059   eXBL_Error             /* An error has occured.  Suspend binding construction */
00060 } XBLPrimaryState;
00061 
00062 /*
00063  * Enum that describes our substate (typically when parsing something
00064  * like <handlers> or <implementation>).
00065  */
00066 typedef enum {
00067   eXBL_None,
00068   eXBL_InHandler,
00069   eXBL_InMethod,
00070   eXBL_InProperty,
00071   eXBL_InField,
00072   eXBL_InBody,
00073   eXBL_InGetter,
00074   eXBL_InSetter,
00075   eXBL_InConstructor,
00076   eXBL_InDestructor
00077 } XBLSecondaryState;
00078 
00079 class nsXULPrototypeElement;
00080 class nsXBLProtoImplMember;
00081 class nsXBLProtoImplProperty;
00082 class nsXBLProtoImplMethod;
00083 class nsXBLProtoImplField;
00084 class nsXBLPrototypeBinding;
00085 
00086 // The XBL content sink overrides the XML content sink to
00087 // builds its own lightweight data structures for the <resources>,
00088 // <handlers>, <implementation>, and 
00089 
00090 class nsXBLContentSink : public nsXMLContentSink {
00091 public:
00092   nsXBLContentSink();
00093   ~nsXBLContentSink();
00094 
00095   nsresult Init(nsIDocument* aDoc,
00096                 nsIURI* aURL,
00097                 nsISupports* aContainer);
00098 
00099   // nsIContentSink overrides
00100   NS_IMETHOD HandleStartElement(const PRUnichar *aName, 
00101                                 const PRUnichar **aAtts, 
00102                                 PRUint32 aAttsCount, 
00103                                 PRInt32 aIndex, 
00104                                 PRUint32 aLineNumber);
00105 
00106   NS_IMETHOD HandleEndElement(const PRUnichar *aName);
00107   
00108   NS_IMETHOD HandleCDataSection(const PRUnichar *aData, 
00109                                 PRUint32 aLength);
00110 
00111 protected:
00112     // nsXMLContentSink overrides
00113     PRBool OnOpenContainer(const PRUnichar **aAtts, 
00114                            PRUint32 aAttsCount, 
00115                            PRInt32 aNameSpaceID, 
00116                            nsIAtom* aTagName,
00117                            PRUint32 aLineNumber);
00118     
00119     nsresult CreateElement(const PRUnichar** aAtts, PRUint32 aAttsCount,
00120                            nsINodeInfo* aNodeInfo, PRUint32 aLineNumber,
00121                            nsIContent** aResult, PRBool* aAppendContent);
00122     
00123     nsresult AddAttributes(const PRUnichar** aAtts, 
00124                            nsIContent* aContent);
00125 
00126 #ifdef MOZ_XUL    
00127     nsresult AddAttributesToXULPrototype(const PRUnichar **aAtts, 
00128                                          PRUint32 aAttsCount, 
00129                                          nsXULPrototypeElement* aElement);
00130 #endif
00131 
00132     // Our own helpers for constructing XBL prototype objects.
00133     nsresult ConstructBinding();
00134     void ConstructHandler(const PRUnichar **aAtts, PRUint32 aLineNumber);
00135     void ConstructResource(const PRUnichar **aAtts, nsIAtom* aResourceType);
00136     void ConstructImplementation(const PRUnichar **aAtts);
00137     void ConstructProperty(const PRUnichar **aAtts);
00138     void ConstructMethod(const PRUnichar **aAtts);
00139     void ConstructParameter(const PRUnichar **aAtts);
00140     void ConstructField(const PRUnichar **aAtts, PRUint32 aLineNumber);
00141   
00142 
00143   // nsXMLContentSink overrides
00144   nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
00145                      PRBool* aDidFlush=nsnull);
00146 
00147   // nsIExpatSink overrides
00148   NS_IMETHOD ReportError(const PRUnichar* aErrorText,
00149                          const PRUnichar* aSourceText);
00150 
00151 protected:
00152   nsresult ReportUnexpectedElement(nsIAtom* aElementName, PRUint32 aLineNumber);
00153 
00154   void AddMember(nsXBLProtoImplMember* aMember);
00155   
00156   XBLPrimaryState mState;
00157   XBLSecondaryState mSecondaryState;
00158   nsIXBLDocumentInfo* mDocInfo;
00159   PRBool mIsChromeOrResource; // For bug #45989
00160 
00161   nsXBLPrototypeBinding* mBinding;
00162   nsXBLPrototypeHandler* mHandler; // current handler, owned by its PrototypeBinding
00163   nsXBLProtoImpl* mImplementation;
00164   nsXBLProtoImplMember* mImplMember;
00165   nsXBLProtoImplProperty* mProperty;
00166   nsXBLProtoImplMethod* mMethod;
00167   nsXBLProtoImplField* mField;
00168 };
00169 
00170 // This is also declared in nsSyncLoadService.cpp
00171 nsresult
00172 NS_NewXBLContentSink(nsIXMLContentSink** aResult,
00173                      nsIDocument* aDoc,
00174                      nsIURI* aURL,
00175                      nsISupports* aContainer);
00176 #endif // nsXBLContentSink_h__