<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[163165] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/163165">163165</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2014-01-31 00:09:07 -0800 (Fri, 31 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix table sizing when 'max-width' is used.
https://bugs.webkit.org/show_bug.cgi?id=115156

Patch by László Langó &lt;lango@inf.u-szeged.hu&gt; on 2014-01-31
Reviewed by Andreas Kling.

Source/WebCore:

<a href="http://trac.webkit.org/projects/webkit/changeset/143534">r143534</a> make &lt;table&gt; abide by 'max-width' all the time which is wrong.
Per the CSS specification, a table should be wide enough to fit its
content, regardless of 'max-width'.

<a href="http://trac.webkit.org/projects/webkit/changeset/140479">r140479</a> fixed part of the regression from that change but made the
same fatal mistake by constraining min-content to fit 'max-width'.

The fix is to avoid constraining min-content and ensure that the table
logical width is at least its min-content size.

Backported from Blink:
https://chromium.googlesource.com/chromium/blink/+/0bca0dec4895aeeb2054ba36316e984e4ebed06f

Test: fast/table/html-table-width-max-width-constrained.html

* rendering/RenderTable.cpp:
(WebCore::RenderTable::updateLogicalWidth):
(WebCore::RenderTable::computePreferredLogicalWidths):

LayoutTests:

