Bug 825720 - Don't use GetRootLayoutFrame to calculate the size of SVG images. r=joe

This commit is contained in:
Seth Fowler 2013-01-10 19:38:34 -08:00
Родитель 58a2c20c33
Коммит e9042e47c6
5 изменённых файлов: 95 добавлений и 38 удалений

Просмотреть файл

@ -41,6 +41,7 @@ native gfxImageFormat(gfxASurface::gfxImageFormat);
native gfxGraphicsFilter(gfxPattern::GraphicsFilter);
[ref] native nsIntRect(nsIntRect);
[ref] native nsIntSize(nsIntSize);
native nsSize(nsSize);
[ptr] native nsIFrame(nsIFrame);
[ptr] native ImageContainer(mozilla::layers::ImageContainer);
[ptr] native LayerManager(mozilla::layers::LayerManager);
@ -55,7 +56,7 @@ native gfxGraphicsFilter(gfxPattern::GraphicsFilter);
*
* Internally, imgIContainer also manages animation of images.
*/
[scriptable, builtinclass, uuid(01e12ac9-7d9f-40d9-9ec1-70b64c53ce7a)]
[scriptable, builtinclass, uuid(a9a6835f-ca7e-4c80-8892-962c959fcd27)]
interface imgIContainer : nsISupports
{
/**
@ -70,6 +71,19 @@ interface imgIContainer : nsISupports
*/
readonly attribute int32_t height;
/**
* The intrinsic size of this image in appunits. If the image has no intrinsic
* size in a dimension, -1 will be returned for that dimension. In the case of
* any error, an exception will be thrown.
*/
[noscript] readonly attribute nsSize intrinsicSize;
/**
* The (dimensionless) intrinsic ratio of this image. In the case of any error,
* an exception will be thrown.
*/
[noscript] readonly attribute nsSize intrinsicRatio;
/**
* Enumerated values for the 'type' attribute (below).
*/

Просмотреть файл

@ -17,6 +17,7 @@
#include "prenv.h"
#include "ImageContainer.h"
#include "Layers.h"
#include "nsPresContext.h"
#include "nsPNGDecoder.h"
#include "nsGIFDecoder2.h"
@ -779,6 +780,31 @@ RasterImage::GetHeight(int32_t *aHeight)
*aHeight = mSize.height;
return NS_OK;
}
//******************************************************************************
/* [noscript] readonly attribute nsSize intrinsicSize; */
NS_IMETHODIMP
RasterImage::GetIntrinsicSize(nsSize* aSize)
{
if (mError)
return NS_ERROR_FAILURE;
*aSize = nsSize(nsPresContext::CSSPixelsToAppUnits(mSize.width),
nsPresContext::CSSPixelsToAppUnits(mSize.height));
return NS_OK;
}
//******************************************************************************
/* [noscript] readonly attribute nsSize intrinsicRatio; */
NS_IMETHODIMP
RasterImage::GetIntrinsicRatio(nsSize* aRatio)
{
if (mError)
return NS_ERROR_FAILURE;
*aRatio = nsSize(mSize.width, mSize.height);
return NS_OK;
}
//******************************************************************************
/* unsigned short GetType(); */

Просмотреть файл

@ -350,6 +350,38 @@ VectorImage::GetHeight(int32_t* aHeight)
return NS_OK;
}
//******************************************************************************
/* [noscript] readonly attribute nsSize intrinsicSize; */
NS_IMETHODIMP
VectorImage::GetIntrinsicSize(nsSize* aSize)
{
nsIFrame* rootFrame = GetRootLayoutFrame();
if (!rootFrame)
return NS_ERROR_FAILURE;
*aSize = nsSize(-1, -1);
nsIFrame::IntrinsicSize rfSize = rootFrame->GetIntrinsicSize();
if (rfSize.width.GetUnit() == eStyleUnit_Coord)
aSize->width = rfSize.width.GetCoordValue();
if (rfSize.height.GetUnit() == eStyleUnit_Coord)
aSize->height = rfSize.height.GetCoordValue();
return NS_OK;
}
//******************************************************************************
/* [noscript] readonly attribute nsSize intrinsicRatio; */
NS_IMETHODIMP
VectorImage::GetIntrinsicRatio(nsSize* aRatio)
{
nsIFrame* rootFrame = GetRootLayoutFrame();
if (!rootFrame)
return NS_ERROR_FAILURE;
*aRatio = rootFrame->GetIntrinsicRatio();
return NS_OK;
}
//******************************************************************************
/* readonly attribute unsigned short type; */
NS_IMETHODIMP

Просмотреть файл

