HTMLBodyElement.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <LibHTML/CSS/StyleProperties.h>
  2. #include <LibHTML/CSS/StyleValue.h>
  3. #include <LibHTML/DOM/Document.h>
  4. #include <LibHTML/DOM/HTMLBodyElement.h>
  5. HTMLBodyElement::HTMLBodyElement(Document& document, const String& tag_name)
  6. : HTMLElement(document, tag_name)
  7. {
  8. }
  9. HTMLBodyElement::~HTMLBodyElement()
  10. {
  11. }
  12. void HTMLBodyElement::apply_presentational_hints(StyleProperties& style) const
  13. {
  14. for_each_attribute([&](auto& name, auto& value) {
  15. if (name == "bgcolor") {
  16. auto color = Color::from_string(value);
  17. if (color.has_value())
  18. style.set_property("background-color", ColorStyleValue::create(color.value()));
  19. } else if (name == "text") {
  20. auto color = Color::from_string(value);
  21. if (color.has_value())
  22. style.set_property("color", ColorStyleValue::create(color.value()));
  23. }
  24. });
  25. }
  26. void HTMLBodyElement::parse_attribute(const String& name, const String& value)
  27. {
  28. if (name == "link") {
  29. auto color = Color::from_string(value);
  30. if (color.has_value())
  31. document().set_link_color(color.value());
  32. } else if (name == "alink") {
  33. auto color = Color::from_string(value);
  34. if (color.has_value())
  35. document().set_active_link_color(color.value());
  36. } else if (name == "vlink") {
  37. auto color = Color::from_string(value);
  38. if (color.has_value())
  39. document().set_visited_link_color(color.value());
  40. }
  41. }