ConicGradientStyleValue.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  5. * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #pragma once
  10. #include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
  11. namespace Web::CSS {
  12. class ConicGradientStyleValue final : public AbstractImageStyleValue {
  13. public:
  14. static ValueComparingNonnullRefPtr<ConicGradientStyleValue> create(Angle from_angle, PositionValue position, Vector<AngularColorStopListElement> color_stop_list, GradientRepeating repeating)
  15. {
  16. VERIFY(color_stop_list.size() >= 2);
  17. return adopt_ref(*new ConicGradientStyleValue(from_angle, position, move(color_stop_list), repeating));
  18. }
  19. virtual ErrorOr<String> to_string() const override;
  20. void paint(PaintContext&, DevicePixelRect const& dest_rect, CSS::ImageRendering) const override;
  21. virtual bool equals(StyleValue const& other) const override;
  22. Vector<AngularColorStopListElement> const& color_stop_list() const
  23. {
  24. return m_properties.color_stop_list;
  25. }
  26. float angle_degrees() const;
  27. bool is_paintable() const override { return true; }
  28. void resolve_for_size(Layout::Node const&, CSSPixelSize) const override;
  29. virtual ~ConicGradientStyleValue() override = default;
  30. bool is_repeating() const { return m_properties.repeating == GradientRepeating::Yes; }
  31. private:
  32. ConicGradientStyleValue(Angle from_angle, PositionValue position, Vector<AngularColorStopListElement> color_stop_list, GradientRepeating repeating)
  33. : AbstractImageStyleValue(Type::ConicGradient)
  34. , m_properties { .from_angle = from_angle, .position = position, .color_stop_list = move(color_stop_list), .repeating = repeating }
  35. {
  36. }
  37. struct Properties {
  38. // FIXME: Support <color-interpolation-method>
  39. Angle from_angle;
  40. PositionValue position;
  41. Vector<AngularColorStopListElement> color_stop_list;
  42. GradientRepeating repeating;
  43. bool operator==(Properties const&) const = default;
  44. } m_properties;
  45. struct ResolvedData {
  46. Painting::ConicGradientData data;
  47. CSSPixelPoint position;
  48. };
  49. mutable Optional<ResolvedData> m_resolved;
  50. };
  51. }