mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 06:09:19 +00:00
Bug 1922208 - Don't use Maybe<> to represent no ratio in images. r=dholbert
AspectRatio already has a way of representing a null / invalid ratio, and there are some cases (broken sizes or invalid SVGOuterSVGFrame ratio) where we might get Some(AspectRatio()). It's not a meaningfully different state, and IMO we shouldn't treat it differently. Differential Revision: https://phabricator.services.mozilla.com/D224212
This commit is contained in:
parent
4f1b4c38f6
commit
b85241f0c8
@ -205,12 +205,11 @@ ClippedImage::GetIntrinsicSize(nsSize* aSize) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Maybe<AspectRatio> ClippedImage::GetIntrinsicRatio() {
|
||||
AspectRatio ClippedImage::GetIntrinsicRatio() {
|
||||
if (!ShouldClip()) {
|
||||
return InnerImage()->GetIntrinsicRatio();
|
||||
}
|
||||
|
||||
return Some(AspectRatio::FromSize(mClip.Width(), mClip.Height()));
|
||||
return AspectRatio::FromSize(mClip.Width(), mClip.Height());
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
||||
|
@ -36,7 +36,7 @@ class ClippedImage : public ImageWrapper {
|
||||
NS_IMETHOD GetWidth(int32_t* aWidth) override;
|
||||
NS_IMETHOD GetHeight(int32_t* aHeight) override;
|
||||
NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
|
||||
Maybe<AspectRatio> GetIntrinsicRatio() override;
|
||||
AspectRatio GetIntrinsicRatio() override;
|
||||
NS_IMETHOD_(already_AddRefed<SourceSurface>)
|
||||
GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
|
||||
NS_IMETHOD_(already_AddRefed<SourceSurface>)
|
||||
|
@ -104,9 +104,9 @@ DynamicImage::GetIntrinsicSize(nsSize* aSize) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Maybe<AspectRatio> DynamicImage::GetIntrinsicRatio() {
|
||||
AspectRatio DynamicImage::GetIntrinsicRatio() {
|
||||
auto size = mDrawable->Size();
|
||||
return Some(AspectRatio::FromSize(size.width, size.height));
|
||||
return AspectRatio::FromSize(size.width, size.height);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(Orientation)
|
||||
|
@ -119,7 +119,7 @@ ImageWrapper::GetIntrinsicSize(nsSize* aSize) {
|
||||
return mInnerImage->GetIntrinsicSize(aSize);
|
||||
}
|
||||
|
||||
Maybe<AspectRatio> ImageWrapper::GetIntrinsicRatio() {
|
||||
AspectRatio ImageWrapper::GetIntrinsicRatio() {
|
||||
return mInnerImage->GetIntrinsicRatio();
|
||||
}
|
||||
|
||||
|
@ -66,10 +66,10 @@ OrientedImage::GetIntrinsicSize(nsSize* aSize) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
Maybe<AspectRatio> OrientedImage::GetIntrinsicRatio() {
|
||||
Maybe<AspectRatio> ratio = InnerImage()->GetIntrinsicRatio();
|
||||
AspectRatio OrientedImage::GetIntrinsicRatio() {
|
||||
AspectRatio ratio = InnerImage()->GetIntrinsicRatio();
|
||||
if (ratio && mOrientation.SwapsWidthAndHeight()) {
|
||||
ratio = Some(ratio->Inverted());
|
||||
ratio = ratio.Inverted();
|
||||
}
|
||||
return ratio;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class OrientedImage : public ImageWrapper {
|
||||
NS_IMETHOD GetHeight(int32_t* aHeight) override;
|
||||
nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) override;
|
||||
NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
|
||||
Maybe<AspectRatio> GetIntrinsicRatio() override;
|
||||
AspectRatio GetIntrinsicRatio() override;
|
||||
NS_IMETHOD_(already_AddRefed<SourceSurface>)
|
||||
GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
|
||||
NS_IMETHOD_(already_AddRefed<SourceSurface>)
|
||||
|
@ -256,12 +256,11 @@ RasterImage::GetIntrinsicSize(nsSize* aSize) {
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
Maybe<AspectRatio> RasterImage::GetIntrinsicRatio() {
|
||||
AspectRatio RasterImage::GetIntrinsicRatio() {
|
||||
if (mError) {
|
||||
return Nothing();
|
||||
return {};
|
||||
}
|
||||
|
||||
return Some(AspectRatio::FromSize(mSize.width, mSize.height));
|
||||
return AspectRatio::FromSize(mSize.width, mSize.height);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(Orientation)
|
||||
|
@ -596,10 +596,9 @@ class ImageSurfaceCache {
|
||||
// available. If our guess was too small, don't use factor-of-scaling.
|
||||
MOZ_ASSERT(mIsVectorImage);
|
||||
factorSize = IntSize(100, 100);
|
||||
Maybe<AspectRatio> aspectRatio = image->GetIntrinsicRatio();
|
||||
if (aspectRatio && *aspectRatio) {
|
||||
if (AspectRatio aspectRatio = image->GetIntrinsicRatio()) {
|
||||
factorSize.width =
|
||||
NSToIntRound(aspectRatio->ApplyToFloat(float(factorSize.height)));
|
||||
NSToIntRound(aspectRatio.ApplyToFloat(float(factorSize.height)));
|
||||
if (factorSize.IsEmpty()) {
|
||||
return aSize;
|
||||
}
|
||||
|
@ -580,17 +580,15 @@ VectorImage::GetIntrinsicSize(nsSize* aSize) {
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
Maybe<AspectRatio> VectorImage::GetIntrinsicRatio() {
|
||||
AspectRatio VectorImage::GetIntrinsicRatio() {
|
||||
if (mError || !mIsFullyLoaded) {
|
||||
return Nothing();
|
||||
return {};
|
||||
}
|
||||
|
||||
nsIFrame* rootFrame = mSVGDocumentWrapper->GetRootLayoutFrame();
|
||||
if (!rootFrame) {
|
||||
return Nothing();
|
||||
return {};
|
||||
}
|
||||
|
||||
return Some(rootFrame->GetIntrinsicRatio());
|
||||
return rootFrame->GetIntrinsicRatio();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(Orientation)
|
||||
|
@ -21,9 +21,12 @@ webidl Document;
|
||||
#include "limits.h"
|
||||
|
||||
class gfxContext;
|
||||
class nsIFrame;
|
||||
|
||||
namespace mozilla {
|
||||
struct AspectRatio;
|
||||
class TimeStamp;
|
||||
class SVGImageContext;
|
||||
struct MediaFeatureChange;
|
||||
|
||||
namespace gfx {
|
||||
class SourceSurface;
|
||||
@ -33,31 +36,19 @@ class WindowRenderer;
|
||||
namespace layers {
|
||||
class ImageContainer;
|
||||
}
|
||||
}
|
||||
|
||||
class nsIFrame;
|
||||
|
||||
namespace mozilla {
|
||||
class TimeStamp;
|
||||
class SVGImageContext;
|
||||
struct MediaFeatureChange;
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
namespace image {
|
||||
|
||||
class ImageRegion;
|
||||
class ImageIntRegion;
|
||||
class WebRenderImageProvider;
|
||||
struct Orientation;
|
||||
struct Resolution;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
native MaybeAspectRatio(mozilla::Maybe<mozilla::AspectRatio>);
|
||||
native AspectRatio(mozilla::AspectRatio);
|
||||
native ImgDrawResult(mozilla::image::ImgDrawResult);
|
||||
[ptr] native gfxContext(gfxContext);
|
||||
[ref] native gfxMatrix(gfxMatrix);
|
||||
@ -115,10 +106,11 @@ interface imgIContainer : nsISupports
|
||||
[noscript] readonly attribute nsSize intrinsicSize;
|
||||
|
||||
/**
|
||||
* The (dimensionless) intrinsic ratio of this image. In the case of any
|
||||
* error, Nothing() will be returned.
|
||||
* The (dimensionless) intrinsic ratio of this image. Might return a
|
||||
* degenerate ratio (one that returns 'false' when coerced to a bool)
|
||||
* if the image is in an error state, or there's no ratio.
|
||||
*/
|
||||
[notxpcom, nostdcall] readonly attribute MaybeAspectRatio intrinsicRatio;
|
||||
[notxpcom, nostdcall] readonly attribute AspectRatio intrinsicRatio;
|
||||
|
||||
/**
|
||||
* The x coordinate of the image's hotspot, or 0 if there is no hotspot.
|
||||
|
@ -6215,8 +6215,7 @@ void nsLayoutUtils::ComputeSizeForDrawing(
|
||||
/* outparam */ bool& aGotHeight) {
|
||||
aGotWidth = NS_SUCCEEDED(aImage->GetWidth(&aImageSize.width));
|
||||
aGotHeight = NS_SUCCEEDED(aImage->GetHeight(&aImageSize.height));
|
||||
Maybe<AspectRatio> intrinsicRatio = aImage->GetIntrinsicRatio();
|
||||
aIntrinsicRatio = intrinsicRatio.valueOr(AspectRatio());
|
||||
aIntrinsicRatio = aImage->GetIntrinsicRatio();
|
||||
|
||||
if (aGotWidth) {
|
||||
aResolution.ApplyXTo(aImageSize.width);
|
||||
@ -6224,13 +6223,6 @@ void nsLayoutUtils::ComputeSizeForDrawing(
|
||||
if (aGotHeight) {
|
||||
aResolution.ApplyYTo(aImageSize.height);
|
||||
}
|
||||
|
||||
if (!(aGotWidth && aGotHeight) && intrinsicRatio.isNothing()) {
|
||||
// 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 = CSSIntSize(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
@ -924,8 +924,8 @@ AspectRatio nsImageFrame::ComputeIntrinsicRatioForImage(
|
||||
}
|
||||
|
||||
if (aImage) {
|
||||
if (Maybe<AspectRatio> fromImage = aImage->GetIntrinsicRatio()) {
|
||||
return *fromImage;
|
||||
if (AspectRatio fromImage = aImage->GetIntrinsicRatio()) {
|
||||
return fromImage;
|
||||
}
|
||||
}
|
||||
if (ShouldUseMappedAspectRatio()) {
|
||||
|
@ -249,7 +249,6 @@ bool SVGImageFrame::GetIntrinsicImageDimensions(
|
||||
}
|
||||
|
||||
ImageResolution resolution = mImageContainer->GetResolution();
|
||||
|
||||
int32_t width, height;
|
||||
if (NS_FAILED(mImageContainer->GetWidth(&width))) {
|
||||
aSize.width = -1;
|
||||
@ -265,9 +264,7 @@ bool SVGImageFrame::GetIntrinsicImageDimensions(
|
||||
resolution.ApplyYTo(aSize.height);
|
||||
}
|
||||
|
||||
Maybe<AspectRatio> asp = mImageContainer->GetIntrinsicRatio();
|
||||
aAspectRatio = asp.valueOr(AspectRatio{});
|
||||
|
||||
aAspectRatio = mImageContainer->GetIntrinsicRatio();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -515,16 +515,16 @@ nsresult nsCocoaUtils::CreateNSImageFromImageContainer(
|
||||
{
|
||||
const bool gotWidth = NS_SUCCEEDED(aImage->GetWidth(&width));
|
||||
const bool gotHeight = NS_SUCCEEDED(aImage->GetHeight(&height));
|
||||
if (auto ratio = aImage->GetIntrinsicRatio(); ratio && *ratio) {
|
||||
if (auto ratio = aImage->GetIntrinsicRatio()) {
|
||||
if (gotWidth != gotHeight) {
|
||||
if (gotWidth) {
|
||||
height = ratio->Inverted().ApplyTo(width);
|
||||
height = ratio.Inverted().ApplyTo(width);
|
||||
} else {
|
||||
width = ratio->ApplyTo(height);
|
||||
width = ratio.ApplyTo(height);
|
||||
}
|
||||
} else if (!gotWidth) {
|
||||
height = std::ceil(aPreferredSize.height);
|
||||
width = ratio->ApplyTo(height);
|
||||
width = ratio.ApplyTo(height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user