HTMLStyleElement.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2021, the SerenityOS developers.
  4. * Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #include <LibWeb/Bindings/HTMLStyleElementPrototype.h>
  9. #include <LibWeb/HTML/HTMLStyleElement.h>
  10. namespace Web::HTML {
  11. GC_DEFINE_ALLOCATOR(HTMLStyleElement);
  12. HTMLStyleElement::HTMLStyleElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLStyleElement::~HTMLStyleElement() = default;
  17. void HTMLStyleElement::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLStyleElement);
  21. }
  22. void HTMLStyleElement::visit_edges(Cell::Visitor& visitor)
  23. {
  24. Base::visit_edges(visitor);
  25. m_style_element_utils.visit_edges(visitor);
  26. }
  27. void HTMLStyleElement::children_changed()
  28. {
  29. m_style_element_utils.update_a_style_block(*this);
  30. Base::children_changed();
  31. }
  32. void HTMLStyleElement::inserted()
  33. {
  34. m_style_element_utils.update_a_style_block(*this);
  35. Base::inserted();
  36. }
  37. void HTMLStyleElement::removed_from(Node* old_parent)
  38. {
  39. m_style_element_utils.update_a_style_block(*this);
  40. Base::removed_from(old_parent);
  41. }
  42. // https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled
  43. bool HTMLStyleElement::disabled()
  44. {
  45. // 1. If this does not have an associated CSS style sheet, return false.
  46. if (!sheet())
  47. return false;
  48. // 2. If this's associated CSS style sheet's disabled flag is set, return true.
  49. if (sheet()->disabled())
  50. return true;
  51. // 3. Return false.
  52. return false;
  53. }
  54. // https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled
  55. void HTMLStyleElement::set_disabled(bool disabled)
  56. {
  57. // 1. If this does not have an associated CSS style sheet, return.
  58. if (!sheet())
  59. return;
  60. // 2. If the given value is true, set this's associated CSS style sheet's disabled flag.
  61. // Otherwise, unset this's associated CSS style sheet's disabled flag.
  62. sheet()->set_disabled(disabled);
  63. }
  64. // https://www.w3.org/TR/cssom/#dom-linkstyle-sheet
  65. CSS::CSSStyleSheet* HTMLStyleElement::sheet()
  66. {
  67. // The sheet attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet.
  68. return m_style_element_utils.sheet();
  69. }
  70. // https://www.w3.org/TR/cssom/#dom-linkstyle-sheet
  71. CSS::CSSStyleSheet const* HTMLStyleElement::sheet() const
  72. {
  73. // The sheet attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet.
  74. return m_style_element_utils.sheet();
  75. }
  76. }