2020-07-31 23:07:00 -03:00
|
|
|
/*
|
2021-04-28 17:46:44 -03:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-07-31 23:07:00 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-31 23:07:00 -03:00
|
|
|
*/
|
|
|
|
|
|
2026-04-18 05:54:06 -03:00
|
|
|
#include <LibWeb/Bindings/HTMLSourceElement.h>
|
2022-09-30 20:16:16 -03:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2023-05-12 16:04:58 -03:00
|
|
|
#include <LibWeb/HTML/AttributeNames.h>
|
|
|
|
|
#include <LibWeb/HTML/HTMLMediaElement.h>
|
2020-07-31 23:07:00 -03:00
|
|
|
#include <LibWeb/HTML/HTMLSourceElement.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(HTMLSourceElement);
|
2023-11-19 15:47:52 -03:00
|
|
|
|
2022-02-18 17:00:52 -03:00
|
|
|
HTMLSourceElement::HTMLSourceElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 07:20:15 -03:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
2020-07-31 23:07:00 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
HTMLSourceElement::~HTMLSourceElement() = default;
|
2020-07-31 23:07:00 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
void HTMLSourceElement::initialize(JS::Realm& realm)
|
2023-01-10 08:28:20 -03:00
|
|
|
{
|
2024-03-16 09:13:08 -03:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLSourceElement);
|
2025-04-20 11:22:57 -03:00
|
|
|
Base::initialize(realm);
|
2023-01-10 08:28:20 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-19 08:24:58 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:html-element-insertion-steps
|
2023-05-12 16:04:58 -03:00
|
|
|
void HTMLSourceElement::inserted()
|
|
|
|
|
{
|
|
|
|
|
// The source HTML element insertion steps, given insertedNode, are:
|
|
|
|
|
Base::inserted();
|
|
|
|
|
|
2025-03-19 08:24:58 -03:00
|
|
|
// 1. Let parent be insertedNode's parent.
|
|
|
|
|
auto* parent = this->parent();
|
2023-05-12 16:04:58 -03:00
|
|
|
|
2025-03-19 08:24:58 -03:00
|
|
|
// 2. If parent is a media element that has no src attribute and whose networkState has the value NETWORK_EMPTY,
|
|
|
|
|
// then invoke that media element's resource selection algorithm.
|
|
|
|
|
if (auto* media_element = as_if<HTMLMediaElement>(parent); media_element
|
|
|
|
|
&& !media_element->has_attribute(HTML::AttributeNames::src)
|
|
|
|
|
&& media_element->network_state() == HTMLMediaElement::NetworkState::Empty) {
|
2025-10-31 09:30:47 -03:00
|
|
|
media_element->select_resource();
|
2023-05-12 16:04:58 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-19 08:24:58 -03:00
|
|
|
// FIXME: 3. If parent is a picture element, then for each child of parent's children, if child is an img element, then
|
|
|
|
|
// count this as a relevant mutation for child.
|
2023-05-12 16:04:58 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-07 20:45:26 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:the-source-element-17
|
|
|
|
|
void HTMLSourceElement::moved_from(GC::Ptr<DOM::Node> old_parent)
|
|
|
|
|
{
|
|
|
|
|
Base::moved_from(old_parent);
|
|
|
|
|
|
|
|
|
|
// FIXME: 1. If oldParent is a picture element, then for each child of oldParent's children, if child is an img
|
|
|
|
|
// element, then count this as a relevant mutation for child.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:the-source-element-18
|
2025-01-23 13:37:18 -03:00
|
|
|
void HTMLSourceElement::removed_from(DOM::Node* old_parent, DOM::Node& old_root)
|
2023-05-12 16:04:58 -03:00
|
|
|
{
|
|
|
|
|
// The source HTML element removing steps, given removedNode and oldParent, are:
|
2025-01-23 13:37:18 -03:00
|
|
|
Base::removed_from(old_parent, old_root);
|
2023-05-12 16:04:58 -03:00
|
|
|
|
2025-03-19 08:24:58 -03:00
|
|
|
// FIXME: 1. If oldParent is a picture element, then for each child of oldParent's children, if child is an img
|
|
|
|
|
// element, then count this as a relevant mutation for child.
|
2023-05-12 16:04:58 -03:00
|
|
|
}
|
|
|
|
|
|
2020-07-31 23:07:00 -03:00
|
|
|
}
|