ConicGradientStyleValue.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include <LibWeb/Painting/GradientPainting.h>
  12. namespace Web::CSS {
  13. class ConicGradientStyleValue final : public AbstractImageStyleValue {
  14. public:
  15. static ValueComparingNonnullRefPtr<ConicGradientStyleValue> create(Angle from_angle, PositionValue position, Vector<AngularColorStopListElement> color_stop_list, GradientRepeating repeating)
  16. {
  17. VERIFY(color_stop_list.size() >= 2);
  18. return adopt_ref(*new ConicGradientStyleValue(from_angle, position, move(color_stop_list), repeating));
  19. }
  20. virtual ErrorOr<String> to_string() const override;
  21. void paint(PaintContext&, DevicePixelRect const& dest_rect, CSS::ImageRendering) const override;
  22. virtual bool equals(StyleValue const& other) const override;
  23. Vector<AngularColorStopListElement> const& color_stop_list() const
  24. {
  25. return m_properties.color_stop_list;
  26. }
  27. float angle_degrees() const;
  28. bool is_paintable() const override { return true; }
  29. void resolve_for_size(Layout::Node const&, CSSPixelSize) const override;
  30. virtual ~ConicGradientStyleValue() override = default;
  31. bool is_repeating() const { return m_properties.repeating == GradientRepeating::Yes; }
  32. private:
  33. ConicGradientStyleValue(Angle from_angle, PositionValue position, Vector<AngularColorStopListElement> color_stop_list, GradientRepeating repeating)
  34. : AbstractImageStyleValue(Type::ConicGradient)
  35. , m_properties { .from_angle = from_angle, .position = position, .color_stop_list = move(color_stop_list), .repeating = repeating }
  36. {
  37. }
  38. struct Properties {
  39. // FIXME: Support <color-interpolation-method>
  40. Angle from_angle;
  41. PositionValue position;
  42. Vector<AngularColorStopListElement> color_stop_list;
  43. GradientRepeating repeating;
  44. bool operator==(Properties const&) const = default;
  45. } m_properties;
  46. struct ResolvedData {
  47. Painting::ConicGradientData data;
  48. CSSPixelPoint position;
  49. };
  50. mutable Optional<ResolvedData> m_resolved;
  51. };
  52. }