HTMLBodyElement.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(CSS::PropertyID::BackgroundColor, 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(CSS::PropertyID::Color, ColorStyleValue::create(color.value()));
  23. } else if (name == "background") {
  24. style.set_property(CSS::PropertyID::BackgroundImage, ImageStyleValue::create(document().complete_url(value), const_cast<Document&>(document())));
  25. }
  26. });
  27. }
  28. void HTMLBodyElement::parse_attribute(const String& name, const String& value)
  29. {
  30. if (name == "link") {
  31. auto color = Color::from_string(value);
  32. if (color.has_value())
  33. document().set_link_color(color.value());
  34. } else if (name == "alink") {
  35. auto color = Color::from_string(value);
  36. if (color.has_value())
  37. document().set_active_link_color(color.value());
  38. } else if (name == "vlink") {
  39. auto color = Color::from_string(value);
  40. if (color.has_value())
  41. document().set_visited_link_color(color.value());
  42. }
  43. }