Bug 922931 - Display a placeholder for broken images if the alt attribute is unset even in no-quirks mode. r=bz

This commit is contained in:
Masatoshi Kimura 2013-10-06 05:25:49 +09:00
parent aa2d9b929c
commit ab2dd4c4b2
10 changed files with 30 additions and 32 deletions

View File

@ -1,6 +1,7 @@
<!DOCTYPE HTML>
<html>
<body>
<img id="image1" src="">
<input id="image3" type="image">
</body>
</html>

View File

@ -2886,7 +2886,6 @@
"[[\"forwarddelete\",\"\"]] \"<p>foo[]</p><br><p>bar</p>\" compare innerHTML":true,
"[[\"forwarddelete\",\"\"]] \"<p>foo[]</p><br><br><p>bar</p>\" compare innerHTML":true,
"[[\"forwarddelete\",\"\"]] \"<p>foo[]</p><img src=/img/lion.svg><p>bar\" compare innerHTML":true,
"[[\"forwarddelete\",\"\"]] \"foo[]<img src=/img/lion.svg>bar\" compare innerHTML":true,
"[[\"forwarddelete\",\"\"]] \"foo []&nbsp;\" compare innerHTML":true,
"[[\"forwarddelete\",\"\"]] \"foo []<span>&nbsp;</span> bar\" compare innerHTML":true,
"[[\"forwarddelete\",\"\"]] \"foo <span>&nbsp;</span>[] bar\" compare innerHTML":true,

View File

@ -51,6 +51,7 @@ function initializeOnload() {
var firstimg = document.createElement('img');
firstimg.addEventListener("load", imageLoad, false);
firstimg.addEventListener("error", imageLoad, false);
firstimg.alt = "";
firstimg.src = "bug733553.sjs";
document.getElementById('content').appendChild(firstimg);

View File

@ -20,6 +20,7 @@
var imgURL = document.location.search.substr(1);
document.images[0].onload = onImageLoad;
document.images[0].onerror = onImageLoad;
document.images[0].alt = "";
document.images[0].src = imgURL;
</script>
</body>

View File

@ -20,6 +20,7 @@
var imgURL = document.location.search.substr(1);
document.images[0].onload = onImageLoad;
document.images[0].onerror = onImageLoad;
document.images[0].alt = "";
document.images[0].src = imgURL;
</script>
</body>

View File

@ -20,6 +20,7 @@
var imgURL = document.location.search.substr(1);
document.images[0].onload = onImageLoad;
document.images[0].onerror = onImageLoad;
document.images[0].alt = "";
document.images[0].src = imgURL;
</script>
</body>

View File

@ -20,6 +20,7 @@
var imgURL = document.location.search.substr(1);
document.images[0].onload = onImageLoad;
document.images[0].onerror = onImageLoad;
document.images[0].alt = "";
document.images[0].src = imgURL;
</script>
</body>

View File

@ -451,9 +451,9 @@ nsImageFrame::ShouldCreateImageFrameFor(Element* aElement,
// - if our special "force icons" style is set, show an icon
// - else if our "do not show placeholders" pref is set, skip the icon
// - else:
// - if QuirksMode, and there is no alt attribute, and this is not an
// <object> (which could not possibly have such an attribute), show an
// icon.
// - if there is a src attribute, there is no alt attribute,
// and this is not an <object> (which could not possibly have
// such an attribute), show an icon.
// - if QuirksMode, and the IMG has a size show an icon.
// - otherwise, skip the icon
bool useSizedBox;
@ -464,31 +464,24 @@ nsImageFrame::ShouldCreateImageFrameFor(Element* aElement,
else if (gIconLoad && gIconLoad->mPrefForceInlineAltText) {
useSizedBox = false;
}
else {
if (aStyleContext->PresContext()->CompatibilityMode() !=
eCompatibility_NavQuirks) {
useSizedBox = false;
}
else {
// We are in quirks mode, so we can just check the tag name; no need to
// check the namespace.
nsIAtom *localName = aElement->Tag();
// Use a sized box if we have no alt text. This means no alt attribute
// and the node is not an object or an input (since those always have alt
// text).
if (!aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::alt) &&
localName != nsGkAtoms::object &&
localName != nsGkAtoms::input) {
useSizedBox = true;
}
else {
// check whether we have fixed size
useSizedBox = HaveFixedSize(aStyleContext->StylePosition());
}
}
else if (aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::src) &&
!aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::alt) &&
!aElement->IsHTML(nsGkAtoms::object) &&
!aElement->IsHTML(nsGkAtoms::input)) {
// Use a sized box if we have no alt text. This means no alt attribute
// and the node is not an object or an input (since those always have alt
// text).
useSizedBox = true;
}
else if (aStyleContext->PresContext()->CompatibilityMode() !=
eCompatibility_NavQuirks) {
useSizedBox = false;
}
else {
// check whether we have fixed size
useSizedBox = HaveFixedSize(aStyleContext->StylePosition());
}
return useSizedBox;
}
@ -720,9 +713,7 @@ nsImageFrame::EnsureIntrinsicSizeAndRatio(nsPresContext* aPresContext)
// invalid image specified
// - make the image big enough for the icon (it may not be
// used if inline alt expansion is used instead)
// XXX: we need this in composer, but it is also good for
// XXX: general quirks mode to always have room for the icon
if (aPresContext->CompatibilityMode() == eCompatibility_NavQuirks) {
if (!(GetStateBits() & NS_FRAME_GENERATED_CONTENT)) {
nscoord edgeLengthToUse =
nsPresContext::CSSPixelsToAppUnits(
ICON_SIZE + (2 * (ICON_PADDING + ALT_BORDER_WIDTH)));

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<body>
<img>

View File

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<body>
<img src="http://www.foo oo.com">
<img src="http://www.foo oo.com" alt="">
<input type="image" src="http://www.foo oo.com">
</body>
</html>