HTMLHRElement.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLHRElementPrototype.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/CSS/StyleProperties.h>
  9. #include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
  10. #include <LibWeb/HTML/HTMLHRElement.h>
  11. #include <LibWeb/HTML/Parser/HTMLParser.h>
  12. namespace Web::HTML {
  13. GC_DEFINE_ALLOCATOR(HTMLHRElement);
  14. HTMLHRElement::HTMLHRElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  15. : HTMLElement(document, move(qualified_name))
  16. {
  17. }
  18. HTMLHRElement::~HTMLHRElement() = default;
  19. void HTMLHRElement::initialize(JS::Realm& realm)
  20. {
  21. Base::initialize(realm);
  22. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLHRElement);
  23. }
  24. void HTMLHRElement::apply_presentational_hints(CSS::StyleProperties& style) const
  25. {
  26. for_each_attribute([&](auto& name, auto& value) {
  27. // https://html.spec.whatwg.org/multipage/rendering.html#the-hr-element-2:maps-to-the-dimension-property
  28. if (name == HTML::AttributeNames::width) {
  29. if (auto parsed_value = parse_dimension_value(value)) {
  30. style.set_property(CSS::PropertyID::Width, *parsed_value);
  31. }
  32. }
  33. });
  34. }
  35. }