<!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>[193952] branches/safari-601.1.46-branch</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/193952">193952</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2015-12-11 02:01:24 -0800 (Fri, 11 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/193859">r193859</a>. rdar://problem/23814345</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari601146branchLayoutTestsChangeLog">branches/safari-601.1.46-branch/LayoutTests/ChangeLog</a></li>
<li><a href="#branchessafari601146branchSourceWebCoreChangeLog">branches/safari-601.1.46-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari601146branchSourceWebCorecssMediaQueryEvaluatorcpp">branches/safari-601.1.46-branch/Source/WebCore/css/MediaQueryEvaluator.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCorecssMediaQueryEvaluatorh">branches/safari-601.1.46-branch/Source/WebCore/css/MediaQueryEvaluator.h</a></li>
<li><a href="#branchessafari601146branchSourceWebCorecssStyleResolverh">branches/safari-601.1.46-branch/Source/WebCore/css/StyleResolver.h</a></li>
<li><a href="#branchessafari601146branchSourceWebCoredomDocumentcpp">branches/safari-601.1.46-branch/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCoredomDocumenth">branches/safari-601.1.46-branch/Source/WebCore/dom/Document.h</a></li>
<li><a href="#branchessafari601146branchSourceWebCorehtmlHTMLImageElementcpp">branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCorehtmlHTMLPictureElementcpp">branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCorehtmlHTMLPictureElementh">branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.h</a></li>
<li><a href="#branchessafari601146branchSourceWebCorehtmlHTMLSourceElementcpp">branches/safari-601.1.46-branch/Source/WebCore/html/HTMLSourceElement.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCorehtmlHTMLSourceElementh">branches/safari-601.1.46-branch/Source/WebCore/html/HTMLSourceElement.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari601146branchLayoutTestsfastpictureresourcesresizetestjs">branches/safari-601.1.46-branch/LayoutTests/fast/picture/resources/resize-test.js</a></li>
<li><a href="#branchessafari601146branchLayoutTestsfastpictureviewportresizeexpectedtxt">branches/safari-601.1.46-branch/LayoutTests/fast/picture/viewport-resize-expected.txt</a></li>
<li><a href="#branchessafari601146branchLayoutTestsfastpictureviewportresizehtml">branches/safari-601.1.46-branch/LayoutTests/fast/picture/viewport-resize.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari601146branchLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/LayoutTests/ChangeLog (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/ChangeLog        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/LayoutTests/ChangeLog        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -1,5 +1,21 @@
</span><span class="cx"> 2015-12-11  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r193859. rdar://problem/23814345
+
+    2015-12-09  David Hyatt  &lt;hyatt@apple.com&gt;
+
+            Picture element needs to respond to dynamic viewport changes.
+            https://bugs.webkit.org/show_bug.cgi?id=152013
+            &lt;rdar://problem/23766375&gt;
+
+            Reviewed by Dean Jackson.
+
+            * fast/picture/resources/resize-test.js: Added.
+            * fast/picture/viewport-resize-expected.txt: Added.
+            * fast/picture/viewport-resize.html: Added.
+
+2015-12-11  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r193922. rdar://problem/23716993
</span><span class="cx"> 
</span><span class="cx">     2015-12-10  Enrica Casucci  &lt;enrica@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari601146branchLayoutTestsfastpictureresourcesresizetestjs"></a>
<div class="addfile"><h4>Added: branches/safari-601.1.46-branch/LayoutTests/fast/picture/resources/resize-test.js (0 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/fast/picture/resources/resize-test.js                                (rev 0)
+++ branches/safari-601.1.46-branch/LayoutTests/fast/picture/resources/resize-test.js        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -0,0 +1,58 @@
</span><ins>+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function resizeTest(sizes, testFunction)
+{
+    var widthDelta;
+    var heightDelta;
+
+    function performNextResize()
+    {
+        if (sizes.length) {
+            resizeTo(sizes[0][0] + widthDelta, sizes[0][1] + heightDelta);
+            return;
+        }
+        removeEventListener(&quot;resize&quot;, resizeHandler);
+        if (window.testRunner)
+            testRunner.notifyDone();
+    };
+
+    function resizeHandler()
+    {
+        var nextSize = sizes.shift();
+
+        shouldEvaluateTo(&quot;innerWidth&quot;, nextSize[0]);
+        shouldEvaluateTo(&quot;innerHeight&quot;, nextSize[1]);
+
+        testFunction();
+
+        performNextResize();
+    };
+
+    const warmupWidth = outerWidth + 13;
+
+    function warmupDone()
+    {
+        if (outerWidth != warmupWidth)
+            return;
+        widthDelta = outerWidth - innerWidth;
+        heightDelta = outerHeight - innerHeight;
+        removeEventListener(&quot;resize&quot;, warmupDone);
+        setTimeout(function () {
+            addEventListener(&quot;resize&quot;, resizeHandler);
+            performNextResize();
+        }, 0);
+    }
+
+    addEventListener(&quot;resize&quot;, warmupDone);
+    setTimeout(function () {
+        resizeTo(warmupWidth, outerHeight);
+    }, 0);
+}
+
+function standardResizeTest(testFunction)
+{
+    resizeTest([[800, 600], [1200, 600]], testFunction);
+}
</ins></span></pre></div>
<a id="branchessafari601146branchLayoutTestsfastpictureviewportresizeexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/safari-601.1.46-branch/LayoutTests/fast/picture/viewport-resize-expected.txt (0 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/fast/picture/viewport-resize-expected.txt                                (rev 0)
+++ branches/safari-601.1.46-branch/LayoutTests/fast/picture/viewport-resize-expected.txt        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -0,0 +1,59 @@
</span><ins>+Test that pictures properly update when the viewport changes size.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS innerWidth is 800
+PASS innerHeight is 600
+PASS document.getElementById(&quot;simple&quot;).clientWidth is 800
+PASS currentSrcFileName(&quot;simple&quot;) is &quot;image-set-2x.png?2&quot;
+PASS document.getElementById(&quot;multiple&quot;).clientWidth is 800
+PASS currentSrcFileName(&quot;multiple&quot;) is &quot;image-set-2x.png?2&quot;
+PASS document.getElementById(&quot;other_children&quot;).clientWidth is 800
+PASS currentSrcFileName(&quot;other_children&quot;) is &quot;image-set-2x.png?2&quot;
+PASS document.getElementById(&quot;img_before_source&quot;).clientWidth is 75
+PASS currentSrcFileName(&quot;img_before_source&quot;) is &quot;blue_rect.jpg?1&quot;
+PASS document.getElementById(&quot;unknown_type&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;unknown_type&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;svg_type&quot;).clientWidth is 800
+PASS currentSrcFileName(&quot;svg_type&quot;) is &quot;image-set-2x.png?2&quot;
+PASS document.getElementById(&quot;empty_type&quot;).clientWidth is 800
+PASS currentSrcFileName(&quot;empty_type&quot;) is &quot;image-set-2x.png?2&quot;
+PASS document.getElementById(&quot;whitespace_type&quot;).clientWidth is 800
+PASS currentSrcFileName(&quot;whitespace_type&quot;) is &quot;image-set-2x.png?2&quot;
+PASS document.getElementById(&quot;parameter_type&quot;).clientWidth is 800
+PASS currentSrcFileName(&quot;parameter_type&quot;) is &quot;image-set-2x.png?2&quot;
+PASS document.getElementById(&quot;empty_srcset&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;empty_srcset&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;no_srcset&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;no_srcset&quot;) is &quot;image-set-4x.png?3&quot;
+PASS innerWidth is 1200
+PASS innerHeight is 600
+PASS document.getElementById(&quot;simple&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;simple&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;multiple&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;multiple&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;other_children&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;other_children&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;img_before_source&quot;).clientWidth is 75
+PASS currentSrcFileName(&quot;img_before_source&quot;) is &quot;blue_rect.jpg?1&quot;
+PASS document.getElementById(&quot;unknown_type&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;unknown_type&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;svg_type&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;svg_type&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;empty_type&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;empty_type&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;whitespace_type&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;whitespace_type&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;parameter_type&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;parameter_type&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;empty_srcset&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;empty_srcset&quot;) is &quot;image-set-4x.png?3&quot;
+PASS document.getElementById(&quot;no_srcset&quot;).clientWidth is 1600
+PASS currentSrcFileName(&quot;no_srcset&quot;) is &quot;image-set-4x.png?3&quot;
+   
+some text
+         
</ins></span></pre></div>
<a id="branchessafari601146branchLayoutTestsfastpictureviewportresizehtml"></a>
<div class="addfile"><h4>Added: branches/safari-601.1.46-branch/LayoutTests/fast/picture/viewport-resize.html (0 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/fast/picture/viewport-resize.html                                (rev 0)
+++ branches/safari-601.1.46-branch/LayoutTests/fast/picture/viewport-resize.html        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -0,0 +1,149 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;body&gt;
+        &lt;!-- A canary image to see that the test is actually working --&gt;
+        &lt;img id=&quot;canary&quot; src=&quot;resources/blue_rect.jpg?0&quot;&gt;
+        &lt;!-- simple picture construct --&gt;
+        &lt;picture&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; sizes=&quot;800px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+                resources/image-set-4x.png?2 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+            &lt;img id=&quot;simple&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+        &lt;/picture&gt;
+        &lt;!-- Multiple img elements --&gt;
+        &lt;picture&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; sizes=&quot;800px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+                resources/image-set-4x.png?2 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+            &lt;img src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+            &lt;img id=&quot;multiple&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+        &lt;/picture&gt;
+        &lt;!-- non-source children - should be ignored--&gt;
+        &lt;picture&gt;
+            &lt;div&gt;some text&lt;/div&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; sizes=&quot;800px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+                resources/image-set-4x.png?2 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+            &lt;img id=&quot;other_children&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+        &lt;/picture&gt;
+        &lt;!-- img before its source siblings - should ignore its siblings --&gt;
+        &lt;picture&gt;
+            &lt;img id=&quot;img_before_source&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; sizes=&quot;800px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+                resources/image-set-4x.png?2 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+        &lt;/picture&gt;
+        &lt;!-- source with unknown type - should be ignored --&gt;
+        &lt;picture&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; type=&quot;image/nonsense&quot; sizes=&quot;800px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+                resources/image-set-4x.png?2 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+            &lt;img id=&quot;unknown_type&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+        &lt;/picture&gt;
+        &lt;!-- SVG source - should not be ignored --&gt;
+        &lt;picture&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; type=&quot;image/svg+xml&quot; sizes=&quot;800px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+                resources/image-set-4x.png?2 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+            &lt;img id=&quot;svg_type&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+        &lt;/picture&gt;
+        &lt;!-- Empty type - should not be ignored --&gt;
+        &lt;picture&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; type=&quot;&quot; sizes=&quot;800px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+                resources/image-set-4x.png?2 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+            &lt;img id=&quot;empty_type&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+        &lt;/picture&gt;
+        &lt;!-- whitespace type - should not be ignored --&gt;
+        &lt;picture&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; type=&quot; &quot; sizes=&quot;800px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+                resources/image-set-4x.png?2 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+            &lt;img id=&quot;whitespace_type&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+        &lt;/picture&gt;
+        &lt;!-- parameter type - should not be ignored --&gt;
+        &lt;picture&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; type=&quot;image/png;bla=bla&quot; sizes=&quot;800px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+                resources/image-set-4x.png?2 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+            &lt;img id=&quot;parameter_type&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+        &lt;/picture&gt;
+        &lt;!-- source with empty srcset - should be ignored --&gt;
+        &lt;picture&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; sizes=&quot;800px&quot; srcset=&quot;, ,  &quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+            &lt;img id=&quot;empty_srcset&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+        &lt;/picture&gt;
+        &lt;!-- source with no srcset - should be ignored --&gt;
+        &lt;picture&gt;
+            &lt;source media=&quot;(max-width: 400px)&quot; sizes=&quot;400px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+                resources/image-set-4x.png?1 1600w&quot;&gt;
+            &lt;source media=&quot;(max-width: 800px)&quot; sizes=&quot;800px&quot;&gt;
+            &lt;source media=&quot;(max-width: 1600px)&quot; sizes=&quot;1600px&quot; srcset=&quot;../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+                resources/image-set-4x.png?3 1600w&quot;&gt;
+            &lt;img id=&quot;no_srcset&quot; src=&quot;resources/blue_rect.jpg?1&quot;&gt;
+        &lt;/picture&gt;
+
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;resources/currentSrcHelper.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;resources/resize-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+description(&quot;Test that pictures properly update when the viewport changes size.&quot;);
+standardResizeTest(function () {
+            var expectedWidth = innerWidth &gt; 800 ? '1600' : '800'
+            var expectedImage = innerWidth &gt; 800 ? '&quot;image-set-4x.png?3&quot;' : '&quot;image-set-2x.png?2&quot;'
+            
+            shouldBe('document.getElementById(&quot;simple&quot;).clientWidth', expectedWidth);
+                shouldBe('currentSrcFileName(&quot;simple&quot;)', expectedImage);
+                shouldBe('document.getElementById(&quot;multiple&quot;).clientWidth', expectedWidth);
+                shouldBe('currentSrcFileName(&quot;multiple&quot;)', expectedImage);
+                shouldBe('document.getElementById(&quot;other_children&quot;).clientWidth', expectedWidth);
+                shouldBe('currentSrcFileName(&quot;other_children&quot;)', expectedImage);
+                shouldBe('document.getElementById(&quot;img_before_source&quot;).clientWidth', '75');
+                shouldBe('currentSrcFileName(&quot;img_before_source&quot;)', '&quot;blue_rect.jpg?1&quot;');
+                shouldBe('document.getElementById(&quot;unknown_type&quot;).clientWidth', '1600');
+                shouldBe('currentSrcFileName(&quot;unknown_type&quot;)', '&quot;image-set-4x.png?3&quot;');
+            shouldBe('document.getElementById(&quot;svg_type&quot;).clientWidth', expectedWidth);
+                shouldBe('currentSrcFileName(&quot;svg_type&quot;)', expectedImage);
+                shouldBe('document.getElementById(&quot;empty_type&quot;).clientWidth', expectedWidth);
+                shouldBe('currentSrcFileName(&quot;empty_type&quot;)', expectedImage);
+                shouldBe('document.getElementById(&quot;whitespace_type&quot;).clientWidth', expectedWidth);
+                shouldBe('currentSrcFileName(&quot;whitespace_type&quot;)', expectedImage);
+                shouldBe('document.getElementById(&quot;parameter_type&quot;).clientWidth', expectedWidth);
+                shouldBe('currentSrcFileName(&quot;parameter_type&quot;)', expectedImage);
+                shouldBe('document.getElementById(&quot;empty_srcset&quot;).clientWidth', '1600');
+                shouldBe('currentSrcFileName(&quot;empty_srcset&quot;)', '&quot;image-set-4x.png?3&quot;');
+                shouldBe('document.getElementById(&quot;no_srcset&quot;).clientWidth', '1600');
+                shouldBe('currentSrcFileName(&quot;no_srcset&quot;)', '&quot;image-set-4x.png?3&quot;');
+    });
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
</ins></span></pre></div>
<a id="branchessafari601146branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/ChangeLog (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/ChangeLog        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/ChangeLog        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -1,5 +1,67 @@
</span><span class="cx"> 2015-12-11  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r193859. rdar://problem/23814345
+
+    2015-12-09  David Hyatt  &lt;hyatt@apple.com&gt;
+
+            Picture element needs to respond to dynamic viewport changes.
+            https://bugs.webkit.org/show_bug.cgi?id=152013
+            &lt;rdar://problem/23766375&gt;
+
+            Reviewed by Dean Jackson.
+
+            Added new tests in fast/picture.
+
+            * css/MediaQueryEvaluator.cpp:
+            (WebCore::MediaQueryEvaluator::evalCheckingViewportDependentResults):
+            Add new evaluation method that adds viewport dependent results to a vector. A follow-up patch
+            will refactor the style resolver code to use this function instead of the special style resolver one, in order to
+            get rid of the code duplication. Tracked by https://bugs.webkit.org/show_bug.cgi?id=152089.
+
+            * css/MediaQueryEvaluator.h:
+            (WebCore::MediaQueryResult::MediaQueryResult):
+            * css/StyleResolver.h:
+            (WebCore::MediaQueryResult::MediaQueryResult): Deleted.
+            Move MediaQueryResult into a header since it is used in multiple places now and not just by the style
+            resolver.
+
+            * dom/Document.cpp:
+            (WebCore::Document::evaluateMediaQueryList):
+            (WebCore::Document::checkViewportDependentPictures):
+            (WebCore::Document::optimizedStyleSheetUpdateTimerFired):
+            (WebCore::Document::applyContentDispositionAttachmentSandbox):
+            (WebCore::Document::addViewportDependentPicture):
+            (WebCore::Document::removeViewportDependentPicture):
+            * dom/Document.h:
+            The document now maintains a HashSet of viewport-dependent pictures, and it checks them whenever the
+            viewport changes. If their media queries stay the same, then nothing happens. If they change, then
+            the &lt;picture&gt; will go back and re-check all its &lt;source&gt; elements to see what the new best candidate is.
+
+            * html/HTMLImageElement.cpp:
+            (WebCore::HTMLImageElement::bestFitSourceFromPictureElement):
+            Revised to check for viewport dependencies and to cache viewport-dependent results on the &lt;picture&gt; elements.
+            When a &lt;picture&gt; is found to be viewport-dependent (or not) it is also added to or removed from the document's
+            set of tracked pictures.
+
+            * html/HTMLPictureElement.cpp:
+            (WebCore::HTMLPictureElement::HTMLPictureElement):
+            (WebCore::HTMLPictureElement::~HTMLPictureElement):
+            (WebCore::HTMLPictureElement::didMoveToNewDocument):
+            (WebCore::HTMLPictureElement::create):
+            (WebCore::HTMLPictureElement::sourcesChanged):
+            (WebCore::HTMLPictureElement::viewportChangeAffectedPicture):
+            * html/HTMLPictureElement.h:
+            New caching of results and updating of the document HashSet when the picture gets destroyed or moves to
+            a different document.
+
+            * html/HTMLSourceElement.cpp:
+            (WebCore::HTMLSourceElement::parseAttribute):
+            * html/HTMLSourceElement.h:
+            Cache the media attribute in a parsed form. A follow-up patch will improve the &lt;video&gt;/&lt;audio&gt;
+            code to make use of this parsed result. Tracked by https://bugs.webkit.org/show_bug.cgi?id=152090.
+
+2015-12-11  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r193922. rdar://problem/23716993
</span><span class="cx"> 
</span><span class="cx">     2015-12-10  Enrica Casucci  &lt;enrica@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorecssMediaQueryEvaluatorcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/css/MediaQueryEvaluator.cpp (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/css/MediaQueryEvaluator.cpp        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/css/MediaQueryEvaluator.cpp        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -170,6 +170,40 @@
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool MediaQueryEvaluator::evalCheckingViewportDependentResults(const MediaQuerySet* querySet, Vector&lt;std::unique_ptr&lt;MediaQueryResult&gt;&gt;&amp; results)
+{
+    if (!querySet)
+        return true;
+
+    auto&amp; queries = querySet-&gt;queryVector();
+    if (!queries.size())
+        return true;
+
+    bool result = false;
+    for (size_t i = 0; i &lt; queries.size() &amp;&amp; !result; ++i) {
+        MediaQuery* query = queries[i].get();
+
+        if (query-&gt;ignored())
+            continue;
+
+        if (mediaTypeMatch(query-&gt;mediaType())) {
+            auto&amp; expressions = query-&gt;expressions();
+            size_t j = 0;
+            for (; j &lt; expressions.size(); ++j) {
+                bool exprResult = eval(expressions.at(j).get());
+                if (expressions.at(j)-&gt;isViewportDependent())
+                    results.append(std::make_unique&lt;MediaQueryResult&gt;(*expressions.at(j), exprResult));
+                if (!exprResult)
+                    break;
+            }
+            result = applyRestrictor(query-&gt;restrictor(), expressions.size() == j);
+        } else
+            result = applyRestrictor(query-&gt;restrictor(), false);
+    }
+
+    return result;
+}
+
</ins><span class="cx"> template&lt;typename T&gt;
</span><span class="cx"> bool compareValue(T a, T b, MediaFeaturePrefix op)
</span><span class="cx"> {
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorecssMediaQueryEvaluatorh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/css/MediaQueryEvaluator.h (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/css/MediaQueryEvaluator.h        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/css/MediaQueryEvaluator.h        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #ifndef MediaQueryEvaluator_h
</span><span class="cx"> #define MediaQueryEvaluator_h
</span><span class="cx"> 
</span><ins>+#include &quot;MediaQueryExp.h&quot;
</ins><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -37,6 +38,19 @@
</span><span class="cx"> class RenderStyle;
</span><span class="cx"> class StyleResolver;
</span><span class="cx"> 
</span><ins>+class MediaQueryResult {
+    WTF_MAKE_NONCOPYABLE(MediaQueryResult); WTF_MAKE_FAST_ALLOCATED;
+public:
+    MediaQueryResult(const MediaQueryExp&amp; expr, bool result)
+        : m_expression(expr)
+        , m_result(result)
+    {
+    }
+
+    MediaQueryExp m_expression;
+    bool m_result;
+};
+
</ins><span class="cx"> /**
</span><span class="cx">  * Class that evaluates css media queries as defined in
</span><span class="cx">  * CSS3 Module &quot;Media Queries&quot; (http://www.w3.org/TR/css3-mediaqueries/)
</span><span class="lines">@@ -78,6 +92,9 @@
</span><span class="cx"> 
</span><span class="cx">     /** Evaluates media query subexpression, ie &quot;and (media-feature: value)&quot; part */
</span><span class="cx">     bool eval(const MediaQueryExp*) const;
</span><ins>+    
+    /* Evaluates a list of media queries and fills in a vector with any viewport-dependent results found. */
+    bool evalCheckingViewportDependentResults(const MediaQuerySet*, Vector&lt;std::unique_ptr&lt;MediaQueryResult&gt;&gt;&amp;);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     String m_mediaType;
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorecssStyleResolverh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/css/StyleResolver.h (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/css/StyleResolver.h        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/css/StyleResolver.h        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -28,7 +28,7 @@
</span><span class="cx"> #include &quot;DocumentRuleSets.h&quot;
</span><span class="cx"> #include &quot;InspectorCSSOMWrappers.h&quot;
</span><span class="cx"> #include &quot;LinkHash.h&quot;
</span><del>-#include &quot;MediaQueryExp.h&quot;
</del><ins>+#include &quot;MediaQueryEvaluator.h&quot;
</ins><span class="cx"> #include &quot;RenderStyle.h&quot;
</span><span class="cx"> #include &quot;RuleFeature.h&quot;
</span><span class="cx"> #include &quot;RuleSet.h&quot;
</span><span class="lines">@@ -93,19 +93,6 @@
</span><span class="cx"> class WebKitCSSFilterValue;
</span><span class="cx"> struct ResourceLoaderOptions;
</span><span class="cx"> 
</span><del>-class MediaQueryResult {
-    WTF_MAKE_NONCOPYABLE(MediaQueryResult); WTF_MAKE_FAST_ALLOCATED;
-public:
-    MediaQueryResult(const MediaQueryExp&amp; expr, bool result)
-        : m_expression(expr)
-        , m_result(result)
-    {
-    }
-
-    MediaQueryExp m_expression;
-    bool m_result;
-};
-
</del><span class="cx"> enum StyleSharingBehavior {
</span><span class="cx">     AllowStyleSharing,
</span><span class="cx">     DisallowStyleSharing,
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/dom/Document.cpp (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/dom/Document.cpp        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/dom/Document.cpp        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -81,6 +81,7 @@
</span><span class="cx"> #include &quot;HTMLMediaElement.h&quot;
</span><span class="cx"> #include &quot;HTMLNameCollection.h&quot;
</span><span class="cx"> #include &quot;HTMLParserIdioms.h&quot;
</span><ins>+#include &quot;HTMLPictureElement.h&quot;
</ins><span class="cx"> #include &quot;HTMLPlugInElement.h&quot;
</span><span class="cx"> #include &quot;HTMLScriptElement.h&quot;
</span><span class="cx"> #include &quot;HTMLStyleElement.h&quot;
</span><span class="lines">@@ -3470,8 +3471,22 @@
</span><span class="cx"> {
</span><span class="cx">     if (m_mediaQueryMatcher)
</span><span class="cx">         m_mediaQueryMatcher-&gt;styleResolverChanged();
</span><ins>+    
+    checkViewportDependentPictures();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Document::checkViewportDependentPictures()
+{
+    Vector&lt;HTMLPictureElement*, 16&gt; changedPictures;
+    HashSet&lt;HTMLPictureElement*&gt;::iterator end = m_viewportDependentPictures.end();
+    for (HashSet&lt;HTMLPictureElement*&gt;::iterator it = m_viewportDependentPictures.begin(); it != end; ++it) {
+        if ((*it)-&gt;viewportChangeAffectedPicture())
+            changedPictures.append(*it);
+    }
+    for (auto* picture : changedPictures)
+        picture-&gt;sourcesChanged();
+}
+
</ins><span class="cx"> void Document::optimizedStyleSheetUpdateTimerFired()
</span><span class="cx"> {
</span><span class="cx">     styleResolverChanged(RecalcStyleIfNeeded);
</span><span class="lines">@@ -6738,4 +6753,14 @@
</span><span class="cx">         enforceSandboxFlags(SandboxOrigin);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Document::addViewportDependentPicture(HTMLPictureElement&amp; picture)
+{
+    m_viewportDependentPictures.add(&amp;picture);
+}
+
+void Document::removeViewportDependentPicture(HTMLPictureElement&amp; picture)
+{
+    m_viewportDependentPictures.remove(&amp;picture);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/dom/Document.h (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/dom/Document.h        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/dom/Document.h        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -114,6 +114,7 @@
</span><span class="cx"> class HTMLMapElement;
</span><span class="cx"> class HTMLMediaElement;
</span><span class="cx"> class HTMLNameCollection;
</span><ins>+class HTMLPictureElement;
</ins><span class="cx"> class HTMLScriptElement;
</span><span class="cx"> class HitTestRequest;
</span><span class="cx"> class HitTestResult;
</span><span class="lines">@@ -1280,6 +1281,9 @@
</span><span class="cx">     bool shouldEnforceContentDispositionAttachmentSandbox() const;
</span><span class="cx">     void applyContentDispositionAttachmentSandbox();
</span><span class="cx"> 
</span><ins>+    void addViewportDependentPicture(HTMLPictureElement&amp;);
+    void removeViewportDependentPicture(HTMLPictureElement&amp;);
+
</ins><span class="cx"> protected:
</span><span class="cx">     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 &lt;&lt; 1 };
</span><span class="cx">     Document(Frame*, const URL&amp;, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0);
</span><span class="lines">@@ -1374,6 +1378,8 @@
</span><span class="cx">     void domCookieCacheExpiryTimerFired();
</span><span class="cx">     virtual void didLoadResourceSynchronously(const ResourceRequest&amp;) override final;
</span><span class="cx"> 
</span><ins>+    void checkViewportDependentPictures();
+
</ins><span class="cx">     unsigned m_referencingNodeCount;
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;StyleResolver&gt; m_styleResolver;
</span><span class="lines">@@ -1596,6 +1602,8 @@
</span><span class="cx">     RefPtr&lt;RenderStyle&gt; m_savedPlaceholderRenderStyle;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    HashSet&lt;HTMLPictureElement*&gt; m_viewportDependentPictures;
+
</ins><span class="cx">     int m_loadEventDelayCount;
</span><span class="cx">     Timer m_loadEventDelayTimer;
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorehtmlHTMLImageElementcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.cpp (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.cpp        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.cpp        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> #include &quot;HTMLDocument.h&quot;
</span><span class="cx"> #include &quot;HTMLFormElement.h&quot;
</span><span class="cx"> #include &quot;HTMLParserIdioms.h&quot;
</span><ins>+#include &quot;HTMLPictureElement.h&quot;
</ins><span class="cx"> #include &quot;HTMLSourceElement.h&quot;
</span><span class="cx"> #include &quot;HTMLSrcsetParser.h&quot;
</span><span class="cx"> #include &quot;MIMETypeRegistry.h&quot;
</span><span class="lines">@@ -145,6 +146,9 @@
</span><span class="cx">     auto* parent = parentNode();
</span><span class="cx">     if (!is&lt;HTMLPictureElement&gt;(parent))
</span><span class="cx">         return { };
</span><ins>+    auto* picture = downcast&lt;HTMLPictureElement&gt;(parent);
+    picture-&gt;clearViewportDependentResults();
+    document().removeViewportDependentPicture(*picture);
</ins><span class="cx">     for (Node* child = parent-&gt;firstChild(); child &amp;&amp; child != this; child = child-&gt;nextSibling()) {
</span><span class="cx">         if (!is&lt;HTMLSourceElement&gt;(*child))
</span><span class="cx">             continue;
</span><span class="lines">@@ -163,7 +167,10 @@
</span><span class="cx">                 continue;
</span><span class="cx">         }
</span><span class="cx">         MediaQueryEvaluator evaluator(document().printing() ? &quot;print&quot; : &quot;screen&quot;, document().frame(), computedStyle());
</span><del>-        if (!evaluator.eval(MediaQuerySet::createAllowingDescriptionSyntax(source.media()).ptr()))
</del><ins>+        bool evaluation = evaluator.evalCheckingViewportDependentResults(source.mediaQuerySet(), picture-&gt;viewportDependentResults());
+        if (picture-&gt;hasViewportDependentResults())
+            document().addViewportDependentPicture(*picture);
+        if (!evaluation)
</ins><span class="cx">             continue;
</span><span class="cx">         
</span><span class="cx">         float sourceSize = parseSizesAttribute(source.fastGetAttribute(sizesAttr).string(), document().renderView(), document().frame());
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorehtmlHTMLPictureElementcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.cpp (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.cpp        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.cpp        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -37,6 +37,20 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+HTMLPictureElement::~HTMLPictureElement()
+{
+    if (hasViewportDependentResults())
+        document().removeViewportDependentPicture(*this);
+}
+
+void HTMLPictureElement::didMoveToNewDocument(Document* oldDocument)
+{
+    if (hasViewportDependentResults() &amp;&amp; oldDocument)
+        oldDocument-&gt;removeViewportDependentPicture(*this);
+    HTMLElement::didMoveToNewDocument(oldDocument);
+    sourcesChanged();
+}
+
</ins><span class="cx"> Ref&lt;HTMLPictureElement&gt; HTMLPictureElement::create(const QualifiedName&amp; tagName, Document&amp; document)
</span><span class="cx"> {
</span><span class="cx">     return adoptRef(*new HTMLPictureElement(tagName, document));
</span><span class="lines">@@ -48,5 +62,16 @@
</span><span class="cx">         imageElement.selectImageSource();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool HTMLPictureElement::viewportChangeAffectedPicture()
+{
+    MediaQueryEvaluator evaluator(document().printing() ? &quot;print&quot; : &quot;screen&quot;, document().frame(), computedStyle());
+    unsigned numResults = m_viewportDependentMediaQueryResults.size();
+    for (unsigned i = 0; i &lt; numResults; i++) {
+        if (evaluator.eval(&amp;m_viewportDependentMediaQueryResults[i]-&gt;m_expression) != m_viewportDependentMediaQueryResults[i]-&gt;m_result)
+            return true;
+    }
+    return false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins></span></pre></div>
<a id="branchessafari601146branchSourceWebCorehtmlHTMLPictureElementh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.h (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.h        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.h        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -27,17 +27,30 @@
</span><span class="cx"> #define HTMLPictureElement_h
</span><span class="cx"> 
</span><span class="cx"> #include &quot;HTMLElement.h&quot;
</span><ins>+#include &quot;MediaQueryEvaluator.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class HTMLPictureElement final : public HTMLElement {
</span><span class="cx"> public:
</span><span class="cx">     static Ref&lt;HTMLPictureElement&gt; create(const QualifiedName&amp;, Document&amp;);
</span><ins>+    ~HTMLPictureElement();
</ins><span class="cx"> 
</span><span class="cx">     void sourcesChanged();
</span><span class="cx"> 
</span><ins>+    void clearViewportDependentResults() { m_viewportDependentMediaQueryResults.clear(); }
+    bool hasViewportDependentResults() const { return m_viewportDependentMediaQueryResults.size(); }
+    Vector&lt;std::unique_ptr&lt;MediaQueryResult&gt;&gt;&amp; viewportDependentResults() { return m_viewportDependentMediaQueryResults; }
+
+    void didMoveToNewDocument(Document* oldDocument);
+    
+    bool viewportChangeAffectedPicture();
+
</ins><span class="cx"> private:
</span><span class="cx">     HTMLPictureElement(const QualifiedName&amp;, Document&amp;);
</span><ins>+    
+    Vector&lt;std::unique_ptr&lt;MediaQueryResult&gt;&gt; m_viewportDependentMediaQueryResults;
+
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorehtmlHTMLSourceElementcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/html/HTMLSourceElement.cpp (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/html/HTMLSourceElement.cpp        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/html/HTMLSourceElement.cpp        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -167,6 +167,8 @@
</span><span class="cx"> {
</span><span class="cx">     HTMLElement::parseAttribute(name, value);
</span><span class="cx">     if (name == srcsetAttr || name == sizesAttr || name == mediaAttr || name == typeAttr) {
</span><ins>+        if (name == mediaAttr)
+            m_mediaQuerySet = MediaQuerySet::createAllowingDescriptionSyntax(value);
</ins><span class="cx">         auto* parent = parentNode();
</span><span class="cx">         if (is&lt;HTMLPictureElement&gt;(parent))
</span><span class="cx">             downcast&lt;HTMLPictureElement&gt;(*parent).sourcesChanged();
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorehtmlHTMLSourceElementh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/html/HTMLSourceElement.h (193951 => 193952)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/html/HTMLSourceElement.h        2015-12-11 10:01:16 UTC (rev 193951)
+++ branches/safari-601.1.46-branch/Source/WebCore/html/HTMLSourceElement.h        2015-12-11 10:01:24 UTC (rev 193952)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #define HTMLSourceElement_h
</span><span class="cx"> 
</span><span class="cx"> #include &quot;HTMLElement.h&quot;
</span><ins>+#include &quot;MediaList.h&quot;
</ins><span class="cx"> #include &quot;Timer.h&quot;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -44,6 +45,8 @@
</span><span class="cx">     void scheduleErrorEvent();
</span><span class="cx">     void cancelPendingErrorEvent();
</span><span class="cx"> 
</span><ins>+    MediaQuerySet* mediaQuerySet() const { return m_mediaQuerySet.get(); }
+
</ins><span class="cx"> private:
</span><span class="cx">     HTMLSourceElement(const QualifiedName&amp;, Document&amp;);
</span><span class="cx">     
</span><span class="lines">@@ -64,6 +67,7 @@
</span><span class="cx"> 
</span><span class="cx">     Timer m_errorEventTimer;
</span><span class="cx">     bool m_shouldRescheduleErrorEventOnResume { false };
</span><ins>+    RefPtr&lt;MediaQuerySet&gt; m_mediaQuerySet;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } //namespace
</span></span></pre>
</div>
</div>

</body>
</html>