Back to index

lightning-sunbird  0.9+nobinonly
nsXBLBinding.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Original Author: David W. Hyatt (hyatt@netscape.com)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsCOMPtr.h"
00040 #include "nsAutoPtr.h"
00041 #include "nsIDOMNodeList.h"
00042 #include "nsIStyleRuleProcessor.h"
00043 
00044 class nsXBLPrototypeBinding;
00045 class nsIContent;
00046 class nsIAtom;
00047 class nsIDocument;
00048 class nsIScriptContext;
00049 class nsObjectHashtable;
00050 struct JSContext;
00051 struct JSObject;
00052 
00053 // *********************************************************************/
00054 // The XBLBinding class
00055 
00056 class nsXBLBinding
00057 {
00058 public:
00059   nsXBLBinding(nsXBLPrototypeBinding* aProtoBinding);
00060   ~nsXBLBinding();
00061 
00072   nsrefcnt AddRef()
00073   {
00074     ++mRefCnt;
00075     NS_LOG_ADDREF(this, mRefCnt, "nsXBLBinding", sizeof(nsXBLBinding));
00076     return mRefCnt;
00077   }
00078 
00079   nsrefcnt Release()
00080   {
00081     --mRefCnt;
00082     NS_LOG_RELEASE(this, mRefCnt, "nsXBLBinding");
00083     if (mRefCnt == 0) {
00084       mRefCnt = 1;
00085       delete this;
00086       return 0;
00087     }
00088     return mRefCnt;
00089   }
00090 
00091   nsXBLPrototypeBinding* PrototypeBinding() { return mPrototypeBinding; }
00092   nsIContent* GetAnonymousContent() { return mContent; }
00093 
00094   nsXBLBinding* GetBaseBinding() { return mNextBinding; }
00095   void SetBaseBinding(nsXBLBinding *aBinding);
00096 
00097   nsIContent* GetBoundElement() { return mBoundElement; }
00098   void SetBoundElement(nsIContent *aElement);
00099 
00100   PRBool IsStyleBinding() const { return mIsStyleBinding; }
00101   void SetIsStyleBinding(PRBool aIsStyle) { mIsStyleBinding = aIsStyle; }
00102 
00103   void MarkForDeath();
00104   PRBool MarkedForDeath() const { return mMarkedForDeath; }
00105 
00106   PRBool HasStyleSheets() const;
00107   PRBool InheritsStyle() const;
00108   PRBool ImplementsInterface(REFNSIID aIID) const;
00109   PRBool ShouldBuildChildFrames() const;
00110 
00111   void GenerateAnonymousContent();
00112   void InstallAnonymousContent(nsIContent* aAnonParent, nsIContent* aElement);
00113   void InstallEventHandlers();
00114   nsresult InstallImplementation();
00115 
00116   void ExecuteAttachedHandler();
00117   void ExecuteDetachedHandler();
00118   void UnhookEventHandlers();
00119 
00120   nsIAtom* GetBaseTag(PRInt32* aNameSpaceID);
00121   nsXBLBinding* GetFirstBindingWithConstructor();
00122   nsXBLBinding* RootBinding();
00123   nsXBLBinding* GetFirstStyleBinding();
00124 
00125   // Get the list of insertion points for aParent.  The nsVoidArray is owned
00126   // by the binding, you should not delete it.
00127   nsresult GetInsertionPointsFor(nsIContent* aParent, nsVoidArray** aResult);
00128 
00129   nsIContent* GetInsertionPoint(nsIContent* aChild, PRUint32* aIndex);
00130 
00131   nsIContent* GetSingleInsertionPoint(PRUint32* aIndex,
00132                                       PRBool* aMultipleInsertionPoints);
00133 
00134   void AttributeChanged(nsIAtom* aAttribute, PRInt32 aNameSpaceID,
00135                         PRBool aRemoveFlag, PRBool aNotify);
00136 
00137   void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument);
00138 
00139   void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData);
00140 
00141   already_AddRefed<nsIDOMNodeList> GetAnonymousNodes();
00142 
00143   static nsresult GetTextData(nsIContent *aParent, nsString& aResult);
00144 
00145   static nsresult DoInitJSClass(JSContext *cx, JSObject *global, JSObject *obj,
00146                                 const nsAFlatCString& aClassName,
00147                                 void **aClassObject);
00148 
00149 // Internal member functions
00150 protected:
00151   nsresult InitClass(const nsCString& aClassName, nsIScriptContext* aContext,
00152                      nsIDocument* aDocument, void** aScriptObject,
00153                      void** aClassObject);
00154 
00155   PRBool AllowScripts();  // XXX make const
00156   
00157 // MEMBER VARIABLES
00158 protected:
00159   nsAutoRefCnt mRefCnt;
00160   nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo
00161   nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us.
00162   nsRefPtr<nsXBLBinding> mNextBinding; // Strong. The derived binding owns the base class bindings.
00163   
00164   nsIContent* mBoundElement; // [WEAK] We have a reference, but we don't own it.
00165   
00166   nsObjectHashtable* mInsertionPointTable;    // A hash from nsIContent* -> (a sorted array of nsXBLInsertionPoint*)
00167 
00168   PRPackedBool mIsStyleBinding;
00169   PRPackedBool mMarkedForDeath;
00170 };