Title: [181165] trunk
Revision
181165
Author
commit-qu...@webkit.org
Date
2015-03-06 10:15:48 -0800 (Fri, 06 Mar 2015)

Log Message

An SVG element without intrinsic size inherits the container size as its viewport instead of inheriting the container viewport.
https://bugs.webkit.org/show_bug.cgi?id=141725.

Patch by Said Abou-Hallawa <sabouhall...@apple.com> on 2015-03-06
Reviewed by Darin Adler.

Source/WebCore:

The current viewport of the <svg> element should be retrieved from its
renderer if the renderer is available. If the renderer is not created yet,
this means the viewport is needed to calculate the size of the renderer.
In this case, we should return the element size if it is intrinsic size.

Test: svg/css/svg-css-different-intrinsic-sizes.html

* svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::currentViewportSize): Change the order for
returning the viewport of the <svg> element. We should consider the case
of a valid renderer before considering the case of an intrinsic size.

LayoutTests:

* svg/css/svg-css-different-intrinsic-sizes-expected.html: Added.
* svg/css/svg-css-different-intrinsic-sizes.html: Added.
The intrinsic size of the <svg> element is overridden by CSS. The elements
inside the <svg> should consider the css size (which is equal to the <svg>
element viewport) instead of the <svg> element intrinsic size.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (181164 => 181165)


--- trunk/LayoutTests/ChangeLog	2015-03-06 18:14:10 UTC (rev 181164)
+++ trunk/LayoutTests/ChangeLog	2015-03-06 18:15:48 UTC (rev 181165)
@@ -1,3 +1,16 @@
+2015-03-06  Said Abou-Hallawa  <sabouhall...@apple.com>
+
+        An SVG element without intrinsic size inherits the container size as its viewport instead of inheriting the container viewport.
+        https://bugs.webkit.org/show_bug.cgi?id=141725.
+
+        Reviewed by Darin Adler.
+
+        * svg/css/svg-css-different-intrinsic-sizes-expected.html: Added.
+        * svg/css/svg-css-different-intrinsic-sizes.html: Added.
+        The intrinsic size of the <svg> element is overridden by CSS. The elements
+        inside the <svg> should consider the css size (which is equal to the <svg>
+        element viewport) instead of the <svg> element intrinsic size.
+
 2015-03-06  Simon Fraser  <simon.fra...@apple.com>
 
         Allow composited clip-path to be updated without a layer repaint

Added: trunk/LayoutTests/svg/css/svg-css-different-intrinsic-sizes-expected.html (0 => 181165)


--- trunk/LayoutTests/svg/css/svg-css-different-intrinsic-sizes-expected.html	                        (rev 0)
+++ trunk/LayoutTests/svg/css/svg-css-different-intrinsic-sizes-expected.html	2015-03-06 18:15:48 UTC (rev 181165)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <style>
+    div {
+      background-image: url("data:image/svg+xml, \
+      <svg xmlns='http://www.w3.org/2000/svg'> \
+        <rect width='75' height='75' fill='yellow'/> \
+        <rect width='50' height='50' fill='lime'/> \
+        <rect width='25' height='25' fill='red'/> \
+      </svg>");
+      width: 75px;
+      height: 75px;
+    }
+  </style>
+</head>
+<body>
+  <div></div>
+  <div></div>
+  <div></div>
+  <div></div>
+  <div></div>
+  <div></div>
+  <div></div>
+</body>
+</html>

Added: trunk/LayoutTests/svg/css/svg-css-different-intrinsic-sizes.html (0 => 181165)


