Got delayed with changed files, here is the second patch... Fixed bug 22710, load and error events were not firing for images. I also changed the select event firing to use nsEvent instead of nsGUIEvent. r=joki.

This commit is contained in:
heikki%netscape.com 2000-09-07 21:03:26 +00:00
parent 3f12f0e88a
commit 50ed716f64
5 changed files with 52 additions and 4 deletions

View File

@ -185,6 +185,7 @@ nsImageFrame::Init(nsIPresContext* aPresContext,
NS_IF_RELEASE(baseURL);
mInitialLoadCompleted = PR_FALSE;
mCanSendLoadEvent = PR_TRUE;
return rv;
}
@ -237,6 +238,13 @@ nsImageFrame::UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus, void*
// or both failed to load, then notify the PresShell
if (imageFailedToLoad) {
if (presShell) {
// Also send error event
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_IMAGE_ERROR;
presShell->HandleEventWithTarget(&event,this,mContent,&status);
nsAutoString usemap;
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::usemap, usemap);
// We failed to load the image. Notify the pres shell if we aren't an image map
@ -254,6 +262,20 @@ nsImageFrame::UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus, void*
}
}
if (mCanSendLoadEvent &&
!imageFailedToLoad &&
(NS_IMAGE_LOAD_STATUS_IMAGE_READY & aStatus) &&
presShell) {
// Send load event
mCanSendLoadEvent = PR_FALSE;
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_IMAGE_LOAD;
presShell->HandleEventWithTarget(&event,this,mContent,&status);
}
#if 0 // ifdef'ing out the deleting of the lowsrc image
// if the "src" image was change via script to an iage that
// didn't exist, the the author would expect the lowsrc to be displayed.
@ -1030,6 +1052,8 @@ nsImageFrame::AttributeChanged(nsIPresContext* aPresContext,
// Stop the earlier image load
mImageLoader.StopLoadImage(aPresContext);
mCanSendLoadEvent = PR_TRUE;
// Update the URL and start the new image load
mImageLoader.UpdateURLSpec(aPresContext, newSRC);
}

View File

@ -132,6 +132,7 @@ protected:
nsImageMap* mImageMap;
PRPackedBool mSizeFrozen;
PRPackedBool mInitialLoadCompleted;
PRPackedBool mCanSendLoadEvent;
nsMargin mBorderPadding;
};

View File

@ -185,6 +185,7 @@ nsImageFrame::Init(nsIPresContext* aPresContext,
NS_IF_RELEASE(baseURL);
mInitialLoadCompleted = PR_FALSE;
mCanSendLoadEvent = PR_TRUE;
return rv;
}
@ -237,6 +238,13 @@ nsImageFrame::UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus, void*
// or both failed to load, then notify the PresShell
if (imageFailedToLoad) {
if (presShell) {
// Also send error event
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_IMAGE_ERROR;
presShell->HandleEventWithTarget(&event,this,mContent,&status);
nsAutoString usemap;
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::usemap, usemap);
// We failed to load the image. Notify the pres shell if we aren't an image map
@ -254,6 +262,20 @@ nsImageFrame::UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus, void*
}
}
if (mCanSendLoadEvent &&
!imageFailedToLoad &&
(NS_IMAGE_LOAD_STATUS_IMAGE_READY & aStatus) &&
presShell) {
// Send load event
mCanSendLoadEvent = PR_FALSE;
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_IMAGE_LOAD;
presShell->HandleEventWithTarget(&event,this,mContent,&status);
}
#if 0 // ifdef'ing out the deleting of the lowsrc image
// if the "src" image was change via script to an iage that
// didn't exist, the the author would expect the lowsrc to be displayed.
@ -1030,6 +1052,8 @@ nsImageFrame::AttributeChanged(nsIPresContext* aPresContext,
// Stop the earlier image load
mImageLoader.StopLoadImage(aPresContext);
mCanSendLoadEvent = PR_TRUE;
// Update the URL and start the new image load
mImageLoader.UpdateURLSpec(aPresContext, newSRC);
}

View File

@ -132,6 +132,7 @@ protected:
nsImageMap* mImageMap;
PRPackedBool mSizeFrozen;
PRPackedBool mInitialLoadCompleted;
PRPackedBool mCanSendLoadEvent;
nsMargin mBorderPadding;
};

View File

@ -321,11 +321,9 @@ nsTextInputListener::NotifySelectionChanged(nsIDOMDocument* aDoc, nsIDOMSelectio
mFrame->GetFormContent(*getter_AddRefs(content));
if (content) {
nsEventStatus status = nsEventStatus_eIgnore;
nsGUIEvent event;
event.eventStructType = NS_GUI_EVENT;
event.widget = nsnull;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_FORM_SELECTED;
event.flags = NS_EVENT_FLAG_INIT;
nsCOMPtr<nsIDocument> doc;
if (NS_SUCCEEDED(content->GetDocument(*getter_AddRefs(doc)))) {