Followup (r220289): RenderImageResourceStyleImage code clean up
[WebKit-https.git] / Source / WebCore / rendering / RenderImageResource.cpp
index d8de5f9..3051495 100644 (file)
@@ -40,51 +40,45 @@ RenderImageResource::RenderImageResource()
 {
 }
 
-RenderImageResource::~RenderImageResource()
-{
-}
-
-void RenderImageResource::initialize(RenderElement* renderer)
+void RenderImageResource::initialize(RenderElement& renderer, CachedImage* styleCachedImage)
 {
     ASSERT(!m_renderer);
-    ASSERT(renderer);
-    m_renderer = renderer;
+    ASSERT(!m_cachedImage);
+    m_renderer = &renderer;
+    m_cachedImage = styleCachedImage;
+    m_cachedImageRemoveClientIsNeeded = !styleCachedImage;
 }
 
 void RenderImageResource::shutdown()
 {
-    if (!m_cachedImage)
-        return;
-
-    ASSERT(m_renderer);
     image()->stopAnimation();
-    m_cachedImage->removeClient(*m_renderer);
+    setCachedImage(nullptr);
 }
 
 void RenderImageResource::setCachedImage(CachedImage* newImage)
 {
-    ASSERT(m_renderer);
-
     if (m_cachedImage == newImage)
         return;
 
-    if (m_cachedImage)
+    ASSERT(m_renderer);
+    if (m_cachedImage && m_cachedImageRemoveClientIsNeeded)
         m_cachedImage->removeClient(*m_renderer);
     m_cachedImage = newImage;
-    if (m_cachedImage) {
-        m_cachedImage->addClient(*m_renderer);
-        if (m_cachedImage->errorOccurred())
-            m_renderer->imageChanged(m_cachedImage.get());
-    }
+    m_cachedImageRemoveClientIsNeeded = true;
+    if (!m_cachedImage)
+        return;
+
+    m_cachedImage->addClient(*m_renderer);
+    if (m_cachedImage->errorOccurred())
+        m_renderer->imageChanged(m_cachedImage.get());
 }
 
 void RenderImageResource::resetAnimation()
 {
-    ASSERT(m_renderer);
-
     if (!m_cachedImage)
         return;
 
+    ASSERT(m_renderer);
     image()->resetAnimation();
 
     if (!m_renderer->needsLayout())
@@ -93,42 +87,22 @@ void RenderImageResource::resetAnimation()
 
 RefPtr<Image> RenderImageResource::image(const IntSize&) const
 {
-    return m_cachedImage ? m_cachedImage->imageForRenderer(m_renderer) : &Image::nullImage();
-}
-
-bool RenderImageResource::errorOccurred() const
-{
-    return m_cachedImage && m_cachedImage->errorOccurred();
+    if (!m_cachedImage)
+        return &Image::nullImage();
+    if (auto image = m_cachedImage->imageForRenderer(m_renderer))
+        return image;
+    return &Image::nullImage();
 }
 
 void RenderImageResource::setContainerSizeForRenderer(const IntSize& imageContainerSize)
 {
+    if (!m_cachedImage)
+        return;
     ASSERT(m_renderer);
-    if (m_cachedImage)
-        m_cachedImage->setContainerSizeForRenderer(m_renderer, imageContainerSize, m_renderer->style().effectiveZoom());
-}
-
-bool RenderImageResource::imageHasRelativeWidth() const
-{
-    return m_cachedImage ? m_cachedImage->imageHasRelativeWidth() : false;
-}
-
-bool RenderImageResource::imageHasRelativeHeight() const
-{
-    return m_cachedImage ? m_cachedImage->imageHasRelativeHeight() : false;
-}
-
-LayoutSize RenderImageResource::imageSize(float multiplier) const
-{
-    return getImageSize(multiplier, CachedImage::UsedSize);
-}
-
-LayoutSize RenderImageResource::intrinsicSize(float multiplier) const
-{
-    return getImageSize(multiplier, CachedImage::IntrinsicSize);
+    m_cachedImage->setContainerSizeForRenderer(m_renderer, imageContainerSize, m_renderer->style().effectiveZoom());
 }
 
-LayoutSize RenderImageResource::getImageSize(float multiplier, CachedImage::SizeType type) const
+LayoutSize RenderImageResource::imageSize(float multiplier, CachedImage::SizeType type) const
 {
     if (!m_cachedImage)
         return LayoutSize();