HTMLOListElement.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLOListElementPrototype.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/HTML/HTMLOListElement.h>
  9. #include <LibWeb/HTML/Numbers.h>
  10. namespace Web::HTML {
  11. GC_DEFINE_ALLOCATOR(HTMLOListElement);
  12. HTMLOListElement::HTMLOListElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLOListElement::~HTMLOListElement() = default;
  17. void HTMLOListElement::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLOListElement);
  21. }
  22. // https://html.spec.whatwg.org/multipage/grouping-content.html#dom-ol-start
  23. WebIDL::Long HTMLOListElement::start()
  24. {
  25. // The start IDL attribute must reflect the content attribute of the same name, with a default value of 1.
  26. auto content_attribute_value = get_attribute(AttributeNames::start).value_or("1"_string);
  27. if (auto maybe_number = HTML::parse_integer(content_attribute_value); maybe_number.has_value())
  28. return *maybe_number;
  29. return 1;
  30. }
  31. }