Title: [269962] trunk
Revision
269962
Author
[email protected]
Date
2020-11-18 09:45:21 -0800 (Wed, 18 Nov 2020)

Log Message

Support <source> as a child of <model> to specify the current source
https://bugs.webkit.org/show_bug.cgi?id=219080

Reviewed by Dean Jackson.

Source/WebCore:

Test: system-preview/model/model-element-source.html

* html/HTMLModelElement.cpp:
(WebCore::HTMLModelElement::sourcesChanged):
(WebCore::HTMLModelElement::setSourceURL):
(WebCore::HTMLModelElement::didMoveToNewDocument):
* html/HTMLModelElement.h:
* html/HTMLModelElement.idl:
* html/HTMLSourceElement.cpp:
(WebCore::HTMLSourceElement::insertedIntoAncestor):
(WebCore::HTMLSourceElement::removedFromAncestor):
(WebCore::HTMLSourceElement::parseAttribute):

LayoutTests:

Add a series of tests for the HTMLModelElement.currentSrc property and its relationship with <source> elements.

* system-preview/model/model-element-source-expected.txt: Added.
* system-preview/model/model-element-source.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (269961 => 269962)


--- trunk/LayoutTests/ChangeLog	2020-11-18 16:58:02 UTC (rev 269961)
+++ trunk/LayoutTests/ChangeLog	2020-11-18 17:45:21 UTC (rev 269962)
@@ -1,3 +1,15 @@
+2020-11-18  Antoine Quint  <[email protected]>
+
+        Support <source> as a child of <model> to specify the current source
+        https://bugs.webkit.org/show_bug.cgi?id=219080
+
+        Reviewed by Dean Jackson.
+
+        Add a series of tests for the HTMLModelElement.currentSrc property and its relationship with <source> elements.
+
+        * system-preview/model/model-element-source-expected.txt: Added.
+        * system-preview/model/model-element-source.html: Added.
+
 2020-11-18  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r269940.

Added: trunk/LayoutTests/system-preview/model/model-element-source-expected.txt (0 => 269962)


--- trunk/LayoutTests/system-preview/model/model-element-source-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/system-preview/model/model-element-source-expected.txt	2020-11-18 17:45:21 UTC (rev 269962)
@@ -0,0 +1,12 @@
+
+PASS The HTMLModelElement interface has a currentSrc property.
+PASS The currentSrc property is read-only.
+PASS The currentSrc property is the empty string when no <source> is provided.
+PASS The currentSrc property is the empty string when a <source> is provided with no src attribute.
+PASS The currentSrc property is the empty string when a <source> is provided.
+PASS Changing the src attribute of a <source> changes the currentSrc property.
+PASS Removing the <source> changes the currentSrc property.
+PASS currentSrc returns the src value for the first <source> element.
+PASS Removing a <source> element updates currentSrc.
+PASS Adding a <source> before the current <source> updates currentSrc.
+

Added: trunk/LayoutTests/system-preview/model/model-element-source.html (0 => 269962)


