HTMLTableCellElement.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2020-2022, 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. #include <LibWeb/HTML/Parser/HTMLParser.h>
  9. namespace Web::HTML {
  10. HTMLTableCellElement::HTMLTableCellElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  11. : HTMLElement(document, move(qualified_name))
  12. {
  13. }
  14. HTMLTableCellElement::~HTMLTableCellElement() = default;
  15. void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& style) const
  16. {
  17. for_each_attribute([&](auto& name, auto& value) {
  18. if (name == HTML::AttributeNames::bgcolor) {
  19. auto color = Color::from_string(value);
  20. if (color.has_value())
  21. style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()));
  22. return;
  23. }
  24. if (name == HTML::AttributeNames::align) {
  25. if (value.equals_ignoring_case("center"sv) || value.equals_ignoring_case("middle"sv)) {
  26. style.set_property(CSS::PropertyID::TextAlign, CSS::IdentifierStyleValue::create(CSS::ValueID::LibwebCenter));
  27. } else {
  28. CSS::Parser parser(CSS::ParsingContext(document()), value.view());
  29. if (auto parsed_value = parser.parse_as_css_value(CSS::PropertyID::TextAlign))
  30. style.set_property(CSS::PropertyID::TextAlign, parsed_value.release_nonnull());
  31. }
  32. return;
  33. }
  34. if (name == HTML::AttributeNames::width) {
  35. if (auto parsed_value = parse_nonzero_dimension_value(value))
  36. style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull());
  37. return;
  38. } else if (name == HTML::AttributeNames::height) {
  39. if (auto parsed_value = parse_nonzero_dimension_value(value))
  40. style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull());
  41. return;
  42. }
  43. });
  44. }
  45. unsigned int HTMLTableCellElement::col_span() const
  46. {
  47. return attribute(HTML::AttributeNames::colspan).to_uint().value_or(1);
  48. }
  49. void HTMLTableCellElement::set_col_span(unsigned int value)
  50. {
  51. set_attribute(HTML::AttributeNames::colspan, String::number(value));
  52. }
  53. }