Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (276678 => 276679)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-04-27 23:35:22 UTC (rev 276678)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-04-27 23:40:17 UTC (rev 276679)
@@ -1,3 +1,13 @@
+2021-04-27 Cameron McCormack <[email protected]>
+
+ Associate a picture element with an img only if the img is a direct child.
+ https://bugs.webkit.org/show_bug.cgi?id=225044
+
+ Reviewed by Ryosuke Niwa.
+
+ * web-platform-tests/html/semantics/embedded-content/the-img-element/img-picture-ancestor-expected.txt: Added.
+ * web-platform-tests/html/semantics/embedded-content/the-img-element/img-picture-ancestor.html: Added.
+
2021-04-27 Alexey Shvayka <[email protected]>
[WebIDL] `window.CSS` should be non-callable object with correct Symbol.toStringTag
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/img-picture-ancestor-expected.txt (0 => 276679)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/img-picture-ancestor-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/img-picture-ancestor-expected.txt 2021-04-27 23:40:17 UTC (rev 276679)
@@ -0,0 +1,8 @@
+
+
+
+PASS currentSrc of img in normally parented picture is correct
+PASS currentSrc of img in nested picture element is correct
+PASS currentSrc of img with picture ancestor but non-picture parent is correct
+PASS currentSrc of img in nested picture element remains correct when the inner picture is removed from the document
+
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/img-picture-ancestor.html (0 => 276679)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/img-picture-ancestor.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/img-picture-ancestor.html 2021-04-27 23:40:17 UTC (rev 276679)
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<title>img should only look at a parent picture element</title>
+<script src=""
+<script src=""
+<picture>
+ <source media="not all" srcset="data:,a">
+ <source media="all" srcset="data:,b">
+ <img src=""
+ <picture>
+ <source media="not all" srcset="data:,e">
+ <source media="all" srcset="data:,f">
+ <img src=""
+ </picture>
+</picture>
+<script>
+const picture1 = document.querySelector("picture");
+const picture2 = document.querySelector("picture > picture");
+const img1 = document.querySelector("picture > img");
+const img2 = document.querySelector("picture > picture > img");
+
+const div = document.createElement("div");
+
+const imgInsideDiv = document.createElement("img");
+imgInsideDiv.src = ""
+div.append(imgInsideDiv);
+
+test(function() {
+ assert_equals(img1.currentSrc, "data:,b");
+}, "currentSrc of img in normally parented picture is correct");
+
+test(function() {
+ assert_equals(img2.currentSrc, "data:,f");
+}, "currentSrc of img in nested picture element is correct");
+
+async_test(function(t) {
+ picture1.append(div);
+ queueMicrotask(t.step_func(function() {
+ assert_equals(imgInsideDiv.currentSrc, "data:,d");
+ t.done();
+ }));
+}, "currentSrc of img with picture ancestor but non-picture parent is correct");
+
+async_test(function(t) {
+ picture2.remove();
+ queueMicrotask(t.step_func(function() {
+ assert_equals(img2.currentSrc, "data:,f");
+ t.done();
+ }));
+}, "currentSrc of img in nested picture element remains correct when the inner picture is removed from the document");
+</script>
Modified: trunk/Source/WebCore/ChangeLog (276678 => 276679)
--- trunk/Source/WebCore/ChangeLog 2021-04-27 23:35:22 UTC (rev 276678)
+++ trunk/Source/WebCore/ChangeLog 2021-04-27 23:40:17 UTC (rev 276679)
@@ -1,3 +1,18 @@
+2021-04-27 Cameron McCormack <[email protected]>
+
+ Associate a picture element with an img only if the img is a direct child.
+ https://bugs.webkit.org/show_bug.cgi?id=225044
+
+ Reviewed by Ryosuke Niwa.
+
+ Test: imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/img-picture-ancestor.html
+
+ * html/HTMLImageElement.cpp:
+ (WebCore::HTMLImageElement::insertedIntoAncestor):
+ (WebCore::HTMLImageElement::removedFromAncestor):
+ * html/parser/HTMLConstructionSite.cpp:
+ (WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface):
+
2021-04-27 Chris Dumez <[email protected]>
IPC::decoder::decode() should mark decoder as invalid when failing
Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (276678 => 276679)
--- trunk/Source/WebCore/html/HTMLImageElement.cpp 2021-04-27 23:35:22 UTC (rev 276678)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp 2021-04-27 23:40:17 UTC (rev 276679)
@@ -382,8 +382,11 @@
if (insertionType.treeScopeChanged && !m_parsedUsemap.isNull())
treeScope().addImageElementByUsemap(*m_parsedUsemap.impl(), *this);
- if (is<HTMLPictureElement>(&parentOfInsertedTree)) {
+ if (is<HTMLPictureElement>(&parentOfInsertedTree) && &parentOfInsertedTree == parentElement()) {
+ // FIXME: When the hack in HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface to eagerly call setPictureElement is removed, we can just assert !pictureElement().
+ ASSERT(!pictureElement() || pictureElement() == &parentOfInsertedTree);
setPictureElement(&downcast<HTMLPictureElement>(parentOfInsertedTree));
+ // FIXME: We should unconditionally call selectImageSource so that source selection is performed even for <img> elements outside the document.
if (insertionType.connectedToDocument) {
selectImageSource(RelevantMutation::Yes);
return insertNotificationRequest;
@@ -411,8 +414,10 @@
if (removalType.treeScopeChanged && !m_parsedUsemap.isNull())
oldParentOfRemovedTree.treeScope().removeImageElementByUsemap(*m_parsedUsemap.impl(), *this);
- if (is<HTMLPictureElement>(oldParentOfRemovedTree)) {
+ if (is<HTMLPictureElement>(oldParentOfRemovedTree) && !parentElement()) {
+ ASSERT(pictureElement() == &oldParentOfRemovedTree);
setPictureElement(nullptr);
+ // FIXME: We should call selectImageSource so that source selection is performed, now that we no longer have a <picture> context.
m_imageLoader->updateFromElementIgnoringPreviousError(RelevantMutation::Yes);
}
Modified: trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp (276678 => 276679)
--- trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp 2021-04-27 23:35:22 UTC (rev 276678)
+++ trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp 2021-04-27 23:40:17 UTC (rev 276679)
@@ -695,7 +695,9 @@
// 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.
+ // loading is working. When this hack is removed, the assertion just before
+ // the setPictureElement() call in HTMLImageElement::insertedIntoAncestor
+ // can be simplified.
if (is<HTMLPictureElement>(currentNode()) && is<HTMLImageElement>(*element))
downcast<HTMLImageElement>(*element).setPictureElement(&downcast<HTMLPictureElement>(currentNode()));