Title: [284667] trunk
Revision
284667
Author
cathiec...@igalia.com
Date
2021-10-21 22:05:42 -0700 (Thu, 21 Oct 2021)

Log Message

The intrisic size of picture image inside a template is always zero
https://bugs.webkit.org/show_bug.cgi?id=227682

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/html/semantics/embedded-content/the-img-element/adoption-expected.txt:

Source/WebCore:

When the picture element is inside a template element, it belongs to a template document which does not
have frame or RenderView, this would affect the source selection and size calculation. Though it calls
sourcesChanged to adjust the source in HTMLPictureElement::didMoveToNewDocument, but at this point
the image element is still inside the template document, so it does not help with this scenario. To
fix it, call sourcesChanged in HTMLImageElement::didMoveToNewDocument instead.

Test: fast/picture/picture-inside-template.html

* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::didMoveToNewDocument):
* html/HTMLPictureElement.cpp:
(WebCore::HTMLPictureElement::didMoveToNewDocument): Deleted.
* html/HTMLPictureElement.h:

LayoutTests:

* fast/picture/picture-inside-template-expected.txt: Added.
* fast/picture/picture-inside-template.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (284666 => 284667)


--- trunk/LayoutTests/ChangeLog	2021-10-22 04:57:49 UTC (rev 284666)
+++ trunk/LayoutTests/ChangeLog	2021-10-22 05:05:42 UTC (rev 284667)
@@ -1,3 +1,13 @@
+2021-10-21  Cathie Chen  <cathiec...@igalia.com>
+
+        The intrisic size of picture image inside a template is always zero
+        https://bugs.webkit.org/show_bug.cgi?id=227682
+
+        Reviewed by Darin Adler.
+
+        * fast/picture/picture-inside-template-expected.txt: Added.
+        * fast/picture/picture-inside-template.html: Added.
+
 2021-10-21  Gabriel Nava Marino  <gnavamar...@apple.com>
 
         Two null box iterators from different paths fail to compare equal

Added: trunk/LayoutTests/fast/picture/picture-inside-template-expected.txt (0 => 284667)


--- trunk/LayoutTests/fast/picture/picture-inside-template-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/picture/picture-inside-template-expected.txt	2021-10-22 05:05:42 UTC (rev 284667)
@@ -0,0 +1,9 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS document.getElementById("canary").clientWidth is 75
+PASS currentSrcFileName("canary") is "blue_rect.jpg?0"
+PASS document.getElementById("simple").clientWidth is 800
+PASS currentSrcFileName("simple") is "image-set-2x.png?2"
+
+

Added: trunk/LayoutTests/fast/picture/picture-inside-template.html (0 => 284667)


