Bug 1616537 - Don't give images with empty alt an intrinsic ratio. r=bzbarsky

The spec seems to want us to treat it like an inline, but that's not what other
browsers do (I added tests for this in bug 1196668, and they still pass in all
engines).

This is an oddly specific condition to put in
nsImageFrame::ShouldShowBrokenImageIcon(), but oh well, we're past all sanity
here I think...

Differential Revision: https://phabricator.services.mozilla.com/D63715

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2020-02-21 21:03:22 +00:00
Родитель 31b1a910ac
Коммит 1bfaededfa
2 изменённых файлов: 32 добавлений и 0 удалений

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

@ -180,6 +180,15 @@ bool nsImageFrame::ShouldShowBrokenImageIcon() const {
return false; return false;
} }
// <img alt=""> is special, and it shouldn't draw the broken image icon,
// unlike the no-alt attribute or non-empty-alt-attribute case.
if (auto* image = HTMLImageElement::FromNode(mContent)) {
const nsAttrValue* alt = image->GetParsedAttr(nsGkAtoms::alt);
if (alt && alt->IsEmptyString()) {
return false;
}
}
// check for broken images. valid null images (eg. img src="") are // check for broken images. valid null images (eg. img src="") are
// not considered broken because they have no image requests // not considered broken because they have no image requests
if (nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest()) { if (nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest()) {

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

@ -0,0 +1,23 @@
<!doctype html>
<title>Images with an empty alt attribute have an intrinsic size of zero</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
img {
width: 50px;
height: auto;
}
</style>
<img src="broken">
<img src="broken" alt="non-empty">
<img src="broken" alt="">
<script>
const t = async_test("Images with an empty alt attribute have an intrinsic size of zero");
onload = t.step_func_done(function() {
for (const img of document.querySelectorAll("img")) {
const alt = img.getAttribute("alt");
const shouldTakeUpSpace = alt == null || alt.length > 0;
(shouldTakeUpSpace ? assert_not_equals : assert_equals)(img.offsetHeight, 0, img.outerHTML);
}
});
</script>