Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Make img elements perform source selection even when not in the docum…
…ent. https://bugs.webkit.org/show_bug.cgi?id=222801 Reviewed by Ryosuke Niwa. LayoutTests/imported/w3c: * web-platform-tests/html/semantics/embedded-content/the-img-element/source-media-outside-doc-expected.txt: Added. * web-platform-tests/html/semantics/embedded-content/the-img-element/source-media-outside-doc.html: Added. Source/WebCore: The rules for image source selection in the HTML spec do not prevent them from running when an <img> is not in the document. So we update HTMLImageElement to call selectImageSource() when inserted into and removed from a <picture> without checking whether it's in a document. Test: imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/source-media-outside-doc.html * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::~HTMLImageElement): Remove useless call to setPictureElement, since all it does is clear a weak pointer. (WebCore::HTMLImageElement::insertedIntoAncestor): (WebCore::HTMLImageElement::removedFromAncestor): Canonical link: https://commits.webkit.org/237111@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@276697 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
5 changed files
with
87 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
PASS Image source selection using media queries is performed for img elements outside the document | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE html> | ||
<title>Image source selection using media queries is performed for img elements outside the document</title> | ||
<link rel="help" href="https://html.spec.whatwg.org/#reacting-to-environment-changes"> | ||
<link rel="help" href="https://html.spec.whatwg.org/#reacting-to-dom-mutations"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<iframe width="350" height="100" onload="async_test(this.contentWindow.run)" srcdoc=" | ||
<!DOCTYPE html> | ||
<script> | ||
const { assert_equals } = parent; | ||
const iframe = parent.document.querySelector('iframe'); | ||
function run(t) { | ||
const picture = document.createElement('picture'); | ||
const source1 = document.createElement('source'); | ||
source1.setAttribute('media', '(min-width: 300px)'); | ||
source1.setAttribute('srcset', 'data:,a'); | ||
picture.append(source1); | ||
const source2 = document.createElement('source'); | ||
source2.setAttribute('media', '(min-width: 200px)'); | ||
source2.setAttribute('srcset', 'data:,b'); | ||
picture.append(source2); | ||
const img = document.createElement('img'); | ||
img.src = 'data:,c'; | ||
picture.append(img); | ||
queueMicrotask(t.step_func(function() { | ||
assert_equals(img.currentSrc, 'data:,a', 'Initial currentSrc value'); | ||
matchMedia(source1.media).addEventListener( | ||
'change', | ||
function() { | ||
queueMicrotask(t.step_func(function() { | ||
assert_equals(img.currentSrc, 'data:,b', 'After MQ change'); | ||
img.remove(); | ||
queueMicrotask(t.step_func(function() { | ||
assert_equals(img.currentSrc, 'data:,c', 'After removing img'); | ||
t.done(); | ||
})); | ||
})); | ||
}, | ||
{ once: true } | ||
); | ||
iframe.width = 250; | ||
})); | ||
} | ||
</script> | ||
"></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters