2001-11-13 04:09:56 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-11-13 04:09:56 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-11-13 04:09:56 +00:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-11-13 04:09:56 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-11-13 04:09:56 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-11-13 04:09:56 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-11-13 04:09:56 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef nsXBLProtoImpl_h__
|
|
|
|
#define nsXBLProtoImpl_h__
|
|
|
|
|
|
|
|
#include "nsMemory.h"
|
2003-02-28 01:04:45 +00:00
|
|
|
#include "nsXBLPrototypeHandler.h"
|
2001-11-13 04:09:56 +00:00
|
|
|
#include "nsXBLProtoImplMember.h"
|
2007-09-28 13:45:01 +00:00
|
|
|
#include "nsXBLProtoImplField.h"
|
2001-11-13 04:09:56 +00:00
|
|
|
|
2005-06-09 15:42:19 +00:00
|
|
|
class nsIXPConnectJSObjectHolder;
|
2007-09-28 13:45:01 +00:00
|
|
|
class nsXBLPrototypeBinding;
|
|
|
|
class nsXBLProtoImplAnonymousMethod;
|
2005-06-09 15:42:19 +00:00
|
|
|
|
2001-11-13 04:09:56 +00:00
|
|
|
class nsXBLProtoImpl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsXBLProtoImpl()
|
2003-02-28 01:04:45 +00:00
|
|
|
: mClassObject(nsnull),
|
|
|
|
mMembers(nsnull),
|
2007-09-28 13:45:01 +00:00
|
|
|
mFields(nsnull),
|
2003-02-28 01:04:45 +00:00
|
|
|
mConstructor(nsnull),
|
|
|
|
mDestructor(nsnull)
|
2001-11-13 04:09:56 +00:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsXBLProtoImpl);
|
2007-04-23 14:21:53 +00:00
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
~nsXBLProtoImpl()
|
|
|
|
{
|
2004-09-10 15:29:19 +00:00
|
|
|
MOZ_COUNT_DTOR(nsXBLProtoImpl);
|
|
|
|
// Note: the constructor and destructor are in mMembers, so we'll
|
|
|
|
// clean them up automatically.
|
2001-11-13 04:09:56 +00:00
|
|
|
for (nsXBLProtoImplMember* curr = mMembers; curr; curr=curr->GetNext())
|
|
|
|
curr->Destroy(mClassObject != nsnull);
|
2007-09-28 13:45:01 +00:00
|
|
|
delete mMembers;
|
|
|
|
delete mFields;
|
2007-04-23 14:21:53 +00:00
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
|
2003-03-06 23:59:18 +00:00
|
|
|
nsresult InstallImplementation(nsXBLPrototypeBinding* aBinding, nsIContent* aBoundElement);
|
|
|
|
nsresult InitTargetObjects(nsXBLPrototypeBinding* aBinding, nsIScriptContext* aContext,
|
2001-11-13 04:09:56 +00:00
|
|
|
nsIContent* aBoundElement,
|
2005-06-09 15:42:19 +00:00
|
|
|
nsIXPConnectJSObjectHolder** aScriptObjectHolder,
|
|
|
|
void** aTargetClassObject);
|
2003-03-06 23:59:18 +00:00
|
|
|
nsresult CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding);
|
2001-11-13 04:09:56 +00:00
|
|
|
|
2007-09-28 13:45:01 +00:00
|
|
|
void SetMemberList(nsXBLProtoImplMember* aMemberList)
|
|
|
|
{
|
|
|
|
delete mMembers;
|
|
|
|
mMembers = aMemberList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFieldList(nsXBLProtoImplField* aFieldList)
|
|
|
|
{
|
|
|
|
delete mFields;
|
|
|
|
mFields = aFieldList;
|
|
|
|
}
|
2001-11-13 04:09:56 +00:00
|
|
|
|
2007-10-29 13:45:07 +00:00
|
|
|
void Trace(TraceCallback aCallback, void *aClosure) const;
|
2008-01-30 02:05:43 +00:00
|
|
|
void UnlinkJSObjects();
|
2007-09-28 13:45:01 +00:00
|
|
|
|
|
|
|
nsXBLProtoImplField* FindField(const nsString& aFieldName) const;
|
|
|
|
|
|
|
|
// Resolve all the fields for this implementation on the object |obj| False
|
|
|
|
// return means a JS exception was set.
|
|
|
|
PRBool ResolveAllFields(JSContext *cx, JSObject *obj) const;
|
2007-05-24 14:10:02 +00:00
|
|
|
|
2007-10-20 04:22:43 +00:00
|
|
|
// Undefine all our fields from object |obj| (which should be a
|
|
|
|
// JSObject for a bound element).
|
|
|
|
void UndefineFields(JSContext* cx, JSObject* obj) const;
|
|
|
|
|
2007-10-06 01:23:09 +00:00
|
|
|
PRBool CompiledMembers() const {
|
|
|
|
return mClassObject != nsnull;
|
|
|
|
}
|
|
|
|
|
2004-01-27 21:18:00 +00:00
|
|
|
protected:
|
|
|
|
// Function to call if compilation of a member fails. When this is called,
|
|
|
|
// all members before aBrokenMember are compiled, compilation of
|
|
|
|
// aBrokenMember failed, and members after aBrokenMember are uncompiled.
|
|
|
|
// This function assumes that aBrokenMember is _not_ compiled.
|
|
|
|
void DestroyMembers(nsXBLProtoImplMember* aBrokenMember);
|
|
|
|
|
2001-11-13 04:09:56 +00:00
|
|
|
public:
|
|
|
|
nsCString mClassName; // The name of the class.
|
2005-02-06 20:34:15 +00:00
|
|
|
|
|
|
|
protected:
|
2001-11-13 04:09:56 +00:00
|
|
|
void* mClassObject; // The class object for the binding. We'll use this to pre-compile properties
|
|
|
|
// and methods for the binding.
|
|
|
|
|
|
|
|
nsXBLProtoImplMember* mMembers; // The members of an implementation are chained in this singly-linked list.
|
2007-09-28 13:45:01 +00:00
|
|
|
|
|
|
|
nsXBLProtoImplField* mFields; // Our fields
|
2001-11-13 04:09:56 +00:00
|
|
|
|
2005-02-06 20:34:15 +00:00
|
|
|
public:
|
2004-09-10 15:29:19 +00:00
|
|
|
nsXBLProtoImplAnonymousMethod* mConstructor; // Our class constructor.
|
|
|
|
nsXBLProtoImplAnonymousMethod* mDestructor; // Our class destructor.
|
2001-11-13 04:09:56 +00:00
|
|
|
};
|
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
nsresult
|
2003-03-06 23:59:18 +00:00
|
|
|
NS_NewXBLProtoImpl(nsXBLPrototypeBinding* aBinding,
|
2002-01-09 21:50:08 +00:00
|
|
|
const PRUnichar* aClassName,
|
2003-09-27 04:18:26 +00:00
|
|
|
nsXBLProtoImpl** aResult);
|
2001-11-13 04:09:56 +00:00
|
|
|
|
|
|
|
#endif // nsXBLProtoImpl_h__
|