зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
31b1a910ac
Коммит
1bfaededfa
|
@ -180,6 +180,15 @@ bool nsImageFrame::ShouldShowBrokenImageIcon() const {
|
|||
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
|
||||
// not considered broken because they have no image requests
|
||||
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>
|
Загрузка…
Ссылка в новой задаче