HTMLFontElement.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. namespace Web::HTML {
  11. HTMLFontElement::HTMLFontElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  12. : HTMLElement(document, move(qualified_name))
  13. {
  14. }
  15. HTMLFontElement::~HTMLFontElement() = default;
  16. JS::ThrowCompletionOr<void> HTMLFontElement::initialize(JS::Realm& realm)
  17. {
  18. MUST_OR_THROW_OOM(Base::initialize(realm));
  19. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLFontElementPrototype>(realm, "HTMLFontElement"));
  20. return {};
  21. }
  22. void HTMLFontElement::apply_presentational_hints(CSS::StyleProperties& style) const
  23. {
  24. for_each_attribute([&](auto& name, auto& value) {
  25. if (name.equals_ignoring_ascii_case("color"sv)) {
  26. auto color = Color::from_string(value);
  27. if (color.has_value())
  28. style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
  29. }
  30. });
  31. }
  32. }