SVG images broken when max-width specified.
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jul 2012 03:59:03 +0000 (03:59 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jul 2012 03:59:03 +0000 (03:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=91474

Source/WebCore:

SVG images were computing intrinsic dimensions when width and height were auto that did not
respect min-max width/height. Normal images had code that applied these constraints properly.
Looking at the code before the check-in that broke things, these constraints used to be
applied to all images regardless of type via calcAspectRatioLogicalWidth/Height.

This patch leaves the new function structure in place but converts the code to be more like
it was prior to the introduction of the regression. Instead of raw intrinsic sizes being
used in the SVG case, now all image types get the intrinsic sizes constrained when doing
width/height computations.

Reviewed by Dan Bernstein.

Test: svg/as-image/svg-intrinsic-size.html

* rendering/RenderReplaced.cpp:
(WebCore::RenderReplaced::computeAspectRatioInformationForRenderBox):
Rename computeIntrinsicRatioInformationForRenderBox to computeAspectRatioInformationForRenderBox.
Also rename the intrinsicSize reference to constrainedSize to reflect the fact that the size
is not necessarily the intrinsic size any longer but instead a size where both axes have been
constrained based off the max-min values of the opposite axes.

Move the constraining code out of RenderReplaced::computeIntrinsicRatioInformation into this
function so that the SVG code path appies the constraints as well. The movement of this code
is what fixes the bug.

(WebCore::RenderReplaced::computeIntrinsicRatioInformation):
Changed to remove the code that constrains the returned size, since it is shifting to
computeAspectRatioInformationForRenderBox instead.

(WebCore::RenderReplaced::computeReplacedLogicalWidth):
(WebCore::RenderReplaced::computeReplacedLogicalHeight):
* rendering/RenderReplaced.h:
(RenderReplaced):
Patch the name of the reference passed in to computeReplacedLogicalWidth/Height to be
constrainedSize instead of intrinsicSize, so that it is more obvious that the returned
result is not just the intrinsic size of the image.

LayoutTests:

Reviewed by Dan Bernstein.

* svg/as-image/svg-intrinsic-size-expected.html: Added.
* svg/as-image/svg-intrinsic-size.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/svg/as-image/svg-intrinsic-size-expected.html [new file with mode: 0644]
LayoutTests/svg/as-image/svg-intrinsic-size.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderReplaced.cpp
Source/WebCore/rendering/RenderReplaced.h

index 44e6512..4143a66 100644 (file)
@@ -1,3 +1,13 @@
+2012-07-19  David Hyatt  <hyatt@apple.com>
+
+        SVG images broken when max-width specified.
+        https://bugs.webkit.org/show_bug.cgi?id=91474
+
+        Reviewed by Dan Bernstein.
+
+        * svg/as-image/svg-intrinsic-size-expected.html: Added.
+        * svg/as-image/svg-intrinsic-size.html: Added.
+
 2012-07-19  Julien Chaffraix  <jchaffraix@webkit.org>
 
         [CSS2.1] Anonymous tables should be inline/block-level based off their parent
diff --git a/LayoutTests/svg/as-image/svg-intrinsic-size-expected.html b/LayoutTests/svg/as-image/svg-intrinsic-size-expected.html
new file mode 100644 (file)
index 0000000..fa2bc91
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<div style="position: absolute; top: 10px; left: 10px; width: 200px; height: 400px; outline: 1px solid blue;">
+    <img style="background-color: yellow; width: auto; height: auto; max-width: 100%; max-height: 100%;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAYAAAB5fY51AAAEJGlDQ1BJQ0MgUHJvZmlsZQAAOBGFVd9v21QUPolvUqQWPyBYR4eKxa9VU1u5GxqtxgZJk6XtShal6dgqJOQ6N4mpGwfb6baqT3uBNwb8AUDZAw9IPCENBmJ72fbAtElThyqqSUh76MQPISbtBVXhu3ZiJ1PEXPX6yznfOec7517bRD1fabWaGVWIlquunc8klZOnFpSeTYrSs9RLA9Sr6U4tkcvNEi7BFffO6+EdigjL7ZHu/k72I796i9zRiSJPwG4VHX0Z+AxRzNRrtksUvwf7+Gm3BtzzHPDTNgQCqwKXfZwSeNHHJz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+<div style="position: absolute; top: 10px; left: 250px; width: 200px; height: 400px; outline: 1px solid blue;">
+    <img id="target" style="background-color: yellow; width: auto; height: auto; max-width: 100%; max-height: 100%;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAYAAAB5fY51AAAEJGlDQ1BJQ0MgUHJvZmlsZQAAOBGFVd9v21QUPolvUqQWPyBYR4eKxa9VU1u5GxqtxgZJk6XtShal6dgqJOQ6N4mpGwfb6baqT3uBNwb8AUDZAw9IPCENBmJ72fbAtElThyqqSUh76MQPISbtBVXhu3ZiJ1PEXPX6yznfOec7517bRD1fabWaGVWIlquunc8klZOnFpSeTYrSs9RLA9Sr6U4tkcvNEi7BFffO6+EdigjL7ZHu/k72I796i9zRiSJPwG4VHX0Z+AxRzNRrtksUvwf7+Gm3BtzzHPDTNgQCqwKXfZwSeNHHJz1OIT8JjtAq6xWtCLwGPLzYZi+3YV8DGMiT4VVuG7oiZpGzrZJhcs/hL49xtzH/Dy6bdfTsXYNY+5yluWO4D4neK/ZUvok/17X0HPBLsF+vuUlhfwX4j/rSfAJ4H1H0qZJ9dN7nR19frRTeBt4Fe9FwpwtN+2p1MXscGLHR9SXrmMgjONd1ZxKzpBeA71b4tNhj6JGoyFNp4GHgwUp9qplfmnFW5oTdy7NamcwCI49kv6fN5IAHgD+0rbyoBc3SOjczohbyS1drbq6pQdqumllRC/0ymTtej8gpbbuVwpQfyw66dqEZyxZKxtHpJn+tZnpnEdrYBbueF9qQn93S7HQGGHnYP7w6L+YGHNtd1FJitqPAR+hERCNOFi1i1alKO6RQnjKUxL1GNjwlMsiEhcPLYTEiT9ISbN15OY/jx4SMshe9LaJRpTvHr3C/ybFYP1PZAfwfYrPsMBtnE6SwN9ib7AhLwTrBDgUKcm06FSrTfSj187xPdVQWOk5Q8vxAfSiIUc7Z7xr6zY/+hpqwSyv0I0/QMTRb7RMgBxNodTfSPqdraz/sDjzKBrv4zu2+a2t0/HHzjd2Lbcc2sG7GtsL42K+xLfx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AwwIMC8CwAAwLMCwAwwIwLMCwAAwLMCwAwwIwLMCwAAwLwLAAwwIwLADDAgwLwLAADAswLADDAjAswLAADAvAsADDAjAsAMMCDAvAsAAMCzAsAMMCEAAwLADDAgwLwLAADAswLADDAjAswLAADAvAsADDAjAsAMMCDAvAsAAMCzAsAMMCMCzAsAAMC8CwAMMCMCwAwwIMC8CwAAQADAvAsADDAjAsAMMCDAvAsAAMCzAsAMMCMCzAsAAMC8CwAMMCMCwAwwIMC8CwAAwLMCwAwwIwLMCwAAwLwLAAwwIwLAARAMMCMCzAsAAMC8CwAMMCMCwAwwIMC8CwAAwLMCwAwwIwLMCwAAwLwLAAwwIwLADDAgwLwLAADAswLADDAjAswLAADAswLBEAwwIwLMCwAAwLwLAAwwIwLADDAgwLwLAADAv4awHFyETzjVi+5gAAAABJRU5ErkJggg==">
+</div>
diff --git a/LayoutTests/svg/as-image/svg-intrinsic-size.html b/LayoutTests/svg/as-image/svg-intrinsic-size.html
new file mode 100644 (file)
index 0000000..24aae25
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<div style="position: absolute; top: 10px; left: 10px; width: 200px; height: 400px; outline: 1px solid blue;">
+    <img style="background-color: yellow; width: auto; height: auto; max-width: 100%; max-height: 100%;" src="data:image/svg+xml,<svg width='300' height='300' xmlns='http://www.w3.org/2000/svg'><rect x='0' y='0' width='300' height='300'></rect></svg>">
+</div>
+
+<div style="position: absolute; top: 10px; left: 250px; width: 200px; height: 400px; outline: 1px solid blue;">
+    <img id="target" style="background-color: yellow; width: auto; height: auto; max-width: 100%; max-height: 100%;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAYAAAB5fY51AAAEJGlDQ1BJQ0MgUHJvZmlsZQAAOBGFVd9v21QUPolvUqQWPyBYR4eKxa9VU1u5GxqtxgZJk6XtShal6dgqJOQ6N4mpGwfb6baqT3uBNwb8AUDZAw9IPCENBmJ72fbAtElThyqqSUh76MQPISbtBVXhu3ZiJ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MC8CwAMMCMCwAwwIMC8CwAAwLMCwAwwIwLMCwAAwLwLAAwwIwLADDAgwLwLAADAswLADDAjAswLAADAswLBEAwwIwLMCwAAwLwLAAwwIwLADDAgwLwLAADAv4awHFyETzjVi+5gAAAABJRU5ErkJggg==">
+</div>
index 10a5034..1329e3f 100644 (file)
@@ -1,3 +1,45 @@
+2012-07-19  David Hyatt  <hyatt@apple.com>
+
+        SVG images broken when max-width specified.
+        https://bugs.webkit.org/show_bug.cgi?id=91474
+
+        SVG images were computing intrinsic dimensions when width and height were auto that did not
+        respect min-max width/height. Normal images had code that applied these constraints properly.
+        Looking at the code before the check-in that broke things, these constraints used to be
+        applied to all images regardless of type via calcAspectRatioLogicalWidth/Height.
+        
+        This patch leaves the new function structure in place but converts the code to be more like
+        it was prior to the introduction of the regression. Instead of raw intrinsic sizes being
+        used in the SVG case, now all image types get the intrinsic sizes constrained when doing
+        width/height computations.
+
+        Reviewed by Dan Bernstein.
+
+        Test: svg/as-image/svg-intrinsic-size.html
+
+        * rendering/RenderReplaced.cpp:
+        (WebCore::RenderReplaced::computeAspectRatioInformationForRenderBox):
+        Rename computeIntrinsicRatioInformationForRenderBox to computeAspectRatioInformationForRenderBox.
+        Also rename the intrinsicSize reference to constrainedSize to reflect the fact that the size
+        is not necessarily the intrinsic size any longer but instead a size where both axes have been
+        constrained based off the max-min values of the opposite axes.
+        
+        Move the constraining code out of RenderReplaced::computeIntrinsicRatioInformation into this
+        function so that the SVG code path appies the constraints as well. The movement of this code
+        is what fixes the bug.
+
+        (WebCore::RenderReplaced::computeIntrinsicRatioInformation):
+        Changed to remove the code that constrains the returned size, since it is shifting to
+        computeAspectRatioInformationForRenderBox instead.
+
+        (WebCore::RenderReplaced::computeReplacedLogicalWidth):
+        (WebCore::RenderReplaced::computeReplacedLogicalHeight):
+        * rendering/RenderReplaced.h:
+        (RenderReplaced):
+        Patch the name of the reference passed in to computeReplacedLogicalWidth/Height to be
+        constrainedSize instead of intrinsicSize, so that it is more obvious that the returned
+        result is not just the intrinsic size of the image.
+
 2012-07-19  Dmitry Titov  <dimich@chromium.org>
 
         Unreviewed, reverting http://trac.webkit.org/changeset/123149.
index 2e0d747..d623b64 100644 (file)
@@ -269,8 +269,9 @@ static inline bool rendererHasAspectRatio(const RenderObject* renderer)
     return renderer->isImage() || renderer->isCanvas() || renderer->isVideo();
 }
 
-void RenderReplaced::computeIntrinsicRatioInformationForRenderBox(RenderBox* contentRenderer, FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const
+void RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* contentRenderer, FloatSize& constrainedSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const
 {
+    FloatSize intrinsicSize;
     if (contentRenderer) {
         contentRenderer->computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio, isPercentageIntrinsicSize);
         if (intrinsicRatio)
@@ -285,11 +286,25 @@ void RenderReplaced::computeIntrinsicRatioInformationForRenderBox(RenderBox* con
 
         if (rendererHasAspectRatio(this) && isPercentageIntrinsicSize)
             intrinsicRatio = 1;
-        return;
+    } else {
+        computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio, isPercentageIntrinsicSize);
+        if (intrinsicRatio)
+            ASSERT(!isPercentageIntrinsicSize);
+    }
+
+    // Now constrain the intrinsic size along each axis according to minimum and maximum width/heights along the
+    // opposite axis. So for example a maximum width that shrinks our width will result in the height we compute here
+    // having to shrink in order to preserve the aspect ratio. Because we compute these values independently along
+    // each axis, the final returned size may in fact not preserve the aspect ratio.
+    // FIXME: In the long term, it might be better to just return this code more to the way it used to be before this
+    // function was added, since all it has done is make the code more unclear.
+    constrainedSize = intrinsicSize;
+    if (intrinsicRatio && !intrinsicSize.isEmpty() && style()->logicalWidth().isAuto() && style()->logicalHeight().isAuto()) {
+        // We can't multiply or divide by 'intrinsicRatio' here, it breaks tests, like fast/images/zoomed-img-size.html, which
+        // can only be fixed once subpixel precision is available for things like intrinsicWidth/Height - which include zoom!
+        constrainedSize.setWidth(RenderBox::computeReplacedLogicalHeight() * intrinsicSize.width() / intrinsicSize.height());
+        constrainedSize.setHeight(RenderBox::computeReplacedLogicalWidth() * intrinsicSize.width() / intrinsicSize.height());
     }
-    computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio, isPercentageIntrinsicSize);
-    if (intrinsicRatio)
-        ASSERT(!isPercentageIntrinsicSize);
 }
 
 void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const
