| Index: Source/core/paint/ImagePainter.cpp
|
| diff --git a/Source/core/paint/ImagePainter.cpp b/Source/core/paint/ImagePainter.cpp
|
| index 922242274108ed2d6aeab8d70131be7b752dcf52..5675fc01ac074029c5e1d2fda1757cabf725b030 100644
|
| --- a/Source/core/paint/ImagePainter.cpp
|
| +++ b/Source/core/paint/ImagePainter.cpp
|
| @@ -78,20 +78,82 @@
|
|
|
| GraphicsContext* context = paintInfo.context;
|
|
|
| - if (!m_renderImage.imageResource()->hasImage()) {
|
| + if (!m_renderImage.imageResource()->hasImage() || m_renderImage.imageResource()->errorOccurred()) {
|
| if (paintInfo.phase == PaintPhaseSelection)
|
| return;
|
|
|
| if (cWidth > 2 && cHeight > 2) {
|
| + const int borderWidth = 1;
|
| +
|
| + LayoutUnit leftBorder = m_renderImage.borderLeft();
|
| + LayoutUnit topBorder = m_renderImage.borderTop();
|
| + LayoutUnit leftPad = m_renderImage.paddingLeft();
|
| + LayoutUnit topPad = m_renderImage.paddingTop();
|
| +
|
| // Draw an outline rect where the image should be.
|
| - IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() + m_renderImage.borderLeft() + m_renderImage.paddingLeft(), paintOffset.y() + m_renderImage.borderTop() + m_renderImage.paddingTop(), cWidth, cHeight));
|
| + IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() + leftBorder + leftPad, paintOffset.y() + topBorder + topPad, cWidth, cHeight));
|
| DrawingRecorder recorder(context, &m_renderImage, paintInfo.phase, paintRect);
|
| context->setStrokeStyle(SolidStroke);
|
| context->setStrokeColor(Color::lightGray);
|
| context->setFillColor(Color::transparent);
|
| context->drawRect(paintRect);
|
| +
|
| + 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.
|
| + LayoutUnit usableWidth = cWidth - 2 * borderWidth;
|
| + LayoutUnit usableHeight = cHeight - 2 * borderWidth;
|
| +
|
| + RefPtr<Image> image = m_renderImage.imageResource()->image();
|
| +
|
| + if (m_renderImage.imageResource()->errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
|
| + float deviceScaleFactor = blink::deviceScaleFactor(m_renderImage.frame());
|
| + // Call brokenImage() explicitly to ensure we get the broken image icon at the appropriate resolution.
|
| + pair<Image*, float> brokenImageAndImageScaleFactor = ImageResource::brokenImage(deviceScaleFactor);
|
| + image = brokenImageAndImageScaleFactor.first;
|
| + IntSize imageSize = image->size();
|
| + imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
|
| + // Center the error image, accounting for border and padding.
|
| + LayoutUnit centerX = (usableWidth - imageSize.width()) / 2;
|
| + if (centerX < 0)
|
| + centerX = 0;
|
| + LayoutUnit centerY = (usableHeight - imageSize.height()) / 2;
|
| + if (centerY < 0)
|
| + centerY = 0;
|
| + imageOffset = LayoutSize(leftBorder + leftPad + centerX + borderWidth, topBorder + topPad + centerY + borderWidth);
|
| + context->drawImage(image.get(), pixelSnappedIntRect(LayoutRect(paintOffset + imageOffset, imageSize)), CompositeSourceOver, m_renderImage.shouldRespectImageOrientation());
|
| + errorPictureDrawn = true;
|
| + }
|
| +
|
| + if (!m_renderImage.altText().isEmpty()) {
|
| + const Font& font = m_renderImage.style()->font();
|
| + const FontMetrics& fontMetrics = font.fontMetrics();
|
| + LayoutUnit ascent = fontMetrics.ascent();
|
| + LayoutPoint textRectOrigin = paintOffset;
|
| + textRectOrigin.move(leftBorder + leftPad + (RenderImage::paddingWidth / 2) - borderWidth, topBorder + topPad + (RenderImage::paddingHeight / 2) - borderWidth);
|
| + LayoutPoint textOrigin(textRectOrigin.x(), textRectOrigin.y() + ascent);
|
| +
|
| + // Only draw the alt text if it'll fit within the content box,
|
| + // and only if it fits above the error image.
|
| + TextRun textRun = constructTextRun(&m_renderImage, font, m_renderImage.altText(), m_renderImage.style(), TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpansion, DefaultTextRunFlags | RespectDirection);
|
| + float textWidth = font.width(textRun);
|
| + TextRunPaintInfo textRunPaintInfo(textRun);
|
| + textRunPaintInfo.bounds = FloatRect(textRectOrigin, FloatSize(textWidth, fontMetrics.height()));
|
| + context->setFillColor(m_renderImage.resolveColor(CSSPropertyColor));
|
| + if (textRun.direction() == RTL) {
|
| + int availableWidth = cWidth - static_cast<int>(RenderImage::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);
|
| + }
|
| + }
|
| }
|
| - } else if (cWidth > 0 && cHeight > 0) {
|
| + } else if (m_renderImage.imageResource()->hasImage() && cWidth > 0 && cHeight > 0) {
|
| LayoutRect contentRect = m_renderImage.contentBoxRect();
|
| contentRect.moveBy(paintOffset);
|
| LayoutRect paintRect = m_renderImage.replacedContentRect();
|
|
|