<!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>[195401] branches/safari-601.1.46-branch/Source/WebCore</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/195401">195401</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2016-01-20 23:16:57 -0800 (Wed, 20 Jan 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merged <a href="http://trac.webkit.org/projects/webkit/changeset/195132">r195132</a>. rdar://problem/24154424</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari601146branchSourceWebCoreChangeLog">branches/safari-601.1.46-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari601146branchSourceWebCorehtmlHTMLImageElementcpp">branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCorehtmlHTMLImageElementh">branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.h</a></li>
<li><a href="#branchessafari601146branchSourceWebCorehtmlHTMLPictureElementh">branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.h</a></li>
<li><a href="#branchessafari601146branchSourceWebCorehtmlparserHTMLConstructionSitecpp">branches/safari-601.1.46-branch/Source/WebCore/html/parser/HTMLConstructionSite.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCorehtmlparserHTMLPreloadScannercpp">branches/safari-601.1.46-branch/Source/WebCore/html/parser/HTMLPreloadScanner.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari601146branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/ChangeLog (195400 => 195401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/ChangeLog        2016-01-21 07:13:45 UTC (rev 195400)
+++ branches/safari-601.1.46-branch/Source/WebCore/ChangeLog        2016-01-21 07:16:57 UTC (rev 195401)
</span><span class="lines">@@ -1,5 +1,45 @@
</span><span class="cx"> 2016-01-20 Babak Shafiei <bshafiei@apple.com>
</span><span class="cx">
</span><ins>+ Merge r195132.
+
+ 2016-01-15 Dave Hyatt <hyatt@apple.com>
+
+ Avoid downloading the wrong image for <picture> elements.
+ https://bugs.webkit.org/show_bug.cgi?id=153027
+
+ Reviewed by Dean Jackson.
+
+ No tests, since they are always flaky.
+
+ * html/HTMLImageElement.cpp:
+ (WebCore::HTMLImageElement::HTMLImageElement):
+ (WebCore::HTMLImageElement::~HTMLImageElement):
+ (WebCore::HTMLImageElement::createForJSConstructor):
+ (WebCore::HTMLImageElement::bestFitSourceFromPictureElement):
+ (WebCore::HTMLImageElement::insertedInto):
+ (WebCore::HTMLImageElement::removedFrom):
+ (WebCore::HTMLImageElement::pictureElement):
+ (WebCore::HTMLImageElement::setPictureElement):
+ (WebCore::HTMLImageElement::width):
+ * html/HTMLImageElement.h:
+ (WebCore::HTMLImageElement::hasShadowControls):
+ * html/HTMLPictureElement.h:
+ * html/parser/HTMLConstructionSite.cpp:
+ (WebCore::HTMLConstructionSite::createHTMLElement):
+ * html/parser/HTMLPreloadScanner.cpp:
+ (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute):
+
+ Images that are built underneath a <picture> element are now connected
+ to that picture element via a setPictureNode call from the parser. This
+ ensures that the correct <source> elements are examined before checking the image.
+
+ This connection between images and their picture owners is handled using a static
+ HashMap in HTMLImageElement. This connection is made both from the parser and from
+ DOM insertions, and the map is queried now instead of looking directly at the
+ image's parentNode().
+
+2016-01-20 Babak Shafiei <bshafiei@apple.com>
+
</ins><span class="cx"> Merge r195075.
</span><span class="cx">
</span><span class="cx"> 2016-01-14 Daniel Bates <dabates@apple.com>
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorehtmlHTMLImageElementcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.cpp (195400 => 195401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.cpp        2016-01-21 07:13:45 UTC (rev 195400)
+++ branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.cpp        2016-01-21 07:16:57 UTC (rev 195401)
</span><span class="lines">@@ -53,6 +53,9 @@
</span><span class="cx">
</span><span class="cx"> using namespace HTMLNames;
</span><span class="cx">
</span><ins>+typedef HashMap<const HTMLImageElement*, WeakPtr<HTMLPictureElement>> PictureOwnerMap;
+static PictureOwnerMap* gPictureOwnerMap = nullptr;
+
</ins><span class="cx"> HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document& document, HTMLFormElement* form)
</span><span class="cx"> : HTMLElement(tagName, document)
</span><span class="cx"> , m_imageLoader(*this)
</span><span class="lines">@@ -83,6 +86,7 @@
</span><span class="cx"> {
</span><span class="cx"> if (m_form)
</span><span class="cx"> m_form->removeImgElement(this);
</span><ins>+ setPictureElement(nullptr);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> Ref<HTMLImageElement> HTMLImageElement::createForJSConstructor(Document& document, const int* optionalWidth, const int* optionalHeight)
</span><span class="lines">@@ -143,13 +147,12 @@
</span><span class="cx">
</span><span class="cx"> ImageCandidate HTMLImageElement::bestFitSourceFromPictureElement()
</span><span class="cx"> {
</span><del>- auto* parent = parentNode();
- if (!is<HTMLPictureElement>(parent))
</del><ins>+ auto* picture = pictureElement();
+ if (!picture)
</ins><span class="cx"> return { };
</span><del>- auto* picture = downcast<HTMLPictureElement>(parent);
</del><span class="cx"> picture->clearViewportDependentResults();
</span><span class="cx"> document().removeViewportDependentPicture(*picture);
</span><del>- for (Node* child = parent->firstChild(); child && child != this; child = child->nextSibling()) {
</del><ins>+ for (Node* child = picture->firstChild(); child && child != this; child = child->nextSibling()) {
</ins><span class="cx"> if (!is<HTMLSourceElement>(*child))
</span><span class="cx"> continue;
</span><span class="cx"> auto& source = downcast<HTMLSourceElement>(*child);
</span><span class="lines">@@ -166,7 +169,7 @@
</span><span class="cx"> if (!type.isEmpty() && !MIMETypeRegistry::isSupportedImageMIMEType(type) && type != "image/svg+xml")
</span><span class="cx"> continue;
</span><span class="cx"> }
</span><del>- MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), computedStyle());
</del><ins>+ MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), document().documentElement() ? document().documentElement()->computedStyle() : nullptr);
</ins><span class="cx"> bool evaluation = evaluator.evalCheckingViewportDependentResults(source.mediaQuerySet(), picture->viewportDependentResults());
</span><span class="cx"> if (picture->hasViewportDependentResults())
</span><span class="cx"> document().addViewportDependentPicture(*picture);
</span><span class="lines">@@ -311,9 +314,11 @@
</span><span class="cx"> if (insertionPoint.inDocument() && !m_lowercasedUsemap.isNull())
</span><span class="cx"> document().addImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this);
</span><span class="cx">
</span><del>- if (is<HTMLPictureElement>(parentNode()))
</del><ins>+ if (is<HTMLPictureElement>(parentNode())) {
+ setPictureElement(&downcast<HTMLPictureElement>(*parentNode()));
</ins><span class="cx"> selectImageSource();
</span><del>-
</del><ins>+ }
+
</ins><span class="cx"> // If we have been inserted from a renderer-less document,
</span><span class="cx"> // our loader may have not fetched the image, so do it now.
</span><span class="cx"> if (insertionPoint.inDocument() && !m_imageLoader.image())
</span><span class="lines">@@ -329,11 +334,37 @@
</span><span class="cx">
</span><span class="cx"> if (insertionPoint.inDocument() && !m_lowercasedUsemap.isNull())
</span><span class="cx"> document().removeImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this);
</span><del>-
</del><ins>+
+ if (is<HTMLPictureElement>(parentNode()))
+ setPictureElement(nullptr);
+
</ins><span class="cx"> m_form = 0;
</span><span class="cx"> HTMLElement::removedFrom(insertionPoint);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+HTMLPictureElement* HTMLImageElement::pictureElement() const
+{
+ if (!gPictureOwnerMap || !gPictureOwnerMap->contains(this))
+ return nullptr;
+ HTMLPictureElement* result = gPictureOwnerMap->get(this).get();
+ if (!result)
+ gPictureOwnerMap->remove(this);
+ return result;
+}
+
+void HTMLImageElement::setPictureElement(HTMLPictureElement* pictureElement)
+{
+ if (!pictureElement) {
+ if (gPictureOwnerMap)
+ gPictureOwnerMap->remove(this);
+ return;
+ }
+
+ if (!gPictureOwnerMap)
+ gPictureOwnerMap = new PictureOwnerMap();
+ gPictureOwnerMap->add(this, pictureElement->createWeakPtr());
+}
+
</ins><span class="cx"> int HTMLImageElement::width(bool ignorePendingStylesheets)
</span><span class="cx"> {
</span><span class="cx"> if (!renderer()) {
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorehtmlHTMLImageElementh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.h (195400 => 195401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.h        2016-01-21 07:13:45 UTC (rev 195400)
+++ branches/safari-601.1.46-branch/Source/WebCore/html/HTMLImageElement.h        2016-01-21 07:16:57 UTC (rev 195401)
</span><span class="lines">@@ -89,6 +89,9 @@
</span><span class="cx"> virtual const AtomicString& imageSourceURL() const override;
</span><span class="cx">
</span><span class="cx"> bool hasShadowControls() const { return m_experimentalImageMenuEnabled; }
</span><ins>+
+ HTMLPictureElement* pictureElement() const;
+ void setPictureElement(HTMLPictureElement*);
</ins><span class="cx">
</span><span class="cx"> protected:
</span><span class="cx"> HTMLImageElement(const QualifiedName&, Document&, HTMLFormElement* = 0);
</span><span class="lines">@@ -128,6 +131,7 @@
</span><span class="cx">
</span><span class="cx"> HTMLImageLoader m_imageLoader;
</span><span class="cx"> HTMLFormElement* m_form;
</span><ins>+
</ins><span class="cx"> CompositeOperator m_compositeOperator;
</span><span class="cx"> AtomicString m_bestFitImageURL;
</span><span class="cx"> #if ENABLE(PICTURE_SIZES)
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorehtmlHTMLPictureElementh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.h (195400 => 195401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.h        2016-01-21 07:13:45 UTC (rev 195400)
+++ branches/safari-601.1.46-branch/Source/WebCore/html/HTMLPictureElement.h        2016-01-21 07:16:57 UTC (rev 195401)
</span><span class="lines">@@ -46,9 +46,12 @@
</span><span class="cx">
</span><span class="cx"> bool viewportChangeAffectedPicture();
</span><span class="cx">
</span><ins>+ WeakPtr<HTMLPictureElement> createWeakPtr() { return m_weakFactory.createWeakPtr(); }
+
</ins><span class="cx"> private:
</span><span class="cx"> HTMLPictureElement(const QualifiedName&, Document&);
</span><span class="cx">
</span><ins>+ WeakPtrFactory<HTMLPictureElement> m_weakFactory { this };
</ins><span class="cx"> Vector<std::unique_ptr<MediaQueryResult>> m_viewportDependentMediaQueryResults;
</span><span class="cx">
</span><span class="cx"> };
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorehtmlparserHTMLConstructionSitecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/html/parser/HTMLConstructionSite.cpp (195400 => 195401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/html/parser/HTMLConstructionSite.cpp        2016-01-21 07:13:45 UTC (rev 195400)
+++ branches/safari-601.1.46-branch/Source/WebCore/html/parser/HTMLConstructionSite.cpp        2016-01-21 07:16:57 UTC (rev 195401)
</span><span class="lines">@@ -36,9 +36,11 @@
</span><span class="cx"> #include "HTMLElementFactory.h"
</span><span class="cx"> #include "HTMLFormElement.h"
</span><span class="cx"> #include "HTMLHtmlElement.h"
</span><ins>+#include "HTMLImageElement.h"
</ins><span class="cx"> #include "HTMLOptGroupElement.h"
</span><span class="cx"> #include "HTMLOptionElement.h"
</span><span class="cx"> #include "HTMLParserIdioms.h"
</span><ins>+#include "HTMLPictureElement.h"
</ins><span class="cx"> #include "HTMLScriptElement.h"
</span><span class="cx"> #include "HTMLTemplateElement.h"
</span><span class="cx"> #include "NotImplemented.h"
</span><span class="lines">@@ -641,6 +643,13 @@
</span><span class="cx"> Document& ownerDocument = ownerDocumentForCurrentNode();
</span><span class="cx"> bool insideTemplateElement = !ownerDocument.frame();
</span><span class="cx"> RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true);
</span><ins>+
+ // FIXME: This is a hack to connect images to pictures before the image has
+ // been inserted into the document. It can be removed once asynchronous image
+ // loading is working.
+ if (is<HTMLPictureElement>(currentNode()) && is<HTMLImageElement>(*element.get()))
+ downcast<HTMLImageElement>(*element.get()).setPictureElement(&downcast<HTMLPictureElement>(currentNode()));
+
</ins><span class="cx"> setAttributes(element.get(), token, m_parserContentPolicy);
</span><span class="cx"> ASSERT(element->isHTMLElement());
</span><span class="cx"> return element.release();
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorehtmlparserHTMLPreloadScannercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/html/parser/HTMLPreloadScanner.cpp (195400 => 195401)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/html/parser/HTMLPreloadScanner.cpp        2016-01-21 07:13:45 UTC (rev 195400)
+++ branches/safari-601.1.46-branch/Source/WebCore/html/parser/HTMLPreloadScanner.cpp        2016-01-21 07:16:57 UTC (rev 195401)
</span><span class="lines">@@ -208,7 +208,7 @@
</span><span class="cx"> m_mediaAttribute = attributeValue;
</span><span class="cx"> Ref<MediaQuerySet> mediaSet = MediaQuerySet::createAllowingDescriptionSyntax(attributeValue);
</span><span class="cx"> Vector<std::unique_ptr<MediaQueryResult>> viewportDependentMediaQueryResults;
</span><del>- MediaQueryEvaluator evaluator(document.printing() ? "print" : "screen", document.frame(), document.documentElement()->computedStyle());
</del><ins>+ MediaQueryEvaluator evaluator(document.printing() ? "print" : "screen", document.frame(), document.documentElement() ? document.documentElement()->computedStyle() : nullptr);
</ins><span class="cx"> m_mediaMatched = evaluator.evalCheckingViewportDependentResults(mediaSet.ptr(), viewportDependentMediaQueryResults);
</span><span class="cx"> }
</span><span class="cx"> break;
</span></span></pre>
</div>
</div>
</body>
</html>