HTMLHRElement.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/ComputedProperties.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. bool HTMLHRElement::is_presentational_hint(FlyString const& name) const
  25. {
  26. if (Base::is_presentational_hint(name))
  27. return true;
  28. return first_is_one_of(name, HTML::AttributeNames::width);
  29. }
  30. void HTMLHRElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
  31. {
  32. for_each_attribute([&](auto& name, auto& value) {
  33. // https://html.spec.whatwg.org/multipage/rendering.html#the-hr-element-2:maps-to-the-dimension-property
  34. if (name == HTML::AttributeNames::width) {
  35. if (auto parsed_value = parse_dimension_value(value)) {
  36. cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, *parsed_value);
  37. }
  38. }
  39. });
  40. }
  41. }