@ -4067,18 +4067,11 @@ nsLayoutUtils::ComputeSizeForDrawing(imgIContainer *aImage,
{
aGotWidth = NS_SUCCEEDED(aImage->GetWidth(&aImageSize.width));
aGotHeight = NS_SUCCEEDED(aImage->GetHeight(&aImageSize.height));
bool gotRatio = NS_SUCCEEDED(aImage->GetIntrinsicRatio(&aIntrinsicRatio));
if (aGotWidth && aGotHeight) {
aIntrinsicRatio = nsSize(aImageSize.width, aImageSize.height);
return;
}
// If we failed to get width or height, we either have a vector image and
// should return its intrinsic ratio, or we hit an error (say, because the
// image failed to load or couldn't be decoded) and should return zero size.
if (nsIFrame* rootFrame = aImage->GetRootLayoutFrame()) {
aIntrinsicRatio = rootFrame->GetIntrinsicRatio();
} else {
if (!(aGotWidth && aGotHeight) && !gotRatio) {
// We hit an error (say, because the image failed to load or couldn't be
// decoded) and should return zero size.
aGotWidth = aGotHeight = true;
aImageSize = nsIntSize(0, 0);
aIntrinsicRatio = nsSize(0, 0);

Просмотреть файл

@ -286,22 +286,23 @@ nsImageFrame::UpdateIntrinsicSize(imgIContainer* aImage)
return false;
nsIFrame::IntrinsicSize oldIntrinsicSize = mIntrinsicSize;
mIntrinsicSize = nsIFrame::IntrinsicSize();
nsIFrame* rootFrame = aImage->GetRootLayoutFrame();
if (rootFrame) {
// Set intrinsic size to match that of aImage's rootFrame.
mIntrinsicSize = rootFrame->GetIntrinsicSize();
// Set intrinsic size to match aImage's reported intrinsic width & height.
nsSize intrinsicSize;
if (NS_SUCCEEDED(aImage->GetIntrinsicSize(&intrinsicSize))) {
// If the image has no intrinsic width, intrinsicSize.width will be -1, and
// we can leave mIntrinsicSize.width at its default value of eStyleUnit_None.
// Otherwise we use intrinsicSize.width. Height works the same way.
if (intrinsicSize.width != -1)
mIntrinsicSize.width.SetCoordValue(intrinsicSize.width);
if (intrinsicSize.height != -1)
mIntrinsicSize.height.SetCoordValue(intrinsicSize.height);
} else {
// Set intrinsic size to match aImage's reported width & height.
nsIntSize imageSizeInPx;
if (NS_FAILED(aImage->GetWidth(&imageSizeInPx.width)) ||
NS_FAILED(aImage->GetHeight(&imageSizeInPx.height))) {
imageSizeInPx.SizeTo(0, 0);
}
mIntrinsicSize.width.SetCoordValue(
nsPresContext::CSSPixelsToAppUnits(imageSizeInPx.width));
mIntrinsicSize.height.SetCoordValue(
nsPresContext::CSSPixelsToAppUnits(imageSizeInPx.height));
// Failure means that the image hasn't loaded enough to report a result. We
// treat this case as if the image's intrinsic size was 0x0.
mIntrinsicSize.width.SetCoordValue(0);
mIntrinsicSize.height.SetCoordValue(0);
}
return mIntrinsicSize != oldIntrinsicSize;
@ -317,18 +318,9 @@ nsImageFrame::UpdateIntrinsicRatio(imgIContainer* aImage)
nsSize oldIntrinsicRatio = mIntrinsicRatio;
nsIFrame* rootFrame = aImage->GetRootLayoutFrame();
if (rootFrame) {
// Set intrinsic ratio to match that of aImage's rootFrame.
mIntrinsicRatio = rootFrame->GetIntrinsicRatio();
} else {
NS_ABORT_IF_FALSE(mIntrinsicSize.width.GetUnit() == eStyleUnit_Coord &&
mIntrinsicSize.height.GetUnit() == eStyleUnit_Coord,
"since aImage doesn't have a rootFrame, our intrinsic "
"dimensions must have coord units (not percent units)");
mIntrinsicRatio.width = mIntrinsicSize.width.GetCoordValue();
mIntrinsicRatio.height = mIntrinsicSize.height.GetCoordValue();
}
// Set intrinsic ratio to match aImage's reported intrinsic ratio.
if (NS_FAILED(aImage->GetIntrinsicRatio(&mIntrinsicRatio)))
mIntrinsicRatio.SizeTo(0, 0);
return mIntrinsicRatio != oldIntrinsicRatio;
}