HTMLTableCellElement.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/CSS/Parser/Parser.h>
  7. #include <LibWeb/HTML/HTMLTableCellElement.h>
  8. namespace Web::HTML {
  9. HTMLTableCellElement::HTMLTableCellElement(DOM::Document& document, QualifiedName qualified_name)
  10. : HTMLElement(document, move(qualified_name))
  11. {
  12. }
  13. HTMLTableCellElement::~HTMLTableCellElement()
  14. {
  15. }
  16. void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& style) const
  17. {
  18. for_each_attribute([&](auto& name, auto& value) {
  19. if (name == HTML::AttributeNames::bgcolor) {
  20. auto color = Color::from_string(value);
  21. if (color.has_value())
  22. style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()));
  23. return;
  24. }
  25. if (name == HTML::AttributeNames::align) {
  26. if (value.equals_ignoring_case("center") || value.equals_ignoring_case("middle"))
  27. style.set_property(CSS::PropertyID::TextAlign, StringView("-libweb-center"));
  28. else
  29. style.set_property(CSS::PropertyID::TextAlign, value.view());
  30. return;
  31. }
  32. if (name == HTML::AttributeNames::width) {
  33. if (auto parsed_value = parse_html_length(document(), value))
  34. style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull());
  35. return;
  36. }
  37. });
  38. }
  39. }