@@ -304,12 +319,6 @@ void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize,
         return;
 
     intrinsicRatio = intrinsicSize.width() / intrinsicSize.height();
-    if (style()->logicalWidth().isAuto() && style()->logicalHeight().isAuto()) {
-        // We can't multiply or divide by 'intrinsicRatio' here, it breaks tests, like fast/images/zoomed-img-size.html, which
-        // can only be fixed once subpixel precision is available for things like intrinsicWidth/Height - which include zoom!
-        intrinsicSize.setWidth(RenderBox::computeReplacedLogicalHeight() * intrinsicLogicalWidth() / intrinsicLogicalHeight());
-        intrinsicSize.setHeight(RenderBox::computeReplacedLogicalWidth() * intrinsicLogicalHeight() / intrinsicLogicalWidth());
-    }
 }
 
 LayoutUnit RenderReplaced::computeReplacedLogicalWidth(bool includeMaxWidth) const
@@ -322,19 +331,19 @@ LayoutUnit RenderReplaced::computeReplacedLogicalWidth(bool includeMaxWidth) con
     // 10.3.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html#inline-replaced-width
     bool isPercentageIntrinsicSize = false;
     double intrinsicRatio = 0;
-    FloatSize intrinsicSize;
-    computeIntrinsicRatioInformationForRenderBox(contentRenderer, intrinsicSize, intrinsicRatio, isPercentageIntrinsicSize);
+    FloatSize constrainedSize;
+    computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize, intrinsicRatio, isPercentageIntrinsicSize);
 
     // FIXME: Remove unnecessary round/roundToInt calls from this method when layout is off ints: webkit.org/b/63656
     if (style()->logicalWidth().isAuto()) {
         bool heightIsAuto = style()->logicalHeight().isAuto();
-        bool hasIntrinsicWidth = !isPercentageIntrinsicSize && intrinsicSize.width() > 0;
+        bool hasIntrinsicWidth = !isPercentageIntrinsicSize && constrainedSize.width() > 0;
 
         // If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic width, then that intrinsic width is the used value of 'width'.
         if (heightIsAuto && hasIntrinsicWidth)
-            return computeReplacedLogicalWidthRespectingMinMaxWidth(roundToInt(intrinsicSize.width()), includeMaxWidth);
+            return computeReplacedLogicalWidthRespectingMinMaxWidth(roundToInt(constrainedSize.width()), includeMaxWidth);
 
-        bool hasIntrinsicHeight = !isPercentageIntrinsicSize && intrinsicSize.height() > 0;
+        bool hasIntrinsicHeight = !isPercentageIntrinsicSize && constrainedSize.height() > 0;
         if (intrinsicRatio || isPercentageIntrinsicSize) {
             // If 'height' and 'width' both have computed values of 'auto' and the element has no intrinsic width, but does have an intrinsic height and intrinsic ratio;
             // or if 'width' has a computed value of 'auto', 'height' has some other computed value, and the element does have an intrinsic ratio; then the used value
@@ -361,14 +370,14 @@ LayoutUnit RenderReplaced::computeReplacedLogicalWidth(bool includeMaxWidth) con
                 LayoutUnit marginEnd = minimumValueForLength(style()->marginEnd(), logicalWidth);
                 logicalWidth = max(ZERO_LAYOUT_UNIT, logicalWidth - (marginStart + marginEnd + (width() - clientWidth())));
                 if (isPercentageIntrinsicSize)
-                    logicalWidth = roundToInt(logicalWidth * intrinsicSize.width() / 100);
+                    logicalWidth = roundToInt(logicalWidth * constrainedSize.width() / 100);
                 return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalWidth, includeMaxWidth);
             }
         }
 
         // Otherwise, if 'width' has a computed value of 'auto', and the element has an intrinsic width, then that intrinsic width is the used value of 'width'.
         if (hasIntrinsicWidth)
