SVGStopElement.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2023, MacDue <macdue@dueutil.tech>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/CSS/Parser/Parser.h>
  8. #include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
  9. #include <LibWeb/Layout/BlockContainer.h>
  10. #include <LibWeb/SVG/AttributeNames.h>
  11. #include <LibWeb/SVG/AttributeParser.h>
  12. #include <LibWeb/SVG/SVGStopElement.h>
  13. namespace Web::SVG {
  14. SVGStopElement::SVGStopElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  15. : SVGElement(document, qualified_name)
  16. {
  17. }
  18. void SVGStopElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value)
  19. {
  20. SVGElement::parse_attribute(name, value);
  21. if (name == SVG::AttributeNames::offset) {
  22. m_offset = AttributeParser::parse_number_percentage(value);
  23. }
  24. }
  25. void SVGStopElement::apply_presentational_hints(CSS::StyleProperties& style) const
  26. {
  27. CSS::Parser::ParsingContext parsing_context { document() };
  28. for_each_attribute([&](auto& name, auto& value) {
  29. if (name.equals_ignoring_ascii_case("stop-color"sv)) {
  30. CSS::Parser::ParsingContext parsing_context { document() };
  31. if (auto stop_color = parse_css_value(parsing_context, value, CSS::PropertyID::StopColor)) {
  32. style.set_property(CSS::PropertyID::StopColor, stop_color.release_nonnull());
  33. }
  34. }
  35. });
  36. }
  37. Gfx::Color SVGStopElement::stop_color() const
  38. {
  39. if (auto css_values = computed_css_values())
  40. return css_values->stop_color();
  41. return Color::Black;
  42. }
  43. JS::NonnullGCPtr<SVGAnimatedNumber> SVGStopElement::offset() const
  44. {
  45. TODO();
  46. }
  47. JS::ThrowCompletionOr<void> SVGStopElement::initialize(JS::Realm& realm)
  48. {
  49. MUST_OR_THROW_OOM(Base::initialize(realm));
  50. set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGStopElementPrototype>(realm, "SVGStopElement"));
  51. return {};
  52. }
  53. }