HTMLBodyElement.cpp 2.4 KB

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