Title: [146635] branches/chromium/1410
Revision
146635
Author
p...@google.com
Date
2013-03-22 11:30:45 -0700 (Fri, 22 Mar 2013)

Log Message

Merge 146227 "Separate SVG image size and container size"

> Separate SVG image size and container size
> https://bugs.webkit.org/show_bug.cgi?id=112651
> 
> Reviewed by Stephen Chenney.
> 
> Source/WebCore:
> 
> Previously, SVG images could retain their cached size between reloads due to a bug where an
> old container size would be re-used if the image's new container size was not available yet.
> 
> This patch changes SVGImage::size() to return the intrinsic size of the image before a
> container size has been set. SVGImageCache::imageSizeForRenderer will now return the
> image's intrinsic size instead of a cached value if the container size cannot be looked up.
> In _javascript_, querying [SVGImage].width will now return either the image's intrinsic size
> or the size of 'imageForContainer'.
> 
> Test: svg/as-image/svg-container-size-after-reload.html
> 
> * svg/graphics/SVGImage.cpp:
> (WebCore::SVGImage::setContainerSize):
> (WebCore::SVGImage::containerSize):
> (WebCore::SVGImage::draw):
> (WebCore::SVGImage::dataChanged):
> * svg/graphics/SVGImage.h:
> 
>     The member variable 'm_intrinsicSize' has been added to track the image's intrinsic
>     size. This term can be found in: http://www.w3.org/TR/css3-images/#default-sizing
> 
> * svg/graphics/SVGImageCache.cpp:
> (WebCore::SVGImageCache::imageSizeForRenderer):
> (WebCore::SVGImageCache::imageForRenderer):
> 
>     In both of these functions, image has been renamed to imageForContainer here to clarify
>     that the cached container size is being returned, not the image's intrinsic size.
> 
> LayoutTests:
> 
> * svg/as-image/svg-container-size-after-reload-expected.txt: Added.
> * svg/as-image/svg-container-size-after-reload.html: Added.
> 

TBR=p...@google.com
Review URL: https://codereview.chromium.org/13008026

Modified Paths

Added Paths

Diff

Copied: branches/chromium/1410/LayoutTests/svg/as-image/svg-container-size-after-reload-expected.txt (from rev 146227, trunk/LayoutTests/svg/as-image/svg-container-size-after-reload-expected.txt) (0 => 146635)


--- branches/chromium/1410/LayoutTests/svg/as-image/svg-container-size-after-reload-expected.txt	                        (rev 0)
+++ branches/chromium/1410/LayoutTests/svg/as-image/svg-container-size-after-reload-expected.txt	2013-03-22 18:30:45 UTC (rev 146635)
@@ -0,0 +1,10 @@
+Test for WK112651: SVG image container size should not survive reloads.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS image2.width is 100
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Copied: branches/chromium/1410/LayoutTests/svg/as-image/svg-container-size-after-reload.html (from rev 146227, trunk/LayoutTests/svg/as-image/svg-container-size-after-reload.html) (0 => 146635)


--- branches/chromium/1410/LayoutTests/svg/as-image/svg-container-size-after-reload.html	                        (rev 0)
+++ branches/chromium/1410/LayoutTests/svg/as-image/svg-container-size-after-reload.html	2013-03-22 18:30:45 UTC (rev 146635)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+jsTestIsAsync = true;
+description("Test for WK112651: SVG image container size should not survive reloads.");
+
+function runTest() {
+    var image1 = document.getElementById('image1');
+    image1.src = "" xmlns='http://www.w3.org/2000/svg' width='100' height='100'><rect width='100%' height='100%' fill='green'/></svg>";
+    image1._onload_ = function() {
+        image1.setAttribute('width', image1.width + 50);
+        var image2 = document.getElementById('image2');
+        image2.src = ""
+        image2._onload_ = function() {
+            shouldBe("image2.width", "100");
+            finishJSTest();
+        }
+    }
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<img id="image1"><img id="image2">
+<script src=""
+</body>
+</html>

Modified: branches/chromium/1410/Source/WebCore/svg/graphics/SVGImage.cpp (146634 => 146635)


--- branches/chromium/1410/Source/WebCore/svg/graphics/SVGImage.cpp	2013-03-22 18:28:36 UTC (rev 146634)
+++ branches/chromium/1410/Source/WebCore/svg/graphics/SVGImage.cpp	2013-03-22 18:30:45 UTC (rev 146635)
@@ -74,12 +74,12 @@
         return;
 
     FrameView* view = frameView();
-    view->resize(this->size());
+    view->resize(this->containerSize());
 
     renderer->setContainerSize(size);
 }
 
