Bug 1019840 - Use cached intrinsic size in nsImageFrame::ComputeSize unless the image loader has a size. r=tn

This commit is contained in:
Seth Fowler 2015-03-18 18:29:32 -07:00
parent 3d794cdd96
commit 7c7c25bd29
3 changed files with 21 additions and 7 deletions

View File

@ -28,16 +28,11 @@ interface nsIFrame;
* become current only when the image is loaded. It is the responsibility of
* observers to check which request they are getting notifications for.
*
* Observers added in mid-load will not get any notifications they
* missed. We should NOT freeze this interface without considering
* this issue. (It could be that the image status on imgIRequest is
* sufficient, when combined with the imageBlockingStatus information.)
*
* Please make sure to update the MozImageLoadingContent WebIDL
* interface to mirror this interface when changing it.
*/
[scriptable, builtinclass, uuid(5794d12b-3195-4526-a814-a2181f6c71fe)]
[scriptable, builtinclass, uuid(770f7d84-c917-42d7-bf8d-d1b70649e733)]
interface nsIImageLoadingContent : imgINotificationObserver
{
/**
@ -100,6 +95,11 @@ interface nsIImageLoadingContent : imgINotificationObserver
*/
imgIRequest getRequest(in long aRequestType);
/**
* @return true if the current request's size is available.
*/
[noscript, notxpcom] boolean currentRequestHasSize();
/**
* Used to notify the image loading content node that a frame has been
* created.

View File

@ -493,6 +493,12 @@ nsImageLoadingContent::GetRequest(int32_t aRequestType,
return result.ErrorCode();
}
NS_IMETHODIMP_(bool)
nsImageLoadingContent::CurrentRequestHasSize()
{
return HaveSize(mCurrentRequest);
}
NS_IMETHODIMP_(void)
nsImageLoadingContent::FrameCreated(nsIFrame* aFrame)
{

View File

@ -743,10 +743,18 @@ nsImageFrame::ComputeSize(nsRenderingContext *aRenderingContext,
NS_ASSERTION(imageLoader, "No content node??");
mozilla::IntrinsicSize intrinsicSize(mIntrinsicSize);
// XXX(seth): We may sometimes find ourselves in the situation where we have
// mImage, but imageLoader's current request does not have a size yet.
// This can happen when we load an image speculatively from cache, it fails
// to validate, and the new image load hasn't fired SIZE_AVAILABLE yet. In
// this situation we should always use mIntrinsicSize, because
// GetNaturalWidth/Height will return 0, so we check CurrentRequestHasSize()
// below. See bug 1019840. We will fix this in bug 1141395.
// Content may override our default dimensions. This is termed as overriding
// the intrinsic size by the spec, but all other consumers of mIntrinsic*
// values are being used to refer to the real/true size of the image data.
if (imageLoader && mImage &&
if (imageLoader && imageLoader->CurrentRequestHasSize() && mImage &&
intrinsicSize.width.GetUnit() == eStyleUnit_Coord &&
intrinsicSize.height.GetUnit() == eStyleUnit_Coord) {
uint32_t width;