HTMLFontElement.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/CSS/StyleProperties.h>
  8. #include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
  9. #include <LibWeb/HTML/HTMLFontElement.h>
  10. #include <LibWeb/HTML/Parser/HTMLParser.h>
  11. namespace Web::HTML {
  12. JS_DEFINE_ALLOCATOR(HTMLFontElement);
  13. HTMLFontElement::HTMLFontElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  14. : HTMLElement(document, move(qualified_name))
  15. {
  16. }
  17. HTMLFontElement::~HTMLFontElement() = default;
  18. void HTMLFontElement::initialize(JS::Realm& realm)
  19. {
  20. Base::initialize(realm);
  21. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLFontElementPrototype>(realm, "HTMLFontElement"));
  22. }
  23. void HTMLFontElement::apply_presentational_hints(CSS::StyleProperties& style) const
  24. {
  25. for_each_attribute([&](auto& name, auto& value) {
  26. if (name.equals_ignoring_ascii_case("color"sv)) {
  27. // https://html.spec.whatwg.org/multipage/rendering.html#phrasing-content-3:rules-for-parsing-a-legacy-colour-value
  28. auto color = parse_legacy_color_value(value);
  29. if (color.has_value())
  30. style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()));
  31. }
  32. });
  33. }
  34. }