Diff
Modified: branches/safari-601-branch/LayoutTests/ChangeLog (193965 => 193966)
--- branches/safari-601-branch/LayoutTests/ChangeLog 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/LayoutTests/ChangeLog 2015-12-11 18:26:38 UTC (rev 193966)
@@ -1,5 +1,21 @@
2015-12-11 Matthew Hanson <matthew_han...@apple.com>
+ Merge r193859. rdar://problem/23814477
+
+ 2015-12-09 David Hyatt <hy...@apple.com>
+
+ Picture element needs to respond to dynamic viewport changes.
+ https://bugs.webkit.org/show_bug.cgi?id=152013
+ <rdar://problem/23766375>
+
+ 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 <matthew_han...@apple.com>
+
Merge r192772. rdar://problem/23797220
2015-11-18 Andy Estes <aes...@apple.com>
Added: branches/safari-601-branch/LayoutTests/fast/picture/resources/resize-test.js (0 => 193966)
--- branches/safari-601-branch/LayoutTests/fast/picture/resources/resize-test.js (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/picture/resources/resize-test.js 2015-12-11 18:26:38 UTC (rev 193966)
@@ -0,0 +1,58 @@
+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("resize", resizeHandler);
+ if (window.testRunner)
+ testRunner.notifyDone();
+ };
+
+ function resizeHandler()
+ {
+ var nextSize = sizes.shift();
+
+ shouldEvaluateTo("innerWidth", nextSize[0]);
+ shouldEvaluateTo("innerHeight", nextSize[1]);
+
+ testFunction();
+
+ performNextResize();
+ };
+
+ const warmupWidth = outerWidth + 13;
+
+ function warmupDone()
+ {
+ if (outerWidth != warmupWidth)
+ return;
+ widthDelta = outerWidth - innerWidth;
+ heightDelta = outerHeight - innerHeight;
+ removeEventListener("resize", warmupDone);
+ setTimeout(function () {
+ addEventListener("resize", resizeHandler);
+ performNextResize();
+ }, 0);
+ }
+
+ addEventListener("resize", warmupDone);
+ setTimeout(function () {
+ resizeTo(warmupWidth, outerHeight);
+ }, 0);
+}
+
+function standardResizeTest(testFunction)
+{
+ resizeTest([[800, 600], [1200, 600]], testFunction);
+}
Added: branches/safari-601-branch/LayoutTests/fast/picture/viewport-resize-expected.txt (0 => 193966)
--- branches/safari-601-branch/LayoutTests/fast/picture/viewport-resize-expected.txt (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/picture/viewport-resize-expected.txt 2015-12-11 18:26:38 UTC (rev 193966)
@@ -0,0 +1,59 @@
+Test that pictures properly update when the viewport changes size.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS innerWidth is 800
+PASS innerHeight is 600
+PASS document.getElementById("simple").clientWidth is 800
+PASS currentSrcFileName("simple") is "image-set-2x.png?2"
+PASS document.getElementById("multiple").clientWidth is 800
+PASS currentSrcFileName("multiple") is "image-set-2x.png?2"
+PASS document.getElementById("other_children").clientWidth is 800
+PASS currentSrcFileName("other_children") is "image-set-2x.png?2"
+PASS document.getElementById("img_before_source").clientWidth is 75
+PASS currentSrcFileName("img_before_source") is "blue_rect.jpg?1"
+PASS document.getElementById("unknown_type").clientWidth is 1600
+PASS currentSrcFileName("unknown_type") is "image-set-4x.png?3"
+PASS document.getElementById("svg_type").clientWidth is 800
+PASS currentSrcFileName("svg_type") is "image-set-2x.png?2"
+PASS document.getElementById("empty_type").clientWidth is 800
+PASS currentSrcFileName("empty_type") is "image-set-2x.png?2"
+PASS document.getElementById("whitespace_type").clientWidth is 800
+PASS currentSrcFileName("whitespace_type") is "image-set-2x.png?2"
+PASS document.getElementById("parameter_type").clientWidth is 800
+PASS currentSrcFileName("parameter_type") is "image-set-2x.png?2"
+PASS document.getElementById("empty_srcset").clientWidth is 1600
+PASS currentSrcFileName("empty_srcset") is "image-set-4x.png?3"
+PASS document.getElementById("no_srcset").clientWidth is 1600
+PASS currentSrcFileName("no_srcset") is "image-set-4x.png?3"
+PASS innerWidth is 1200
+PASS innerHeight is 600
+PASS document.getElementById("simple").clientWidth is 1600
+PASS currentSrcFileName("simple") is "image-set-4x.png?3"
+PASS document.getElementById("multiple").clientWidth is 1600
+PASS currentSrcFileName("multiple") is "image-set-4x.png?3"
+PASS document.getElementById("other_children").clientWidth is 1600
+PASS currentSrcFileName("other_children") is "image-set-4x.png?3"
+PASS document.getElementById("img_before_source").clientWidth is 75
+PASS currentSrcFileName("img_before_source") is "blue_rect.jpg?1"
+PASS document.getElementById("unknown_type").clientWidth is 1600
+PASS currentSrcFileName("unknown_type") is "image-set-4x.png?3"
+PASS document.getElementById("svg_type").clientWidth is 1600
+PASS currentSrcFileName("svg_type") is "image-set-4x.png?3"
+PASS document.getElementById("empty_type").clientWidth is 1600
+PASS currentSrcFileName("empty_type") is "image-set-4x.png?3"
+PASS document.getElementById("whitespace_type").clientWidth is 1600
+PASS currentSrcFileName("whitespace_type") is "image-set-4x.png?3"
+PASS document.getElementById("parameter_type").clientWidth is 1600
+PASS currentSrcFileName("parameter_type") is "image-set-4x.png?3"
+PASS document.getElementById("empty_srcset").clientWidth is 1600
+PASS currentSrcFileName("empty_srcset") is "image-set-4x.png?3"
+PASS document.getElementById("no_srcset").clientWidth is 1600
+PASS currentSrcFileName("no_srcset") is "image-set-4x.png?3"
+
+some text
+
Added: branches/safari-601-branch/LayoutTests/fast/picture/viewport-resize.html (0 => 193966)
--- branches/safari-601-branch/LayoutTests/fast/picture/viewport-resize.html (rev 0)
+++ branches/safari-601-branch/LayoutTests/fast/picture/viewport-resize.html 2015-12-11 18:26:38 UTC (rev 193966)
@@ -0,0 +1,149 @@
+<!DOCTYPE html>
+<body>
+ <!-- A canary image to see that the test is actually working -->
+ <img id="canary" src=""
+ <!-- simple picture construct -->
+ <picture>
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" sizes="800px" srcset="../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+ resources/image-set-4x.png?2 1600w">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ <img id="simple" src=""
+ </picture>
+ <!-- Multiple img elements -->
+ <picture>
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" sizes="800px" srcset="../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+ resources/image-set-4x.png?2 1600w">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ <img src=""
+ <img id="multiple" src=""
+ </picture>
+ <!-- non-source children - should be ignored-->
+ <picture>
+ <div>some text</div>
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" sizes="800px" srcset="../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+ resources/image-set-4x.png?2 1600w">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ <img id="other_children" src=""
+ </picture>
+ <!-- img before its source siblings - should ignore its siblings -->
+ <picture>
+ <img id="img_before_source" src=""
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" sizes="800px" srcset="../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+ resources/image-set-4x.png?2 1600w">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ </picture>
+ <!-- source with unknown type - should be ignored -->
+ <picture>
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" type="image/nonsense" sizes="800px" srcset="../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+ resources/image-set-4x.png?2 1600w">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ <img id="unknown_type" src=""
+ </picture>
+ <!-- SVG source - should not be ignored -->
+ <picture>
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" type="image/svg+xml" sizes="800px" srcset="../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+ resources/image-set-4x.png?2 1600w">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ <img id="svg_type" src=""
+ </picture>
+ <!-- Empty type - should not be ignored -->
+ <picture>
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" type="" sizes="800px" srcset="../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+ resources/image-set-4x.png?2 1600w">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ <img id="empty_type" src=""
+ </picture>
+ <!-- whitespace type - should not be ignored -->
+ <picture>
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" type=" " sizes="800px" srcset="../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+ resources/image-set-4x.png?2 1600w">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ <img id="whitespace_type" src=""
+ </picture>
+ <!-- parameter type - should not be ignored -->
+ <picture>
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" type="image/png;bla=bla" sizes="800px" srcset="../hidpi/resources/image-set-1x.png?2 400w, ../hidpi/resources/image-set-2x.png?2 800w,
+ resources/image-set-4x.png?2 1600w">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ <img id="parameter_type" src=""
+ </picture>
+ <!-- source with empty srcset - should be ignored -->
+ <picture>
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" sizes="800px" srcset=", , ">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ <img id="empty_srcset" src=""
+ </picture>
+ <!-- source with no srcset - should be ignored -->
+ <picture>
+ <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w, ../hidpi/resources/image-set-2x.png?1 800w,
+ resources/image-set-4x.png?1 1600w">
+ <source media="(max-width: 800px)" sizes="800px">
+ <source media="(max-width: 1600px)" sizes="1600px" srcset="../hidpi/resources/image-set-1x.png?3 400w, ../hidpi/resources/image-set-2x.png?3 800w,
+ resources/image-set-4x.png?3 1600w">
+ <img id="no_srcset" src=""
+ </picture>
+
+<script src=""
+<script src=""
+<script src=""
+<script>
+description("Test that pictures properly update when the viewport changes size.");
+standardResizeTest(function () {
+ var expectedWidth = innerWidth > 800 ? '1600' : '800'
+ var expectedImage = innerWidth > 800 ? '"image-set-4x.png?3"' : '"image-set-2x.png?2"'
+
+ shouldBe('document.getElementById("simple").clientWidth', expectedWidth);
+ shouldBe('currentSrcFileName("simple")', expectedImage);
+ shouldBe('document.getElementById("multiple").clientWidth', expectedWidth);
+ shouldBe('currentSrcFileName("multiple")', expectedImage);
+ shouldBe('document.getElementById("other_children").clientWidth', expectedWidth);
+ shouldBe('currentSrcFileName("other_children")', expectedImage);
+ shouldBe('document.getElementById("img_before_source").clientWidth', '75');
+ shouldBe('currentSrcFileName("img_before_source")', '"blue_rect.jpg?1"');
+ shouldBe('document.getElementById("unknown_type").clientWidth', '1600');
+ shouldBe('currentSrcFileName("unknown_type")', '"image-set-4x.png?3"');
+ shouldBe('document.getElementById("svg_type").clientWidth', expectedWidth);
+ shouldBe('currentSrcFileName("svg_type")', expectedImage);
+ shouldBe('document.getElementById("empty_type").clientWidth', expectedWidth);
+ shouldBe('currentSrcFileName("empty_type")', expectedImage);
+ shouldBe('document.getElementById("whitespace_type").clientWidth', expectedWidth);
+ shouldBe('currentSrcFileName("whitespace_type")', expectedImage);
+ shouldBe('document.getElementById("parameter_type").clientWidth', expectedWidth);
+ shouldBe('currentSrcFileName("parameter_type")', expectedImage);
+ shouldBe('document.getElementById("empty_srcset").clientWidth', '1600');
+ shouldBe('currentSrcFileName("empty_srcset")', '"image-set-4x.png?3"');
+ shouldBe('document.getElementById("no_srcset").clientWidth', '1600');
+ shouldBe('currentSrcFileName("no_srcset")', '"image-set-4x.png?3"');
+ });
+</script>
+<script src=""
Modified: branches/safari-601-branch/Source/WebCore/ChangeLog (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/ChangeLog 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/ChangeLog 2015-12-11 18:26:38 UTC (rev 193966)
@@ -1,5 +1,67 @@
2015-12-11 Matthew Hanson <matthew_han...@apple.com>
+ Merge r193859. rdar://problem/23814477
+
+ 2015-12-09 David Hyatt <hy...@apple.com>
+
+ Picture element needs to respond to dynamic viewport changes.
+ https://bugs.webkit.org/show_bug.cgi?id=152013
+ <rdar://problem/23766375>
+
+ 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 <picture> will go back and re-check all its <source> 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 <picture> elements.
+ When a <picture> 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 <video>/<audio>
+ code to make use of this parsed result. Tracked by https://bugs.webkit.org/show_bug.cgi?id=152090.
+
+2015-12-11 Matthew Hanson <matthew_han...@apple.com>
+
Merge r192772. rdar://problem/23797220
2015-11-18 Andy Estes <aes...@apple.com>
Modified: branches/safari-601-branch/Source/WebCore/css/MediaQueryEvaluator.cpp (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/css/MediaQueryEvaluator.cpp 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/css/MediaQueryEvaluator.cpp 2015-12-11 18:26:38 UTC (rev 193966)
@@ -170,6 +170,40 @@
return result;
}
+bool MediaQueryEvaluator::evalCheckingViewportDependentResults(const MediaQuerySet* querySet, Vector<std::unique_ptr<MediaQueryResult>>& results)
+{
+ if (!querySet)
+ return true;
+
+ auto& queries = querySet->queryVector();
+ if (!queries.size())
+ return true;
+
+ bool result = false;
+ for (size_t i = 0; i < queries.size() && !result; ++i) {
+ MediaQuery* query = queries[i].get();
+
+ if (query->ignored())
+ continue;
+
+ if (mediaTypeMatch(query->mediaType())) {
+ auto& expressions = query->expressions();
+ size_t j = 0;
+ for (; j < expressions.size(); ++j) {
+ bool exprResult = eval(expressions.at(j).get());
+ if (expressions.at(j)->isViewportDependent())
+ results.append(std::make_unique<MediaQueryResult>(*expressions.at(j), exprResult));
+ if (!exprResult)
+ break;
+ }
+ result = applyRestrictor(query->restrictor(), expressions.size() == j);
+ } else
+ result = applyRestrictor(query->restrictor(), false);
+ }
+
+ return result;
+}
+
template<typename T>
bool compareValue(T a, T b, MediaFeaturePrefix op)
{
Modified: branches/safari-601-branch/Source/WebCore/css/MediaQueryEvaluator.h (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/css/MediaQueryEvaluator.h 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/css/MediaQueryEvaluator.h 2015-12-11 18:26:38 UTC (rev 193966)
@@ -28,6 +28,7 @@
#ifndef MediaQueryEvaluator_h
#define MediaQueryEvaluator_h
+#include "MediaQueryExp.h"
#include <wtf/text/WTFString.h>
namespace WebCore {
@@ -37,6 +38,19 @@
class RenderStyle;
class StyleResolver;
+class MediaQueryResult {
+ WTF_MAKE_NONCOPYABLE(MediaQueryResult); WTF_MAKE_FAST_ALLOCATED;
+public:
+ MediaQueryResult(const MediaQueryExp& expr, bool result)
+ : m_expression(expr)
+ , m_result(result)
+ {
+ }
+
+ MediaQueryExp m_expression;
+ bool m_result;
+};
+
/**
* Class that evaluates css media queries as defined in
* CSS3 Module "Media Queries" (http://www.w3.org/TR/css3-mediaqueries/)
@@ -78,6 +92,9 @@
/** Evaluates media query subexpression, ie "and (media-feature: value)" part */
bool eval(const MediaQueryExp*) const;
+
+ /* Evaluates a list of media queries and fills in a vector with any viewport-dependent results found. */
+ bool evalCheckingViewportDependentResults(const MediaQuerySet*, Vector<std::unique_ptr<MediaQueryResult>>&);
private:
String m_mediaType;
Modified: branches/safari-601-branch/Source/WebCore/css/StyleResolver.h (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/css/StyleResolver.h 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/css/StyleResolver.h 2015-12-11 18:26:38 UTC (rev 193966)
@@ -28,7 +28,7 @@
#include "DocumentRuleSets.h"
#include "InspectorCSSOMWrappers.h"
#include "LinkHash.h"
-#include "MediaQueryExp.h"
+#include "MediaQueryEvaluator.h"
#include "RenderStyle.h"
#include "RuleFeature.h"
#include "RuleSet.h"
@@ -93,19 +93,6 @@
class WebKitCSSFilterValue;
struct ResourceLoaderOptions;
-class MediaQueryResult {
- WTF_MAKE_NONCOPYABLE(MediaQueryResult); WTF_MAKE_FAST_ALLOCATED;
-public:
- MediaQueryResult(const MediaQueryExp& expr, bool result)
- : m_expression(expr)
- , m_result(result)
- {
- }
-
- MediaQueryExp m_expression;
- bool m_result;
-};
-
enum StyleSharingBehavior {
AllowStyleSharing,
DisallowStyleSharing,
Modified: branches/safari-601-branch/Source/WebCore/dom/Document.cpp (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/dom/Document.cpp 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/dom/Document.cpp 2015-12-11 18:26:38 UTC (rev 193966)
@@ -81,6 +81,7 @@
#include "HTMLMediaElement.h"
#include "HTMLNameCollection.h"
#include "HTMLParserIdioms.h"
+#include "HTMLPictureElement.h"
#include "HTMLPlugInElement.h"
#include "HTMLScriptElement.h"
#include "HTMLStyleElement.h"
@@ -3469,8 +3470,22 @@
{
if (m_mediaQueryMatcher)
m_mediaQueryMatcher->styleResolverChanged();
+
+ checkViewportDependentPictures();
}
+void Document::checkViewportDependentPictures()
+{
+ Vector<HTMLPictureElement*, 16> changedPictures;
+ HashSet<HTMLPictureElement*>::iterator end = m_viewportDependentPictures.end();
+ for (HashSet<HTMLPictureElement*>::iterator it = m_viewportDependentPictures.begin(); it != end; ++it) {
+ if ((*it)->viewportChangeAffectedPicture())
+ changedPictures.append(*it);
+ }
+ for (auto* picture : changedPictures)
+ picture->sourcesChanged();
+}
+
void Document::optimizedStyleSheetUpdateTimerFired()
{
styleResolverChanged(RecalcStyleIfNeeded);
@@ -6732,4 +6747,14 @@
return contentDispositionAttachmentSandboxEnabled && responseIsAttachment;
}
+void Document::addViewportDependentPicture(HTMLPictureElement& picture)
+{
+ m_viewportDependentPictures.add(&picture);
+}
+
+void Document::removeViewportDependentPicture(HTMLPictureElement& picture)
+{
+ m_viewportDependentPictures.remove(&picture);
+}
+
} // namespace WebCore
Modified: branches/safari-601-branch/Source/WebCore/dom/Document.h (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/dom/Document.h 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/dom/Document.h 2015-12-11 18:26:38 UTC (rev 193966)
@@ -113,7 +113,11 @@
class HTMLImageElement;
class HTMLMapElement;
class HTMLMediaElement;
+<<<<<<< HEAD
class HTMLNameCollection;
+=======
+class HTMLPictureElement;
+>>>>>>> 58f8aa0... Picture element needs to respond to dynamic viewport changes.
class HTMLScriptElement;
class HitTestRequest;
class HitTestResult;
@@ -1279,6 +1283,9 @@
ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToPropagate() const;
bool shouldEnforceContentDispositionAttachmentSandbox() const;
+ void addViewportDependentPicture(HTMLPictureElement&);
+ void removeViewportDependentPicture(HTMLPictureElement&);
+
protected:
enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
Document(Frame*, const URL&, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0);
@@ -1373,6 +1380,8 @@
void domCookieCacheExpiryTimerFired();
virtual void didLoadResourceSynchronously(const ResourceRequest&) override final;
+ void checkViewportDependentPictures();
+
unsigned m_referencingNodeCount;
std::unique_ptr<StyleResolver> m_styleResolver;
@@ -1595,6 +1604,8 @@
RefPtr<RenderStyle> m_savedPlaceholderRenderStyle;
#endif
+ HashSet<HTMLPictureElement*> m_viewportDependentPictures;
+
int m_loadEventDelayCount;
Timer m_loadEventDelayTimer;
Modified: branches/safari-601-branch/Source/WebCore/html/HTMLImageElement.cpp (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/html/HTMLImageElement.cpp 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/html/HTMLImageElement.cpp 2015-12-11 18:26:38 UTC (rev 193966)
@@ -32,6 +32,7 @@
#include "HTMLDocument.h"
#include "HTMLFormElement.h"
#include "HTMLParserIdioms.h"
+#include "HTMLPictureElement.h"
#include "HTMLSourceElement.h"
#include "HTMLSrcsetParser.h"
#include "MIMETypeRegistry.h"
@@ -145,6 +146,9 @@
auto* parent = parentNode();
if (!is<HTMLPictureElement>(parent))
return { };
+ auto* picture = downcast<HTMLPictureElement>(parent);
+ picture->clearViewportDependentResults();
+ document().removeViewportDependentPicture(*picture);
for (Node* child = parent->firstChild(); child && child != this; child = child->nextSibling()) {
if (!is<HTMLSourceElement>(*child))
continue;
@@ -163,7 +167,10 @@
continue;
}
MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), computedStyle());
- if (!evaluator.eval(MediaQuerySet::createAllowingDescriptionSyntax(source.media()).ptr()))
+ bool evaluation = evaluator.evalCheckingViewportDependentResults(source.mediaQuerySet(), picture->viewportDependentResults());
+ if (picture->hasViewportDependentResults())
+ document().addViewportDependentPicture(*picture);
+ if (!evaluation)
continue;
float sourceSize = parseSizesAttribute(source.fastGetAttribute(sizesAttr).string(), document().renderView(), document().frame());
Modified: branches/safari-601-branch/Source/WebCore/html/HTMLPictureElement.cpp (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/html/HTMLPictureElement.cpp 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/html/HTMLPictureElement.cpp 2015-12-11 18:26:38 UTC (rev 193966)
@@ -37,6 +37,20 @@
{
}
+HTMLPictureElement::~HTMLPictureElement()
+{
+ if (hasViewportDependentResults())
+ document().removeViewportDependentPicture(*this);
+}
+
+void HTMLPictureElement::didMoveToNewDocument(Document* oldDocument)
+{
+ if (hasViewportDependentResults() && oldDocument)
+ oldDocument->removeViewportDependentPicture(*this);
+ HTMLElement::didMoveToNewDocument(oldDocument);
+ sourcesChanged();
+}
+
Ref<HTMLPictureElement> HTMLPictureElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(*new HTMLPictureElement(tagName, document));
@@ -48,5 +62,16 @@
imageElement.selectImageSource();
}
+bool HTMLPictureElement::viewportChangeAffectedPicture()
+{
+ MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), computedStyle());
+ unsigned numResults = m_viewportDependentMediaQueryResults.size();
+ for (unsigned i = 0; i < numResults; i++) {
+ if (evaluator.eval(&m_viewportDependentMediaQueryResults[i]->m_expression) != m_viewportDependentMediaQueryResults[i]->m_result)
+ return true;
+ }
+ return false;
}
+}
+
Modified: branches/safari-601-branch/Source/WebCore/html/HTMLPictureElement.h (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/html/HTMLPictureElement.h 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/html/HTMLPictureElement.h 2015-12-11 18:26:38 UTC (rev 193966)
@@ -27,17 +27,30 @@
#define HTMLPictureElement_h
#include "HTMLElement.h"
+#include "MediaQueryEvaluator.h"
namespace WebCore {
class HTMLPictureElement final : public HTMLElement {
public:
static Ref<HTMLPictureElement> create(const QualifiedName&, Document&);
+ ~HTMLPictureElement();
void sourcesChanged();
+ void clearViewportDependentResults() { m_viewportDependentMediaQueryResults.clear(); }
+ bool hasViewportDependentResults() const { return m_viewportDependentMediaQueryResults.size(); }
+ Vector<std::unique_ptr<MediaQueryResult>>& viewportDependentResults() { return m_viewportDependentMediaQueryResults; }
+
+ void didMoveToNewDocument(Document* oldDocument);
+
+ bool viewportChangeAffectedPicture();
+
private:
HTMLPictureElement(const QualifiedName&, Document&);
+
+ Vector<std::unique_ptr<MediaQueryResult>> m_viewportDependentMediaQueryResults;
+
};
} // namespace WebCore
Modified: branches/safari-601-branch/Source/WebCore/html/HTMLSourceElement.cpp (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/html/HTMLSourceElement.cpp 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/html/HTMLSourceElement.cpp 2015-12-11 18:26:38 UTC (rev 193966)
@@ -167,6 +167,8 @@
{
HTMLElement::parseAttribute(name, value);
if (name == srcsetAttr || name == sizesAttr || name == mediaAttr || name == typeAttr) {
+ if (name == mediaAttr)
+ m_mediaQuerySet = MediaQuerySet::createAllowingDescriptionSyntax(value);
auto* parent = parentNode();
if (is<HTMLPictureElement>(parent))
downcast<HTMLPictureElement>(*parent).sourcesChanged();
Modified: branches/safari-601-branch/Source/WebCore/html/HTMLSourceElement.h (193965 => 193966)
--- branches/safari-601-branch/Source/WebCore/html/HTMLSourceElement.h 2015-12-11 18:26:31 UTC (rev 193965)
+++ branches/safari-601-branch/Source/WebCore/html/HTMLSourceElement.h 2015-12-11 18:26:38 UTC (rev 193966)
@@ -27,6 +27,7 @@
#define HTMLSourceElement_h
#include "HTMLElement.h"
+#include "MediaList.h"
#include "Timer.h"
namespace WebCore {
@@ -44,6 +45,8 @@
void scheduleErrorEvent();
void cancelPendingErrorEvent();
+ MediaQuerySet* mediaQuerySet() const { return m_mediaQuerySet.get(); }
+
private:
HTMLSourceElement(const QualifiedName&, Document&);
@@ -64,6 +67,7 @@
Timer m_errorEventTimer;
bool m_shouldRescheduleErrorEventOnResume { false };
+ RefPtr<MediaQuerySet> m_mediaQuerySet;
};
} //namespace