From 3e82d91d63e767c4b91d24eb4de1fcd8f9da1075 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Fri, 1 Sep 2000 23:23:35 +0000 Subject: [PATCH] Tweaking the fix to nsbeta3+ bug 28277 so that the src property of the a JavaScript constructed image is correcly set at the time when the onload and onerror events fire. r=nisheeth@netscape.com --- .../html/content/src/nsHTMLImageElement.cpp | 119 +++++++++--------- .../html/content/src/nsHTMLImageElement.cpp | 119 +++++++++--------- 2 files changed, 116 insertions(+), 122 deletions(-) diff --git a/content/html/content/src/nsHTMLImageElement.cpp b/content/html/content/src/nsHTMLImageElement.cpp index b006aefc8a99..fd4e5defcce6 100644 --- a/content/html/content/src/nsHTMLImageElement.cpp +++ b/content/html/content/src/nsHTMLImageElement.cpp @@ -925,73 +925,74 @@ nsresult nsHTMLImageElement::ImageLibCallBack(nsIPresContext* aPresContext, nsresult -nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL, const nsAReadableString& aSrc) +nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL, + const nsAReadableString& aSrc) { nsresult result = NS_OK; - if (nsnull != mOwnerDocument) { - PRInt32 i, count = mOwnerDocument->GetNumberOfShells(); + result = mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::src, aSrc, + PR_TRUE); + + if (NS_SUCCEEDED(result) && mOwnerDocument) { nsIPresShell* shell; - for (i = 0; i < count; i++) { - shell = mOwnerDocument->GetShellAt(i); - if (nsnull != shell) { - nsIPresContext* context; - - result = shell->GetPresContext(&context); - if (NS_SUCCEEDED(result)) { - nsSize size; - nsHTMLValue val; - float p2t; - - context->GetScaledPixelsToTwips(&p2t); - result = mInner.GetHTMLAttribute(nsHTMLAtoms::width, val); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - size.width = NSIntPixelsToTwips(val.GetIntValue(), p2t); - } - else { - size.width = 0; - } - result = mInner.GetHTMLAttribute(nsHTMLAtoms::height, val); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - size.height = NSIntPixelsToTwips(val.GetIntValue(), p2t); - } - else { - size.height = 0; - } + shell = mOwnerDocument->GetShellAt(0); + if (nsnull != shell) { + nsIPresContext* context; - nsAutoString url; - if (nsnull != aBaseURL) { - result = NS_MakeAbsoluteURI(url, aSrc, aBaseURL); - if (NS_FAILED(result)) { - url.Assign(aSrc); - } - } - else { + result = shell->GetPresContext(&context); + if (NS_SUCCEEDED(result)) { + nsSize size; + nsHTMLValue val; + float p2t; + + context->GetScaledPixelsToTwips(&p2t); + result = mInner.GetHTMLAttribute(nsHTMLAtoms::width, val); + if (NS_CONTENT_ATTR_HAS_VALUE == result) { + size.width = NSIntPixelsToTwips(val.GetIntValue(), p2t); + } + else { + size.width = 0; + } + result = mInner.GetHTMLAttribute(nsHTMLAtoms::height, val); + if (NS_CONTENT_ATTR_HAS_VALUE == result) { + size.height = NSIntPixelsToTwips(val.GetIntValue(), p2t); + } + else { + size.height = 0; + } + + nsAutoString url; + if (nsnull != aBaseURL) { + result = NS_MakeAbsoluteURI(url, aSrc, aBaseURL); + if (NS_FAILED(result)) { url.Assign(aSrc); } - - nsSize* specifiedSize = nsnull; - if ((size.width > 0) || (size.height > 0)) { - specifiedSize = &size; - } - - // If we have a loader we're in the middle of loading a image, - // we'll cancel that load and start a new one. - if (mLoader) { - mLoader->RemoveFrame(this); - } - - // Start the image loading. - result = context->StartLoadImage(url, nsnull, specifiedSize, - nsnull, ImageLibCallBack, this, - this, getter_AddRefs(mLoader)); - - NS_RELEASE(context); } - - NS_RELEASE(shell); + else { + url.Assign(aSrc); + } + + nsSize* specifiedSize = nsnull; + if ((size.width > 0) || (size.height > 0)) { + specifiedSize = &size; + } + + // If we have a loader we're in the middle of loading a image, + // we'll cancel that load and start a new one. + if (mLoader) { + mLoader->RemoveFrame(this); + } + + // Start the image loading. + result = context->StartLoadImage(url, nsnull, specifiedSize, + nsnull, ImageLibCallBack, this, + this, getter_AddRefs(mLoader)); + + NS_RELEASE(context); } + + NS_RELEASE(shell); } // Only do this the first time since it's only there for @@ -999,10 +1000,6 @@ nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL, const nsAReadableString& aSrc) NS_RELEASE(mOwnerDocument); } - if (NS_SUCCEEDED(result)) { - result = mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::src, aSrc, PR_TRUE); - } - return result; } diff --git a/layout/html/content/src/nsHTMLImageElement.cpp b/layout/html/content/src/nsHTMLImageElement.cpp index b006aefc8a99..fd4e5defcce6 100644 --- a/layout/html/content/src/nsHTMLImageElement.cpp +++ b/layout/html/content/src/nsHTMLImageElement.cpp @@ -925,73 +925,74 @@ nsresult nsHTMLImageElement::ImageLibCallBack(nsIPresContext* aPresContext, nsresult -nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL, const nsAReadableString& aSrc) +nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL, + const nsAReadableString& aSrc) { nsresult result = NS_OK; - if (nsnull != mOwnerDocument) { - PRInt32 i, count = mOwnerDocument->GetNumberOfShells(); + result = mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::src, aSrc, + PR_TRUE); + + if (NS_SUCCEEDED(result) && mOwnerDocument) { nsIPresShell* shell; - for (i = 0; i < count; i++) { - shell = mOwnerDocument->GetShellAt(i); - if (nsnull != shell) { - nsIPresContext* context; - - result = shell->GetPresContext(&context); - if (NS_SUCCEEDED(result)) { - nsSize size; - nsHTMLValue val; - float p2t; - - context->GetScaledPixelsToTwips(&p2t); - result = mInner.GetHTMLAttribute(nsHTMLAtoms::width, val); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - size.width = NSIntPixelsToTwips(val.GetIntValue(), p2t); - } - else { - size.width = 0; - } - result = mInner.GetHTMLAttribute(nsHTMLAtoms::height, val); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - size.height = NSIntPixelsToTwips(val.GetIntValue(), p2t); - } - else { - size.height = 0; - } + shell = mOwnerDocument->GetShellAt(0); + if (nsnull != shell) { + nsIPresContext* context; - nsAutoString url; - if (nsnull != aBaseURL) { - result = NS_MakeAbsoluteURI(url, aSrc, aBaseURL); - if (NS_FAILED(result)) { - url.Assign(aSrc); - } - } - else { + result = shell->GetPresContext(&context); + if (NS_SUCCEEDED(result)) { + nsSize size; + nsHTMLValue val; + float p2t; + + context->GetScaledPixelsToTwips(&p2t); + result = mInner.GetHTMLAttribute(nsHTMLAtoms::width, val); + if (NS_CONTENT_ATTR_HAS_VALUE == result) { + size.width = NSIntPixelsToTwips(val.GetIntValue(), p2t); + } + else { + size.width = 0; + } + result = mInner.GetHTMLAttribute(nsHTMLAtoms::height, val); + if (NS_CONTENT_ATTR_HAS_VALUE == result) { + size.height = NSIntPixelsToTwips(val.GetIntValue(), p2t); + } + else { + size.height = 0; + } + + nsAutoString url; + if (nsnull != aBaseURL) { + result = NS_MakeAbsoluteURI(url, aSrc, aBaseURL); + if (NS_FAILED(result)) { url.Assign(aSrc); } - - nsSize* specifiedSize = nsnull; - if ((size.width > 0) || (size.height > 0)) { - specifiedSize = &size; - } - - // If we have a loader we're in the middle of loading a image, - // we'll cancel that load and start a new one. - if (mLoader) { - mLoader->RemoveFrame(this); - } - - // Start the image loading. - result = context->StartLoadImage(url, nsnull, specifiedSize, - nsnull, ImageLibCallBack, this, - this, getter_AddRefs(mLoader)); - - NS_RELEASE(context); } - - NS_RELEASE(shell); + else { + url.Assign(aSrc); + } + + nsSize* specifiedSize = nsnull; + if ((size.width > 0) || (size.height > 0)) { + specifiedSize = &size; + } + + // If we have a loader we're in the middle of loading a image, + // we'll cancel that load and start a new one. + if (mLoader) { + mLoader->RemoveFrame(this); + } + + // Start the image loading. + result = context->StartLoadImage(url, nsnull, specifiedSize, + nsnull, ImageLibCallBack, this, + this, getter_AddRefs(mLoader)); + + NS_RELEASE(context); } + + NS_RELEASE(shell); } // Only do this the first time since it's only there for @@ -999,10 +1000,6 @@ nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL, const nsAReadableString& aSrc) NS_RELEASE(mOwnerDocument); } - if (NS_SUCCEEDED(result)) { - result = mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::src, aSrc, PR_TRUE); - } - return result; }