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
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/
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
15 * The Original Code is Mozilla Communicator client code.
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.
23 * David Hyatt <hyatt@netscape.com> (Original Author)
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.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsXBLProtoImplMethod_h__
40 #define nsXBLProtoImplMethod_h__
45 #include "nsIContent.h"
47 #include "nsXBLProtoImplMember.h"
49 struct nsXBLParameter
{
50 nsXBLParameter
* mNext
;
53 nsXBLParameter(const nsAString
& aName
) {
54 MOZ_COUNT_CTOR(nsXBLParameter
);
55 mName
= ToNewCString(aName
);
60 MOZ_COUNT_DTOR(nsXBLParameter
);
61 nsMemory::Free(mName
);
66 struct nsXBLUncompiledMethod
{
67 nsXBLParameter
* mParameters
;
68 nsXBLParameter
* mLastParameter
;
69 nsXBLTextWithLineNumber mBodyText
;
71 nsXBLUncompiledMethod() :
73 mLastParameter(nsnull
),
76 MOZ_COUNT_CTOR(nsXBLUncompiledMethod
);
79 ~nsXBLUncompiledMethod() {
80 MOZ_COUNT_DTOR(nsXBLUncompiledMethod
);
84 PRInt32
GetParameterCount() {
86 for (nsXBLParameter
* curr
= mParameters
; curr
; curr
=curr
->mNext
)
91 void AppendBodyText(const nsAString
& aText
) {
92 mBodyText
.AppendText(aText
);
95 void AddParameter(const nsAString
& aText
) {
96 nsXBLParameter
* param
= new nsXBLParameter(aText
);
102 mLastParameter
->mNext
= param
;
103 mLastParameter
= param
;
106 void SetLineNumber(PRUint32 aLineNumber
) {
107 mBodyText
.SetLineNumber(aLineNumber
);
111 class nsXBLProtoImplMethod
: public nsXBLProtoImplMember
114 nsXBLProtoImplMethod(const PRUnichar
* aName
);
115 virtual ~nsXBLProtoImplMethod();
117 void AppendBodyText(const nsAString
& aBody
);
118 void AddParameter(const nsAString
& aName
);
120 void SetLineNumber(PRUint32 aLineNumber
);
122 virtual nsresult
InstallMember(nsIScriptContext
* aContext
,
123 nsIContent
* aBoundElement
,
125 void* aTargetClassObject
,
126 const nsCString
& aClassStr
);
127 virtual nsresult
CompileMember(nsIScriptContext
* aContext
,
128 const nsCString
& aClassStr
,
131 virtual void Trace(TraceCallback aCallback
, void *aClosure
) const;
133 PRBool
IsCompiled() const
135 return !(mUncompiledMethod
& BIT_UNCOMPILED
);
137 void SetUncompiledMethod(nsXBLUncompiledMethod
* aUncompiledMethod
)
139 mUncompiledMethod
= PRUptrdiff(aUncompiledMethod
) | BIT_UNCOMPILED
;
141 nsXBLUncompiledMethod
* GetUncompiledMethod() const
143 PRUptrdiff unmasked
= mUncompiledMethod
& ~BIT_UNCOMPILED
;
144 return reinterpret_cast<nsXBLUncompiledMethod
*>(unmasked
);
148 enum { BIT_UNCOMPILED
= 1 << 0 };
151 PRUptrdiff mUncompiledMethod
; // An object that represents the method before being compiled.
152 JSObject
* mJSMethodObject
; // The JS object for the method (after compilation)
160 class nsXBLProtoImplAnonymousMethod
: public nsXBLProtoImplMethod
{
162 nsXBLProtoImplAnonymousMethod() :
163 nsXBLProtoImplMethod(EmptyString().get())
166 nsresult
Execute(nsIContent
* aBoundElement
);
168 // Override InstallMember; these methods never get installed as members on
169 // binding instantiations (though they may hang out in mMembers on the
170 // prototype implementation).
171 virtual nsresult
InstallMember(nsIScriptContext
* aContext
,
172 nsIContent
* aBoundElement
,
174 void* aTargetClassObject
,
175 const nsCString
& aClassStr
) {
180 #endif // nsXBLProtoImplMethod_h__