NumberStyleValue.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 <LibWeb/CSS/StyleValues/CSSUnitValue.h>
  11. namespace Web::CSS {
  12. class NumberStyleValue final : public CSSUnitValue {
  13. public:
  14. static ValueComparingNonnullRefPtr<NumberStyleValue> create(double value)
  15. {
  16. return adopt_ref(*new (nothrow) NumberStyleValue(value));
  17. }
  18. double number() const { return m_value; }
  19. virtual double value() const override { return m_value; }
  20. virtual StringView unit() const override { return "number"sv; }
  21. virtual String to_string() const override;
  22. bool equals(CSSStyleValue const& other) const override
  23. {
  24. if (type() != other.type())
  25. return false;
  26. auto const& other_number = other.as_number();
  27. return m_value == other_number.m_value;
  28. }
  29. private:
  30. explicit NumberStyleValue(double value)
  31. : CSSUnitValue(Type::Number)
  32. , m_value(value)
  33. {
  34. }
  35. double m_value { 0 };
  36. };
  37. }