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 nsXBLProtoImpl_h__
40 : #define nsXBLProtoImpl_h__
41 :
42 : #include "nsMemory.h"
43 : #include "nsXBLPrototypeHandler.h"
44 : #include "nsXBLProtoImplMember.h"
45 : #include "nsXBLProtoImplField.h"
46 :
47 : class nsIXPConnectJSObjectHolder;
48 : class nsXBLPrototypeBinding;
49 : class nsXBLProtoImplAnonymousMethod;
50 :
51 : class nsXBLProtoImpl
52 : {
53 : public:
54 0 : nsXBLProtoImpl()
55 : : mClassObject(nsnull),
56 : mMembers(nsnull),
57 : mFields(nsnull),
58 : mConstructor(nsnull),
59 0 : mDestructor(nsnull)
60 : {
61 0 : MOZ_COUNT_CTOR(nsXBLProtoImpl);
62 0 : }
63 0 : ~nsXBLProtoImpl()
64 0 : {
65 0 : MOZ_COUNT_DTOR(nsXBLProtoImpl);
66 : // Note: the constructor and destructor are in mMembers, so we'll
67 : // clean them up automatically.
68 0 : delete mMembers;
69 0 : delete mFields;
70 0 : }
71 :
72 : nsresult InstallImplementation(nsXBLPrototypeBinding* aBinding, nsIContent* aBoundElement);
73 : nsresult InitTargetObjects(nsXBLPrototypeBinding* aBinding, nsIScriptContext* aContext,
74 : nsIContent* aBoundElement,
75 : nsIXPConnectJSObjectHolder** aScriptObjectHolder,
76 : JSObject** aTargetClassObject);
77 : nsresult CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding);
78 :
79 0 : void SetMemberList(nsXBLProtoImplMember* aMemberList)
80 : {
81 0 : delete mMembers;
82 0 : mMembers = aMemberList;
83 0 : }
84 :
85 0 : void SetFieldList(nsXBLProtoImplField* aFieldList)
86 : {
87 0 : delete mFields;
88 0 : mFields = aFieldList;
89 0 : }
90 :
91 : void Trace(TraceCallback aCallback, void *aClosure) const;
92 : void UnlinkJSObjects();
93 :
94 : nsXBLProtoImplField* FindField(const nsString& aFieldName) const;
95 :
96 : // Resolve all the fields for this implementation on the object |obj| False
97 : // return means a JS exception was set.
98 : bool ResolveAllFields(JSContext *cx, JSObject *obj) const;
99 :
100 : // Undefine all our fields from object |obj| (which should be a
101 : // JSObject for a bound element).
102 : void UndefineFields(JSContext* cx, JSObject* obj) const;
103 :
104 0 : bool CompiledMembers() const {
105 0 : return mClassObject != nsnull;
106 : }
107 :
108 : nsresult Read(nsIScriptContext* aContext,
109 : nsIObjectInputStream* aStream,
110 : nsXBLPrototypeBinding* aBinding,
111 : nsIScriptGlobalObject* aGlobal);
112 : nsresult Write(nsIScriptContext* aContext,
113 : nsIObjectOutputStream* aStream,
114 : nsXBLPrototypeBinding* aBinding);
115 :
116 : protected:
117 : // used by Read to add each member
118 0 : nsXBLProtoImplMember* AddMember(nsXBLProtoImplMember* aMember,
119 : nsXBLProtoImplMember* aPreviousMember)
120 : {
121 0 : if (aPreviousMember)
122 0 : aPreviousMember->SetNext(aMember);
123 : else
124 0 : mMembers = aMember;
125 0 : return aMember;
126 : }
127 :
128 : void DestroyMembers();
129 :
130 : public:
131 : nsCString mClassName; // The name of the class.
132 :
133 : protected:
134 : JSObject* mClassObject; // The class object for the binding. We'll use this to pre-compile properties
135 : // and methods for the binding.
136 :
137 : nsXBLProtoImplMember* mMembers; // The members of an implementation are chained in this singly-linked list.
138 :
139 : nsXBLProtoImplField* mFields; // Our fields
140 :
141 : public:
142 : nsXBLProtoImplAnonymousMethod* mConstructor; // Our class constructor.
143 : nsXBLProtoImplAnonymousMethod* mDestructor; // Our class destructor.
144 : };
145 :
146 : nsresult
147 : NS_NewXBLProtoImpl(nsXBLPrototypeBinding* aBinding,
148 : const PRUnichar* aClassName,
149 : nsXBLProtoImpl** aResult);
150 :
151 : #endif // nsXBLProtoImpl_h__
|