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

Unified Diff: Source/core/rendering/RenderImage.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, 3 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
« Source/core/rendering/RenderBox.cpp ('K') | « Source/core/rendering/RenderImage.h ('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 7fed328e648c9ddda67dd5ab8124dc25c2aa5f40..deb8cc7472f3cd8f95c071b0421011948e42d676 100644
--- a/Source/core/rendering/RenderImage.cpp
+++ b/Source/core/rendering/RenderImage.cpp
@@ -63,7 +63,6 @@ RenderImage::RenderImage(Element* element)
, m_isGeneratedContent(false)
, m_imageDevicePixelRatio(1.0f)
{
- updateAltText();
ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->addRenderObject(this);
}
@@ -92,62 +91,6 @@ void RenderImage::setImageResource(PassOwnPtr<RenderImageResource> imageResource
m_imageResource->initialize(this);
}
-// If we'll be displaying either alt text or an image, add some padding.
-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);
- ASSERT_ARG(newImage, newImage->imageForRenderer(this));
-
- IntSize imageSize;
- if (newImage->willPaintBrokenImage()) {
- float deviceScaleFactor = blink::deviceScaleFactor(frame());
- pair<Image*, float> brokenImageAndImageScaleFactor = ImageResource::brokenImage(deviceScaleFactor);
- imageSize = brokenImageAndImageScaleFactor.first->size();
- imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
- } else
- imageSize = newImage->imageForRenderer(this)->size();
-
- // imageSize() returns 0 for the error image. We need the true size of the
- // error image, so we have to get it by grabbing image() directly.
- return IntSize(paddingWidth + imageSize.width() * style()->effectiveZoom(), paddingHeight + imageSize.height() * style()->effectiveZoom());
-}
-
-// Sets the image height and width to fit the alt text. Returns true if the
-// image size changed.
-bool RenderImage::setImageSizeForAltText(ImageResource* newImage /* = 0 */)
-{
- IntSize imageSize;
- if (newImage && newImage->imageForRenderer(this))
- imageSize = imageSizeForError(newImage);
- else if (!m_altText.isEmpty() || newImage) {
- // If we'll be displaying either text or an image, add a little padding.
- imageSize = IntSize(paddingWidth, paddingHeight);
- }
-
- // we have an alt and the user meant it (its not a text we invented)
- if (!m_altText.isEmpty()) {
- 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));
- imageSize = imageSize.expandedTo(paddedTextSize);
- }
-
- if (imageSize == intrinsicSize())
- return false;
-
- setIntrinsicSize(imageSize);
- return true;
-}
-
void RenderImage::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
{
if (documentBeingDestroyed())
@@ -173,13 +116,7 @@ void RenderImage::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
m_didIncrementVisuallyNonEmptyPixelCount = true;
}
- bool imageSizeChanged = false;
-
- // Set image dimensions, taking into account the size of the alt text.
- if (m_imageResource->errorOccurred() || !newImage)
- imageSizeChanged = setImageSizeForAltText(m_imageResource->cachedImage());
-
- paintInvalidationOrMarkForLayout(imageSizeChanged, rect);
+ repaintOrMarkForLayout(rect);
}
void RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize)
@@ -198,7 +135,7 @@ void RenderImage::updateInnerContentRect()
m_imageResource->setContainerSizeForRenderer(containerSize);
}
-void RenderImage::paintInvalidationOrMarkForLayout(bool imageSizeChangedToAccomodateAltText, const IntRect* rect)
+void RenderImage::repaintOrMarkForLayout(const IntRect* rect)
{
LayoutSize oldIntrinsicSize = intrinsicSize();
LayoutSize newIntrinsicSize = m_imageResource->intrinsicSize(style()->effectiveZoom());
@@ -211,7 +148,7 @@ void RenderImage::paintInvalidationOrMarkForLayout(bool imageSizeChangedToAccomo
if (!containingBlock())
return;
- bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize || imageSizeChangedToAccomodateAltText;
+ bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize;
if (imageSourceHasChangedSize)
setPreferredLogicalWidthsDirty();
@@ -283,79 +220,16 @@ void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
LayoutUnit cHeight = contentHeight();
GraphicsContext* context = paintInfo.context;
-
- if (!m_imageResource->hasImage() || m_imageResource->errorOccurred()) {
+ if (!m_imageResource->hasImage()) {
if (paintInfo.phase == PaintPhaseSelection)
return;
if (cWidth > 2 && cHeight > 2) {
- const int borderWidth = 1;
-
- LayoutUnit leftBorder = borderLeft();
- LayoutUnit topBorder = borderTop();
- LayoutUnit leftPad = paddingLeft();
- LayoutUnit topPad = paddingTop();
-
// Draw an outline rect where the image should be.
context->setStrokeStyle(SolidStroke);
context->setStrokeColor(Color::lightGray);
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.
- LayoutUnit usableWidth = cWidth - 2 * borderWidth;
- LayoutUnit usableHeight = cHeight - 2 * borderWidth;
-
- RefPtr<Image> image = m_imageResource->image();
-
- if (m_imageResource->errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
- 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);
- 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();
- LayoutUnit ascent = fontMetrics.ascent();
- LayoutPoint textRectOrigin = paintOffset;
- textRectOrigin.move(leftBorder + leftPad + (paddingWidth / 2) - borderWidth, topBorder + topPad + (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(this, font, m_altText, 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(resolveColor(CSSPropertyColor));
- if (textRun.direction() == RTL) {
- 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->drawRect(pixelSnappedIntRect(LayoutRect(paintOffset.x() + borderLeft() + paddingLeft(), paintOffset.y() + borderTop() + paddingTop(), cWidth, cHeight)));
esprehn 2014/09/05 00:47:52 What is this drawing?
rhogan 2014/09/08 19:52:43 This is for when an image has no src and no alt te
}
} else if (m_imageResource->hasImage() && cWidth > 0 && cHeight > 0) {
LayoutRect contentRect = contentBoxRect();
@@ -542,17 +416,6 @@ bool RenderImage::nodeAtPoint(const HitTestRequest& request, HitTestResult& resu
return inside;
}
-void RenderImage::updateAltText()
-{
- if (!node())
- return;
-
- if (isHTMLInputElement(*node()))
- m_altText = toHTMLInputElement(node())->altText();
- else if (isHTMLImageElement(*node()))
- m_altText = toHTMLImageElement(node())->altText();
-}
-
void RenderImage::layout()
{
LayoutRect oldContentRect = replacedContentRect();
« Source/core/rendering/RenderBox.cpp ('K') | « Source/core/rendering/RenderImage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698