#include "config.h"
#include "RenderImage.h"
#include "BitmapImage.h"
#include "CachedImage.h"
#include "Font.h"
#include "FontCache.h"
#include "Frame.h"
#include "FrameSelection.h"
#include "GeometryUtilities.h"
#include "GraphicsContext.h"
#include "HTMLAreaElement.h"
#include "HTMLImageElement.h"
#include "HTMLInputElement.h"
#include "HTMLMapElement.h"
#include "HTMLNames.h"
#include "HitTestResult.h"
#include "InlineElementBox.h"
#include "Page.h"
#include "PaintInfo.h"
#include "RenderFlowThread.h"
#include "RenderImageResourceStyleImage.h"
#include "RenderView.h"
#include "SVGImage.h"
#include <wtf/StackStats.h>
#if PLATFORM(IOS)
#include "LogicalSelectionOffsetCaches.h"
#include "SelectionRect.h"
#endif
namespace WebCore {
#if PLATFORM(IOS)
void RenderImage::collectSelectionRects(Vector<SelectionRect>& rects, unsigned, unsigned)
{
RenderBlock* containingBlock = this->containingBlock();
IntRect imageRect;
IntRect lineExtentRect;
bool isFirstOnLine = false;
bool isLastOnLine = false;
InlineBox* inlineBox = inlineBoxWrapper();
if (!inlineBox) {
imageRect = IntRect(0, 0, width(), height());
isFirstOnLine = true;
isLastOnLine = true;
lineExtentRect = imageRect;
if (containingBlock->isHorizontalWritingMode()) {
lineExtentRect.setX(containingBlock->x());
lineExtentRect.setWidth(containingBlock->width());
} else {
lineExtentRect.setY(containingBlock->y());
lineExtentRect.setHeight(containingBlock->height());
}
} else {
LayoutUnit selectionTop = !containingBlock->style().isFlippedBlocksWritingMode() ? inlineBox->root().selectionTop() - logicalTop() : logicalBottom() - inlineBox->root().selectionBottom();
imageRect = IntRect(0, selectionTop, logicalWidth(), inlineBox->root().selectionHeight());
isFirstOnLine = !inlineBox->previousOnLineExists();
isLastOnLine = !inlineBox->nextOnLineExists();
LogicalSelectionOffsetCaches cache(*containingBlock);
LayoutUnit leftOffset = containingBlock->logicalLeftSelectionOffset(*containingBlock, inlineBox->logicalTop(), cache);
LayoutUnit rightOffset = containingBlock->logicalRightSelectionOffset(*containingBlock, inlineBox->logicalTop(), cache);
lineExtentRect = IntRect(leftOffset - logicalLeft(), imageRect.y(), rightOffset - leftOffset, imageRect.height());
if (!inlineBox->isHorizontal()) {
imageRect = imageRect.transposedRect();
lineExtentRect = lineExtentRect.transposedRect();
}
}
bool isFixed = false;
IntRect absoluteBounds = localToAbsoluteQuad(FloatRect(imageRect), false, &isFixed).enclosingBoundingBox();
IntRect lineExtentBounds = localToAbsoluteQuad(FloatRect(lineExtentRect)).enclosingBoundingBox();
if (!containingBlock->isHorizontalWritingMode())
lineExtentBounds = lineExtentBounds.transposedRect();
rects.append(SelectionRect(absoluteBounds, containingBlock->style().direction(), lineExtentBounds.x(), lineExtentBounds.maxX(), lineExtentBounds.maxY(), 0, false , isFirstOnLine, isLastOnLine, false , false , containingBlock->style().isHorizontalWritingMode(), isFixed, false , view().pageNumberForBlockProgressionOffset(absoluteBounds.x())));
}
#endif
using namespace HTMLNames;
RenderImage::RenderImage(Element& element, PassRef<RenderStyle> style, StyleImage* styleImage, const float imageDevicePixelRatio)
: RenderReplaced(element, WTF::move(style), IntSize())
, m_imageResource(styleImage ? std::make_unique<RenderImageResourceStyleImage>(*styleImage) : std::make_unique<RenderImageResource>())
, m_needsToSetSizeForAltText(false)
, m_didIncrementVisuallyNonEmptyPixelCount(false)
, m_isGeneratedContent(false)
, m_hasShadowControls(false)
, m_imageDevicePixelRatio(imageDevicePixelRatio)
{
updateAltText();
imageResource().initialize(this);
if (isHTMLImageElement(element))
m_hasShadowControls = toHTMLImageElement(element).hasShadowControls();
}
RenderImage::RenderImage(Document& document, PassRef<RenderStyle> style, StyleImage* styleImage)
: RenderReplaced(document, WTF::move(style), IntSize())
, m_imageResource(styleImage ? std::make_unique<RenderImageResourceStyleImage>(*styleImage) : std::make_unique<RenderImageResource>())
, m_needsToSetSizeForAltText(false)
, m_didIncrementVisuallyNonEmptyPixelCount(false)
, m_isGeneratedContent(false)
, m_hasShadowControls(false)
, m_imageDevicePixelRatio(1.0f)
{
imageResource().initialize(this);
}
RenderImage::~RenderImage()
{
imageResource().shutdown();
}
static const unsigned short paddingWidth = 4;
static const unsigned short paddingHeight = 4;
static const float maxAltTextWidth = 1024;
static const int maxAltTextHeight = 256;
IntSize RenderImage::imageSizeForError(CachedImage* newImage) const
{
ASSERT_ARG(newImage, newImage);
ASSERT_ARG(newImage, newImage->imageForRenderer(this));
FloatSize imageSize;
if (newImage->willPaintBrokenImage()) {
std::pair<Image*, float> brokenImageAndImageScaleFactor = newImage->brokenImage(document().deviceScaleFactor());
imageSize = brokenImageAndImageScaleFactor.first->size();
imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
} else
imageSize = newImage->imageForRenderer(this)->size();
return IntSize(paddingWidth + imageSize.width() * style().effectiveZoom(), paddingHeight + imageSize.height() * style().effectiveZoom());
}
bool RenderImage::setImageSizeForAltText(CachedImage* newImage )
{
IntSize imageSize;
if (newImage && newImage->imageForRenderer(this))
imageSize = imageSizeForError(newImage);
else if (!m_altText.isEmpty() || newImage) {
imageSize = IntSize(paddingWidth, paddingHeight);
}
if (!m_altText.isEmpty()) {
FontCachePurgePreventer fontCachePurgePreventer;
const Font& font = style().font();
IntSize paddedTextSize(paddingWidth + std::min(ceilf(font.width(RenderBlock::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::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
RenderReplaced::styleDidChange(diff, oldStyle);
if (m_needsToSetSizeForAltText) {
if (!m_altText.isEmpty() && setImageSizeForAltText(imageResource().cachedImage()))
imageDimensionsChanged(true );
m_needsToSetSizeForAltText = false;
}
#if ENABLE(CSS_IMAGE_ORIENTATION)
if (diff == StyleDifferenceLayout && oldStyle->imageOrientation() != style().imageOrientation())
return imageDimensionsChanged(true );
#endif
#if ENABLE(CSS_IMAGE_RESOLUTION)
if (diff == StyleDifferenceLayout
&& (oldStyle->imageResolution() != style().imageResolution()
|| oldStyle->imageResolutionSnap() != style().imageResolutionSnap()
|| oldStyle->imageResolutionSource() != style().imageResolutionSource()))
imageDimensionsChanged(true );
#endif
}
void RenderImage::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
{
if (documentBeingDestroyed() || document().inPageCache())
return;
if (hasBoxDecorations() || hasMask() || hasShapeOutside())
RenderReplaced::imageChanged(newImage, rect);
if (newImage != imageResource().imagePtr() || !newImage)
return;
if (!m_didIncrementVisuallyNonEmptyPixelCount) {
view().frameView().incrementVisuallyNonEmptyPixelCount(flooredIntSize(imageResource().imageSize(1.0f)));
m_didIncrementVisuallyNonEmptyPixelCount = true;
}
bool imageSizeChanged = false;
if (imageResource().errorOccurred()) {
if (!m_altText.isEmpty() && document().hasPendingStyleRecalc()) {
ASSERT(element());
if (element()) {
m_needsToSetSizeForAltText = true;
element()->setNeedsStyleRecalc(SyntheticStyleChange);
}
return;
}
imageSizeChanged = setImageSizeForAltText(imageResource().cachedImage());
}
imageDimensionsChanged(imageSizeChanged, rect);
}
bool RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize, bool imageSizeChanged)
{
if (newSize == intrinsicSize() && !imageSizeChanged)
return false;
if (imageResource().errorOccurred())
return imageSizeChanged;
setIntrinsicSize(newSize);
return true;
}
void RenderImage::updateInnerContentRect()
{
LayoutRect paintRect = replacedContentRect(intrinsicSize());
IntSize containerSize(paintRect.width(), paintRect.height());
if (!containerSize.isEmpty())
imageResource().setContainerSizeForRenderer(containerSize);
}
void RenderImage::imageDimensionsChanged(bool imageSizeChanged, const IntRect* rect)
{
#if ENABLE(CSS_IMAGE_RESOLUTION)
double scale = style().imageResolution();
if (style().imageResolutionSnap() == ImageResolutionSnapPixels)
scale = roundForImpreciseConversion<int>(scale);
if (scale <= 0)
scale = 1;
bool intrinsicSizeChanged = updateIntrinsicSizeIfNeeded(imageResource().intrinsicSize(style().effectiveZoom() / scale), imageSizeChanged);
#else
bool intrinsicSizeChanged = updateIntrinsicSizeIfNeeded(imageResource().intrinsicSize(style().effectiveZoom()), imageSizeChanged);
#endif
if (!containingBlock())
return;
bool shouldRepaint = true;
if (intrinsicSizeChanged) {
if (!preferredLogicalWidthsDirty())
setPreferredLogicalWidthsDirty(true);
bool hasOverrideSize = hasOverrideHeight() || hasOverrideWidth();
if (!hasOverrideSize && !imageSizeChanged) {
LogicalExtentComputedValues computedValues;
computeLogicalWidthInRegion(computedValues);
LayoutUnit newWidth = computedValues.m_extent;
computeLogicalHeight(height(), 0, computedValues);
LayoutUnit newHeight = computedValues.m_extent;
imageSizeChanged = width() != newWidth || height() != newHeight;
}
bool containingBlockNeedsToRecomputePreferredSize =
style().logicalWidth().isPercent()
|| style().logicalMaxWidth().isPercent()
|| style().logicalMinWidth().isPercent();
bool layoutSizeDependsOnIntrinsicSize = style().aspectRatioType() == AspectRatioFromIntrinsic;
if (imageSizeChanged || hasOverrideSize || containingBlockNeedsToRecomputePreferredSize || layoutSizeDependsOnIntrinsicSize) {
shouldRepaint = false;
if (!selfNeedsLayout())
setNeedsLayout();
}
if (everHadLayout() && !selfNeedsLayout()) {
updateInnerContentRect();
}
}
if (shouldRepaint) {
LayoutRect repaintRect;
if (rect) {
repaintRect = enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint(), imageResource().imageSize(1.0f)), contentBoxRect()));
repaintRect.intersect(contentBoxRect());
} else
repaintRect = contentBoxRect();
repaintRectangle(repaintRect);
contentChanged(ImageChanged);
}
}
void RenderImage::notifyFinished(CachedResource* newImage)
{
if (documentBeingDestroyed())
return;
invalidateBackgroundObscurationStatus();
if (newImage == imageResource().cachedImage()) {
contentChanged(ImageChanged);
}
}
void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
LayoutUnit cWidth = contentWidth();
LayoutUnit cHeight = contentHeight();
LayoutUnit leftBorder = borderLeft();
LayoutUnit topBorder = borderTop();
LayoutUnit leftPad = paddingLeft();
LayoutUnit topPad = paddingTop();
GraphicsContext* context = paintInfo.context;
float deviceScaleFactor = document().deviceScaleFactor();
Page* page = frame().page();
if (!imageResource().hasImage() || imageResource().errorOccurred()) {
if (paintInfo.phase == PaintPhaseSelection)
return;
if (page && paintInfo.phase == PaintPhaseForeground)
page->addRelevantUnpaintedObject(this, visualOverflowRect());
if (cWidth > 2 && cHeight > 2) {
LayoutUnit borderWidth = LayoutUnit(1 / deviceScaleFactor);
context->setStrokeStyle(SolidStroke);
context->setStrokeColor(Color::lightGray, style().colorSpace());
context->setFillColor(Color::transparent, style().colorSpace());
context->drawRect(pixelSnappedForPainting(LayoutRect(paintOffset.x() + leftBorder + leftPad, paintOffset.y() + topBorder + topPad, cWidth, cHeight), deviceScaleFactor), borderWidth);
bool errorPictureDrawn = false;
LayoutSize imageOffset;
LayoutUnit usableWidth = cWidth - 2 * borderWidth;
LayoutUnit usableHeight = cHeight - 2 * borderWidth;
RefPtr<Image> image = imageResource().image();
if (imageResource().errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
std::pair<Image*, float> brokenImageAndImageScaleFactor = imageResource().cachedImage()->brokenImage(document().deviceScaleFactor());
image = brokenImageAndImageScaleFactor.first;
FloatSize imageSize = image->size();
imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
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);
ImageOrientationDescription orientationDescription(shouldRespectImageOrientation());
#if ENABLE(CSS_IMAGE_ORIENTATION)
orientationDescription.setImageOrientationEnum(style().imageOrientation());
#endif
context->drawImage(image.get(), style().colorSpace(), pixelSnappedForPainting(LayoutRect(paintOffset + imageOffset, imageSize), deviceScaleFactor), orientationDescription);
errorPictureDrawn = true;
}
if (!m_altText.isEmpty()) {
String text = document().displayStringModifiedByEncoding(m_altText);
context->setFillColor(style().visitedDependentColor(CSSPropertyColor), style().colorSpace());
const Font& font = style().font();
const FontMetrics& fontMetrics = font.fontMetrics();
LayoutUnit ascent = fontMetrics.ascent();
LayoutPoint altTextOffset = paintOffset;
altTextOffset.move(leftBorder + leftPad + (paddingWidth / 2) - borderWidth, topBorder + topPad + ascent + (paddingHeight / 2) - borderWidth);
TextRun textRun = RenderBlock::constructTextRun(this, font, text, style());
LayoutUnit textWidth = font.width(textRun);
if (errorPictureDrawn) {
if (usableWidth >= textWidth && fontMetrics.height() <= imageOffset.height())
context->drawText(font, textRun, altTextOffset);
} else if (usableWidth >= textWidth && usableHeight >= fontMetrics.height())
context->drawText(font, textRun, altTextOffset);
}
}
} else if (imageResource().hasImage() && cWidth > 0 && cHeight > 0) {
RefPtr<Image> img = imageResource().image(cWidth, cHeight);
if (!img || img->isNull()) {
if (page && paintInfo.phase == PaintPhaseForeground)
page->addRelevantUnpaintedObject(this, visualOverflowRect());
return;
}
LayoutRect contentRect = contentBoxRect();
contentRect.moveBy(paintOffset);
LayoutRect paintRect = replacedContentRect(intrinsicSize());
paintRect.moveBy(paintOffset);
bool clip = !contentRect.contains(paintRect);
GraphicsContextStateSaver stateSaver(*context, clip);
if (clip)
context->clip(contentRect);
paintIntoRect(context, pixelSnappedForPainting(paintRect, deviceScaleFactor));
if (cachedImage() && page && paintInfo.phase == PaintPhaseForeground) {
LayoutRect visibleRect = intersection(paintRect, contentRect);
if (cachedImage()->isLoading())
page->addRelevantUnpaintedObject(this, visibleRect);
else
page->addRelevantRepaintedObject(this, visibleRect);
}
}
}
void RenderImage::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
RenderReplaced::paint(paintInfo, paintOffset);
if (paintInfo.phase == PaintPhaseOutline)
paintAreaElementFocusRing(paintInfo);
}
void RenderImage::paintAreaElementFocusRing(PaintInfo& paintInfo)
{
#if PLATFORM(IOS)
UNUSED_PARAM(paintInfo);
#else
if (document().printing() || !frame().selection().isFocusedAndActive())
return;
if (paintInfo.context->paintingDisabled() && !paintInfo.context->updatingControlTints())
return;
Element* focusedElement = document().focusedElement();
if (!focusedElement || !isHTMLAreaElement(focusedElement))
return;
HTMLAreaElement* areaElement = toHTMLAreaElement(focusedElement);
if (areaElement->imageElement() != element())
return;
Path path = areaElement->computePath(this);
if (path.isEmpty())
return;
RenderStyle* areaElementStyle = areaElement->computedStyle();
unsigned short outlineWidth = areaElementStyle->outlineWidth();
if (!outlineWidth)
return;
paintInfo.context->drawFocusRing(path, outlineWidth,
areaElementStyle->outlineOffset(),
areaElementStyle->visitedDependentColor(CSSPropertyOutlineColor));
#endif
}
void RenderImage::areaElementFocusChanged(HTMLAreaElement* element)
{
ASSERT_UNUSED(element, element->imageElement() == this->element());
repaint();
}
void RenderImage::paintIntoRect(GraphicsContext* context, const FloatRect& rect)
{
if (!imageResource().hasImage() || imageResource().errorOccurred() || rect.width() <= 0 || rect.height() <= 0)
return;
RefPtr<Image> img = imageResource().image(rect.width(), rect.height());
if (!img || img->isNull())
return;
HTMLImageElement* imageElt = (element() && isHTMLImageElement(element())) ? toHTMLImageElement(element()) : 0;
CompositeOperator compositeOperator = imageElt ? imageElt->compositeOperator() : CompositeSourceOver;
Image* image = imageResource().image().get();
bool useLowQualityScaling = shouldPaintAtLowQuality(context, image, image, LayoutSize(rect.size()));
ImageOrientationDescription orientationDescription(shouldRespectImageOrientation());
#if ENABLE(CSS_IMAGE_ORIENTATION)
orientationDescription.setImageOrientationEnum(style().imageOrientation());
#endif
context->drawImage(imageResource().image(rect.width(), rect.height()).get(), style().colorSpace(), rect,
ImagePaintingOptions(compositeOperator, BlendModeNormal, orientationDescription, useLowQualityScaling));
}
bool RenderImage::boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance bleedAvoidance, InlineFlowBox*) const
{
if (!RenderBoxModelObject::boxShadowShouldBeAppliedToBackground(bleedAvoidance))
return false;
return !const_cast<RenderImage*>(this)->backgroundIsKnownToBeObscured();
}
bool RenderImage::foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const
{
UNUSED_PARAM(maxDepthToTest);
if (!imageResource().hasImage() || imageResource().errorOccurred())
return false;
if (imageResource().cachedImage() && !imageResource().cachedImage()->isLoaded())
return false;
if (!contentBoxRect().contains(localRect))
return false;
EFillBox backgroundClip = style().backgroundClip();
if (backgroundClip == BorderFillBox && style().hasBorder() && !borderObscuresBackground())
return false;
if ((backgroundClip == BorderFillBox || backgroundClip == PaddingFillBox) && style().hasPadding())
return false;
ObjectFit objectFit = style().objectFit();
if (objectFit != ObjectFitFill && objectFit != ObjectFitCover)
return false;
return imageResource().cachedImage() && imageResource().cachedImage()->currentFrameKnownToBeOpaque(this);
}
bool RenderImage::computeBackgroundIsKnownToBeObscured()
{
if (!hasBackground())
return false;
LayoutRect paintedExtent;
if (!getBackgroundPaintedExtent(paintedExtent))
return false;
return foregroundIsKnownToBeOpaqueInRect(paintedExtent, 0);
}
LayoutUnit RenderImage::minimumReplacedHeight() const
{
return imageResource().errorOccurred() ? intrinsicSize().height() : LayoutUnit();
}
HTMLMapElement* RenderImage::imageMap() const
{
HTMLImageElement* i = element() && isHTMLImageElement(element()) ? toHTMLImageElement(element()) : 0;
return i ? i->treeScope().getImageMap(i->fastGetAttribute(usemapAttr)) : 0;
}
bool RenderImage::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
{
HitTestResult tempResult(result.hitTestLocation());
bool inside = RenderReplaced::nodeAtPoint(request, tempResult, locationInContainer, accumulatedOffset, hitTestAction);
if (tempResult.innerNode() && element()) {
if (HTMLMapElement* map = imageMap()) {
LayoutRect contentBox = contentBoxRect();
float scaleFactor = 1 / style().effectiveZoom();
LayoutPoint mapLocation = locationInContainer.point() - toLayoutSize(accumulatedOffset) - locationOffset() - toLayoutSize(contentBox.location());
mapLocation.scale(scaleFactor, scaleFactor);
if (map->mapMouseEvent(mapLocation, contentBox.size(), tempResult))
tempResult.setInnerNonSharedNode(element());
}
}
if (!inside && result.isRectBasedTest())
result.append(tempResult);
if (inside)
result = tempResult;
return inside;
}
void RenderImage::updateAltText()
{
if (!element())
return;
if (isHTMLInputElement(element()))
m_altText = toHTMLInputElement(element())->altText();
else if (isHTMLImageElement(element()))
m_altText = toHTMLImageElement(element())->altText();
}
bool RenderImage::canHaveChildren() const
{
#if !ENABLE(SERVICE_CONTROLS)
return false;
#else
return m_hasShadowControls;
#endif
}
void RenderImage::layout()
{
StackStats::LayoutCheckPoint layoutCheckPoint;
LayoutSize oldSize = contentBoxRect().size();
RenderReplaced::layout();
updateInnerContentRect();
if (m_hasShadowControls)
layoutShadowControls(oldSize);
}
void RenderImage::layoutShadowControls(const LayoutSize& oldSize)
{
RenderBox* controlsRenderer = toRenderBox(firstChild());
if (!controlsRenderer)
return;
bool controlsNeedLayout = controlsRenderer->needsLayout();
const RenderFlowThread* flowThread = flowThreadContainingBlock();
if (flowThread && !controlsNeedLayout) {
if (flowThread->pageLogicalSizeChanged())
controlsNeedLayout = true;
}
LayoutSize newSize = contentBoxRect().size();
if (newSize == oldSize && !controlsNeedLayout)
return;
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
if (shadowControlsNeedCustomLayoutMetrics()) {
controlsRenderer->setLocation(LayoutPoint(borderLeft(), borderTop()) + LayoutSize(paddingLeft(), paddingTop()));
controlsRenderer->style().setHeight(Length(newSize.height(), Fixed));
controlsRenderer->style().setWidth(Length(newSize.width(), Fixed));
}
controlsRenderer->setNeedsLayout(MarkOnlyThis);
controlsRenderer->layout();
clearChildNeedsLayout();
statePusher.pop();
}
void RenderImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const
{
RenderReplaced::computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio);
if (intrinsicSize.isEmpty() && (imageResource().imageHasRelativeWidth() || imageResource().imageHasRelativeHeight())) {
RenderObject* containingBlock = isOutOfFlowPositioned() ? container() : this->containingBlock();
if (containingBlock->isBox()) {
RenderBox* box = toRenderBox(containingBlock);
intrinsicSize.setWidth(box->availableLogicalWidth());
intrinsicSize.setHeight(box->availableLogicalHeight(IncludeMarginBorderPadding));
}
}
if (imageResource().errorOccurred()) {
intrinsicRatio = 1;
return;
}
}
bool RenderImage::needsPreferredWidthsRecalculation() const
{
if (RenderReplaced::needsPreferredWidthsRecalculation())
return true;
return embeddedContentBox();
}
RenderBox* RenderImage::embeddedContentBox() const
{
CachedImage* cachedImage = imageResource().cachedImage();
if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage())
return static_cast<SVGImage*>(cachedImage->image())->embeddedContentBox();
return 0;
}
}