From a65685f2019e7f1efcd45574bbd840ebf8786da5 Mon Sep 17 00:00:00 2001 From: "Olli.Pettay%helsinki.fi" Date: Thu, 31 Aug 2006 19:33:01 +0000 Subject: [PATCH] Bug 350846, Combine NS_***_LOAD events, r+sr=jst git-svn-id: svn://10.0.0.236/trunk@208936 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocument.cpp | 4 +--- mozilla/content/base/src/nsImageLoadingContent.cpp | 2 +- mozilla/content/base/src/nsXMLHttpRequest.cpp | 2 +- mozilla/content/events/src/nsDOMEvent.cpp | 6 ++---- mozilla/content/events/src/nsEventListenerManager.cpp | 4 +--- .../content/html/content/src/nsHTMLScriptElement.cpp | 4 ++-- mozilla/content/svg/content/src/nsSVGScriptElement.cpp | 2 +- mozilla/content/xml/document/src/nsXMLDocument.cpp | 2 +- mozilla/dom/src/base/nsGlobalWindow.cpp | 10 +++++++--- mozilla/layout/base/nsDocumentViewer.cpp | 2 +- mozilla/layout/xul/base/src/nsImageBoxFrame.cpp | 4 ++-- mozilla/widget/public/nsGUIEvent.h | 4 +--- mozilla/widget/src/xpwidgets/nsBaseWidget.cpp | 3 +-- 13 files changed, 22 insertions(+), 27 deletions(-) diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 75ef7805e40..56bb7b3c6cf 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -4274,9 +4274,7 @@ nsDocument::PreHandleEvent(nsEventChainPreVisitor& aVisitor) aVisitor.mForceContentDispatch = PR_TRUE; // Load events must not propagate to |window| object, see bug 335251. - if (!(aVisitor.mEvent->message == NS_IMAGE_LOAD || - aVisitor.mEvent->message == NS_PAGE_LOAD || - aVisitor.mEvent->message == NS_SCRIPT_LOAD)) { + if (aVisitor.mEvent->message != NS_LOAD) { aVisitor.mParentTarget = GetWindow(); } return NS_OK; diff --git a/mozilla/content/base/src/nsImageLoadingContent.cpp b/mozilla/content/base/src/nsImageLoadingContent.cpp index 47595a45e9b..90ee5b613d1 100644 --- a/mozilla/content/base/src/nsImageLoadingContent.cpp +++ b/mozilla/content/base/src/nsImageLoadingContent.cpp @@ -808,7 +808,7 @@ nsImageLoadingContent::Event::Run() PRUint32 eventMsg; if (mMessage.EqualsLiteral("load")) { - eventMsg = NS_IMAGE_LOAD; + eventMsg = NS_LOAD; } else { eventMsg = NS_IMAGE_ERROR; } diff --git a/mozilla/content/base/src/nsXMLHttpRequest.cpp b/mozilla/content/base/src/nsXMLHttpRequest.cpp index d70ff8b4c17..910b8427413 100644 --- a/mozilla/content/base/src/nsXMLHttpRequest.cpp +++ b/mozilla/content/base/src/nsXMLHttpRequest.cpp @@ -1409,7 +1409,7 @@ nsXMLHttpRequest::RequestCompleted() CopyEventListeners(mOnLoadListener, mLoadEventListeners, loadEventListeners); // We need to create the event before nulling out mDocument - nsEvent evt(PR_TRUE, NS_PAGE_LOAD); + nsEvent evt(PR_TRUE, NS_LOAD); nsCOMPtr domevent; if (loadEventListeners.Count()) { rv = CreateEvent(&evt, EmptyString(), getter_AddRefs(domevent)); diff --git a/mozilla/content/events/src/nsDOMEvent.cpp b/mozilla/content/events/src/nsDOMEvent.cpp index 1dc9d8e65bb..42531e4d7ff 100644 --- a/mozilla/content/events/src/nsDOMEvent.cpp +++ b/mozilla/content/events/src/nsDOMEvent.cpp @@ -421,7 +421,7 @@ nsDOMEvent::SetEventType(const nsAString& aEventTypeArg) else if (atom == nsLayoutAtoms::onselect) mEvent->message = NS_FORM_SELECTED; else if (atom == nsLayoutAtoms::onload) - mEvent->message = NS_PAGE_LOAD; + mEvent->message = NS_LOAD; else if (atom == nsLayoutAtoms::onunload) mEvent->message = NS_PAGE_UNLOAD; else if (atom == nsLayoutAtoms::onabort) @@ -1131,9 +1131,7 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return sEventNames[eDOMEvents_blur]; case NS_XUL_CLOSE: return sEventNames[eDOMEvents_close]; - case NS_PAGE_LOAD: - case NS_IMAGE_LOAD: - case NS_SCRIPT_LOAD: + case NS_LOAD: return sEventNames[eDOMEvents_load]; case NS_BEFORE_PAGE_UNLOAD: return sEventNames[eDOMEvents_beforeunload]; diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index d515723d768..48bed9cf478 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -244,9 +244,7 @@ static const EventDispatchData sFormEvents[] = { }; static const EventDispatchData sLoadEvents[] = { - {NS_PAGE_LOAD, HANDLER(&nsIDOMLoadListener::Load), NS_EVENT_BITS_LOAD_LOAD}, - {NS_IMAGE_LOAD, HANDLER(&nsIDOMLoadListener::Load), NS_EVENT_BITS_LOAD_LOAD}, - {NS_SCRIPT_LOAD, HANDLER(&nsIDOMLoadListener::Load), NS_EVENT_BITS_LOAD_LOAD}, + {NS_LOAD, HANDLER(&nsIDOMLoadListener::Load), NS_EVENT_BITS_LOAD_LOAD}, {NS_PAGE_UNLOAD, HANDLER(&nsIDOMLoadListener::Unload),NS_EVENT_BITS_LOAD_UNLOAD}, {NS_IMAGE_ERROR, HANDLER(&nsIDOMLoadListener::Error), NS_EVENT_BITS_LOAD_ERROR}, {NS_SCRIPT_ERROR,HANDLER(&nsIDOMLoadListener::Error), NS_EVENT_BITS_LOAD_ERROR}, diff --git a/mozilla/content/html/content/src/nsHTMLScriptElement.cpp b/mozilla/content/html/content/src/nsHTMLScriptElement.cpp index d0f850acd17..a8fd7d6f966 100644 --- a/mozilla/content/html/content/src/nsHTMLScriptElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLScriptElement.cpp @@ -614,9 +614,9 @@ nsHTMLScriptElement::ScriptEvaluated(nsresult aResult, nsresult rv = NS_OK; if (!aIsInline) { nsEventStatus status = nsEventStatus_eIgnore; - PRUint32 type = NS_SUCCEEDED(aResult) ? NS_SCRIPT_LOAD : NS_SCRIPT_ERROR; + PRUint32 type = NS_SUCCEEDED(aResult) ? NS_LOAD : NS_SCRIPT_ERROR; nsEvent event(PR_TRUE, type); - if (type == NS_SCRIPT_LOAD) { + if (type == NS_LOAD) { // Load event doesn't bubble. event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; } diff --git a/mozilla/content/svg/content/src/nsSVGScriptElement.cpp b/mozilla/content/svg/content/src/nsSVGScriptElement.cpp index f9c3068353b..3fff24e7e3e 100644 --- a/mozilla/content/svg/content/src/nsSVGScriptElement.cpp +++ b/mozilla/content/svg/content/src/nsSVGScriptElement.cpp @@ -280,7 +280,7 @@ nsSVGScriptElement::ScriptEvaluated(nsresult aResult, nsEventStatus status = nsEventStatus_eIgnore; nsEvent event(PR_TRUE, - NS_SUCCEEDED(aResult) ? NS_SCRIPT_LOAD : NS_SCRIPT_ERROR); + NS_SUCCEEDED(aResult) ? NS_LOAD : NS_SCRIPT_ERROR); event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; nsEventDispatcher::Dispatch(NS_STATIC_CAST(nsIContent*, this), presContext, &event, nsnull, &status); diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index 7cb3e44c021..3ebde2ea918 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -632,7 +632,7 @@ nsXMLDocument::EndLoad() // Generate a document load event for the case when an XML // document was loaded as pure data without any presentation // attached to it. - nsEvent event(PR_TRUE, NS_PAGE_LOAD); + nsEvent event(PR_TRUE, NS_LOAD); nsEventStatus status = nsEventStatus_eIgnore; nsIScriptGlobalObject* sgo = nsnull; diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 77b59133ecb..bf631dac0cb 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -1798,7 +1798,8 @@ nsGlobalWindow::PostHandleEvent(nsEventChainPostVisitor& aVisitor) if (aVisitor.mEvent->message == NS_RESIZE_EVENT) { mIsHandlingResizeEvent = PR_FALSE; - } else if (aVisitor.mEvent->message == NS_PAGE_UNLOAD) { + } else if (aVisitor.mEvent->message == NS_PAGE_UNLOAD && + NS_IS_TRUSTED_EVENT(aVisitor.mEvent)) { // Execute bindingdetached handlers before we tear ourselves // down. if (mDocument) { @@ -1806,7 +1807,10 @@ nsGlobalWindow::PostHandleEvent(nsEventChainPostVisitor& aVisitor) mDoc->BindingManager()->ExecuteDetachedHandlers(); } mIsDocumentLoaded = PR_FALSE; - } else if (aVisitor.mEvent->message == NS_PAGE_LOAD) { + } else if (aVisitor.mEvent->message == NS_LOAD && + NS_IS_TRUSTED_EVENT(aVisitor.mEvent)) { + // This is page load event since load events don't propagate to |window|. + // @see nsDocument::PreHandleEvent. mIsDocumentLoaded = PR_TRUE; nsCOMPtr content(do_QueryInterface(GetFrameElementInternal())); @@ -1825,7 +1829,7 @@ nsGlobalWindow::PostHandleEvent(nsEventChainPostVisitor& aVisitor) // onload event for the frame element. nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_IS_TRUSTED_EVENT(aVisitor.mEvent), NS_PAGE_LOAD); + nsEvent event(NS_IS_TRUSTED_EVENT(aVisitor.mEvent), NS_LOAD); event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; // Most of the time we could get a pres context to pass in here, diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 8c8ac750ee0..faf50f2783d 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -1050,7 +1050,7 @@ DocumentViewerImpl::LoadComplete(nsresult aStatus) PRBool restoring = PR_FALSE; if(NS_SUCCEEDED(aStatus)) { nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(PR_TRUE, NS_PAGE_LOAD); + nsEvent event(PR_TRUE, NS_LOAD); event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; // XXX Dispatching to |window|, but using |document| as the target. event.target = mDocument; diff --git a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp index e4cec10a180..74665e40f15 100644 --- a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp @@ -148,7 +148,7 @@ nsImageBoxFrameEvent::Run() void FireImageDOMEvent(nsIContent* aContent, PRUint32 aMessage) { - NS_ASSERTION(aMessage == NS_IMAGE_LOAD || aMessage == NS_IMAGE_ERROR, + NS_ASSERTION(aMessage == NS_LOAD || aMessage == NS_IMAGE_ERROR, "invalid message"); nsCOMPtr event = new nsImageBoxFrameEvent(aContent, aMessage); @@ -561,7 +561,7 @@ NS_IMETHODIMP nsImageBoxFrame::OnStopDecode(imgIRequest *request, { if (NS_SUCCEEDED(aStatus)) // Fire an onload DOM event. - FireImageDOMEvent(mContent, NS_IMAGE_LOAD); + FireImageDOMEvent(mContent, NS_LOAD); else { // Fire an onerror DOM event. mIntrinsicSize.SizeTo(0, 0); diff --git a/mozilla/widget/public/nsGUIEvent.h b/mozilla/widget/public/nsGUIEvent.h index 8d126cab293..cfc4e1db334 100644 --- a/mozilla/widget/public/nsGUIEvent.h +++ b/mozilla/widget/public/nsGUIEvent.h @@ -231,12 +231,10 @@ class nsIDOMEvent; #define NS_SCROLLBAR_LINE_PREV (NS_SCROLLBAR_MESSAGE_START + 4) #define NS_STREAM_EVENT_START 1100 -#define NS_PAGE_LOAD (NS_STREAM_EVENT_START) +#define NS_LOAD (NS_STREAM_EVENT_START) #define NS_PAGE_UNLOAD (NS_STREAM_EVENT_START + 1) -#define NS_IMAGE_LOAD (NS_STREAM_EVENT_START + 2) #define NS_IMAGE_ABORT (NS_STREAM_EVENT_START + 3) #define NS_IMAGE_ERROR (NS_STREAM_EVENT_START + 4) -#define NS_SCRIPT_LOAD (NS_STREAM_EVENT_START + 5) #define NS_BEFORE_PAGE_UNLOAD (NS_STREAM_EVENT_START + 6) #define NS_PAGE_RESTORE (NS_STREAM_EVENT_START + 7) diff --git a/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp b/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp index 50109154b7c..ed91478a014 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp +++ b/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp @@ -951,7 +951,6 @@ case _value: eventName.AssignWithConversion(_name) ; break _ASSIGN_eventName(NS_GOTFOCUS,"NS_GOTFOCUS"); _ASSIGN_eventName(NS_IMAGE_ABORT,"NS_IMAGE_ABORT"); _ASSIGN_eventName(NS_IMAGE_ERROR,"NS_IMAGE_ERROR"); - _ASSIGN_eventName(NS_IMAGE_LOAD,"NS_IMAGE_LOAD"); _ASSIGN_eventName(NS_KEY_DOWN,"NS_KEY_DOWN"); _ASSIGN_eventName(NS_KEY_PRESS,"NS_KEY_PRESS"); _ASSIGN_eventName(NS_KEY_UP,"NS_KEY_UP"); @@ -973,7 +972,7 @@ case _value: eventName.AssignWithConversion(_name) ; break _ASSIGN_eventName(NS_MOUSE_RIGHT_CLICK,"NS_MOUSE_RIGHT_CLICK"); _ASSIGN_eventName(NS_MOUSE_RIGHT_DOUBLECLICK,"NS_MOUSE_RIGHT_DBLCLICK"); _ASSIGN_eventName(NS_MOVE,"NS_MOVE"); - _ASSIGN_eventName(NS_PAGE_LOAD,"NS_PAGE_LOAD"); + _ASSIGN_eventName(NS_LOAD,"NS_LOAD"); _ASSIGN_eventName(NS_PAGE_UNLOAD,"NS_PAGE_UNLOAD"); _ASSIGN_eventName(NS_PAINT,"NS_PAINT"); _ASSIGN_eventName(NS_XUL_BROADCAST, "NS_XUL_BROADCAST");