Bug 1602047 - For <img src=""> (no current request), do not use mapped aspect ratio. r=tnikkel

This works in chrome because they don't event create an image box for this case,
which is totally against the spec.

The spec doesn't consider an image with a null image request, but our behavior
changes in some other places as well because of it...

Depends on D56367

Differential Revision: https://phabricator.services.mozilla.com/D56368
This commit is contained in:
Emilio Cobos Álvarez
2019-12-10 05:28:15 +00:00
parent 77a365c22a
commit 0ba9abf4dd
2 changed files with 16 additions and 7 deletions

View File

@@ -440,6 +440,7 @@ static void ScaleIntrinsicSizeForDensity(nsIContent& aContent,
}
static IntrinsicSize ComputeIntrinsicSize(imgIContainer* aImage,
bool aHasRequest,
nsImageFrame::Kind aKind,
const nsImageFrame& aFrame) {
const ComputedStyle& style = *aFrame.Style();
@@ -464,7 +465,7 @@ static IntrinsicSize ComputeIntrinsicSize(imgIContainer* aImage,
return IntrinsicSize(edgeLengthToUse, edgeLengthToUse);
}
if (style.StylePosition()->mAspectRatio != 0.0f) {
if (aHasRequest && style.StylePosition()->mAspectRatio != 0.0f) {
return IntrinsicSize();
}
@@ -473,11 +474,13 @@ static IntrinsicSize ComputeIntrinsicSize(imgIContainer* aImage,
bool nsImageFrame::UpdateIntrinsicSize() {
IntrinsicSize oldIntrinsicSize = mIntrinsicSize;
mIntrinsicSize = ComputeIntrinsicSize(mImage, mKind, *this);
nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest();
mIntrinsicSize = ComputeIntrinsicSize(mImage, !!currentRequest, mKind, *this);
return mIntrinsicSize != oldIntrinsicSize;
}
static AspectRatio ComputeAspectRatio(imgIContainer* aImage,
bool aHasRequest,
const nsImageFrame& aFrame) {
const ComputedStyle& style = *aFrame.Style();
if (style.StyleDisplay()->IsContainSize()) {
@@ -488,7 +491,7 @@ static AspectRatio ComputeAspectRatio(imgIContainer* aImage,
return *fromImage;
}
}
if (style.StylePosition()->mAspectRatio != 0.0f) {
if (aHasRequest && style.StylePosition()->mAspectRatio != 0.0f) {
return AspectRatio(style.StylePosition()->mAspectRatio);
}
if (aFrame.ShouldShowBrokenImageIcon()) {
@@ -499,7 +502,8 @@ static AspectRatio ComputeAspectRatio(imgIContainer* aImage,
bool nsImageFrame::UpdateIntrinsicRatio() {
AspectRatio oldIntrinsicRatio = mIntrinsicRatio;
mIntrinsicRatio = ComputeAspectRatio(mImage, *this);
nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest();
mIntrinsicRatio = ComputeAspectRatio(mImage, !!currentRequest, *this);
return mIntrinsicRatio != oldIntrinsicRatio;
}
@@ -1720,9 +1724,12 @@ static bool OldImageHasDifferentRatio(const nsImageFrame& aFrame,
}
auto currentRatio = aFrame.GetComputedIntrinsicRatio();
MOZ_ASSERT(currentRatio == ComputeAspectRatio(&aImage, aFrame),
// If we have an image, we need to have a current request.
// Same if we had an image.
const bool hasRequest = true;
MOZ_ASSERT(currentRatio == ComputeAspectRatio(&aImage, hasRequest, aFrame),
"aspect-ratio got out of sync during paint? How?");
auto oldRatio = ComputeAspectRatio(aPrevImage, aFrame);
auto oldRatio = ComputeAspectRatio(aPrevImage, hasRequest, aFrame);
return oldRatio != currentRatio;
}