Remove StylePendingImage
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Aug 2016 15:06:19 +0000 (15:06 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Aug 2016 15:06:19 +0000 (15:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161245

Reviewed by Andreas Kling.

Instances of this confusing type are used as placeholders during style resolution.
We can get rid of it and make "pending" a state of StyleImage. This simplies the code and
will allow further improvements.

* WebCore.xcodeproj/project.pbxproj:
* css/CSSCrossfadeValue.cpp:
(WebCore::CSSCrossfadeValue::isPending):
(WebCore::CSSCrossfadeValue::blend):
* css/CSSCrossfadeValue.h:
* css/CSSCursorImageValue.cpp:
(WebCore::CSSCursorImageValue::CSSCursorImageValue):
(WebCore::CSSCursorImageValue::~CSSCursorImageValue):

    Save the original URL since the underlying CSSImageValue may change.

(WebCore::CSSCursorImageValue::updateCursorElement):
(WebCore::CSSCursorImageValue::cursorElementRemoved):
(WebCore::CSSCursorImageValue::cursorElementChanged):
(WebCore::CSSCursorImageValue::loadImage):
(WebCore::CSSCursorImageValue::styleImage):
(WebCore::CSSCursorImageValue::isSVGCursor):
(WebCore::CSSCursorImageValue::cachedImageURL):
(WebCore::CSSCursorImageValue::updateCachedImage):
(WebCore::CSSCursorImageValue::detachPendingImage): Deleted.
(WebCore::CSSCursorImageValue::cachedImage): Deleted.
(WebCore::CSSCursorImageValue::cachedOrPendingImage): Deleted.
(WebCore::CSSCursorImageValue::clearCachedImage): Deleted.
* css/CSSCursorImageValue.h:
* css/CSSFilterImageValue.cpp:
(WebCore::CSSFilterImageValue::isPending):
* css/CSSFilterImageValue.h:
* css/CSSImageGeneratorValue.cpp:
(WebCore::CSSImageGeneratorValue::isPending):
(WebCore::CSSImageGeneratorValue::subimageIsPending):
(WebCore::CSSImageGeneratorValue::cachedImageForCSSValue):
* css/CSSImageGeneratorValue.h:
* css/CSSImageSetValue.cpp:
(WebCore::CSSImageSetValue::~CSSImageSetValue):
(WebCore::CSSImageSetValue::loadBestFitImage):
(WebCore::CSSImageSetValue::styleImage):
(WebCore::CSSImageSetValue::traverseSubresources):
(WebCore::CSSImageSetValue::detachPendingImage): Deleted.
(WebCore::CSSImageSetValue::bestFitImage): Deleted.
(WebCore::CSSImageSetValue::cachedOrPendingImageSet): Deleted.
* css/CSSImageSetValue.h:
* css/CSSImageValue.cpp:
(WebCore::CSSImageValue::CSSImageValue):
(WebCore::CSSImageValue::~CSSImageValue):
(WebCore::CSSImageValue::isPending):
(WebCore::CSSImageValue::styleImage):
(WebCore::CSSImageValue::loadImage):
(WebCore::CSSImageValue::traverseSubresources):
(WebCore::CSSImageValue::detachPendingImage): Deleted.
(WebCore::CSSImageValue::cachedOrPendingImage): Deleted.
(WebCore::CSSImageValue::cachedImage): Deleted.
* css/CSSImageValue.h:
(WebCore::CSSImageValue::create):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::cachedOrPendingFromValue):
(WebCore::StyleResolver::generatedOrPendingFromValue):
(WebCore::StyleResolver::setOrPendingFromValue):
(WebCore::StyleResolver::cursorOrPendingFromValue):
* page/PageSerializer.cpp:
(WebCore::PageSerializer::retrieveResourcesForProperties):
* page/animation/CSSPropertyAnimation.cpp:
(WebCore::blendFilter):
(WebCore::crossfadeBlend):
* rendering/RenderImageResourceStyleImage.cpp:
(WebCore::RenderImageResourceStyleImage::image):
* rendering/shapes/ShapeOutsideInfo.cpp:
(WebCore::ShapeOutsideInfo::createShapeForImage):
* rendering/style/StyleCachedImage.cpp:
(WebCore::StyleCachedImage::StyleCachedImage):
(WebCore::StyleCachedImage::~StyleCachedImage):
(WebCore::StyleCachedImage::setCachedImage):
(WebCore::StyleCachedImage::cssValue):
(WebCore::StyleCachedImage::canRender):
(WebCore::StyleCachedImage::isPending):
(WebCore::StyleCachedImage::isLoaded):
(WebCore::StyleCachedImage::errorOccurred):
(WebCore::StyleCachedImage::imageSize):
(WebCore::StyleCachedImage::imageHasRelativeWidth):
(WebCore::StyleCachedImage::imageHasRelativeHeight):
(WebCore::StyleCachedImage::computeIntrinsicDimensions):
(WebCore::StyleCachedImage::usesImageContainerSize):
(WebCore::StyleCachedImage::setContainerSizeForRenderer):
(WebCore::StyleCachedImage::addClient):
(WebCore::StyleCachedImage::removeClient):
(WebCore::StyleCachedImage::image):
(WebCore::StyleCachedImage::knownToBeOpaque):
* rendering/style/StyleCachedImage.h:
* rendering/style/StyleGeneratedImage.cpp:
(WebCore::StyleGeneratedImage::isPending):
* rendering/style/StyleGeneratedImage.h:
* rendering/style/StyleImage.h:
(WebCore::StyleImage::isCachedImage):
(WebCore::StyleImage::StyleImage):
(WebCore::StyleImage::canRender): Deleted.
(WebCore::StyleImage::isPendingImage): Deleted.
* rendering/style/StylePendingImage.h: Removed.
* style/StylePendingResources.cpp:
(WebCore::Style::loadPendingImage):
(WebCore::Style::loadPendingImages):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205181 268f45cc-cd09-0410-ab3c-d52691b4dbfc

26 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSCrossfadeValue.cpp
Source/WebCore/css/CSSCrossfadeValue.h
Source/WebCore/css/CSSCursorImageValue.cpp
Source/WebCore/css/CSSCursorImageValue.h
Source/WebCore/css/CSSFilterImageValue.cpp
Source/WebCore/css/CSSFilterImageValue.h
Source/WebCore/css/CSSImageGeneratorValue.cpp
Source/WebCore/css/CSSImageGeneratorValue.h
Source/WebCore/css/CSSImageSetValue.cpp
Source/WebCore/css/CSSImageSetValue.h
Source/WebCore/css/CSSImageValue.cpp
Source/WebCore/css/CSSImageValue.h
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/page/PageSerializer.cpp
Source/WebCore/page/animation/CSSPropertyAnimation.cpp
Source/WebCore/rendering/RenderImageResourceStyleImage.cpp
Source/WebCore/rendering/shapes/ShapeOutsideInfo.cpp
Source/WebCore/rendering/style/StyleCachedImage.cpp
Source/WebCore/rendering/style/StyleCachedImage.h
Source/WebCore/rendering/style/StyleGeneratedImage.cpp
Source/WebCore/rendering/style/StyleGeneratedImage.h
Source/WebCore/rendering/style/StyleImage.h
Source/WebCore/rendering/style/StylePendingImage.h [deleted file]
Source/WebCore/style/StylePendingResources.cpp

index 0d198e2..d707ebf 100644 (file)
@@ -1,3 +1,114 @@
+2016-08-30  Antti Koivisto  <antti@apple.com>
+
+        Remove StylePendingImage
+        https://bugs.webkit.org/show_bug.cgi?id=161245
+
+        Reviewed by Andreas Kling.
+
+        Instances of this confusing type are used as placeholders during style resolution.
+        We can get rid of it and make "pending" a state of StyleImage. This simplies the code and
+        will allow further improvements.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSCrossfadeValue.cpp:
+        (WebCore::CSSCrossfadeValue::isPending):
+        (WebCore::CSSCrossfadeValue::blend):
+        * css/CSSCrossfadeValue.h:
+        * css/CSSCursorImageValue.cpp:
+        (WebCore::CSSCursorImageValue::CSSCursorImageValue):
+        (WebCore::CSSCursorImageValue::~CSSCursorImageValue):
+
+            Save the original URL since the underlying CSSImageValue may change.
+
+        (WebCore::CSSCursorImageValue::updateCursorElement):
+        (WebCore::CSSCursorImageValue::cursorElementRemoved):
+        (WebCore::CSSCursorImageValue::cursorElementChanged):
+        (WebCore::CSSCursorImageValue::loadImage):
+        (WebCore::CSSCursorImageValue::styleImage):
+        (WebCore::CSSCursorImageValue::isSVGCursor):
+        (WebCore::CSSCursorImageValue::cachedImageURL):
+        (WebCore::CSSCursorImageValue::updateCachedImage):
+        (WebCore::CSSCursorImageValue::detachPendingImage): Deleted.
+        (WebCore::CSSCursorImageValue::cachedImage): Deleted.
+        (WebCore::CSSCursorImageValue::cachedOrPendingImage): Deleted.
+        (WebCore::CSSCursorImageValue::clearCachedImage): Deleted.
+        * css/CSSCursorImageValue.h:
+        * css/CSSFilterImageValue.cpp:
+        (WebCore::CSSFilterImageValue::isPending):
+        * css/CSSFilterImageValue.h:
+        * css/CSSImageGeneratorValue.cpp:
+        (WebCore::CSSImageGeneratorValue::isPending):
+        (WebCore::CSSImageGeneratorValue::subimageIsPending):
+        (WebCore::CSSImageGeneratorValue::cachedImageForCSSValue):
+        * css/CSSImageGeneratorValue.h:
+        * css/CSSImageSetValue.cpp:
+        (WebCore::CSSImageSetValue::~CSSImageSetValue):
+        (WebCore::CSSImageSetValue::loadBestFitImage):
+        (WebCore::CSSImageSetValue::styleImage):
+        (WebCore::CSSImageSetValue::traverseSubresources):
+        (WebCore::CSSImageSetValue::detachPendingImage): Deleted.
+        (WebCore::CSSImageSetValue::bestFitImage): Deleted.
+        (WebCore::CSSImageSetValue::cachedOrPendingImageSet): Deleted.
+        * css/CSSImageSetValue.h:
+        * css/CSSImageValue.cpp:
+        (WebCore::CSSImageValue::CSSImageValue):
+        (WebCore::CSSImageValue::~CSSImageValue):
+        (WebCore::CSSImageValue::isPending):
+        (WebCore::CSSImageValue::styleImage):
+        (WebCore::CSSImageValue::loadImage):
+        (WebCore::CSSImageValue::traverseSubresources):
+        (WebCore::CSSImageValue::detachPendingImage): Deleted.
+        (WebCore::CSSImageValue::cachedOrPendingImage): Deleted.
+        (WebCore::CSSImageValue::cachedImage): Deleted.
+        * css/CSSImageValue.h:
+        (WebCore::CSSImageValue::create):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::cachedOrPendingFromValue):
+        (WebCore::StyleResolver::generatedOrPendingFromValue):
+        (WebCore::StyleResolver::setOrPendingFromValue):
+        (WebCore::StyleResolver::cursorOrPendingFromValue):
+        * page/PageSerializer.cpp:
+        (WebCore::PageSerializer::retrieveResourcesForProperties):
+        * page/animation/CSSPropertyAnimation.cpp:
+        (WebCore::blendFilter):
+        (WebCore::crossfadeBlend):
+        * rendering/RenderImageResourceStyleImage.cpp:
+        (WebCore::RenderImageResourceStyleImage::image):
+        * rendering/shapes/ShapeOutsideInfo.cpp:
+        (WebCore::ShapeOutsideInfo::createShapeForImage):
+        * rendering/style/StyleCachedImage.cpp:
+        (WebCore::StyleCachedImage::StyleCachedImage):
+        (WebCore::StyleCachedImage::~StyleCachedImage):
+        (WebCore::StyleCachedImage::setCachedImage):
+        (WebCore::StyleCachedImage::cssValue):
+        (WebCore::StyleCachedImage::canRender):
+        (WebCore::StyleCachedImage::isPending):
+        (WebCore::StyleCachedImage::isLoaded):
+        (WebCore::StyleCachedImage::errorOccurred):
+        (WebCore::StyleCachedImage::imageSize):
+        (WebCore::StyleCachedImage::imageHasRelativeWidth):
+        (WebCore::StyleCachedImage::imageHasRelativeHeight):
+        (WebCore::StyleCachedImage::computeIntrinsicDimensions):
+        (WebCore::StyleCachedImage::usesImageContainerSize):
+        (WebCore::StyleCachedImage::setContainerSizeForRenderer):
+        (WebCore::StyleCachedImage::addClient):
+        (WebCore::StyleCachedImage::removeClient):
+        (WebCore::StyleCachedImage::image):
+        (WebCore::StyleCachedImage::knownToBeOpaque):
+        * rendering/style/StyleCachedImage.h:
+        * rendering/style/StyleGeneratedImage.cpp:
+        (WebCore::StyleGeneratedImage::isPending):
+        * rendering/style/StyleGeneratedImage.h:
+        * rendering/style/StyleImage.h:
+        (WebCore::StyleImage::isCachedImage):
+        (WebCore::StyleImage::StyleImage):
+        (WebCore::StyleImage::canRender): Deleted.
+        (WebCore::StyleImage::isPendingImage): Deleted.
+        * rendering/style/StylePendingImage.h: Removed.
+        * style/StylePendingResources.cpp:
+        (WebCore::Style::loadPendingImage):
+        (WebCore::Style::loadPendingImages):
+
 2016-08-30  Philippe Normand  <pnormand@igalia.com>
 
         [GStreamer] bump required version to 1.2.3