-IntSize SVGImage::size() const
+IntSize SVGImage::containerSize() const
 {
     if (!m_page)
         return IntSize();
@@ -192,7 +192,7 @@
     context->translate(destOffset.x(), destOffset.y());
     context->scale(scale);
 
-    view->resize(size());
+    view->resize(containerSize());
 
     if (view->needsLayout())
         view->layout();
@@ -336,6 +336,9 @@
         loader->activeDocumentLoader()->writer()->begin(KURL()); // create the empty document
         loader->activeDocumentLoader()->writer()->addData(data()->data(), data()->size());
         loader->activeDocumentLoader()->writer()->end();
+
+        // Set the intrinsic size before a container size is available.
+        m_intrinsicSize = containerSize();
     }
 
     return m_page;

Modified: branches/chromium/1410/Source/WebCore/svg/graphics/SVGImage.h (146634 => 146635)


--- branches/chromium/1410/Source/WebCore/svg/graphics/SVGImage.h	2013-03-22 18:28:36 UTC (rev 146634)
+++ branches/chromium/1410/Source/WebCore/svg/graphics/SVGImage.h	2013-03-22 18:30:45 UTC (rev 146635)
@@ -51,7 +51,7 @@
     FrameView* frameView() const;
 
     virtual bool isSVGImage() const { return true; }
-    virtual IntSize size() const;
+    virtual IntSize size() const OVERRIDE { return m_intrinsicSize; }
 
     virtual bool hasRelativeWidth() const;
     virtual bool hasRelativeHeight() const;
@@ -71,6 +71,7 @@
     virtual String filenameExtension() const;
 
     virtual void setContainerSize(const IntSize&);
+    IntSize containerSize() const;
     virtual bool usesContainerSize() const { return true; }
     virtual void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
 
@@ -94,6 +95,7 @@
 
     OwnPtr<SVGImageChromeClient> m_chromeClient;
     OwnPtr<Page> m_page;
+    IntSize m_intrinsicSize;
 };
 }
 

Modified: branches/chromium/1410/Source/WebCore/svg/graphics/SVGImageCache.cpp (146634 => 146635)


--- branches/chromium/1410/Source/WebCore/svg/graphics/SVGImageCache.cpp	2013-03-22 18:28:36 UTC (rev 146634)
+++ branches/chromium/1410/Source/WebCore/svg/graphics/SVGImageCache.cpp	2013-03-22 18:30:45 UTC (rev 146635)
@@ -74,9 +74,9 @@
     if (it == m_imageForContainerMap.end())
         return imageSize;
 
-    RefPtr<SVGImageForContainer> image = it->value;
-    ASSERT(!image->size().isEmpty());
-    return image->size();
+    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
@@ -90,9 +90,9 @@
     if (it == m_imageForContainerMap.end())
         return Image::nullImage();
 
-    RefPtr<SVGImageForContainer> image = it->value;
-    ASSERT(!image->size().isEmpty());
-    return image.get();
+    RefPtr<SVGImageForContainer> imageForContainer = it->value;
+    ASSERT(!imageForContainer->size().isEmpty());
+    return imageForContainer.get();
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to