HTMLStyleElement.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/HTML/HTMLStyleElement.h>
  8. namespace Web::HTML {
  9. HTMLStyleElement::HTMLStyleElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  10. : HTMLElement(document, move(qualified_name))
  11. {
  12. }
  13. HTMLStyleElement::~HTMLStyleElement() = default;
  14. void HTMLStyleElement::initialize(JS::Realm& realm)
  15. {
  16. Base::initialize(realm);
  17. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLStyleElementPrototype>(realm, "HTMLStyleElement"));
  18. }
  19. void HTMLStyleElement::visit_edges(Cell::Visitor& visitor)
  20. {
  21. Base::visit_edges(visitor);
  22. visitor.visit(m_style_element_utils.sheet());
  23. }
  24. void HTMLStyleElement::children_changed()
  25. {
  26. m_style_element_utils.update_a_style_block(*this);
  27. Base::children_changed();
  28. }
  29. void HTMLStyleElement::inserted()
  30. {
  31. m_style_element_utils.update_a_style_block(*this);
  32. Base::inserted();
  33. }
  34. void HTMLStyleElement::removed_from(Node* old_parent)
  35. {
  36. m_style_element_utils.update_a_style_block(*this);
  37. Base::removed_from(old_parent);
  38. }
  39. // https://www.w3.org/TR/cssom/#dom-linkstyle-sheet
  40. CSS::CSSStyleSheet* HTMLStyleElement::sheet()
  41. {
  42. // The sheet attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet.
  43. return m_style_element_utils.sheet();
  44. }
  45. // https://www.w3.org/TR/cssom/#dom-linkstyle-sheet
  46. CSS::CSSStyleSheet const* HTMLStyleElement::sheet() const
  47. {
  48. // The sheet attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet.
  49. return m_style_element_utils.sheet();
  50. }
  51. }