index 8a99287..8f53fbe 100644 (file)
                0F97A658155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F97A657155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm */; };
                0FA24D79162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FA24D77162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp */; };
                0FA24D7A162DF91900A3F4C0 /* GraphicsLayerUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FA24D78162DF91900A3F4C0 /* GraphicsLayerUpdater.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               0FA6F96F1BCF614A0031EE70 /* StylePendingImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FA6F96E1BCF614A0031EE70 /* StylePendingImage.h */; };
                0FA88EBD16A8D1BD00F99984 /* ScrollingStateFrameScrollingNodeMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0FA88EBC16A8D1BD00F99984 /* ScrollingStateFrameScrollingNodeMac.mm */; };
                0FB6252E18DE1B1500A07C05 /* GeometryUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FB6252C18DE1B1500A07C05 /* GeometryUtilities.cpp */; };
                0FB6252F18DE1B1500A07C05 /* GeometryUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB6252D18DE1B1500A07C05 /* GeometryUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0F97A657155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DisplayRefreshMonitorIOS.mm; sourceTree = "<group>"; };
                0FA24D77162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsLayerUpdater.cpp; sourceTree = "<group>"; };
                0FA24D78162DF91900A3F4C0 /* GraphicsLayerUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsLayerUpdater.h; sourceTree = "<group>"; };
-               0FA6F96E1BCF614A0031EE70 /* StylePendingImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StylePendingImage.h; sourceTree = "<group>"; };
                0FA88EBC16A8D1BD00F99984 /* ScrollingStateFrameScrollingNodeMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingStateFrameScrollingNodeMac.mm; sourceTree = "<group>"; };
                0FB6252C18DE1B1500A07C05 /* GeometryUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeometryUtilities.cpp; sourceTree = "<group>"; };
                0FB6252D18DE1B1500A07C05 /* GeometryUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeometryUtilities.h; sourceTree = "<group>"; };
                                BC5EB7280E81DE8100B25965 /* StyleMarqueeData.h */,
                                BC5EB74B0E81E06700B25965 /* StyleMultiColData.cpp */,
                                BC5EB74C0E81E06700B25965 /* StyleMultiColData.h */,
-                               0FA6F96E1BCF614A0031EE70 /* StylePendingImage.h */,
                                BC2272E10E82EE9B00E7F975 /* StyleRareInheritedData.cpp */,
                                BC2272E20E82EE9B00E7F975 /* StyleRareInheritedData.h */,
                                BC2272BA0E82EAAE00E7F975 /* StyleRareNonInheritedData.cpp */,
                                BC5EB72A0E81DE8100B25965 /* StyleMarqueeData.h in Headers */,
                                0FF50272102BA96A0066F39A /* StyleMedia.h in Headers */,
                                BC5EB74E0E81E06700B25965 /* StyleMultiColData.h in Headers */,
-                               0FA6F96F1BCF614A0031EE70 /* StylePendingImage.h in Headers */,
                                E4DACE6A1D12E10B0075980F /* StylePendingResources.h in Headers */,
                                A80E6DFC0A199067007FB8C5 /* StyleProperties.h in Headers */,
                                E1B25107152A0BB00069B779 /* StylePropertyShorthand.h in Headers */,
index 136f865..6f07c03 100644 (file)
@@ -110,7 +110,7 @@ FloatSize CSSCrossfadeValue::fixedSize(const RenderElement* renderer)
         fromImageSize.height() * inversePercentage + toImageSize.height() * percentage);
 }
 
