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

Unified Diff: Source/core/css/CSSCrossfadeValue.cpp

Issue 1334713002: Check renderability of images in a (-webkit-)cross-fade before using (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update fixedSize() too; Add helper. Created 5 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
« no previous file with comments | « LayoutTests/css3/images/cross-fade-broken-image-expected.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSCrossfadeValue.cpp
diff --git a/Source/core/css/CSSCrossfadeValue.cpp b/Source/core/css/CSSCrossfadeValue.cpp
index 5afe76a4aa1152e353b0b620208c8ca86e232214..6a08597c000077f70590e70bd35d1cdfb3dbff9c 100644
--- a/Source/core/css/CSSCrossfadeValue.cpp
+++ b/Source/core/css/CSSCrossfadeValue.cpp
@@ -84,6 +84,18 @@ static ImageResource* cachedImageForCSSValue(CSSValue* value, Document* document
return 0;
}
+static Image* renderableImageForCSSValue(CSSValue* value, const LayoutObject* layoutObject)
+{
+ ImageResource* cachedImage = cachedImageForCSSValue(value, &layoutObject->document());
+
+ // If the image can be rendered at 1 zoom it will have non-empty dimension
+ // and should be able to render at other scales as well.
+ if (!cachedImage || !cachedImage->canRender(*layoutObject, 1))
+ return nullptr;
+
+ return cachedImage->imageForLayoutObject(layoutObject);
+}
+
CSSCrossfadeValue::~CSSCrossfadeValue()
{
if (m_cachedFromImage)
@@ -107,24 +119,23 @@ String CSSCrossfadeValue::customCSSText() const
IntSize CSSCrossfadeValue::fixedSize(const LayoutObject* layoutObject)
{
- float percentage = m_percentageValue->getFloatValue();
- float inversePercentage = 1 - percentage;
+ Image* fromImage = renderableImageForCSSValue(m_fromValue.get(), layoutObject);
+ Image* toImage = renderableImageForCSSValue(m_toValue.get(), layoutObject);
- Document* document = &layoutObject->document();
- ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), document);
- ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), document);
-
- if (!cachedFromImage || !cachedToImage)
+ if (!fromImage || !toImage)
return IntSize();
- IntSize fromImageSize = cachedFromImage->imageForLayoutObject(layoutObject)->size();
- IntSize toImageSize = cachedToImage->imageForLayoutObject(layoutObject)->size();
+ IntSize fromImageSize = fromImage->size();
+ IntSize toImageSize = toImage->size();
// Rounding issues can cause transitions between images of equal size to return
// a different fixed size; avoid performing the interpolation if the images are the same size.
if (fromImageSize == toImageSize)
return fromImageSize;
+ float percentage = m_percentageValue->getFloatValue();
+ float inversePercentage = 1 - percentage;
+
return IntSize(fromImageSize.width() * inversePercentage + toImageSize.width() * percentage,
fromImageSize.height() * inversePercentage + toImageSize.height() * percentage);
}
@@ -169,15 +180,8 @@ PassRefPtr<Image> CSSCrossfadeValue::image(LayoutObject* layoutObject, const Int
if (size.isEmpty())
return nullptr;
- Document* document = &layoutObject->document();
- ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), document);
- ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), document);
-
- if (!cachedFromImage || !cachedToImage)
- return Image::nullImage();
-
- Image* fromImage = cachedFromImage->imageForLayoutObject(layoutObject);
- Image* toImage = cachedToImage->imageForLayoutObject(layoutObject);
+ Image* fromImage = renderableImageForCSSValue(m_fromValue.get(), layoutObject);
+ Image* toImage = renderableImageForCSSValue(m_toValue.get(), layoutObject);
if (!fromImage || !toImage)
return Image::nullImage();
« no previous file with comments | « LayoutTests/css3/images/cross-fade-broken-image-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698