Changeset 269962 in webkit


Ignore:
Timestamp:
Nov 18, 2020 9:45:21 AM (3 years ago)
Author:
graouts@webkit.org
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.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r269950 r269962  
     12020-11-18  Antoine Quint  <graouts@webkit.org>
     2
     3        Support <source> as a child of <model> to specify the current source
     4        https://bugs.webkit.org/show_bug.cgi?id=219080
     5
     6        Reviewed by Dean Jackson.
     7
     8        Add a series of tests for the HTMLModelElement.currentSrc property and its relationship with <source> elements.
     9
     10        * system-preview/model/model-element-source-expected.txt: Added.
     11        * system-preview/model/model-element-source.html: Added.
     12
    1132020-11-18  Commit Queue  <commit-queue@webkit.org>
    214
  • trunk/Source/WebCore/ChangeLog

    r269960 r269962  
     12020-11-18  Antoine Quint  <graouts@webkit.org>
     2
     3        Support <source> as a child of <model> to specify the current source
     4        https://bugs.webkit.org/show_bug.cgi?id=219080
     5
     6        Reviewed by Dean Jackson.
     7
     8        Test: system-preview/model/model-element-source.html
     9
     10        * html/HTMLModelElement.cpp:
     11        (WebCore::HTMLModelElement::sourcesChanged):
     12        (WebCore::HTMLModelElement::setSourceURL):
     13        (WebCore::HTMLModelElement::didMoveToNewDocument):
     14        * html/HTMLModelElement.h:
     15        * html/HTMLModelElement.idl:
     16        * html/HTMLSourceElement.cpp:
     17        (WebCore::HTMLSourceElement::insertedIntoAncestor):
     18        (WebCore::HTMLSourceElement::removedFromAncestor):
     19        (WebCore::HTMLSourceElement::parseAttribute):
     20
    1212020-11-18  Chris Dumez  <cdumez@apple.com>
    222
  • trunk/Source/WebCore/html/HTMLModelElement.cpp

    r269880 r269962  
    2929#if ENABLE(MODEL_ELEMENT)
    3030
     31#include "HTMLNames.h"
     32#include "HTMLSourceElement.h"
    3133#include <wtf/IsoMallocInlines.h>
     34#include <wtf/URL.h>
    3235
    3336namespace WebCore {
     
    4952}
    5053
     54void HTMLModelElement::sourcesChanged()
     55{
     56    if (!document().hasBrowsingContext()) {
     57        setSourceURL(URL());
     58        return;
     59    }
     60
     61    for (auto& element : childrenOfType<HTMLSourceElement>(*this)) {
     62        // FIXME: for now we use the first valid URL without looking at the mime-type.
     63        auto url = element.getNonEmptyURLAttribute(srcAttr);
     64        if (url.isValid()) {
     65            setSourceURL(url);
     66            return;
     67        }
     68    }
     69
     70    setSourceURL(URL());
     71}
     72
     73void HTMLModelElement::setSourceURL(const URL& url)
     74{
     75    // FIXME: actually do something with that URL now.
     76    m_sourceURL = url;
     77}
     78
     79void HTMLModelElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
     80{
     81    HTMLElement::didMoveToNewDocument(oldDocument, newDocument);
     82    sourcesChanged();
     83}
     84
    5185}
    5286
  • trunk/Source/WebCore/html/HTMLModelElement.h

    r269880 r269962  
    3838    virtual ~HTMLModelElement();
    3939
     40    void sourcesChanged();
     41    const URL& currentSrc() const { return m_sourceURL; }
     42
    4043private:
    4144    HTMLModelElement(const QualifiedName&, Document&);
     45
     46    void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
     47
     48    void setSourceURL(const URL&);
     49
     50    URL m_sourceURL;
    4251};
    4352
  • trunk/Source/WebCore/html/HTMLModelElement.idl

    r269880 r269962  
    2929    Exposed=Window,
    3030] interface HTMLModelElement : HTMLElement {
     31    [URL] readonly attribute USVString currentSrc;
    3132};
  • trunk/Source/WebCore/html/HTMLSourceElement.cpp

    r263345 r269962  
    4141#endif
    4242
     43#if ENABLE(MODEL_ELEMENT)
     44#include "HTMLModelElement.h"
     45#endif
     46
    4347namespace WebCore {
    4448
     
    7680        if (is<HTMLMediaElement>(*parent))
    7781            downcast<HTMLMediaElement>(*parent).sourceWasAdded(*this);
     82        else
     83#endif
     84#if ENABLE(MODEL_ELEMENT)
     85        if (is<HTMLModelElement>(*parent))
     86            downcast<HTMLModelElement>(*parent).sourcesChanged();
    7887        else
    7988#endif
     
    101110        else
    102111#endif
     112#if ENABLE(MODEL_ELEMENT)
     113        if (is<HTMLModelElement>(oldParentOfRemovedTree))
     114            downcast<HTMLModelElement>(oldParentOfRemovedTree).sourcesChanged();
     115        else
     116#endif
    103117        if (m_shouldCallSourcesChanged) {
    104118            downcast<HTMLPictureElement>(oldParentOfRemovedTree).sourcesChanged();
     
    171185            downcast<HTMLPictureElement>(*parent).sourcesChanged();
    172186    }
     187#if ENABLE(MODEL_ELEMENT)
     188    if (name == srcAttr ||  name == typeAttr) {
     189        RefPtr<Element> parent = parentElement();
     190        if (is<HTMLModelElement>(parent))
     191            downcast<HTMLModelElement>(*parent).sourcesChanged();
     192    }
     193#endif
    173194}
    174195
Note: See TracChangeset for help on using the changeset viewer.