Use modern for-loops in WebCore/svg.
[WebKit-https.git] / Source / WebCore / svg / graphics / SVGImageCache.cpp
index f1e6b8e..98e50f6 100644 (file)
 #include "config.h"
 #include "SVGImageCache.h"
 
-#if ENABLE(SVG)
-#include "CachedImage.h"
 #include "FrameView.h"
 #include "GraphicsContext.h"
+#include "HTMLImageElement.h"
 #include "ImageBuffer.h"
+#include "LayoutSize.h"
 #include "Page.h"
 #include "RenderSVGRoot.h"
 #include "SVGImage.h"
@@ -48,31 +48,24 @@ void SVGImageCache::removeClientFromCache(const CachedImageClient* client)
 {
     ASSERT(client);
 
-    if (m_imageForContainerMap.contains(client))
-        m_imageForContainerMap.remove(client);
+    m_imageForContainerMap.remove(client);
 }
 
-void SVGImageCache::setContainerSizeForRenderer(const CachedImageClient* client, const IntSize& containerSize, float containerZoom)
+void SVGImageCache::setContainerSizeForRenderer(const CachedImageClient* client, const LayoutSize& containerSize, float containerZoom)
 {
     ASSERT(client);
     ASSERT(!containerSize.isEmpty());
+    ASSERT(containerZoom);
 
     FloatSize containerSizeWithoutZoom(containerSize);
     containerSizeWithoutZoom.scale(1 / containerZoom);
 
-    ImageForContainerMap::iterator imageIt = m_imageForContainerMap.find(client);
-    if (imageIt == m_imageForContainerMap.end()) {
-        RefPtr<SVGImageForContainer> image = SVGImageForContainer::create(m_svgImage, containerSizeWithoutZoom, 1, containerZoom);
-        m_imageForContainerMap.set(client, image);
-    } else {
-        imageIt->value->setSize(containerSizeWithoutZoom);
-        imageIt->value->setZoom(containerZoom);
-    }
+    m_imageForContainerMap.set(client, SVGImageForContainer::create(m_svgImage, containerSizeWithoutZoom, containerZoom));
 }
 
-IntSize SVGImageCache::imageSizeForRenderer(const RenderObject* renderer) const
+FloatSize SVGImageCache::imageSizeForRenderer(const RenderObject* renderer) const
 {
-    IntSize imageSize = m_svgImage->size();
+    FloatSize imageSize = m_svgImage->size();
     if (!renderer)
         return imageSize;
 
@@ -80,15 +73,9 @@ IntSize SVGImageCache::imageSizeForRenderer(const RenderObject* renderer) const
     if (it == m_imageForContainerMap.end())
         return imageSize;
 
-    RefPtr<SVGImageForContainer> image = it->value;
-    FloatSize size = image->containerSize();
-    if (!size.isEmpty()) {
-        size.scale(image->zoom());
-        imageSize.setWidth(size.width());
-        imageSize.setHeight(size.height());
-    }
-
-    return imageSize;
+    RefPtr<SVGImageForContainer> imageForContainer = it->value;
+    ASSERT(!imageForContainer->size().isEmpty());
+    return imageForContainer->size();
 }
 
 // FIXME: This doesn't take into account the animation timeline so animations will not
@@ -98,21 +85,21 @@ Image* SVGImageCache::imageForRenderer(const RenderObject* renderer)
     if (!renderer)
         return Image::nullImage();
 
-    // The cache needs to know the size of the renderer before querying an image for it.
     ImageForContainerMap::iterator it = m_imageForContainerMap.find(renderer);
     if (it == m_imageForContainerMap.end())
         return Image::nullImage();
 
-    RefPtr<SVGImageForContainer> image = it->value;
-    ASSERT(!image->containerSize().isEmpty());
-
-    // FIXME: Set the page scale in setContainerSizeForRenderer instead of looking it up here.
-    Page* page = renderer->document()->page();
-    image->setPageScale(page->deviceScaleFactor() * page->pageScaleFactor());
-
-    return image.get();
+    RefPtr<SVGImageForContainer> imageForContainer = it->value;
+    
+    Node* node = renderer->node();
+    if (is<HTMLImageElement>(node)) {
+        const AtomicString& urlString = downcast<HTMLImageElement>(*node).imageSourceURL();
+        URL url = node->document().completeURL(urlString);
+        imageForContainer->setURL(url);
+    }
+        
+    ASSERT(!imageForContainer->size().isEmpty());
+    return imageForContainer.get();
 }
 
 } // namespace WebCore
-
-#endif // ENABLE(SVG)