Bug 1680387 - Apply intrinsic image resolution as appropriate in layout/style/dom, and update test expectations. r=tnikkel
This should be mostly straight-forward, since we have code for this anyways for image-set() and srcset. The only thing is that we were using floats for resolution, but since EXIF allows you to scale each axis separately, we now need to pass an image::Resolution instead. The main outstanding issue is the spec comment mentioned in the previous patch, about what happens if you have srcset/image-set and the image density specified together. For now I've implemented what the image-set() spec says, but this is subject to change before shipping of course. Differential Revision: https://phabricator.services.mozilla.com/D113265
This commit is contained in:
@@ -710,28 +710,33 @@ uint32_t HTMLImageElement::Height() { return GetWidthHeightForImage().height; }
|
||||
|
||||
uint32_t HTMLImageElement::Width() { return GetWidthHeightForImage().width; }
|
||||
|
||||
uint32_t HTMLImageElement::NaturalHeight() {
|
||||
uint32_t height = nsImageLoadingContent::NaturalHeight();
|
||||
|
||||
if (mResponsiveSelector) {
|
||||
double density = mResponsiveSelector->GetSelectedImageDensity();
|
||||
MOZ_ASSERT(density >= 0.0);
|
||||
height = NSToIntRound(double(height) / density);
|
||||
nsIntSize HTMLImageElement::NaturalSize() {
|
||||
if (!mCurrentRequest) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
uint32_t HTMLImageElement::NaturalWidth() {
|
||||
uint32_t width = nsImageLoadingContent::NaturalWidth();
|
||||
|
||||
if (mResponsiveSelector) {
|
||||
double density = mResponsiveSelector->GetSelectedImageDensity();
|
||||
MOZ_ASSERT(density >= 0.0);
|
||||
width = NSToIntRound(double(width) / density);
|
||||
nsCOMPtr<imgIContainer> image;
|
||||
mCurrentRequest->GetImage(getter_AddRefs(image));
|
||||
if (!image) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return width;
|
||||
nsIntSize size;
|
||||
Unused << image->GetHeight(&size.height);
|
||||
Unused << image->GetWidth(&size.width);
|
||||
|
||||
ImageResolution resolution = image->GetResolution();
|
||||
// NOTE(emilio): What we implement here matches the image-set() spec, but it's
|
||||
// unclear whether this is the right thing to do, see
|
||||
// https://github.com/whatwg/html/pull/5574#issuecomment-826335244.
|
||||
if (mResponsiveSelector) {
|
||||
float density = mResponsiveSelector->GetSelectedImageDensity();
|
||||
MOZ_ASSERT(density >= 0.0);
|
||||
resolution = {density, density};
|
||||
}
|
||||
|
||||
resolution.ApplyTo(size.width, size.height);
|
||||
return size;
|
||||
}
|
||||
|
||||
nsresult HTMLImageElement::CopyInnerTo(HTMLImageElement* aDest) {
|
||||
|
||||
Reference in New Issue
Block a user