Fix <rdar://problem/5668517> REGRESSION: Major under painting issues in SVG (carto...
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Jan 2008 07:15:25 +0000 (07:15 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Jan 2008 07:15:25 +0000 (07:15 +0000)
Revied by Maciej.

We need to cache the absolute bounds of the <image>,
as there's no reliable way to recompute the old bounding
box one we have started layout.

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

LayoutTests/ChangeLog
LayoutTests/svg/custom/repaint-on-image-bounds-change-expected.checksum [new file with mode: 0644]
LayoutTests/svg/custom/repaint-on-image-bounds-change-expected.png [new file with mode: 0644]
LayoutTests/svg/custom/repaint-on-image-bounds-change-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/repaint-on-image-bounds-change.svg [new file with mode: 0644]
WebCore/ChangeLog
WebCore/rendering/RenderSVGImage.cpp
WebCore/rendering/RenderSVGImage.h

index 6a726ea..9a9c07b 100644 (file)
@@ -1,3 +1,14 @@
+2008-01-03  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Maciej.
+
+        Testcase for <rdar://problem/5668517> REGRESSION: Major under painting issues in SVG
+
+        * svg/custom/repaint-on-image-bounds-change-expected.checksum: Copied from LayoutTests/svg/custom/resource-client-removal-expected.checksum.
+        * svg/custom/repaint-on-image-bounds-change-expected.png: Copied from LayoutTests/svg/custom/resource-client-removal-expected.png.
+        * svg/custom/repaint-on-image-bounds-change-expected.txt: Added.
+        * svg/custom/repaint-on-image-bounds-change.svg: Added.
+
 2008-01-03  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Sam Weinig.
diff --git a/LayoutTests/svg/custom/repaint-on-image-bounds-change-expected.checksum b/LayoutTests/svg/custom/repaint-on-image-bounds-change-expected.checksum
new file mode 100644 (file)
index 0000000..3a4f1f7
--- /dev/null
@@ -0,0 +1 @@
+16310588467cfc20d551635abc59b784
\ No newline at end of file
diff --git a/LayoutTests/svg/custom/repaint-on-image-bounds-change-expected.png b/LayoutTests/svg/custom/repaint-on-image-bounds-change-expected.png
new file mode 100644 (file)
index 0000000..3db2634
Binary files /dev/null and b/LayoutTests/svg/custom/repaint-on-image-bounds-change-expected.png differ
diff --git a/LayoutTests/svg/custom/repaint-on-image-bounds-change-expected.txt b/LayoutTests/svg/custom/repaint-on-image-bounds-change-expected.txt
new file mode 100644 (file)
index 0000000..fcd559d
--- /dev/null
@@ -0,0 +1,6 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderSVGRoot {svg} at (0,0) size 100x100
+    RenderPath {rect} at (0,0) size 100x100 [fill={[type=SOLID] [color=#008000]}] [data="M0.00,0.00L100.00,0.00L100.00,100.00L0.00,100.00"]
+    RenderImage {image} at (0,0) size 0x0
diff --git a/LayoutTests/svg/custom/repaint-on-image-bounds-change.svg b/LayoutTests/svg/custom/repaint-on-image-bounds-change.svg
new file mode 100644 (file)
index 0000000..a9092b8
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" onload="runRepaintTest()" >
+<script type="text/ecmascript">
+<![CDATA[
+// This is used to test that we correctly invalidate the original image bounds when the 
+// image attributes are changed.  A correct result will be a 100x100px green square
+function repaintTest() {
+    var target = document.getElementById("target");
+    target.setAttributeNS(null,"width", 0);
+    target.setAttributeNS(null,"height", 0);
+    target.setAttributeNS(null,"x", 50);
+    target.setAttributeNS(null,"y", 50);
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+    
+}
+
+function runRepaintTest()
+{
+    if (window.layoutTestController) {
+        layoutTestController.display();
+        layoutTestController.waitUntilDone();
+    }
+    setTimeout(repaintTest, 50);
+}
+
+]]>
+</script>
+<rect x="0" y="0" width="100" height="100" fill="green" stroke="none"/>
+<image xlink:href="../../css2.1/support/swatch-red.png" id="target" x="0" y="0" width="100" height="100" />
+</svg>
\ No newline at end of file
index d27b3dd..580832e 100644 (file)
@@ -1,3 +1,18 @@
+2008-01-03  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Maciej.
+
+        Fix <rdar://problem/5668517> REGRESSION: Major under painting issues in SVG (carto.net dock example)
+
+        We need to cache the absolute bounds of the <image>,
+        as there's no reliable way to recompute the old bounding
+        box one we have started layout.
+
+        * rendering/RenderSVGImage.cpp:
+        (WebCore::RenderSVGImage::layout):
+        (WebCore::RenderSVGImage::calculateAbsoluteBounds):
+        * rendering/RenderSVGImage.h:
+
 2008-01-03  Alp Toker  <alp@atoker.com>
 
         Reviewed by Mark Rowe.
index 3ed861c..fbefc50 100644 (file)
@@ -151,6 +151,7 @@ void RenderSVGImage::layout()
     
     calcWidth();
     calcHeight();
+    calculateAbsoluteBounds();
 
     if (checkForRepaint)
         repaintAfterLayoutIfNeeded(oldBounds, oldOutlineBox);
@@ -239,21 +240,26 @@ void RenderSVGImage::imageChanged(CachedImage* image)
     repaintRectangle(absoluteClippedOverflowRect());
 }
 
-IntRect RenderSVGImage::absoluteClippedOverflowRect()
+void RenderSVGImage::calculateAbsoluteBounds()
 {
-    FloatRect repaintRect = absoluteTransform().mapRect(relativeBBox(true));
+    FloatRect absoluteRect = absoluteTransform().mapRect(relativeBBox(true));
 
 #if ENABLE(SVG_FILTERS)
     // Filters can expand the bounding box
     SVGResourceFilter* filter = getFilterById(document(), SVGURIReference::getTarget(style()->svgStyle()->filter()));
     if (filter)
-        repaintRect.unite(filter->filterBBoxForItemBBox(repaintRect));
+        absoluteRect.unite(filter->filterBBoxForItemBBox(absoluteRect));
 #endif
 
-    if (!repaintRect.isEmpty())
-        repaintRect.inflate(1); // inflate 1 pixel for antialiasing
+    if (!absoluteRect.isEmpty())
+        absoluteRect.inflate(1.5f); // inflate 1 pixel for antialiasing, 0.5 due to subpixel position or dimensions.
+
+    m_absoluteBounds = enclosingIntRect(absoluteRect);
+}
 
-    return enclosingIntRect(repaintRect);
+IntRect RenderSVGImage::absoluteClippedOverflowRect()
+{
+    return m_absoluteBounds;
 }
 
 void RenderSVGImage::addFocusRingRects(GraphicsContext* graphicsContext, int tx, int ty)
index c38841e..38330bc 100644 (file)
@@ -62,10 +62,12 @@ namespace WebCore {
         bool calculateLocalTransform();
 
     private:
+        void calculateAbsoluteBounds();
         AffineTransform translationForAttributes();
         AffineTransform m_localTransform;
         float m_imageWidth;
         float m_imageHeight;
+        IntRect m_absoluteBounds;
     };
 
 } // namespace WebCore