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

Unified Diff: Source/core/paint/ImagePainter.cpp

Issue 481753002: Use Shadow DOM to display fallback content for images (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated Created 6 years 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 | « Source/core/loader/ImageLoader.cpp ('k') | Source/core/rendering/RenderBox.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/paint/ImagePainter.cpp
diff --git a/Source/core/paint/ImagePainter.cpp b/Source/core/paint/ImagePainter.cpp
index 6ff4abc1797eb1ac1ab8cbc9c5f602ec8a6189cb..f4388257d6c5f8bb97f712a37fc636ecb5e4f560 100644
--- a/Source/core/paint/ImagePainter.cpp
+++ b/Source/core/paint/ImagePainter.cpp
@@ -78,82 +78,20 @@ void ImagePainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
GraphicsContext* context = paintInfo.context;
- if (!m_renderImage.imageResource()->hasImage() || m_renderImage.imageResource()->errorOccurred()) {
+ if (!m_renderImage.imageResource()->hasImage()) {
Noel Gordon 2014/12/16 00:54:53 I may have missed a mention of this in the ChangeL
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() + leftBorder + leftPad, paintOffset.y() + topBorder + topPad, cWidth, cHeight));
+ IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() + m_renderImage.borderLeft() + m_renderImage.paddingLeft(), paintOffset.y() + m_renderImage.borderTop() + m_renderImage.paddingTop(), cWidth, cHeight));
RenderDrawingRecorder 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, LayoutSize(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);
- FloatPoint textOrigin(textRectOrigin.x().toFloat(), (textRectOrigin.y() + ascent).toFloat());
-
- // 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(FloatPoint(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 (m_renderImage.imageResource()->hasImage() && cWidth > 0 && cHeight > 0) {
+ } else if (cWidth > 0 && cHeight > 0) {
LayoutRect contentRect = m_renderImage.contentBoxRect();
contentRect.moveBy(paintOffset);
LayoutRect paintRect = m_renderImage.replacedContentRect();
« no previous file with comments | « Source/core/loader/ImageLoader.cpp ('k') | Source/core/rendering/RenderBox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698