378327 - minor cleanup/simplification of ForwardReferences code in nsXULDocument

- move AddForwardReference and ResolveForwardReferences from nsIXULDocument to
nsXULDocument, make them non-virtual.
- make mForwardReferences an nsTArray<nsAutoPtr<nsForwardReference> > instead
of nsAutoVoidArray.

r=smaug, sr=roc
This commit is contained in:
asqueella%gmail.com 2007-04-27 14:15:25 +00:00
Родитель 625a20520f
Коммит 90c7ae7568
3 изменённых файлов: 48 добавлений и 56 удалений

Просмотреть файл

@ -42,22 +42,15 @@
#include "nsString.h"
#include "nsCOMArray.h"
class nsForwardReference;
class nsIAtom;
class nsIDOMElement;
class nsIPrincipal;
class nsIRDFResource;
class nsISupportsArray;
class nsIXULTemplateBuilder;
class nsIURI;
class nsIContent;
class nsIRDFDataSource;
class nsIScriptGlobalObjectOwner;
// {01c4fe87-961f-4194-a21d-04f4387c4bb3}
// {57314526-f749-4cf0-b6b6-3723eba21480}
#define NS_IXULDOCUMENT_IID \
{ 0x01c4fe87, 0x961f, 0x4194, \
{ 0xa2, 0x1d, 0x04, 0xf4, 0x38, 0x7c, 0x4b, 0xb3 } }
{ 0x57314526, 0xf749, 0x4cf0, \
{ 0xb6, 0xb6, 0x37, 0x23, 0xeb, 0xa2, 0x14, 0x80 } }
/*
@ -90,17 +83,6 @@ public:
*/
NS_IMETHOD GetElementsForID(const nsAString& aID, nsCOMArray<nsIContent>& aElements) = 0;
/**
* Add a "forward declaration" of a XUL observer. Such declarations
* will be resolved when document loading completes.
*/
NS_IMETHOD AddForwardReference(nsForwardReference* aForwardReference) = 0;
/**
* Resolve the all of the document's forward references.
*/
NS_IMETHOD ResolveForwardReferences() = 0;
/**
* Get the nsIScriptGlobalObjectOwner for this document.
*/

Просмотреть файл

@ -218,7 +218,7 @@ nsXULDocument::~nsXULDocument()
// In case we failed somewhere early on and the forward observer
// decls never got resolved.
DestroyForwardReferences();
mForwardReferences.Clear();
// Destroy our broadcaster map.
if (mBroadcasterMap) {
@ -1070,11 +1070,14 @@ nsXULDocument::GetElementsForID(const nsAString& aID,
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsXULDocument::AddForwardReference(nsForwardReference* aRef)
{
if (mResolutionPhase < aRef->GetPhase()) {
mForwardReferences.AppendElement(aRef);
if (!mForwardReferences.AppendElement(aRef)) {
delete aRef;
return NS_ERROR_OUT_OF_MEMORY;
}
}
else {
NS_ERROR("forward references have already been resolved");
@ -1085,7 +1088,7 @@ nsXULDocument::AddForwardReference(nsForwardReference* aRef)
}
NS_IMETHODIMP
nsresult
nsXULDocument::ResolveForwardReferences()
{
if (mResolutionPhase == nsForwardReference::eDone)
@ -1099,12 +1102,13 @@ nsXULDocument::ResolveForwardReferences()
const nsForwardReference::Phase* pass = nsForwardReference::kPasses;
while ((mResolutionPhase = *pass) != nsForwardReference::eDone) {
PRInt32 previous = 0;
while (mForwardReferences.Count() && mForwardReferences.Count() != previous) {
previous = mForwardReferences.Count();
PRUint32 previous = 0;
while (mForwardReferences.Length() &&
mForwardReferences.Length() != previous) {
previous = mForwardReferences.Length();
for (PRInt32 i = 0; i < mForwardReferences.Count(); ++i) {
nsForwardReference* fwdref = NS_REINTERPRET_CAST(nsForwardReference*, mForwardReferences[i]);
for (PRUint32 i = 0; i < mForwardReferences.Length(); ++i) {
nsForwardReference* fwdref = mForwardReferences[i];
if (fwdref->GetPhase() == *pass) {
nsForwardReference::Result result = fwdref->Resolve();
@ -1113,7 +1117,6 @@ nsXULDocument::ResolveForwardReferences()
case nsForwardReference::eResolve_Succeeded:
case nsForwardReference::eResolve_Error:
mForwardReferences.RemoveElementAt(i);
delete fwdref;
// fixup because we removed from list
--i;
@ -1130,7 +1133,7 @@ nsXULDocument::ResolveForwardReferences()
++pass;
}
DestroyForwardReferences();
mForwardReferences.Clear();
return NS_OK;
}
@ -1367,21 +1370,6 @@ nsXULDocument::Persist(nsIContent* aElement, PRInt32 aNameSpaceID,
}
nsresult
nsXULDocument::DestroyForwardReferences()
{
for (PRInt32 i = mForwardReferences.Count() - 1; i >= 0; --i) {
nsForwardReference* fwdref =
NS_REINTERPRET_CAST(nsForwardReference*, mForwardReferences[i]);
delete fwdref;
}
mForwardReferences.Clear();
return NS_OK;
}
nsresult
nsXULDocument::GetPixelDimensions(nsIPresShell* aShell, PRInt32* aWidth,
PRInt32* aHeight)

Просмотреть файл

@ -136,8 +136,7 @@ public:
NS_IMETHOD RemoveElementForID(const nsAString& aID, nsIContent* aElement);
NS_IMETHOD GetElementsForID(const nsAString& aID,
nsCOMArray<nsIContent>& aElements);
NS_IMETHOD AddForwardReference(nsForwardReference* aRef);
NS_IMETHOD ResolveForwardReferences();
NS_IMETHOD GetScriptGlobalObjectOwner(nsIScriptGlobalObjectOwner** aGlobalOwner);
NS_IMETHOD AddSubtreeToDocument(nsIContent* aElement);
NS_IMETHOD RemoveSubtreeFromDocument(nsIContent* aElement);
@ -255,9 +254,6 @@ protected:
nsresult
Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aAttribute);
nsresult
DestroyForwardReferences();
// 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
@ -297,9 +293,6 @@ protected:
BuilderTable;
BuilderTable* mTemplateBuilderTable;
nsVoidArray mForwardReferences;
nsForwardReference::Phase mResolutionPhase;
PRUint32 mPendingSheets;
/*
@ -434,6 +427,35 @@ protected:
*/
nsresult AddPrototypeSheets();
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();
/**
* Used to resolve broadcaster references
*/