| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 toCSSImageGeneratorValue(value)->loadSubimages(document); | 77 toCSSImageGeneratorValue(value)->loadSubimages(document); |
| 78 // FIXME: Handle CSSImageGeneratorValue (and thus cross-fades with gradi
ents and canvas). | 78 // FIXME: Handle CSSImageGeneratorValue (and thus cross-fades with gradi
ents and canvas). |
| 79 return 0; | 79 return 0; |
| 80 } | 80 } |
| 81 | 81 |
| 82 ASSERT_NOT_REACHED(); | 82 ASSERT_NOT_REACHED(); |
| 83 | 83 |
| 84 return 0; | 84 return 0; |
| 85 } | 85 } |
| 86 | 86 |
| 87 static Image* renderableImageForCSSValue(CSSValue* value, const LayoutObject* la
youtObject) |
| 88 { |
| 89 ImageResource* cachedImage = cachedImageForCSSValue(value, &layoutObject->do
cument()); |
| 90 |
| 91 // If the image can be rendered at 1 zoom it will have non-empty dimension |
| 92 // and should be able to render at other scales as well. |
| 93 if (!cachedImage || !cachedImage->canRender(*layoutObject, 1)) |
| 94 return nullptr; |
| 95 |
| 96 return cachedImage->imageForLayoutObject(layoutObject); |
| 97 } |
| 98 |
| 87 CSSCrossfadeValue::~CSSCrossfadeValue() | 99 CSSCrossfadeValue::~CSSCrossfadeValue() |
| 88 { | 100 { |
| 89 if (m_cachedFromImage) | 101 if (m_cachedFromImage) |
| 90 m_cachedFromImage->removeClient(&m_crossfadeSubimageObserver); | 102 m_cachedFromImage->removeClient(&m_crossfadeSubimageObserver); |
| 91 if (m_cachedToImage) | 103 if (m_cachedToImage) |
| 92 m_cachedToImage->removeClient(&m_crossfadeSubimageObserver); | 104 m_cachedToImage->removeClient(&m_crossfadeSubimageObserver); |
| 93 } | 105 } |
| 94 | 106 |
| 95 String CSSCrossfadeValue::customCSSText() const | 107 String CSSCrossfadeValue::customCSSText() const |
| 96 { | 108 { |
| 97 StringBuilder result; | 109 StringBuilder result; |
| 98 result.appendLiteral("-webkit-cross-fade("); | 110 result.appendLiteral("-webkit-cross-fade("); |
| 99 result.append(m_fromValue->cssText()); | 111 result.append(m_fromValue->cssText()); |
| 100 result.appendLiteral(", "); | 112 result.appendLiteral(", "); |
| 101 result.append(m_toValue->cssText()); | 113 result.append(m_toValue->cssText()); |
| 102 result.appendLiteral(", "); | 114 result.appendLiteral(", "); |
| 103 result.append(m_percentageValue->cssText()); | 115 result.append(m_percentageValue->cssText()); |
| 104 result.append(')'); | 116 result.append(')'); |
| 105 return result.toString(); | 117 return result.toString(); |
| 106 } | 118 } |
| 107 | 119 |
| 108 IntSize CSSCrossfadeValue::fixedSize(const LayoutObject* layoutObject) | 120 IntSize CSSCrossfadeValue::fixedSize(const LayoutObject* layoutObject) |
| 109 { | 121 { |
| 110 float percentage = m_percentageValue->getFloatValue(); | 122 Image* fromImage = renderableImageForCSSValue(m_fromValue.get(), layoutObjec
t); |
| 111 float inversePercentage = 1 - percentage; | 123 Image* toImage = renderableImageForCSSValue(m_toValue.get(), layoutObject); |
| 112 | 124 |
| 113 Document* document = &layoutObject->document(); | 125 if (!fromImage || !toImage) |
| 114 ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), d
ocument); | |
| 115 ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), docum
ent); | |
| 116 | |
| 117 if (!cachedFromImage || !cachedToImage) | |
| 118 return IntSize(); | 126 return IntSize(); |
| 119 | 127 |
| 120 IntSize fromImageSize = cachedFromImage->imageForLayoutObject(layoutObject)-
>size(); | 128 IntSize fromImageSize = fromImage->size(); |
| 121 IntSize toImageSize = cachedToImage->imageForLayoutObject(layoutObject)->siz
e(); | 129 IntSize toImageSize = toImage->size(); |
| 122 | 130 |
| 123 // Rounding issues can cause transitions between images of equal size to ret
urn | 131 // Rounding issues can cause transitions between images of equal size to ret
urn |
| 124 // a different fixed size; avoid performing the interpolation if the images
are the same size. | 132 // a different fixed size; avoid performing the interpolation if the images
are the same size. |
| 125 if (fromImageSize == toImageSize) | 133 if (fromImageSize == toImageSize) |
| 126 return fromImageSize; | 134 return fromImageSize; |
| 127 | 135 |
| 136 float percentage = m_percentageValue->getFloatValue(); |
| 137 float inversePercentage = 1 - percentage; |
| 138 |
| 128 return IntSize(fromImageSize.width() * inversePercentage + toImageSize.width
() * percentage, | 139 return IntSize(fromImageSize.width() * inversePercentage + toImageSize.width
() * percentage, |
| 129 fromImageSize.height() * inversePercentage + toImageSize.height() * perc
entage); | 140 fromImageSize.height() * inversePercentage + toImageSize.height() * perc
entage); |
| 130 } | 141 } |
| 131 | 142 |
| 132 bool CSSCrossfadeValue::isPending() const | 143 bool CSSCrossfadeValue::isPending() const |
| 133 { | 144 { |
| 134 return subimageIsPending(m_fromValue.get()) || subimageIsPending(m_toValue.g
et()); | 145 return subimageIsPending(m_fromValue.get()) || subimageIsPending(m_toValue.g
et()); |
| 135 } | 146 } |
| 136 | 147 |
| 137 bool CSSCrossfadeValue::knownToBeOpaque(const LayoutObject* layoutObject) const | 148 bool CSSCrossfadeValue::knownToBeOpaque(const LayoutObject* layoutObject) const |
| (...skipping 24 matching lines...) Expand all Loading... |
| 162 } | 173 } |
| 163 | 174 |
| 164 m_crossfadeSubimageObserver.setReady(true); | 175 m_crossfadeSubimageObserver.setReady(true); |
| 165 } | 176 } |
| 166 | 177 |
| 167 PassRefPtr<Image> CSSCrossfadeValue::image(LayoutObject* layoutObject, const Int
Size& size) | 178 PassRefPtr<Image> CSSCrossfadeValue::image(LayoutObject* layoutObject, const Int
Size& size) |
| 168 { | 179 { |
| 169 if (size.isEmpty()) | 180 if (size.isEmpty()) |
| 170 return nullptr; | 181 return nullptr; |
| 171 | 182 |
| 172 Document* document = &layoutObject->document(); | 183 Image* fromImage = renderableImageForCSSValue(m_fromValue.get(), layoutObjec
t); |
| 173 ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), d
ocument); | 184 Image* toImage = renderableImageForCSSValue(m_toValue.get(), layoutObject); |
| 174 ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), docum
ent); | |
| 175 | |
| 176 if (!cachedFromImage || !cachedToImage) | |
| 177 return Image::nullImage(); | |
| 178 | |
| 179 Image* fromImage = cachedFromImage->imageForLayoutObject(layoutObject); | |
| 180 Image* toImage = cachedToImage->imageForLayoutObject(layoutObject); | |
| 181 | 185 |
| 182 if (!fromImage || !toImage) | 186 if (!fromImage || !toImage) |
| 183 return Image::nullImage(); | 187 return Image::nullImage(); |
| 184 | 188 |
| 185 m_generatedImage = CrossfadeGeneratedImage::create(fromImage, toImage, m_per
centageValue->getFloatValue(), fixedSize(layoutObject), size); | 189 m_generatedImage = CrossfadeGeneratedImage::create(fromImage, toImage, m_per
centageValue->getFloatValue(), fixedSize(layoutObject), size); |
| 186 | 190 |
| 187 return m_generatedImage.release(); | 191 return m_generatedImage.release(); |
| 188 } | 192 } |
| 189 | 193 |
| 190 void CSSCrossfadeValue::crossfadeChanged(const IntRect&) | 194 void CSSCrossfadeValue::crossfadeChanged(const IntRect&) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 220 DEFINE_TRACE_AFTER_DISPATCH(CSSCrossfadeValue) | 224 DEFINE_TRACE_AFTER_DISPATCH(CSSCrossfadeValue) |
| 221 { | 225 { |
| 222 visitor->trace(m_fromValue); | 226 visitor->trace(m_fromValue); |
| 223 visitor->trace(m_toValue); | 227 visitor->trace(m_toValue); |
| 224 visitor->trace(m_percentageValue); | 228 visitor->trace(m_percentageValue); |
| 225 visitor->trace(m_crossfadeSubimageObserver); | 229 visitor->trace(m_crossfadeSubimageObserver); |
| 226 CSSImageGeneratorValue::traceAfterDispatch(visitor); | 230 CSSImageGeneratorValue::traceAfterDispatch(visitor); |
| 227 } | 231 } |
| 228 | 232 |
| 229 } // namespace blink | 233 } // namespace blink |
| OLD | NEW |