HTMLFontElement.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/StyleValue.h>
  9. #include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
  10. #include <LibWeb/HTML/HTMLFontElement.h>
  11. namespace Web::HTML {
  12. HTMLFontElement::HTMLFontElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLFontElement::~HTMLFontElement() = default;
  17. JS::ThrowCompletionOr<void> HTMLFontElement::initialize(JS::Realm& realm)
  18. {
  19. MUST_OR_THROW_OOM(Base::initialize(realm));
  20. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLFontElementPrototype>(realm, "HTMLFontElement"));
  21. return {};
  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. auto color = Color::from_string(value);
  28. if (color.has_value())
  29. style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()));
  30. }
  31. });
  32. }
  33. }