ShadowStyleValue.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <LibGfx/Color.h>
  11. #include <LibWeb/CSS/Length.h>
  12. #include <LibWeb/CSS/StyleValue.h>
  13. namespace Web::CSS {
  14. enum class ShadowPlacement {
  15. Outer,
  16. Inner,
  17. };
  18. class ShadowStyleValue final : public StyleValueWithDefaultOperators<ShadowStyleValue> {
  19. public:
  20. static ValueComparingNonnullRefPtr<ShadowStyleValue> create(Color color, Length const& offset_x, Length const& offset_y, Length const& blur_radius, Length const& spread_distance, ShadowPlacement placement)
  21. {
  22. return adopt_ref(*new ShadowStyleValue(color, offset_x, offset_y, blur_radius, spread_distance, placement));
  23. }
  24. virtual ~ShadowStyleValue() override = default;
  25. Color color() const { return m_properties.color; }
  26. Length const& offset_x() const { return m_properties.offset_x; }
  27. Length const& offset_y() const { return m_properties.offset_y; }
  28. Length const& blur_radius() const { return m_properties.blur_radius; }
  29. Length const& spread_distance() const { return m_properties.spread_distance; }
  30. ShadowPlacement placement() const { return m_properties.placement; }
  31. virtual ErrorOr<String> to_string() const override;
  32. bool properties_equal(ShadowStyleValue const& other) const { return m_properties == other.m_properties; }
  33. private:
  34. explicit ShadowStyleValue(Color color, Length const& offset_x, Length const& offset_y, Length const& blur_radius, Length const& spread_distance, ShadowPlacement placement)
  35. : StyleValueWithDefaultOperators(Type::Shadow)
  36. , m_properties { .color = color, .offset_x = offset_x, .offset_y = offset_y, .blur_radius = blur_radius, .spread_distance = spread_distance, .placement = placement }
  37. {
  38. }
  39. virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const override;
  40. struct Properties {
  41. Color color;
  42. Length offset_x;
  43. Length offset_y;
  44. Length blur_radius;
  45. Length spread_distance;
  46. ShadowPlacement placement;
  47. bool operator==(Properties const&) const = default;
  48. } m_properties;
  49. };
  50. }