~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/content/xbl/src/nsXBLPrototypeBinding.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
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
 * Original Author: David W. Hyatt (hyatt@netscape.com)
 
24
 *
 
25
 *
 
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.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
40
#ifndef nsXBLPrototypeBinding_h__
 
41
#define nsXBLPrototypeBinding_h__
 
42
 
 
43
#include "nsCOMPtr.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"
 
53
#include "nsIURL.h"
 
54
 
 
55
class nsIAtom;
 
56
class nsIDocument;
 
57
class nsIScriptContext;
 
58
class nsISupportsArray;
 
59
class nsSupportsHashtable;
 
60
class nsIXBLService;
 
61
class nsFixedSizeAllocator;
 
62
class nsXBLProtoImpl;
 
63
class nsIXBLBinding;
 
64
 
 
65
// *********************************************************************/
 
66
// The XBLPrototypeBinding class
 
67
 
 
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).
 
71
 
 
72
class nsXBLPrototypeBinding
 
73
{
 
74
public:
 
75
  already_AddRefed<nsIContent> GetBindingElement();
 
76
  void SetBindingElement(nsIContent* aElement);
 
77
 
 
78
  nsIURI* BindingURI() const { return mBindingURI; }
 
79
  nsIURI* DocURI() const { return mXBLDocInfoWeak->DocumentURI(); }
 
80
  nsresult GetID(nsACString& aResult) const { return mBindingURI->GetRef(aResult); }
 
81
 
 
82
  nsresult GetAllowScripts(PRBool* aResult);
 
83
 
 
84
  nsresult BindingAttached(nsIDOMEventReceiver* aRec);
 
85
  nsresult BindingDetached(nsIDOMEventReceiver* aRec);
 
86
 
 
87
  PRBool LoadResources();
 
88
  nsresult AddResource(nsIAtom* aResourceType, const nsAString& aSrc);
 
89
 
 
90
  PRBool InheritsStyle() { return mInheritStyle; }
 
91
 
 
92
  nsXBLPrototypeHandler* GetPrototypeHandlers() { return mPrototypeHandler; }
 
93
  void SetPrototypeHandlers(nsXBLPrototypeHandler* aHandler) { mPrototypeHandler = aHandler; }
 
94
 
 
95
  nsXBLPrototypeHandler* GetConstructor();
 
96
  nsresult SetConstructor(nsXBLPrototypeHandler* aConstructor);
 
97
  nsXBLPrototypeHandler* GetDestructor();
 
98
  nsresult SetDestructor(nsXBLPrototypeHandler* aDestructor);
 
99
 
 
100
  nsresult InitClass(const nsCString& aClassName, nsIScriptContext * aContext, void * aScriptObject, void ** aClassObject);
 
101
  
 
102
  nsresult ConstructInterfaceTable(const nsAString& aImpls);
 
103
  
 
104
  void SetImplementation(nsXBLProtoImpl* aImpl) { mImplementation = aImpl; }
 
105
  nsresult InstallImplementation(nsIContent* aBoundElement);
 
106
 
 
107
  void AttributeChanged(nsIAtom* aAttribute, PRInt32 aNameSpaceID,
 
108
                        PRBool aRemoveFlag, nsIContent* aChangedElement,
 
109
                        nsIContent* aAnonymousContent, PRBool aNotify);
 
110
 
 
111
  void SetBasePrototype(nsXBLPrototypeBinding* aBinding);
 
112
  nsXBLPrototypeBinding* GetBasePrototype() { return mBaseBinding; }
 
113
 
 
114
  nsIXBLDocumentInfo* XBLDocumentInfo() const { return mXBLDocInfoWeak; }
 
115
  
 
116
  PRBool HasBasePrototype() { return mHasBaseProto; }
 
117
  void SetHasBasePrototype(PRBool aHasBase) { mHasBaseProto = aHasBase; }
 
118
 
 
119
  void SetInitialAttributes(nsIContent* aBoundElement, nsIContent* aAnonymousContent);
 
120
 
 
121
  nsCOMArray<nsIStyleRuleProcessor>* GetRuleProcessors();
 
122
  nsCOMArray<nsICSSStyleSheet>* GetStyleSheets();
 
123
 
 
124
  PRBool HasInsertionPoints() { return mInsertionPointTable != nsnull; }
 
125
  
 
126
  PRBool HasStyleSheets() {
 
127
    return mResources && mResources->mStyleSheetList.Count() > 0;
 
128
  }
 
129
 
 
130
  nsresult FlushSkinSheets();
 
131
 
 
132
  void InstantiateInsertionPoints(nsIXBLBinding* aBinding);
 
133
 
 
134
  void GetInsertionPoint(nsIContent* aBoundElement, nsIContent* aCopyRoot,
 
135
                         nsIContent* aChild, nsIContent** aResult,
 
136
                         PRUint32* aIndex, nsIContent** aDefaultContent);
 
137
 
 
138
  void GetSingleInsertionPoint(nsIContent* aBoundElement,
 
139
                               nsIContent* aCopyRoot, nsIContent** aResult,
 
140
                               PRUint32* aIndex, PRBool* aMultiple,
 
141
                               nsIContent** aDefaultContent);
 
142
 
 
143
  void GetBaseTag(PRInt32* aNamespaceID, nsIAtom** aTag);
 
144
  void SetBaseTag(PRInt32 aNamespaceID, nsIAtom* aTag);
 
145
 
 
146
  PRBool ImplementsInterface(REFNSIID aIID);
 
147
 
 
148
  PRBool ShouldBuildChildFrames();
 
149
 
 
150
  nsresult AddResourceListener(nsIContent* aBoundElement);
 
151
 
 
152
  void Initialize();
 
153
 
 
154
  const nsCOMArray<nsXBLKeyEventHandler>* GetKeyEventHandlers()
 
155
  {
 
156
    if (!mKeyHandlersRegistered) {
 
157
      CreateKeyHandlers();
 
158
      mKeyHandlersRegistered = PR_TRUE;
 
159
    }
 
160
 
 
161
    return &mKeyHandlers;
 
162
  }
 
163
 
 
164
public:
 
165
  nsXBLPrototypeBinding();
 
166
  ~nsXBLPrototypeBinding();
 
167
 
 
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);
 
