ResolutionStyleValue.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2022-2024, Sam Atkins <sam@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/CSS/Resolution.h>
  8. #include <LibWeb/CSS/StyleValues/CSSUnitValue.h>
  9. namespace Web::CSS {
  10. class ResolutionStyleValue : public CSSUnitValue {
  11. public:
  12. static ValueComparingNonnullRefPtr<ResolutionStyleValue> create(Resolution resolution)
  13. {
  14. return adopt_ref(*new (nothrow) ResolutionStyleValue(move(resolution)));
  15. }
  16. virtual ~ResolutionStyleValue() override = default;
  17. Resolution const& resolution() const { return m_resolution; }
  18. virtual double value() const override { return m_resolution.raw_value(); }
  19. virtual StringView unit() const override { return m_resolution.unit_name(); }
  20. virtual String to_string() const override { return m_resolution.to_string(); }
  21. bool equals(CSSStyleValue const& other) const override
  22. {
  23. if (type() != other.type())
  24. return false;
  25. auto const& other_resolution = other.as_resolution();
  26. return m_resolution == other_resolution.m_resolution;
  27. }
  28. private:
  29. explicit ResolutionStyleValue(Resolution resolution)
  30. : CSSUnitValue(Type::Resolution)
  31. , m_resolution(move(resolution))
  32. {
  33. }
  34. Resolution m_resolution;
  35. };
  36. }