LCOV - code coverage report
Current view: directory - content/xul/document/src - nsXULDocument.h (source / functions) Found Hit Coverage
Test: app.info Lines: 29 1 3.4 %
Date: 2012-06-02 Functions: 20 1 5.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       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                 :  *   Chris Waterson <waterson@netscape.com>
      24                 :  *   Dan Rosen <dr@netscape.com>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      28                 :  * or 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 MPL, 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 MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef nsXULDocument_h__
      41                 : #define nsXULDocument_h__
      42                 : 
      43                 : #include "nsCOMPtr.h"
      44                 : #include "nsXULPrototypeDocument.h"
      45                 : #include "nsXULPrototypeCache.h"
      46                 : #include "nsTArray.h"
      47                 : 
      48                 : #include "nsXMLDocument.h"
      49                 : #include "nsForwardReference.h"
      50                 : #include "nsIContent.h"
      51                 : #include "nsIDOMEventTarget.h"
      52                 : #include "nsIDOMXULCommandDispatcher.h"
      53                 : #include "nsIDOMXULDocument.h"
      54                 : #include "nsCOMArray.h"
      55                 : #include "nsIURI.h"
      56                 : #include "nsIXULDocument.h"
      57                 : #include "nsScriptLoader.h"
      58                 : #include "nsIStreamListener.h"
      59                 : #include "nsICSSLoaderObserver.h"
      60                 : 
      61                 : class nsIRDFResource;
      62                 : class nsIRDFService;
      63                 : class nsPIWindowRoot;
      64                 : #if 0 // XXXbe save me, scc (need NSCAP_FORWARD_DECL(nsXULPrototypeScript))
      65                 : class nsIObjectInputStream;
      66                 : class nsIObjectOutputStream;
      67                 : class nsIXULPrototypeScript;
      68                 : #else
      69                 : #include "nsIObjectInputStream.h"
      70                 : #include "nsIObjectOutputStream.h"
      71                 : #include "nsXULElement.h"
      72                 : #endif
      73                 : #include "nsURIHashKey.h"
      74                 : #include "nsInterfaceHashtable.h"
      75                 :  
      76                 : struct JSObject;
      77                 : struct PRLogModuleInfo;
      78                 : 
      79                 : class nsRefMapEntry : public nsStringHashKey
      80               0 : {
      81                 : public:
      82                 :   nsRefMapEntry(const nsAString& aKey) :
      83                 :     nsStringHashKey(&aKey)
      84                 :   {
      85                 :   }
      86               0 :   nsRefMapEntry(const nsAString *aKey) :
      87               0 :     nsStringHashKey(aKey)
      88                 :   {
      89               0 :   }
      90                 :   nsRefMapEntry(const nsRefMapEntry& aOther) :
      91                 :     nsStringHashKey(&aOther.GetKey())
      92                 :   {
      93                 :     NS_ERROR("Should never be called");
      94                 :   }
      95                 : 
      96                 :   mozilla::dom::Element* GetFirstElement();
      97                 :   void AppendAll(nsCOMArray<nsIContent>* aElements);
      98                 :   /**
      99                 :    * @return true if aElement was added, false if we failed due to OOM
     100                 :    */
     101                 :   bool AddElement(mozilla::dom::Element* aElement);
     102                 :   /**
     103                 :    * @return true if aElement was removed and it was the last content for
     104                 :    * this ref, so this entry should be removed from the map
     105                 :    */
     106                 :   bool RemoveElement(mozilla::dom::Element* aElement);
     107                 : 
     108                 : private:
     109                 :   nsSmallVoidArray mRefContentList;
     110                 : };
     111                 : 
     112                 : /**
     113                 :  * The XUL document class
     114                 :  */
     115                 : class nsXULDocument : public nsXMLDocument,
     116                 :                       public nsIXULDocument,
     117                 :                       public nsIDOMXULDocument,
     118                 :                       public nsIStreamLoaderObserver,
     119                 :                       public nsICSSLoaderObserver
     120                 : {
     121                 : public:
     122                 :     nsXULDocument();
     123                 :     virtual ~nsXULDocument();
     124                 : 
     125                 :     // nsISupports interface
     126                 :     NS_DECL_ISUPPORTS_INHERITED
     127                 :     NS_DECL_NSISTREAMLOADEROBSERVER
     128                 : 
     129                 :     // nsIDocument interface
     130                 :     virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
     131                 :     virtual void ResetToURI(nsIURI *aURI, nsILoadGroup* aLoadGroup,
     132                 :                             nsIPrincipal* aPrincipal);
     133                 : 
     134                 :     virtual nsresult StartDocumentLoad(const char* aCommand,
     135                 :                                        nsIChannel *channel,
     136                 :                                        nsILoadGroup* aLoadGroup,
     137                 :                                        nsISupports* aContainer,
     138                 :                                        nsIStreamListener **aDocListener,
     139                 :                                        bool aReset = true,
     140                 :                                        nsIContentSink* aSink = nsnull);
     141                 : 
     142                 :     virtual void SetContentType(const nsAString& aContentType);
     143                 : 
     144                 :     virtual void EndLoad();
     145                 : 
     146                 :     // nsIMutationObserver interface
     147                 :     NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
     148                 :     NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
     149                 :     NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
     150                 :     NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
     151                 :     NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
     152                 : 
     153                 :     // nsIXULDocument interface
     154                 :     virtual void GetElementsForID(const nsAString& aID,
     155                 :                                   nsCOMArray<nsIContent>& aElements);
     156                 : 
     157                 :     NS_IMETHOD GetScriptGlobalObjectOwner(nsIScriptGlobalObjectOwner** aGlobalOwner);
     158                 :     NS_IMETHOD AddSubtreeToDocument(nsIContent* aContent);
     159                 :     NS_IMETHOD RemoveSubtreeFromDocument(nsIContent* aContent);
     160                 :     NS_IMETHOD SetTemplateBuilderFor(nsIContent* aContent,
     161                 :                                      nsIXULTemplateBuilder* aBuilder);
     162                 :     NS_IMETHOD GetTemplateBuilderFor(nsIContent* aContent,
     163                 :                                      nsIXULTemplateBuilder** aResult);
     164                 :     NS_IMETHOD OnPrototypeLoadDone(bool aResumeWalk);
     165                 :     bool OnDocumentParserError();
     166                 : 
     167                 :     // nsIDOMNode interface overrides
     168                 :     NS_IMETHOD CloneNode(bool deep, nsIDOMNode **_retval);
     169                 : 
     170                 :     // nsIDOMDocument
     171                 :     NS_IMETHOD GetContentType(nsAString& aContentType);
     172                 : 
     173                 :     // nsDocument interface overrides
     174               0 :     NS_IMETHOD GetElementById(const nsAString& aId, nsIDOMElement** aReturn)
     175                 :     {
     176               0 :         return nsDocument::GetElementById(aId, aReturn);
     177                 :     }
     178                 :     virtual mozilla::dom::Element* GetElementById(const nsAString & elementId);
     179                 : 
     180                 :     // nsIDOMXULDocument interface
     181                 :     NS_DECL_NSIDOMXULDOCUMENT
     182                 : 
     183                 :     // nsICSSLoaderObserver
     184                 :     NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet,
     185                 :                                 bool aWasAlternate,
     186                 :                                 nsresult aStatus);
     187                 : 
     188                 :     virtual void EndUpdate(nsUpdateType aUpdateType);
     189                 : 
     190                 :     virtual bool IsDocumentRightToLeft();
     191                 : 
     192                 :     virtual void ResetDocumentDirection();
     193                 : 
     194                 :     virtual int GetDocumentLWTheme();
     195                 : 
     196               0 :     virtual void ResetDocumentLWTheme() { mDocLWTheme = Doc_Theme_Uninitialized; }
     197                 : 
     198                 :     static bool
     199                 :     MatchAttribute(nsIContent* aContent,
     200                 :                    PRInt32 aNameSpaceID,
     201                 :                    nsIAtom* aAttrName,
     202                 :                    void* aData);
     203                 : 
     204            1464 :     NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsXULDocument, nsXMLDocument)
     205                 : 
     206                 :     virtual nsXPCClassInfo* GetClassInfo();
     207                 : protected:
     208                 :     // Implementation methods
     209                 :     friend nsresult
     210                 :     NS_NewXULDocument(nsIXULDocument** aResult);
     211                 : 
     212                 :     nsresult Init(void);
     213                 :     nsresult StartLayout(void);
     214                 : 
     215                 :     nsresult
     216                 :     AddElementToRefMap(mozilla::dom::Element* aElement);
     217                 :     void
     218                 :     RemoveElementFromRefMap(mozilla::dom::Element* aElement);
     219                 : 
     220                 :     nsresult GetViewportSize(PRInt32* aWidth, PRInt32* aHeight);
     221                 : 
     222                 :     nsresult PrepareToLoad(nsISupports* aContainer,
     223                 :                            const char* aCommand,
     224                 :                            nsIChannel* aChannel,
     225                 :                            nsILoadGroup* aLoadGroup,
     226                 :                            nsIParser** aResult);
     227                 : 
     228                 :     nsresult
     229                 :     PrepareToLoadPrototype(nsIURI* aURI,
     230                 :                            const char* aCommand,
     231                 :                            nsIPrincipal* aDocumentPrincipal,
     232                 :                            nsIParser** aResult);
     233                 : 
     234                 :     nsresult 
     235                 :     LoadOverlayInternal(nsIURI* aURI, bool aIsDynamic, bool* aShouldReturn,
     236                 :                         bool* aFailureFromContent);
     237                 : 
     238                 :     nsresult ApplyPersistentAttributes();
     239                 :     nsresult ApplyPersistentAttributesInternal();
     240                 :     nsresult ApplyPersistentAttributesToElements(nsIRDFResource* aResource,
     241                 :                                                  nsCOMArray<nsIContent>& aElements);
     242                 : 
     243                 :     nsresult
     244                 :     AddElementToDocumentPre(mozilla::dom::Element* aElement);
     245                 : 
     246                 :     nsresult
     247                 :     AddElementToDocumentPost(mozilla::dom::Element* aElement);
     248                 : 
     249                 :     nsresult
     250                 :     ExecuteOnBroadcastHandlerFor(nsIContent* aBroadcaster,
     251                 :                                  nsIDOMElement* aListener,
     252                 :                                  nsIAtom* aAttr);
     253                 : 
     254                 :     nsresult
     255                 :     BroadcastAttributeChangeFromOverlay(nsIContent* aNode,
     256                 :                                         PRInt32 aNameSpaceID,
     257                 :                                         nsIAtom* aAttribute,
     258                 :                                         nsIAtom* aPrefix,
     259                 :                                         const nsAString& aValue);
     260                 : 
     261                 :     already_AddRefed<nsPIWindowRoot> GetWindowRoot();
     262                 : 
     263                 :     static NS_HIDDEN_(int) DirectionChanged(const char* aPrefName, void* aData);
     264                 : 
     265                 :     // pseudo constants
     266                 :     static PRInt32 gRefCnt;
     267                 : 
     268                 :     static nsIAtom** kIdentityAttrs[];
     269                 : 
     270                 :     static nsIRDFService* gRDFService;
     271                 :     static nsIRDFResource* kNC_persist;
     272                 :     static nsIRDFResource* kNC_attribute;
     273                 :     static nsIRDFResource* kNC_value;
     274                 : 
     275                 :     static nsXULPrototypeCache* gXULCache;
     276                 : 
     277                 :     static PRLogModuleInfo* gXULLog;
     278                 : 
     279                 :     bool
     280                 :     IsCapabilityEnabled(const char* aCapabilityLabel);
     281                 : 
     282                 :     nsresult
     283                 :     Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aAttribute);
     284                 : 
     285                 :     // IMPORTANT: The ownership implicit in the following member
     286                 :     // variables has been explicitly checked and set using nsCOMPtr
     287                 :     // for owning pointers and raw COM interface pointers for weak
     288                 :     // (ie, non owning) references. If you add any members to this
     289                 :     // class, please make the ownership explicit (pinkerton, scc).
     290                 :     // NOTE, THIS IS STILL IN PROGRESS, TALK TO PINK OR SCC BEFORE
     291                 :     // CHANGING
     292                 : 
     293                 :     nsXULDocument*             mNextSrcLoadWaiter;  // [OWNER] but not COMPtr
     294                 : 
     295                 :     // Tracks elements with a 'ref' attribute, or an 'id' attribute where
     296                 :     // the element's namespace has no registered ID attribute name.
     297                 :     nsTHashtable<nsRefMapEntry> mRefMap;
     298                 :     nsCOMPtr<nsIRDFDataSource> mLocalStore;
     299                 :     bool                       mApplyingPersistedAttrs;
     300                 :     bool                       mIsWritingFastLoad;
     301                 :     bool                       mDocumentLoaded;
     302                 :     /**
     303                 :      * Since ResumeWalk is interruptible, it's possible that last
     304                 :      * stylesheet finishes loading while the PD walk is still in
     305                 :      * progress (waiting for an overlay to finish loading).
     306                 :      * mStillWalking prevents DoneLoading (and StartLayout) from being
     307                 :      * called in this situation.
     308                 :      */
     309                 :     bool                       mStillWalking;
     310                 : 
     311                 :     /**
     312                 :      * An array of style sheets, that will be added (preserving order) to the
     313                 :      * document after all of them are loaded (in DoneWalking).
     314                 :      */
     315                 :     nsTArray<nsRefPtr<nsCSSStyleSheet> > mOverlaySheets;
     316                 : 
     317                 :     nsCOMPtr<nsIDOMXULCommandDispatcher>     mCommandDispatcher; // [OWNER] of the focus tracker
     318                 : 
     319                 :     // Maintains the template builders that have been attached to
     320                 :     // content elements
     321                 :     typedef nsInterfaceHashtable<nsISupportsHashKey, nsIXULTemplateBuilder>
     322                 :         BuilderTable;
     323                 :     BuilderTable* mTemplateBuilderTable;
     324                 : 
     325                 :     PRUint32 mPendingSheets;
     326                 : 
     327                 :     /**
     328                 :      * document lightweight theme for use with :-moz-lwtheme, :-moz-lwtheme-brighttext
     329                 :      * and :-moz-lwtheme-darktext
     330                 :      */
     331                 :     DocumentTheme                         mDocLWTheme;
     332                 : 
     333                 :     /**
     334                 :      * Context stack, which maintains the state of the Builder and allows
     335                 :      * it to be interrupted.
     336                 :      */
     337                 :     class ContextStack {
     338                 :     protected:
     339                 :         struct Entry {
     340                 :             nsXULPrototypeElement* mPrototype;
     341                 :             nsIContent*            mElement;
     342                 :             PRInt32                mIndex;
     343                 :             Entry*                 mNext;
     344                 :         };
     345                 : 
     346                 :         Entry* mTop;
     347                 :         PRInt32 mDepth;
     348                 : 
     349                 :     public:
     350                 :         ContextStack();
     351                 :         ~ContextStack();
     352                 : 
     353               0 :         PRInt32 Depth() { return mDepth; }
     354                 : 
     355                 :         nsresult Push(nsXULPrototypeElement* aPrototype, nsIContent* aElement);
     356                 :         nsresult Pop();
     357                 :         nsresult Peek(nsXULPrototypeElement** aPrototype, nsIContent** aElement, PRInt32* aIndex);
     358                 : 
     359                 :         nsresult SetTopIndex(PRInt32 aIndex);
     360                 :     };
     361                 : 
     362                 :     friend class ContextStack;
     363                 :     ContextStack mContextStack;
     364                 : 
     365                 :     enum State { eState_Master, eState_Overlay };
     366                 :     State mState;
     367                 : 
     368                 :     /**
     369                 :      * An array of overlay nsIURIs that have yet to be resolved. The
     370                 :      * order of the array is significant: overlays at the _end_ of the
     371                 :      * array are resolved before overlays earlier in the array (i.e.,
     372                 :      * it is a stack).
     373                 :      *
     374                 :      * In the current implementation the order the overlays are loaded
     375                 :      * in is as follows: first overlays from xul-overlay PIs, in the
     376                 :      * same order as in the document, then the overlays from the chrome
     377                 :      * registry.
     378                 :      */
     379                 :     nsCOMArray<nsIURI> mUnloadedOverlays;
     380                 : 
     381                 :     /**
     382                 :      * Load the transcluded script at the specified URI. If the
     383                 :      * prototype construction must 'block' until the load has
     384                 :      * completed, aBlock will be set to true.
     385                 :      */
     386                 :     nsresult LoadScript(nsXULPrototypeScript *aScriptProto, bool* aBlock);
     387                 : 
     388                 :     /**
     389                 :      * Execute the precompiled script object scoped by this XUL document's
     390                 :      * containing window object, and using its associated script context.
     391                 :      */
     392                 :     nsresult ExecuteScript(nsIScriptContext *aContext, JSScript* aScriptObject);
     393                 : 
     394                 :     /**
     395                 :      * Helper method for the above that uses aScript to find the appropriate
     396                 :      * script context and object.
     397                 :      */
     398                 :     nsresult ExecuteScript(nsXULPrototypeScript *aScript);
     399                 : 
     400                 :     /**
     401                 :      * Create a delegate content model element from a prototype.
     402                 :      * Note that the resulting content node is not bound to any tree
     403                 :      */
     404                 :     nsresult CreateElementFromPrototype(nsXULPrototypeElement* aPrototype,
     405                 :                                         mozilla::dom::Element** aResult);
     406                 : 
     407                 :     /**
     408                 :      * Create a hook-up element to which content nodes can be attached for
     409                 :      * later resolution.
     410                 :      */
     411                 :     nsresult CreateOverlayElement(nsXULPrototypeElement* aPrototype,
     412                 :                                   mozilla::dom::Element** aResult);
     413                 : 
     414                 :     /**
     415                 :      * Add attributes from the prototype to the element.
     416                 :      */
     417                 :     nsresult AddAttributes(nsXULPrototypeElement* aPrototype, nsIContent* aElement);
     418                 : 
     419                 :     /**
     420                 :      * The prototype-script of the current transcluded script that is being
     421                 :      * loaded.  For document.write('<script src="nestedwrite.js"><\/script>')
     422                 :      * to work, these need to be in a stack element type, and we need to hold
     423                 :      * the top of stack here.
     424                 :      */
     425                 :     nsXULPrototypeScript* mCurrentScriptProto;
     426                 : 
     427                 :     /**
     428                 :      * Check if a XUL template builder has already been hooked up.
     429                 :      */
     430                 :     static nsresult
     431                 :     CheckTemplateBuilderHookup(nsIContent* aElement, bool* aNeedsHookup);
     432                 : 
     433                 :     /**
     434                 :      * Create a XUL template builder on the specified node.
     435                 :      */
     436                 :     static nsresult
     437                 :     CreateTemplateBuilder(nsIContent* aElement);
     438                 : 
     439                 :     /**
     440                 :      * Add the current prototype's style sheets (currently it's just
     441                 :      * style overlays from the chrome registry) to the document.
     442                 :      */
     443                 :     nsresult AddPrototypeSheets();
     444                 : 
     445                 : 
     446                 : protected:
     447                 :     /* Declarations related to forward references. 
     448                 :      *
     449                 :      * Forward references are declarations which are added to the temporary
     450                 :      * list (mForwardReferences) during the document (or overlay) load and
     451                 :      * are resolved later, when the document loading is almost complete.
     452                 :      */
     453                 : 
     454                 :     /**
     455                 :      * The list of different types of forward references to resolve. After
     456                 :      * a reference is resolved, it is removed from this array (and
     457                 :      * automatically deleted)
     458                 :      */
     459                 :     nsTArray<nsAutoPtr<nsForwardReference> > mForwardReferences;
     460                 : 
     461                 :     /** Indicates what kind of forward references are still to be processed. */
     462                 :     nsForwardReference::Phase mResolutionPhase;
     463                 : 
     464                 :     /**
     465                 :      * Adds aRef to the mForwardReferences array. Takes the ownership of aRef.
     466                 :      */
     467                 :     nsresult AddForwardReference(nsForwardReference* aRef);
     468                 : 
     469                 :     /**
     470                 :      * Resolve all of the document's forward references.
     471                 :      */
     472                 :     nsresult ResolveForwardReferences();
     473                 : 
     474                 :     /**
     475                 :      * Used to resolve broadcaster references
     476                 :      */
     477                 :     class BroadcasterHookup : public nsForwardReference
     478                 :     {
     479                 :     protected:
     480                 :         nsXULDocument* mDocument;              // [WEAK]
     481                 :         nsRefPtr<mozilla::dom::Element> mObservesElement; // [OWNER]
     482                 :         bool mResolved;
     483                 : 
     484                 :     public:
     485               0 :         BroadcasterHookup(nsXULDocument* aDocument,
     486                 :                           mozilla::dom::Element* aObservesElement)
     487                 :             : mDocument(aDocument),
     488                 :               mObservesElement(aObservesElement),
     489               0 :               mResolved(false)
     490                 :         {
     491               0 :         }
     492                 : 
     493                 :         virtual ~BroadcasterHookup();
     494                 : 
     495               0 :         virtual Phase GetPhase() { return eHookup; }
     496                 :         virtual Result Resolve();
     497                 :     };
     498                 : 
     499                 :     friend class BroadcasterHookup;
     500                 : 
     501                 : 
     502                 :     /**
     503                 :      * Used to hook up overlays
     504                 :      */
     505                 :     class OverlayForwardReference : public nsForwardReference
     506                 :     {
     507                 :     protected:
     508                 :         nsXULDocument* mDocument;      // [WEAK]
     509                 :         nsCOMPtr<nsIContent> mOverlay; // [OWNER]
     510                 :         bool mResolved;
     511                 : 
     512                 :         nsresult Merge(nsIContent* aTargetNode, nsIContent* aOverlayNode, bool aNotify);
     513                 : 
     514                 :     public:
     515               0 :         OverlayForwardReference(nsXULDocument* aDocument, nsIContent* aOverlay)
     516               0 :             : mDocument(aDocument), mOverlay(aOverlay), mResolved(false) {}
     517                 : 
     518                 :         virtual ~OverlayForwardReference();
     519                 : 
     520               0 :         virtual Phase GetPhase() { return eConstruction; }
     521                 :         virtual Result Resolve();
     522                 :     };
     523                 : 
     524                 :     friend class OverlayForwardReference;
     525                 : 
     526                 :     class TemplateBuilderHookup : public nsForwardReference
     527               0 :     {
     528                 :     protected:
     529                 :         nsCOMPtr<nsIContent> mElement; // [OWNER]
     530                 : 
     531                 :     public:
     532               0 :         TemplateBuilderHookup(nsIContent* aElement)
     533               0 :             : mElement(aElement) {}
     534                 : 
     535               0 :         virtual Phase GetPhase() { return eHookup; }
     536                 :         virtual Result Resolve();
     537                 :     };
     538                 : 
     539                 :     friend class TemplateBuilderHookup;
     540                 : 
     541                 :     // The out params of FindBroadcaster only have values that make sense when
     542                 :     // the method returns NS_FINDBROADCASTER_FOUND.  In all other cases, the
     543                 :     // values of the out params should not be relied on (though *aListener and
     544                 :     // *aBroadcaster do need to be released if non-null, of course).
     545                 :     nsresult
     546                 :     FindBroadcaster(mozilla::dom::Element* aElement,
     547                 :                     nsIDOMElement** aListener,
     548                 :                     nsString& aBroadcasterID,
     549                 :                     nsString& aAttribute,
     550                 :                     nsIDOMElement** aBroadcaster);
     551                 : 
     552                 :     nsresult
     553                 :     CheckBroadcasterHookup(mozilla::dom::Element* aElement,
     554                 :                            bool* aNeedsHookup,
     555                 :                            bool* aDidResolve);
     556                 : 
     557                 :     void
     558                 :     SynchronizeBroadcastListener(nsIDOMElement   *aBroadcaster,
     559                 :                                  nsIDOMElement   *aListener,
     560                 :                                  const nsAString &aAttr);
     561                 : 
     562                 :     static
     563                 :     nsresult
     564                 :     InsertElement(nsIContent* aParent, nsIContent* aChild, bool aNotify);
     565                 : 
     566                 :     static 
     567                 :     nsresult
     568                 :     RemoveElement(nsIContent* aParent, nsIContent* aChild);
     569                 : 
     570                 :     /**
     571                 :      * The current prototype that we are walking to construct the
     572                 :      * content model.
     573                 :      */
     574                 :     nsRefPtr<nsXULPrototypeDocument> mCurrentPrototype;
     575                 : 
     576                 :     /**
     577                 :      * The master document (outermost, .xul) prototype, from which
     578                 :      * all subdocuments get their security principals.
     579                 :      */
     580                 :     nsRefPtr<nsXULPrototypeDocument> mMasterPrototype;
     581                 : 
     582                 :     /**
     583                 :      * Owning references to all of the prototype documents that were
     584                 :      * used to construct this document.
     585                 :      */
     586                 :     nsTArray< nsRefPtr<nsXULPrototypeDocument> > mPrototypes;
     587                 : 
     588                 :     /**
     589                 :      * Prepare to walk the current prototype.
     590                 :      */
     591                 :     nsresult PrepareToWalk();
     592                 : 
     593                 :     /**
     594                 :      * Creates a processing instruction based on aProtoPI and inserts
     595                 :      * it to the DOM (as the aIndex-th child of aParent).
     596                 :      */
     597                 :     nsresult
     598                 :     CreateAndInsertPI(const nsXULPrototypePI* aProtoPI,
     599                 :                       nsINode* aParent, PRUint32 aIndex);
     600                 : 
     601                 :     /**
     602                 :      * Inserts the passed <?xml-stylesheet ?> PI at the specified
     603                 :      * index. Loads and applies the associated stylesheet
     604                 :      * asynchronously.
     605                 :      * The prototype document walk can happen before the stylesheets
     606                 :      * are loaded, but the final steps in the load process (see
     607                 :      * DoneWalking()) are not run before all the stylesheets are done
     608                 :      * loading.
     609                 :      */
     610                 :     nsresult
     611                 :     InsertXMLStylesheetPI(const nsXULPrototypePI* aProtoPI,
     612                 :                           nsINode* aParent,
     613                 :                           PRUint32 aIndex,
     614                 :                           nsIContent* aPINode);
     615                 : 
     616                 :     /**
     617                 :      * Inserts the passed <?xul-overlay ?> PI at the specified index.
     618                 :      * Schedules the referenced overlay URI for further processing.
     619                 :      */
     620                 :     nsresult
     621                 :     InsertXULOverlayPI(const nsXULPrototypePI* aProtoPI,
     622                 :                        nsINode* aParent,
     623                 :                        PRUint32 aIndex,
     624                 :                        nsIContent* aPINode);
     625                 : 
     626                 :     /**
     627                 :      * Add overlays from the chrome registry to the set of unprocessed
     628                 :      * overlays still to do.
     629                 :      */
     630                 :     nsresult AddChromeOverlays();
     631                 : 
     632                 :     /**
     633                 :      * Resume (or initiate) an interrupted (or newly prepared)
     634                 :      * prototype walk.
     635                 :      */
     636                 :     nsresult ResumeWalk();
     637                 : 
     638                 :     /**
     639                 :      * Called at the end of ResumeWalk() and from StyleSheetLoaded().
     640                 :      * Expects that both the prototype document walk is complete and
     641                 :      * all referenced stylesheets finished loading.
     642                 :      */
     643                 :     nsresult DoneWalking();
     644                 : 
     645                 :     /**
     646                 :      * Report that an overlay failed to load
     647                 :      * @param aURI the URI of the overlay that failed to load
     648                 :      */
     649                 :     void ReportMissingOverlay(nsIURI* aURI);
     650                 : 
     651                 :     class CachedChromeStreamListener : public nsIStreamListener {
     652                 :     protected:
     653                 :         nsXULDocument* mDocument;
     654                 :         bool           mProtoLoaded;
     655                 : 
     656                 :         virtual ~CachedChromeStreamListener();
     657                 : 
     658                 :     public:
     659                 :         CachedChromeStreamListener(nsXULDocument* aDocument,
     660                 :                                    bool aProtoLoaded);
     661                 : 
     662                 :         NS_DECL_ISUPPORTS
     663                 :         NS_DECL_NSIREQUESTOBSERVER
     664                 :         NS_DECL_NSISTREAMLISTENER
     665                 :     };
     666                 : 
     667                 :     friend class CachedChromeStreamListener;
     668                 : 
     669                 : 
     670                 :     class ParserObserver : public nsIRequestObserver {
     671                 :     protected:
     672                 :         nsRefPtr<nsXULDocument> mDocument;
     673                 :         nsRefPtr<nsXULPrototypeDocument> mPrototype;
     674                 :         virtual ~ParserObserver();
     675                 : 
     676                 :     public:
     677                 :         ParserObserver(nsXULDocument* aDocument,
     678                 :                        nsXULPrototypeDocument* aPrototype);
     679                 : 
     680                 :         NS_DECL_ISUPPORTS
     681                 :         NS_DECL_NSIREQUESTOBSERVER
     682                 :     };
     683                 : 
     684                 :     friend class ParserObserver;
     685                 : 
     686                 :     /**
     687                 :      * A map from a broadcaster element to a list of listener elements.
     688                 :      */
     689                 :     PLDHashTable* mBroadcasterMap;
     690                 : 
     691                 :     nsInterfaceHashtable<nsURIHashKey,nsIObserver> mOverlayLoadObservers;
     692                 :     nsInterfaceHashtable<nsURIHashKey,nsIObserver> mPendingOverlayLoadNotifications;
     693                 :     
     694                 :     bool mInitialLayoutComplete;
     695                 : 
     696                 :     class nsDelayedBroadcastUpdate
     697               0 :     {
     698                 :     public:
     699               0 :       nsDelayedBroadcastUpdate(nsIDOMElement* aBroadcaster,
     700                 :                                nsIDOMElement* aListener,
     701                 :                                const nsAString &aAttr)
     702                 :       : mBroadcaster(aBroadcaster), mListener(aListener), mAttr(aAttr),
     703               0 :         mSetAttr(false), mNeedsAttrChange(false) {}
     704                 : 
     705               0 :       nsDelayedBroadcastUpdate(nsIDOMElement* aBroadcaster,
     706                 :                                nsIDOMElement* aListener,
     707                 :                                nsIAtom* aAttrName,
     708                 :                                const nsAString &aAttr,
     709                 :                                bool aSetAttr,
     710                 :                                bool aNeedsAttrChange)
     711                 :       : mBroadcaster(aBroadcaster), mListener(aListener), mAttr(aAttr),
     712                 :         mAttrName(aAttrName), mSetAttr(aSetAttr),
     713               0 :         mNeedsAttrChange(aNeedsAttrChange) {}
     714                 : 
     715               0 :       nsDelayedBroadcastUpdate(const nsDelayedBroadcastUpdate& aOther)
     716                 :       : mBroadcaster(aOther.mBroadcaster), mListener(aOther.mListener),
     717                 :         mAttr(aOther.mAttr), mAttrName(aOther.mAttrName),
     718               0 :         mSetAttr(aOther.mSetAttr), mNeedsAttrChange(aOther.mNeedsAttrChange) {}
     719                 : 
     720                 :       nsCOMPtr<nsIDOMElement> mBroadcaster;
     721                 :       nsCOMPtr<nsIDOMElement> mListener;
     722                 :       // Note if mAttrName isn't used, this is the name of the attr, otherwise
     723                 :       // this is the value of the attribute.
     724                 :       nsString                mAttr;
     725                 :       nsCOMPtr<nsIAtom>       mAttrName;
     726                 :       bool                    mSetAttr;
     727                 :       bool                    mNeedsAttrChange;
     728                 : 
     729                 :       class Comparator {
     730                 :         public:
     731               0 :           static bool Equals(const nsDelayedBroadcastUpdate& a, const nsDelayedBroadcastUpdate& b) {
     732               0 :             return a.mBroadcaster == b.mBroadcaster && a.mListener == b.mListener && a.mAttrName == b.mAttrName;
     733                 :           }
     734                 :       };
     735                 :     };
     736                 : 
     737                 :     nsTArray<nsDelayedBroadcastUpdate> mDelayedBroadcasters;
     738                 :     nsTArray<nsDelayedBroadcastUpdate> mDelayedAttrChangeBroadcasts;
     739                 :     bool                               mHandlingDelayedAttrChange;
     740                 :     bool                               mHandlingDelayedBroadcasters;
     741                 : 
     742                 :     void MaybeBroadcast();
     743                 : private:
     744                 :     // helpers
     745                 : 
     746                 : };
     747                 : 
     748                 : #endif // nsXULDocument_h__

Generated by: LCOV version 1.7