--- trunk/LayoutTests/system-preview/model/model-element-source.html	                        (rev 0)
+++ trunk/LayoutTests/system-preview/model/model-element-source.html	2020-11-18 17:45:21 UTC (rev 269962)
@@ -0,0 +1,81 @@
+<script src=""
+<script src=""
+<script>
+
+const makeSource = src ="" {
+    const source = document.createElement("source");
+    source.src = ""
+    return source;
+}
+
+test(() => {
+    assert_idl_attribute(document.createElement("model"), "currentSrc");
+}, "The HTMLModelElement interface has a currentSrc property.");
+
+test(() => {
+    assert_readonly(document.createElement("model"), "currentSrc");
+}, "The currentSrc property is read-only.");
+
+test(() => {
+    assert_equals(document.createElement("model").currentSrc, "");
+}, "The currentSrc property is the empty string when no <source> is provided.");
+
+test(() => {
+    const model = document.createElement("model");
+    model.appendChild(makeSource(""));
+    assert_equals(model.currentSrc, "");
+}, "The currentSrc property is the empty string when a <source> is provided with no src attribute.");
+
+test(() => {
+    const model = document.createElement("model");
+    const source = model.appendChild(makeSource("model.usdz"));
+    assert_equals(model.currentSrc, source.src);
+}, "The currentSrc property is the empty string when a <source> is provided.");
+
+test(() => {
+    const model = document.createElement("model");
+    const source = model.appendChild(makeSource(""));
+    assert_equals(model.currentSrc, "");
+
+    source.src = ""
+    assert_equals(model.currentSrc, source.src);
+}, "Changing the src attribute of a <source> changes the currentSrc property.");
+
+test(() => {
+    const model = document.createElement("model");
+    const source = model.appendChild(makeSource("model.usdz"));
+    assert_equals(model.currentSrc, source.src);
+
+    source.remove();
+    assert_equals(model.currentSrc, "");
+}, "Removing the <source> changes the currentSrc property.");
+
+test(() => {
+    const model = document.createElement("model");
+    const firstSource = model.appendChild(makeSource("model-1.usdz"));
+    const secondSource = model.appendChild(makeSource("model-2.usdz"));
+    assert_equals(model.currentSrc, firstSource.src);
+}, "currentSrc returns the src value for the first <source> element.");
+
+test(() => {
+    const model = document.createElement("model");
+    const firstSource = model.appendChild(makeSource("model-1.usdz"));
+    const secondSource = model.appendChild(makeSource("model-2.usdz"));
+    assert_equals(model.currentSrc, firstSource.src);
+
+    firstSource.remove();
+    assert_equals(model.currentSrc, secondSource.src);
+}, "Removing a <source> element updates currentSrc.");
+
+test(() => {
+    const model = document.createElement("model");
+    const initialSource = model.appendChild(makeSource("model-initial.usdz"));
+    assert_equals(model.currentSrc, initialSource.src);
+
+    const secondSource = model.insertBefore(makeSource("model-initial.usdz"), initialSource);
+    assert_equals(model.currentSrc, secondSource.src);
+}, "Adding a <source> before the current <source> updates currentSrc.");
+
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (269961 => 269962)


--- trunk/Source/WebCore/ChangeLog	2020-11-18 16:58:02 UTC (rev 269961)
+++ trunk/Source/WebCore/ChangeLog	2020-11-18 17:45:21 UTC (rev 269962)
@@ -1,3 +1,23 @@
+2020-11-18  Antoine Quint  <[email protected]>
+
+        Support <source> as a child of <model> to specify the current source
+        https://bugs.webkit.org/show_bug.cgi?id=219080
+
+        Reviewed by Dean Jackson.
+
+        Test: system-preview/model/model-element-source.html
+
+        * html/HTMLModelElement.cpp:
+        (WebCore::HTMLModelElement::sourcesChanged):
+        (WebCore::HTMLModelElement::setSourceURL):
+        (WebCore::HTMLModelElement::didMoveToNewDocument):
+        * html/HTMLModelElement.h:
+        * html/HTMLModelElement.idl:
+        * html/HTMLSourceElement.cpp:
+        (WebCore::HTMLSourceElement::insertedIntoAncestor):
+        (WebCore::HTMLSourceElement::removedFromAncestor):
+        (WebCore::HTMLSourceElement::parseAttribute):
+
 2020-11-18  Chris Dumez  <[email protected]>
 
         navigator.clipboard is not exposed on *.localhost pages

Modified: trunk/Source/WebCore/html/HTMLModelElement.cpp (269961 => 269962)


--- trunk/Source/WebCore/html/HTMLModelElement.cpp	2020-11-18 16:58:02 UTC (rev 269961)
+++ trunk/Source/WebCore/html/HTMLModelElement.cpp	2020-11-18 17:45:21 UTC (rev 269962)
@@ -28,7 +28,10 @@
 
 #if ENABLE(MODEL_ELEMENT)
 
+#include "HTMLNames.h"
+#include "HTMLSourceElement.h"
 #include <wtf/IsoMallocInlines.h>
+#include <wtf/URL.h>
 
 namespace WebCore {
 
@@ -48,6 +51,37 @@
     return adoptRef(*new HTMLModelElement(tagName, document));
 }
 
+void HTMLModelElement::sourcesChanged()
+{
+    if (!document().hasBrowsingContext()) {
+        setSourceURL(URL());
+        return;
+    }
+
+    for (auto& element : childrenOfType<HTMLSourceElement>(*this)) {
+        // FIXME: for now we use the first valid URL without looking at the mime-type.
+        auto url = ""
+        if (url.isValid()) {
+            setSourceURL(url);
+            return;
+        }
+    }
+
+    setSourceURL(URL());
 }
 
