HTMLTableColElement.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLTableColElementPrototype.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/CSS/StyleProperties.h>
  9. #include <LibWeb/HTML/HTMLTableColElement.h>
  10. #include <LibWeb/HTML/Numbers.h>
  11. #include <LibWeb/HTML/Parser/HTMLParser.h>
  12. namespace Web::HTML {
  13. GC_DEFINE_ALLOCATOR(HTMLTableColElement);
  14. HTMLTableColElement::HTMLTableColElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  15. : HTMLElement(document, move(qualified_name))
  16. {
  17. }
  18. HTMLTableColElement::~HTMLTableColElement() = default;
  19. void HTMLTableColElement::initialize(JS::Realm& realm)
  20. {
  21. Base::initialize(realm);
  22. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTableColElement);
  23. }
  24. // https://html.spec.whatwg.org/multipage/tables.html#dom-colgroup-span
  25. unsigned int HTMLTableColElement::span() const
  26. {
  27. // The span IDL attribute must reflect the content attribute of the same name. It is clamped to the range [1, 1000], and its default value is 1.
  28. if (auto span_string = get_attribute(HTML::AttributeNames::span); span_string.has_value()) {
  29. if (auto span = parse_non_negative_integer(*span_string); span.has_value())
  30. return clamp(*span, 1, 1000);
  31. }
  32. return 1;
  33. }
  34. WebIDL::ExceptionOr<void> HTMLTableColElement::set_span(unsigned int value)
  35. {
  36. return set_attribute(HTML::AttributeNames::span, String::number(value));
  37. }
  38. void HTMLTableColElement::apply_presentational_hints(CSS::StyleProperties& style) const
  39. {
  40. for_each_attribute([&](auto& name, auto& value) {
  41. // https://html.spec.whatwg.org/multipage/rendering.html#tables-2:maps-to-the-dimension-property-2
  42. if (name == HTML::AttributeNames::width) {
  43. if (auto parsed_value = parse_dimension_value(value)) {
  44. style.set_property(CSS::PropertyID::Width, *parsed_value);
  45. }
  46. }
  47. });
  48. }
  49. }