HTMLBodyElement.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/CSS/StyleProperties.h>
  7. #include <LibWeb/CSS/StyleValue.h>
  8. #include <LibWeb/DOM/Document.h>
  9. #include <LibWeb/HTML/HTMLBodyElement.h>
  10. #include <LibWeb/HTML/Window.h>
  11. namespace Web::HTML {
  12. HTMLBodyElement::HTMLBodyElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLBodyElement::~HTMLBodyElement() = default;
  17. void HTMLBodyElement::apply_presentational_hints(CSS::StyleProperties& style) const
  18. {
  19. for_each_attribute([&](auto& name, auto& value) {
  20. if (name.equals_ignoring_case("bgcolor")) {
  21. auto color = Color::from_string(value);
  22. if (color.has_value())
  23. style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()));
  24. } else if (name.equals_ignoring_case("text")) {
  25. auto color = Color::from_string(value);
  26. if (color.has_value())
  27. style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()));
  28. } else if (name.equals_ignoring_case("background")) {
  29. VERIFY(m_background_style_value);
  30. style.set_property(CSS::PropertyID::BackgroundImage, *m_background_style_value);
  31. }
  32. });
  33. }
  34. void HTMLBodyElement::parse_attribute(const FlyString& name, const String& value)
  35. {
  36. HTMLElement::parse_attribute(name, value);
  37. if (name.equals_ignoring_case("link")) {
  38. auto color = Color::from_string(value);
  39. if (color.has_value())
  40. document().set_link_color(color.value());
  41. } else if (name.equals_ignoring_case("alink")) {
  42. auto color = Color::from_string(value);
  43. if (color.has_value())
  44. document().set_active_link_color(color.value());
  45. } else if (name.equals_ignoring_case("vlink")) {
  46. auto color = Color::from_string(value);
  47. if (color.has_value())
  48. document().set_visited_link_color(color.value());
  49. } else if (name.equals_ignoring_case("background")) {
  50. m_background_style_value = CSS::ImageStyleValue::create(document().parse_url(value));
  51. }
  52. }
  53. DOM::EventTarget& HTMLBodyElement::global_event_handlers_to_event_target()
  54. {
  55. // NOTE: This is a little weird, but IIUC document.body.onload actually refers to window.onload
  56. return document().window();
  57. }
  58. }