Title: [146227] trunk
Revision
146227
Author
[email protected]
Date
2013-03-19 11:39:18 -0700 (Tue, 19 Mar 2013)

Log Message

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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (146226 => 146227)


--- trunk/LayoutTests/ChangeLog	2013-03-19 18:31:05 UTC (rev 146226)
+++ trunk/LayoutTests/ChangeLog	2013-03-19 18:39:18 UTC (rev 146227)
@@ -1,3 +1,13 @@
+2013-03-19  Philip Rogers  <[email protected]>
+
+        Separate SVG image size and container size
+        https://bugs.webkit.org/show_bug.cgi?id=112651
+
+        Reviewed by Stephen Chenney.
+
+        * svg/as-image/svg-container-size-after-reload-expected.txt: Added.
+        * svg/as-image/svg-container-size-after-reload.html: Added.
+
 2013-03-19  Terry Anderson  <[email protected]>
 
         Hover effects from a GestureTapDown are dismissed by a GestureTap on the hover element

Added: trunk/LayoutTests/svg/as-image/svg-container-size-after-reload-expected.txt (0 => 146227)


--- trunk/LayoutTests/svg/as-image/svg-container-size-after-reload-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/svg/as-image/svg-container-size-after-reload-expected.txt	2013-03-19 18:39:18 UTC (rev 146227)
@@ -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
+

Added: trunk/LayoutTests/svg/as-image/svg-container-size-after-reload.html (0 => 146227)


--- trunk/LayoutTests/svg/as-image/svg-container-size-after-reload.html	                        (rev 0)
+++ trunk/LayoutTests/svg/as-image/svg-container-size-after-reload.html	2013-03-19 18:39:18 UTC (rev 146227)
@@ -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: trunk/Source/WebCore/ChangeLog (146226 => 146227)


--- trunk/Source/WebCore/ChangeLog	2013-03-19 18:31:05 UTC (rev 146226)
+++ trunk/Source/WebCore/ChangeLog	2013-03-19 18:39:18 UTC (rev 146227)
@@ -1,3 +1,38 @@
+2013-03-19  Philip Rogers  <[email protected]>
+
+        Separate SVG image size and container size
+        https://bugs.webkit.org/show_bug.cgi?id=112651
+
+        Reviewed by Stephen Chenney.
+
+        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.
+
 2013-03-19  Joshua Bell  <[email protected]>
 
         IndexedDB: Use integer plumbing for deleteDatabase onVersionChange calls

Modified: trunk/Source/WebCore/svg/graphics/SVGImage.cpp (146226 => 146227)


--- trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2013-03-19 18:31:05 UTC (rev 146226)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2013-03-19 18:39:18 UTC (rev 146227)
@@ -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: trunk/Source/WebCore/svg/graphics/SVGImage.h (146226 => 146227)


--- trunk/Source/WebCore/svg/graphics/SVGImage.h	2013-03-19 18:31:05 UTC (rev 146226)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.h	2013-03-19 18:39:18 UTC (rev 146227)
@@ -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: trunk/Source/WebCore/svg/graphics/SVGImageCache.cpp (146226 => 146227)


--- trunk/Source/WebCore/svg/graphics/SVGImageCache.cpp	2013-03-19 18:31:05 UTC (rev 146226)
+++ trunk/Source/WebCore/svg/graphics/SVGImageCache.cpp	2013-03-19 18:39:18 UTC (rev 146227)
@@ -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
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to