CSSOKLab.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/CSS/StyleValues/CSSColorValue.h>
  8. #include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
  9. namespace Web::CSS {
  10. // https://drafts.css-houdini.org/css-typed-om-1/#cssoklab
  11. class CSSOKLab final : public CSSColorValue {
  12. public:
  13. static ValueComparingNonnullRefPtr<CSSOKLab> create(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingRefPtr<CSSStyleValue> alpha = {})
  14. {
  15. // alpha defaults to 1
  16. if (!alpha)
  17. return adopt_ref(*new (nothrow) CSSOKLab(move(l), move(a), move(b), NumberStyleValue::create(1)));
  18. return adopt_ref(*new (nothrow) CSSOKLab(move(l), move(a), move(b), alpha.release_nonnull()));
  19. }
  20. virtual ~CSSOKLab() override = default;
  21. CSSStyleValue const& l() const { return *m_properties.l; }
  22. CSSStyleValue const& a() const { return *m_properties.a; }
  23. CSSStyleValue const& b() const { return *m_properties.b; }
  24. CSSStyleValue const& alpha() const { return *m_properties.alpha; }
  25. virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const override;
  26. String to_string() const override;
  27. virtual bool equals(CSSStyleValue const& other) const override;
  28. private:
  29. CSSOKLab(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)
  30. : CSSColorValue(ColorType::OKLab)
  31. , m_properties { .l = move(l), .a = move(a), .b = move(b), .alpha = move(alpha) }
  32. {
  33. }
  34. struct Properties {
  35. ValueComparingNonnullRefPtr<CSSStyleValue> l;
  36. ValueComparingNonnullRefPtr<CSSStyleValue> a;
  37. ValueComparingNonnullRefPtr<CSSStyleValue> b;
  38. ValueComparingNonnullRefPtr<CSSStyleValue> alpha;
  39. bool operator==(Properties const&) const = default;
  40. } m_properties;
  41. };
  42. }