| 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 16 matching lines...) Expand all Loading... |
| 27 #include "core/css/CSSCrossfadeValue.h" | 27 #include "core/css/CSSCrossfadeValue.h" |
| 28 | 28 |
| 29 #include "core/css/CSSImageValue.h" | 29 #include "core/css/CSSImageValue.h" |
| 30 #include "core/layout/LayoutObject.h" | 30 #include "core/layout/LayoutObject.h" |
| 31 #include "core/style/StyleFetchedImage.h" | 31 #include "core/style/StyleFetchedImage.h" |
| 32 #include "platform/graphics/CrossfadeGeneratedImage.h" | 32 #include "platform/graphics/CrossfadeGeneratedImage.h" |
| 33 #include "wtf/text/StringBuilder.h" | 33 #include "wtf/text/StringBuilder.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 static bool subimageIsPending(CSSValue* value) | 37 static bool subimageIsPending(CSSValue value) |
| 38 { | 38 { |
| 39 if (value->isImageValue()) | 39 if (value.isImageValue()) |
| 40 return toCSSImageValue(value)->cachedOrPendingImage()->isPendingImage(); | 40 return toCSSImageValue(value).cachedOrPendingImage()->isPendingImage(); |
| 41 | 41 |
| 42 if (value->isImageGeneratorValue()) | 42 if (value.isImageGeneratorValue()) |
| 43 return toCSSImageGeneratorValue(value)->isPending(); | 43 return toCSSImageGeneratorValue(value).isPending(); |
| 44 | 44 |
| 45 ASSERT_NOT_REACHED(); | 45 ASSERT_NOT_REACHED(); |
| 46 | 46 |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 static bool subimageKnownToBeOpaque(CSSValue* value, const LayoutObject* layoutO
bject) | 50 static bool subimageKnownToBeOpaque(CSSValue value, const LayoutObject* layoutOb
ject) |
| 51 { | 51 { |
| 52 if (value->isImageValue()) | 52 if (value.isImageValue()) |
| 53 return toCSSImageValue(value)->knownToBeOpaque(layoutObject); | 53 return toCSSImageValue(value).knownToBeOpaque(layoutObject); |
| 54 | 54 |
| 55 if (value->isImageGeneratorValue()) | 55 if (value.isImageGeneratorValue()) |
| 56 return toCSSImageGeneratorValue(value)->knownToBeOpaque(layoutObject); | 56 return toCSSImageGeneratorValue(value).knownToBeOpaque(layoutObject); |
| 57 | 57 |
| 58 ASSERT_NOT_REACHED(); | 58 ASSERT_NOT_REACHED(); |
| 59 | 59 |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 | 62 |
| 63 static ImageResource* cachedImageForCSSValue(CSSValue* value, Document* document
) | 63 static ImageResource* cachedImageForCSSValue(CSSValue value, Document* document) |
| 64 { | 64 { |
| 65 if (!value) | 65 if (value.isImageValue()) { |
| 66 return 0; | 66 StyleFetchedImage* styleImageResource = toCSSImageValue(value).cachedIma
ge(document); |
| 67 | |
| 68 if (value->isImageValue()) { | |
| 69 StyleFetchedImage* styleImageResource = toCSSImageValue(value)->cachedIm
age(document); | |
| 70 if (!styleImageResource) | 67 if (!styleImageResource) |
| 71 return 0; | 68 return 0; |
| 72 | 69 |
| 73 return styleImageResource->cachedImage(); | 70 return styleImageResource->cachedImage(); |
| 74 } | 71 } |
| 75 | 72 |
| 76 if (value->isImageGeneratorValue()) { | 73 if (value.isImageGeneratorValue()) { |
| 77 toCSSImageGeneratorValue(value)->loadSubimages(document); | 74 toCSSImageGeneratorValue(value).loadSubimages(document); |
| 78 // FIXME: Handle CSSImageGeneratorValue (and thus cross-fades with gradi
ents and canvas). | 75 // FIXME: Handle CSSImageGeneratorValue (and thus cross-fades with gradi
ents and canvas). |
| 79 return 0; | 76 return 0; |
| 80 } | 77 } |
| 81 | 78 |
| 82 ASSERT_NOT_REACHED(); | 79 ASSERT_NOT_REACHED(); |
| 83 | 80 |
| 84 return 0; | 81 return 0; |
| 85 } | 82 } |
| 86 | 83 |
| 87 CSSCrossfadeValue::~CSSCrossfadeValue() | 84 CSSCrossfadeValue::~CSSCrossfadeValue() |
| 88 { | 85 { |
| 89 if (m_cachedFromImage) | 86 if (m_cachedFromImage) |
| 90 m_cachedFromImage->removeClient(&m_crossfadeSubimageObserver); | 87 m_cachedFromImage->removeClient(&m_crossfadeSubimageObserver); |
| 91 if (m_cachedToImage) | 88 if (m_cachedToImage) |
| 92 m_cachedToImage->removeClient(&m_crossfadeSubimageObserver); | 89 m_cachedToImage->removeClient(&m_crossfadeSubimageObserver); |
| 93 } | 90 } |
| 94 | 91 |
| 95 String CSSCrossfadeValue::customCSSText() const | 92 String CSSCrossfadeValue::customCSSText() const |
| 96 { | 93 { |
| 97 StringBuilder result; | 94 StringBuilder result; |
| 98 result.appendLiteral("-webkit-cross-fade("); | 95 result.appendLiteral("-webkit-cross-fade("); |
| 99 result.append(m_fromValue->cssText()); | 96 result.append(m_fromValue.cssText()); |
| 100 result.appendLiteral(", "); | 97 result.appendLiteral(", "); |
| 101 result.append(m_toValue->cssText()); | 98 result.append(m_toValue.cssText()); |
| 102 result.appendLiteral(", "); | 99 result.appendLiteral(", "); |
| 103 result.append(m_percentageValue->cssText()); | 100 result.append(m_percentageValue->cssText()); |
| 104 result.append(')'); | 101 result.append(')'); |
| 105 return result.toString(); | 102 return result.toString(); |
| 106 } | 103 } |
| 107 | 104 |
| 108 IntSize CSSCrossfadeValue::fixedSize(const LayoutObject* layoutObject) | 105 IntSize CSSCrossfadeValue::fixedSize(const LayoutObject* layoutObject) |
| 109 { | 106 { |
| 110 float percentage = m_percentageValue->getFloatValue(); | 107 float percentage = m_percentageValue->getFloatValue(); |
| 111 float inversePercentage = 1 - percentage; | 108 float inversePercentage = 1 - percentage; |
| 112 | 109 |
| 113 Document* document = &layoutObject->document(); | 110 Document* document = &layoutObject->document(); |
| 114 ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), d
ocument); | 111 ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue, documen
t); |
| 115 ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), docum
ent); | 112 ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue, document); |
| 116 | 113 |
| 117 if (!cachedFromImage || !cachedToImage) | 114 if (!cachedFromImage || !cachedToImage) |
| 118 return IntSize(); | 115 return IntSize(); |
| 119 | 116 |
| 120 IntSize fromImageSize = cachedFromImage->imageForLayoutObject(layoutObject)-
>size(); | 117 IntSize fromImageSize = cachedFromImage->imageForLayoutObject(layoutObject)-
>size(); |
| 121 IntSize toImageSize = cachedToImage->imageForLayoutObject(layoutObject)->siz
e(); | 118 IntSize toImageSize = cachedToImage->imageForLayoutObject(layoutObject)->siz
e(); |
| 122 | 119 |
| 123 // Rounding issues can cause transitions between images of equal size to ret
urn | 120 // 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. | 121 // a different fixed size; avoid performing the interpolation if the images
are the same size. |
| 125 if (fromImageSize == toImageSize) | 122 if (fromImageSize == toImageSize) |
| 126 return fromImageSize; | 123 return fromImageSize; |
| 127 | 124 |
| 128 return IntSize(fromImageSize.width() * inversePercentage + toImageSize.width
() * percentage, | 125 return IntSize(fromImageSize.width() * inversePercentage + toImageSize.width
() * percentage, |
| 129 fromImageSize.height() * inversePercentage + toImageSize.height() * perc
entage); | 126 fromImageSize.height() * inversePercentage + toImageSize.height() * perc
entage); |
| 130 } | 127 } |
| 131 | 128 |
| 132 bool CSSCrossfadeValue::isPending() const | 129 bool CSSCrossfadeValue::isPending() const |
| 133 { | 130 { |
| 134 return subimageIsPending(m_fromValue.get()) || subimageIsPending(m_toValue.g
et()); | 131 return subimageIsPending(m_fromValue) || subimageIsPending(m_toValue); |
| 135 } | 132 } |
| 136 | 133 |
| 137 bool CSSCrossfadeValue::knownToBeOpaque(const LayoutObject* layoutObject) const | 134 bool CSSCrossfadeValue::knownToBeOpaque(const LayoutObject* layoutObject) const |
| 138 { | 135 { |
| 139 return subimageKnownToBeOpaque(m_fromValue.get(), layoutObject) && subimageK
nownToBeOpaque(m_toValue.get(), layoutObject); | 136 return subimageKnownToBeOpaque(m_fromValue, layoutObject) && subimageKnownTo
BeOpaque(m_toValue, layoutObject); |
| 140 } | 137 } |
| 141 | 138 |
| 142 void CSSCrossfadeValue::loadSubimages(Document* document) | 139 void CSSCrossfadeValue::loadSubimages(Document* document) |
| 143 { | 140 { |
| 144 ResourcePtr<ImageResource> oldCachedFromImage = m_cachedFromImage; | 141 ResourcePtr<ImageResource> oldCachedFromImage = m_cachedFromImage; |
| 145 ResourcePtr<ImageResource> oldCachedToImage = m_cachedToImage; | 142 ResourcePtr<ImageResource> oldCachedToImage = m_cachedToImage; |
| 146 | 143 |
| 147 m_cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), document); | 144 m_cachedFromImage = cachedImageForCSSValue(m_fromValue, document); |
| 148 m_cachedToImage = cachedImageForCSSValue(m_toValue.get(), document); | 145 m_cachedToImage = cachedImageForCSSValue(m_toValue, document); |
| 149 | 146 |
| 150 if (m_cachedFromImage != oldCachedFromImage) { | 147 if (m_cachedFromImage != oldCachedFromImage) { |
| 151 if (oldCachedFromImage) | 148 if (oldCachedFromImage) |
| 152 oldCachedFromImage->removeClient(&m_crossfadeSubimageObserver); | 149 oldCachedFromImage->removeClient(&m_crossfadeSubimageObserver); |
| 153 if (m_cachedFromImage) | 150 if (m_cachedFromImage) |
| 154 m_cachedFromImage->addClient(&m_crossfadeSubimageObserver); | 151 m_cachedFromImage->addClient(&m_crossfadeSubimageObserver); |
| 155 } | 152 } |
| 156 | 153 |
| 157 if (m_cachedToImage != oldCachedToImage) { | 154 if (m_cachedToImage != oldCachedToImage) { |
| 158 if (oldCachedToImage) | 155 if (oldCachedToImage) |
| 159 oldCachedToImage->removeClient(&m_crossfadeSubimageObserver); | 156 oldCachedToImage->removeClient(&m_crossfadeSubimageObserver); |
| 160 if (m_cachedToImage) | 157 if (m_cachedToImage) |
| 161 m_cachedToImage->addClient(&m_crossfadeSubimageObserver); | 158 m_cachedToImage->addClient(&m_crossfadeSubimageObserver); |
| 162 } | 159 } |
| 163 | 160 |
| 164 m_crossfadeSubimageObserver.setReady(true); | 161 m_crossfadeSubimageObserver.setReady(true); |
| 165 } | 162 } |
| 166 | 163 |
| 167 PassRefPtr<Image> CSSCrossfadeValue::image(LayoutObject* layoutObject, const Int
Size& size) | 164 PassRefPtr<Image> CSSCrossfadeValue::image(LayoutObject* layoutObject, const Int
Size& size) |
| 168 { | 165 { |
| 169 if (size.isEmpty()) | 166 if (size.isEmpty()) |
| 170 return nullptr; | 167 return nullptr; |
| 171 | 168 |
| 172 Document* document = &layoutObject->document(); | 169 Document* document = &layoutObject->document(); |
| 173 ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), d
ocument); | 170 ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue, documen
t); |
| 174 ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), docum
ent); | 171 ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue, document); |
| 175 | 172 |
| 176 if (!cachedFromImage || !cachedToImage) | 173 if (!cachedFromImage || !cachedToImage) |
| 177 return Image::nullImage(); | 174 return Image::nullImage(); |
| 178 | 175 |
| 179 Image* fromImage = cachedFromImage->imageForLayoutObject(layoutObject); | 176 Image* fromImage = cachedFromImage->imageForLayoutObject(layoutObject); |
| 180 Image* toImage = cachedToImage->imageForLayoutObject(layoutObject); | 177 Image* toImage = cachedToImage->imageForLayoutObject(layoutObject); |
| 181 | 178 |
| 182 if (!fromImage || !toImage) | 179 if (!fromImage || !toImage) |
| 183 return Image::nullImage(); | 180 return Image::nullImage(); |
| 184 | 181 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 205 { | 202 { |
| 206 if (m_cachedFromImage && m_cachedFromImage->loadFailedOrCanceled()) | 203 if (m_cachedFromImage && m_cachedFromImage->loadFailedOrCanceled()) |
| 207 return true; | 204 return true; |
| 208 if (m_cachedToImage && m_cachedToImage->loadFailedOrCanceled()) | 205 if (m_cachedToImage && m_cachedToImage->loadFailedOrCanceled()) |
| 209 return true; | 206 return true; |
| 210 return false; | 207 return false; |
| 211 } | 208 } |
| 212 | 209 |
| 213 bool CSSCrossfadeValue::equals(const CSSCrossfadeValue& other) const | 210 bool CSSCrossfadeValue::equals(const CSSCrossfadeValue& other) const |
| 214 { | 211 { |
| 215 return compareCSSValuePtr(m_fromValue, other.m_fromValue) | 212 return m_fromValue.equals(other.m_fromValue) |
| 216 && compareCSSValuePtr(m_toValue, other.m_toValue) | 213 && m_toValue.equals(other.m_toValue) |
| 217 && compareCSSValuePtr(m_percentageValue, other.m_percentageValue); | 214 && compareCSSValuePtr(m_percentageValue, other.m_percentageValue); |
| 218 } | 215 } |
| 219 | 216 |
| 220 DEFINE_TRACE_AFTER_DISPATCH(CSSCrossfadeValue) | 217 DEFINE_TRACE_AFTER_DISPATCH(CSSCrossfadeValue) |
| 221 { | 218 { |
| 222 visitor->trace(m_fromValue); | 219 visitor->trace(m_fromValue); |
| 223 visitor->trace(m_toValue); | 220 visitor->trace(m_toValue); |
| 224 visitor->trace(m_percentageValue); | 221 visitor->trace(m_percentageValue); |
| 225 CSSImageGeneratorValue::traceAfterDispatch(visitor); | 222 CSSImageGeneratorValue::traceAfterDispatch(visitor); |
| 226 } | 223 } |
| 227 | 224 |
| 228 } // namespace blink | 225 } // namespace blink |
| OLD | NEW |