2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsXULDocument_h__
|
|
|
|
#define nsXULDocument_h__
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsXULPrototypeDocument.h"
|
|
|
|
#include "nsXULPrototypeCache.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
#include "nsXMLDocument.h"
|
|
|
|
#include "nsForwardReference.h"
|
|
|
|
#include "nsIContent.h"
|
2007-05-14 02:11:38 -07:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMXULCommandDispatcher.h"
|
|
|
|
#include "nsIDOMXULDocument.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIXULDocument.h"
|
|
|
|
#include "nsScriptLoader.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsICSSLoaderObserver.h"
|
|
|
|
|
2012-05-05 02:00:05 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIRDFResource;
|
|
|
|
class nsIRDFService;
|
2010-02-20 08:07:03 -08:00
|
|
|
class nsPIWindowRoot;
|
2007-03-22 10:30:00 -07:00
|
|
|
#if 0 // XXXbe save me, scc (need NSCAP_FORWARD_DECL(nsXULPrototypeScript))
|
|
|
|
class nsIObjectInputStream;
|
|
|
|
class nsIObjectOutputStream;
|
|
|
|
class nsIXULPrototypeScript;
|
|
|
|
#else
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsXULElement.h"
|
|
|
|
#endif
|
|
|
|
#include "nsURIHashKey.h"
|
|
|
|
#include "nsInterfaceHashtable.h"
|
2012-08-24 13:22:23 -07:00
|
|
|
|
2012-12-31 12:40:21 -08:00
|
|
|
class JSObject;
|
2012-08-24 13:22:23 -07:00
|
|
|
struct JSTracer;
|
2007-03-22 10:30:00 -07:00
|
|
|
struct PRLogModuleInfo;
|
|
|
|
|
2010-06-21 20:00:26 -07:00
|
|
|
class nsRefMapEntry : public nsStringHashKey
|
2008-06-22 18:48:05 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-06-21 20:00:26 -07:00
|
|
|
nsRefMapEntry(const nsAString& aKey) :
|
|
|
|
nsStringHashKey(&aKey)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
nsRefMapEntry(const nsAString *aKey) :
|
|
|
|
nsStringHashKey(aKey)
|
2008-06-22 18:48:05 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
nsRefMapEntry(const nsRefMapEntry& aOther) :
|
2010-06-21 20:00:26 -07:00
|
|
|
nsStringHashKey(&aOther.GetKey())
|
2008-06-22 18:48:05 -07:00
|
|
|
{
|
|
|
|
NS_ERROR("Should never be called");
|
|
|
|
}
|
|
|
|
|
2010-04-19 08:41:38 -07:00
|
|
|
mozilla::dom::Element* GetFirstElement();
|
2008-06-22 18:48:05 -07:00
|
|
|
void AppendAll(nsCOMArray<nsIContent>* aElements);
|
|
|
|
/**
|
2010-04-19 08:41:38 -07:00
|
|
|
* @return true if aElement was added, false if we failed due to OOM
|
2008-06-22 18:48:05 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AddElement(mozilla::dom::Element* aElement);
|
2008-06-22 18:48:05 -07:00
|
|
|
/**
|
2010-04-19 08:41:38 -07:00
|
|
|
* @return true if aElement was removed and it was the last content for
|
2008-06-22 18:48:05 -07:00
|
|
|
* this ref, so this entry should be removed from the map
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool RemoveElement(mozilla::dom::Element* aElement);
|
2008-06-22 18:48:05 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsSmallVoidArray mRefContentList;
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* The XUL document class
|
|
|
|
*/
|
|
|
|
class nsXULDocument : public nsXMLDocument,
|
|
|
|
public nsIXULDocument,
|
|
|
|
public nsIDOMXULDocument,
|
|
|
|
public nsIStreamLoaderObserver,
|
|
|
|
public nsICSSLoaderObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsXULDocument();
|
|
|
|
virtual ~nsXULDocument();
|
|
|
|
|
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSISTREAMLOADEROBSERVER
|
|
|
|
|
|
|
|
// nsIDocument interface
|
|
|
|
virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
|
|
|
|
virtual void ResetToURI(nsIURI *aURI, nsILoadGroup* aLoadGroup,
|
|
|
|
nsIPrincipal* aPrincipal);
|
|
|
|
|
|
|
|
virtual nsresult StartDocumentLoad(const char* aCommand,
|
|
|
|
nsIChannel *channel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIStreamListener **aDocListener,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aReset = true,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContentSink* aSink = nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
virtual void SetContentType(const nsAString& aContentType);
|
|
|
|
|
|
|
|
virtual void EndLoad();
|
|
|
|
|
|
|
|
// nsIMutationObserver interface
|
2007-07-12 13:05:45 -07:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
2009-06-29 11:36:25 -07:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
|
2008-06-22 18:48:05 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIXULDocument interface
|
2010-06-21 20:00:26 -07:00
|
|
|
virtual void GetElementsForID(const nsAString& aID,
|
|
|
|
nsCOMArray<nsIContent>& aElements);
|
2007-04-27 07:15:25 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD GetScriptGlobalObjectOwner(nsIScriptGlobalObjectOwner** aGlobalOwner);
|
2010-04-30 06:12:05 -07:00
|
|
|
NS_IMETHOD AddSubtreeToDocument(nsIContent* aContent);
|
|
|
|
NS_IMETHOD RemoveSubtreeFromDocument(nsIContent* aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD SetTemplateBuilderFor(nsIContent* aContent,
|
|
|
|
nsIXULTemplateBuilder* aBuilder);
|
|
|
|
NS_IMETHOD GetTemplateBuilderFor(nsIContent* aContent,
|
|
|
|
nsIXULTemplateBuilder** aResult);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD OnPrototypeLoadDone(bool aResumeWalk);
|
|
|
|
bool OnDocumentParserError();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-06 12:21:18 -08:00
|
|
|
// nsINode interface overrides
|
|
|
|
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-06 12:21:18 -08:00
|
|
|
// nsIDOMNode interface
|
|
|
|
NS_FORWARD_NSIDOMNODE_TO_NSINODE
|
|
|
|
|
|
|
|
// nsIDOMDocument interface
|
|
|
|
NS_FORWARD_NSIDOMDOCUMENT(nsXMLDocument::)
|
2012-12-22 00:27:27 -08:00
|
|
|
// And explicitly import the things from nsDocument that we just shadowed
|
|
|
|
using nsDocument::GetImplementation;
|
|
|
|
using nsDocument::GetTitle;
|
|
|
|
using nsDocument::SetTitle;
|
|
|
|
using nsDocument::GetLastStyleSheetSet;
|
|
|
|
using nsDocument::MozSetImageElement;
|
|
|
|
using nsDocument::GetMozFullScreenElement;
|
2011-05-28 00:43:53 -07:00
|
|
|
|
2010-04-19 08:41:38 -07:00
|
|
|
// nsDocument interface overrides
|
2010-06-03 18:09:20 -07:00
|
|
|
virtual mozilla::dom::Element* GetElementById(const nsAString & elementId);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIDOMXULDocument interface
|
|
|
|
NS_DECL_NSIDOMXULDOCUMENT
|
|
|
|
|
|
|
|
// nsICSSLoaderObserver
|
2010-05-11 13:41:47 -07:00
|
|
|
NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aWasAlternate,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult aStatus);
|
|
|
|
|
2008-09-16 01:53:30 -07:00
|
|
|
virtual void EndUpdate(nsUpdateType aUpdateType);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool IsDocumentRightToLeft();
|
2009-07-29 11:33:53 -07:00
|
|
|
|
2010-03-17 10:10:57 -07:00
|
|
|
virtual void ResetDocumentDirection();
|
2009-07-29 11:33:53 -07:00
|
|
|
|
2009-10-01 23:22:18 -07:00
|
|
|
virtual int GetDocumentLWTheme();
|
|
|
|
|
|
|
|
virtual void ResetDocumentLWTheme() { mDocLWTheme = Doc_Theme_Uninitialized; }
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
MatchAttribute(nsIContent* aContent,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttrName,
|
|
|
|
void* aData);
|
|
|
|
|
2011-04-27 08:44:24 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsXULDocument, nsXMLDocument)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
virtual nsXPCClassInfo* GetClassInfo();
|
2012-08-24 13:22:23 -07:00
|
|
|
|
|
|
|
void TraceProtos(JSTracer* aTrc, uint32_t aGCNumber);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
// Implementation methods
|
|
|
|
friend nsresult
|
|
|
|
NS_NewXULDocument(nsIXULDocument** aResult);
|
|
|
|
|
|
|
|
nsresult Init(void);
|
|
|
|
nsresult StartLayout(void);
|
|
|
|
|
|
|
|
nsresult
|
2010-04-19 08:41:38 -07:00
|
|
|
AddElementToRefMap(mozilla::dom::Element* aElement);
|
2008-06-22 18:48:05 -07:00
|
|
|
void
|
2010-04-19 08:41:38 -07:00
|
|
|
RemoveElementFromRefMap(mozilla::dom::Element* aElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult GetViewportSize(int32_t* aWidth, int32_t* aHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult PrepareToLoad(nsISupports* aContainer,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsIParser** aResult);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PrepareToLoadPrototype(nsIURI* aURI,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIPrincipal* aDocumentPrincipal,
|
|
|
|
nsIParser** aResult);
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
LoadOverlayInternal(nsIURI* aURI, bool aIsDynamic, bool* aShouldReturn,
|
|
|
|
bool* aFailureFromContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult ApplyPersistentAttributes();
|
2008-10-18 18:21:28 -07:00
|
|
|
nsresult ApplyPersistentAttributesInternal();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult ApplyPersistentAttributesToElements(nsIRDFResource* aResource,
|
|
|
|
nsCOMArray<nsIContent>& aElements);
|
|
|
|
|
|
|
|
nsresult
|
2010-04-30 06:12:05 -07:00
|
|
|
AddElementToDocumentPre(mozilla::dom::Element* aElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
2010-04-30 06:12:05 -07:00
|
|
|
AddElementToDocumentPost(mozilla::dom::Element* aElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
ExecuteOnBroadcastHandlerFor(nsIContent* aBroadcaster,
|
|
|
|
nsIDOMElement* aListener,
|
|
|
|
nsIAtom* aAttr);
|
|
|
|
|
2011-04-19 10:21:26 -07:00
|
|
|
nsresult
|
|
|
|
BroadcastAttributeChangeFromOverlay(nsIContent* aNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNameSpaceID,
|
2011-04-19 10:21:26 -07:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
nsIAtom* aPrefix,
|
|
|
|
const nsAString& aValue);
|
|
|
|
|
2010-02-20 08:07:03 -08:00
|
|
|
already_AddRefed<nsPIWindowRoot> GetWindowRoot();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-29 11:33:53 -07:00
|
|
|
static NS_HIDDEN_(int) DirectionChanged(const char* aPrefName, void* aData);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// pseudo constants
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t gRefCnt;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static nsIAtom** kIdentityAttrs[];
|
|
|
|
|
|
|
|
static nsIRDFService* gRDFService;
|
|
|
|
static nsIRDFResource* kNC_persist;
|
|
|
|
static nsIRDFResource* kNC_attribute;
|
|
|
|
static nsIRDFResource* kNC_value;
|
|
|
|
|
|
|
|
static nsXULPrototypeCache* gXULCache;
|
|
|
|
|
|
|
|
static PRLogModuleInfo* gXULLog;
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
Persist(nsIContent* aElement, int32_t aNameSpaceID, nsIAtom* aAttribute);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// IMPORTANT: The ownership implicit in the following member
|
|
|
|
// variables has been explicitly checked and set using nsCOMPtr
|
|
|
|
// for owning pointers and raw COM interface pointers for weak
|
|
|
|
// (ie, non owning) references. If you add any members to this
|
|
|
|
// class, please make the ownership explicit (pinkerton, scc).
|
|
|
|
// NOTE, THIS IS STILL IN PROGRESS, TALK TO PINK OR SCC BEFORE
|
|
|
|
// CHANGING
|
|
|
|
|
|
|
|
nsXULDocument* mNextSrcLoadWaiter; // [OWNER] but not COMPtr
|
|
|
|
|
2008-06-22 18:48:05 -07:00
|
|
|
// Tracks elements with a 'ref' attribute, or an 'id' attribute where
|
|
|
|
// the element's namespace has no registered ID attribute name.
|
|
|
|
nsTHashtable<nsRefMapEntry> mRefMap;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIRDFDataSource> mLocalStore;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mApplyingPersistedAttrs;
|
|
|
|
bool mIsWritingFastLoad;
|
|
|
|
bool mDocumentLoaded;
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Since ResumeWalk is interruptible, it's possible that last
|
|
|
|
* stylesheet finishes loading while the PD walk is still in
|
|
|
|
* progress (waiting for an overlay to finish loading).
|
|
|
|
* mStillWalking prevents DoneLoading (and StartLayout) from being
|
|
|
|
* called in this situation.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mStillWalking;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of style sheets, that will be added (preserving order) to the
|
|
|
|
* document after all of them are loaded (in DoneWalking).
|
|
|
|
*/
|
2010-05-11 13:41:47 -07:00
|
|
|
nsTArray<nsRefPtr<nsCSSStyleSheet> > mOverlaySheets;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULCommandDispatcher> mCommandDispatcher; // [OWNER] of the focus tracker
|
|
|
|
|
|
|
|
// Maintains the template builders that have been attached to
|
|
|
|
// content elements
|
|
|
|
typedef nsInterfaceHashtable<nsISupportsHashKey, nsIXULTemplateBuilder>
|
|
|
|
BuilderTable;
|
|
|
|
BuilderTable* mTemplateBuilderTable;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mPendingSheets;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-01 23:22:18 -07:00
|
|
|
/**
|
|
|
|
* document lightweight theme for use with :-moz-lwtheme, :-moz-lwtheme-brighttext
|
|
|
|
* and :-moz-lwtheme-darktext
|
|
|
|
*/
|
|
|
|
DocumentTheme mDocLWTheme;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Context stack, which maintains the state of the Builder and allows
|
|
|
|
* it to be interrupted.
|
|
|
|
*/
|
|
|
|
class ContextStack {
|
|
|
|
protected:
|
|
|
|
struct Entry {
|
|
|
|
nsXULPrototypeElement* mPrototype;
|
|
|
|
nsIContent* mElement;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
Entry* mNext;
|
|
|
|
};
|
|
|
|
|
|
|
|
Entry* mTop;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mDepth;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
ContextStack();
|
|
|
|
~ContextStack();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t Depth() { return mDepth; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult Push(nsXULPrototypeElement* aPrototype, nsIContent* aElement);
|
|
|
|
nsresult Pop();
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult Peek(nsXULPrototypeElement** aPrototype, nsIContent** aElement, int32_t* aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SetTopIndex(int32_t aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
friend class ContextStack;
|
|
|
|
ContextStack mContextStack;
|
|
|
|
|
|
|
|
enum State { eState_Master, eState_Overlay };
|
|
|
|
State mState;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of overlay nsIURIs that have yet to be resolved. The
|
|
|
|
* order of the array is significant: overlays at the _end_ of the
|
|
|
|
* array are resolved before overlays earlier in the array (i.e.,
|
|
|
|
* it is a stack).
|
|
|
|
*
|
|
|
|
* In the current implementation the order the overlays are loaded
|
|
|
|
* in is as follows: first overlays from xul-overlay PIs, in the
|
|
|
|
* same order as in the document, then the overlays from the chrome
|
|
|
|
* registry.
|
|
|
|
*/
|
2012-07-30 06:48:02 -07:00
|
|
|
nsTArray<nsCOMPtr<nsIURI> > mUnloadedOverlays;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the transcluded script at the specified URI. If the
|
|
|
|
* prototype construction must 'block' until the load has
|
|
|
|
* completed, aBlock will be set to true.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult LoadScript(nsXULPrototypeScript *aScriptProto, bool* aBlock);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the precompiled script object scoped by this XUL document's
|
|
|
|
* containing window object, and using its associated script context.
|
|
|
|
*/
|
2011-10-29 13:14:26 -07:00
|
|
|
nsresult ExecuteScript(nsIScriptContext *aContext, JSScript* aScriptObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for the above that uses aScript to find the appropriate
|
|
|
|
* script context and object.
|
|
|
|
*/
|
|
|
|
nsresult ExecuteScript(nsXULPrototypeScript *aScript);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a delegate content model element from a prototype.
|
|
|
|
* Note that the resulting content node is not bound to any tree
|
|
|
|
*/
|
|
|
|
nsresult CreateElementFromPrototype(nsXULPrototypeElement* aPrototype,
|
2010-04-30 06:12:05 -07:00
|
|
|
mozilla::dom::Element** aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a hook-up element to which content nodes can be attached for
|
|
|
|
* later resolution.
|
|
|
|
*/
|
2010-04-30 06:12:05 -07:00
|
|
|
nsresult CreateOverlayElement(nsXULPrototypeElement* aPrototype,
|
|
|
|
mozilla::dom::Element** aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add attributes from the prototype to the element.
|
|
|
|
*/
|
|
|
|
nsresult AddAttributes(nsXULPrototypeElement* aPrototype, nsIContent* aElement);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The prototype-script of the current transcluded script that is being
|
|
|
|
* loaded. For document.write('<script src="nestedwrite.js"><\/script>')
|
|
|
|
* to work, these need to be in a stack element type, and we need to hold
|
|
|
|
* the top of stack here.
|
|
|
|
*/
|
|
|
|
nsXULPrototypeScript* mCurrentScriptProto;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a XUL template builder has already been hooked up.
|
|
|
|
*/
|
|
|
|
static nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
CheckTemplateBuilderHookup(nsIContent* aElement, bool* aNeedsHookup);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a XUL template builder on the specified node.
|
|
|
|
*/
|
|
|
|
static nsresult
|
|
|
|
CreateTemplateBuilder(nsIContent* aElement);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the current prototype's style sheets (currently it's just
|
|
|
|
* style overlays from the chrome registry) to the document.
|
|
|
|
*/
|
|
|
|
nsresult AddPrototypeSheets();
|
|
|
|
|
2007-04-27 07:15:25 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/* Declarations related to forward references.
|
|
|
|
*
|
|
|
|
* Forward references are declarations which are added to the temporary
|
|
|
|
* list (mForwardReferences) during the document (or overlay) load and
|
|
|
|
* are resolved later, when the document loading is almost complete.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The list of different types of forward references to resolve. After
|
|
|
|
* a reference is resolved, it is removed from this array (and
|
|
|
|
* automatically deleted)
|
|
|
|
*/
|
|
|
|
nsTArray<nsAutoPtr<nsForwardReference> > mForwardReferences;
|
|
|
|
|
|
|
|
/** Indicates what kind of forward references are still to be processed. */
|
|
|
|
nsForwardReference::Phase mResolutionPhase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds aRef to the mForwardReferences array. Takes the ownership of aRef.
|
|
|
|
*/
|
|
|
|
nsresult AddForwardReference(nsForwardReference* aRef);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve all of the document's forward references.
|
|
|
|
*/
|
|
|
|
nsresult ResolveForwardReferences();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Used to resolve broadcaster references
|
|
|
|
*/
|
|
|
|
class BroadcasterHookup : public nsForwardReference
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
nsXULDocument* mDocument; // [WEAK]
|
2010-07-30 20:44:45 -07:00
|
|
|
nsRefPtr<mozilla::dom::Element> mObservesElement; // [OWNER]
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mResolved;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
BroadcasterHookup(nsXULDocument* aDocument,
|
2010-04-30 06:12:06 -07:00
|
|
|
mozilla::dom::Element* aObservesElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mDocument(aDocument),
|
|
|
|
mObservesElement(aObservesElement),
|
2011-10-17 07:59:28 -07:00
|
|
|
mResolved(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~BroadcasterHookup();
|
|
|
|
|
|
|
|
virtual Phase GetPhase() { return eHookup; }
|
|
|
|
virtual Result Resolve();
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class BroadcasterHookup;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to hook up overlays
|
|
|
|
*/
|
|
|
|
class OverlayForwardReference : public nsForwardReference
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
nsXULDocument* mDocument; // [WEAK]
|
|
|
|
nsCOMPtr<nsIContent> mOverlay; // [OWNER]
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mResolved;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult Merge(nsIContent* aTargetNode, nsIContent* aOverlayNode, bool aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
OverlayForwardReference(nsXULDocument* aDocument, nsIContent* aOverlay)
|
2011-10-17 07:59:28 -07:00
|
|
|
: mDocument(aDocument), mOverlay(aOverlay), mResolved(false) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
virtual ~OverlayForwardReference();
|
|
|
|
|
|
|
|
virtual Phase GetPhase() { return eConstruction; }
|
|
|
|
virtual Result Resolve();
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class OverlayForwardReference;
|
|
|
|
|
|
|
|
class TemplateBuilderHookup : public nsForwardReference
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIContent> mElement; // [OWNER]
|
|
|
|
|
|
|
|
public:
|
|
|
|
TemplateBuilderHookup(nsIContent* aElement)
|
|
|
|
: mElement(aElement) {}
|
|
|
|
|
|
|
|
virtual Phase GetPhase() { return eHookup; }
|
|
|
|
virtual Result Resolve();
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class TemplateBuilderHookup;
|
|
|
|
|
|
|
|
// The out params of FindBroadcaster only have values that make sense when
|
|
|
|
// the method returns NS_FINDBROADCASTER_FOUND. In all other cases, the
|
|
|
|
// values of the out params should not be relied on (though *aListener and
|
|
|
|
// *aBroadcaster do need to be released if non-null, of course).
|
|
|
|
nsresult
|
2010-04-30 06:12:06 -07:00
|
|
|
FindBroadcaster(mozilla::dom::Element* aElement,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDOMElement** aListener,
|
|
|
|
nsString& aBroadcasterID,
|
|
|
|
nsString& aAttribute,
|
|
|
|
nsIDOMElement** aBroadcaster);
|
|
|
|
|
|
|
|
nsresult
|
2010-04-30 06:12:06 -07:00
|
|
|
CheckBroadcasterHookup(mozilla::dom::Element* aElement,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aNeedsHookup,
|
|
|
|
bool* aDidResolve);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
SynchronizeBroadcastListener(nsIDOMElement *aBroadcaster,
|
|
|
|
nsIDOMElement *aListener,
|
2008-02-09 21:19:42 -08:00
|
|
|
const nsAString &aAttr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
InsertElement(nsIContent* aParent, nsIContent* aChild, bool aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static
|
|
|
|
nsresult
|
|
|
|
RemoveElement(nsIContent* aParent, nsIContent* aChild);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current prototype that we are walking to construct the
|
|
|
|
* content model.
|
|
|
|
*/
|
|
|
|
nsRefPtr<nsXULPrototypeDocument> mCurrentPrototype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The master document (outermost, .xul) prototype, from which
|
|
|
|
* all subdocuments get their security principals.
|
|
|
|
*/
|
|
|
|
nsRefPtr<nsXULPrototypeDocument> mMasterPrototype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Owning references to all of the prototype documents that were
|
|
|
|
* used to construct this document.
|
|
|
|
*/
|
|
|
|
nsTArray< nsRefPtr<nsXULPrototypeDocument> > mPrototypes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare to walk the current prototype.
|
|
|
|
*/
|
|
|
|
nsresult PrepareToWalk();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a processing instruction based on aProtoPI and inserts
|
|
|
|
* it to the DOM (as the aIndex-th child of aParent).
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
CreateAndInsertPI(const nsXULPrototypePI* aProtoPI,
|
2012-08-22 08:56:38 -07:00
|
|
|
nsINode* aParent, uint32_t aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts the passed <?xml-stylesheet ?> PI at the specified
|
|
|
|
* index. Loads and applies the associated stylesheet
|
|
|
|
* asynchronously.
|
|
|
|
* The prototype document walk can happen before the stylesheets
|
|
|
|
* are loaded, but the final steps in the load process (see
|
|
|
|
* DoneWalking()) are not run before all the stylesheets are done
|
|
|
|
* loading.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
InsertXMLStylesheetPI(const nsXULPrototypePI* aProtoPI,
|
|
|
|
nsINode* aParent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* aPINode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts the passed <?xul-overlay ?> PI at the specified index.
|
|
|
|
* Schedules the referenced overlay URI for further processing.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
InsertXULOverlayPI(const nsXULPrototypePI* aProtoPI,
|
|
|
|
nsINode* aParent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* aPINode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add overlays from the chrome registry to the set of unprocessed
|
|
|
|
* overlays still to do.
|
|
|
|
*/
|
|
|
|
nsresult AddChromeOverlays();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume (or initiate) an interrupted (or newly prepared)
|
|
|
|
* prototype walk.
|
|
|
|
*/
|
|
|
|
nsresult ResumeWalk();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called at the end of ResumeWalk() and from StyleSheetLoaded().
|
|
|
|
* Expects that both the prototype document walk is complete and
|
|
|
|
* all referenced stylesheets finished loading.
|
|
|
|
*/
|
|
|
|
nsresult DoneWalking();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report that an overlay failed to load
|
|
|
|
* @param aURI the URI of the overlay that failed to load
|
|
|
|
*/
|
|
|
|
void ReportMissingOverlay(nsIURI* aURI);
|
|
|
|
|
|
|
|
class CachedChromeStreamListener : public nsIStreamListener {
|
|
|
|
protected:
|
|
|
|
nsXULDocument* mDocument;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mProtoLoaded;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
virtual ~CachedChromeStreamListener();
|
|
|
|
|
|
|
|
public:
|
|
|
|
CachedChromeStreamListener(nsXULDocument* aDocument,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aProtoLoaded);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class CachedChromeStreamListener;
|
|
|
|
|
|
|
|
|
|
|
|
class ParserObserver : public nsIRequestObserver {
|
|
|
|
protected:
|
2007-07-11 12:44:27 -07:00
|
|
|
nsRefPtr<nsXULDocument> mDocument;
|
|
|
|
nsRefPtr<nsXULPrototypeDocument> mPrototype;
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~ParserObserver();
|
|
|
|
|
|
|
|
public:
|
2007-07-11 12:44:27 -07:00
|
|
|
ParserObserver(nsXULDocument* aDocument,
|
|
|
|
nsXULPrototypeDocument* aPrototype);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class ParserObserver;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A map from a broadcaster element to a list of listener elements.
|
|
|
|
*/
|
|
|
|
PLDHashTable* mBroadcasterMap;
|
|
|
|
|
|
|
|
nsInterfaceHashtable<nsURIHashKey,nsIObserver> mOverlayLoadObservers;
|
|
|
|
nsInterfaceHashtable<nsURIHashKey,nsIObserver> mPendingOverlayLoadNotifications;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mInitialLayoutComplete;
|
2008-09-16 01:53:30 -07:00
|
|
|
|
|
|
|
class nsDelayedBroadcastUpdate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDelayedBroadcastUpdate(nsIDOMElement* aBroadcaster,
|
|
|
|
nsIDOMElement* aListener,
|
|
|
|
const nsAString &aAttr)
|
2008-12-03 03:12:54 -08:00
|
|
|
: mBroadcaster(aBroadcaster), mListener(aListener), mAttr(aAttr),
|
2011-10-17 07:59:28 -07:00
|
|
|
mSetAttr(false), mNeedsAttrChange(false) {}
|
2008-12-03 03:12:54 -08:00
|
|
|
|
|
|
|
nsDelayedBroadcastUpdate(nsIDOMElement* aBroadcaster,
|
|
|
|
nsIDOMElement* aListener,
|
|
|
|
nsIAtom* aAttrName,
|
|
|
|
const nsAString &aAttr,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSetAttr,
|
|
|
|
bool aNeedsAttrChange)
|
2008-12-03 03:12:54 -08:00
|
|
|
: mBroadcaster(aBroadcaster), mListener(aListener), mAttr(aAttr),
|
2008-12-19 04:49:28 -08:00
|
|
|
mAttrName(aAttrName), mSetAttr(aSetAttr),
|
|
|
|
mNeedsAttrChange(aNeedsAttrChange) {}
|
2008-09-16 01:53:30 -07:00
|
|
|
|
|
|
|
nsDelayedBroadcastUpdate(const nsDelayedBroadcastUpdate& aOther)
|
|
|
|
: mBroadcaster(aOther.mBroadcaster), mListener(aOther.mListener),
|
2008-12-03 03:12:54 -08:00
|
|
|
mAttr(aOther.mAttr), mAttrName(aOther.mAttrName),
|
2008-12-19 04:49:28 -08:00
|
|
|
mSetAttr(aOther.mSetAttr), mNeedsAttrChange(aOther.mNeedsAttrChange) {}
|
2008-09-16 01:53:30 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> mBroadcaster;
|
|
|
|
nsCOMPtr<nsIDOMElement> mListener;
|
2008-12-03 03:12:54 -08:00
|
|
|
// Note if mAttrName isn't used, this is the name of the attr, otherwise
|
|
|
|
// this is the value of the attribute.
|
2008-09-16 01:53:30 -07:00
|
|
|
nsString mAttr;
|
2008-12-03 03:12:54 -08:00
|
|
|
nsCOMPtr<nsIAtom> mAttrName;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mSetAttr;
|
|
|
|
bool mNeedsAttrChange;
|
2009-10-13 03:11:17 -07:00
|
|
|
|
|
|
|
class Comparator {
|
|
|
|
public:
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool Equals(const nsDelayedBroadcastUpdate& a, const nsDelayedBroadcastUpdate& b) {
|
2009-10-13 03:11:17 -07:00
|
|
|
return a.mBroadcaster == b.mBroadcaster && a.mListener == b.mListener && a.mAttrName == b.mAttrName;
|
|
|
|
}
|
|
|
|
};
|
2008-09-16 01:53:30 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nsTArray<nsDelayedBroadcastUpdate> mDelayedBroadcasters;
|
2008-12-03 03:12:54 -08:00
|
|
|
nsTArray<nsDelayedBroadcastUpdate> mDelayedAttrChangeBroadcasts;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHandlingDelayedAttrChange;
|
|
|
|
bool mHandlingDelayedBroadcasters;
|
2009-01-31 04:53:01 -08:00
|
|
|
|
|
|
|
void MaybeBroadcast();
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
// helpers
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXULDocument_h__
|