Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / content / xbl / src / nsXBLProtoImplMethod.h
blobf659c7ecbef3416bf454254fadca4513434e8b48
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
13 * License.
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.
22 * Contributor(s):
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__
42 #include "nsIAtom.h"
43 #include "nsString.h"
44 #include "jsapi.h"
45 #include "nsIContent.h"
46 #include "nsString.h"
47 #include "nsXBLProtoImplMember.h"
49 struct nsXBLParameter {
50 nsXBLParameter* mNext;
51 char* mName;
53 nsXBLParameter(const nsAString& aName) {
54 MOZ_COUNT_CTOR(nsXBLParameter);
55 mName = ToNewCString(aName);
56 mNext = nsnull;
59 ~nsXBLParameter() {
60 MOZ_COUNT_DTOR(nsXBLParameter);
61 nsMemory::Free(mName);
62 delete mNext;
66 struct nsXBLUncompiledMethod {
67 nsXBLParameter* mParameters;
68 nsXBLParameter* mLastParameter;
69 nsXBLTextWithLineNumber mBodyText;
71 nsXBLUncompiledMethod() :
72 mParameters(nsnull),
73 mLastParameter(nsnull),
74 mBodyText()
76 MOZ_COUNT_CTOR(nsXBLUncompiledMethod);
79 ~nsXBLUncompiledMethod() {
80 MOZ_COUNT_DTOR(nsXBLUncompiledMethod);
81 delete mParameters;
84 PRInt32 GetParameterCount() {
85 PRInt32 result = 0;
86 for (nsXBLParameter* curr = mParameters; curr; curr=curr->mNext)
87 result++;
88 return result;
91 void AppendBodyText(const nsAString& aText) {
92 mBodyText.AppendText(aText);
95 void AddParameter(const nsAString& aText) {
96 nsXBLParameter* param = new nsXBLParameter(aText);
97 if (!param)
98 return;
99 if (!mParameters)
100 mParameters = param;
101 else
102 mLastParameter->mNext = param;
103 mLastParameter = param;
106 void SetLineNumber(PRUint32 aLineNumber) {
107 mBodyText.SetLineNumber(aLineNumber);
111 class nsXBLProtoImplMethod: public nsXBLProtoImplMember
113 public:
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,
124 void* aScriptObject,
125 void* aTargetClassObject,
126 const nsCString& aClassStr);
127 virtual nsresult CompileMember(nsIScriptContext* aContext,
128 const nsCString& aClassStr,
129 void* aClassObject);
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);
147 protected:
148 enum { BIT_UNCOMPILED = 1 << 0 };
150 union {
151 PRUptrdiff mUncompiledMethod; // An object that represents the method before being compiled.
152 JSObject* mJSMethodObject; // The JS object for the method (after compilation)
155 #ifdef DEBUG
156 PRBool mIsCompiled;
157 #endif
160 class nsXBLProtoImplAnonymousMethod : public nsXBLProtoImplMethod {
161 public:
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,
173 void* aScriptObject,
174 void* aTargetClassObject,
175 const nsCString& aClassStr) {
176 return NS_OK;
180 #endif // nsXBLProtoImplMethod_h__