HTMLTableCellElement.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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, DOM::QualifiedName qualified_name)
  10. : HTMLElement(document, move(qualified_name))
  11. {
  12. }
  13. HTMLTableCellElement::~HTMLTableCellElement() = default;
  14. void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& style) const
  15. {
  16. for_each_attribute([&](auto& name, auto& value) {
  17. if (name == HTML::AttributeNames::bgcolor) {
  18. auto color = Color::from_string(value);
  19. if (color.has_value())
  20. style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()));
  21. return;
  22. }
  23. if (name == HTML::AttributeNames::align) {
  24. if (value.equals_ignoring_case("center"sv) || value.equals_ignoring_case("middle"sv)) {
  25. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::LibwebCenter));
  26. } else {
  27. CSS::Parser parser(CSS::ParsingContext(document()), value.view());
  28. if (auto parsed_value = parser.parse_as_css_value(CSS::PropertyID::TextAlign))
  29. style.set_property(CSS::PropertyID::TextAlign, parsed_value.release_nonnull());
  30. }
  31. return;
  32. }
  33. if (name == HTML::AttributeNames::width) {
  34. if (auto parsed_value = parse_html_length(document(), value))
  35. style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull());
  36. return;
  37. }
  38. });
  39. }
  40. }