HTMLPreElement.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLPreElementPrototype.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/CSS/ComputedProperties.h>
  9. #include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
  10. #include <LibWeb/HTML/HTMLPreElement.h>
  11. #include <LibWeb/HTML/Numbers.h>
  12. namespace Web::HTML {
  13. GC_DEFINE_ALLOCATOR(HTMLPreElement);
  14. HTMLPreElement::HTMLPreElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  15. : HTMLElement(document, move(qualified_name))
  16. {
  17. }
  18. HTMLPreElement::~HTMLPreElement() = default;
  19. void HTMLPreElement::initialize(JS::Realm& realm)
  20. {
  21. Base::initialize(realm);
  22. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLPreElement);
  23. }
  24. bool HTMLPreElement::is_presentational_hint(FlyString const& name) const
  25. {
  26. if (Base::is_presentational_hint(name))
  27. return true;
  28. return name == HTML::AttributeNames::wrap;
  29. }
  30. void HTMLPreElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
  31. {
  32. HTMLElement::apply_presentational_hints(cascaded_properties);
  33. for_each_attribute([&](auto const& name, auto const&) {
  34. if (name.equals_ignoring_ascii_case(HTML::AttributeNames::wrap))
  35. cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::WhiteSpace, CSS::CSSKeywordValue::create(CSS::Keyword::PreWrap));
  36. });
  37. }
  38. }