Commit caccabc0 authored by yoav's avatar yoav Committed by Commit bot

Notify LayoutImage that intrinsic dimensions changed when sizes changes

When the sizes attribute changes, that has the potential of modifying the
image's intrinsic dimensions. However, the LayoutImage object was not
notified of that explicitly. While the intrinsic dimensions were changed
when a new resource was downloaded as a result of the sizes attribute
change, that wasn't the case when such the resource was not changed.

This CL fixes that, by explicitly notifying the LayoutImage of the change.

BUG=639845

Review-Url: https://codereview.chromium.org/2292013002
Cr-Commit-Position: refs/heads/master@{#415369}
parent be8b5afc
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<body>
<img id="image"
srcset="resources/black.png 100w,
resources/image-set-4x.png 1600w"
sizes="100px"
>
<script>
var t = async_test('Make sure that a sizes change also changes the intrinsic dimensions');
window.onload = t.step_func(function() {
var img = document.getElementById("image");
img.onload = t.step_func(function() {
assert_equals(img.width, 1600);
img.onload = function(){};
img.sizes = "100px";
assert_equals(img.width, 100);
t.done();
});
img.sizes = "1600px";
});
</script>
</body>
</html>
......@@ -227,6 +227,7 @@ void HTMLImageElement::setBestFitURLAndDPRFromImageCandidate(const ImageCandidat
{
m_bestFitImageURL = candidate.url();
float candidateDensity = candidate.density();
float oldImageDevicePixelRatio = m_imageDevicePixelRatio;
if (candidateDensity >= 0)
m_imageDevicePixelRatio = 1.0 / candidateDensity;
......@@ -237,9 +238,13 @@ void HTMLImageElement::setBestFitURLAndDPRFromImageCandidate(const ImageCandidat
} else if (!candidate.srcOrigin()) {
UseCounter::count(document(), UseCounter::SrcsetXDescriptor);
}
if (layoutObject() && layoutObject()->isImage())
if (layoutObject() && layoutObject()->isImage()) {
LayoutImageItem(toLayoutImage(layoutObject())).setImageDevicePixelRatio(m_imageDevicePixelRatio);
if (oldImageDevicePixelRatio != m_imageDevicePixelRatio)
toLayoutImage(layoutObject())->intrinsicSizeChanged();
}
if (intrinsicSizingViewportDependant) {
if (!m_listener)
m_listener = ViewportChangeListener::create(this);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment