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

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, 1 month 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
Index: Source/core/rendering/RenderImage.cpp
diff --git a/Source/core/rendering/RenderImage.cpp b/Source/core/rendering/RenderImage.cpp
index d22459a9c54785fc6be3fd635bcf7a07354f191a..24d11ab9aeac21239da827cc896c98a71b13f2b6 100644
--- a/Source/core/rendering/RenderImage.cpp
+++ b/Source/core/rendering/RenderImage.cpp
@@ -60,7 +60,6 @@ RenderImage::RenderImage(Element* element)
, m_isGeneratedContent(false)
, m_imageDevicePixelRatio(1.0f)
{
- updateAltText();
ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->addRenderObject(this);
}
@@ -89,58 +88,6 @@ void RenderImage::setImageResource(PassOwnPtr<RenderImageResource> imageResource
m_imageResource->initialize(this);
}
-// 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())
@@ -166,13 +113,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)
@@ -191,7 +132,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());
@@ -204,7 +145,7 @@ void RenderImage::paintInvalidationOrMarkForLayout(bool imageSizeChangedToAccomo
if (!containingBlock())
return;
- bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize || imageSizeChangedToAccomodateAltText;
+ bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize;
if (imageSourceHasChangedSize)
setPreferredLogicalWidthsDirty();
@@ -300,7 +241,7 @@ void RenderImage::areaElementFocusChanged(HTMLAreaElement* areaElement)
paintInvalidationRect.moveBy(-absoluteContentBox().location());
paintInvalidationRect.inflate(outlineWidth);
- paintInvalidationOrMarkForLayout(false, &paintInvalidationRect);
+ repaintOrMarkForLayout(&paintInvalidationRect);
}
bool RenderImage::boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance bleedAvoidance, InlineFlowBox*) const
@@ -383,17 +324,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()
{
RenderReplaced::layout();

Powered by Google App Engine
This is Rietveld 408576698