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

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

Issue 328703003: Change behaviour of Alt text. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed Layout tests Created 6 years, 5 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/tables/mozilla/collapsing_borders/bug41262-3-expected.png ('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 04560131d86ff2abeb3f32b3bc12bf093ae1eadc..af47fa0d010c1ba9ce43b5f14f38b1fd4ad34438 100644
--- a/Source/core/rendering/RenderImage.cpp
+++ b/Source/core/rendering/RenderImage.cpp
@@ -293,8 +293,7 @@ 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;
+ bool altTextDisplayed = false;
// 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;
@@ -302,25 +301,6 @@ 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()) {
- float deviceScaleFactor = WebCore::deviceScaleFactor(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, shouldRespectImageOrientation());
- errorPictureDrawn = true;
- }
-
if (!m_altText.isEmpty()) {
const Font& font = style()->font();
const FontMetrics& fontMetrics = font.fontMetrics();
@@ -340,13 +320,30 @@ 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()) {
+ if (usableWidth >= textWidth && usableHeight >= fontMetrics.height()) {
context->drawBidiText(font, textRunPaintInfo, textOrigin);
+ altTextDisplayed = true;
}
}
+
+ if (!altTextDisplayed && m_imageResource->errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
+ float deviceScaleFactor = WebCore::deviceScaleFactor(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;
+ LayoutSize imageOffset;
+ imageOffset = LayoutSize(leftBorder + leftPad + centerX + borderWidth, topBorder + topPad + centerY + borderWidth);
+ context->drawImage(image.get(), pixelSnappedIntRect(LayoutRect(paintOffset + imageOffset, imageSize)), CompositeSourceOver, shouldRespectImageOrientation());
+ }
}
} else if (m_imageResource->hasImage() && cWidth > 0 && cHeight > 0) {
RefPtr<Image> img = m_imageResource->image(cWidth, cHeight);
« no previous file with comments | « LayoutTests/platform/linux/tables/mozilla/collapsing_borders/bug41262-3-expected.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698