CSSColorValue.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. XYZD50,
  33. XYZD65,
  34. };
  35. ColorType color_type() const { return m_color_type; }
  36. protected:
  37. explicit CSSColorValue(ColorType color_type)
  38. : CSSStyleValue(Type::Color)
  39. , m_color_type(color_type)
  40. {
  41. }
  42. static Optional<float> resolve_hue(CSSStyleValue const&);
  43. static Optional<float> resolve_with_reference_value(CSSStyleValue const&, float one_hundred_percent_value);
  44. static Optional<float> resolve_alpha(CSSStyleValue const&);
  45. private:
  46. ColorType m_color_type;
  47. };
  48. }