Bug 186835: Hold off notifying that the transformation is finished until all stylesheets are loaded.

r=peterv sr=bz
This commit is contained in:
sicking%bigfoot.com 2003-01-06 14:55:13 +00:00
Родитель e57af92235
Коммит f58ff0e965
9 изменённых файлов: 54 добавлений и 30 удалений

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

@ -43,6 +43,7 @@
class nsIParser;
class nsIDocument;
class nsICSSLoaderObserver;
#define NS_ISTYLESHEETLINKINGELEMENT_IID \
{0xa6cf90e9, 0x15b3, 0x11d2, \
@ -88,8 +89,11 @@ public:
* @param aOldDocument the document that this element was part
* of (nsnull if we're not moving the element
* from one document to another).
* @param aObserver observer to notify once the stylesheet is loaded.
* It might be notified before the function returns.
*/
NS_IMETHOD UpdateStyleSheet(nsIDocument *aOldDocument) = 0;
NS_IMETHOD UpdateStyleSheet(nsIDocument *aOldDocument,
nsICSSLoaderObserver* aObserver) = 0;
/**
* Tells this element wether to update the stylesheet when the

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

@ -163,7 +163,8 @@ const PRBool kBlockByDefault=PR_TRUE;
#endif
NS_IMETHODIMP
nsStyleLinkElement::UpdateStyleSheet(nsIDocument *aOldDocument)
nsStyleLinkElement::UpdateStyleSheet(nsIDocument *aOldDocument,
nsICSSLoaderObserver* aObserver)
{
if (mDontLoadStyle || !mUpdatesEnabled) {
return NS_OK;
@ -314,13 +315,13 @@ nsStyleLinkElement::UpdateStyleSheet(nsIDocument *aOldDocument)
rv = loader->LoadInlineStyle(thisContent, uin, title, media,
kNameSpaceID_Unknown,
((blockParser) ? parser.get() : nsnull),
doneLoading, nsnull);
doneLoading, aObserver);
}
else {
rv = loader->LoadStyleLink(thisContent, uri, title, media,
kNameSpaceID_Unknown,
((blockParser) ? parser.get() : nsnull),
doneLoading, nsnull);
doneLoading, aObserver);
}
if (NS_SUCCEEDED(rv) && blockParser && !doneLoading) {

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

@ -48,7 +48,8 @@ public:
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet);
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet);
NS_IMETHOD InitStyleLinkElement(nsIParser *aParser, PRBool aDontLoadStyle);
NS_IMETHOD UpdateStyleSheet(nsIDocument *aOldDocument = nsnull);
NS_IMETHOD UpdateStyleSheet(nsIDocument *aOldDocument = nsnull,
nsICSSLoaderObserver* aObserver = nsnull);
NS_IMETHOD SetEnableUpdates(PRBool aEnableUpdates);
NS_IMETHOD GetCharset(nsAString& aCharset);

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

@ -4976,7 +4976,7 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode)
if (ssle) {
ssle->SetEnableUpdates(PR_TRUE);
result = ssle->UpdateStyleSheet(nsnull);
result = ssle->UpdateStyleSheet(nsnull, nsnull);
// look for <link rel="next" href="url">
nsAutoString relVal;
@ -5790,7 +5790,7 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
if (ssle) {
ssle->SetEnableUpdates(PR_TRUE);
rv = ssle->UpdateStyleSheet(nsnull);
rv = ssle->UpdateStyleSheet(nsnull, nsnull);
}
return rv;

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

@ -44,6 +44,8 @@
{ 0xa6cf9116, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
class nsICSSStyleSheet;
class nsICSSLoaderObserver : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICSSLOADEROBSERVER_IID)

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

@ -690,7 +690,7 @@ nsXMLContentSink::CloseElement(nsIContent* aContent, PRBool* aAppendContent)
if (ssle) {
ssle->SetEnableUpdates(PR_TRUE);
rv = ssle->UpdateStyleSheet(nsnull);
rv = ssle->UpdateStyleSheet(nsnull, nsnull);
if (rv == NS_ERROR_HTMLPARSER_BLOCK && mParser) {
mParser->BlockParser();
}
@ -1960,7 +1960,7 @@ nsXMLContentSink::HandleProcessingInstruction(const PRUnichar *aTarget,
if (ssle) {
ssle->SetEnableUpdates(PR_TRUE);
result = ssle->UpdateStyleSheet(nsnull);
result = ssle->UpdateStyleSheet(nsnull, nsnull);
if (NS_FAILED(result)) {
if (result == NS_ERROR_HTMLPARSER_BLOCK && mParser) {

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

@ -63,6 +63,7 @@
#include "nsIConsoleService.h"
#include "nsIDOMDocumentFragment.h"
#include "nsINameSpaceManager.h"
#include "nsICSSStyleSheet.h"
extern nsINameSpaceManager* gTxNameSpaceManager;
@ -120,9 +121,10 @@ txMozillaXMLOutput::~txMozillaXMLOutput()
{
}
NS_IMPL_ISUPPORTS2(txMozillaXMLOutput,
NS_IMPL_ISUPPORTS3(txMozillaXMLOutput,
txIOutputXMLEventHandler,
nsIScriptLoaderObserver);
nsIScriptLoaderObserver,
nsICSSLoaderObserver);
void txMozillaXMLOutput::attribute(const String& aName,
const PRInt32 aNsID,
@ -312,15 +314,15 @@ void txMozillaXMLOutput::processingInstruction(const String& aTarget, const Stri
if (ssle) {
ssle->SetEnableUpdates(PR_TRUE);
ssle->UpdateStyleSheet(nsnull);
rv = ssle->UpdateStyleSheet(nsnull, this);
if (rv == NS_ERROR_HTMLPARSER_BLOCK) {
nsCOMPtr<nsIStyleSheet> stylesheet;
ssle->GetStyleSheet(*getter_AddRefs(stylesheet));
mStylesheets.AppendObject(stylesheet);
}
}
}
void txMozillaXMLOutput::removeScriptElement(nsIDOMHTMLScriptElement *aElement)
{
mScriptElements.RemoveObject(aElement);
}
void txMozillaXMLOutput::startDocument()
{
mInTransform = PR_TRUE;
@ -602,7 +604,12 @@ void txMozillaXMLOutput::endHTMLElement(nsIDOMElement* aElement,
do_QueryInterface(aElement);
if (ssle) {
ssle->SetEnableUpdates(PR_TRUE);
ssle->UpdateStyleSheet(nsnull);
ssle->UpdateStyleSheet(nsnull, this);
if (rv == NS_ERROR_HTMLPARSER_BLOCK) {
nsCOMPtr<nsIStyleSheet> stylesheet;
ssle->GetStyleSheet(*getter_AddRefs(stylesheet));
mStylesheets.AppendObject(stylesheet);
}
}
}
}
@ -738,7 +745,7 @@ txMozillaXMLOutput::ScriptAvailable(nsresult aResult,
const nsAString& aScript)
{
if (NS_FAILED(aResult)) {
removeScriptElement(aElement);
mScriptElements.RemoveObject(aElement);
SignalTransformEnd();
}
@ -751,7 +758,16 @@ txMozillaXMLOutput::ScriptEvaluated(nsresult aResult,
PRBool aIsInline,
PRBool aWasPending)
{
removeScriptElement(aElement);
mScriptElements.RemoveObject(aElement);
SignalTransformEnd();
return NS_OK;
}
NS_IMETHODIMP
txMozillaXMLOutput::StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aNotify)
{
// aSheet might not be in our list if the load was done synchronously
mStylesheets.RemoveObject(aSheet);
SignalTransformEnd();
return NS_OK;
}
@ -768,7 +784,7 @@ txMozillaXMLOutput::SignalTransformEnd()
return;
}
if (mScriptElements.Count() > 0) {
if (mScriptElements.Count() > 0 || mStylesheets.Count() > 0) {
return;
}

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

@ -50,9 +50,11 @@
#include "nsWeakPtr.h"
#include "txOutputFormat.h"
#include "nsCOMArray.h"
#include "nsICSSLoaderObserver.h"
class txMozillaXMLOutput : public txIOutputXMLEventHandler,
public nsIScriptLoaderObserver
public nsIScriptLoaderObserver,
public nsICSSLoaderObserver
{
public:
txMozillaXMLOutput(const String& aRootName,
@ -67,6 +69,9 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSISCRIPTLOADEROBSERVER
// nsICSSLoaderObserver
NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aNotify);
/**
* Signals to receive the start of an attribute.
@ -153,14 +158,6 @@ public:
void startElement(const String& aName,
const PRInt32 aNsID);
/**
* Removes a script element from the array of elements that are
* still loading.
*
* @param aReturn the script element to remove
*/
void removeScriptElement(nsIDOMHTMLScriptElement *aElement);
/**
* Gets the Mozilla output document
*
@ -192,6 +189,7 @@ private:
nsCString mRefreshString;
nsCOMArray<nsIDOMHTMLScriptElement> mScriptElements;
nsCOMArray<nsIStyleSheet> mStylesheets;
nsAutoString mText;

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

@ -44,6 +44,8 @@
{ 0xa6cf9116, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
class nsICSSStyleSheet;
class nsICSSLoaderObserver : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICSSLOADEROBSERVER_IID)