зеркало из https://github.com/mozilla/pjs.git
Fix for bug 23074. Implemented image.complete. r=pollmann
This commit is contained in:
Родитель
0627177b1b
Коммит
bc3cf76724
|
@ -118,6 +118,7 @@ public:
|
|||
// XXX Casing is different for backward compatibility
|
||||
NS_IMETHOD GetLowsrc(nsString& aLowsrc);
|
||||
NS_IMETHOD SetLowsrc(const nsString& aLowsrc);
|
||||
NS_IMETHOD GetComplete(PRBool* aComplete);
|
||||
|
||||
// nsIScriptObjectOwner
|
||||
NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC(mInner)
|
||||
|
@ -151,7 +152,7 @@ public:
|
|||
nsresult SetSrcInner(nsIURI* aBaseURL, const nsString& aSrc);
|
||||
nsresult GetCallerSourceURL(JSContext* cx, nsIURI** sourceURL);
|
||||
|
||||
nsresult GetIntrinsicImageSize(nsSize& aSize);
|
||||
nsresult GetImageFrame(nsImageFrame** aImageFrame);
|
||||
|
||||
protected:
|
||||
nsGenericHTMLLeafElement mInner;
|
||||
|
@ -247,7 +248,7 @@ NS_IMPL_STRING_ATTR(nsHTMLImageElement, Vspace, vspace)
|
|||
NS_IMPL_STRING_ATTR(nsHTMLImageElement, Lowsrc, lowsrc)
|
||||
|
||||
nsresult
|
||||
nsHTMLImageElement::GetIntrinsicImageSize(nsSize& aSize)
|
||||
nsHTMLImageElement::GetImageFrame(nsImageFrame** aImageFrame)
|
||||
{
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
|
@ -280,24 +281,41 @@ nsHTMLImageElement::GetIntrinsicImageSize(nsSize& aSize)
|
|||
// preferred the ugliness of a static cast to the weight of
|
||||
// a new interface.
|
||||
nsImageFrame* imageFrame = NS_STATIC_CAST(nsImageFrame*, frame);
|
||||
*aImageFrame = imageFrame;
|
||||
|
||||
return imageFrame->GetIntrinsicImageSize(aSize);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::GetComplete(PRBool* aComplete)
|
||||
{
|
||||
nsresult result;
|
||||
nsImageFrame* imageFrame;
|
||||
|
||||
result = GetImageFrame(&imageFrame);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = imageFrame->IsImageComplete(aComplete);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::GetHeight(nsString& aValue)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
if (NS_CONTENT_ATTR_NOT_THERE == mInner.GetAttribute(kNameSpaceID_None, nsHTMLAtoms::height, aValue)) {
|
||||
nsSize size;
|
||||
nsImageFrame* imageFrame;
|
||||
|
||||
result = GetIntrinsicImageSize(size);
|
||||
result = GetImageFrame(&imageFrame);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsSize size;
|
||||
imageFrame->GetIntrinsicImageSize(size);
|
||||
aValue.Append(size.height);
|
||||
}
|
||||
}
|
||||
|
@ -317,10 +335,12 @@ nsHTMLImageElement::GetWidth(nsString& aValue)
|
|||
nsresult result;
|
||||
|
||||
if (NS_CONTENT_ATTR_NOT_THERE == mInner.GetAttribute(kNameSpaceID_None, nsHTMLAtoms::width, aValue)) {
|
||||
nsSize size;
|
||||
nsImageFrame* imageFrame;
|
||||
|
||||
result = GetIntrinsicImageSize(size);
|
||||
result = GetImageFrame(&imageFrame);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsSize size;
|
||||
imageFrame->GetIntrinsicImageSize(size);
|
||||
aValue.Append(size.width);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,18 +39,22 @@ public:
|
|||
|
||||
NS_IMETHOD GetLowsrc(nsString& aLowsrc)=0;
|
||||
NS_IMETHOD SetLowsrc(const nsString& aLowsrc)=0;
|
||||
|
||||
NS_IMETHOD GetComplete(PRBool* aComplete)=0;
|
||||
};
|
||||
|
||||
|
||||
#define NS_DECL_IDOMIMAGE \
|
||||
NS_IMETHOD GetLowsrc(nsString& aLowsrc); \
|
||||
NS_IMETHOD SetLowsrc(const nsString& aLowsrc); \
|
||||
NS_IMETHOD GetComplete(PRBool* aComplete); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMIMAGE(_to) \
|
||||
NS_IMETHOD GetLowsrc(nsString& aLowsrc) { return _to GetLowsrc(aLowsrc); } \
|
||||
NS_IMETHOD SetLowsrc(const nsString& aLowsrc) { return _to SetLowsrc(aLowsrc); } \
|
||||
NS_IMETHOD GetComplete(PRBool* aComplete) { return _to GetComplete(aComplete); } \
|
||||
|
||||
|
||||
#endif // nsIDOMImage_h__
|
||||
|
|
|
@ -28,4 +28,5 @@
|
|||
|
||||
void Image();
|
||||
attribute DOMString lowsrc;
|
||||
readonly attribute boolean complete;
|
||||
};
|
||||
|
|
|
@ -599,6 +599,7 @@ enum nsDOMProp {
|
|||
NS_DOM_PROP_HTMLTITLEELEMENT_TEXT,
|
||||
NS_DOM_PROP_HTMLULISTELEMENT_COMPACT,
|
||||
NS_DOM_PROP_HTMLULISTELEMENT_TYPE,
|
||||
NS_DOM_PROP_IMAGE_COMPLETE,
|
||||
NS_DOM_PROP_IMAGE_LOWSRC,
|
||||
NS_DOM_PROP_KEYEVENT_ALTKEY,
|
||||
NS_DOM_PROP_KEYEVENT_CHARCODE,
|
||||
|
|
|
@ -598,6 +598,7 @@
|
|||
"htmltitleelement.text", \
|
||||
"htmlulistelement.compact", \
|
||||
"htmlulistelement.type", \
|
||||
"image.complete", \
|
||||
"image.lowsrc", \
|
||||
"keyevent.altkey", \
|
||||
"keyevent.charcode", \
|
||||
|
|
|
@ -64,7 +64,8 @@ enum HTMLImageElement_slots {
|
|||
HTMLIMAGEELEMENT_USEMAP = -10,
|
||||
HTMLIMAGEELEMENT_VSPACE = -11,
|
||||
HTMLIMAGEELEMENT_WIDTH = -12,
|
||||
IMAGE_LOWSRC = -13
|
||||
IMAGE_LOWSRC = -13,
|
||||
IMAGE_COMPLETE = -14
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
|
@ -331,6 +332,32 @@ GetHTMLImageElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case IMAGE_COMPLETE:
|
||||
{
|
||||
PRBool ok = PR_FALSE;
|
||||
secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_IMAGE_COMPLETE, PR_FALSE, &ok);
|
||||
if (!ok) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_SECURITY_ERR);
|
||||
}
|
||||
PRBool prop;
|
||||
nsIDOMImage* b;
|
||||
if (NS_OK == a->QueryInterface(kIImageIID, (void **)&b)) {
|
||||
nsresult result = NS_OK;
|
||||
result = b->GetComplete(&prop);
|
||||
if(NS_SUCCEEDED(result)) {
|
||||
*vp = BOOLEAN_TO_JSVAL(prop);
|
||||
NS_RELEASE(b);
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(b);
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);
|
||||
}
|
||||
|
@ -634,6 +661,7 @@ static JSPropertySpec HTMLImageElementProperties[] =
|
|||
{"vspace", HTMLIMAGEELEMENT_VSPACE, JSPROP_ENUMERATE},
|
||||
{"width", HTMLIMAGEELEMENT_WIDTH, JSPROP_ENUMERATE},
|
||||
{"lowsrc", IMAGE_LOWSRC, JSPROP_ENUMERATE},
|
||||
{"complete", IMAGE_COMPLETE, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
@ -902,6 +902,14 @@ nsImageFrame::GetIntrinsicImageSize(nsSize& aSize)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImageFrame::IsImageComplete(PRBool* aComplete)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aComplete);
|
||||
*aComplete = (PRBool)(mImageLoader.GetLoadStatus() & NS_IMAGE_LOAD_STATUS_IMAGE_READY);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
NS_IMETHODIMP
|
||||
nsImageFrame::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
||||
|
|
|
@ -66,6 +66,7 @@ public:
|
|||
PRInt32 aHint);
|
||||
NS_IMETHOD GetFrameType(nsIAtom** aResult) const;
|
||||
NS_IMETHOD GetIntrinsicImageSize(nsSize& aSize);
|
||||
NS_IMETHOD IsImageComplete(PRBool* aComplete);
|
||||
|
||||
#ifdef DEBUG
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
||||
|
|
|
@ -902,6 +902,14 @@ nsImageFrame::GetIntrinsicImageSize(nsSize& aSize)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImageFrame::IsImageComplete(PRBool* aComplete)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aComplete);
|
||||
*aComplete = (PRBool)(mImageLoader.GetLoadStatus() & NS_IMAGE_LOAD_STATUS_IMAGE_READY);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
NS_IMETHODIMP
|
||||
nsImageFrame::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
||||
|
|
|
@ -66,6 +66,7 @@ public:
|
|||
PRInt32 aHint);
|
||||
NS_IMETHOD GetFrameType(nsIAtom** aResult) const;
|
||||
NS_IMETHOD GetIntrinsicImageSize(nsSize& aSize);
|
||||
NS_IMETHOD IsImageComplete(PRBool* aComplete);
|
||||
|
||||
#ifdef DEBUG
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
||||
|
|
|
@ -118,6 +118,7 @@ public:
|
|||
// XXX Casing is different for backward compatibility
|
||||
NS_IMETHOD GetLowsrc(nsString& aLowsrc);
|
||||
NS_IMETHOD SetLowsrc(const nsString& aLowsrc);
|
||||
NS_IMETHOD GetComplete(PRBool* aComplete);
|
||||
|
||||
// nsIScriptObjectOwner
|
||||
NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC(mInner)
|
||||
|
@ -151,7 +152,7 @@ public:
|
|||
nsresult SetSrcInner(nsIURI* aBaseURL, const nsString& aSrc);
|
||||
nsresult GetCallerSourceURL(JSContext* cx, nsIURI** sourceURL);
|
||||
|
||||
nsresult GetIntrinsicImageSize(nsSize& aSize);
|
||||
nsresult GetImageFrame(nsImageFrame** aImageFrame);
|
||||
|
||||
protected:
|
||||
nsGenericHTMLLeafElement mInner;
|
||||
|
@ -247,7 +248,7 @@ NS_IMPL_STRING_ATTR(nsHTMLImageElement, Vspace, vspace)
|
|||
NS_IMPL_STRING_ATTR(nsHTMLImageElement, Lowsrc, lowsrc)
|
||||
|
||||
nsresult
|
||||
nsHTMLImageElement::GetIntrinsicImageSize(nsSize& aSize)
|
||||
nsHTMLImageElement::GetImageFrame(nsImageFrame** aImageFrame)
|
||||
{
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIPresContext> context;
|
||||
|
@ -280,24 +281,41 @@ nsHTMLImageElement::GetIntrinsicImageSize(nsSize& aSize)
|
|||
// preferred the ugliness of a static cast to the weight of
|
||||
// a new interface.
|
||||
nsImageFrame* imageFrame = NS_STATIC_CAST(nsImageFrame*, frame);
|
||||
*aImageFrame = imageFrame;
|
||||
|
||||
return imageFrame->GetIntrinsicImageSize(aSize);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::GetComplete(PRBool* aComplete)
|
||||
{
|
||||
nsresult result;
|
||||
nsImageFrame* imageFrame;
|
||||
|
||||
result = GetImageFrame(&imageFrame);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = imageFrame->IsImageComplete(aComplete);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::GetHeight(nsString& aValue)
|
||||
{
|
||||
nsresult result;
|
||||
|
||||
if (NS_CONTENT_ATTR_NOT_THERE == mInner.GetAttribute(kNameSpaceID_None, nsHTMLAtoms::height, aValue)) {
|
||||
nsSize size;
|
||||
nsImageFrame* imageFrame;
|
||||
|
||||
result = GetIntrinsicImageSize(size);
|
||||
result = GetImageFrame(&imageFrame);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsSize size;
|
||||
imageFrame->GetIntrinsicImageSize(size);
|
||||
aValue.Append(size.height);
|
||||
}
|
||||
}
|
||||
|
@ -317,10 +335,12 @@ nsHTMLImageElement::GetWidth(nsString& aValue)
|
|||
nsresult result;
|
||||
|
||||
if (NS_CONTENT_ATTR_NOT_THERE == mInner.GetAttribute(kNameSpaceID_None, nsHTMLAtoms::width, aValue)) {
|
||||
nsSize size;
|
||||
nsImageFrame* imageFrame;
|
||||
|
||||
result = GetIntrinsicImageSize(size);
|
||||
result = GetImageFrame(&imageFrame);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsSize size;
|
||||
imageFrame->GetIntrinsicImageSize(size);
|
||||
aValue.Append(size.width);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче