Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Unified Diff: Source/core/rendering/RenderImage.cpp

Issue 419453003: Show alt text when source image is missing or broken or not found. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebaselining newly added Layout test cases Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/platform/linux/fast/dom/HTMLImageElement/image-alt-text-width-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/RenderImage.cpp
diff --git a/Source/core/rendering/RenderImage.cpp b/Source/core/rendering/RenderImage.cpp
index c46e8f0897192af236d61e1663e6f467b39afc4e..c698b7982f283315825d0a4b26ad47c7a6229d36 100644
--- a/Source/core/rendering/RenderImage.cpp
+++ b/Source/core/rendering/RenderImage.cpp
@@ -95,11 +95,6 @@ void RenderImage::setImageResource(PassOwnPtr<RenderImageResource> imageResource
static const unsigned short paddingWidth = 4;
static const unsigned short paddingHeight = 4;
-// Alt text is restricted to this maximum size, in pixels. These are
-// signed integers because they are compared with other signed values.
-static const float maxAltTextWidth = 1024;
-static const int maxAltTextHeight = 256;
-
IntSize RenderImage::imageSizeForError(ImageResource* newImage) const
{
ASSERT_ARG(newImage, newImage);
@@ -136,7 +131,7 @@ bool RenderImage::setImageSizeForAltText(ImageResource* newImage /* = 0 */)
FontCachePurgePreventer fontCachePurgePreventer;
const Font& font = style()->font();
- IntSize paddedTextSize(paddingWidth + std::min(ceilf(font.width(constructTextRun(this, font, m_altText, style()))), maxAltTextWidth), paddingHeight + std::min(font.fontMetrics().height(), maxAltTextHeight));
+ IntSize paddedTextSize(paddingWidth + ceilf(font.width(constructTextRun(this, font, m_altText, style()))), paddingHeight + font.fontMetrics().height());
imageSize = imageSize.expandedTo(paddedTextSize);
}
@@ -299,7 +294,6 @@ void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
context->setFillColor(Color::transparent);
context->drawRect(pixelSnappedIntRect(LayoutRect(paintOffset.x() + leftBorder + leftPad, paintOffset.y() + topBorder + topPad, cWidth, cHeight)));
- bool errorPictureDrawn = false;
LayoutSize imageOffset;
// When calculating the usable dimensions, exclude the pixels of
// the ouline rect so the error image/alt text doesn't draw on it.
@@ -308,7 +302,7 @@ void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
RefPtr<Image> image = m_imageResource->image();
- if (m_imageResource->errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
+ if (m_imageResource->errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height() && m_altText.isEmpty()) {
float deviceScaleFactor = blink::deviceScaleFactor(frame());
// Call brokenImage() explicitly to ensure we get the broken image icon at the appropriate resolution.
pair<Image*, float> brokenImageAndImageScaleFactor = ImageResource::brokenImage(deviceScaleFactor);
@@ -324,7 +318,6 @@ void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
centerY = 0;
imageOffset = LayoutSize(leftBorder + leftPad + centerX + borderWidth, topBorder + topPad + centerY + borderWidth);
context->drawImage(image.get(), pixelSnappedIntRect(LayoutRect(paintOffset + imageOffset, imageSize)), CompositeSourceOver, shouldRespectImageOrientation());
- errorPictureDrawn = true;
}
if (!m_altText.isEmpty()) {
@@ -346,12 +339,7 @@ void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
int availableWidth = cWidth - static_cast<int>(paddingWidth);
textOrigin.move(availableWidth - ceilf(textWidth), 0);
}
- if (errorPictureDrawn) {
- if (usableWidth >= textWidth && fontMetrics.height() <= imageOffset.height())
- context->drawBidiText(font, textRunPaintInfo, textOrigin);
- } else if (usableWidth >= textWidth && usableHeight >= fontMetrics.height()) {
- context->drawBidiText(font, textRunPaintInfo, textOrigin);
- }
+ context->drawBidiText(font, textRunPaintInfo, textOrigin);
}
}
} else if (m_imageResource->hasImage() && cWidth > 0 && cHeight > 0) {
« no previous file with comments | « LayoutTests/platform/linux/fast/dom/HTMLImageElement/image-alt-text-width-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698