1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
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
* Original Author: David W. Hyatt (hyatt@netscape.com)
26
* Alternatively, the contents of this file may be used under the terms of
27
* either the GNU General Public License Version 2 or later (the "GPL"), or
28
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
* in which case the provisions of the GPL or the LGPL are applicable instead
30
* of those above. If you wish to allow use of your version of this file only
31
* under the terms of either the GPL or the LGPL, and not to allow others to
32
* use your version of this file under the terms of the NPL, indicate your
33
* decision by deleting the provisions above and replace them with the notice
34
* and other provisions required by the GPL or the LGPL. If you do not delete
35
* the provisions above, a recipient may use your version of this file under
36
* the terms of any one of the NPL, the GPL or the LGPL.
38
* ***** END LICENSE BLOCK ***** */
40
#ifndef nsXBLPrototypeBinding_h__
41
#define nsXBLPrototypeBinding_h__
44
#include "nsXBLPrototypeResources.h"
45
#include "nsXBLPrototypeHandler.h"
46
#include "nsICSSStyleSheet.h"
47
#include "nsICSSLoaderObserver.h"
48
#include "nsWeakReference.h"
49
#include "nsIContent.h"
50
#include "nsHashtable.h"
51
#include "nsIXBLDocumentInfo.h"
52
#include "nsCOMArray.h"
57
class nsIScriptContext;
58
class nsISupportsArray;
59
class nsSupportsHashtable;
61
class nsFixedSizeAllocator;
65
// *********************************************************************/
66
// The XBLPrototypeBinding class
68
// References to the prototype binding are held by each nsXBLBinding instance
69
// that uses this prototype binding, and also by the XBLDocumentInfo's
70
// binding table (with the XUL cache disabled).
72
class nsXBLPrototypeBinding
75
already_AddRefed<nsIContent> GetBindingElement();
76
void SetBindingElement(nsIContent* aElement);
78
nsIURI* BindingURI() const { return mBindingURI; }
79
nsIURI* DocURI() const { return mXBLDocInfoWeak->DocumentURI(); }
80
nsresult GetID(nsACString& aResult) const { return mBindingURI->GetRef(aResult); }
82
nsresult GetAllowScripts(PRBool* aResult);
84
nsresult BindingAttached(nsIDOMEventReceiver* aRec);
85
nsresult BindingDetached(nsIDOMEventReceiver* aRec);
87
PRBool LoadResources();
88
nsresult AddResource(nsIAtom* aResourceType, const nsAString& aSrc);
90
PRBool InheritsStyle() { return mInheritStyle; }
92
nsXBLPrototypeHandler* GetPrototypeHandlers() { return mPrototypeHandler; }
93
void SetPrototypeHandlers(nsXBLPrototypeHandler* aHandler) { mPrototypeHandler = aHandler; }
95
nsXBLPrototypeHandler* GetConstructor();
96
nsresult SetConstructor(nsXBLPrototypeHandler* aConstructor);
97
nsXBLPrototypeHandler* GetDestructor();
98
nsresult SetDestructor(nsXBLPrototypeHandler* aDestructor);
100
nsresult InitClass(const nsCString& aClassName, nsIScriptContext * aContext, void * aScriptObject, void ** aClassObject);
102
nsresult ConstructInterfaceTable(const nsAString& aImpls);
104
void SetImplementation(nsXBLProtoImpl* aImpl) { mImplementation = aImpl; }
105
nsresult InstallImplementation(nsIContent* aBoundElement);
107
void AttributeChanged(nsIAtom* aAttribute, PRInt32 aNameSpaceID,
108
PRBool aRemoveFlag, nsIContent* aChangedElement,
109
nsIContent* aAnonymousContent, PRBool aNotify);
111
void SetBasePrototype(nsXBLPrototypeBinding* aBinding);
112
nsXBLPrototypeBinding* GetBasePrototype() { return mBaseBinding; }
114
nsIXBLDocumentInfo* XBLDocumentInfo() const { return mXBLDocInfoWeak; }
116
PRBool HasBasePrototype() { return mHasBaseProto; }
117
void SetHasBasePrototype(PRBool aHasBase) { mHasBaseProto = aHasBase; }
119
void SetInitialAttributes(nsIContent* aBoundElement, nsIContent* aAnonymousContent);
121
nsCOMArray<nsIStyleRuleProcessor>* GetRuleProcessors();
122
nsCOMArray<nsICSSStyleSheet>* GetStyleSheets();
124
PRBool HasInsertionPoints() { return mInsertionPointTable != nsnull; }
126
PRBool HasStyleSheets() {
127
return mResources && mResources->mStyleSheetList.Count() > 0;
130
nsresult FlushSkinSheets();
132
void InstantiateInsertionPoints(nsIXBLBinding* aBinding);
134
void GetInsertionPoint(nsIContent* aBoundElement, nsIContent* aCopyRoot,
135
nsIContent* aChild, nsIContent** aResult,
136
PRUint32* aIndex, nsIContent** aDefaultContent);
138
void GetSingleInsertionPoint(nsIContent* aBoundElement,
139
nsIContent* aCopyRoot, nsIContent** aResult,
140
PRUint32* aIndex, PRBool* aMultiple,
141
nsIContent** aDefaultContent);
143
void GetBaseTag(PRInt32* aNamespaceID, nsIAtom** aTag);
144
void SetBaseTag(PRInt32 aNamespaceID, nsIAtom* aTag);
146
PRBool ImplementsInterface(REFNSIID aIID);
148
PRBool ShouldBuildChildFrames();
150
nsresult AddResourceListener(nsIContent* aBoundElement);
154
const nsCOMArray<nsXBLKeyEventHandler>* GetKeyEventHandlers()
156
if (!mKeyHandlersRegistered) {
158
mKeyHandlersRegistered = PR_TRUE;
161
return &mKeyHandlers;
165
nsXBLPrototypeBinding();
166
~nsXBLPrototypeBinding();
168
// Init must be called after construction to initialize the prototype
169
// binding. It may well throw errors (eg on out-of-memory). Do not confuse
170
// this with the Initialize() method, which must be called after the
171
// binding's handlers, properties, etc are all set.
172
nsresult Init(const nsACString& aRef,
173
nsIXBLDocumentInfo* aInfo,
174
nsIContent* aElement);
177
static PRUint32 gRefCnt;
179
static nsFixedSizeAllocator* kAttrPool;
180
static nsFixedSizeAllocator* kInsPool;
182
// Internal member functions
184
already_AddRefed<nsIContent> GetImmediateChild(nsIAtom* aTag);
185
already_AddRefed<nsIContent> LocateInstance(nsIContent* aBoundElt,
186
nsIContent* aTemplRoot,
187
nsIContent* aCopyRoot,
188
nsIContent* aTemplChild);
191
void ConstructAttributeTable(nsIContent* aElement);
192
void ConstructInsertionTable(nsIContent* aElement);
193
void GetNestedChildren(nsIAtom* aTag, nsIContent* aContent,
194
nsISupportsArray** aList);
195
void CreateKeyHandlers();
198
// Internal helper class for managing our IID table.
199
class nsIIDKey : public nsHashKey {
204
nsIIDKey(REFNSIID key) : mKey(key) {}
207
PRUint32 HashCode(void) const {
208
// Just use the 32-bit m0 field.
212
PRBool Equals(const nsHashKey *aKey) const {
213
return mKey.Equals( ((nsIIDKey*) aKey)->mKey);
216
nsHashKey *Clone(void) const {
217
return new nsIIDKey(mKey);
223
nsCOMPtr<nsIURL> mBindingURI;
224
nsCOMPtr<nsIContent> mBinding; // Strong. We own a ref to our content element in the binding doc.
225
nsAutoPtr<nsXBLPrototypeHandler> mPrototypeHandler; // Strong. DocInfo owns us, and we own the handlers.
227
nsXBLProtoImpl* mImplementation; // Our prototype implementation (includes methods, properties, fields,
228
// the constructor, and the destructor).
230
nsXBLPrototypeBinding* mBaseBinding; // Weak. The docinfo will own our base binding.
231
PRPackedBool mInheritStyle;
232
PRPackedBool mHasBaseProto;
233
PRPackedBool mKeyHandlersRegistered;
235
nsXBLPrototypeResources* mResources; // If we have any resources, this will be non-null.
237
nsIXBLDocumentInfo* mXBLDocInfoWeak; // A pointer back to our doc info. Weak, since it owns us.
239
nsObjectHashtable* mAttributeTable; // A table for attribute entries. Used to efficiently
240
// handle attribute changes.
242
nsObjectHashtable* mInsertionPointTable; // A table of insertion points for placing explicit content
243
// underneath anonymous content.
245
nsSupportsHashtable* mInterfaceTable; // A table of cached interfaces that we support.
247
PRInt32 mBaseNameSpaceID; // If we extend a tagname/namespace, then that information will
248
nsCOMPtr<nsIAtom> mBaseTag; // be stored in here.
250
nsAutoRefCnt mRefCnt;
252
nsCOMArray<nsXBLKeyEventHandler> mKeyHandlers;