<!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>[164265] 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/164265">164265</a></dd>
<dt>Author</dt> <dd>dino@apple.com</dd>
<dt>Date</dt> <dd>2014-02-17 18:31:18 -0800 (Mon, 17 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Constrain replaced element layout to from-intrinsic aspect ratio if specified
https://bugs.webkit.org/show_bug.cgi?id=128629

Reviewed by Simon Fraser.

Source/WebCore:

First pass at implementing -webkit-aspect-ratio: from-instrinsics;

After RenderReplaced has done layout, attempt to update the
resulting size to match the desired aspect ratio. This step
will only reduce the size of an element, and never below the
minimum dimensions.

Tests: fast/css/aspect-ratio/columns.html
       fast/css/aspect-ratio/containers.html
       fast/css/aspect-ratio/simple.html

* rendering/RenderImage.cpp:
(WebCore::RenderImage::imageDimensionsChanged): If we get an update
to our intrinsic dimensions, and layout depends on this, trigger
another layout pass.
* rendering/RenderReplaced.cpp:
(WebCore::RenderReplaced::layout): Implement the step described
above.

LayoutTests:

Three new tests that exercise aspect ratio on:
- normal content
- content that is constrained within a parent container
- content in columns (pages)

* fast/css/aspect-ratio/badchess-tall.png: Added.
* fast/css/aspect-ratio/badchess-wide.png: Added.
* fast/css/aspect-ratio/columns-expected.html: Added.
* fast/css/aspect-ratio/columns.html: Added.
* fast/css/aspect-ratio/containers-expected.html: Added.
* fast/css/aspect-ratio/containers.html: Added.
* fast/css/aspect-ratio/simple-expected.html: Added.
* fast/css/aspect-ratio/simple.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderImagecpp">trunk/Source/WebCore/rendering/RenderImage.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderReplacedcpp">trunk/Source/WebCore/rendering/RenderReplaced.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/LayoutTests/fast/css/aspect-ratio/</li>
<li><a href="#trunkLayoutTestsfastcssaspectratiobadchesstallpng">trunk/LayoutTests/fast/css/aspect-ratio/badchess-tall.png</a></li>
<li><a href="#trunkLayoutTestsfastcssaspectratiobadchesswidepng">trunk/LayoutTests/fast/css/aspect-ratio/badchess-wide.png</a></li>
<li><a href="#trunkLayoutTestsfastcssaspectratiocolumnsexpectedhtml">trunk/LayoutTests/fast/css/aspect-ratio/columns-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastcssaspectratiocolumnshtml">trunk/LayoutTests/fast/css/aspect-ratio/columns.html</a></li>
<li><a href="#trunkLayoutTestsfastcssaspectratiocontainersexpectedhtml">trunk/LayoutTests/fast/css/aspect-ratio/containers-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastcssaspectratiocontainershtml">trunk/LayoutTests/fast/css/aspect-ratio/containers.html</a></li>
<li><a href="#trunkLayoutTestsfastcssaspectratiosimpleexpectedhtml">trunk/LayoutTests/fast/css/aspect-ratio/simple-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastcssaspectratiosimplehtml">trunk/LayoutTests/fast/css/aspect-ratio/simple.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (164264 => 164265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-02-18 02:03:49 UTC (rev 164264)
+++ trunk/LayoutTests/ChangeLog        2014-02-18 02:31:18 UTC (rev 164265)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2014-02-17  Dean Jackson  &lt;dino@apple.com&gt;
+
+        Constrain replaced element layout to from-intrinsic aspect ratio if specified
+        https://bugs.webkit.org/show_bug.cgi?id=128629
+
+        Reviewed by Simon Fraser.
+
+        Three new tests that exercise aspect ratio on:
+        - normal content
+        - content that is constrained within a parent container
+        - content in columns (pages)
+
+        * fast/css/aspect-ratio/badchess-tall.png: Added.
+        * fast/css/aspect-ratio/badchess-wide.png: Added.
+        * fast/css/aspect-ratio/columns-expected.html: Added.
+        * fast/css/aspect-ratio/columns.html: Added.
+        * fast/css/aspect-ratio/containers-expected.html: Added.
+        * fast/css/aspect-ratio/containers.html: Added.
+        * fast/css/aspect-ratio/simple-expected.html: Added.
+        * fast/css/aspect-ratio/simple.html: Added.
+
</ins><span class="cx"> 2014-02-17  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Win] Unreviewed gardening.
</span></span></pre></div>
<a id="trunkLayoutTestsfastcssaspectratiobadchesstallpng"></a>
<div class="binary"><h4>Added: trunk/LayoutTests/fast/css/aspect-ratio/badchess-tall.png</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/LayoutTests/fast/css/aspect-ratio/badchess-tall.png
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkLayoutTestsfastcssaspectratiobadchesswidepng"></a>
<div class="binary"><h4>Added: trunk/LayoutTests/fast/css/aspect-ratio/badchess-wide.png</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/LayoutTests/fast/css/aspect-ratio/badchess-wide.png
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkLayoutTestsfastcssaspectratiocolumnsexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/css/aspect-ratio/columns-expected.html (0 => 164265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/aspect-ratio/columns-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/css/aspect-ratio/columns-expected.html        2014-02-18 02:31:18 UTC (rev 164265)
</span><span class="lines">@@ -0,0 +1,58 @@
</span><ins>+&lt;style&gt;
+.column-container {
+    max-width: 180px;
+}
+
+.columns {
+    box-sizing: border-box;
+    -webkit-column-width: 100px;
+    height: 300px;
+}
+
+img {
+    max-width: 100%;
+    max-height: 100%;
+    margin-bottom: 10px;
+}
+
+#b {
+    width: 180px;
+    height: 90px;
+}
+
+#c {
+    width: 150px;
+    height: 300px;
+}
+
+#e, #g {
+    width: 300px;
+    height: 300px;
+}
+
+#d, #e {
+    min-width: 20px;
+    max-width: 20px;
+    min-height: 20px;
+    max-height: 20px;
+}
+
+#f, #g {
+    width: auto;
+    height: auto;
+    min-width: 30px;
+    min-height: 30px;
+}
+&lt;/style&gt;
+
+&lt;div class=&quot;column-container&quot;&gt;
+    &lt;div class=&quot;columns&quot;&gt;
+        &lt;div&gt;&lt;img id=&quot;a&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+        &lt;div&gt;&lt;img id=&quot;b&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+        &lt;div&gt;&lt;img id=&quot;c&quot; src=&quot;badchess-tall.png&quot;&gt;&lt;/div&gt;
+        &lt;div&gt;&lt;img id=&quot;d&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+        &lt;div&gt;&lt;img id=&quot;e&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+        &lt;div&gt;&lt;img id=&quot;f&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+        &lt;div&gt;&lt;img id=&quot;g&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+    &lt;/div&gt;
+&lt;/div&gt;
</ins><span class="cx">\ No newline at end of file
</span><span class="cx">Property changes on: trunk/LayoutTests/fast/css/aspect-ratio/columns-expected.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsfastcssaspectratiocolumnshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/css/aspect-ratio/columns.html (0 => 164265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/aspect-ratio/columns.html                                (rev 0)
+++ trunk/LayoutTests/fast/css/aspect-ratio/columns.html        2014-02-18 02:31:18 UTC (rev 164265)
</span><span class="lines">@@ -0,0 +1,71 @@
</span><ins>+&lt;style&gt;
+.column-container {
+    max-width: 180px;
+}
+
+.columns {
+    box-sizing: border-box;
+    -webkit-column-width: 100px;
+    height: 300px;
+}
+
+img {
+    max-width: 100%;
+    max-height: 100%;
+    margin-bottom: 10px;
+}
+
+#b, #c, #e, #g {
+    width: 300px;
+    height: 300px;
+    -webkit-aspect-ratio: from-intrinsic;
+}
+
+#d, #e {
+    min-width: 20px;
+    max-width: 20px;
+    min-height: 20px;
+    max-height: 20px;
+}
+
+#f, #g {
+    width: auto;
+    height: auto;
+    min-width: 30px;
+    min-height: 30px;
+}
+
+#results {
+    width: initial;
+    height: initial;
+    max-width: initial;
+    max-height: initial;
+}
+&lt;/style&gt;
+
+&lt;div class=&quot;column-container&quot;&gt;
+    &lt;div class=&quot;columns&quot;&gt;
+
+        &lt;!-- auto sizing within constrained bounds --&gt;
+        &lt;div&gt;&lt;img id=&quot;a&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+        &lt;!-- specified sizing within constrained bounds and aspect ratio --&gt;
+        &lt;div&gt;&lt;img id=&quot;b&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+        &lt;!-- specified sizing within constrained bounds and aspect ratio --&gt;
+        &lt;div&gt;&lt;img id=&quot;c&quot; src=&quot;badchess-tall.png&quot;&gt;&lt;/div&gt;
+
+        &lt;!-- sizing with min/max constraints --&gt;
+        &lt;div&gt;&lt;img id=&quot;d&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+        &lt;!-- sizing with min/max constraints and aspect ratio --&gt;
+        &lt;div&gt;&lt;img id=&quot;e&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+        &lt;!-- auto sizing with min constraints --&gt;
+        &lt;div&gt;&lt;img id=&quot;f&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+        &lt;!-- auto sizing with min constraints and aspect ratio --&gt;
+        &lt;div&gt;&lt;img id=&quot;g&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+    &lt;/div&gt;
+&lt;/div&gt;
</ins><span class="cx">\ No newline at end of file
</span><span class="cx">Property changes on: trunk/LayoutTests/fast/css/aspect-ratio/columns.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsfastcssaspectratiocontainersexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/css/aspect-ratio/containers-expected.html (0 => 164265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/aspect-ratio/containers-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/css/aspect-ratio/containers-expected.html        2014-02-18 02:31:18 UTC (rev 164265)
</span><span class="lines">@@ -0,0 +1,44 @@
</span><ins>+&lt;style&gt;
+div {
+    position: relative;
+    width: 50px;
+    height: 50px;
+    margin-bottom: 5px;
+}
+img {
+    max-width: 100%;
+    max-height: 100%;
+}
+
+#b {
+    width: 50px;
+    height: 25px;
+}
+
+#c {
+    width: 25px;
+    height: 50px;
+}
+
+#d, #e {
+    min-width: 20px;
+    max-width: 20px;
+    min-height: 20px;
+    max-height: 20px;
+}
+
+#f, #g {
+    width: auto;
+    height: auto;
+    min-width: 30px;
+    min-height: 30px;
+}
+&lt;/style&gt;
+
+&lt;div&gt;&lt;img id=&quot;a&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;b&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;c&quot; src=&quot;badchess-tall.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;d&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;e&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;f&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;g&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
</ins><span class="cx">Property changes on: trunk/LayoutTests/fast/css/aspect-ratio/containers-expected.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsfastcssaspectratiocontainershtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/css/aspect-ratio/containers.html (0 => 164265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/aspect-ratio/containers.html                                (rev 0)
+++ trunk/LayoutTests/fast/css/aspect-ratio/containers.html        2014-02-18 02:31:18 UTC (rev 164265)
</span><span class="lines">@@ -0,0 +1,58 @@
</span><ins>+&lt;style&gt;
+div {
+    position: relative;
+    width: 50px;
+    height: 50px;
+    margin-bottom: 5px;
+}
+img {
+    max-width: 100%;
+    max-height: 100%;
+}
+
+#b, #c, #e, #g {
+    -webkit-aspect-ratio: from-intrinsic;
+}
+
+#d, #e {
+    min-width: 20px;
+    max-width: 20px;
+    min-height: 20px;
+    max-height: 20px;
+}
+
+#f, #g {
+    width: auto;
+    height: auto;
+    min-width: 30px;
+    min-height: 30px;
+}
+
+#results {
+    width: initial;
+    height: initial;
+    max-width: initial;
+    max-height: initial;
+}
+&lt;/style&gt;
+
+&lt;!-- auto sizing within constrained bounds --&gt;
+&lt;div&gt;&lt;img id=&quot;a&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- auto sizing within constrained bounds and aspect ratio --&gt;
+&lt;div&gt;&lt;img id=&quot;b&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- auto sizing within constrained bounds and aspect ratio --&gt;
+&lt;div&gt;&lt;img id=&quot;c&quot; src=&quot;badchess-tall.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- specified sizing with min/max constraints --&gt;
+&lt;div&gt;&lt;img id=&quot;d&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- specified sizing with min/max constraints and aspect ratio --&gt;
+&lt;div&gt;&lt;img id=&quot;e&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- auto sizing with min constraints --&gt;
+&lt;div&gt;&lt;img id=&quot;f&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- auto sizing with min constraints and aspect ratio --&gt;
+&lt;div&gt;&lt;img id=&quot;g&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
</ins><span class="cx">Property changes on: trunk/LayoutTests/fast/css/aspect-ratio/containers.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsfastcssaspectratiosimpleexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/css/aspect-ratio/simple-expected.html (0 => 164265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/aspect-ratio/simple-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/css/aspect-ratio/simple-expected.html        2014-02-18 02:31:18 UTC (rev 164265)
</span><span class="lines">@@ -0,0 +1,43 @@
</span><ins>+&lt;style&gt;
+div {
+    margin-bottom: 5px;
+}
+
+img {
+    width: 300px;
+    height: 10px;
+}
+
+#b {
+    width: 20px;
+    height: 10px;
+}
+
+#c {
+    width: 5px;
+    height: 10px;
+}
+
+#d, #e {
+    min-width: 20px;
+    max-width: 20px;
+    min-height: 20px;
+    max-height: 20px;
+}
+
+#f, #g {
+    width: auto;
+    height: auto;
+    max-width: 30px;
+    max-height: 30px;
+}
+
+&lt;/style&gt;
+
+&lt;div&gt;&lt;img id=&quot;a&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;b&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;c&quot; src=&quot;badchess-tall.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;d&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;e&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;f&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+&lt;div&gt;&lt;img id=&quot;g&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
</ins><span class="cx">Property changes on: trunk/LayoutTests/fast/css/aspect-ratio/simple-expected.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsfastcssaspectratiosimplehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/css/aspect-ratio/simple.html (0 => 164265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/aspect-ratio/simple.html                                (rev 0)
+++ trunk/LayoutTests/fast/css/aspect-ratio/simple.html        2014-02-18 02:31:18 UTC (rev 164265)
</span><span class="lines">@@ -0,0 +1,49 @@
</span><ins>+&lt;style&gt;
+div {
+    margin-bottom: 5px;
+}
+img {
+    width: 300px;
+    height: 10px;
+}
+
+#b, #c, #e, #g {
+    -webkit-aspect-ratio: from-intrinsic;
+}
+
+#d, #e {
+    min-width: 20px;
+    max-width: 20px;
+    min-height: 20px;
+    max-height: 20px;
+}
+
+#f, #g {
+    width: auto;
+    height: auto;
+    max-width: 30px;
+    max-height: 30px;
+}
+
+&lt;/style&gt;
+
+&lt;!-- specified sizing --&gt;
+&lt;div&gt;&lt;img id=&quot;a&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- intrinsic aspect ratio wide --&gt;
+&lt;div&gt;&lt;img id=&quot;b&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- intrinsic aspect ratio tall --&gt;
+&lt;div&gt;&lt;img id=&quot;c&quot; src=&quot;badchess-tall.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- specified sizing with min/max constraints --&gt;
+&lt;div&gt;&lt;img id=&quot;d&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- specified sizing with min/max constraints and aspect ratio --&gt;
+&lt;div&gt;&lt;img id=&quot;e&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- auto sizing with max constraints --&gt;
+&lt;div&gt;&lt;img id=&quot;f&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
+
+&lt;!-- auto sizing with max constraints and aspect ratio --&gt;
+&lt;div&gt;&lt;img id=&quot;g&quot; src=&quot;badchess-wide.png&quot;&gt;&lt;/div&gt;
</ins><span class="cx">Property changes on: trunk/LayoutTests/fast/css/aspect-ratio/simple.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svnkeywords"></a>
<div class="addfile"><h4>Added: svn:keywords</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (164264 => 164265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-18 02:03:49 UTC (rev 164264)
+++ trunk/Source/WebCore/ChangeLog        2014-02-18 02:31:18 UTC (rev 164265)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2014-02-17  Dean Jackson  &lt;dino@apple.com&gt;
+
+        Constrain replaced element layout to from-intrinsic aspect ratio if specified
+        https://bugs.webkit.org/show_bug.cgi?id=128629
+
+        Reviewed by Simon Fraser.
+
+        First pass at implementing -webkit-aspect-ratio: from-instrinsics;
+
+        After RenderReplaced has done layout, attempt to update the
+        resulting size to match the desired aspect ratio. This step
+        will only reduce the size of an element, and never below the
+        minimum dimensions.
+
+        Tests: fast/css/aspect-ratio/columns.html
+               fast/css/aspect-ratio/containers.html
+               fast/css/aspect-ratio/simple.html
+
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::imageDimensionsChanged): If we get an update
+        to our intrinsic dimensions, and layout depends on this, trigger
+        another layout pass.
+        * rendering/RenderReplaced.cpp:
+        (WebCore::RenderReplaced::layout): Implement the step described
+        above.
+
</ins><span class="cx"> 2014-02-17  Sam Weinig  &lt;sam@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix build.
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (164264 => 164265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderImage.cpp        2014-02-18 02:03:49 UTC (rev 164264)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp        2014-02-18 02:31:18 UTC (rev 164265)
</span><span class="lines">@@ -323,7 +323,9 @@
</span><span class="cx">             || style().logicalMaxWidth().isPercent()
</span><span class="cx">             || style().logicalMinWidth().isPercent();
</span><span class="cx"> 
</span><del>-        if (imageSizeChanged || hasOverrideSize || containingBlockNeedsToRecomputePreferredSize) {
</del><ins>+        bool layoutSizeDependsOnIntrinsicSize = style().aspectRatioType() == AspectRatioFromIntrinsic;
+
+        if (imageSizeChanged || hasOverrideSize || containingBlockNeedsToRecomputePreferredSize || layoutSizeDependsOnIntrinsicSize) {
</ins><span class="cx">             shouldRepaint = false;
</span><span class="cx">             if (!selfNeedsLayout())
</span><span class="cx">                 setNeedsLayout();
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderReplacedcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderReplaced.cpp (164264 => 164265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderReplaced.cpp        2014-02-18 02:03:49 UTC (rev 164264)
+++ trunk/Source/WebCore/rendering/RenderReplaced.cpp        2014-02-18 02:31:18 UTC (rev 164265)
</span><span class="lines">@@ -99,6 +99,18 @@
</span><span class="cx">     updateLogicalWidth();
</span><span class="cx">     updateLogicalHeight();
</span><span class="cx"> 
</span><ins>+    // Now that we've calculated our preferred layout, we check to see
+    // if we should further constrain sizing to the intrinsic aspect ratio.
+    if (style().aspectRatioType() == AspectRatioFromIntrinsic &amp;&amp; !m_intrinsicSize.isEmpty()) {
+        float aspectRatio = m_intrinsicSize.aspectRatio();
+        LayoutSize frameSize = size();
+        float frameAspectRatio = frameSize.aspectRatio();
+        if (frameAspectRatio &lt; aspectRatio)
+            setHeight(computeReplacedLogicalHeightRespectingMinMaxHeight(frameSize.height() * frameAspectRatio / aspectRatio));
+        else if (frameAspectRatio &gt; aspectRatio)
+            setWidth(computeReplacedLogicalWidthRespectingMinMaxWidth(frameSize.width() * aspectRatio / frameAspectRatio, ComputePreferred));
+    }
+
</ins><span class="cx">     clearOverflow();
</span><span class="cx">     addVisualEffectOverflow();
</span><span class="cx">     updateLayerTransform();
</span></span></pre>
</div>
</div>

</body>
</html>