+void HTMLModelElement::setSourceURL(const URL& url)
+{
+    // FIXME: actually do something with that URL now.
+    m_sourceURL = url;
+}
+
+void HTMLModelElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
+{
+    HTMLElement::didMoveToNewDocument(oldDocument, newDocument);
+    sourcesChanged();
+}
+
+}
+
 #endif // ENABLE(MODEL_ELEMENT)

Modified: trunk/Source/WebCore/html/HTMLModelElement.h (269961 => 269962)


--- trunk/Source/WebCore/html/HTMLModelElement.h	2020-11-18 16:58:02 UTC (rev 269961)
+++ trunk/Source/WebCore/html/HTMLModelElement.h	2020-11-18 17:45:21 UTC (rev 269962)
@@ -37,8 +37,17 @@
     static Ref<HTMLModelElement> create(const QualifiedName&, Document&);
     virtual ~HTMLModelElement();
 
+    void sourcesChanged();
+    const URL& currentSrc() const { return m_sourceURL; }
+
 private:
     HTMLModelElement(const QualifiedName&, Document&);
+
+    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
+
+    void setSourceURL(const URL&);
+
+    URL m_sourceURL;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLModelElement.idl (269961 => 269962)


--- trunk/Source/WebCore/html/HTMLModelElement.idl	2020-11-18 16:58:02 UTC (rev 269961)
+++ trunk/Source/WebCore/html/HTMLModelElement.idl	2020-11-18 17:45:21 UTC (rev 269962)
@@ -28,4 +28,5 @@
     EnabledBySetting=ModelElement,
     Exposed=Window,
 ] interface HTMLModelElement : HTMLElement {
+    [URL] readonly attribute USVString currentSrc;
 };

Modified: trunk/Source/WebCore/html/HTMLSourceElement.cpp (269961 => 269962)


--- trunk/Source/WebCore/html/HTMLSourceElement.cpp	2020-11-18 16:58:02 UTC (rev 269961)
+++ trunk/Source/WebCore/html/HTMLSourceElement.cpp	2020-11-18 17:45:21 UTC (rev 269962)
@@ -40,6 +40,10 @@
 #include "HTMLMediaElement.h"
 #endif
 
+#if ENABLE(MODEL_ELEMENT)
+#include "HTMLModelElement.h"
+#endif
+
 namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLSourceElement);
@@ -77,6 +81,11 @@
             downcast<HTMLMediaElement>(*parent).sourceWasAdded(*this);
         else
 #endif
+#if ENABLE(MODEL_ELEMENT)
+        if (is<HTMLModelElement>(*parent))
+            downcast<HTMLModelElement>(*parent).sourcesChanged();
+        else
+#endif
         if (is<HTMLPictureElement>(*parent)) {
             // The new source element only is a relevant mutation if it precedes any img element.
             m_shouldCallSourcesChanged = true;
@@ -100,6 +109,11 @@
             downcast<HTMLMediaElement>(oldParentOfRemovedTree).sourceWasRemoved(*this);
         else
 #endif
+#if ENABLE(MODEL_ELEMENT)
+        if (is<HTMLModelElement>(oldParentOfRemovedTree))
+            downcast<HTMLModelElement>(oldParentOfRemovedTree).sourcesChanged();
+        else
+#endif
         if (m_shouldCallSourcesChanged) {
             downcast<HTMLPictureElement>(oldParentOfRemovedTree).sourcesChanged();
             m_shouldCallSourcesChanged = false;
@@ -170,6 +184,13 @@
         if (m_shouldCallSourcesChanged)
             downcast<HTMLPictureElement>(*parent).sourcesChanged();
     }
+#if ENABLE(MODEL_ELEMENT)
+    if (name == srcAttr ||  name == typeAttr) {
+        RefPtr<Element> parent = parentElement();
+        if (is<HTMLModelElement>(parent))
+            downcast<HTMLModelElement>(*parent).sourcesChanged();
+    }
+#endif
 }
 
 const MediaQuerySet* HTMLSourceElement::parsedMediaAttribute(Document& document) const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to