--- trunk/LayoutTests/svg/css/svg-css-different-intrinsic-sizes.html	                        (rev 0)
+++ trunk/LayoutTests/svg/css/svg-css-different-intrinsic-sizes.html	2015-03-06 18:15:48 UTC (rev 181165)
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <style>
+    div {
+      background: yellow;
+      width: 75px;
+      height: 75px;
+    }
+    svg {
+      background: lime;
+    }
+    svg.intrinsic-size {
+      width: 50px;
+      height: 50px;
+    }
+    rect {
+      fill: red;
+    }
+  </style>
+</head>
+<body>
+  <div>
+    <svg class='intrinsic-size' width='100' height='100'>
+  	  <rect width='50%' height='50%'/>
+    </svg>
+  </div>
+  <div>
+    <svg width='100' height='100'>
+      <style>
+        svg {
+          width: 50px;
+          height: 50px;
+        }
+      </style>
+  	  <rect width='50%' height='50%'/>
+    </svg>
+  </div>
+  <div>
+    <svg class='intrinsic-size' width='100' height='100'>
+  	  <svg viewbox='0 0 100 100'>
+  	    <rect width='50%' height='50%'/>
+  	  </svg>
+    </svg>
+  </div>
+  <div>
+    <svg class='intrinsic-size' width='100' height='100'>
+  	  <svg class='intrinsic-size' viewbox='0 0 100 100'>
+  	    <rect width='50' height='50'/>
+  	  </svg>
+    </svg>
+  </div>
+  <div>
+    <svg class='intrinsic-size' width='100' height='100'>
+  	  <svg class='intrinsic-size' width='50%' height='50%' viewbox='0 0 100 100'>
+  	    <rect width='100%' height='100%'/>
+  	  </svg>
+    </svg>
+  </div>
+  <div>
+    <svg class='intrinsic-size' width='100' height='100'>
+  	  <svg width='50%' height='50%' viewbox='0 0 100 100'>
+  	    <rect width='100' height='100'/>
+  	  </svg>
+    </svg>
+  </div>
+  <div>
+    <svg width='100' height='100'>
+      <style>
+        svg {
+          width: 50px;
+          height: 50px;
+        }
+      </style>
+  	  <svg width='50%' height='50%' viewbox='0 0 100 100'>
+  	    <rect width='100' height='100'/>
+  	  </svg>
+    </svg>
+  </div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (181164 => 181165)


--- trunk/Source/WebCore/ChangeLog	2015-03-06 18:14:10 UTC (rev 181164)
+++ trunk/Source/WebCore/ChangeLog	2015-03-06 18:15:48 UTC (rev 181165)
@@ -1,3 +1,22 @@
+2015-03-06  Said Abou-Hallawa  <sabouhall...@apple.com>
+
+        An SVG element without intrinsic size inherits the container size as its viewport instead of inheriting the container viewport.
+        https://bugs.webkit.org/show_bug.cgi?id=141725.
+
+        Reviewed by Darin Adler.
+
+        The current viewport of the <svg> element should be retrieved from its
+        renderer if the renderer is available. If the renderer is not created yet,
+        this means the viewport is needed to calculate the size of the renderer.
+        In this case, we should return the element size if it is intrinsic size.
+        
+        Test: svg/css/svg-css-different-intrinsic-sizes.html
+
+        * svg/SVGSVGElement.cpp:
+        (WebCore::SVGSVGElement::currentViewportSize): Change the order for
+        returning the viewport of the <svg> element. We should consider the case
+        of a valid renderer before considering the case of an intrinsic size.
+
 2015-03-06  Simon Fraser  <simon.fra...@apple.com>
 
         Allow composited clip-path to be updated without a layer repaint

Modified: trunk/Source/WebCore/svg/SVGSVGElement.cpp (181164 => 181165)


--- trunk/Source/WebCore/svg/SVGSVGElement.cpp	2015-03-06 18:14:10 UTC (rev 181164)
+++ trunk/Source/WebCore/svg/SVGSVGElement.cpp	2015-03-06 18:15:48 UTC (rev 181165)
@@ -526,18 +526,23 @@
 
 FloatSize SVGSVGElement::currentViewportSize() const
 {
-    if (hasIntrinsicWidth() && hasIntrinsicHeight())
-        return FloatSize(floatValueForLength(intrinsicWidth(), 0), floatValueForLength(intrinsicHeight(), 0));
+    FloatSize viewportSize;
 
-    if (!renderer())
+    if (renderer()) {
+        if (is<RenderSVGRoot>(*renderer())) {
+            auto& root = downcast<RenderSVGRoot>(*renderer());
+            viewportSize = root.contentBoxRect().size() / root.style().effectiveZoom();
+        } else
+            viewportSize = downcast<RenderSVGViewportContainer>(*renderer()).viewport().size();
+    }
+
+    if (!viewportSize.isEmpty())
+        return viewportSize;
+
+    if (!(hasIntrinsicWidth() && hasIntrinsicHeight()))
         return { };
 
-    if (is<RenderSVGRoot>(*renderer())) {
-        auto& root = downcast<RenderSVGRoot>(*renderer());
-        return root.contentBoxRect().size() / root.style().effectiveZoom();
-    }
-
-    return downcast<RenderSVGViewportContainer>(*renderer()).viewport().size();
+    return FloatSize(floatValueForLength(intrinsicWidth(), 0), floatValueForLength(intrinsicHeight(), 0));
 }
 
 bool SVGSVGElement::hasIntrinsicWidth() const
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to