HTMLSourceElement.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. void HTMLSourceElement::initialize(JS::Realm& realm)
  17. {
  18. Base::initialize(realm);
  19. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLSourceElementPrototype>(realm, "HTMLSourceElement"));
  20. }
  21. // https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:the-source-element-15
  22. void HTMLSourceElement::inserted()
  23. {
  24. // The source HTML element insertion steps, given insertedNode, are:
  25. Base::inserted();
  26. // 1. If insertedNode's parent is a media element that has no src attribute and whose networkState has the value
  27. // NETWORK_EMPTY, then invoke that media element's resource selection algorithm.
  28. if (is<HTMLMediaElement>(parent())) {
  29. auto& media_element = static_cast<HTMLMediaElement&>(*parent());
  30. if (!media_element.has_attribute(HTML::AttributeNames::src) && media_element.network_state() == HTMLMediaElement::NetworkState::Empty)
  31. media_element.select_resource().release_value_but_fixme_should_propagate_errors();
  32. }
  33. // FIXME: 2. If insertedNode's next sibling is an img element and its parent is a picture element, then, count this as a
  34. // relevant mutation for the img element.
  35. }
  36. // https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:the-source-element-16
  37. void HTMLSourceElement::removed_from(DOM::Node* old_parent)
  38. {
  39. // The source HTML element removing steps, given removedNode and oldParent, are:
  40. Base::removed_from(old_parent);
  41. // FIXME: 1. If removedNode's next sibling was an img element and oldParent is a picture element, then, count this as a
  42. // relevant mutation for the img element.
  43. }
  44. }