CSSColorValue.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. * Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.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/CSSStyleValue.h>
  12. namespace Web::CSS {
  13. // https://drafts.css-houdini.org/css-typed-om-1/#csscolorvalue
  14. class CSSColorValue : public CSSStyleValue {
  15. public:
  16. static ValueComparingNonnullRefPtr<CSSColorValue> create_from_color(Color color);
  17. virtual ~CSSColorValue() override = default;
  18. virtual bool has_color() const override { return true; }
  19. enum class ColorType {
  20. RGB, // This is used by CSSRGB for rgb(...) and rgba(...).
  21. A98RGB,
  22. DisplayP3,
  23. HSL,
  24. HWB,
  25. Lab,
  26. LCH,
  27. OKLab,
  28. OKLCH,
  29. sRGB, // This is used by CSSColor for color(srgb ...).
  30. sRGBLinear,
  31. ProPhotoRGB,
  32. Rec2020,
  33. XYZD50,
  34. XYZD65,
  35. };
  36. ColorType color_type() const { return m_color_type; }
  37. protected:
  38. explicit CSSColorValue(ColorType color_type)
  39. : CSSStyleValue(Type::Color)
  40. , m_color_type(color_type)
  41. {
  42. }
  43. static Optional<double> resolve_hue(CSSStyleValue const&);
  44. static Optional<double> resolve_with_reference_value(CSSStyleValue const&, float one_hundred_percent_value);
  45. static Optional<double> resolve_alpha(CSSStyleValue const&);
  46. private:
  47. ColorType m_color_type;
  48. };
  49. }