HTMLTableColElement.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/HTML/HTMLTableColElement.h>
  8. #include <LibWeb/HTML/Numbers.h>
  9. namespace Web::HTML {
  10. JS_DEFINE_ALLOCATOR(HTMLTableColElement);
  11. HTMLTableColElement::HTMLTableColElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  12. : HTMLElement(document, move(qualified_name))
  13. {
  14. }
  15. HTMLTableColElement::~HTMLTableColElement() = default;
  16. void HTMLTableColElement::initialize(JS::Realm& realm)
  17. {
  18. Base::initialize(realm);
  19. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTableColElement);
  20. }
  21. // https://html.spec.whatwg.org/multipage/tables.html#dom-colgroup-span
  22. unsigned int HTMLTableColElement::span() const
  23. {
  24. // 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.
  25. if (auto span_string = get_attribute(HTML::AttributeNames::span); span_string.has_value()) {
  26. if (auto span = parse_non_negative_integer(*span_string); span.has_value())
  27. return clamp(*span, 1, 1000);
  28. }
  29. return 1;
  30. }
  31. WebIDL::ExceptionOr<void> HTMLTableColElement::set_span(unsigned int value)
  32. {
  33. return set_attribute(HTML::AttributeNames::span, MUST(String::number(value)));
  34. }
  35. }