HTMLTableCellElement.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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()
  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"sv) || value.equals_ignoring_case("middle"sv)) {
  27. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::LibwebCenter));
  28. } else {
  29. CSS::Parser parser(CSS::ParsingContext(document()), value.view());
  30. if (auto parsed_value = parser.parse_as_css_value(CSS::PropertyID::TextAlign))
  31. style.set_property(CSS::PropertyID::TextAlign, parsed_value.release_nonnull());
  32. }
  33. return;
  34. }
  35. if (name == HTML::AttributeNames::width) {
  36. if (auto parsed_value = parse_html_length(document(), value))
  37. style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull());
  38. return;
  39. }
  40. });
  41. }
  42. }