NumberStyleValue.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.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/StyleValue.h>
  11. namespace Web::CSS {
  12. class NumberStyleValue : public StyleValueWithDefaultOperators<NumberStyleValue> {
  13. public:
  14. static ErrorOr<ValueComparingNonnullRefPtr<NumberStyleValue>> create(float value)
  15. {
  16. return adopt_nonnull_ref_or_enomem(new (nothrow) NumberStyleValue(value));
  17. }
  18. float number() const { return m_value; }
  19. virtual ErrorOr<String> to_string() const override;
  20. bool properties_equal(NumberStyleValue const& other) const { return m_value == other.m_value; }
  21. private:
  22. explicit NumberStyleValue(float value)
  23. : StyleValueWithDefaultOperators(Type::Number)
  24. , m_value(value)
  25. {
  26. }
  27. float m_value { 0 };
  28. };
  29. }