Title: [136424] trunk
Revision
136424
Author
p...@google.com
Date
2012-12-03 11:44:11 -0800 (Mon, 03 Dec 2012)

Log Message

Source/WebCore: Invalidate SVG width on width attribute changes.
https://bugs.webkit.org/show_bug.cgi?id=103304

Reviewed by Dirk Schulze.

An inline SVG element's replaced width can depend on both attributes and style properties.
After r105513, we invalidated this width on style changes but not attribute changes. With
this patch we invalidate the replaced width on width attribute changes too. Note that height
is handled differently for replaced elements so only the width attribute needs this handling
(the added test covers this too).

Test: svg/custom/root-size-attribute-changes.html

* svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::svgAttributeChanged):

LayoutTests: Invalidate SVG width on width attribute change.
https://bugs.webkit.org/show_bug.cgi?id=103304

Reviewed by Dirk Schulze.

* svg/custom/root-size-attribute-changes-expected.html: Added.
* svg/custom/root-size-attribute-changes.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (136423 => 136424)


--- trunk/LayoutTests/ChangeLog	2012-12-03 19:36:47 UTC (rev 136423)
+++ trunk/LayoutTests/ChangeLog	2012-12-03 19:44:11 UTC (rev 136424)
@@ -1,3 +1,13 @@
+2012-12-03  Philip Rogers  <p...@google.com>
+
+        Invalidate SVG width on width attribute change.
+        https://bugs.webkit.org/show_bug.cgi?id=103304
+
+        Reviewed by Dirk Schulze.
+
+        * svg/custom/root-size-attribute-changes-expected.html: Added.
+        * svg/custom/root-size-attribute-changes.html: Added.
+
 2012-12-03  Stephen White  <senorbla...@chromium.org>
 
         [chromium] Turn on the new Skia mask blur algorithm.

Added: trunk/LayoutTests/svg/custom/root-size-attribute-changes-expected.html (0 => 136424)


--- trunk/LayoutTests/svg/custom/root-size-attribute-changes-expected.html	                        (rev 0)
+++ trunk/LayoutTests/svg/custom/root-size-attribute-changes-expected.html	2012-12-03 19:44:11 UTC (rev 136424)
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML>
+<html>
+<style>
+  body { line-height: 10px; }
+</style>
+<body>
+<p id="description">Test changing of SVG size attributes. This test passes if there is a green square and no red.</p>
+<svg id="svg" width="300" height="300">
+  <rect x="0" y="0" width="100" height="100" fill="green"/>
+</svg>
+</body>
+</html>

Added: trunk/LayoutTests/svg/custom/root-size-attribute-changes.html (0 => 136424)


--- trunk/LayoutTests/svg/custom/root-size-attribute-changes.html	                        (rev 0)
+++ trunk/LayoutTests/svg/custom/root-size-attribute-changes.html	2012-12-03 19:44:11 UTC (rev 136424)
@@ -0,0 +1,51 @@
+<!DOCTYPE HTML>
+<html>
+<style>
+  body { line-height: 10px; }
+</style>
+<script>
+function runTest() {
+  if (window.testRunner)
+    testRunner.waitUntilDone();
+
+  // Defer to allow the initial layout.
+  setTimeout(function() {
+    // This test works by collapsing each svg element into a 100 x 25 green square
+    // so, together, they form a 100 x 100 green square.
+    var svg1 = document.getElementById('svg1');
+    svg1.setAttribute('width', '100px');
+    var svg2 = document.getElementById('svg2');
+    svg2.setAttribute('height', '25px');
+    var svg3 = document.getElementById('svg3');
+    svg3.style.width = "100px";
+    var svg4 = document.getElementById('svg4');
+    svg4.style.height = "25px";
+    if (window.testRunner)
+      testRunner.notifyDone();
+  }, 0);
+}
+</script>
+<body _onload_="runTest()">
+<p id="description">Test changing of SVG size attributes. This test passes if there is a green square and no red.</p>
+<svg id="svg1" width="300" height="25">
+  <rect x="0" y="0" width="200" height="100" fill="red" />
+  <rect x="0" y="0" width="100" height="25" fill="green" />
+</svg>
+<br/>
+<svg id="svg2" width="100" height="50">
+  <rect x="0" y="0" width="200" height="100" fill="red" />
+  <rect x="0" y="0" width="100" height="25" fill="green" />
+</svg>
+<br/>
+<svg id="svg3" width="300" height="25">
+  <rect x="0" y="0" width="200" height="100" fill="red" />
+  <rect x="0" y="0" width="100" height="25" fill="green" />
+</svg>
+<br/>
+<svg id="svg4" width="100" height="50">
+  <rect x="0" y="0" width="200" height="100" fill="red" />
+  <rect x="0" y="0" width="100" height="25" fill="green" />
+</svg>
+<br/>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (136423 => 136424)


--- trunk/Source/WebCore/ChangeLog	2012-12-03 19:36:47 UTC (rev 136423)
+++ trunk/Source/WebCore/ChangeLog	2012-12-03 19:44:11 UTC (rev 136424)
@@ -1,3 +1,21 @@
+2012-12-03  Philip Rogers  <p...@google.com>
+
+        Invalidate SVG width on width attribute changes.
+        https://bugs.webkit.org/show_bug.cgi?id=103304
+
+        Reviewed by Dirk Schulze.
+
+        An inline SVG element's replaced width can depend on both attributes and style properties.
+        After r105513, we invalidated this width on style changes but not attribute changes. With
+        this patch we invalidate the replaced width on width attribute changes too. Note that height
+        is handled differently for replaced elements so only the width attribute needs this handling
+        (the added test covers this too).
+
+        Test: svg/custom/root-size-attribute-changes.html
+
+        * svg/SVGSVGElement.cpp:
+        (WebCore::SVGSVGElement::svgAttributeChanged):
+
 2012-12-03  Alec Flett  <alecfl...@chromium.org>
 
         IndexedDB: remove IDBDatabaseBackendInterface::transaction()

Modified: trunk/Source/WebCore/svg/SVGSVGElement.cpp (136423 => 136424)


--- trunk/Source/WebCore/svg/SVGSVGElement.cpp	2012-12-03 19:36:47 UTC (rev 136423)
+++ trunk/Source/WebCore/svg/SVGSVGElement.cpp	2012-12-03 19:44:11 UTC (rev 136424)
@@ -282,12 +282,21 @@
 void SVGSVGElement::svgAttributeChanged(const QualifiedName& attrName)
 { 
     bool updateRelativeLengthsOrViewBox = false;
-    if (attrName == SVGNames::widthAttr
+    bool widthChanged = attrName == SVGNames::widthAttr;
+    if (widthChanged
         || attrName == SVGNames::heightAttr
         || attrName == SVGNames::xAttr
         || attrName == SVGNames::yAttr) {
         updateRelativeLengthsOrViewBox = true;
         updateRelativeLengthsInformation();
+
+        // At the SVG/HTML boundary (aka RenderSVGRoot), the width attribute can
+        // affect the replaced size so we need to mark it for updating.
+        if (widthChanged) {
+            RenderObject* renderObject = renderer();
+            if (renderObject && renderObject->isSVGRoot())
+                toRenderSVGRoot(renderObject)->setNeedsLayoutAndPrefWidthsRecalc();
+        }
     }
 
     if (SVGFitToViewBox::isKnownAttribute(attrName)) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to