-bool CSSCrossfadeValue::isPending()
+bool CSSCrossfadeValue::isPending() const
 {
     return CSSImageGeneratorValue::subimageIsPending(m_fromValue)
         || CSSImageGeneratorValue::subimageIsPending(m_toValue);
@@ -199,11 +199,8 @@ RefPtr<CSSCrossfadeValue> CSSCrossfadeValue::blend(const CSSCrossfadeValue& from
     ASSERT(equalInputImages(from));
     if (!m_cachedToImage || !m_cachedFromImage)
         return nullptr;
-    RefPtr<StyleCachedImage> toStyledImage = StyleCachedImage::create(m_cachedToImage.get());
-    RefPtr<StyleCachedImage> fromStyledImage = StyleCachedImage::create(m_cachedFromImage.get());
-
-    auto fromImageValue = CSSImageValue::create(m_cachedFromImage->url(), fromStyledImage.get());
-    auto toImageValue = CSSImageValue::create(m_cachedToImage->url(), toStyledImage.get());
+    auto fromImageValue = CSSImageValue::create(*m_cachedFromImage);
+    auto toImageValue = CSSImageValue::create(*m_cachedToImage);
 
     double fromPercentage = from.m_percentageValue->getDoubleValue();
     if (from.m_percentageValue->isPercentage())
index c0a7e15..d934199 100644 (file)
@@ -57,7 +57,7 @@ public:
     FloatSize fixedSize(const RenderElement*);
 
     bool isPrefixed() const { return m_isPrefixed; }
-    bool isPending();
+    bool isPending() const;
     bool knownToBeOpaque(const RenderElement*) const;
 
     void loadSubimages(CachedResourceLoader&, const ResourceLoaderOptions&);
index 2deae77..ae4ac05 100644 (file)
@@ -28,7 +28,6 @@
 #include "CachedResourceLoader.h"
 #include "StyleCachedImage.h"
 #include "StyleImage.h"
-#include "StylePendingImage.h"
 #include "SVGCursorElement.h"
 #include "SVGLengthContext.h"
 #include "SVGNames.h"
@@ -46,18 +45,12 @@ CSSCursorImageValue::CSSCursorImageValue(Ref<CSSValue>&& imageValue, bool hasHot
     , m_hasHotSpot(hasHotSpot)
     , m_hotSpot(hotSpot)
 {
-}
-
-inline void CSSCursorImageValue::detachPendingImage()
-{
-    if (is<StylePendingImage>(m_image.get()))
-        downcast<StylePendingImage>(*m_image).detachFromCSSValue();
+    if (is<CSSImageValue>(m_imageValue.get()))
+        m_originalURL = { ParsedURLString, downcast<CSSImageValue>(m_imageValue.get()).url() };
 }
 
 CSSCursorImageValue::~CSSCursorImageValue()
 {
-    detachPendingImage();
-
     for (auto* element : m_cursorElements)
         element->removeClient(*this);
 }
@@ -77,10 +70,10 @@ String CSSCursorImageValue::customCSSText() const
 
 SVGCursorElement* CSSCursorImageValue::updateCursorElement(const Document& document)
 {
-    if (!isSVGCursor())
+    if (!m_originalURL.hasFragmentIdentifier())
         return nullptr;
 
-    auto* element = SVGURIReference::targetElementFromIRIString(downcast<CSSImageValue>(m_imageValue.get()).url(), document);
+    auto* element = SVGURIReference::targetElementFromIRIString(m_originalURL, document);
     if (!is<SVGCursorElement>(element))
         return nullptr;
 
@@ -95,13 +88,10 @@ SVGCursorElement* CSSCursorImageValue::updateCursorElement(const Document& docum
 void CSSCursorImageValue::cursorElementRemoved(SVGCursorElement& cursorElement)
 {
     m_cursorElements.remove(&cursorElement);
-    clearCachedImage();
 }
 
 void CSSCursorImageValue::cursorElementChanged(SVGCursorElement& cursorElement)
 {
-    clearCachedImage();
-
     // FIXME: This will override hot spot specified in CSS, which is probably incorrect.
     SVGLengthContext lengthContext(nullptr);
     m_hasHotSpot = true;
@@ -112,71 +102,32 @@ void CSSCursorImageValue::cursorElementChanged(SVGCursorElement& cursorElement)
     m_hotSpot.setY(static_cast<int>(y));
 }
 
-StyleImage* CSSCursorImageValue::cachedImage(CachedResourceLoader& loader, const ResourceLoaderOptions& options)
+void CSSCursorImageValue::loadImage(CachedResourceLoader& loader, const ResourceLoaderOptions& options)
 {
-    if (is<CSSImageSetValue>(m_imageValue.get()))
-        return downcast<CSSImageSetValue>(m_imageValue.get()).bestFitImage(loader, options);
-
-    auto* cursorElement = loader.document() ? updateCursorElement(*loader.document()) : nullptr;
-
-    if (!m_isImageValid) {
-        m_isImageValid = true;
-        // For SVG images we need to lazily substitute in the correct URL. Rather than attempt
-        // to change the URL of the CSSImageValue (which would then change behavior like cssText),
-        // we create an alternate CSSImageValue to use.
-        if (cursorElement) {
-            detachPendingImage();
-            Ref<CSSImageValue> svgImageValue(CSSImageValue::create(cursorElement->href()));
-            StyleCachedImage* cachedImage = svgImageValue->cachedImage(loader, options);
-            m_image = cachedImage;
-            return cachedImage;
-        }
-
-        if (is<CSSImageValue>(m_imageValue.get())) {
-            detachPendingImage();
-            m_image = downcast<CSSImageValue>(m_imageValue.get()).cachedImage(loader, options);
-        }
+    if (is<CSSImageSetValue>(m_imageValue.get())) {
+        downcast<CSSImageSetValue>(m_imageValue.get()).loadBestFitImage(loader, options);
+        return;
     }
 
-    if (is<StyleCachedImage>(m_image.get()))
-        return downcast<StyleCachedImage>(m_image.get());
-
-    return nullptr;
+    downcast<CSSImageValue>(m_imageValue.get()).loadImage(loader, options);
 }
 
-StyleImage* CSSCursorImageValue::cachedOrPendingImage(const Document& document)
+StyleCachedImage& CSSCursorImageValue::styleImage(const Document& document)
 {
     // Need to delegate completely so that changes in device scale factor can be handled appropriately.
+    StyleCachedImage* styleImage;
     if (is<CSSImageSetValue>(m_imageValue.get()))
-        return downcast<CSSImageSetValue>(m_imageValue.get()).cachedOrPendingImageSet(document);
-
-    if (!m_image)
-        m_image = StylePendingImage::create(this);
-
-    return m_image.get();
-}
-
-bool CSSCursorImageValue::isSVGCursor() const
-{
-    if (is<CSSImageValue>(m_imageValue.get())) {
-        URL kurl(ParsedURLString, downcast<CSSImageValue>(m_imageValue.get()).url());
-        return kurl.hasFragmentIdentifier();
+        styleImage = &downcast<CSSImageSetValue>(m_imageValue.get()).styleImage(document);
+    else {
+        if (auto* cursorElement = updateCursorElement(document)) {
+            if (cursorElement->href() != downcast<CSSImageValue>(m_imageValue.get()).url())
+                m_imageValue = CSSImageValue::create(cursorElement->href());
+        }
+        styleImage = &downcast<CSSImageValue>(m_imageValue.get()).styleImage();
     }
-    return false;
-}
+    styleImage->setCSSValue(*this);
 
-String CSSCursorImageValue::cachedImageURL()
-{
-    if (!is<StyleCachedImage>(m_image.get()))
-        return String();
-    return downcast<StyleCachedImage>(*m_image).cachedImage()->url();
-}
-
-void CSSCursorImageValue::clearCachedImage()
-{
-    detachPendingImage();
-    m_image = nullptr;
-    m_isImageValid = false;
+    return *styleImage;
 }
 
 bool CSSCursorImageValue::equals(const CSSCursorImageValue& other) const
index 6fdf488..f8e1eda 100644 (file)
@@ -31,6 +31,7 @@ class Document;
 class Element;
 class SVGCursorElement;
 class SVGElement;
+class StyleCachedImage;
 
 class CSSCursorImageValue final : public CSSValue {
 public:
@@ -52,9 +53,8 @@ public:
 
     String customCSSText() const;
 
-    SVGCursorElement* updateCursorElement(const Document&);
-    StyleImage* cachedImage(CachedResourceLoader&, const ResourceLoaderOptions&);
-    StyleImage* cachedOrPendingImage(const Document&);
+    void loadImage(CachedResourceLoader&, const ResourceLoaderOptions&);
+    StyleCachedImage& styleImage(const Document&);
 
     void removeReferencedElement(SVGElement*);
 
@@ -66,18 +66,13 @@ public:
 private:
     CSSCursorImageValue(Ref<CSSValue>&& imageValue, bool hasHotSpot, const IntPoint& hotSpot);
 
-    void detachPendingImage();
-
-    bool isSVGCursor() const;
-    String cachedImageURL();
-    void clearCachedImage();
+    SVGCursorElement* updateCursorElement(const Document&);
 
+    URL m_originalURL;
     Ref<CSSValue> m_imageValue;
 
     bool m_hasHotSpot;
     IntPoint m_hotSpot;
-    RefPtr<StyleImage> m_image;
-    bool m_isImageValid { false };
     HashSet<SVGCursorElement*> m_cursorElements;
 };
 
index 388dfb3..01a6df9 100644 (file)
@@ -73,7 +73,7 @@ FloatSize CSSFilterImageValue::fixedSize(const RenderElement* renderer)
     return cachedImage->imageForRenderer(renderer)->size();
 }
 
-bool CSSFilterImageValue::isPending()
+bool CSSFilterImageValue::isPending() const
 {
     return CSSImageGeneratorValue::subimageIsPending(m_imageValue);
 }
index 2567b9a..952a08d 100644 (file)
@@ -59,7 +59,7 @@ public:
     bool isFixedSize() const { return true; }
     FloatSize fixedSize(const RenderElement*);
 
-    bool isPending();
+    bool isPending() const;
     bool knownToBeOpaque(const RenderElement*) const;
 
     void loadSubimages(CachedResourceLoader&, const ResourceLoaderOptions&);
index 6c94dfd..3d54b6a 100644 (file)
@@ -167,7 +167,7 @@ FloatSize CSSImageGeneratorValue::fixedSize(const RenderElement* renderer)
     return FloatSize();
 }
 
-bool CSSImageGeneratorValue::isPending()
+bool CSSImageGeneratorValue::isPending() const
 {
     switch (classType()) {
     case CrossfadeClass:
@@ -232,10 +232,10 @@ void CSSImageGeneratorValue::loadSubimages(CachedResourceLoader& cachedResourceL
     }
 }
 
-bool CSSImageGeneratorValue::subimageIsPending(CSSValue& value)
+bool CSSImageGeneratorValue::subimageIsPending(const CSSValue& value)
 {
     if (is<CSSImageValue>(value))
-        return downcast<CSSImageValue>(value).cachedOrPendingImage().isPendingImage();
+        return downcast<CSSImageValue>(value).isPending();
     
     if (is<CSSImageGeneratorValue>(value))
         return downcast<CSSImageGeneratorValue>(value).isPending();
@@ -251,11 +251,9 @@ bool CSSImageGeneratorValue::subimageIsPending(CSSValue& value)
 CachedImage* CSSImageGeneratorValue::cachedImageForCSSValue(CSSValue& value, CachedResourceLoader& cachedResourceLoader, const ResourceLoaderOptions& options)
 {
     if (is<CSSImageValue>(value)) {
-        StyleCachedImage* styleCachedImage = downcast<CSSImageValue>(value).cachedImage(cachedResourceLoader, options);
-        if (!styleCachedImage)
-            return nullptr;
-
-        return styleCachedImage->cachedImage();
+        auto& imageValue = downcast<CSSImageValue>(value);
+        imageValue.loadImage(cachedResourceLoader, options);
+        return imageValue.styleImage().cachedImage();
     }
     
     if (is<CSSImageGeneratorValue>(value)) {
index 12fb3c3..9527dd8 100644 (file)
@@ -54,7 +54,7 @@ public:
     bool isFixedSize() const;
     FloatSize fixedSize(const RenderElement*);
 
-    bool isPending();
+    bool isPending() const;
     bool knownToBeOpaque(const RenderElement*) const;
 
     void loadSubimages(CachedResourceLoader&, const ResourceLoaderOptions&);
@@ -68,7 +68,7 @@ protected:
 
     // Helper functions for Crossfade and Filter.
     static CachedImage* cachedImageForCSSValue(CSSValue&, CachedResourceLoader&, const ResourceLoaderOptions&);
-    static bool subimageIsPending(CSSValue&);
+    static bool subimageIsPending(const CSSValue&);
 
 private:
     class CachedGeneratedImage {
index 5f537eb..ba4af1e 100644 (file)
@@ -36,7 +36,6 @@
 #include "Document.h"
 #include "Page.h"
 #include "StyleCachedImage.h"
-#include "StylePendingImage.h"
 #include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
@@ -48,18 +47,10 @@ CSSImageSetValue::CSSImageSetValue()
 {
 }
 
-inline void CSSImageSetValue::detachPendingImage()
-{
-    if (is<StylePendingImage>(m_image.get()))
-        downcast<StylePendingImage>(*m_image).detachFromCSSValue();
-}
-
 CSSImageSetValue::~CSSImageSetValue()
 {
-    detachPendingImage();
-
-    if (is<StyleCachedImage>(m_image.get()))
-        downcast<StyleCachedImage>(*m_image).detachFromCSSValue();
+    if (m_image)
+        m_image->detachFromCSSValue();
 }
 
 void CSSImageSetValue::fillImageSet()
@@ -98,7 +89,7 @@ CSSImageSetValue::ImageWithScale CSSImageSetValue::bestImageForScaleFactor()
     return image;
 }
 
-StyleCachedImage* CSSImageSetValue::bestFitImage(CachedResourceLoader& loader, const ResourceLoaderOptions& options)
+void CSSImageSetValue::loadBestFitImage(CachedResourceLoader& loader, const ResourceLoaderOptions& options)
 {
     Document* document = loader.document();
     if (Page* page = document->page())
@@ -109,32 +100,29 @@ StyleCachedImage* CSSImageSetValue::bestFitImage(CachedResourceLoader& loader, c
     if (!m_imagesInSet.size())
         fillImageSet();
 
-    if (!m_accessedBestFitImage) {
-        // FIXME: In the future, we want to take much more than deviceScaleFactor into acount here. 
-        // All forms of scale should be included: Page::pageScaleFactor(), Frame::pageZoomFactor(),
-        // and any CSS transforms. https://bugs.webkit.org/show_bug.cgi?id=81698
-        ImageWithScale image = bestImageForScaleFactor();
-        CachedResourceRequest request(ResourceRequest(document->completeURL(image.imageURL)), options);
-        request.setInitiator(cachedResourceRequestInitiators().css);
-        if (options.mode == FetchOptions::Mode::Cors) {
-            ASSERT(document->securityOrigin());
-            updateRequestForAccessControl(request.mutableResourceRequest(), *document->securityOrigin(), options.allowCredentials);
-        }
-        if (CachedResourceHandle<CachedImage> cachedImage = loader.requestImage(request)) {
-            detachPendingImage();
-            m_image = StyleCachedImage::createForImageSet(cachedImage.get(), image.scaleFactor, *this);
-            m_accessedBestFitImage = true;
-        }
+    if (m_accessedBestFitImage)
+        return;
+    // FIXME: In the future, we want to take much more than deviceScaleFactor into acount here.
+    // All forms of scale should be included: Page::pageScaleFactor(), Frame::pageZoomFactor(),
+    // and any CSS transforms. https://bugs.webkit.org/show_bug.cgi?id=81698
+    ImageWithScale image = bestImageForScaleFactor();
+    CachedResourceRequest request(ResourceRequest(document->completeURL(image.imageURL)), options);
+    request.setInitiator(cachedResourceRequestInitiators().css);
+    if (options.mode == FetchOptions::Mode::Cors) {
+        ASSERT(document->securityOrigin());
+        updateRequestForAccessControl(request.mutableResourceRequest(), *document->securityOrigin(), options.allowCredentials);
+    }
+    if (CachedResourceHandle<CachedImage> cachedImage = loader.requestImage(request)) {
+        styleImage(*document).setCachedImage(*cachedImage, image.scaleFactor);
+        m_accessedBestFitImage = true;
     }
-
-    return is<StyleCachedImage>(m_image.get()) ? downcast<StyleCachedImage>(m_image.get()) : nullptr;
 }
 
-StyleImage* CSSImageSetValue::cachedOrPendingImageSet(const Document& document)
+StyleCachedImage& CSSImageSetValue::styleImage(const Document& document)
 {
     if (!m_image)
-        m_image = StylePendingImage::create(this);
-    else if (!m_image->isPendingImage()) {
+        m_image = StyleCachedImage::create(*this);
+    else if (!m_image->isPending()) {
         float deviceScaleFactor = 1;
         if (Page* page = document.page())
             deviceScaleFactor = page->deviceScaleFactor();
@@ -142,11 +130,12 @@ StyleImage* CSSImageSetValue::cachedOrPendingImageSet(const Document& document)
         // If the deviceScaleFactor has changed, we may not have the best image loaded, so we have to re-assess.
         if (deviceScaleFactor != m_scaleFactor) {
             m_accessedBestFitImage = false;
-            m_image = StylePendingImage::create(this);
+            m_image->detachFromCSSValue();
+            m_image = StyleCachedImage::create(*this);
         }
     }
 
-    return m_image.get();
+    return *m_image;
 }
 
 String CSSImageSetValue::customCSSText() const
@@ -181,10 +170,11 @@ String CSSImageSetValue::customCSSText() const
 
 bool CSSImageSetValue::traverseSubresources(const std::function<bool (const CachedResource&)>& handler) const
 {
-    if (!is<StyleCachedImage>(m_image.get()))
+    if (!m_image)
+        return false;
+    CachedImage* cachedResource = m_image->cachedImage();
+    if (!cachedResource)
         return false;
-    CachedImage* cachedResource = downcast<StyleCachedImage>(*m_image).cachedImage();
-    ASSERT(cachedResource);
     return handler(*cachedResource);
 }
 
index f4ae5bb..27e8465 100644 (file)
@@ -45,10 +45,8 @@ public:
     }
     ~CSSImageSetValue();
 
-    StyleCachedImage* bestFitImage(CachedResourceLoader&, const ResourceLoaderOptions&);
-
-    // Returns a StyleCachedImage if the best fit image has been cached already, otherwise a StylePendingImage.
-    StyleImage* cachedOrPendingImageSet(const Document&);
+    void loadBestFitImage(CachedResourceLoader&, const ResourceLoaderOptions&);
+    StyleCachedImage& styleImage(const Document&);
 
     String customCSSText() const;
 
@@ -70,11 +68,10 @@ private:
     CSSImageSetValue();
     CSSImageSetValue(const CSSImageSetValue& cloneFrom);
 
-    void detachPendingImage();
     void fillImageSet();
     static inline bool compareByScaleFactor(ImageWithScale first, ImageWithScale second) { return first.scaleFactor < second.scaleFactor; }
 
-    RefPtr<StyleImage> m_image;
+    RefPtr<StyleCachedImage> m_image;
     bool m_accessedBestFitImage;
 
     // This represents the scale factor that we used to find the best fit image. It does not necessarily
index 73058ef..c8aee0d 100644 (file)
@@ -33,7 +33,6 @@
 #include "Element.h"
 #include "MemoryCache.h"
 #include "StyleCachedImage.h"
-#include "StylePendingImage.h"
 
 namespace WebCore {
 
@@ -44,63 +43,62 @@ CSSImageValue::CSSImageValue(const String& url)
 {
 }
 
-CSSImageValue::CSSImageValue(const String& url, StyleImage* image)
+CSSImageValue::CSSImageValue(CachedImage& image)
     : CSSValue(ImageClass)
-    , m_url(url)
-    , m_image(image)
+    , m_url(image.url())
+    , m_image(StyleCachedImage::create(*this))
     , m_accessedImage(true)
 {
+    m_image->setCachedImage(image);
 }
 
-inline void CSSImageValue::detachPendingImage()
+
+CSSImageValue::~CSSImageValue()
 {
-    if (is<StylePendingImage>(m_image.get()))
-        downcast<StylePendingImage>(*m_image).detachFromCSSValue();
+    if (m_image)
+        m_image->detachFromCSSValue();
 }
 
-CSSImageValue::~CSSImageValue()
+bool CSSImageValue::isPending() const
 {
-    detachPendingImage();
+    return !m_image || !m_image->cachedImage();
 }
 
-StyleImage& CSSImageValue::cachedOrPendingImage()
+StyleCachedImage& CSSImageValue::styleImage()
 {
     if (!m_image)
-        m_image = StylePendingImage::create(this);
+        m_image = StyleCachedImage::create(*this);
 
     return *m_image;
 }
 
-StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader& loader, const ResourceLoaderOptions& options)
+void CSSImageValue::loadImage(CachedResourceLoader& loader, const ResourceLoaderOptions& options)
 {
-    if (!m_accessedImage) {
-        m_accessedImage = true;
-
-        CachedResourceRequest request(ResourceRequest(loader.document()->completeURL(m_url)), options);
-        if (m_initiatorName.isEmpty())
-            request.setInitiator(cachedResourceRequestInitiators().css);
-        else
-            request.setInitiator(m_initiatorName);
-
-        if (options.mode == FetchOptions::Mode::Cors) {
-            ASSERT(loader.document()->securityOrigin());
-            updateRequestForAccessControl(request.mutableResourceRequest(), *loader.document()->securityOrigin(), options.allowCredentials);
-        }
-        if (CachedResourceHandle<CachedImage> cachedImage = loader.requestImage(request)) {
-            detachPendingImage();
-            m_image = StyleCachedImage::create(cachedImage.get());
-        }
+    if (m_accessedImage)
+        return;
+    m_accessedImage = true;
+
+    CachedResourceRequest request(ResourceRequest(loader.document()->completeURL(m_url)), options);
+    if (m_initiatorName.isEmpty())
+        request.setInitiator(cachedResourceRequestInitiators().css);
+    else
+        request.setInitiator(m_initiatorName);
+
+    if (options.mode == FetchOptions::Mode::Cors) {
+        ASSERT(loader.document()->securityOrigin());
+        updateRequestForAccessControl(request.mutableResourceRequest(), *loader.document()->securityOrigin(), options.allowCredentials);
     }
-
-    return is<StyleCachedImage>(m_image.get()) ? downcast<StyleCachedImage>(m_image.get()) : nullptr;
+    if (CachedResourceHandle<CachedImage> cachedImage = loader.requestImage(request))
+        styleImage().setCachedImage(*cachedImage);
 }
 
 bool CSSImageValue::traverseSubresources(const std::function<bool (const CachedResource&)>& handler) const
 {
-    if (!is<StyleCachedImage>(m_image.get()))
+    if (!m_image)
+        return false;
+    CachedResource* cachedResource = m_image->cachedImage();
+    if (!cachedResource)
         return false;
-    CachedResource* cachedResource = downcast<StyleCachedImage>(*m_image).cachedImage();
-    ASSERT(cachedResource);
     return handler(*cachedResource);
 }
 
index 97372d8..0a8de95 100644 (file)
 
 namespace WebCore {
 
+class CachedImage;
 class CachedResourceLoader;
 class Element;
 class StyleCachedImage;
-class StyleImage;
 class RenderElement;
 struct ResourceLoaderOptions;
 
 class CSSImageValue final : public CSSValue {
 public:
     static Ref<CSSImageValue> create(const String& url) { return adoptRef(*new CSSImageValue(url)); }
-    static Ref<CSSImageValue> create(const String& url, StyleImage* image) { return adoptRef(*new CSSImageValue(url, image)); }
+    static Ref<CSSImageValue> create(CachedImage& image) { return adoptRef(*new CSSImageValue(image)); }
     ~CSSImageValue();
 
-    StyleCachedImage* cachedImage(CachedResourceLoader&, const ResourceLoaderOptions&);
-    // Returns a StyleCachedImage if the image is cached already, otherwise a StylePendingImage.
-    StyleImage& cachedOrPendingImage();
+    bool isPending() const;
+    void loadImage(CachedResourceLoader&, const ResourceLoaderOptions&);
+    StyleCachedImage& styleImage();
 
     const String& url() const { return m_url; }
 
@@ -59,11 +59,10 @@ public:
 
 private:
     explicit CSSImageValue(const String& url);
-    CSSImageValue(const String& url, StyleImage*);
-    void detachPendingImage();
+    explicit CSSImageValue(CachedImage&);
 
     String m_url;
-    RefPtr<StyleImage> m_image;
+    RefPtr<StyleCachedImage> m_image;
     bool m_accessedImage;
     AtomicString m_initiatorName;
 };
index 5fab59b..3594b2a 100644 (file)
 #include "StyleCachedImage.h"
 #include "StyleFontSizeFunctions.h"
 #include "StyleGeneratedImage.h"
-#include "StylePendingImage.h"
 #include "StyleProperties.h"
 #include "StylePropertyShorthand.h"
 #include "StyleRule.h"
@@ -1723,8 +1722,8 @@ RefPtr<StyleImage> StyleResolver::styleImage(CSSPropertyID property, CSSValue& v
 
 Ref<StyleImage> StyleResolver::cachedOrPendingFromValue(CSSPropertyID property, CSSImageValue& value)
 {
-    Ref<StyleImage> image = value.cachedOrPendingImage();
-    if (image->isPendingImage())
+    Ref<StyleImage> image = value.styleImage();
+    if (image->isPending())
         m_state.ensurePendingResources().pendingImages.set(property, &value);
     return image;
 }
@@ -1735,28 +1734,26 @@ Ref<StyleImage> StyleResolver::generatedOrPendingFromValue(CSSPropertyID propert
         // FilterImage needs to calculate FilterOperations.
         downcast<CSSFilterImageValue>(value).createFilterOperations(this);
     }
-
-    if (value.isPending()) {
+    if (value.isPending())
         m_state.ensurePendingResources().pendingImages.set(property, &value);
-        return StylePendingImage::create(&value);
-    }
+
     return StyleGeneratedImage::create(value);
 }
 
 RefPtr<StyleImage> StyleResolver::setOrPendingFromValue(CSSPropertyID property, CSSImageSetValue& value)
 {
-    RefPtr<StyleImage> image = value.cachedOrPendingImageSet(document());
-    if (image && image->isPendingImage())
+    auto& image = value.styleImage(document());
+    if (image.isPending())
         m_state.ensurePendingResources().pendingImages.set(property, &value);
-    return image;
+    return &image;
 }
 
 RefPtr<StyleImage> StyleResolver::cursorOrPendingFromValue(CSSPropertyID property, CSSCursorImageValue& value)
 {
-    RefPtr<StyleImage> image = value.cachedOrPendingImage(document());
-    if (image && image->isPendingImage())
+    auto& image = value.styleImage(document());
+    if (image.isPending())
         m_state.ensurePendingResources().pendingImages.set(property, &value);
-    return image;
+    return &image;
 }
 
 #if ENABLE(IOS_TEXT_AUTOSIZING)
index 818ac64..279b206 100644 (file)
@@ -331,12 +331,11 @@ void PageSerializer::retrieveResourcesForProperties(const StyleProperties* style
         if (!is<CSSImageValue>(*cssValue))
             continue;
 
-        auto& styleImage = downcast<CSSImageValue>(*cssValue).cachedOrPendingImage();
-        // Non cached-images are just place-holders and do not contain data.
-        if (!is<StyleCachedImage>(styleImage))
-            continue;
+        auto& styleImage = downcast<CSSImageValue>(*cssValue).styleImage();
 
-        CachedImage* image = downcast<StyleCachedImage>(styleImage).cachedImage();
+        auto* image = styleImage.cachedImage();
+        if (!image)
+            continue;
 
         URL url = document->completeURL(image->url());
         addImageToResources(image, nullptr, url);
index 8669aca..5ca1b4d 100644 (file)
@@ -225,8 +225,7 @@ static inline PassRefPtr<StyleImage> blendFilter(const AnimationBase* anim, Cach
     ASSERT(image);
     FilterOperations filterResult = blendFilterOperations(anim, from, to, progress);
 
-    RefPtr<StyleCachedImage> styledImage = StyleCachedImage::create(image);
-    auto imageValue = CSSImageValue::create(image->url(), styledImage.get());
+    auto imageValue = CSSImageValue::create(*image);
     auto filterValue = ComputedStyleExtractor::valueForFilter(anim->renderer()->style(), filterResult, DoNotAdjustPixelValues);
 
     auto result = CSSFilterImageValue::create(WTFMove(imageValue), WTFMove(filterValue));
@@ -290,8 +289,8 @@ static inline PassRefPtr<StyleImage> crossfadeBlend(const AnimationBase*, StyleC
     if (progress == 1)
         return toStyleImage;
 
-    auto fromImageValue = CSSImageValue::create(fromStyleImage->cachedImage()->url(), fromStyleImage);
-    auto toImageValue = CSSImageValue::create(toStyleImage->cachedImage()->url(), toStyleImage);
+    auto fromImageValue = CSSImageValue::create(*fromStyleImage->cachedImage());
+    auto toImageValue = CSSImageValue::create(*toStyleImage->cachedImage());
     auto percentageValue = CSSPrimitiveValue::create(progress, CSSPrimitiveValue::CSS_NUMBER);
 
     auto crossfadeValue = CSSCrossfadeValue::create(WTFMove(fromImageValue), WTFMove(toImageValue), WTFMove(percentageValue));
index 41203b8..4046d54 100644 (file)
@@ -63,7 +63,7 @@ void RenderImageResourceStyleImage::shutdown()
 RefPtr<Image> RenderImageResourceStyleImage::image(int width, int height) const
 {
     // Generated content may trigger calls to image() while we're still pending, don't assert but gracefully exit.
-    if (m_styleImage->isPendingImage())
+    if (m_styleImage->isPending())
         return nullptr;
     return m_styleImage->image(m_renderer, IntSize(width, height));
 }
index 63073b4..2d84666 100644 (file)
@@ -156,7 +156,7 @@ std::unique_ptr<Shape> ShapeOutsideInfo::createShapeForImage(StyleImage* styleIm
         ? downcast<RenderImage>(m_renderer).replacedContentRect(m_renderer.intrinsicSize())
         : LayoutRect(LayoutPoint(), imageSize);
 
-    ASSERT(!styleImage->isPendingImage());
+    ASSERT(!styleImage->isPending());
     RefPtr<Image> image = styleImage->image(const_cast<RenderBox*>(&m_renderer), imageSize);
     return Shape::createRasterShape(image.get(), shapeImageThreshold, imageRect, marginRect, writingMode, margin);
 }
index f5f345f..fe62cc7 100644 (file)
 
 namespace WebCore {
 
-StyleCachedImage::StyleCachedImage(CachedImage* image, float scaleFactor, CSSImageSetValue* cssValue)
-    : m_image(image)
-    , m_scaleFactor(scaleFactor)
-    , m_cssImageSetValue(cssValue)
+StyleCachedImage::StyleCachedImage(CSSValue& cssValue)
+    : m_cssValue(&cssValue)
 {
     m_isCachedImage = true;
-    m_image->addClient(this);
 }
 
 StyleCachedImage::~StyleCachedImage()
 {
-    m_image->removeClient(this);
+    if (m_image)
+        m_image->removeClient(this);
+}
+
+void StyleCachedImage::setCachedImage(CachedImage& image, float scaleFactor)
+{
+    ASSERT(!m_image);
+    m_image = &image;
+    m_image->addClient(this);
+    m_scaleFactor = scaleFactor;
 }
 
 PassRefPtr<CSSValue> StyleCachedImage::cssValue() const
 {
-    if (m_cssImageSetValue)
-        return const_cast<CSSImageSetValue*>(m_cssImageSetValue);
+    if (m_cssValue)
+        return m_cssValue;
     return CSSPrimitiveValue::create(m_image->url(), CSSPrimitiveValue::CSS_URI);
 }
 
 bool StyleCachedImage::canRender(const RenderObject* renderer, float multiplier) const
 {
+    if (!m_image)
+        return false;
     return m_image->canRender(renderer, multiplier);
 }
 
+bool StyleCachedImage::isPending() const
+{
+    return !m_image;
+}
+
 bool StyleCachedImage::isLoaded() const
 {
+    if (!m_image)
+        return false;
     return m_image->isLoaded();
 }
 
 bool StyleCachedImage::errorOccurred() const
 {
+    if (!m_image)
+        return false;
     return m_image->errorOccurred();
 }
 
 FloatSize StyleCachedImage::imageSize(const RenderElement* renderer, float multiplier) const
 {
+    if (!m_image)
+        return { };
     FloatSize size = m_image->imageSizeForRenderer(renderer, multiplier);
     size.scale(1 / m_scaleFactor);
     return size;
@@ -75,41 +94,57 @@ FloatSize StyleCachedImage::imageSize(const RenderElement* renderer, float multi
 
 bool StyleCachedImage::imageHasRelativeWidth() const
 {
+    if (!m_image)
+        return false;
     return m_image->imageHasRelativeWidth();
 }
 
 bool StyleCachedImage::imageHasRelativeHeight() const
 {
+    if (!m_image)
+        return false;
     return m_image->imageHasRelativeHeight();
 }
 
 void StyleCachedImage::computeIntrinsicDimensions(const RenderElement*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
 {
+    if (!m_image)
+        return;
     m_image->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
 }
 
 bool StyleCachedImage::usesImageContainerSize() const
 {
+    if (!m_image)
+        return false;
     return m_image->usesImageContainerSize();
 }
 
 void StyleCachedImage::setContainerSizeForRenderer(const RenderElement* renderer, const FloatSize& imageContainerSize, float imageContainerZoomFactor)
 {
+    if (!m_image)
+        return;
     m_image->setContainerSizeForRenderer(renderer, LayoutSize(imageContainerSize), imageContainerZoomFactor);
 }
 
 void StyleCachedImage::addClient(RenderElement* renderer)
 {
+    if (!m_image)
+        return;
     m_image->addClient(renderer);
 }
 
 void StyleCachedImage::removeClient(RenderElement* renderer)
 {
+    if (!m_image)
+        return;
     m_image->removeClient(renderer);
 }
 
 RefPtr<Image> StyleCachedImage::image(RenderElement* renderer, const FloatSize&) const
 {
+    if (!m_image)
+        return nullptr;
     return m_image->imageForRenderer(renderer);
 }
 
@@ -120,6 +155,8 @@ float StyleCachedImage::imageScaleFactor() const
 
 bool StyleCachedImage::knownToBeOpaque(const RenderElement* renderer) const
 {
+    if (!m_image)
+        return false;
     return m_image->currentFrameKnownToBeOpaque(renderer);
 }
 
index 8e6db32..f8a5d31 100644 (file)
 
 namespace WebCore {
 
-class CSSImageSetValue;
+class CSSValue;
 class CachedImage;
 
 class StyleCachedImage final : public StyleImage, private CachedImageClient {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static Ref<StyleCachedImage> create(CachedImage* image) { return adoptRef(*new StyleCachedImage(image, 1, nullptr)); }
-    static Ref<StyleCachedImage> createForImageSet(CachedImage* image, float scaleFactor, CSSImageSetValue& cssValue) { return adoptRef(*new StyleCachedImage(image, scaleFactor, &cssValue)); }
+    static Ref<StyleCachedImage> create(CSSValue& cssValue) { return adoptRef(*new StyleCachedImage(cssValue)); }
     virtual ~StyleCachedImage();
 
     CachedImage* cachedImage() const override { return m_image.get(); }
 
-    void detachFromCSSValue() { m_cssImageSetValue = nullptr; }
+    void detachFromCSSValue() { m_cssValue = nullptr; }
+    void setCSSValue(CSSValue& value) { m_cssValue = &value; }
+
+    void setCachedImage(CachedImage&, float scaleFactor = 1);
 
-private:
     WrappedImagePtr data() const override { return m_image.get(); }
 
     PassRefPtr<CSSValue> cssValue() const override;
     
     bool canRender(const RenderObject*, float multiplier) const override;
+    bool isPending() const override;
     bool isLoaded() const override;
     bool errorOccurred() const override;
     FloatSize imageSize(const RenderElement*, float multiplier) const override;
@@ -64,11 +66,12 @@ private:
     float imageScaleFactor() const override;
     bool knownToBeOpaque(const RenderElement*) const override;
 
-    StyleCachedImage(CachedImage*, float scaleFactor, CSSImageSetValue*);
+private:
+    StyleCachedImage(CSSValue&);
 
+    CSSValue* m_cssValue;
+    float m_scaleFactor { 1 };
     CachedResourceHandle<CachedImage> m_image;
-    float m_scaleFactor;
-    CSSImageSetValue* m_cssImageSetValue; // Not retained; it owns us.
 };
 
 } // namespace WebCore
index 24ae933..1c92519 100644 (file)
@@ -42,6 +42,11 @@ PassRefPtr<CSSValue> StyleGeneratedImage::cssValue() const
     return const_cast<CSSImageGeneratorValue*>(m_imageGeneratorValue.ptr());
 }
 
+bool StyleGeneratedImage::isPending() const
+{
+    return m_imageGeneratorValue->isPending();
+}
+
 FloatSize StyleGeneratedImage::imageSize(const RenderElement* renderer, float multiplier) const
 {
     if (m_fixedSize) {
index f892ef6..63c5922 100644 (file)
@@ -45,6 +45,7 @@ private:
 
     PassRefPtr<CSSValue> cssValue() const override;
 
+    bool isPending() const override;
     FloatSize imageSize(const RenderElement*, float multiplier) const override;
     bool imageHasRelativeWidth() const override { return !m_fixedSize; }
     bool imageHasRelativeHeight() const override { return !m_fixedSize; }
index fbd5920..aa45637 100644 (file)
@@ -47,12 +47,13 @@ public:
 
     bool operator==(const StyleImage& other) const
     {
-        return data() == other.data();
+        return &other == this || (data() && data() == other.data());
     }
 
     virtual PassRefPtr<CSSValue> cssValue() const = 0;
 
     virtual bool canRender(const RenderObject*, float /*multiplier*/) const { return true; }
+    virtual bool isPending() const = 0;
     virtual bool isLoaded() const { return true; }
     virtual bool errorOccurred() const { return false; }
     virtual FloatSize imageSize(const RenderElement*, float multiplier) const = 0;
@@ -70,18 +71,15 @@ public:
     virtual CachedImage* cachedImage() const { return 0; }
 
     ALWAYS_INLINE bool isCachedImage() const { return m_isCachedImage; }
-    ALWAYS_INLINE bool isPendingImage() const { return m_isPendingImage; }
     ALWAYS_INLINE bool isGeneratedImage() const { return m_isGeneratedImage; }
 
 protected:
     StyleImage()
         : m_isCachedImage(false)
-        , m_isPendingImage(false)
         , m_isGeneratedImage(false)
     {
     }
     bool m_isCachedImage : 1;
-    bool m_isPendingImage : 1;
     bool m_isGeneratedImage : 1;
 };
 
diff --git a/Source/WebCore/rendering/style/StylePendingImage.h b/Source/WebCore/rendering/style/StylePendingImage.h
deleted file mode 100644 (file)
index 41f726e..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#ifndef StylePendingImage_h
-#define StylePendingImage_h
-
-#include "CSSCursorImageValue.h"
-#include "CSSImageGeneratorValue.h"
-#include "CSSImageSetValue.h"
-#include "CSSImageValue.h"
-#include "StyleImage.h"
-
-namespace WebCore {
-
-// StylePendingImage is a placeholder StyleImage that is entered into the RenderStyle during
-// style resolution, in order to avoid loading images that are not referenced by the final style.
-// They should never exist in a RenderStyle after it has been returned from the style selector.
-
-class StylePendingImage final : public StyleImage {
-public:
-    static Ref<StylePendingImage> create(CSSValue* value) { return adoptRef(*new StylePendingImage(value)); }
-
-    CSSImageValue* cssImageValue() const { return is<CSSImageValue>(m_value) ? downcast<CSSImageValue>(m_value) : nullptr; }
-    CSSImageGeneratorValue* cssImageGeneratorValue() const { return is<CSSImageGeneratorValue>(m_value) ? static_cast<CSSImageGeneratorValue*>(m_value) : nullptr; }
-    CSSCursorImageValue* cssCursorImageValue() const { return is<CSSCursorImageValue>(m_value) ? downcast<CSSCursorImageValue>(m_value) : nullptr; }
-    CSSImageSetValue* cssImageSetValue() const { return is<CSSImageSetValue>(m_value) ? downcast<CSSImageSetValue>(m_value) : nullptr; }
-
-    void detachFromCSSValue() { m_value = nullptr; }
-
-private:
-    WrappedImagePtr data() const override { return const_cast<StylePendingImage*>(this); }
-
-    PassRefPtr<CSSValue> cssValue() const override { return m_value; }
-    
-    FloatSize imageSize(const RenderElement*, float /*multiplier*/) const override { return FloatSize(); }
-    bool imageHasRelativeWidth() const override { return false; }
-    bool imageHasRelativeHeight() const override { return false; }
-    void computeIntrinsicDimensions(const RenderElement*, Length& /* intrinsicWidth */ , Length& /* intrinsicHeight */, FloatSize& /* intrinsicRatio */) override { }
-    bool usesImageContainerSize() const override { return false; }
-    void setContainerSizeForRenderer(const RenderElement*, const FloatSize&, float) override { }
-    void addClient(RenderElement*) override { }
-    void removeClient(RenderElement*) override { }
-
-    RefPtr<Image> image(RenderElement*, const FloatSize&) const override
-    {
-        ASSERT_NOT_REACHED();
-        return nullptr;
-    }
-
-    bool knownToBeOpaque(const RenderElement*) const override { return false; }
-    
-    StylePendingImage(CSSValue* value)
-        : m_value(value)
-    {
-        m_isPendingImage = true;
-    }
-
-    CSSValue* m_value; // Not retained; it owns us.
-};
-
-} // namespace WebCore
-
-SPECIALIZE_TYPE_TRAITS_STYLE_IMAGE(StylePendingImage, isPendingImage)
-
-#endif // StylePendingImage_h
index b02a586..d996cf5 100644 (file)
 #include "config.h"
 #include "StylePendingResources.h"
 
+#include "CSSCursorImageValue.h"
+#include "CSSImageGeneratorValue.h"
+#include "CSSImageSetValue.h"
+#include "CSSImageValue.h"
 #include "CachedResourceLoader.h"
 #include "CachedSVGDocumentReference.h"
 #include "ContentData.h"
 #include "SVGURIReference.h"
 #include "StyleCachedImage.h"
 #include "StyleGeneratedImage.h"
-#include "StylePendingImage.h"
 #include "TransformFunctions.h"
 
 namespace WebCore {
 namespace Style {
 
 enum class LoadPolicy { Normal, ShapeOutside };
-static RefPtr<StyleImage> loadPendingImage(Document& document, const StyleImage& image, const Element* element, LoadPolicy loadPolicy = LoadPolicy::Normal)
+static void loadPendingImage(Document& document, const StyleImage* styleImage, const Element* element, LoadPolicy loadPolicy = LoadPolicy::Normal)
 {
-    auto& pendingImage = downcast<StylePendingImage>(image);
+    if (!styleImage || !styleImage->isPending())
+        return;
+
     ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
     options.contentSecurityPolicyImposition = element && element->isInUserAgentShadowTree() ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
 
@@ -55,21 +60,26 @@ static RefPtr<StyleImage> loadPendingImage(Document& document, const StyleImage&
         options.allowCredentials = DoNotAllowStoredCredentials;
     }
 
-    if (auto imageValue = pendingImage.cssImageValue())
-        return imageValue->cachedImage(document.cachedResourceLoader(), options);
-
-    if (auto imageGeneratorValue = pendingImage.cssImageGeneratorValue()) {
-        imageGeneratorValue->loadSubimages(document.cachedResourceLoader(), options);
-        return StyleGeneratedImage::create(*imageGeneratorValue);
-    }
+    auto cssValue = const_cast<StyleImage*>(styleImage)->cssValue();
+    if (is<CSSImageValue>(cssValue.get())) {
+        downcast<CSSImageValue>(*cssValue).loadImage(document.cachedResourceLoader(), options);
+        return;
+    };
 
-    if (auto cursorImageValue = pendingImage.cssCursorImageValue())
-        return cursorImageValue->cachedImage(document.cachedResourceLoader(), options);
+    if (is<CSSImageSetValue>(cssValue.get())) {
+        downcast<CSSImageSetValue>(*cssValue).loadBestFitImage(document.cachedResourceLoader(), options);
+        return;
+    };
 
-    if (auto imageSetValue = pendingImage.cssImageSetValue())
-        return imageSetValue->bestFitImage(document.cachedResourceLoader(), options);
+    if (is<CSSImageGeneratorValue>(cssValue.get())) {
+        downcast<CSSImageGeneratorValue>(*cssValue).loadSubimages(document.cachedResourceLoader(), options);
+        return;
+    };
 
-    return nullptr;
+    if (is<CSSCursorImageValue>(cssValue.get())) {
+        downcast<CSSCursorImageValue>(*cssValue).loadImage(document.cachedResourceLoader(), options);
+        return;
+    };
 }
 
 static void loadPendingImages(const PendingResources& pendingResources, Document& document, RenderStyle& style, const Element* element)
@@ -77,82 +87,52 @@ static void loadPendingImages(const PendingResources& pendingResources, Document
     for (auto currentProperty : pendingResources.pendingImages.keys()) {
         switch (currentProperty) {
         case CSSPropertyBackgroundImage: {
-            for (FillLayer* backgroundLayer = &style.ensureBackgroundLayers(); backgroundLayer; backgroundLayer = backgroundLayer->next()) {
-                auto* styleImage = backgroundLayer->image();
-                if (is<StylePendingImage>(styleImage))
-                    backgroundLayer->setImage(loadPendingImage(document, *styleImage, element));
-            }
+            for (auto* backgroundLayer = &style.ensureBackgroundLayers(); backgroundLayer; backgroundLayer = backgroundLayer->next())
+                loadPendingImage(document, backgroundLayer->image(), element);
             break;
         }
         case CSSPropertyContent: {
-            for (ContentData* contentData = const_cast<ContentData*>(style.contentData()); contentData; contentData = contentData->next()) {
+            for (auto* contentData = const_cast<ContentData*>(style.contentData()); contentData; contentData = contentData->next()) {
                 if (is<ImageContentData>(*contentData)) {
                     auto& styleImage = downcast<ImageContentData>(*contentData).image();
-                    if (is<StylePendingImage>(styleImage)) {
-                        if (auto loadedImage = loadPendingImage(document, styleImage, element))
-                            downcast<ImageContentData>(*contentData).setImage(WTFMove(loadedImage));
-                    }
+                    loadPendingImage(document, &styleImage, element);
                 }
             }
             break;
         }
         case CSSPropertyCursor: {
-            if (CursorList* cursorList = style.cursors()) {
-                for (size_t i = 0; i < cursorList->size(); ++i) {
-                    CursorData& currentCursor = cursorList->at(i);
-                    auto* styleImage = currentCursor.image();
-                    if (is<StylePendingImage>(styleImage))
-                        currentCursor.setImage(loadPendingImage(document, *styleImage, element));
-                }
+            if (auto* cursorList = style.cursors()) {
+                for (size_t i = 0; i < cursorList->size(); ++i)
+                    loadPendingImage(document, cursorList->at(i).image(), element);
             }
             break;
         }
         case CSSPropertyListStyleImage: {
-            auto* styleImage = style.listStyleImage();
-            if (is<StylePendingImage>(styleImage))
-                style.setListStyleImage(loadPendingImage(document, *styleImage, element));
+            loadPendingImage(document, style.listStyleImage(), element);
             break;
         }
         case CSSPropertyBorderImageSource: {
-            auto* styleImage = style.borderImageSource();
-            if (is<StylePendingImage>(styleImage))
-                style.setBorderImageSource(loadPendingImage(document, *styleImage, element));
+            loadPendingImage(document, style.borderImageSource(), element);
             break;
         }
         case CSSPropertyWebkitBoxReflect: {
-            if (StyleReflection* reflection = style.boxReflect()) {
-                const NinePieceImage& maskImage = reflection->mask();
-                auto* styleImage = maskImage.image();
-                if (is<StylePendingImage>(styleImage)) {
-                    auto loadedImage = loadPendingImage(document, *styleImage, element);
-                    reflection->setMask(NinePieceImage(WTFMove(loadedImage), maskImage.imageSlices(), maskImage.fill(), maskImage.borderSlices(), maskImage.outset(), maskImage.horizontalRule(), maskImage.verticalRule()));
-                }
-            }
+            if (auto* reflection = style.boxReflect())
+                loadPendingImage(document, reflection->mask().image(), element);
             break;
         }
         case CSSPropertyWebkitMaskBoxImageSource: {
-            auto* styleImage = style.maskBoxImageSource();
-            if (is<StylePendingImage>(styleImage))
-                style.setMaskBoxImageSource(loadPendingImage(document, *styleImage, element));
+            loadPendingImage(document, style.maskBoxImageSource(), element);
             break;
         }
         case CSSPropertyWebkitMaskImage: {
-            for (FillLayer* maskLayer = &style.ensureMaskLayers(); maskLayer; maskLayer = maskLayer->next()) {
-                auto* styleImage = maskLayer->image();
-                if (is<StylePendingImage>(styleImage))
-                    maskLayer->setImage(loadPendingImage(document, *styleImage, element));
-            }
+            for (auto* maskLayer = &style.ensureMaskLayers(); maskLayer; maskLayer = maskLayer->next())
+                loadPendingImage(document, maskLayer->image(), element);
             break;
         }
 #if ENABLE(CSS_SHAPES)
         case CSSPropertyWebkitShapeOutside: {
-            if (!style.shapeOutside())
-                return;
-
-            StyleImage* image = style.shapeOutside()->image();
-            if (is<StylePendingImage>(image))
-                style.shapeOutside()->setImage(loadPendingImage(document, *image, element, LoadPolicy::ShapeOutside));
-
+            if (style.shapeOutside())
+                loadPendingImage(document, style.shapeOutside()->image(), element, LoadPolicy::ShapeOutside);
             break;
         }
 #endif