HTMLSourceElement.cpp 2.1 KB

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