Diff
Modified: branches/safari-601-branch/Source/WebCore/ChangeLog (195715 => 195716)
--- branches/safari-601-branch/Source/WebCore/ChangeLog 2016-01-28 01:34:12 UTC (rev 195715)
+++ branches/safari-601-branch/Source/WebCore/ChangeLog 2016-01-28 01:34:16 UTC (rev 195716)
@@ -1,5 +1,45 @@
2016-01-27 Matthew Hanson <[email protected]>
+ Merge r195132. rdar://problem/24154292
+
+ 2016-01-15 Dave Hyatt <[email protected]>
+
+ 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-27 Matthew Hanson <[email protected]>
+
Merge r195075. rdar://problem/24302727
2016-01-14 Daniel Bates <[email protected]>
Modified: branches/safari-601-branch/Source/WebCore/html/HTMLImageElement.cpp (195715 => 195716)
--- branches/safari-601-branch/Source/WebCore/html/HTMLImageElement.cpp 2016-01-28 01:34:12 UTC (rev 195715)
+++ branches/safari-601-branch/Source/WebCore/html/HTMLImageElement.cpp 2016-01-28 01:34:16 UTC (rev 195716)
@@ -53,6 +53,9 @@
using namespace HTMLNames;
+typedef HashMap<const HTMLImageElement*, WeakPtr<HTMLPictureElement>> PictureOwnerMap;
+static PictureOwnerMap* gPictureOwnerMap = nullptr;
+
HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document& document, HTMLFormElement* form)
: HTMLElement(tagName, document)
, m_imageLoader(*this)
@@ -83,6 +86,7 @@
{
if (m_form)
m_form->removeImgElement(this);
+ setPictureElement(nullptr);
}
Ref<HTMLImageElement> HTMLImageElement::createForJSConstructor(Document& document, const int* optionalWidth, const int* optionalHeight)
@@ -143,13 +147,12 @@
ImageCandidate HTMLImageElement::bestFitSourceFromPictureElement()
{
- auto* parent = parentNode();
- if (!is<HTMLPictureElement>(parent))
+ auto* picture = pictureElement();
+ if (!picture)
return { };
- auto* picture = downcast<HTMLPictureElement>(parent);
picture->clearViewportDependentResults();
document().removeViewportDependentPicture(*picture);
- for (Node* child = parent->firstChild(); child && child != this; child = child->nextSibling()) {
+ for (Node* child = picture->firstChild(); child && child != this; child = child->nextSibling()) {
if (!is<HTMLSourceElement>(*child))
continue;
auto& source = downcast<HTMLSourceElement>(*child);
@@ -166,7 +169,7 @@
if (!type.isEmpty() && !MIMETypeRegistry::isSupportedImageMIMEType(type) && type != "image/svg+xml")
continue;
}
- MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), computedStyle());
+ MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), document().documentElement() ? document().documentElement()->computedStyle() : nullptr);
bool evaluation = evaluator.evalCheckingViewportDependentResults(source.mediaQuerySet(), picture->viewportDependentResults());
if (picture->hasViewportDependentResults())
document().addViewportDependentPicture(*picture);
@@ -311,9 +314,11 @@
if (insertionPoint.inDocument() && !m_lowercasedUsemap.isNull())
document().addImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this);
- if (is<HTMLPictureElement>(parentNode()))
+ if (is<HTMLPictureElement>(parentNode())) {
+ setPictureElement(&downcast<HTMLPictureElement>(*parentNode()));
selectImageSource();
-
+ }
+
// If we have been inserted from a renderer-less document,
// our loader may have not fetched the image, so do it now.
if (insertionPoint.inDocument() && !m_imageLoader.image())
@@ -329,11 +334,37 @@
if (insertionPoint.inDocument() && !m_lowercasedUsemap.isNull())
document().removeImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this);
-
+
+ if (is<HTMLPictureElement>(parentNode()))
+ setPictureElement(nullptr);
+
m_form = 0;
HTMLElement::removedFrom(insertionPoint);
}
+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());
+}
+
int HTMLImageElement::width(bool ignorePendingStylesheets)
{
if (!renderer()) {
Modified: branches/safari-601-branch/Source/WebCore/html/HTMLImageElement.h (195715 => 195716)
--- branches/safari-601-branch/Source/WebCore/html/HTMLImageElement.h 2016-01-28 01:34:12 UTC (rev 195715)
+++ branches/safari-601-branch/Source/WebCore/html/HTMLImageElement.h 2016-01-28 01:34:16 UTC (rev 195716)
@@ -89,6 +89,9 @@
virtual const AtomicString& imageSourceURL() const override;
bool hasShadowControls() const { return m_experimentalImageMenuEnabled; }
+
+ HTMLPictureElement* pictureElement() const;
+ void setPictureElement(HTMLPictureElement*);
protected:
HTMLImageElement(const QualifiedName&, Document&, HTMLFormElement* = 0);
@@ -128,6 +131,7 @@
HTMLImageLoader m_imageLoader;
HTMLFormElement* m_form;
+
CompositeOperator m_compositeOperator;
AtomicString m_bestFitImageURL;
#if ENABLE(PICTURE_SIZES)
Modified: branches/safari-601-branch/Source/WebCore/html/HTMLPictureElement.h (195715 => 195716)
--- branches/safari-601-branch/Source/WebCore/html/HTMLPictureElement.h 2016-01-28 01:34:12 UTC (rev 195715)
+++ branches/safari-601-branch/Source/WebCore/html/HTMLPictureElement.h 2016-01-28 01:34:16 UTC (rev 195716)
@@ -46,9 +46,12 @@
bool viewportChangeAffectedPicture();
+ WeakPtr<HTMLPictureElement> createWeakPtr() { return m_weakFactory.createWeakPtr(); }
+
private:
HTMLPictureElement(const QualifiedName&, Document&);
+ WeakPtrFactory<HTMLPictureElement> m_weakFactory { this };
Vector<std::unique_ptr<MediaQueryResult>> m_viewportDependentMediaQueryResults;
};
Modified: branches/safari-601-branch/Source/WebCore/html/parser/HTMLConstructionSite.cpp (195715 => 195716)
--- branches/safari-601-branch/Source/WebCore/html/parser/HTMLConstructionSite.cpp 2016-01-28 01:34:12 UTC (rev 195715)
+++ branches/safari-601-branch/Source/WebCore/html/parser/HTMLConstructionSite.cpp 2016-01-28 01:34:16 UTC (rev 195716)
@@ -36,9 +36,11 @@
#include "HTMLElementFactory.h"
#include "HTMLFormElement.h"
#include "HTMLHtmlElement.h"
+#include "HTMLImageElement.h"
#include "HTMLOptGroupElement.h"
#include "HTMLOptionElement.h"
#include "HTMLParserIdioms.h"
+#include "HTMLPictureElement.h"
#include "HTMLScriptElement.h"
#include "HTMLTemplateElement.h"
#include "NotImplemented.h"
@@ -641,6 +643,13 @@
Document& ownerDocument = ownerDocumentForCurrentNode();
bool insideTemplateElement = !ownerDocument.frame();
RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true);
+
+ // 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()));
+
setAttributes(element.get(), token, m_parserContentPolicy);
ASSERT(element->isHTMLElement());
return element.release();
Modified: branches/safari-601-branch/Source/WebCore/html/parser/HTMLPreloadScanner.cpp (195715 => 195716)
--- branches/safari-601-branch/Source/WebCore/html/parser/HTMLPreloadScanner.cpp 2016-01-28 01:34:12 UTC (rev 195715)
+++ branches/safari-601-branch/Source/WebCore/html/parser/HTMLPreloadScanner.cpp 2016-01-28 01:34:16 UTC (rev 195716)
@@ -208,7 +208,7 @@
m_mediaAttribute = attributeValue;
Ref<MediaQuerySet> mediaSet = MediaQuerySet::createAllowingDescriptionSyntax(attributeValue);
Vector<std::unique_ptr<MediaQueryResult>> viewportDependentMediaQueryResults;
- MediaQueryEvaluator evaluator(document.printing() ? "print" : "screen", document.frame(), document.documentElement()->computedStyle());
+ MediaQueryEvaluator evaluator(document.printing() ? "print" : "screen", document.frame(), document.documentElement() ? document.documentElement()->computedStyle() : nullptr);
m_mediaMatched = evaluator.evalCheckingViewportDependentResults(mediaSet.ptr(), viewportDependentMediaQueryResults);
}
break;