-            return computeReplacedLogicalWidthRespectingMinMaxWidth(roundToInt(intrinsicSize.width()), includeMaxWidth);
+            return computeReplacedLogicalWidthRespectingMinMaxWidth(roundToInt(constrainedSize.width()), includeMaxWidth);
 
         // Otherwise, if 'width' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'width' becomes 300px. If 300px is too
         // wide to fit the device, UAs should use the width of the largest rectangle that has a 2:1 ratio and fits the device instead.
@@ -391,16 +400,16 @@ LayoutUnit RenderReplaced::computeReplacedLogicalHeight() const
     // 10.6.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html#inline-replaced-height
     bool isPercentageIntrinsicSize = false;
     double intrinsicRatio = 0;
-    FloatSize intrinsicSize;
-    computeIntrinsicRatioInformationForRenderBox(contentRenderer, intrinsicSize, intrinsicRatio, isPercentageIntrinsicSize);
+    FloatSize constrainedSize;
+    computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize, intrinsicRatio, isPercentageIntrinsicSize);
 
     // FIXME: Remove unnecessary round/roundToInt calls from this method when layout is off ints: webkit.org/b/63656
     bool widthIsAuto = style()->logicalWidth().isAuto();
-    bool hasIntrinsicHeight = !isPercentageIntrinsicSize && intrinsicSize.height() > 0;
+    bool hasIntrinsicHeight = !isPercentageIntrinsicSize && constrainedSize.height() > 0;
 
     // If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic height, then that intrinsic height is the used value of 'height'.
     if (widthIsAuto && hasIntrinsicHeight)
