HTMLStyleElement.cpp 915 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <AK/StringBuilder.h>
  2. #include <LibHTML/DOM/Document.h>
  3. #include <LibHTML/DOM/HTMLStyleElement.h>
  4. #include <LibHTML/DOM/Text.h>
  5. #include <LibHTML/Parser/CSSParser.h>
  6. HTMLStyleElement::HTMLStyleElement(Document& document, const String& tag_name)
  7. : HTMLElement(document, tag_name)
  8. {
  9. }
  10. HTMLStyleElement::~HTMLStyleElement()
  11. {
  12. }
  13. void HTMLStyleElement::inserted_into(Node& new_parent)
  14. {
  15. StringBuilder builder;
  16. for_each_child([&](auto& child) {
  17. if (is<Text>(child))
  18. builder.append(to<Text>(child).text_content());
  19. });
  20. m_stylesheet = parse_css(builder.to_string());
  21. if (m_stylesheet)
  22. document().add_sheet(*m_stylesheet);
  23. HTMLElement::inserted_into(new_parent);
  24. }
  25. void HTMLStyleElement::removed_from(Node& old_parent)
  26. {
  27. if (m_stylesheet) {
  28. // FIXME: Remove the sheet from the document
  29. }
  30. return HTMLElement::removed_from(old_parent);
  31. }