HTMLTableCellElement.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value.view(), 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_nonzero_dimension_value(value))
  35. style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull());
  36. return;
  37. } else if (name == HTML::AttributeNames::height) {
  38. if (auto parsed_value = parse_nonzero_dimension_value(value))
  39. style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull());
  40. return;
  41. }
  42. });
  43. }
  44. unsigned int HTMLTableCellElement::col_span() const
  45. {
  46. return attribute(HTML::AttributeNames::colspan).to_uint().value_or(1);
  47. }
  48. void HTMLTableCellElement::set_col_span(unsigned int value)
  49. {
  50. set_attribute(HTML::AttributeNames::colspan, String::number(value));
  51. }
  52. unsigned int HTMLTableCellElement::row_span() const
  53. {
  54. return attribute(HTML::AttributeNames::rowspan).to_uint().value_or(1);
  55. }
  56. void HTMLTableCellElement::set_row_span(unsigned int value)
  57. {
  58. set_attribute(HTML::AttributeNames::rowspan, String::number(value));
  59. }
  60. }