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 Communicator client 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 : * David Hyatt <hyatt@netscape.com> (Original Author)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsXBLContentSink_h__
40 : #define nsXBLContentSink_h__
41 :
42 : #include "nsXMLContentSink.h"
43 : #include "nsXBLDocumentInfo.h"
44 : #include "nsXBLPrototypeHandler.h"
45 : #include "nsXBLProtoImpl.h"
46 : #include "nsLayoutCID.h"
47 :
48 : /*
49 : * Enum that describes the primary state of the parsing process
50 : */
51 : typedef enum {
52 : eXBL_InDocument, /* outside any bindings */
53 : eXBL_InBindings, /* Inside a <bindings> element */
54 : eXBL_InBinding, /* Inside a <binding> */
55 : eXBL_InResources, /* Inside a <resources> */
56 : eXBL_InImplementation, /* Inside a <implementation> */
57 : eXBL_InHandlers, /* Inside a <handlers> */
58 : eXBL_Error /* An error has occurred. Suspend binding construction */
59 : } XBLPrimaryState;
60 :
61 : /*
62 : * Enum that describes our substate (typically when parsing something
63 : * like <handlers> or <implementation>).
64 : */
65 : typedef enum {
66 : eXBL_None,
67 : eXBL_InHandler,
68 : eXBL_InMethod,
69 : eXBL_InProperty,
70 : eXBL_InField,
71 : eXBL_InBody,
72 : eXBL_InGetter,
73 : eXBL_InSetter,
74 : eXBL_InConstructor,
75 : eXBL_InDestructor
76 : } XBLSecondaryState;
77 :
78 : class nsXULPrototypeElement;
79 : class nsXBLProtoImplMember;
80 : class nsXBLProtoImplProperty;
81 : class nsXBLProtoImplMethod;
82 : class nsXBLProtoImplField;
83 : class nsXBLPrototypeBinding;
84 :
85 : // The XBL content sink overrides the XML content sink to
86 : // builds its own lightweight data structures for the <resources>,
87 : // <handlers>, <implementation>, and
88 :
89 : class nsXBLContentSink : public nsXMLContentSink {
90 : public:
91 : nsXBLContentSink();
92 : ~nsXBLContentSink();
93 :
94 0 : NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
95 :
96 : nsresult Init(nsIDocument* aDoc,
97 : nsIURI* aURL,
98 : nsISupports* aContainer);
99 :
100 : // nsIContentSink overrides
101 : NS_IMETHOD HandleStartElement(const PRUnichar *aName,
102 : const PRUnichar **aAtts,
103 : PRUint32 aAttsCount,
104 : PRInt32 aIndex,
105 : PRUint32 aLineNumber);
106 :
107 : NS_IMETHOD HandleEndElement(const PRUnichar *aName);
108 :
109 : NS_IMETHOD HandleCDataSection(const PRUnichar *aData,
110 : PRUint32 aLength);
111 :
112 : protected:
113 : // nsXMLContentSink overrides
114 : virtual void MaybeStartLayout(bool aIgnorePendingSheets);
115 :
116 : bool OnOpenContainer(const PRUnichar **aAtts,
117 : PRUint32 aAttsCount,
118 : PRInt32 aNameSpaceID,
119 : nsIAtom* aTagName,
120 : PRUint32 aLineNumber);
121 :
122 0 : bool NotifyForDocElement() { return false; }
123 :
124 : nsresult CreateElement(const PRUnichar** aAtts, PRUint32 aAttsCount,
125 : nsINodeInfo* aNodeInfo, PRUint32 aLineNumber,
126 : nsIContent** aResult, bool* aAppendContent,
127 : mozilla::dom::FromParser aFromParser);
128 :
129 : nsresult AddAttributes(const PRUnichar** aAtts,
130 : nsIContent* aContent);
131 :
132 : #ifdef MOZ_XUL
133 : nsresult AddAttributesToXULPrototype(const PRUnichar **aAtts,
134 : PRUint32 aAttsCount,
135 : nsXULPrototypeElement* aElement);
136 : #endif
137 :
138 : // Our own helpers for constructing XBL prototype objects.
139 : nsresult ConstructBinding(PRUint32 aLineNumber);
140 : void ConstructHandler(const PRUnichar **aAtts, PRUint32 aLineNumber);
141 : void ConstructResource(const PRUnichar **aAtts, nsIAtom* aResourceType);
142 : void ConstructImplementation(const PRUnichar **aAtts);
143 : void ConstructProperty(const PRUnichar **aAtts);
144 : void ConstructMethod(const PRUnichar **aAtts);
145 : void ConstructParameter(const PRUnichar **aAtts);
146 : void ConstructField(const PRUnichar **aAtts, PRUint32 aLineNumber);
147 :
148 :
149 : // nsXMLContentSink overrides
150 : nsresult FlushText(bool aReleaseTextNode = true);
151 :
152 : // nsIExpatSink overrides
153 : NS_IMETHOD ReportError(const PRUnichar* aErrorText,
154 : const PRUnichar* aSourceText,
155 : nsIScriptError *aError,
156 : bool *_retval);
157 :
158 : protected:
159 : nsresult ReportUnexpectedElement(nsIAtom* aElementName, PRUint32 aLineNumber);
160 :
161 : void AddMember(nsXBLProtoImplMember* aMember);
162 : void AddField(nsXBLProtoImplField* aField);
163 :
164 : XBLPrimaryState mState;
165 : XBLSecondaryState mSecondaryState;
166 : nsXBLDocumentInfo* mDocInfo;
167 : bool mIsChromeOrResource; // For bug #45989
168 : bool mFoundFirstBinding;
169 :
170 : nsXBLPrototypeBinding* mBinding;
171 : nsXBLPrototypeHandler* mHandler; // current handler, owned by its PrototypeBinding
172 : nsXBLProtoImpl* mImplementation;
173 : nsXBLProtoImplMember* mImplMember;
174 : nsXBLProtoImplField* mImplField;
175 : nsXBLProtoImplProperty* mProperty;
176 : nsXBLProtoImplMethod* mMethod;
177 : nsXBLProtoImplField* mField;
178 : };
179 :
180 : nsresult
181 : NS_NewXBLContentSink(nsIXMLContentSink** aResult,
182 : nsIDocument* aDoc,
183 : nsIURI* aURL,
184 : nsISupports* aContainer);
185 : #endif // nsXBLContentSink_h__
|