ConicGradientStyleValue.h 2.6 KB

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