--- trunk/LayoutTests/fast/picture/picture-inside-template.html	                        (rev 0)
+++ trunk/LayoutTests/fast/picture/picture-inside-template.html	2021-10-22 05:05:42 UTC (rev 284667)
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<script src=""
+<script src=""
+<script>
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function runTest() {
+    shouldBe('document.getElementById("canary").clientWidth', '75');
+    shouldBe('currentSrcFileName("canary")', '"blue_rect.jpg?0"');
+    shouldBe('document.getElementById("simple").clientWidth', '800');
+    shouldBe('currentSrcFileName("simple")', '"image-set-2x.png?2"');
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function removeTemplate() {
+    let container = document.getElementById("container");
+    let template = document.getElementsByTagName("template")[0];
+    container.removeChild(template);
+    let rocketElement = template.content.children[0];
+    container.appendChild(rocketElement);
+    setTimeout(runTest, 100);
+}
+
+window._onload_ = removeTemplate;
+
+
+</script>
+<!-- A canary image to see that the test is actually working -->
+<img id="canary" src=""
+
+<!-- The image source should be selected correctly after remove template element -->
+<div id="container">
+    <template>
+        <picture>
+            <source media="(max-width: 400px)" sizes="400px" srcset="../hidpi/resources/image-set-1x.png?1 400w">
+            <source media="(max-width: 800px)" sizes="800px" srcset="../hidpi/resources/image-set-2x.png?2 800w">
+            <source media="(max-width: 1600px)" sizes="1600px" srcset="resources/image-set-4x.png?3 1600w">
+            <img id="simple" src=""
+        </picture>
+    </template>
+</div>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (284666 => 284667)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-22 04:57:49 UTC (rev 284666)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-22 05:05:42 UTC (rev 284667)
@@ -1,3 +1,12 @@
+2021-10-21  Cathie Chen  <cathiec...@igalia.com>
+
+        The intrisic size of picture image inside a template is always zero
+        https://bugs.webkit.org/show_bug.cgi?id=227682
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/html/semantics/embedded-content/the-img-element/adoption-expected.txt:
+
 2021-10-21  Sihui Liu  <sihui_...@apple.com>
 
         FileSystemSyncAccessHandle should close platform file handle on close()

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/adoption-expected.txt (284666 => 284667)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/adoption-expected.txt	2021-10-22 04:57:49 UTC (rev 284666)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/adoption-expected.txt	2021-10-22 05:05:42 UTC (rev 284667)
@@ -2,11 +2,11 @@
 Harness Error (TIMEOUT), message = null
 
 TIMEOUT img (src only) Test timed out
-TIMEOUT img (src only), parent is picture Test timed out
-TIMEOUT img (src only), previous sibling is source Test timed out
+PASS img (src only), parent is picture
+PASS img (src only), previous sibling is source
 TIMEOUT img (srcset 1 cand) Test timed out
-TIMEOUT img (srcset 1 cand), parent is picture Test timed out
-TIMEOUT img (srcset 1 cand), previous sibling is source Test timed out
+PASS img (srcset 1 cand), parent is picture
+PASS img (srcset 1 cand), previous sibling is source
 FAIL adopt a cloned img in template assert_equals: expected "http://localhost:8800/images/green-1x1.png" but got "/images/green-1x1.png"
 PASS adoption is from appendChild
 

Modified: trunk/Source/WebCore/ChangeLog (284666 => 284667)


--- trunk/Source/WebCore/ChangeLog	2021-10-22 04:57:49 UTC (rev 284666)
+++ trunk/Source/WebCore/ChangeLog	2021-10-22 05:05:42 UTC (rev 284667)
@@ -1,3 +1,24 @@
+2021-10-21  Cathie Chen  <cathiec...@igalia.com>
+
+        The intrisic size of picture image inside a template is always zero
+        https://bugs.webkit.org/show_bug.cgi?id=227682
+
+        Reviewed by Darin Adler.
+
+        When the picture element is inside a template element, it belongs to a template document which does not
+        have frame or RenderView, this would affect the source selection and size calculation. Though it calls
+        sourcesChanged to adjust the source in HTMLPictureElement::didMoveToNewDocument, but at this point
+        the image element is still inside the template document, so it does not help with this scenario. To
+        fix it, call sourcesChanged in HTMLImageElement::didMoveToNewDocument instead.
+
+        Test: fast/picture/picture-inside-template.html
+
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::didMoveToNewDocument):
+        * html/HTMLPictureElement.cpp:
+        (WebCore::HTMLPictureElement::didMoveToNewDocument): Deleted.
+        * html/HTMLPictureElement.h:
+
 2021-10-21  Gabriel Nava Marino  <gnavamar...@apple.com>
 
         Two null box iterators from different paths fail to compare equal

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (284666 => 284667)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2021-10-22 04:57:49 UTC (rev 284666)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2021-10-22 05:05:42 UTC (rev 284667)
@@ -681,6 +681,8 @@
 
     m_imageLoader->elementDidMoveToNewDocument(oldDocument);
     HTMLElement::didMoveToNewDocument(oldDocument, newDocument);
+    if (RefPtr element = pictureElement())
+        element->sourcesChanged();
 }
 
 bool HTMLImageElement::isServerMap() const

Modified: trunk/Source/WebCore/html/HTMLPictureElement.cpp (284666 => 284667)


--- trunk/Source/WebCore/html/HTMLPictureElement.cpp	2021-10-22 04:57:49 UTC (rev 284666)
+++ trunk/Source/WebCore/html/HTMLPictureElement.cpp	2021-10-22 05:05:42 UTC (rev 284667)
@@ -47,12 +47,6 @@
 {
 }
 
-void HTMLPictureElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
-{
-    HTMLElement::didMoveToNewDocument(oldDocument, newDocument);
-    sourcesChanged();
-}
-
 Ref<HTMLPictureElement> HTMLPictureElement::create(const QualifiedName& tagName, Document& document)
 {
     return adoptRef(*new HTMLPictureElement(tagName, document));

Modified: trunk/Source/WebCore/html/HTMLPictureElement.h (284666 => 284667)


--- trunk/Source/WebCore/html/HTMLPictureElement.h	2021-10-22 04:57:49 UTC (rev 284666)
+++ trunk/Source/WebCore/html/HTMLPictureElement.h	2021-10-22 05:05:42 UTC (rev 284667)
@@ -44,8 +44,6 @@
 
 private:
     HTMLPictureElement(const QualifiedName&, Document&);
-
-    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to