* fast/table/css-table-max-width-expected.txt:
* fast/table/css-table-max-width.html:
* fast/table/html-table-width-max-width-constrained-expected.txt: Added.
* fast/table/html-table-width-max-width-constrained.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfasttablecsstablemaxwidthexpectedtxt">trunk/LayoutTests/fast/table/css-table-max-width-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasttablecsstablemaxwidthhtml">trunk/LayoutTests/fast/table/css-table-max-width.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderTablecpp">trunk/Source/WebCore/rendering/RenderTable.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasttablehtmltablewidthmaxwidthconstrainedexpectedtxt">trunk/LayoutTests/fast/table/html-table-width-max-width-constrained-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasttablehtmltablewidthmaxwidthconstrainedhtml">trunk/LayoutTests/fast/table/html-table-width-max-width-constrained.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (163164 => 163165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-01-31 07:51:17 UTC (rev 163164)
+++ trunk/LayoutTests/ChangeLog        2014-01-31 08:09:07 UTC (rev 163165)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-01-31  László Langó  &lt;lango@inf.u-szeged.hu&gt;
+
+        Fix table sizing when 'max-width' is used.
+        https://bugs.webkit.org/show_bug.cgi?id=115156
+
+        Reviewed by Andreas Kling.
+
+        * fast/table/css-table-max-width-expected.txt:
+        * fast/table/css-table-max-width.html:
+        * fast/table/html-table-width-max-width-constrained-expected.txt: Added.
+        * fast/table/html-table-width-max-width-constrained.html: Added.
+
</ins><span class="cx"> 2014-01-28  Timothy Hatcher  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add column number and call timing support to LegacyProfiler.
</span></span></pre></div>
<a id="trunkLayoutTestsfasttablecsstablemaxwidthexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/table/css-table-max-width-expected.txt (163164 => 163165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/table/css-table-max-width-expected.txt        2014-01-31 07:51:17 UTC (rev 163164)
+++ trunk/LayoutTests/fast/table/css-table-max-width-expected.txt        2014-01-31 08:09:07 UTC (rev 163165)
</span><span class="lines">@@ -10,11 +10,11 @@
</span><span class="cx"> PASS maxGreatThanMinWidthAutoLayout.getBoundingClientRect().width is 202
</span><span class="cx"> PASS minGreatThanMaxWidthAutoLayout.getBoundingClientRect().width is 202
</span><span class="cx"> PASS onlyMaxWidthAutoLayout.getBoundingClientRect().width is 202
</span><del>-PASS maxWidthZeroAutoLayout.getBoundingClientRect().width is 0
</del><ins>+PASS maxWidthZeroAutoLayout.getBoundingClientRect().width is 182
</ins><span class="cx"> PASS maxGreatThanMinWidthFixedLayout.getBoundingClientRect().width is 202
</span><span class="cx"> PASS minGreatThanMaxWidthFixedLayout.getBoundingClientRect().width is 202
</span><span class="cx"> PASS onlyMaxWidthFixedLayout.getBoundingClientRect().width is 202
</span><del>-PASS maxWidthZeroFixedLayout.getBoundingClientRect().width is 0
</del><ins>+PASS maxWidthZeroFixedLayout.getBoundingClientRect().width is 2
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsfasttablecsstablemaxwidthhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/table/css-table-max-width.html (163164 => 163165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/table/css-table-max-width.html        2014-01-31 07:51:17 UTC (rev 163164)
+++ trunk/LayoutTests/fast/table/css-table-max-width.html        2014-01-31 08:09:07 UTC (rev 163165)
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx">         fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa 
</span><span class="cx">         qui officia deserunt mollit anim id est laborum.
</span><span class="cx">     &lt;/div&gt;
</span><del>-    &lt;div id=&quot;maxWidthZeroAutoLayout&quot; class=&quot;child&quot; style=&quot;display:table; max-width:0; width:100%;&quot;&gt;
</del><ins>+    &lt;div id=&quot;maxWidthZeroAutoLayout&quot; class=&quot;child&quot; style=&quot;display:table; max-width:0; width:100%; font: 10px/1 Ahem;&quot;&gt;
</ins><span class="cx">         Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod 
</span><span class="cx">         tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
</span><span class="cx">         quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
</span><span class="lines">@@ -97,7 +97,7 @@
</span><span class="cx"> onlyMaxWidthAutoLayout = document.getElementById(&quot;onlyMaxWidthAutoLayout&quot;);
</span><span class="cx"> shouldBe(&quot;onlyMaxWidthAutoLayout.getBoundingClientRect().width&quot;,&quot;202&quot;);
</span><span class="cx"> maxWidthZeroAutoLayout = document.getElementById(&quot;maxWidthZeroAutoLayout&quot;);
</span><del>-shouldBe(&quot;maxWidthZeroAutoLayout.getBoundingClientRect().width&quot;,&quot;0&quot;);
</del><ins>+shouldBe(&quot;maxWidthZeroAutoLayout.getBoundingClientRect().width&quot;,&quot;182&quot;);
</ins><span class="cx"> maxGreatThanMinWidthFixedLayout = document.getElementById(&quot;maxGreatThanMinWidthFixedLayout&quot;);
</span><span class="cx"> shouldBe(&quot;maxGreatThanMinWidthFixedLayout.getBoundingClientRect().width&quot;,&quot;202&quot;);
</span><span class="cx"> minGreatThanMaxWidthFixedLayout = document.getElementById(&quot;minGreatThanMaxWidthFixedLayout&quot;);
</span><span class="lines">@@ -105,7 +105,7 @@
</span><span class="cx"> onlyMaxWidthFixedLayout = document.getElementById(&quot;onlyMaxWidthFixedLayout&quot;);
</span><span class="cx"> shouldBe(&quot;onlyMaxWidthFixedLayout.getBoundingClientRect().width&quot;,&quot;202&quot;);
</span><span class="cx"> maxWidthZeroFixedLayout = document.getElementById(&quot;maxWidthZeroFixedLayout&quot;);
</span><del>-shouldBe(&quot;maxWidthZeroFixedLayout.getBoundingClientRect().width&quot;,&quot;0&quot;);
</del><ins>+shouldBe(&quot;maxWidthZeroFixedLayout.getBoundingClientRect().width&quot;,&quot;2&quot;);
</ins><span class="cx"> 
</span><span class="cx"> document.body.removeChild(document.getElementById('container'));
</span><span class="cx"> &lt;/script&gt;
</span></span></pre></div>
<a id="trunkLayoutTestsfasttablehtmltablewidthmaxwidthconstrainedexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/table/html-table-width-max-width-constrained-expected.txt (0 => 163165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/table/html-table-width-max-width-constrained-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/table/html-table-width-max-width-constrained-expected.txt        2014-01-31 08:09:07 UTC (rev 163165)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+This test checks that a fixed table layout with max-width doesn't over-constraint the cell (ie the content width still wins over max-width per the specification).
+For this test to pass, the second cell shouldn't bleed out of the table.
+Cell text        Cell text text text text
+PASS
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttablehtmltablewidthmaxwidthconstrainedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/table/html-table-width-max-width-constrained.html (0 => 163165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/table/html-table-width-max-width-constrained.html                                (rev 0)
+++ trunk/LayoutTests/fast/table/html-table-width-max-width-constrained.html        2014-01-31 08:09:07 UTC (rev 163165)
</span><span class="lines">@@ -0,0 +1,34 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;style&gt;
+table {
+    font: 20px/1 Ahem;
+    border-collapse: separate;
+    table-layout: fixed;
+    max-width: 300px;
+    width: 300px;
+    border: 1px solid #dddddd;
+    border-spacing: 0px;
+}
+
+td {
+    padding: 0px;
+    width: 200px;
+    border-left: 1px solid #dddddd;
+}
+&lt;/style&gt;
+&lt;script src=&quot;../../resources/check-layout.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;checkLayout('table')&quot;&gt;
+    &lt;div&gt;This test checks that a fixed table layout with max-width doesn't over-constraint the cell (ie the content width still wins over max-width per the specification).&lt;/div&gt;
+    &lt;div&gt;For this test to pass, the second cell shouldn't bleed out of the table.&lt;/div&gt;
+    &lt;table data-expected-width=&quot;404&quot;&gt;
+        &lt;tbody&gt;
+            &lt;tr&gt;
+            &lt;td&gt;Cell text&lt;/td&gt;
+            &lt;td&gt;Cell text text text text&lt;/td&gt;
+            &lt;/tr&gt;
+        &lt;/tbody&gt;
+    &lt;/table&gt;
+&lt;/body&gt;&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163164 => 163165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-01-31 07:51:17 UTC (rev 163164)
+++ trunk/Source/WebCore/ChangeLog        2014-01-31 08:09:07 UTC (rev 163165)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2014-01-31  László Langó  &lt;lango@inf.u-szeged.hu&gt;
+
+        Fix table sizing when 'max-width' is used.
+        https://bugs.webkit.org/show_bug.cgi?id=115156
+
+        Reviewed by Andreas Kling.
+
+        r143534 make &lt;table&gt; abide by 'max-width' all the time which is wrong.
+        Per the CSS specification, a table should be wide enough to fit its
+        content, regardless of 'max-width'.
+
+        r140479 fixed part of the regression from that change but made the
+        same fatal mistake by constraining min-content to fit 'max-width'.
+
+        The fix is to avoid constraining min-content and ensure that the table
+        logical width is at least its min-content size.
+
+        Backported from Blink:
+        https://chromium.googlesource.com/chromium/blink/+/0bca0dec4895aeeb2054ba36316e984e4ebed06f
+
+        Test: fast/table/html-table-width-max-width-constrained.html
+
+        * rendering/RenderTable.cpp:
+        (WebCore::RenderTable::updateLogicalWidth):
+        (WebCore::RenderTable::computePreferredLogicalWidths):
+
</ins><span class="cx"> 2014-01-30  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix iOS build after r163156.
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderTablecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderTable.cpp (163164 => 163165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderTable.cpp        2014-01-31 07:51:17 UTC (rev 163164)
+++ trunk/Source/WebCore/rendering/RenderTable.cpp        2014-01-31 08:09:07 UTC (rev 163165)
</span><span class="lines">@@ -292,16 +292,16 @@
</span><span class="cx">         setLogicalWidth(std::min&lt;int&gt;(availableContentLogicalWidth, maxPreferredLogicalWidth()));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // Ensure we aren't smaller than our min preferred width.
-    setLogicalWidth(std::max&lt;int&gt;(logicalWidth(), minPreferredLogicalWidth()));
-
-    
</del><span class="cx">     // Ensure we aren't bigger than our max-width style.
</span><span class="cx">     Length styleMaxLogicalWidth = style().logicalMaxWidth();
</span><span class="cx">     if ((styleMaxLogicalWidth.isSpecified() &amp;&amp; !styleMaxLogicalWidth.isNegative()) || styleMaxLogicalWidth.isIntrinsic()) {
</span><span class="cx">         LayoutUnit computedMaxLogicalWidth = convertStyleLogicalWidthToComputedWidth(styleMaxLogicalWidth, availableLogicalWidth);
</span><span class="cx">         setLogicalWidth(std::min&lt;int&gt;(logicalWidth(), computedMaxLogicalWidth));
</span><span class="cx">     }
</span><ins>+    
+    // Ensure we aren't smaller than our min preferred width. This MUST be done after 'max-width' as
+    // we ignore it if it means we wouldn't accomodate our content.
+    setLogicalWidth(std::max&lt;int&gt;(logicalWidth(), minPreferredLogicalWidth()));
</ins><span class="cx"> 
</span><span class="cx">     // Ensure we aren't smaller than our min-width style.
</span><span class="cx">     Length styleMinLogicalWidth = style().logicalMinWidth();
</span><span class="lines">@@ -328,6 +328,10 @@
</span><span class="cx">         setMarginStart(minimumValueForLength(style().marginStart(), availableLogicalWidth));
</span><span class="cx">         setMarginEnd(minimumValueForLength(style().marginEnd(), availableLogicalWidth));
</span><span class="cx">     }
</span><ins>+
+    // We should NEVER shrink the table below the min-content logical width, or else the table can't accomodate
+    // its own content which doesn't match CSS nor what authors expect.
+    ASSERT(logicalWidth() &gt;= minPreferredLogicalWidth());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // This method takes a RenderStyle's logical width, min-width, or max-width length and computes its actual value.
</span><span class="lines">@@ -778,8 +782,9 @@
</span><span class="cx"> 
</span><span class="cx">     // FIXME: This should probably be checking for isSpecified since you should be able to use percentage, calc or viewport relative values for maxWidth.
</span><span class="cx">     if (styleToUse.logicalMaxWidth().isFixed()) {
</span><ins>+        // We don't constrain m_minPreferredLogicalWidth as the table should be at least the size of its min-content, regardless of 'max-width'.
</ins><span class="cx">         m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value()));
</span><del>-        m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value()));
</del><ins>+        m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // FIXME: We should be adding borderAndPaddingLogicalWidth here, but m_tableLayout-&gt;computePreferredLogicalWidths already does,
</span></span></pre>
</div>
</div>

</body>
</html>