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

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 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 e36c6f741e42b9570faa6ac60cdb5c6f87daabce..8e79299b78be056a39916d97ea90e4b8c768d33e 100644
--- a/Source/core/rendering/RenderImage.cpp
+++ b/Source/core/rendering/RenderImage.cpp
@@ -59,7 +59,6 @@ RenderImage::RenderImage(Element* element)
, m_isGeneratedContent(false)
, m_imageDevicePixelRatio(1.0f)
{
- updateAltText();
ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->addRenderObject(this);
}
@@ -88,59 +87,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 */)
-{
- LayoutSize imageSize;
- if (newImage && newImage->imageForRenderer(this)) {
- imageSize = LayoutSize(imageSizeForError(newImage));
- } else if (!m_altText.isEmpty() || newImage) {
- // If we'll be displaying either text or an image, add a little padding.
- imageSize = LayoutSize(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();
- LayoutSize 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 +112,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 +131,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 +144,7 @@ void RenderImage::paintInvalidationOrMarkForLayout(bool imageSizeChangedToAccomo
if (!containingBlock())
return;
- bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize || imageSizeChangedToAccomodateAltText;
+ bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize;
if (imageSourceHasChangedSize)
setPreferredLogicalWidthsDirty();
@@ -295,7 +235,7 @@ void RenderImage::areaElementFocusChanged(HTMLAreaElement* areaElement)
paintInvalidationRect.moveBy(-IntPoint(absoluteContentBoxOffset()));
paintInvalidationRect.inflate(outlineWidth);
- paintInvalidationOrMarkForLayout(false, &paintInvalidationRect);
+ repaintOrMarkForLayout(&paintInvalidationRect);
}
bool RenderImage::boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance bleedAvoidance, InlineFlowBox*) const
@@ -378,17 +318,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