Back to index

lightning-sunbird  0.9+nobinonly
nsDocument.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.org 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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsDocument_h___
00038 #define nsDocument_h___
00039 
00040 #include "nsCOMPtr.h"
00041 #include "nsAutoPtr.h"
00042 #include "nsCRT.h"
00043 #include "nsIDocument.h"
00044 #include "nsIDOMGCParticipant.h"
00045 #include "nsWeakReference.h"
00046 #include "nsWeakPtr.h"
00047 #include "nsVoidArray.h"
00048 #include "nsHashSets.h"
00049 #include "nsIDOMXMLDocument.h"
00050 #include "nsIDOM3Document.h"
00051 #include "nsIDOMDocumentView.h"
00052 #include "nsIDOMDocumentXBL.h"
00053 #include "nsIDOMNSDocument.h"
00054 #include "nsIDOMNSDocumentStyle.h"
00055 #include "nsIDOMDocumentRange.h"
00056 #include "nsIDOMDocumentTraversal.h"
00057 #include "nsStubDocumentObserver.h"
00058 #include "nsIDOMEventReceiver.h"
00059 #include "nsIDOM3EventTarget.h"
00060 #include "nsIDOMNSEventTarget.h"
00061 #include "nsIDOMStyleSheetList.h"
00062 #include "nsIScriptGlobalObject.h"
00063 #include "nsIDOMEventTarget.h"
00064 #include "nsIContent.h"
00065 #include "nsIEventListenerManager.h"
00066 #include "nsGenericDOMNodeList.h"
00067 #include "nsIDOM3Node.h"
00068 #include "nsIPrincipal.h"
00069 #include "nsIParser.h"
00070 #include "nsIBindingManager.h"
00071 #include "nsINodeInfo.h"
00072 #include "nsIDOMDocumentEvent.h"
00073 #include "nsIDOM3DocumentEvent.h"
00074 #include "nsCOMArray.h"
00075 #include "nsHashtable.h"
00076 #include "nsIWordBreakerFactory.h"
00077 #include "nsILineBreakerFactory.h"
00078 #include "nsIScriptObjectPrincipal.h"
00079 #include "nsIURI.h"
00080 #include "nsScriptLoader.h"
00081 #include "nsICSSLoader.h"
00082 #include "nsIDOMXPathEvaluator.h"
00083 #include "nsIRadioGroupContainer.h"
00084 #include "nsIScriptEventManager.h"
00085 #include "nsILayoutHistoryState.h"
00086 #include "nsIRequest.h"
00087 #include "nsILoadGroup.h"
00088 
00089 // Put these here so all document impls get them automatically
00090 #include "nsHTMLStyleSheet.h"
00091 #include "nsIHTMLCSSStyleSheet.h"
00092 
00093 #include "nsStyleSet.h"
00094 #include "nsXMLEventsManager.h"
00095 #include "pldhash.h"
00096 #include "nsAttrAndChildArray.h"
00097 
00098 #define XML_DECLARATION_BITS_DECLARATION_EXISTS   (1 << 0)
00099 #define XML_DECLARATION_BITS_ENCODING_EXISTS      (1 << 1)
00100 #define XML_DECLARATION_BITS_STANDALONE_EXISTS    (1 << 2)
00101 #define XML_DECLARATION_BITS_STANDALONE_YES       (1 << 3)
00102 
00103 
00104 class nsIEventListenerManager;
00105 class nsDOMStyleSheetList;
00106 class nsIOutputStream;
00107 class nsDocument;
00108 class nsIDTD;
00109 class nsXPathDocumentTearoff;
00110 class nsIRadioVisitor;
00111 class nsIFormControl;
00112 struct nsRadioGroupStruct;
00113 class nsOnloadBlocker;
00114 
00121 class nsUint32ToContentHashEntry : public PLDHashEntryHdr
00122 {
00123   public:
00124     typedef const PRUint32& KeyType;
00125     typedef const PRUint32* KeyTypePointer;
00126 
00127     nsUint32ToContentHashEntry(const KeyTypePointer key) :
00128       mValue(*key), mValOrHash(nsnull) { }
00129     nsUint32ToContentHashEntry(const nsUint32ToContentHashEntry& toCopy) :
00130       mValue(toCopy.mValue), mValOrHash(toCopy.mValOrHash)
00131     {
00132       // Pathetic attempt to not die: clear out the other mValOrHash so we're
00133       // effectively stealing it. If toCopy is destroyed right after this,
00134       // we'll be OK.
00135       NS_CONST_CAST(nsUint32ToContentHashEntry&, toCopy).mValOrHash = nsnull;
00136       NS_ERROR("Copying not supported. Fasten your seat belt.");
00137     }
00138     ~nsUint32ToContentHashEntry() { Destroy(); }
00139 
00140     KeyType GetKey() const { return mValue; }
00141     KeyTypePointer GetKeyPointer() const { return &mValue; }
00142 
00143     PRBool KeyEquals(KeyTypePointer aKey) const { return mValue == *aKey; }
00144 
00145     static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
00146     static PLDHashNumber HashKey(KeyTypePointer aKey) { return *aKey; }
00147     enum { ALLOW_MEMMOVE = PR_TRUE };
00148 
00149     // Content set methods
00150     nsresult PutContent(nsIContent* aContent);
00151 
00152     void RemoveContent(nsIContent* aContent);
00153 
00154     struct Visitor {
00155       virtual void Visit(nsIContent* aContent) = 0;
00156     };
00157     void VisitContent(Visitor* aVisitor);
00158 
00159     PRBool IsEmpty() { return mValOrHash == nsnull; }
00160 
00161   private:
00162     typedef unsigned long PtrBits;
00163     typedef nsTHashtable<nsISupportsHashKey> HashSet;
00165     HashSet* GetHashSet()
00166     {
00167       return (PtrBits(mValOrHash) & 0x1) ? nsnull : (HashSet*)mValOrHash;
00168     }
00170     nsIContent* GetContent()
00171     {
00172       return (PtrBits(mValOrHash) & 0x1)
00173              ? (nsIContent*)(PtrBits(mValOrHash) & ~0x1)
00174              : nsnull;
00175     }
00177     nsresult SetContent(nsIContent* aVal)
00178     {
00179       NS_IF_ADDREF(aVal);
00180       mValOrHash = (void*)(PtrBits(aVal) | 0x1);
00181       return NS_OK;
00182     }
00184     nsresult InitHashSet(HashSet** aSet);
00185 
00186     void Destroy();
00187 
00188   private:
00189     const PRUint32 mValue;
00191     void* mValOrHash;
00192 };
00193 
00194 
00195 class nsDocHeaderData
00196 {
00197 public:
00198   nsDocHeaderData(nsIAtom* aField, const nsAString& aData)
00199     : mField(aField), mData(aData), mNext(nsnull)
00200   {
00201   }
00202 
00203   ~nsDocHeaderData(void)
00204   {
00205     delete mNext;
00206   }
00207 
00208   nsCOMPtr<nsIAtom> mField;
00209   nsString          mData;
00210   nsDocHeaderData*  mNext;
00211 };
00212 
00213 // Represents the children of a document (prolog, epilog and
00214 // document element)
00215 class nsDocumentChildNodes : public nsGenericDOMNodeList
00216 {
00217 public:
00218   nsDocumentChildNodes(nsIDocument* aDocument);
00219   ~nsDocumentChildNodes();
00220 
00221   NS_IMETHOD    GetLength(PRUint32* aLength);
00222   NS_IMETHOD    Item(PRUint32 aIndex, nsIDOMNode** aReturn);
00223 
00224   void DropReference();
00225 
00226 protected:
00227   nsDocumentChildNodes(); // Not implemented
00228 
00229   nsIDocument* mDocument;
00230 };
00231 
00232 
00233 class nsDOMStyleSheetList : public nsIDOMStyleSheetList,
00234                             public nsStubDocumentObserver
00235 {
00236 public:
00237   nsDOMStyleSheetList(nsIDocument *aDocument);
00238   virtual ~nsDOMStyleSheetList();
00239 
00240   NS_DECL_ISUPPORTS
00241 
00242   NS_DECL_NSIDOMSTYLESHEETLIST
00243 
00244   // nsIDocumentObserver
00245   virtual void DocumentWillBeDestroyed(nsIDocument *aDocument);
00246   virtual void StyleSheetAdded(nsIDocument *aDocument,
00247                                nsIStyleSheet* aStyleSheet,
00248                                PRBool aDocumentSheet);
00249   virtual void StyleSheetRemoved(nsIDocument *aDocument,
00250                                  nsIStyleSheet* aStyleSheet,
00251                                  PRBool aDocumentSheet);
00252 
00253 protected:
00254   PRInt32       mLength;
00255   nsIDocument*  mDocument;
00256 };
00257 
00258 class nsOnloadBlocker : public nsIRequest
00259 {
00260 public:
00261   nsOnloadBlocker() {}
00262 
00263   NS_DECL_ISUPPORTS
00264   NS_DECL_NSIREQUEST
00265 
00266 private:
00267   ~nsOnloadBlocker() {}
00268 };
00269 
00276 class nsDocumentObserverList
00277 {
00278 public:
00279   nsDocumentObserverList() :
00280     mIterators(nsnull)
00281   {}
00282 
00283   class Iterator;
00284   friend class Iterator;
00285 
00286   class Iterator
00287   {
00288   public:
00289     nsIDocumentObserver* GetNext();
00290 
00291   protected:
00292     Iterator(PRInt32 aStep, nsDocumentObserverList& aList) :
00293       mPosition(aStep > 0 ? 0 : aList.mObservers.Count() - 1),
00294       mStep(aStep),
00295       mList(aList),
00296       mNext(aList.mIterators)
00297     {
00298       NS_ASSERTION(mStep == 1 || mStep == -1, "Invalid step size");
00299       aList.mIterators = this;
00300     }
00301 
00302     ~Iterator() {
00303       NS_ASSERTION(mList.mIterators == this, "Destroyed out of order?");
00304       mList.mIterators = mNext;
00305     }
00306 
00307     friend class nsDocumentObserverList;
00308 
00309     // Our current position in mObservers
00310     PRInt32 mPosition;
00311     
00312   private:
00313     // Which direction to move in
00314     PRInt32 mStep;
00315 
00316     // The observer array to work with
00317     nsDocumentObserverList& mList;
00318 
00319     // Our next iterator.
00320     Iterator* mNext;
00321   };
00322 
00323   class ForwardIterator : public Iterator
00324   {
00325   public:
00326     ForwardIterator(nsDocumentObserverList& aList) :
00327       Iterator(1, aList)
00328     {}
00329   };
00330 
00331   class ReverseIterator : public Iterator
00332   {
00333   public:
00334     ReverseIterator(nsDocumentObserverList& aList) :
00335       Iterator(-1, aList)
00336     {}
00337   };
00338 
00339   PRBool PrependElement(nsIDocumentObserver* aObserver);
00340 
00341   PRInt32 Contains(nsIDocumentObserver* aPossibleObserver) const {
00342     return mObservers.IndexOf(aPossibleObserver) != -1;
00343   }
00344 
00345   PRBool AppendElement(nsIDocumentObserver* aElement) {
00346     return mObservers.AppendElement(aElement);
00347   }
00348 
00349   PRBool RemoveElement(nsIDocumentObserver* aElement);
00350 
00351   void Clear();
00352 
00353 private:
00354   nsAutoVoidArray mObservers;
00355   Iterator* mIterators;
00356 };
00357 
00358 // Base class for our document implementations.
00359 //
00360 // Note that this class *implements* nsIDOMXMLDocument, but it's not
00361 // really an nsIDOMXMLDocument. The reason for implementing
00362 // nsIDOMXMLDocument on this class is to avoid having to duplicate all
00363 // its inherited methods on document classes that *are*
00364 // nsIDOMXMLDocument's. nsDocument's QI should *not* claim to support
00365 // nsIDOMXMLDocument unless someone writes a real implementation of
00366 // the interface.
00367 class nsDocument : public nsIDocument,
00368                    public nsIDocument_MOZILLA_1_8_0_BRANCH,
00369                    public nsIDocument_MOZILLA_1_8_BRANCH2,
00370                    public nsIDocument_MOZILLA_1_8_BRANCH3,
00371                    public nsIDOMXMLDocument, // inherits nsIDOMDocument
00372                    public nsIDOMNSDocument,
00373                    public nsIDOMDocumentEvent,
00374                    public nsIDOM3DocumentEvent,
00375                    public nsIDOMNSDocumentStyle,
00376                    public nsIDOMDocumentView,
00377                    public nsIDOMDocumentRange,
00378                    public nsIDOMDocumentTraversal,
00379                    public nsIDOMDocumentXBL,
00380                    public nsIDOM3Document,
00381                    public nsSupportsWeakReference,
00382                    public nsIDOMEventReceiver,
00383                    public nsIDOM3EventTarget,
00384                    public nsIDOMNSEventTarget,
00385                    public nsIScriptObjectPrincipal,
00386                    public nsIRadioGroupContainer,
00387                    public nsIDOMGCParticipant
00388 {
00389 public:
00390   NS_DECL_ISUPPORTS
00391 
00392   virtual void Reset(nsIChannel *aChannel, nsILoadGroup *aLoadGroup);
00393   virtual void ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup);
00394 
00395   virtual nsresult StartDocumentLoad(const char* aCommand,
00396                                      nsIChannel* aChannel,
00397                                      nsILoadGroup* aLoadGroup,
00398                                      nsISupports* aContainer,
00399                                      nsIStreamListener **aDocListener,
00400                                      PRBool aReset = PR_TRUE,
00401                                      nsIContentSink* aContentSink = nsnull);
00402 
00403   virtual void StopDocumentLoad();
00404 
00408   virtual nsIPrincipal* GetPrincipal();
00409 
00413   virtual void SetPrincipal(nsIPrincipal *aPrincipal);
00414 
00418   // NS_IMETHOD GetContentType(nsAString& aContentType);
00419   // Already declared in nsIDOMNSDocument
00420 
00424   virtual void SetContentType(const nsAString& aContentType);
00425 
00426   virtual nsresult SetBaseURI(nsIURI* aURI);
00427 
00431   virtual void GetBaseTarget(nsAString &aBaseTarget) const;
00432   virtual void SetBaseTarget(const nsAString &aBaseTarget);
00433 
00438   virtual void SetDocumentCharacterSet(const nsACString& aCharSetID);
00439 
00443   virtual nsresult AddCharSetObserver(nsIObserver* aObserver);
00444 
00448   virtual void RemoveCharSetObserver(nsIObserver* aObserver);
00449 
00453   virtual nsILineBreaker* GetLineBreaker();
00454   virtual void SetLineBreaker(nsILineBreaker* aLineBreaker);
00455   virtual nsIWordBreaker* GetWordBreaker();
00456   virtual void SetWordBreaker(nsIWordBreaker* aWordBreaker);
00457 
00462   virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const;
00463   virtual void SetHeaderData(nsIAtom* aheaderField,
00464                              const nsAString& aData);
00465 
00471   virtual nsresult CreateShell(nsPresContext* aContext,
00472                                nsIViewManager* aViewManager,
00473                                nsStyleSet* aStyleSet,
00474                                nsIPresShell** aInstancePtrResult);
00475   virtual PRBool DeleteShell(nsIPresShell* aShell);
00476   virtual PRUint32 GetNumberOfShells() const;
00477   virtual nsIPresShell *GetShellAt(PRUint32 aIndex) const;
00478 
00479   virtual nsresult SetSubDocumentFor(nsIContent *aContent,
00480                                      nsIDocument* aSubDoc);
00481   virtual nsIDocument* GetSubDocumentFor(nsIContent *aContent) const;
00482   virtual nsIContent* FindContentForSubDocument(nsIDocument *aDocument) const;
00483 
00484   virtual nsresult SetRootContent(nsIContent* aRoot);
00485 
00490   virtual nsIContent *GetChildAt(PRUint32 aIndex) const;
00491   virtual PRInt32 IndexOf(nsIContent* aPossibleChild) const;
00492   virtual PRUint32 GetChildCount() const;
00493   virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify);
00494 
00499   virtual PRInt32 GetNumberOfStyleSheets() const;
00500   virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex) const;
00501   virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const;
00502   virtual void AddStyleSheet(nsIStyleSheet* aSheet);
00503   virtual void RemoveStyleSheet(nsIStyleSheet* aSheet);
00504 
00505   virtual void UpdateStyleSheets(nsCOMArray<nsIStyleSheet>& aOldSheets,
00506                                  nsCOMArray<nsIStyleSheet>& aNewSheets);
00507   virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet);
00508   virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet);
00509 
00510   virtual void InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex);
00511   virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
00512                                             PRBool aApplicable);
00513 
00514   virtual PRInt32 GetNumberOfCatalogStyleSheets() const;
00515   virtual nsIStyleSheet* GetCatalogStyleSheetAt(PRInt32 aIndex) const;
00516   virtual void AddCatalogStyleSheet(nsIStyleSheet* aSheet);
00517   virtual void EnsureCatalogStyleSheet(const char *aStyleSheetURI);
00518 
00519   virtual nsIChannel* GetChannel() const {
00520     return mChannel;
00521   }
00522 
00527   virtual nsHTMLStyleSheet* GetAttributeStyleSheet() const {
00528     return mAttrStyleSheet;
00529   }
00530 
00535   virtual nsIHTMLCSSStyleSheet* GetInlineStyleSheet() const {
00536     return mStyleAttrStyleSheet;
00537   }
00538   
00544   virtual nsIScriptGlobalObject* GetScriptGlobalObject() const;
00545   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject);
00546   virtual nsIScriptGlobalObject*
00547     GetScriptHandlingObject(PRBool& aHasHadScriptHandlingObject) const;
00548   virtual void SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject);
00549   void ClearScriptHandlingObject()
00550   {
00551     mScriptObject = nsnull;
00552     mHasHadScriptHandlingObject = PR_TRUE;
00553   }
00554 
00555   virtual nsIScriptGlobalObject* GetScopeObject();
00556 
00560   virtual nsPIDOMWindow *GetWindow();
00561 
00565   virtual nsIScriptLoader* GetScriptLoader();
00566 
00572   virtual void AddObserver(nsIDocumentObserver* aObserver);
00573 
00578   virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver);
00579 
00580   // Observation hooks used to propagate notifications to document
00581   // observers.
00582   virtual void BeginUpdate(nsUpdateType aUpdateType);
00583   virtual void EndUpdate(nsUpdateType aUpdateType);
00584   virtual void BeginLoad();
00585   virtual void EndLoad();
00586   virtual void CharacterDataChanged(nsIContent* aContent,
00587                                     PRBool aAppend);
00588   virtual void ContentStatesChanged(nsIContent* aContent1,
00589                                     nsIContent* aContent2,
00590                                     PRInt32 aStateMask);
00591 
00592   virtual void AttributeWillChange(nsIContent* aChild,
00593                                    PRInt32 aNameSpaceID,
00594                                    nsIAtom* aAttribute);
00595   virtual void AttributeChanged(nsIContent* aChild,
00596                                 PRInt32 aNameSpaceID,
00597                                 nsIAtom* aAttribute,
00598                                 PRInt32 aModType);
00599   virtual void ContentAppended(nsIContent* aContainer,
00600                                PRInt32 aNewIndexInContainer);
00601   virtual void ContentInserted(nsIContent* aContainer,
00602                                nsIContent* aChild,
00603                                PRInt32 aIndexInContainer);
00604   virtual void ContentRemoved(nsIContent* aContainer,
00605                               nsIContent* aChild,
00606                               PRInt32 aIndexInContainer);
00607 
00608   virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet,
00609                                 nsIStyleRule* aOldStyleRule,
00610                                 nsIStyleRule* aNewStyleRule);
00611   virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet,
00612                               nsIStyleRule* aStyleRule);
00613   virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
00614                                 nsIStyleRule* aStyleRule);
00615 
00616   virtual void FlushPendingNotifications(mozFlushType aType);
00617   virtual nsIScriptEventManager* GetScriptEventManager();
00618   virtual void SetXMLDeclaration(const PRUnichar *aVersion,
00619                                  const PRUnichar *aEncoding,
00620                                  const PRInt32 aStandalone);
00621   virtual void GetXMLDeclaration(nsAString& aVersion,
00622                                  nsAString& aEncoding,
00623                                  nsAString& Standalone);
00624   virtual PRBool IsScriptEnabled();
00625 
00626   virtual nsresult HandleDOMEvent(nsPresContext* aPresContext,
00627                                   nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
00628                                   PRUint32 aFlags,
00629                                   nsEventStatus* aEventStatus);
00630 
00631   virtual void OnPageShow(PRBool aPersisted);
00632   virtual void OnPageHide(PRBool aPersisted);
00633 
00634   // nsIRadioGroupContainer
00635   NS_IMETHOD WalkRadioGroup(const nsAString& aName,
00636                             nsIRadioVisitor* aVisitor);
00637   NS_IMETHOD SetCurrentRadioButton(const nsAString& aName,
00638                                    nsIDOMHTMLInputElement* aRadio);
00639   NS_IMETHOD GetCurrentRadioButton(const nsAString& aName,
00640                                    nsIDOMHTMLInputElement** aRadio);
00641   NS_IMETHOD GetPositionInGroup(nsIDOMHTMLInputElement *aRadio,
00642                                 PRInt32 *aPositionIndex,
00643                                 PRInt32 *aItemsInGroup);
00644   NS_IMETHOD GetNextRadioButton(const nsAString& aName,
00645                                 const PRBool aPrevious,
00646                                 nsIDOMHTMLInputElement*  aFocusedRadio,
00647                                 nsIDOMHTMLInputElement** aRadioOut);
00648   NS_IMETHOD AddToRadioGroup(const nsAString& aName,
00649                              nsIFormControl* aRadio);
00650   NS_IMETHOD RemoveFromRadioGroup(const nsAString& aName,
00651                                   nsIFormControl* aRadio);
00652 
00653   // for radio group
00654   nsresult GetRadioGroup(const nsAString& aName,
00655                          nsRadioGroupStruct **aRadioGroup);
00656 
00657   // nsIDOMGCParticipant interface methods
00658   virtual nsIDOMGCParticipant* GetSCCIndex();
00659   virtual void AppendReachableList(nsCOMArray<nsIDOMGCParticipant>& aArray);
00660 
00661   // nsIDOMNode
00662   NS_DECL_NSIDOMNODE
00663 
00664   // nsIDOM3Node
00665   NS_DECL_NSIDOM3NODE
00666 
00667   // nsIDOMDocument
00668   NS_DECL_NSIDOMDOCUMENT
00669 
00670   // nsIDOM3Document
00671   NS_DECL_NSIDOM3DOCUMENT
00672 
00673   // nsIDOMXMLDocument
00674   NS_DECL_NSIDOMXMLDOCUMENT
00675 
00676   // nsIDOMNSDocument
00677   NS_DECL_NSIDOMNSDOCUMENT
00678 
00679   // nsIDOMDocumentEvent
00680   NS_DECL_NSIDOMDOCUMENTEVENT
00681 
00682   // nsIDOM3DocumentEvent
00683   NS_DECL_NSIDOM3DOCUMENTEVENT
00684 
00685   // nsIDOMDocumentStyle
00686   NS_DECL_NSIDOMDOCUMENTSTYLE
00687 
00688   // nsIDOMNSDocumentStyle
00689   NS_DECL_NSIDOMNSDOCUMENTSTYLE
00690 
00691   // nsIDOMDocumentView
00692   NS_DECL_NSIDOMDOCUMENTVIEW
00693 
00694   // nsIDOMDocumentRange
00695   NS_DECL_NSIDOMDOCUMENTRANGE
00696 
00697   // nsIDOMDocumentTraversal
00698   NS_DECL_NSIDOMDOCUMENTTRAVERSAL
00699 
00700   // nsIDOMDocumentXBL
00701   NS_DECL_NSIDOMDOCUMENTXBL
00702 
00703   // nsIDOMEventReceiver interface
00704   NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
00705                                    const nsIID& aIID);
00706   NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener,
00707                                       const nsIID& aIID);
00708   NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
00709   NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
00710   NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
00711 
00712   // nsIDOMEventTarget
00713   NS_DECL_NSIDOMEVENTTARGET
00714 
00715   // nsIDOM3EventTarget
00716   NS_DECL_NSIDOM3EVENTTARGET
00717 
00718   // nsIDOMNSEventTarget
00719   NS_DECL_NSIDOMNSEVENTTARGET
00720 
00721   // nsIScriptObjectPrincipal
00722   // virtual nsIPrincipal* GetPrincipal();
00723   // Already declared in nsIDocument
00724 
00725   virtual nsresult Init();
00726   
00727   virtual nsresult AddXMLEventsContent(nsIContent * aXMLEventsElement);
00728 
00729   virtual nsresult CreateElem(nsIAtom *aName, nsIAtom *aPrefix,
00730                               PRInt32 aNamespaceID,
00731                               PRBool aDocumentDefaultType,
00732                               nsIContent **aResult);
00733 
00734   virtual NS_HIDDEN_(void*) GetProperty(nsIAtom  *aPropertyName,
00735                                         nsresult *aStatus = nsnull) const;
00736 
00737   virtual NS_HIDDEN_(nsresult) SetProperty(nsIAtom            *aPropertyName,
00738                                            void               *aValue,
00739                                            NSPropertyDtorFunc  aDtor = nsnull);
00740 
00741   virtual NS_HIDDEN_(nsresult) DeleteProperty(nsIAtom *aPropertyName);
00742 
00743   virtual NS_HIDDEN_(void*) UnsetProperty(nsIAtom  *aPropertyName,
00744                                           nsresult *aStatus = nsnull);
00745 
00746   virtual NS_HIDDEN_(nsresult) Sanitize();
00747 
00748   virtual NS_HIDDEN_(void) EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
00749                                                  void *aData);
00750 
00751   virtual NS_HIDDEN_(PRBool) CanSavePresentation(nsIRequest *aNewRequest);
00752   virtual NS_HIDDEN_(void) Destroy();
00753   virtual NS_HIDDEN_(already_AddRefed<nsILayoutHistoryState>) GetLayoutHistoryState() const;
00754 
00755   virtual NS_HIDDEN_(void) BlockOnload();
00756   virtual NS_HIDDEN_(void) UnblockOnload();
00757 
00758   virtual NS_HIDDEN_(void) AddStyleRelevantLink(nsIContent* aContent, nsIURI* aURI);
00759   virtual NS_HIDDEN_(void) ForgetLink(nsIContent* aContent);
00760   virtual NS_HIDDEN_(void) NotifyURIVisitednessChanged(nsIURI* aURI);
00761 
00762 protected:
00763 
00764   void DispatchContentLoadedEvents();
00765 
00766   void RetrieveRelevantHeaders(nsIChannel *aChannel);
00767 
00768   static PRBool TryChannelCharset(nsIChannel *aChannel,
00769                                   PRInt32& aCharsetSource,
00770                                   nsACString& aCharset);
00771   
00772   void UpdateLinkMap();
00773   // Call this before the document does something that will unbind all content.
00774   // That will stop us from resolving URIs for all links as they are removed.
00775   void DestroyLinkMap();
00776 
00777   nsresult doCreateShell(nsPresContext* aContext,
00778                          nsIViewManager* aViewManager, nsStyleSet* aStyleSet,
00779                          nsCompatibility aCompatMode,
00780                          nsIPresShell** aInstancePtrResult);
00781 
00782   nsresult ResetStylesheetsToURI(nsIURI* aURI);
00783   virtual nsStyleSet::sheetType GetAttrSheetType();
00784   void FillStyleSet(nsStyleSet* aStyleSet);
00785 
00786   nsresult CreateElement(nsINodeInfo *aNodeInfo, PRInt32 aElementType,
00787                          nsIContent** aResult);
00788 
00789   // Return whether all the presshells for this document are safe to flush
00790   PRBool IsSafeToFlush() const;
00791   
00792   virtual PRInt32 GetDefaultNamespaceID() const
00793   {
00794     return kNameSpaceID_None;
00795   };
00796 
00797   // Dispatch an event to the ScriptGlobalObject for this document
00798   void DispatchEventToWindow(nsEvent *aEvent);
00799 
00800   // NS_DOCUMENT_NOTIFY_OBSERVERS goes backwards for now for backwards compat.
00801   // If you change this, update ContentAppended/Inserted/Removed accordingly.
00802 #define NS_DOCUMENT_NOTIFY_OBSERVERS(func_, params_)                          \
00803   do {                                                                        \
00804     nsDocumentObserverList::ReverseIterator iter_(mObservers);                \
00805     nsCOMPtr<nsIDocumentObserver> obs_;                                       \
00806     while ((obs_ = iter_.GetNext())) {                                        \
00807       obs_ -> func_ params_ ;                                                 \
00808     }                                                                         \
00809   } while (0)
00810 
00811 #define NS_DOCUMENT_FORWARD_NOTIFY_OBSERVERS(func_, params_)                  \
00812   do {                                                                        \
00813     nsDocumentObserverList::ForwardIterator iter_(mObservers);                \
00814     nsCOMPtr<nsIDocumentObserver> obs_;                                       \
00815     while ((obs_ = iter_.GetNext())) {                                        \
00816       obs_ -> func_ params_ ;                                                 \
00817     }                                                                         \
00818   } while (0)
00819  
00820   nsDocument();
00821   virtual ~nsDocument();
00822 
00823   nsCString mReferrer;
00824   nsString mLastModified;
00825   nsCOMPtr<nsIPrincipal> mPrincipal;
00826 
00827   nsVoidArray mCharSetObservers;
00828 
00829   PLDHashTable *mSubDocuments;
00830 
00831   nsSmallVoidArray mPresShells;
00832 
00833   // Array of owning references to all children
00834   nsAttrAndChildArray mChildren;
00835 
00836   // Pointer to our parser if we're currently in the process of being
00837   // parsed into.
00838   nsCOMPtr<nsIParser> mParser;
00839 
00840   nsCOMArray<nsIStyleSheet> mStyleSheets;
00841   nsCOMArray<nsIStyleSheet> mCatalogSheets;
00842 
00843   // Basically always has at least 1 entry
00844   nsDocumentObserverList mObservers;
00845 
00846   // The document's script global object, the object from which the
00847   // document can get its script context and scope. This is the
00848   // *inner* window object.
00849   nsCOMPtr<nsIScriptGlobalObject> mScriptGlobalObject;
00850 
00851   // If document is created for example using
00852   // document.implementation.createDocument(...), mScriptObject points to
00853   // the script global object of the original document.
00854   nsWeakPtr mScriptObject;
00855 
00856   // Weak reference to the scope object (aka the script global object)
00857   // that, unlike mScriptGlobalObject, is never unset once set. This
00858   // is a weak reference to avoid leaks due to circular references.
00859   nsWeakPtr mScopeObject;
00860 
00861   nsCOMPtr<nsIEventListenerManager> mListenerManager;
00862   nsCOMPtr<nsIDOMStyleSheetList> mDOMStyleSheets;
00863   nsCOMPtr<nsIScriptLoader> mScriptLoader;
00864   nsDocHeaderData* mHeaderData;
00865   nsCOMPtr<nsILineBreaker> mLineBreaker;
00866   nsCOMPtr<nsIWordBreaker> mWordBreaker;
00867 
00868   nsRefPtr<nsDocumentChildNodes> mChildNodes;
00869 
00870   nsHashtable mRadioGroups;
00871 
00872   // True if the document has been detached from its content viewer.
00873   PRPackedBool mIsGoingAway:1;
00874   // True if the document is being destroyed.
00875   PRPackedBool mInDestructor:1;
00876   // True if the document "page" is not hidden
00877   PRPackedBool mVisible:1;
00878   // True if document has ever had script handling object.
00879   PRPackedBool mHasHadScriptHandlingObject:1;
00880 
00881   PRUint8 mXMLDeclarationBits;
00882 
00883   PRUint8 mDefaultElementType;
00884 
00885   nsSupportsHashtable* mBoxObjectTable;
00886 
00887   // The channel that got passed to StartDocumentLoad(), if any
00888   nsCOMPtr<nsIChannel> mChannel;
00889   nsRefPtr<nsHTMLStyleSheet> mAttrStyleSheet;
00890   nsCOMPtr<nsIHTMLCSSStyleSheet> mStyleAttrStyleSheet;
00891   nsRefPtr<nsXMLEventsManager> mXMLEventsManager;
00892 
00893   nsCOMPtr<nsIScriptEventManager> mScriptEventManager;
00894 
00895   nsString mBaseTarget;
00896 
00897 private:
00898   nsresult IsAllowedAsChild(PRUint16 aNodeType, nsIContent* aRefContent);
00899 
00900   // These are not implemented and not supported.
00901   nsDocument(const nsDocument& aOther);
00902   nsDocument& operator=(const nsDocument& aOther);
00903 
00904   nsXPathDocumentTearoff* mXPathDocument;
00905 
00906   // The layout history state that should be used by nodes in this
00907   // document.  We only actually store a pointer to it when:
00908   // 1)  We have no script global object.
00909   // 2)  We haven't had Destroy() called on us yet.
00910   nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
00911 
00912   PRUint32 mOnloadBlockCount;
00913   nsCOMPtr<nsIRequest> mOnloadBlocker;
00914   
00915   // A map from unvisited URI hashes to content elements
00916   nsTHashtable<nsUint32ToContentHashEntry> mLinkMap;
00917   // URIs whose visitedness has changed while we were hidden
00918   nsCOMArray<nsIURI> mVisitednessChangedURIs;
00919 
00920   // Our update nesting level
00921   PRUint32 mUpdateNestLevel;
00922 };
00923 
00924 
00925 #endif /* nsDocument_h___ */