IntegerStyleValue.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2023-2024, Sam Atkins <sam@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/CSS/StyleValues/CSSUnitValue.h>
  8. namespace Web::CSS {
  9. class IntegerStyleValue final : public CSSUnitValue {
  10. public:
  11. static ValueComparingNonnullRefPtr<IntegerStyleValue> create(i64 value)
  12. {
  13. return adopt_ref(*new (nothrow) IntegerStyleValue(value));
  14. }
  15. i64 integer() const { return m_value; }
  16. virtual double value() const override { return m_value; }
  17. virtual StringView unit() const override { return "number"sv; }
  18. virtual String to_string() const override;
  19. bool equals(CSSStyleValue const& other) const override
  20. {
  21. if (type() != other.type())
  22. return false;
  23. auto const& other_integer = other.as_integer();
  24. return m_value == other_integer.m_value;
  25. }
  26. private:
  27. explicit IntegerStyleValue(i64 value)
  28. : CSSUnitValue(Type::Integer)
  29. , m_value(value)
  30. {
  31. }
  32. i64 m_value { 0 };
  33. };
  34. }