-        return computeReplacedLogicalHeightRespectingMinMaxHeight(roundToInt(intrinsicSize.height()));
+        return computeReplacedLogicalHeightRespectingMinMaxHeight(roundToInt(constrainedSize.height()));
 
     // Otherwise, if 'height' has a computed value of 'auto', and the element has an intrinsic ratio then the used value of 'height' is:
     // (used width) / (intrinsic ratio)
@@ -409,7 +418,7 @@ LayoutUnit RenderReplaced::computeReplacedLogicalHeight() const
 
     // Otherwise, if 'height' has a computed value of 'auto', and the element has an intrinsic height, then that intrinsic height is the used value of 'height'.
     if (hasIntrinsicHeight)
-        return computeReplacedLogicalHeightRespectingMinMaxHeight(roundToInt(intrinsicSize.height()));
+        return computeReplacedLogicalHeightRespectingMinMaxHeight(roundToInt(constrainedSize.height()));
 
     // Otherwise, if 'height' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'height' must be set to the height
     // of the largest rectangle that has a 2:1 ratio, has a height not greater than 150px, and has a width not greater than the device width.
index 9ebc634..bc215d5 100644 (file)
@@ -77,7 +77,7 @@ private:
     virtual bool canBeSelectionLeaf() const { return true; }
 
     virtual LayoutRect selectionRectForRepaint(RenderBoxModelObject* repaintContainer, bool clipToVisibleContent = true);
-    void computeIntrinsicRatioInformationForRenderBox(RenderBox*, FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const;
+    void computeAspectRatioInformationForRenderBox(RenderBox*, FloatSize& constrainedSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const;
 
     IntSize m_intrinsicSize;
 };