HTMLSourceElement.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/HTML/AttributeNames.h>
  8. #include <LibWeb/HTML/HTMLMediaElement.h>
  9. #include <LibWeb/HTML/HTMLSourceElement.h>
  10. namespace Web::HTML {
  11. HTMLSourceElement::HTMLSourceElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  12. : HTMLElement(document, move(qualified_name))
  13. {
  14. }
  15. HTMLSourceElement::~HTMLSourceElement() = default;
  16. JS::ThrowCompletionOr<void> HTMLSourceElement::initialize(JS::Realm& realm)
  17. {
  18. MUST_OR_THROW_OOM(Base::initialize(realm));
  19. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLSourceElementPrototype>(realm, "HTMLSourceElement"));
  20. return {};
  21. }
  22. // https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:the-source-element-15
  23. void HTMLSourceElement::inserted()
  24. {
  25. // The source HTML element insertion steps, given insertedNode, are:
  26. Base::inserted();
  27. // 1. If insertedNode's parent is a media element that has no src attribute and whose networkState has the value
  28. // NETWORK_EMPTY, then invoke that media element's resource selection algorithm.
  29. if (is<HTMLMediaElement>(parent())) {
  30. auto& media_element = static_cast<HTMLMediaElement&>(*parent());
  31. if (!media_element.has_attribute(HTML::AttributeNames::src) && media_element.network_state() == HTMLMediaElement::NetworkState::Empty)
  32. media_element.select_resource().release_value_but_fixme_should_propagate_errors();
  33. }
  34. // FIXME: 2. If insertedNode's next sibling is an img element and its parent is a picture element, then, count this as a
  35. // relevant mutation for the img element.
  36. }
  37. // https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:the-source-element-16
  38. void HTMLSourceElement::removed_from(DOM::Node* old_parent)
  39. {
  40. // The source HTML element removing steps, given removedNode and oldParent, are:
  41. Base::removed_from(old_parent);
  42. // FIXME: 1. If removedNode's next sibling was an img element and oldParent is a picture element, then, count this as a
  43. // relevant mutation for the img element.
  44. }
  45. }