175
  
 
176
// Static members
 
177
  static PRUint32 gRefCnt;
 
178
 
 
179
  static nsFixedSizeAllocator* kAttrPool;
 
180
  static nsFixedSizeAllocator* kInsPool;
 
181
 
 
182
// Internal member functions
 
183
public:
 
184
  already_AddRefed<nsIContent> GetImmediateChild(nsIAtom* aTag);
 
185
  already_AddRefed<nsIContent> LocateInstance(nsIContent* aBoundElt,
 
186
                                              nsIContent* aTemplRoot,
 
187
                                              nsIContent* aCopyRoot,
 
188
                                              nsIContent* aTemplChild);
 
189
 
 
190
protected:  
 
191
  void ConstructAttributeTable(nsIContent* aElement);
 
192
  void ConstructInsertionTable(nsIContent* aElement);
 
193
  void GetNestedChildren(nsIAtom* aTag, nsIContent* aContent,
 
194
                         nsISupportsArray** aList);
 
195
  void CreateKeyHandlers();
 
196
 
 
197
protected:
 
198
  // Internal helper class for managing our IID table.
 
199
  class nsIIDKey : public nsHashKey {
 
200
    protected:
 
201
      nsIID mKey;
 
202
  
 
203
    public:
 
204
      nsIIDKey(REFNSIID key) : mKey(key) {}
 
205
      ~nsIIDKey(void) {}
 
206
 
 
207
      PRUint32 HashCode(void) const {
 
208
        // Just use the 32-bit m0 field.
 
209
        return mKey.m0;
 
210
      }
 
211
 
 
212
      PRBool Equals(const nsHashKey *aKey) const {
 
213
        return mKey.Equals( ((nsIIDKey*) aKey)->mKey);
 
214
      }
 
215
 
 
216
      nsHashKey *Clone(void) const {
 
217
        return new nsIIDKey(mKey);
 
218
      }
 
219
  };
 
220
 
 
221
// MEMBER VARIABLES
 
222
protected:
 
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.
 
226
  
 
227
  nsXBLProtoImpl* mImplementation; // Our prototype implementation (includes methods, properties, fields,
 
228
                                   // the constructor, and the destructor).
 
229
 
 
230
  nsXBLPrototypeBinding* mBaseBinding; // Weak.  The docinfo will own our base binding.
 
231
  PRPackedBool mInheritStyle;
 
232
  PRPackedBool mHasBaseProto;
 
233
  PRPackedBool mKeyHandlersRegistered;
 
234
 
 
235
  nsXBLPrototypeResources* mResources; // If we have any resources, this will be non-null.
 
236
                                      
 
237
  nsIXBLDocumentInfo* mXBLDocInfoWeak; // A pointer back to our doc info.  Weak, since it owns us.
 
238
 
 
239
  nsObjectHashtable* mAttributeTable; // A table for attribute entries.  Used to efficiently
 
240
                                      // handle attribute changes.
 
241
 
 
242
  nsObjectHashtable* mInsertionPointTable; // A table of insertion points for placing explicit content
 
243
                                           // underneath anonymous content.
 
244
 
 
245
  nsSupportsHashtable* mInterfaceTable; // A table of cached interfaces that we support.
 
246
 
 
247
  PRInt32 mBaseNameSpaceID;    // If we extend a tagname/namespace, then that information will
 
248
  nsCOMPtr<nsIAtom> mBaseTag;  // be stored in here.
 
249
 
 
250
  nsAutoRefCnt mRefCnt;
 
251
 
 
252
  nsCOMArray<nsXBLKeyEventHandler> mKeyHandlers;
 
253
};
 
254
 
 
255
#endif
 
256